111 return comps[0] != NULL;
125 size_t len = strlen(filename);
126 if (len >= 4 && filename[len - 4] ==
'.' &&
127 toupper(filename[len - 3]) ==
'P' &&
128 (toupper(filename[len - 2])==
'P' || toupper(filename[len - 2]) ==
'G') &&
129 toupper(filename[len - 1]) ==
'M')
145 width = calc_aligned_size<si32, byte_alignment>(width);
148 line.
wrap(buffer, width, 0);
150 for (
ui32 c = 0; c < num_comps; ++c)
153 for (
ui32 h = 0; h < height; ++h)
156 memcpy(p, line.
i32, w *
sizeof(
si32));
166 const char *p = strchr(filename,
':');
167 if (p != NULL && p - filename >= 4 && p[-4] ==
'.' &&
168 toupper(p[-3]) ==
'Y' && toupper(p[-2])==
'U' && toupper(p[-1]) ==
'V')
175 const char *p = strchr(filename,
':');
176 const char *name_end = p;
178 printf(
"A .yuv that does not have the expected format, which is\n");
179 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
180 printf(
"either 444, 422, or 420\n");
185 s.
w = (
ui32)atoi(++p);
188 printf(
"Expecting image height.\n");
189 printf(
"A .yuv that does not have the expected format, which is\n");
190 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
191 printf(
"either 444, 422, or 420\n");
194 s.
h = (
ui32)atoi(++p);
197 printf(
"Expecting image bitdepth.\n");
198 printf(
"A .yuv that does not have the expected format, which is\n");
199 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
200 printf(
"either 444, 422, or 420\n");
206 printf(
"Expecting color subsampling format.\n");
207 printf(
"A .yuv that does not have the expected format, which is\n");
208 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
209 printf(
"either 444, 422, or 420\n");
214 size_t len = strlen(p);
217 printf(
"Image color format must have 3 characters, %s was supplied.\n", p);
218 printf(
"A .yuv that does not have the expected format, which is\n");
219 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
220 printf(
"either 444, 422, or 420\n");
226 if (strcmp(p,
"444") == 0)
231 else if (strcmp(p,
"422") == 0)
235 downsampling[1].
x = downsampling[2].
x = 2;
237 else if (strcmp(p,
"420") == 0)
241 downsampling[1].
x = downsampling[2].
x = 2;
242 downsampling[1].
y = downsampling[2].
y = 2;
244 else if (strcmp(p,
"400") == 0)
250 printf(
"Unknown image color format, %s.\n", p);
255 ptrdiff_t cpy_len = name_end - filename > 2047 ? 2047 : name_end - filename;
256 strncpy(name_buf, filename, (
size_t)cpy_len);
257 name_buf[cpy_len] = 0;
260 ui32 depths[3] = {bit_depth, bit_depth, bit_depth};
265 img.
init(num_comps, s.
w, s.
h, bit_depth,
false, format);
267 size_t w = calc_aligned_size<si32, byte_alignment>(s.
w);
270 line.
wrap(buffer, w, 0);
272 for (
ui32 c = 0; c < num_comps; ++c)
276 for (
ui32 h = 0; h < height; ++h)
279 memcpy(p, line.
i32, w *
sizeof(
si32));
289 const char *p = strchr(filename,
':');
290 if (p != NULL && p - filename >= 5 && p[-5] ==
'.' &&
291 toupper(p[-4]) ==
'R' && toupper(p[-3])==
'A' &&
292 toupper(p[-2]) ==
'W' && toupper(p[-1]) ==
'L')
299 const char *p = strchr(filename,
':');
300 const char *name_end = p;
302 printf(
"A .rawl that does not have the expected format, which is\n");
303 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
311 printf(
"Expecting image height.\n");
312 printf(
"A .rawl that does not have the expected format, which is\n");
313 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
320 printf(
"Expecting image bitdepth.\n");
321 printf(
"A .rawl that does not have the expected format, which is\n");
322 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
329 printf(
"Expecting signedness information (either 0 or 1).\n");
330 printf(
"A .rawl that does not have the expected format, which is\n");
331 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp, where num_comp is\n");
332 printf(
"either 1 or 3\n");
336 bool is_signed = *p !=
'0';
339 printf(
"Expecting number of components.\n");
340 printf(
"A .rawl that does not have the expected format, which is\n");
341 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp, where num_comp is\n");
342 printf(
"either 1 or 3\n");
347 if (num_comps != 1 && num_comps != 3)
349 printf(
"num_comp must be either 1 or 3, %s was supplied.\n", p);
350 printf(
"A .rawl that does not have the expected format, which is\n");
351 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp, where format is\n");
352 printf(
"either 1 or 3\n");
357 ptrdiff_t cpy_len = name_end - filename > 2047 ? 2047 : name_end - filename;
358 strncpy(name_buf, filename, (
size_t)cpy_len);
359 name_buf[cpy_len] = 0;
371 FILE *f = fopen(name_buf,
"rb");
373 printf(
"Error opening file %s\n", name_buf);
377 for (
ui32 i = 0; i < num_comps; ++i)
381 if (fread(buffer, 1, s.
w * s.
h, f) != s.
w * s.
h) {
382 printf(
"Error reading from file %s\n", name_buf);
385 for (
ui32 j = s.
w * s.
h; j > 0; --j)
391 else if (bit_depth <= 16)
394 FILE *f = fopen(name_buf,
"rb");
396 printf(
"Error opening file %s\n", name_buf);
400 for (
ui32 i = 0; i < num_comps; ++i)
404 if (fread(buffer, 2, s.
w * s.
h, f) != s.
w * s.
h) {
405 printf(
"Error reading from file %s\n", name_buf);
408 for (
ui32 j = s.
w * s.
h; j > 0; --j)
417 FILE *f = fopen(name_buf,
"rb");
419 printf(
"Error opening file %s\n", name_buf);
423 for (
ui32 i = 0; i < num_comps; ++i)
427 if (fread(buffer, 4, s.
w * s.
h, f) != s.
w * s.
h) {
428 printf(
"Error reading from file %s\n", name_buf);
431 for (
ui32 j = s.
w * s.
h; j > 0; --j)
443 FILE *f = fopen(name_buf,
"rb");
445 printf(
"Error opening file %s\n", name_buf);
449 for (
ui32 i = 0; i < num_comps; ++i)
453 if (fread(buffer, 1, s.
w * s.
h, f) != s.
w * s.
h) {
454 printf(
"Error reading from file %s\n", name_buf);
457 for (
ui32 j = s.
w * s.
h; j > 0; --j)
463 else if (bit_depth <= 16)
466 FILE *f = fopen(name_buf,
"rb");
468 printf(
"Error opening file %s\n", name_buf);
472 for (
ui32 i = 0; i < num_comps; ++i)
476 if (fread(buffer, 2, s.
w * s.
h, f) != s.
w * s.
h) {
477 printf(
"Error reading from file %s\n", name_buf);
480 for (
ui32 j = s.
w * s.
h; j > 0; --j)
489 FILE *f = fopen(name_buf,
"rb");
491 printf(
"Error opening file %s\n", name_buf);
495 for (
ui32 i = 0; i < num_comps; ++i)
499 if (fread(buffer, 4, s.
w * s.
h, f) != s.
w * s.
h) {
500 printf(
"Error reading from file %s\n", name_buf);
503 for (
ui32 j = s.
w * s.
h; j > 0; --j)
513 float mse[3],
ui32 pae[3])
519 printf(
"Error: mismatching images\n");
530 for (
ui32 v = 0; v < h; ++v)
534 for (
ui32 s = 0; s < w; ++s)
536 si32 err = *p0++ - *p1++;
537 ui32 ae = (
ui32)(err > 0 ? err : -err);
538 lpae = ae > lpae ? ae : lpae;
539 se += (double)err * (
double)err;
543 for (
ui32 v = 0; v < h; ++v)
547 for (
ui32 s = 0; s < w; ++s)
551 ui32 err = a > b ? a - b : b - a;
552 lpae = err > lpae ? err : lpae;
553 se += (double)err * (
double)err;
556 mse[c] = (float)se / (
float)(w * h);
562 float mse[3],
ui32 pae[3])
568 printf(
"Error: mismatching images\n");
580 for (
ui32 v = 0; v < h; ++v)
584 for (
ui32 s = 0; s < w; ++s)
588 a = (a >= 0) ? a : (- a - bias);
589 b = (b >= 0) ? b : (- b - bias);
590 ui32 err = (
ui32)(a > b ? a - b : b - a);
591 lpae = err > lpae ? err : lpae;
592 se += (double)err * (
double)err;
595 mse[c] = (float)se / (
float)(w * h);
606 for (
ui32 v = 0; v < h; ++v)
610 for (
ui32 s = 0; s < w; ++s)
614 ui32 err = a > b ? a - b : b - a;
615 lpae = err > lpae ? err : lpae;
616 se += (double)err * (
double)err;
619 mse[c] = (float)se / (
float)(w * h);
624int main(
int argc,
char *argv[])
628 printf(
"mse_pae expects two arguments <filename1, filename2>\n");
629 printf(
"A third optional argment is \"-nlt\".\n");
636 if (strcmp(
"-nlt", argv[3]) == 0)
639 printf(
"unknown 4th parameter %s\n", argv[3]);
654 printf(
"mse_pae does not know file format of %s\n", argv[1]);
655 printf(
"or a .yuv that does not have the expected format, which is\n");
656 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
657 printf(
"either 444, 422, or 420, or wrongly format .rawl, which has\n");
658 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp format.\n");
662 catch (
const std::exception& e)
664 const char *p = e.what();
665 if (strncmp(p,
"ojph error", 10) != 0)
678 printf(
"mse_pae does not know file format of %s\n", argv[2]);
679 printf(
"or a .yuv that does not have the expected format, which is\n");
680 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
681 printf(
"either 444, 422, or 420, or wrongly format .rawl, which has\n");
682 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp format.\n");
686 catch (
const std::exception& e)
688 const char *p = e.what();
689 if (strncmp(p,
"ojph error", 10) != 0)
694 float mse[3];
ui32 pae[3];
701 printf(
"%f %d\n", mse[c], pae[c]);
void wrap(T *buffer, size_t num_ele, ui32 pre_size)
void open(const char *filename)
ui32 get_num_components()
void set_planar(bool planar)
ui32 get_bit_depth(ui32 comp_num)
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[])
void find_nlt_mse_pae(const img_info &img1, const img_info &img2, float mse[3], ui32 pae[3])
bool is_yuv(const char *filename)
void load_rawl(const char *filename, img_info &img)
bool is_rawl(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 bit_depth, bool is_signed, ui32 format=FORMAT444)