OpenJPH: /build/openjph/src/OpenJPH/tests/mse_pae.cpp Source File

OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
mse_pae.cpp
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2019, Aous Naman
6// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2019, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the testing routines for the OpenJPH software
33// implementation.
34// File: mse_pae.cpp
35// Author: Aous Naman
36// Date: 18 March 2021
37//***************************************************************************/
38
39#include <cstdio>
40#include <cstdlib>
41#include <stdexcept>
42#include <cctype>
43
44#include "ojph_arch.h"
45#include "ojph_img_io.h"
46#include "ojph_mem.h"
47
48using namespace ojph;
49using namespace std;
50
51enum : ui32 {
52 UNDEFINED = 0,
53 FORMAT444 = 1,
54 FORMAT422 = 2,
55 FORMAT420 = 3,
56 FORMAT400 = 4,
57};
58
59 struct img_info {
60 img_info() {
61 num_comps = 0;
62 width = height = 0;
63 comps[0] = comps[1] = comps[2] = 0;
64 format = UNDEFINED;
65 bit_depth = 0;
66 is_signed = false;
67 }
68 ~img_info() {
69 for (ui32 i = 0; i < num_comps; ++i)
70 {
71 if (comps[i]) delete[] comps[i];
72 comps[i] = NULL;
73 }
74 }
75
76 void init(ui32 num_comps, size_t width, size_t height, ui32 bit_depth,
77 bool is_signed, ui32 format=FORMAT444)
78 {
79 assert(num_comps <= 3 && comps[0] == NULL);
80 this->num_comps = num_comps;
81 this->width = width;
82 this->height = height;
83 this->format = format;
84 this->bit_depth = bit_depth;
85 this->is_signed = is_signed;
86 for (ui32 i = 0; i < num_comps; ++i)
87 switch (format)
88 {
89 case FORMAT444:
90 case FORMAT400:
91 downsampling[i].x = downsampling[i].y = 1;
92 break;
93 case FORMAT422:
94 downsampling[i].x = i == 0 ? 1 : 2;
95 downsampling[i].y = 1;
96 break;
97 case FORMAT420:
98 downsampling[i].x = i == 0 ? 1 : 2;
99 downsampling[i].y = i == 0 ? 1 : 2;
100 break;
101 default:
102 assert(0);
103 };
104 for (ui32 i = 0; i < num_comps; ++i)
105 {
106 size_t w = (this->width + downsampling[i].x - 1) / downsampling[i].x;
107 size_t h = (this->height + downsampling[i].x - 1) / downsampling[i].x;
108 comps[i] = new si32[w * h];
109 }
110 }
111
112 bool exist() {
113 return comps[0] != NULL;
114 }
115
116 ui32 num_comps;
117 size_t width, height;
118 point downsampling[3];
119 si32 *comps[3];
120 ui32 format;
121 ui32 bit_depth;
122 bool is_signed;
123};
124
125 bool is_pnm(const char *filename)
126{
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')
132 return true;
133 return false;
134}
135
136 void load_ppm(const char *filename, img_info& img)
137{
138 ppm_in ppm;
139 ppm.set_planar(true);
140 ppm.open(filename);
141
142 ui32 num_comps = ppm.get_num_components();
143 size_t width = ppm.get_width();
144 size_t height = ppm.get_height();
145 img.init(num_comps, width, height, ppm.get_bit_depth(0), false);
146
147 width = calc_aligned_size<si32, byte_alignment>(width);
148 si32 *buffer = new si32[width];
149 line_buf line;
150 line.wrap(buffer, width, 0);
151
152 for (ui32 c = 0; c < num_comps; ++c)
153 {
154 si32 *p = img.comps[c];
155 for (ui32 h = 0; h < height; ++h)
156 {
157 ui32 w = ppm.read(&line, c);
158 memcpy(p, line.i32, w * sizeof(si32));
159 p += w;
160 }
161 }
162
163 delete[] buffer;
164}
165
166 bool is_yuv(const char *filename)
167{
168 const char *p = strchr(filename, ':'); // p is either NULL or pointing to ':'
169 if (p != NULL && p - filename >= 4 && p[-4] == '.' &&
170 toupper(p[-3]) == 'Y' && toupper(p[-2])== 'U' && toupper(p[-1]) == 'V')
171 return true;
172 return false;
173}
174
175 void load_yuv(const char *filename, img_info& img)
176{
177 const char *p = strchr(filename, ':'); // p is either NULL or pointing to ':'
178 const char *name_end = p;
179 if (p == NULL) {
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");
183 exit(-1);
184 }
185
186 ojph::size s;
187 s.w = (ui32)atoi(++p);
188 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
189 if (p == NULL) {
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");
194 exit(-1);
195 }
196 s.h = (ui32)atoi(++p);
197 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
198 if (p == NULL) {
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");
203 exit(-1);
204 }
205 ui32 bit_depth = (ui32)atoi(++p);
206 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
207 if (p == NULL) {
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");
212 exit(-1);
213 }
214 // p must be pointing to color subsampling format
215 ++p;
216 size_t len = strlen(p);
217 if (len != 3)
218 {
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");
223 exit(-1);
224 }
225 ui32 num_comps;
226 point downsampling[3] = { point(1,1), point(1,1), point(1,1)};
227 ui32 format;
228 if (strcmp(p, "444") == 0)
229 {
230 num_comps = 3;
231 format = FORMAT444;
232 }
233 else if (strcmp(p, "422") == 0)
234 {
235 num_comps = 3;
236 format = FORMAT422;
237 downsampling[1].x = downsampling[2].x = 2;
238 }
239 else if (strcmp(p, "420") == 0)
240 {
241 num_comps = 3;
242 format = FORMAT420;
243 downsampling[1].x = downsampling[2].x = 2;
244 downsampling[1].y = downsampling[2].y = 2;
245 }
246 else if (strcmp(p, "400") == 0)
247 {
248 num_comps = 1;
249 format = FORMAT400;
250 }
251 else {
252 printf("Unknown image color format, %s.\n", p);
253 exit(-1);
254 }
255
256 char name_buf[2048];
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;
260
261 yuv_in yuv;
262 ui32 depths[3] = {bit_depth, bit_depth, bit_depth};
263 yuv.set_bit_depth(num_comps, depths);
264 yuv.set_img_props(s, num_comps, num_comps, downsampling);
265 yuv.open(name_buf);
266
267 img.init(num_comps, s.w, s.h, bit_depth, false, format);
268
269 size_t w = calc_aligned_size<si32, byte_alignment>(s.w);
270 si32 *buffer = new si32[w];
271 line_buf line;
272 line.wrap(buffer, w, 0);
273
274 for (ui32 c = 0; c < num_comps; ++c)
275 {
276 si32 *p = img.comps[c];
277 ui32 height = (s.h + img.downsampling[c].y - 1) / img.downsampling[c].y;
278 for (ui32 h = 0; h < height; ++h)
279 {
280 ui32 w = yuv.read(&line, c);
281 memcpy(p, line.i32, w * sizeof(si32));
282 p += w;
283 }
284 }
285
286 delete[] buffer;
287}
288
289 bool is_rawl(const char *filename)
290{
291 const char *p = strchr(filename, ':'); // p is either NULL or pointing to ':'
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')
295 return true;
296 return false;
297}
298
299 void load_rawl(const char *filename, img_info& img)
300{
301 const char *p = strchr(filename, ':'); // p is either NULL or pointing to ':'
302 const char *name_end = p;
303 if (p == NULL) {
304 printf("A .rawl that does not have the expected format, which is\n");
305 printf(".rawl:widthxheightxbitdepthxsignedxnum_comp\n");
306 exit(-1);
307 }
308 ojph::size s;
309 ++p;
310 s.w = (ui32)atoi(p);
311 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
312 if (p == NULL) {
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");
316 exit(-1);
317 }
318 ++p;
319 s.h = (ui32)atoi(p);
320 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
321 if (p == NULL) {
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");
325 exit(-1);
326 }
327 ++p;
328 ui32 bit_depth = (ui32)atoi(p);
329 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
330 if (p == NULL) {
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");
335 exit(-1);
336 }
337 ++p;
338 bool is_signed = *p != '0';
339 p = strchr(p, 'x'); // p is either NULL or pointing to ':'
340 if (p == NULL) {
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");
345 exit(-1);
346 }
347 ++p;
348 ui32 num_comps = (ui32)atoi(p);
349 if (num_comps != 1 && num_comps != 3)
350 {
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");
355 exit(-1);
356 }
357
358 char name_buf[2048];
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;
362
363 if (num_comps == 3)
364 img.init(num_comps, s.w, s.h, bit_depth, is_signed, FORMAT444);
365 else
366 img.init(num_comps, s.w, s.h, bit_depth, is_signed, FORMAT400);
367
368 if (is_signed)
369 {
370 if (bit_depth <= 8)
371 {
372 si8 *buffer = new si8[s.w * s.h];
373 FILE *f = fopen(name_buf, "rb");
374 if (f == NULL) {
375 printf("Error opening file %s\n", name_buf);
376 exit(-1);
377 }
378
379 for (ui32 i = 0; i < num_comps; ++i)
380 {
381 si8 *sp = buffer;
382 si32 *dp = img.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);
385 exit(-1);
386 }
387 for (ui32 j = s.w * s.h; j > 0; --j)
388 *dp++ = *sp++;
389 }
390 fclose(f);
391 delete[] buffer;
392 }
393 else if (bit_depth <= 16)
394 {
395 si16 *buffer = new si16[s.w * s.h];
396 FILE *f = fopen(name_buf, "rb");
397 if (f == NULL) {
398 printf("Error opening file %s\n", name_buf);
399 exit(-1);
400 }
401
402 for (ui32 i = 0; i < num_comps; ++i)
403 {
404 si16 *sp = buffer;
405 si32 *dp = img.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);
408 exit(-1);
409 }
410 for (ui32 j = s.w * s.h; j > 0; --j) {
411 si16 v = *sp++;
412 *dp++ = (si16)swap_bytes_if_be((ui16)v);
413 }
414 }
415 fclose(f);
416 delete[] buffer;
417 }
418 else
419 {
420 si32 *buffer = new si32[s.w * s.h];
421 FILE *f = fopen(name_buf, "rb");
422 if (f == NULL) {
423 printf("Error opening file %s\n", name_buf);
424 exit(-1);
425 }
426
427 for (ui32 i = 0; i < num_comps; ++i)
428 {
429 si32 *sp = buffer;
430 si32 *dp = img.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);
433 exit(-1);
434 }
435 for (ui32 j = s.w * s.h; j > 0; --j) {
436 si32 v = *sp++;
437 *dp++ = (si32)swap_bytes_if_be((ui32)v);
438 }
439 }
440 fclose(f);
441 delete[] buffer;
442 }
443 }
444 else
445 {
446 if (bit_depth <= 8)
447 {
448 ui8 *buffer = new ui8[s.w * s.h];
449 FILE *f = fopen(name_buf, "rb");
450 if (f == NULL) {
451 printf("Error opening file %s\n", name_buf);
452 exit(-1);
453 }
454
455 for (ui32 i = 0; i < num_comps; ++i)
456 {
457 ui8 *sp = buffer;
458 si32 *dp = img.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);
461 exit(-1);
462 }
463 for (ui32 j = s.w * s.h; j > 0; --j)
464 *dp++ = *sp++;
465 }
466 fclose(f);
467 delete[] buffer;
468 }
469 else if (bit_depth <= 16)
470 {
471 ui16 *buffer = new ui16[s.w * s.h];
472 FILE *f = fopen(name_buf, "rb");
473 if (f == NULL) {
474 printf("Error opening file %s\n", name_buf);
475 exit(-1);
476 }
477
478 for (ui32 i = 0; i < num_comps; ++i)
479 {
480 ui16 *sp = buffer;
481 si32 *dp = img.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);
484 exit(-1);
485 }
486 for (ui32 j = s.w * s.h; j > 0; --j) {
487 ui16 v = *sp++;
488 *dp++ = (si32)swap_bytes_if_be(v);
489 }
490 }
491 fclose(f);
492 delete[] buffer;
493 }
494 else
495 {
496 ui32 *buffer = new ui32[s.w * s.h];
497 FILE *f = fopen(name_buf, "rb");
498 if (f == NULL) {
499 printf("Error opening file %s\n", name_buf);
500 exit(-1);
501 }
502
503 for (ui32 i = 0; i < num_comps; ++i)
504 {
505 ui32 *sp = buffer;
506 si32 *dp = img.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);
509 exit(-1);
510 }
511 for (ui32 j = s.w * s.h; j > 0; --j) {
512 ui32 v = *sp++;
513 *dp++ = (si32)swap_bytes_if_be(v);
514 }
515 }
516 fclose(f);
517 delete[] buffer;
518 }
519 }
520}
521
522 void find_mse_pae(const img_info& img1, const img_info& img2,
523 float mse[3], ui32 pae[3])
524{
525 if (img1.num_comps != img2.num_comps || img1.format != img2.format ||
526 img1.width != img2.width || img1.height != img2.height ||
527 img1.bit_depth != img2.bit_depth || img1.is_signed != img2.is_signed)
528 {
529 printf("Error: mismatching images\n");
530 exit(-1);
531 }
532 for (ui32 c = 0; c < img1.num_comps; ++c)
533 {
534 size_t w, h;
535 w = (img1.width + img1.downsampling[c].x - 1) / img1.downsampling[c].x;
536 h = (img1.height + img1.downsampling[c].x - 1) / img1.downsampling[c].x;
537 double se = 0;
538 ui32 lpae = 0;
539 if (img1.is_signed)
540 for (ui32 v = 0; v < h; ++v)
541 {
542 si32 *p0 = img1.comps[c] + w * v;
543 si32 *p1 = img2.comps[c] + w * v;
544 for (ui32 s = 0; s < w; ++s)
545 {
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;
550 }
551 }
552 else
553 for (ui32 v = 0; v < h; ++v)
554 {
555 ui32 *p0 = (ui32*)img1.comps[c] + w * v;
556 ui32 *p1 = (ui32*)img2.comps[c] + w * v;
557 for (ui32 s = 0; s < w; ++s)
558 {
559 ui32 a = *p0++;
560 ui32 b = *p1++;
561 ui32 err = a > b ? a - b : b - a;
562 lpae = err > lpae ? err : lpae;
563 se += (double)err * (double)err;
564 }
565 }
566 mse[c] = (float)se / (float)(w * h);
567 pae[c] = lpae;
568 }
569}
570
571 void find_nlt_mse_pae(const img_info& img1, const img_info& img2,
572 float mse[3], ui32 pae[3])
573{
574 if (img1.num_comps != img2.num_comps || img1.format != img2.format ||
575 img1.width != img2.width || img1.height != img2.height ||
576 img1.bit_depth != img2.bit_depth || img1.is_signed != img2.is_signed)
577 {
578 printf("Error: mismatching images\n");
579 exit(-1);
580 }
581 if (img1.is_signed)
582 for (ui32 c = 0; c < img1.num_comps; ++c)
583 {
584 size_t w, h;
585 w = (img1.width + img1.downsampling[c].x - 1) / img1.downsampling[c].x;
586 h = (img1.height + img1.downsampling[c].x - 1) / img1.downsampling[c].x;
587 double se = 0;
588 ui32 lpae = 0;
589 si32 bias = (si32)((1ULL << (img1.bit_depth - 1)) + 1);
590 for (ui32 v = 0; v < h; ++v)
591 {
592 si32 *p0 = img1.comps[c] + w * v;
593 si32 *p1 = img2.comps[c] + w * v;
594 for (ui32 s = 0; s < w; ++s)
595 {
596 si32 a = *p0++;
597 si32 b = *p1++;
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;
603 }
604 }
605 mse[c] = (float)se / (float)(w * h);
606 pae[c] = lpae;
607 }
608 else
609 for (ui32 c = 0; c < img1.num_comps; ++c)
610 {
611 size_t w, h;
612 w = (img1.width + img1.downsampling[c].x - 1) / img1.downsampling[c].x;
613 h = (img1.height + img1.downsampling[c].x - 1) / img1.downsampling[c].x;
614 double se = 0;
615 ui32 lpae = 0;
616 for (ui32 v = 0; v < h; ++v)
617 {
618 ui32 *p0 = (ui32*)img1.comps[c] + w * v;
619 ui32 *p1 = (ui32*)img2.comps[c] + w * v;
620 for (ui32 s = 0; s < w; ++s)
621 {
622 ui32 a = *p0++;
623 ui32 b = *p1++;
624 ui32 err = a > b ? a - b : b - a;
625 lpae = err > lpae ? err : lpae;
626 se += (double)err * (double)err;
627 }
628 }
629 mse[c] = (float)se / (float)(w * h);
630 pae[c] = lpae;
631 }
632}
633
634 int main(int argc, char *argv[])
635{
636 if (argc < 3)
637 {
638 printf("mse_pae expects two arguments <filename1, filename2>\n");
639 printf("A third optional argment is \"-nlt\".\n");
640 exit(-1);
641 }
642
643 bool nlt = false;
644 if (argc == 4)
645 {
646 if (strcmp("-nlt", argv[3]) == 0)
647 nlt = true;
648 else {
649 printf("unknown 4th parameter %s\n", argv[3]);
650 exit(-1);
651 }
652 }
653
654
655 img_info img1, img2;
656 try {
657 if (is_pnm(argv[1]))
658 load_ppm(argv[1], img1);
659 else if (is_yuv(argv[1]))
660 load_yuv(argv[1], img1);
661 else if (is_rawl(argv[1]))
662 load_rawl(argv[1], img1);
663 else {
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");
669 exit(-1);
670 }
671 }
672 catch (const std::exception& e)
673 {
674 const char *p = e.what();
675 if (strncmp(p, "ojph error", 10) != 0)
676 printf("%s\n", p);
677 exit(-1);
678 }
679
680 try {
681 if (is_pnm(argv[2]))
682 load_ppm(argv[2], img2);
683 else if (is_yuv(argv[2]))
684 load_yuv(argv[2], img2);
685 else if (is_rawl(argv[2]))
686 load_rawl(argv[2], img2);
687 else {
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");
693 exit(-1);
694 }
695 }
696 catch (const std::exception& e)
697 {
698 const char *p = e.what();
699 if (strncmp(p, "ojph error", 10) != 0)
700 printf("%s\n", p);
701 exit(-1);
702 }
703
704 float mse[3]; ui32 pae[3];
705 if (!nlt)
706 find_mse_pae(img1, img2, mse, pae);
707 else
708 find_nlt_mse_pae(img1, img2, mse, pae);
709
710 for (ui32 c = 0; c < img1.num_comps; ++c)
711 printf("%f %d\n", mse[c], pae[c]);
712
713 return 0;
714}
715
716
ojph::line_buf
Definition ojph_mem.h:161
ojph::line_buf::wrap
void wrap(T *buffer, size_t num_ele, ui32 pre_size)
ojph::line_buf::i32
si32 * i32
Definition ojph_mem.h:185
ojph::ppm_in
Definition ojph_img_io.h:82
ojph::ppm_in::get_height
ui32 get_height()
Definition ojph_img_io.h:117
ojph::ppm_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:245
ojph::ppm_in::get_num_components
ui32 get_num_components()
Definition ojph_img_io.h:119
ojph::ppm_in::set_planar
void set_planar(bool planar)
Definition ojph_img_io.h:113
ojph::ppm_in::get_width
ui32 get_width()
Definition ojph_img_io.h:116
ojph::ppm_in::get_bit_depth
ui32 get_bit_depth(ui32 comp_num)
Definition ojph_img_io.h:120
ojph::ppm_in::read
virtual ui32 read(const line_buf *line, ui32 comp_num)
Definition ojph_img_io.cpp:338
ojph::yuv_in
Definition ojph_img_io.h:348
ojph::yuv_in::read
virtual ui32 read(const line_buf *line, ui32 comp_num)
Definition ojph_img_io.cpp:1350
ojph::yuv_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:1325
ojph::yuv_in::set_img_props
void set_img_props(const size &s, ui32 num_components, ui32 num_downsampling, const point *downsampling)
Definition ojph_img_io.cpp:1381
ojph::yuv_in::set_bit_depth
void set_bit_depth(ui32 num_bit_depths, ui32 *bit_depth)
Definition ojph_img_io.cpp:1408
find_mse_pae
void find_mse_pae(const img_info &img1, const img_info &img2, float mse[3], ui32 pae[3])
Definition mse_pae.cpp:522
main
int main(int argc, char *argv[])
Definition mse_pae.cpp:634
find_nlt_mse_pae
void find_nlt_mse_pae(const img_info &img1, const img_info &img2, float mse[3], ui32 pae[3])
Definition mse_pae.cpp:571
is_yuv
bool is_yuv(const char *filename)
Definition mse_pae.cpp:166
load_rawl
void load_rawl(const char *filename, img_info &img)
Definition mse_pae.cpp:299
FORMAT444
@ FORMAT444
Definition mse_pae.cpp:53
UNDEFINED
@ UNDEFINED
Definition mse_pae.cpp:52
FORMAT400
@ FORMAT400
Definition mse_pae.cpp:56
FORMAT420
@ FORMAT420
Definition mse_pae.cpp:55
FORMAT422
@ FORMAT422
Definition mse_pae.cpp:54
is_rawl
bool is_rawl(const char *filename)
Definition mse_pae.cpp:289
is_pnm
bool is_pnm(const char *filename)
Definition mse_pae.cpp:125
load_ppm
void load_ppm(const char *filename, img_info &img)
Definition mse_pae.cpp:136
load_yuv
void load_yuv(const char *filename, img_info &img)
Definition mse_pae.cpp:175
ojph
Definition ojph_img_io.h:52
ojph::si8
int8_t si8
Definition ojph_defs.h:51
ojph::calc_aligned_size
size_t calc_aligned_size(size_t size)
Definition ojph_arch.h:360
ojph::ui16
uint16_t ui16
Definition ojph_defs.h:52
ojph::swap_bytes_if_be
static ui16 swap_bytes_if_be(ui16 t)
Definition ojph_arch.h:405
ojph::si32
int32_t si32
Definition ojph_defs.h:55
ojph::si16
int16_t si16
Definition ojph_defs.h:53
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph::ui8
uint8_t ui8
Definition ojph_defs.h:50
ojph_arch.h
ojph_img_io.h
ojph_mem.h
img_info
Definition mse_pae.cpp:59
img_info::height
size_t height
Definition mse_pae.cpp:117
img_info::img_info
img_info()
Definition mse_pae.cpp:60
img_info::init
void init(ui32 num_comps, size_t width, size_t height, ui32 bit_depth, bool is_signed, ui32 format=FORMAT444)
Definition mse_pae.cpp:76
img_info::comps
si32 * comps[3]
Definition mse_pae.cpp:119
img_info::~img_info
~img_info()
Definition mse_pae.cpp:68
img_info::downsampling
point downsampling[3]
Definition mse_pae.cpp:118
img_info::is_signed
bool is_signed
Definition mse_pae.cpp:122
img_info::num_comps
ui32 num_comps
Definition mse_pae.cpp:116
img_info::exist
bool exist()
Definition mse_pae.cpp:112
img_info::format
ui32 format
Definition mse_pae.cpp:120
img_info::bit_depth
ui32 bit_depth
Definition mse_pae.cpp:121
img_info::width
size_t width
Definition mse_pae.cpp:117
ojph::point
Definition ojph_base.h:58
ojph::point::y
ui32 y
Definition ojph_base.h:60
ojph::point::x
ui32 x
Definition ojph_base.h:60
ojph::size
Definition ojph_base.h:48
ojph::size::w
ui32 w
Definition ojph_base.h:50
ojph::size::h
ui32 h
Definition ojph_base.h:51