113 return comps[0] != NULL;
127 size_t len = strlen(filename);
128 if (len >= 4 && filename[len - 4] ==
'.' &&
129 toupper(filename[len - 3]) ==
'P' &&
130 (toupper(filename[len - 2])==
'P' || toupper(filename[len - 2]) ==
'G') &&
131 toupper(filename[len - 1]) ==
'M')
150 line.
wrap(buffer, width, 0);
152 for (
ui32 c = 0; c < num_comps; ++c)
155 for (
ui32 h = 0; h < height; ++h)
158 memcpy(p, line.
i32, w *
sizeof(
si32));
168 const char *p = strchr(filename,
':');
169 if (p != NULL && p - filename >= 4 && p[-4] ==
'.' &&
170 toupper(p[-3]) ==
'Y' && toupper(p[-2])==
'U' && toupper(p[-1]) ==
'V')
177 const char *p = strchr(filename,
':');
178 const char *name_end = p;
180 printf(
"A .yuv that does not have the expected format, which is\n");
181 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
182 printf(
"either 444, 422, or 420\n");
187 s.
w = (
ui32)atoi(++p);
190 printf(
"Expecting image height.\n");
191 printf(
"A .yuv that does not have the expected format, which is\n");
192 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
193 printf(
"either 444, 422, or 420\n");
196 s.
h = (
ui32)atoi(++p);
199 printf(
"Expecting image bitdepth.\n");
200 printf(
"A .yuv that does not have the expected format, which is\n");
201 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
202 printf(
"either 444, 422, or 420\n");
208 printf(
"Expecting color subsampling format.\n");
209 printf(
"A .yuv that does not have the expected format, which is\n");
210 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
211 printf(
"either 444, 422, or 420\n");
216 size_t len = strlen(p);
219 printf(
"Image color format must have 3 characters, %s was supplied.\n", p);
220 printf(
"A .yuv that does not have the expected format, which is\n");
221 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
222 printf(
"either 444, 422, or 420\n");
228 if (strcmp(p,
"444") == 0)
233 else if (strcmp(p,
"422") == 0)
237 downsampling[1].
x = downsampling[2].
x = 2;
239 else if (strcmp(p,
"420") == 0)
243 downsampling[1].
x = downsampling[2].
x = 2;
244 downsampling[1].
y = downsampling[2].
y = 2;
246 else if (strcmp(p,
"400") == 0)
252 printf(
"Unknown image color format, %s.\n", p);
257 ptrdiff_t cpy_len = name_end - filename > 2047 ? 2047 : name_end - filename;
258 strncpy(name_buf, filename, (
size_t)cpy_len);
259 name_buf[cpy_len] = 0;
262 ui32 depths[3] = {bit_depth, bit_depth, bit_depth};
267 img.
init(num_comps, s.
w, s.
h, bit_depth,
false, format);
272 line.
wrap(buffer, w, 0);
274 for (
ui32 c = 0; c < num_comps; ++c)
278 for (
ui32 h = 0; h < height; ++h)
281 memcpy(p, line.
i32, w *
sizeof(
si32));
291 const char *p = strchr(filename,
':');
292 if (p != NULL && p - filename >= 5 && p[-5] ==
'.' &&
293 toupper(p[-4]) ==
'R' && toupper(p[-3])==
'A' &&
294 toupper(p[-2]) ==
'W' && toupper(p[-1]) ==
'L')
301 const char *p = strchr(filename,
':');
302 const char *name_end = p;
304 printf(
"A .rawl that does not have the expected format, which is\n");
305 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
313 printf(
"Expecting image height.\n");
314 printf(
"A .rawl that does not have the expected format, which is\n");
315 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
322 printf(
"Expecting image bitdepth.\n");
323 printf(
"A .rawl that does not have the expected format, which is\n");
324 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
331 printf(
"Expecting signedness information (either 0 or 1).\n");
332 printf(
"A .rawl that does not have the expected format, which is\n");
333 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp, where num_comp is\n");
334 printf(
"either 1 or 3\n");
338 bool is_signed = *p !=
'0';
341 printf(
"Expecting number of components.\n");
342 printf(
"A .rawl that does not have the expected format, which is\n");
343 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp, where num_comp is\n");
344 printf(
"either 1 or 3\n");
349 if (num_comps != 1 && num_comps != 3)
351 printf(
"num_comp must be either 1 or 3, %s was supplied.\n", p);
352 printf(
"A .rawl that does not have the expected format, which is\n");
353 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp, where format is\n");
354 printf(
"either 1 or 3\n");
359 ptrdiff_t cpy_len = name_end - filename > 2047 ? 2047 : name_end - filename;
360 strncpy(name_buf, filename, (
size_t)cpy_len);
361 name_buf[cpy_len] = 0;
373 FILE *f = fopen(name_buf,
"rb");
375 printf(
"Error opening file %s\n", name_buf);
379 for (
ui32 i = 0; i < num_comps; ++i)
383 if (fread(buffer, 1, s.
w * s.
h, f) != s.
w * s.
h) {
384 printf(
"Error reading from file %s\n", name_buf);
387 for (
ui32 j = s.
w * s.
h; j > 0; --j)
393 else if (bit_depth <= 16)
396 FILE *f = fopen(name_buf,
"rb");
398 printf(
"Error opening file %s\n", name_buf);
402 for (
ui32 i = 0; i < num_comps; ++i)
406 if (fread(buffer, 2, s.
w * s.
h, f) != s.
w * s.
h) {
407 printf(
"Error reading from file %s\n", name_buf);
410 for (
ui32 j = s.
w * s.
h; j > 0; --j) {
421 FILE *f = fopen(name_buf,
"rb");
423 printf(
"Error opening file %s\n", name_buf);
427 for (
ui32 i = 0; i < num_comps; ++i)
431 if (fread(buffer, 4, s.
w * s.
h, f) != s.
w * s.
h) {
432 printf(
"Error reading from file %s\n", name_buf);
435 for (
ui32 j = s.
w * s.
h; j > 0; --j) {
449 FILE *f = fopen(name_buf,
"rb");
451 printf(
"Error opening file %s\n", name_buf);
455 for (
ui32 i = 0; i < num_comps; ++i)
459 if (fread(buffer, 1, s.
w * s.
h, f) != s.
w * s.
h) {
460 printf(
"Error reading from file %s\n", name_buf);
463 for (
ui32 j = s.
w * s.
h; j > 0; --j)
469 else if (bit_depth <= 16)
472 FILE *f = fopen(name_buf,
"rb");
474 printf(
"Error opening file %s\n", name_buf);
478 for (
ui32 i = 0; i < num_comps; ++i)
482 if (fread(buffer, 2, s.
w * s.
h, f) != s.
w * s.
h) {
483 printf(
"Error reading from file %s\n", name_buf);
486 for (
ui32 j = s.
w * s.
h; j > 0; --j) {
497 FILE *f = fopen(name_buf,
"rb");
499 printf(
"Error opening file %s\n", name_buf);
503 for (
ui32 i = 0; i < num_comps; ++i)
507 if (fread(buffer, 4, s.
w * s.
h, f) != s.
w * s.
h) {
508 printf(
"Error reading from file %s\n", name_buf);
511 for (
ui32 j = s.
w * s.
h; j > 0; --j) {
523 float mse[3],
ui32 pae[3])
529 printf(
"Error: mismatching images\n");
540 for (
ui32 v = 0; v < h; ++v)
544 for (
ui32 s = 0; s < w; ++s)
546 si32 err = *p0++ - *p1++;
547 ui32 ae = (
ui32)(err > 0 ? err : -err);
548 lpae = ae > lpae ? ae : lpae;
549 se += (double)err * (
double)err;
553 for (
ui32 v = 0; v < h; ++v)
557 for (
ui32 s = 0; s < w; ++s)
561 ui32 err = a > b ? a - b : b - a;
562 lpae = err > lpae ? err : lpae;
563 se += (double)err * (
double)err;
566 mse[c] = (float)se / (
float)(w * h);
572 float mse[3],
ui32 pae[3])
578 printf(
"Error: mismatching images\n");
590 for (
ui32 v = 0; v < h; ++v)
594 for (
ui32 s = 0; s < w; ++s)
598 a = (a >= 0) ? a : (- a - bias);
599 b = (b >= 0) ? b : (- b - bias);
600 ui32 err = (
ui32)(a > b ? a - b : b - a);
601 lpae = err > lpae ? err : lpae;
602 se += (double)err * (
double)err;
605 mse[c] = (float)se / (
float)(w * h);
616 for (
ui32 v = 0; v < h; ++v)
620 for (
ui32 s = 0; s < w; ++s)
624 ui32 err = a > b ? a - b : b - a;
625 lpae = err > lpae ? err : lpae;
626 se += (double)err * (
double)err;
629 mse[c] = (float)se / (
float)(w * h);
634int main(
int argc,
char *argv[])
638 printf(
"mse_pae expects two arguments <filename1, filename2>\n");
639 printf(
"A third optional argment is \"-nlt\".\n");
646 if (strcmp(
"-nlt", argv[3]) == 0)
649 printf(
"unknown 4th parameter %s\n", argv[3]);
664 printf(
"mse_pae does not know file format of %s\n", argv[1]);
665 printf(
"or a .yuv that does not have the expected format, which is\n");
666 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
667 printf(
"either 444, 422, or 420, or wrongly format .rawl, which has\n");
668 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp format.\n");
672 catch (
const std::exception& e)
674 const char *p = e.what();
675 if (strncmp(p,
"ojph error", 10) != 0)
688 printf(
"mse_pae does not know file format of %s\n", argv[2]);
689 printf(
"or a .yuv that does not have the expected format, which is\n");
690 printf(
".yuv:widthxheightxbitdepthxformat, where format is\n");
691 printf(
"either 444, 422, or 420, or wrongly format .rawl, which has\n");
692 printf(
".rawl:widthxheightxbitdepthxsignedxnum_comp format.\n");
696 catch (
const std::exception& e)
698 const char *p = e.what();
699 if (strncmp(p,
"ojph error", 10) != 0)
704 float mse[3];
ui32 pae[3];
711 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)
size_t calc_aligned_size(size_t size)
static ui16 swap_bytes_if_be(ui16 t)
void init(ui32 num_comps, size_t width, size_t height, ui32 bit_depth, bool is_signed, ui32 format=FORMAT444)