Skip to content

Commit 73e05e6

Browse files
committed
V1.2 Using U+2580 for finer output
1 parent 787a94a commit 73e05e6

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
![Sample Output](./OutputSample.jpg)
22

33
## Note:
4-
4+
- If on Linux, use [chafa](https://github.com/hpjansson/chafa)
55
- For build, tested only with GCC of Mingw-w64 v12.1.0
6-
- For use, tested only on Windows 11 with Windows Terminal v1.15.2875.0
6+
- For use, tested only on the latest version of Windows 11 and Windows Terminal
77
- Questions? Read the source, for it's short
88

99
## Build

build.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
param(
2+
[String]$action="build"
3+
)
4+
5+
function main(){
6+
if($action -eq "build") { Start-BuildRoutinue; }
7+
elseif($action -eq "test") { Start-BuildRoutinue; Start-TestRoutinue; }
8+
}
9+
10+
function Start-BuildRoutinue($outputPath="sii"){
11+
gcc main.c -o $outputPath
12+
}
13+
14+
function Start-TestRoutinue($inputImagePath="./input.jpg"){
15+
./sii.exe $inputImagePath
16+
}
17+
18+
main

main.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ int main(int Arguments_Count, char** Arguments_Value)
1414
const int OUT_WIDTH_MAX = 1080; // <-- Configure it
1515
const int OUT_WIDTH_MIN = 16; // <-- Configure it
1616
// https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit
17-
const char TERMINAL_PIXEL_STRING_HEAD[] = "\033[48;2;"; // Background Color Mode
17+
const char TERMINAL_PIXEL_STRING_FOREGROUND_COLOR_HEAD[] = "\033[38;2;";
18+
const char TERMINAL_PIXEL_STRING_BACKGROUND_COLOR_HEAD[] = ";48;2;";
1819
const char TERMINAL_PIXEL_STRING_TAIL[] = "\033[m";
1920

2021
CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo;
2122
int TerminalHorizontalPixelCount;
2223
int TerminalVerticalPixelCount;
2324
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ConsoleScreenBufferInfo);
24-
TerminalHorizontalPixelCount = (ConsoleScreenBufferInfo.srWindow.Right - ConsoleScreenBufferInfo.srWindow.Left + 1)/2;
25-
TerminalVerticalPixelCount = ConsoleScreenBufferInfo.srWindow.Bottom - ConsoleScreenBufferInfo.srWindow.Top + 1;
25+
TerminalHorizontalPixelCount = ((ConsoleScreenBufferInfo.srWindow.Right - ConsoleScreenBufferInfo.srWindow.Left + 1)/2) * 2;
26+
TerminalVerticalPixelCount = (ConsoleScreenBufferInfo.srWindow.Bottom - ConsoleScreenBufferInfo.srWindow.Top + 1) * 2;
2627

2728
const char HELP_DOC[] =
2829
"ShowInputImage (sii)\n\n"
@@ -92,6 +93,9 @@ int main(int Arguments_Count, char** Arguments_Value)
9293
Out_Width = Out_Width_f;
9394
}
9495

96+
// Using U+2580 (Upper Half Block), and hence upscaling he size
97+
// https://www.compart.com/en/unicode/block/U+2580
98+
9599
unsigned char* Resized_Image_Data = malloc( Out_Width * Out_Height * OUT_CHANNELS_NUM );
96100
stbir_resize_uint8(
97101
Image_Data, Image_Width, Image_Height, 0,
@@ -101,26 +105,43 @@ int main(int Arguments_Count, char** Arguments_Value)
101105
// Text: Output Image
102106
int Pixel_Num_Max = Out_Width * Out_Height;
103107

108+
int x_Tracker = 0;
109+
104110
for(
105111
int Pixel_Num_Current = 0;
106112
Pixel_Num_Current<Pixel_Num_Max;
107113
Pixel_Num_Current++
108114
)
109115
{
110-
int R_Index = Pixel_Num_Current * 3;
111-
int G_Index = Pixel_Num_Current * 3 + 1;
112-
int B_Index = Pixel_Num_Current * 3 + 2;
113-
int R = Resized_Image_Data[R_Index];
114-
int G = Resized_Image_Data[G_Index];
115-
int B = Resized_Image_Data[B_Index];
116-
printf("%s%d;%d;%dm %s",
117-
TERMINAL_PIXEL_STRING_HEAD,
118-
R, G, B,
116+
int Upper_R_Index = Pixel_Num_Current * 3;
117+
int Upper_G_Index = Pixel_Num_Current * 3 + 1;
118+
int Upper_B_Index = Pixel_Num_Current * 3 + 2;
119+
int Upper_R = Resized_Image_Data[Upper_R_Index];
120+
int Upper_G = Resized_Image_Data[Upper_G_Index];
121+
int Upper_B = Resized_Image_Data[Upper_B_Index];
122+
123+
int Lower_R_Index = (Pixel_Num_Current + Out_Width) * 3;
124+
int Lower_G_Index = (Pixel_Num_Current + Out_Width) * 3 + 1;
125+
int Lower_B_Index = (Pixel_Num_Current + Out_Width) * 3 + 2;
126+
int Lower_R = Resized_Image_Data[Lower_R_Index];
127+
int Lower_G = Resized_Image_Data[Lower_G_Index];
128+
int Lower_B = Resized_Image_Data[Lower_B_Index];
129+
130+
printf("%s%d;%d;%d%s%d;%d;%dm▀%s",
131+
TERMINAL_PIXEL_STRING_FOREGROUND_COLOR_HEAD,
132+
Upper_R, Upper_G, Upper_B,
133+
TERMINAL_PIXEL_STRING_BACKGROUND_COLOR_HEAD,
134+
Lower_R, Lower_G, Lower_B,
119135
TERMINAL_PIXEL_STRING_TAIL
120136
);
121137
if(Pixel_Num_Current != 0 && (Pixel_Num_Current+1)%Out_Width == 0){
122138
printf("\n");
123139
}
140+
x_Tracker += 1;
141+
if(x_Tracker == Out_Width){
142+
Pixel_Num_Current += Out_Width;
143+
x_Tracker = 0;
144+
}
124145
}
125146

126147
// Text: Memory Management

0 commit comments

Comments
 (0)