71 {
72 if (original == NULL || !palette_chars || !luminance_palette) {
73 log_error("ascii_convert: invalid parameters");
74 return NULL;
75 }
76
77
78 if (palette_chars[0] == '\0' || luminance_palette[0] == '\0') {
79 log_error("ascii_convert: empty palette strings");
80 return NULL;
81 }
82
83
84
85
86
87 ssize_t resized_width = width;
88 ssize_t resized_height = height;
89
90
91 if (_aspect_ratio) {
92
93
94 aspect_ratio(original->w, original->h, resized_width, resized_height, stretch, &resized_width, &resized_height);
95 }
96
97
98 size_t pad_width = 0;
99 size_t pad_height = 0;
100
101 if (_aspect_ratio) {
102
103 ssize_t pad_width_ss = width > resized_width ? (width - resized_width) / 2 : 0;
104 pad_width = (size_t)pad_width_ss;
105
106 ssize_t pad_height_ss = height > resized_height ? (height - resized_height) / 2 : 0;
107 pad_height = (size_t)pad_height_ss;
108 }
109
110
111 if (resized_width <= 0 || resized_height <= 0) {
112 log_error("Invalid dimensions for resize: width=%zd, height=%zd", resized_width, resized_height);
113 return NULL;
114 }
115
116
117 if (resized_width > INT_MAX || resized_height > INT_MAX) {
118 log_error("Dimensions exceed INT_MAX: width=%zd, height=%zd", resized_width, resized_height);
119 return NULL;
120 }
121
122
123 image_t *resized =
image_new((
size_t)resized_width, (
size_t)resized_height);
124 if (!resized) {
125 log_error("Failed to allocate resized image");
126 return NULL;
127 }
128
131
132 char *ascii;
133 if (color) {
134
135 if (GET_OPTION(render_mode) == RENDER_MODE_HALF_BLOCK) {
136#if SIMD_SUPPORT_NEON
137
138 const uint8_t *rgb_data = (const uint8_t *)resized->pixels;
139 ascii = rgb_to_truecolor_halfblocks_neon(rgb_data, resized->w, resized->h, 0);
140#else
141 log_error("Half-block mode requires NEON support (ARM architecture)");
143 return NULL;
144#endif
145 } else {
146#ifdef SIMD_SUPPORT
147
148 bool use_background = (GET_OPTION(render_mode) == RENDER_MODE_BACKGROUND);
150#else
152#endif
153 }
154 } else {
155
156#ifdef SIMD_SUPPORT
158#else
160#endif
161 }
162
163 if (!ascii) {
164 log_error("Failed to convert image to ASCII");
166 return NULL;
167 }
168
169 size_t ascii_len = strlen(ascii);
170 if (ascii_len == 0) {
171 log_error("ASCII conversion returned empty string (resized dimensions: %dx%d)", resized->w, resized->h);
172 SAFE_FREE(ascii);
174 return NULL;
175 }
176
178 SAFE_FREE(ascii);
179
181 SAFE_FREE(ascii_width_padded);
182
183
185
186 return ascii_padded;
187}
char * ascii_pad_frame_width(const char *frame, size_t pad_left)
char * ascii_pad_frame_height(const char *frame, size_t pad_top)
char * image_print_simd(image_t *image, const char *ascii_chars)
char * image_print_color_simd(image_t *image, bool use_background_mode, bool use_256color, const char *ascii_chars)
void aspect_ratio(const ssize_t img_w, const ssize_t img_h, const ssize_t width, const ssize_t height, const bool stretch, ssize_t *out_width, ssize_t *out_height)
char * image_print(const image_t *p, const char *palette)
char * image_print_color(const image_t *p, const char *palette)
void image_resize(const image_t *s, image_t *d)
void image_clear(image_t *p)
void image_destroy(image_t *p)
image_t * image_new(size_t width, size_t height)