109 return comps[0] != NULL;
122 size_t len = strlen(filename);
123 if (len >= 4 && filename[len - 4] ==
'.' &&
124 toupper(filename[len - 3]) ==
'P' &&
125 (toupper(filename[len - 2])==
'P' || toupper(filename[len - 2]) ==
'G') &&
126 toupper(filename[len - 1]) ==
'M')
142 width = calc_aligned_size<si32, byte_alignment>(width);
145 line.
wrap(buffer, width, 0);
147 for (
ui32 c = 0; c < num_comps; ++c)
150 for (
ui32 h = 0; h < height; ++h)
153 memcpy(p, line.
i32, w *
sizeof(
si32));
163 const char *p = strchr(filename,
':');
164 if (p != NULL && p - filename >= 4 && p[-4] ==
'.' &&
165 toupper(p[-3]) ==
'Y' && toupper(p[-2])==
'U' && toupper(p[-1]) ==
'V')
172 const char *p = strchr(filename,
':');
173 const char *name_end = p;
175 printf(
"A .yuv that does not have the expected format, which is\n");
176 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
177 printf(
"either 444, 422, or 420\n");
182 s.
w = (
ui32)atoi(++p);
185 printf(
"Expecting image height.\n");
186 printf(
"A .yuv that does not have the expected format, which is\n");
187 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
188 printf(
"either 444, 422, or 420\n");
191 s.
h = (
ui32)atoi(++p);
194 printf(
"Expecting image bitdepth.\n");
195 printf(
"A .yuv that does not have the expected format, which is\n");
196 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
197 printf(
"either 444, 422, or 420\n");
203 printf(
"Expecting color subsampling format.\n");
204 printf(
"A .yuv that does not have the expected format, which is\n");
205 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
206 printf(
"either 444, 422, or 420\n");
211 size_t len = strlen(p);
214 printf(
"Image color format must have 3 characters, %s was supplied.\n", p);
215 printf(
"A .yuv that does not have the expected format, which is\n");
216 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
217 printf(
"either 444, 422, or 420\n");
223 if (strcmp(p,
"444") == 0)
228 else if (strcmp(p,
"422") == 0)
232 downsampling[1].
x = downsampling[2].
x = 2;
234 else if (strcmp(p,
"420") == 0)
238 downsampling[1].
x = downsampling[2].
x = 2;
239 downsampling[1].
y = downsampling[2].
y = 2;
241 else if (strcmp(p,
"400") == 0)
247 printf(
"Unknown image color format, %s.\n", p);
252 ptrdiff_t cpy_len = name_end - filename > 2047 ? 2047 : name_end - filename;
253 strncpy(name_buf, filename, (
size_t)cpy_len);
254 name_buf[cpy_len] = 0;
257 ui32 depths[3] = {bit_depth, bit_depth, bit_depth};
262 img.
init(num_comps, s.
w, s.
h, (1 << bit_depth) - 1, format);
264 size_t w = calc_aligned_size<si32, byte_alignment>(s.
w);
267 line.
wrap(buffer, w, 0);
269 for (
ui32 c = 0; c < num_comps; ++c)
273 for (
ui32 h = 0; h < height; ++h)
276 memcpy(p, line.
i32, w *
sizeof(
si32));
285 float mse[3],
ui32 pae[3])
291 printf(
"Error: mismatching images\n");
301 for (
ui32 v = 0; v < h; ++v)
305 for (
ui32 s = 0; s < w; ++s)
307 si32 err = *p0++ - *p1++;
308 ui32 ae = (
ui32)(err > 0 ? err : -err);
309 lpae = ae > lpae ? ae : lpae;
310 se += (double)err * (
double)err;
313 mse[c] = (float)se / (
float)(w * h);
323int main(
int argc,
char *argv[])
327 printf(
"mse_pae expects two arguments <filename1, filename2>\n");
338 printf(
"mse_pae does not know file format of %s\n", argv[1]);
339 printf(
"or a .yuv that does not have the expected format, which is\n");
340 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
341 printf(
"either 444, 422, or 420\n");
345 catch (
const std::exception& e)
347 const char *p = e.what();
348 if (strncmp(p,
"ojph error", 10) != 0)
359 printf(
"mse_pae does not know file format of %s\n", argv[2]);
360 printf(
"or a .yuv that does not have the expected format, which is\n");
361 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
362 printf(
"either 444, 422, or 420\n");
366 catch (
const std::exception& e)
368 const char *p = e.what();
369 if (strncmp(p,
"ojph error", 10) != 0)
374 float mse[3];
ui32 pae[3];
378 printf(
"%f %d\n", mse[c], pae[c]);
void open(const char *filename)
ui32 get_num_components()
void set_planar(bool planar)
virtual ui32 read(const line_buf *line, ui32 comp_num)
virtual ui32 read(const line_buf *line, ui32 comp_num)
void open(const char *filename)
void set_img_props(const size &s, ui32 num_components, ui32 num_downsampling, const point *downsampling)
void set_bit_depth(ui32 num_bit_depths, ui32 *bit_depth)
void find_mse_pae(const img_info &img1, const img_info &img2, float mse[3], ui32 pae[3])
int main(int argc, char *argv[])
bool is_yuv(const char *filename)
bool is_pnm(const char *filename)
void load_ppm(const char *filename, img_info &img)
void load_yuv(const char *filename, img_info &img)
void init(ui32 num_comps, size_t width, size_t height, ui32 max_val, ui32 format=FORMAT444)
void wrap(T *buffer, size_t num_ele, ui32 pre_size)