38#define _USE_MATH_DEFINES
94 ui32 bit_depth,
bool is_signed)
170 if (num_decompositions > 32)
172 "maximum number of decompositions cannot exceed 32");
181 if (width == 0 || width != (1u << log_width)
182 || height == 0 || height != (1u << log_height)
183 || log_width < 2 || log_height < 2
184 || log_width + log_height > 12)
185 OJPH_ERROR(0x00050011,
"incorrect code block dimensions");
193 if (num_levels == 0 || precinct_size == NULL)
200 size t = precinct_size[i < num_levels ? i : num_levels - 1];
204 if (t.
w == 0 || t.
h == 0)
205 OJPH_ERROR(0x00050021,
"precinct width or height cannot be 0");
206 if (t.
w != (1u<<PPx) || t.
h != (1u<<PPy))
208 "precinct width and height should be a power of 2");
209 if (PPx > 15 || PPy > 15)
210 OJPH_ERROR(0x00050023,
"precinct size is too large");
211 if (i > 0 && (PPx == 0 || PPy == 0))
212 OJPH_ERROR(0x00050024,
"precinct size is too small");
222 size_t len = strlen(name);
236 OJPH_ERROR(0x00050031,
"unknown progression order");
239 OJPH_ERROR(0x00050032,
"improper progression order");
399 size_t t = strlen(str);
402 "COM marker string length cannot be larger than 65531");
413 "COM marker string length cannot be larger than 65531");
433 return (
ui16)((t << 8) | (t >> 8));
483 1.4021e+00f, 2.0304e+00f, 2.9012e+00f, 4.1153e+00f, 5.8245e+00f,
484 8.2388e+00f, 1.1652e+01f, 1.6479e+01f, 2.3304e+01f, 3.2957e+01f,
485 4.6609e+01f, 6.5915e+01f, 9.3217e+01f, 1.3183e+02f, 1.8643e+02f,
486 2.6366e+02f, 3.7287e+02f, 5.2732e+02f, 7.4574e+02f, 1.0546e+03f,
487 1.4915e+03f, 2.1093e+03f, 2.9830e+03f, 4.2185e+03f, 5.9659e+03f,
488 8.4371e+03f, 1.1932e+04f, 1.6874e+04f, 2.3864e+04f, 3.3748e+04f,
489 4.7727e+04f, 6.7496e+04f, 9.5454e+04f };
491 1.9669e+00f, 2.8839e+00f, 4.1475e+00f, 5.8946e+00f, 8.3472e+00f,
492 1.1809e+01f, 1.6701e+01f, 2.3620e+01f, 3.3403e+01f, 4.7240e+01f,
493 6.6807e+01f, 9.4479e+01f, 1.3361e+02f, 1.8896e+02f, 2.6723e+02f,
494 3.7792e+02f, 5.3446e+02f, 7.5583e+02f, 1.0689e+03f, 1.5117e+03f,
495 2.1378e+03f, 3.0233e+03f, 4.2756e+03f, 6.0467e+03f, 8.5513e+03f,
496 1.2093e+04f, 1.7103e+04f, 2.4187e+04f, 3.4205e+04f, 4.8373e+04f,
497 6.8410e+04f, 9.6747e+04f, 1.3682e+05f };
499 1.2247e+00f, 1.3229e+00f, 1.5411e+00f, 1.7139e+00f, 1.9605e+00f,
500 2.2044e+00f, 2.5047e+00f, 2.8277e+00f, 3.2049e+00f, 3.6238e+00f,
501 4.1033e+00f, 4.6423e+00f, 5.2548e+00f, 5.9462e+00f, 6.7299e+00f,
502 7.6159e+00f, 8.6193e+00f, 9.7544e+00f, 1.1039e+01f, 1.2493e+01f,
503 1.4139e+01f, 1.6001e+01f, 1.8108e+01f, 2.0493e+01f, 2.3192e+01f,
504 2.6246e+01f, 2.9702e+01f, 3.3614e+01f, 3.8041e+01f, 4.3051e+01f,
505 4.8721e+01f, 5.5138e+01f, 6.2399e+01f };
507 1.3975e+00f, 1.4389e+00f, 1.7287e+00f, 1.8880e+00f, 2.1841e+00f,
508 2.4392e+00f, 2.7830e+00f, 3.1341e+00f, 3.5576e+00f, 4.0188e+00f,
509 4.5532e+00f, 5.1494e+00f, 5.8301e+00f, 6.5963e+00f, 7.4663e+00f,
510 8.4489e+00f, 9.5623e+00f, 1.0821e+01f, 1.2247e+01f, 1.3860e+01f,
511 1.5685e+01f, 1.7751e+01f, 2.0089e+01f, 2.2735e+01f, 2.5729e+01f,
512 2.9117e+01f, 3.2952e+01f, 3.7292e+01f, 4.2203e+01f, 4.7761e+01f,
513 5.4051e+01f, 6.1170e+01f, 6.9226e+01f };
534 1.3328e+00f, 1.3067e+00f, 1.3028e+00f, 1.3001e+00f, 1.2993e+00f,
535 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
536 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
537 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
538 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
539 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
540 1.2992e+00f, 1.2992e+00f };
542 1.2757e+00f, 1.2352e+00f, 1.2312e+00f, 1.2285e+00f, 1.2280e+00f,
543 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
544 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
545 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
546 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
547 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
548 1.2278e+00f, 1.2278e+00f };
550 1.6250e+00f, 1.6875e+00f, 1.6963e+00f, 1.7067e+00f, 1.7116e+00f,
551 1.7129e+00f, 1.7141e+00f, 1.7145e+00f, 1.7151e+00f, 1.7152e+00f,
552 1.7155e+00f, 1.7155e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
553 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
554 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
555 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
556 1.7156e+00f, 1.7156e+00f };
558 2.7500e+00f, 2.8047e+00f, 2.8198e+00f, 2.8410e+00f, 2.8558e+00f,
559 2.8601e+00f, 2.8628e+00f, 2.8656e+00f, 2.8662e+00f, 2.8667e+00f,
560 2.8669e+00f, 2.8670e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
561 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
562 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
563 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
564 2.8671e+00f, 2.8671e+00f };
586 result &= file->
write(&buf, 2) == 2;
588 result &= file->
write(&buf, 2) == 2;
590 result &= file->
write(&buf, 2) == 2;
592 result &= file->
write(&buf, 4) == 4;
594 result &= file->
write(&buf, 4) == 4;
596 result &= file->
write(&buf, 4) == 4;
598 result &= file->
write(&buf, 4) == 4;
600 result &= file->
write(&buf, 4) == 4;
602 result &= file->
write(&buf, 4) == 4;
604 result &= file->
write(&buf, 4) == 4;
606 result &= file->
write(&buf, 4) == 4;
608 result &= file->
write(&buf, 2) == 2;
609 for (
int c = 0; c <
Csiz; ++c)
614 result &= file->
write(&buf, 3) == 3;
624 OJPH_ERROR(0x00050041,
"error reading SIZ marker");
626 int num_comps = (
Lsiz - 38) / 3;
627 if (
Lsiz != 38 + 3 * num_comps)
628 OJPH_ERROR(0x00050042,
"error in SIZ marker length");
630 OJPH_ERROR(0x00050043,
"error reading SIZ marker");
632 if ((
Rsiz & 0x4000) == 0)
634 "Rsiz bit 14 is not set (this is not a JPH file)");
635 if ((
Rsiz & 0x8000) != 0 && (
Rsiz & 0xD5F) != 0)
636 OJPH_WARN(0x00050001,
"Rsiz in SIZ has unimplemented fields");
638 OJPH_ERROR(0x00050045,
"error reading SIZ marker");
641 OJPH_ERROR(0x00050046,
"error reading SIZ marker");
644 OJPH_ERROR(0x00050047,
"error reading SIZ marker");
647 OJPH_ERROR(0x00050048,
"error reading SIZ marker");
650 OJPH_ERROR(0x00050049,
"error reading SIZ marker");
653 OJPH_ERROR(0x0005004A,
"error reading SIZ marker");
656 OJPH_ERROR(0x0005004B,
"error reading SIZ marker");
659 OJPH_ERROR(0x0005004C,
"error reading SIZ marker");
662 OJPH_ERROR(0x0005004D,
"error reading SIZ marker");
664 if (
Csiz != num_comps)
665 OJPH_ERROR(0x0005004E,
"Csiz does not match the SIZ marker size");
673 for (
int c = 0; c <
Csiz; ++c)
676 OJPH_ERROR(0x00050051,
"error reading SIZ marker");
678 OJPH_ERROR(0x00050052,
"error reading SIZ marker");
680 OJPH_ERROR(0x00050053,
"error reading SIZ marker");
735 result &= file->
write(&buf, 2) == 2;
737 result &= file->
write(&buf, 2) == 2;
739 result &= file->
write(&buf, 4) == 4;
742 result &= file->
write(&buf, 2) == 2;
751 OJPH_ERROR(0x00050061,
"error reading CAP marker");
754 OJPH_ERROR(0x00050062,
"error reading CAP marker");
757 if (
Pcap & 0xFFFDFFFF)
759 "error Pcap in CAP has options that are not supported");
760 if ((
Pcap & 0x00020000) == 0)
762 "error Pcap should have its 15th MSB set, Pcap^15. "
763 " This is not a JPH file");
764 for (
ui32 i = 0; i < count; ++i)
766 OJPH_ERROR(0x00050065,
"error reading CAP marker");
767 if (
Lcap != 6 + 2 * count)
768 OJPH_ERROR(0x00050066,
"error in CAP marker length");
789 bit_depth +=
comp_num < 3 ? employing_color_transform : 0;
812 result &= file->
write(&buf, 2) == 2;
814 result &= file->
write(&buf, 2) == 2;
816 result &= file->
write(&buf, 1) == 1;
818 result &= file->
write(&buf, 1) == 1;
820 result &= file->
write(&buf, 2) == 2;
822 result &= file->
write(&buf, 1) == 1;
827 result &= file->
write(&buf, 4) == 4;
829 result &= file->
write(&buf, 1) == 1;
834 result &= file->
write(&buf, 1) == 1;
848 OJPH_ERROR(0x00050071,
"error reading COD segment");
851 OJPH_ERROR(0x00050072,
"error reading COD segment");
853 OJPH_ERROR(0x00050073,
"error reading COD segment");
855 {
OJPH_ERROR(0x00050074,
"error reading COD segment"); }
859 OJPH_ERROR(0x00050075,
"error reading COD segment");
861 OJPH_ERROR(0x00050076,
"error reading COD segment");
863 OJPH_ERROR(0x00050077,
"error reading COD segment");
865 OJPH_ERROR(0x00050078,
"error reading COD segment");
867 OJPH_ERROR(0x00050079,
"error reading COD segment");
869 OJPH_ERROR(0x0005007A,
"error reading COD segment");
873 OJPH_ERROR(0x0005007B,
"error reading COD segment");
875 OJPH_ERROR(0x0005007C,
"error in COD segment length");
890 OJPH_ERROR(0x00050121,
"error reading COC segment");
892 if (num_comps < 257) {
894 if (file->
read(&t, 1) != 1)
895 OJPH_ERROR(0x00050122,
"error reading COC segment");
900 OJPH_ERROR(0x00050123,
"error reading COC segment");
904 OJPH_ERROR(0x00050124,
"error reading COC segment");
907 "Unsupported options in Scoc field of the COC segment");
909 OJPH_ERROR(0x00050125,
"error reading COC segment");
911 OJPH_ERROR(0x00050126,
"error reading COC segment");
913 OJPH_ERROR(0x00050127,
"error reading COC segment");
915 OJPH_ERROR(0x00050128,
"error reading COC segment");
917 OJPH_ERROR(0x00050129,
"error reading COC segment");
921 OJPH_ERROR(0x0005012A,
"error reading COC segment");
923 t += num_comps < 257 ? 0 : 1;
926 OJPH_ERROR(0x0005012B,
"error in COC segment length");
933 if (this->atk == NULL)
934 OJPH_ERROR(0x00050131,
"A COD/COC segment employs the DWT kernel "
935 "atk=%d, but a corresponding ATK segment cannot be found",
949 bool is_employing_color_transform)
952 B += is_employing_color_transform ? 1 : 0;
955 ui32 X = (
ui32) ceil(log(bibo_l * bibo_l) / M_LN2);
958 for (
ui32 d = num_decomps; d > 0; --d)
962 X = (
ui32) ceil(log(bibo_h * bibo_l) / M_LN2);
964 max_B_plus_X =
ojph_max(max_B_plus_X, B + X);
966 max_B_plus_X =
ojph_max(max_B_plus_X, B + X);
967 X = (
ui32) ceil(log(bibo_h * bibo_h) / M_LN2);
969 max_B_plus_X =
ojph_max(max_B_plus_X, B + X);
972 if (max_B_plus_X > 38)
973 OJPH_ERROR(0x00050151,
"The specified combination of bit_depth, "
974 "colour transform, and type of wavelet transform requires more than "
975 "38 bits; it requires %d bits. This is beyond what is allowed in "
976 "the JPEG2000 image coding format.", max_B_plus_X);
983 for (
ui32 d = num_decomps; d > 0; --d)
998 Sqcd = (
ui8)((guard_bits<<5)|0x2);
1001 float delta_b =
base_delta / (gain_l * gain_l);
1002 int exp = 0, mantissa;
1003 while (delta_b < 1.0f)
1004 { exp++; delta_b *= 2.0f; }
1007 mantissa = (int)round(delta_b * (
float)(1<<11)) - (1<<11);
1008 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1010 for (
ui32 d = num_decomps; d > 0; --d)
1017 int exp = 0, mantissa;
1018 while (delta_b < 1.0f)
1019 { exp++; delta_b *= 2.0f; }
1020 mantissa = (int)round(delta_b * (
float)(1<<11)) - (1<<11);
1021 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1029 { exp++; delta_b *= 2.0f; }
1030 mantissa = (int)round(delta_b * (
float)(1<<11)) - (1<<11);
1031 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1044 int irrev =
Sqcd & 0x1F;
1051 else if (irrev == 2)
1054 ui32 nb = num_decomps - (i ? (i - 1) / 3 : 0);
1065 ui32 num_decompositions,
1068 float arr[] = { 1.0f, 2.0f, 2.0f, 4.0f };
1069 assert((
Sqcd & 0x1F) == 2);
1072 if (dfs != NULL && dfs->
exists())
1077 OJPH_INFO(0x00050101,
"Trying to access quantization step size for "
1078 "subband %d when the QCD/QCC marker segment specifies "
1079 "quantization step sizes for %d subbands only. To continue "
1080 "decoding, we are using the step size for subband %d, which can "
1081 "produce incorrect results",
1088 mantissa /= (float)(1 << 11);
1089 mantissa /= (float)(1u << eps);
1105 if (dfs != NULL && dfs->
exists())
1110 OJPH_INFO(0x00050111,
"Trying to access quantization step size for "
1111 "subband %d when the QCD/QCC marker segment specifies "
1112 "quantization step sizes for %d subbands only. To continue "
1113 "decoding, we are using the step size for subband %d, which can "
1114 "produce incorrect results",
1119 int irrev =
Sqcd & 0x1F;
1123 num_bits = num_bits == 0 ? 0 : num_bits - 1;
1125 else if (irrev == 1)
1127 else if (irrev == 2)
1138 int irrev =
Sqcd & 0x1F;
1144 else if (irrev == 2)
1154 result &= file->
write(&buf, 2) == 2;
1156 result &= file->
write(&buf, 2) == 2;
1158 result &= file->
write(&buf, 1) == 1;
1164 result &= file->
write(&buf, 1) == 1;
1166 else if (irrev == 2)
1170 result &= file->
write(&buf, 2) == 2;
1182 OJPH_ERROR(0x00050081,
"error reading QCD marker");
1185 OJPH_ERROR(0x00050082,
"error reading QCD marker");
1186 if ((
Sqcd & 0x1F) == 0)
1190 OJPH_ERROR(0x00050083,
"wrong Lqcd value in QCD marker");
1193 OJPH_ERROR(0x00050084,
"error reading QCD marker");
1195 else if ((
Sqcd & 0x1F) == 1)
1199 "Scalar derived quantization is not supported yet in QCD marker");
1201 OJPH_ERROR(0x00050085,
"wrong Lqcd value in QCD marker");
1203 else if ((
Sqcd & 0x1F) == 2)
1207 OJPH_ERROR(0x00050086,
"wrong Lqcd value in QCD marker");
1211 OJPH_ERROR(0x00050087,
"error reading QCD marker");
1216 OJPH_ERROR(0x00050088,
"wrong Sqcd value in QCD marker");
1231 OJPH_ERROR(0x000500A1,
"error reading QCC marker");
1233 if (num_comps < 257)
1236 if (file->
read(&v, 1) != 1)
1237 OJPH_ERROR(0x000500A2,
"error reading QCC marker");
1243 OJPH_ERROR(0x000500A3,
"error reading QCC marker");
1247 OJPH_ERROR(0x000500A4,
"error reading QCC marker");
1248 ui32 offset = num_comps < 257 ? 4 : 5;
1249 if ((
Sqcd & 0x1F) == 0)
1253 OJPH_ERROR(0x000500A5,
"wrong Lqcd value in QCC marker");
1256 OJPH_ERROR(0x000500A6,
"error reading QCC marker");
1258 else if ((
Sqcd & 0x1F) == 1)
1262 "Scalar derived quantization is not supported yet in QCC marker");
1264 OJPH_ERROR(0x000500A7,
"wrong Lqcc value in QCC marker");
1266 else if ((
Sqcd & 0x1F) == 2)
1270 OJPH_ERROR(0x000500A8,
"wrong Lqcc value in QCC marker");
1274 OJPH_ERROR(0x000500A9,
"error reading QCC marker");
1279 OJPH_ERROR(0x000500AA,
"wrong Sqcc value in QCC marker");
1296 bool all_same =
true;
1304 bool is_signed =
false;
1305 for (
ui32 c = 0; c < num_comps; ++c)
1318 all_same = all_same && (is_signed == siz.
is_signed(c));
1336 this->
BDnlt = (
ui8)((bit_depth - 1) | (is_signed ? 0x80 : (
ui8)0));
1344 for (
ui32 c = 0; c < num_comps; ++c)
1348 if (bd != bit_depth || is != is_signed)
1361 p->
BDnlt = (
ui8)((bd - 1) | (is ? 0x80 : 0));
1389 bool& is_signed)
const
1395 bit_depth = (
ui8)((p->
BDnlt & 0x7F) + 1);
1396 bit_depth = bit_depth <= 38 ? bit_depth : 38;
1397 is_signed = (p->
BDnlt & 0x80) == 0x80;
1417 result &= file->
write(&buf, 2) == 2;
1419 result &= file->
write(&buf, 2) == 2;
1421 result &= file->
write(&buf, 2) == 2;
1423 result &= file->
write(&p->
Tnlt, 1) == 1;
1435 if (file->
read(buf, 6) != 6)
1436 OJPH_ERROR(0x00050141,
"error reading NLT marker segment");
1439 if (length != 6 || buf[5] != 3)
1440 OJPH_ERROR(0x00050142,
"Unsupported NLT type %d\n", buf[5]);
1444 if (comp != special_comp_num::ALL_COMPS)
1467 if (
Cnlt == comp_num)
1471 while (p && p->
Cnlt != comp_num)
1480 assert(
Cnlt != comp_num);
1482 while (p->
next != NULL) {
1483 assert(p->
Cnlt != comp_num);
1498 while (p && p->
enabled ==
false)
1529 this->
Psot = payload_len + 14;
1533 result &= file->
write(&buf, 2) == 2;
1535 result &= file->
write(&buf, 2) == 2;
1537 result &= file->
write(&buf, 2) == 2;
1539 result &= file->
write(&buf, 4) == 4;
1555 result &= file->
write(&buf, 2) == 2;
1557 result &= file->
write(&buf, 2) == 2;
1559 result &= file->
write(&buf, 2) == 2;
1561 result &= file->
write(&buf, 4) == 4;
1575 OJPH_INFO(0x00050091,
"error reading SOT marker");
1582 OJPH_INFO(0x00050092,
"error in SOT length");
1588 OJPH_INFO(0x00050093,
"error reading tile index");
1595 OJPH_INFO(0x00050094,
"tile index in SOT marker cannot be 0xFFFF");
1601 OJPH_INFO(0x00050095,
"error reading SOT marker");
1608 OJPH_INFO(0x00050096,
"error reading SOT marker");
1614 OJPH_INFO(0x00050097,
"error reading SOT marker");
1622 OJPH_ERROR(0x00050091,
"error reading SOT marker");
1625 OJPH_ERROR(0x00050092,
"error in SOT length");
1627 OJPH_ERROR(0x00050093,
"error reading SOT tile index");
1630 OJPH_ERROR(0x00050094,
"tile index in SOT marker cannot be 0xFFFF");
1632 OJPH_ERROR(0x00050095,
"error reading SOT marker");
1635 OJPH_ERROR(0x00050096,
"error reading SOT marker");
1637 OJPH_ERROR(0x00050097,
"error reading SOT marker");
1654 OJPH_ERROR(0x000500B1,
"Trying to allocate more than 65535 bytes for "
1655 "a TLM marker; this can be resolved by having more than "
1656 "one TLM marker, but the code does not support this. "
1657 "In any case, this limit means that we have 10922 "
1658 "tileparts or more, which is a huge number.");
1684 result &= file->
write(&buf, 2) == 2;
1686 result &= file->
write(&buf, 2) == 2;
1692 result &= file->
write(&buf, 2) == 2;
1694 result &= file->
write(&buf, 4) == 4;
1711 while (p && p->
Sdfs != index)
1720 ui32 d = decomp_level - 1;
1722 ui32 bits = d & 0x3;
1723 ui32 val = (
Ddfs[idx] >> (6 - 2 * bits)) & 0x3;
1734 ui32 ns[4] = { 0, 3, 1, 1 };
1756 ui32 decomp_level = 1;
1757 while (skipped_resolutions > 0)
1761 { factor.
x *= 2; factor.
y *= 2; }
1768 --skipped_resolutions;
1778 while (p->
next != NULL)
1782 return p->
read(file);
1786 OJPH_ERROR(0x000500D1,
"error reading DFS-Ldfs parameter");
1789 OJPH_ERROR(0x000500D2,
"error reading DFS-Sdfs parameter");
1792 OJPH_ERROR(0x000500D3,
"The DFS-Sdfs parameter is %d, which is "
1793 "larger than the permissible 15",
Sdfs);
1795 if (file->
read(&l_Ids, 1) != 1)
1796 OJPH_ERROR(0x000500D4,
"error reading DFS-Ids parameter");
1797 constexpr int max_Ddfs =
sizeof(
Ddfs) * 4;
1798 if (l_Ids > max_Ddfs)
1799 OJPH_INFO(0x000500D5,
"The DFS-Ids parameter is %d; while this is "
1800 "valid, the number is unnessarily large -- you do not need more "
1801 "than %d. Please contact me regarding this issue.",
1803 Ids = l_Ids < max_Ddfs ? l_Ids : max_Ddfs;
1804 for (
int i = 0; i <
Ids; i += 4)
1805 if (file->
read(&
Ddfs[i / 4], 1) != 1)
1806 OJPH_ERROR(0x000500D6,
"error reading DFS-Ddfs parameters");
1807 for (
int i =
Ids; i < l_Ids; i += 4)
1808 if (file->
read(&t, 1) != 1)
1809 OJPH_ERROR(0x000500D7,
"error reading DFS-Ddfs parameters");
1834 if (coeff_type == 0) {
1836 if (file->
read(&v, 1) != 1)
return false;
1839 else if (coeff_type == 1) {
1841 if (file->
read(&v, 2) != 2)
return false;
1844 else if (coeff_type == 2) {
1849 if (file->
read(&v.i, 4) != 4)
return false;
1853 else if (coeff_type == 3) {
1858 if (file->
read(&v.i, 8) != 8)
return false;
1862 else if (coeff_type == 4) {
1864 if (file->
read(&v, 8) != 8)
return false;
1865 if (file->
read(&v1, 8) != 8)
return false;
1875 si32 e = (
si32)((v >> 48) & 0x7FFF);
1881 s.i |= ((
ui32)(v >> 32) & 0x80000000);
1883 s.i |= (
ui32)((v >> 25) & 0x007FFFFF);
1894 if (coeff_type == 0) {
1896 if (file->
read(&v, 1) != 1)
return false;
1899 else if (coeff_type == 1) {
1901 if (file->
read(&v, 2) != 2)
return false;
1914 while (p->
next != NULL)
1919 return p->
read(file);
1923 OJPH_ERROR(0x000500E1,
"error reading ATK-Latk parameter");
1926 OJPH_ERROR(0x000500E2,
"error reading ATK-Satk parameter");
1929 OJPH_ERROR(0x000500E3,
"ATK-Satk parameter sets m_init to 1, "
1930 "requiring odd-indexed subsequence in first reconstruction step, "
1931 "which is not supported yet.");
1933 OJPH_ERROR(0x000500E4,
"ATK-Satk parameter specified ARB filter, "
1934 "which is not supported yet.");
1936 OJPH_ERROR(0x000500E5,
"ATK-Satk parameter does not make sense. "
1937 "It employs floats with reversible filtering.");
1939 OJPH_ERROR(0x000500E6,
"ATK-Satk parameter requires constant "
1940 "boundary extension, which is not supported yet.");
1943 OJPH_ERROR(0x000500E7,
"error reading ATK-Katk parameter");
1945 OJPH_ERROR(0x000500E8,
"error reading ATK-Natk parameter");
1955 for (
int s = 0; s <
Natk; ++s)
1958 OJPH_ERROR(0x000500E9,
"error reading ATK-Eatk parameter");
1960 OJPH_ERROR(0x000500EA,
"error reading ATK-Batk parameter");
1963 if (file->
read(&LCatk, 1) != 1)
1964 OJPH_ERROR(0x000500EB,
"error reading ATK-LCatk parameter");
1966 OJPH_ERROR(0x000500EC,
"Encountered a ATK-LCatk value of zero; "
1967 "something is wrong.");
1969 OJPH_ERROR(0x000500ED,
"ATK-LCatk value greater than 1; "
1970 "that is, a multitap filter is not supported");
1972 OJPH_ERROR(0x000500EE,
"Error reding ATK-Aatk parameter");
1977 for (
int s = 0; s <
Natk; ++s)
1980 if (file->
read(&LCatk, 1) != 1)
1981 OJPH_ERROR(0x000500EF,
"error reading ATK-LCatk parameter");
1983 OJPH_ERROR(0x000500F0,
"Encountered a ATK-LCatk value of zero; "
1984 "something is wrong.");
1986 OJPH_ERROR(0x000500F1,
"ATK-LCatk value greater than 1; "
1987 "that is, a multitap filter is not supported.");
1989 OJPH_ERROR(0x000500F2,
"Error reding ATK-Aatk parameter");
2000 Katk = (float)1.230174104914001;
2004 d[0].
irv.
Aatk = (float)0.443506852043971;
2005 d[1].
irv.
Aatk = (float)0.882911075530934;
2006 d[2].
irv.
Aatk = (float)-0.052980118572961;
2007 d[3].
irv.
Aatk = (float)-1.586134342059924;
virtual size_t read(void *ptr, size_t size)=0
static const float gain_5x3_l[34]
static float get_bibo_gain_l(ui32 num_decomp, bool reversible)
static const float gain_5x3_h[34]
static float get_bibo_gain_h(ui32 num_decomp, bool reversible)
static const float gain_9x7_h[34]
static const float gain_9x7_l[34]
static const float gain_5x3_l[34]
static const float gain_5x3_h[34]
static float get_gain_l(ui32 num_decomp, bool reversible)
static const float gain_9x7_l[34]
static float get_gain_h(ui32 num_decomp, bool reversible)
static const float gain_9x7_h[34]
virtual size_t write(const void *ptr, size_t size)=0
size get_block_dims() const
int get_progression_order() const
bool is_using_color_transform() const
void set_num_decomposition(ui32 num_decompositions)
ui32 get_num_decompositions() const
size get_log_block_dims() const
bool packets_may_use_sop() const
size get_precinct_size(ui32 level_num) const
const char * get_progression_order_as_string() const
void set_precinct_size(int num_levels, size *precinct_size)
bool packets_use_eph() const
bool is_reversible() const
void set_progression_order(const char *name)
bool get_block_vertical_causality() const
void set_block_dims(ui32 width, ui32 height)
size get_log_precinct_size(ui32 level_num) const
int get_num_layers() const
void set_color_transform(bool color_transform)
void set_reversible(bool reversible)
void set_type3_transformation(ui32 comp_num, bool enable)
enables or disables type 3 nonlinearity for a component or the default setting
bool get_type3_transformation(ui32 comp_num, ui8 &bit_depth, bool &is_signed)
get the state (enabled or disabled) of type 3 nonlinearity for a component or the default setting
void set_irrev_quant(float delta)
void set_tile_size(size s)
point get_image_extent() const
void set_component(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
void set_num_components(ui32 num_comps)
ui32 get_bit_depth(ui32 comp_num) const
void set_tile_offset(point offset)
point get_image_offset() const
void set_image_offset(point offset)
size get_tile_size() const
ui32 get_recon_height(ui32 comp_num) const
point get_downsampling(ui32 comp_num) const
void set_image_extent(point extent)
point get_tile_offset() const
ui32 get_recon_width(ui32 comp_num) const
bool is_signed(ui32 comp_num) const
ui32 get_num_components() const
static ui16 swap_byte(ui16 t)
const char OJPH_PO_STRING_PCRL[]
static ui32 population_count(ui32 val)
const char OJPH_PO_STRING_RLCP[]
const char OJPH_PO_STRING_RPCL[]
const char OJPH_PO_STRING_CPRL[]
static ui32 count_leading_zeros(ui32 val)
const char OJPH_PO_STRING_LRCP[]
#define ojph_div_ceil(a, b)
#define OJPH_INFO(t,...)
MACROs to insert file and line number for info, warning, and error.
#define OJPH_ERROR(t,...)
const param_atk * get_atk(int index) const
bool is_reversible() const
bool read(infile_base *file)
int get_coeff_type() const
bool read_coefficient(infile_base *file, float &K)
bool is_whole_sample() const
bool is_using_ws_extension() const
void read(infile_base *file)
bool write(outfile_base *file)
bool write(outfile_base *file)
size get_block_dims() const
size get_log_block_dims() const
ui16 get_dfs_index() const
void set_reversible(bool reversible)
const param_cod * get_cod(ui32 comp_num) const
bool is_employing_color_transform() const
void employ_color_transform(ui8 val)
const param_atk * access_atk() const
size get_log_precinct_size(ui32 res_num) const
bool is_dfs_defined() const
bool packets_use_eph() const
ui8 get_num_decompositions() const
void read(infile_base *file, cod_type type)
void update_atk(const param_atk *atk)
bool packets_may_use_sop() const
size get_precinct_size(ui32 res_num) const
ui8 get_wavelet_kern() const
ui32 propose_precision(const param_siz *siz, ui32 comp_num) const
bool read(infile_base *file)
dfs_dwt_type get_dwt_type(ui32 decomp_level) const
point get_res_downsamp(ui32 skipped_resolutions) const
ui32 get_subband_idx(ui32 num_decompositions, ui32 resolution, ui32 subband) const
const param_dfs * get_dfs(int index) const
void set_type3_transformation(ui32 comp_num, bool enable)
bool get_type3_transformation(ui32 comp_num, ui8 &bit_depth, bool &is_signed) const
bool write(outfile_base *file) const
param_nlt * add_object(ui32 comp_num)
void trim_non_existing_components(ui32 num_comps)
void read(infile_base *file)
const param_nlt * get_comp_object(ui32 comp_num) const
void check_validity(param_siz &siz)
bool is_any_enabled() const
void read(infile_base *file, ui32 num_comps)
float irrev_get_delta(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
ui8 encode_SPqcd(ui8 v) const
void set_rev_quant(ui32 num_decomps, ui32 bit_depth, bool is_employing_color_transform)
void set_irrev_quant(ui32 num_decomps)
ui32 get_num_guard_bits() const
void set_delta(float delta)
bool write(outfile_base *file)
void read(infile_base *file)
ui32 get_Kmax(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
ui8 decode_SPqcd(ui8 v) const
ui32 get_bit_depth(ui32 comp_num) const
bool ws_kern_support_needed
ui32 get_recon_height(ui32 comp_num) const
bool is_signed(ui32 comp_num) const
bool write(outfile_base *file)
ui16 get_num_components() const
point get_recon_downsampling(ui32 comp_num) const
void set_Rsiz_flag(ui16 flag)
point get_recon_size(ui32 comp_num) const
void set_comp_info(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
point get_downsampling(ui32 comp_num) const
void read(infile_base *file)
void set_num_components(ui32 num_comps)
ui32 get_recon_width(ui32 comp_num) const
bool read(infile_base *file, bool resilient)
bool write(outfile_base *file, ui32 payload_len)
void set_next_pair(ui16 Ttlm, ui32 Ptlm)
bool write(outfile_base *file)
void init(ui32 num_pairs, Ttlm_Ptlm_pair *store)