38#define _USE_MATH_DEFINES
169 if (num_decompositions > 32)
171 "maximum number of decompositions cannot exceed 32");
178 ui32 log_width = 31 - count_leading_zeros(width);
179 ui32 log_height = 31 - count_leading_zeros(height);
180 if (width == 0 || width != (1u << log_width)
181 || height == 0 || height != (1u << log_height)
182 || log_width < 2 || log_height < 2
183 || log_width + log_height > 12)
184 OJPH_ERROR(0x00050011,
"incorrect code block dimensions");
192 if (num_levels == 0 || precinct_size == NULL)
199 size t = precinct_size[i < num_levels ? i : num_levels - 1];
201 ui32 PPx = 31 - count_leading_zeros(t.
w);
202 ui32 PPy = 31 - count_leading_zeros(t.
h);
203 if (t.
w == 0 || t.
h == 0)
204 OJPH_ERROR(0x00050021,
"precinct width or height cannot be 0");
205 if (t.
w != (1u<<PPx) || t.
h != (1u<<PPy))
207 "precinct width and height should be a power of 2");
208 if (PPx > 15 || PPy > 15)
209 OJPH_ERROR(0x00050023,
"precinct size is too large");
210 if (i > 0 && (PPx == 0 || PPy == 0))
211 OJPH_ERROR(0x00050024,
"precinct size is too small");
221 size_t len = strlen(name);
235 OJPH_ERROR(0x00050031,
"unknown progression order");
238 OJPH_ERROR(0x00050032,
"improper progression order");
451 ui8 decoded_bit_depth,
452 bool decoded_signedness,
454 ui16 num_points,
void* points,
458 decoded_signedness, d_min, d_max, pt_val, num_points, points, nl_type);
463 ui8& decoded_bit_depth,
464 bool& decoded_signedness,
468 decoded_signedness, nl_type);
482 size_t t = strlen(str);
485 "COM marker string length cannot be larger than 65531");
496 "COM marker string length cannot be larger than 65531");
531 1.4021e+00f, 2.0304e+00f, 2.9012e+00f, 4.1153e+00f, 5.8245e+00f,
532 8.2388e+00f, 1.1652e+01f, 1.6479e+01f, 2.3304e+01f, 3.2957e+01f,
533 4.6609e+01f, 6.5915e+01f, 9.3217e+01f, 1.3183e+02f, 1.8643e+02f,
534 2.6366e+02f, 3.7287e+02f, 5.2732e+02f, 7.4574e+02f, 1.0546e+03f,
535 1.4915e+03f, 2.1093e+03f, 2.9830e+03f, 4.2185e+03f, 5.9659e+03f,
536 8.4371e+03f, 1.1932e+04f, 1.6874e+04f, 2.3864e+04f, 3.3748e+04f,
537 4.7727e+04f, 6.7496e+04f, 9.5454e+04f };
539 1.9669e+00f, 2.8839e+00f, 4.1475e+00f, 5.8946e+00f, 8.3472e+00f,
540 1.1809e+01f, 1.6701e+01f, 2.3620e+01f, 3.3403e+01f, 4.7240e+01f,
541 6.6807e+01f, 9.4479e+01f, 1.3361e+02f, 1.8896e+02f, 2.6723e+02f,
542 3.7792e+02f, 5.3446e+02f, 7.5583e+02f, 1.0689e+03f, 1.5117e+03f,
543 2.1378e+03f, 3.0233e+03f, 4.2756e+03f, 6.0467e+03f, 8.5513e+03f,
544 1.2093e+04f, 1.7103e+04f, 2.4187e+04f, 3.4205e+04f, 4.8373e+04f,
545 6.8410e+04f, 9.6747e+04f, 1.3682e+05f };
547 1.2247e+00f, 1.3229e+00f, 1.5411e+00f, 1.7139e+00f, 1.9605e+00f,
548 2.2044e+00f, 2.5047e+00f, 2.8277e+00f, 3.2049e+00f, 3.6238e+00f,
549 4.1033e+00f, 4.6423e+00f, 5.2548e+00f, 5.9462e+00f, 6.7299e+00f,
550 7.6159e+00f, 8.6193e+00f, 9.7544e+00f, 1.1039e+01f, 1.2493e+01f,
551 1.4139e+01f, 1.6001e+01f, 1.8108e+01f, 2.0493e+01f, 2.3192e+01f,
552 2.6246e+01f, 2.9702e+01f, 3.3614e+01f, 3.8041e+01f, 4.3051e+01f,
553 4.8721e+01f, 5.5138e+01f, 6.2399e+01f };
555 1.3975e+00f, 1.4389e+00f, 1.7287e+00f, 1.8880e+00f, 2.1841e+00f,
556 2.4392e+00f, 2.7830e+00f, 3.1341e+00f, 3.5576e+00f, 4.0188e+00f,
557 4.5532e+00f, 5.1494e+00f, 5.8301e+00f, 6.5963e+00f, 7.4663e+00f,
558 8.4489e+00f, 9.5623e+00f, 1.0821e+01f, 1.2247e+01f, 1.3860e+01f,
559 1.5685e+01f, 1.7751e+01f, 2.0089e+01f, 2.2735e+01f, 2.5729e+01f,
560 2.9117e+01f, 3.2952e+01f, 3.7292e+01f, 4.2203e+01f, 4.7761e+01f,
561 5.4051e+01f, 6.1170e+01f, 6.9226e+01f };
582 1.3328e+00f, 1.3067e+00f, 1.3028e+00f, 1.3001e+00f, 1.2993e+00f,
583 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
584 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
585 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
586 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
587 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f, 1.2992e+00f,
588 1.2992e+00f, 1.2992e+00f };
590 1.2757e+00f, 1.2352e+00f, 1.2312e+00f, 1.2285e+00f, 1.2280e+00f,
591 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
592 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
593 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
594 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
595 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f, 1.2278e+00f,
596 1.2278e+00f, 1.2278e+00f };
598 1.6250e+00f, 1.6875e+00f, 1.6963e+00f, 1.7067e+00f, 1.7116e+00f,
599 1.7129e+00f, 1.7141e+00f, 1.7145e+00f, 1.7151e+00f, 1.7152e+00f,
600 1.7155e+00f, 1.7155e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
601 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
602 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
603 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f, 1.7156e+00f,
604 1.7156e+00f, 1.7156e+00f };
606 2.7500e+00f, 2.8047e+00f, 2.8198e+00f, 2.8410e+00f, 2.8558e+00f,
607 2.8601e+00f, 2.8628e+00f, 2.8656e+00f, 2.8662e+00f, 2.8667e+00f,
608 2.8669e+00f, 2.8670e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
609 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
610 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
611 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f, 2.8671e+00f,
612 2.8671e+00f, 2.8671e+00f };
632 if (component_subsampling.
x == 2 && component_subsampling.
y == 2)
634 else if (component_subsampling.
x == 2 && component_subsampling.
y == 1)
636 else if (component_subsampling.
x == 1 && component_subsampling.
y == 1)
647 else if (
comp_type == comp_type::OJPH_COMP_CB)
657 else if (
comp_type == comp_type::OJPH_COMP_CR)
680 if (subband_idx == 0)
683 assert(subband_idx >= 1 && subband_idx <= 3);
684 assert(decomposition_level > 0);
685 decomposition_level =
ojph_min(decomposition_level, 6);
686 ui32 index = (decomposition_level - 1) * 3 + (3 - subband_idx);
696 else if (
comp_type == comp_type::OJPH_COMP_CB)
697 return 1.8051f / 1.7321f;
698 else if (
comp_type == comp_type::OJPH_COMP_CR)
699 return 1.5734f / 1.7321f;
711 constexpr float t0 = 65.0f;
712 constexpr float t1 = 97.0f;
713 constexpr float alpha_t0 = 0.04f, alpha_t1 = 0.10f;
714 constexpr float m_t0 = 2.0f * (1.0f - t0 / 100.0f);
715 constexpr float m_t1 = 2.0f * (1.0f - t1 / 100.0f);
719 m_q = 50.0f / qfactor;
721 m_q = 2.0f * (1.0f - qfactor / 100.0f);
729 else if (qfactor < t1)
731 power = std::log(m_q) - std::log(m_t1);
732 power /= std::log(m_t0) - std::log(m_t1);
733 alpha_q = alpha_t1 * std::pow(alpha_t0 / alpha_t1, power);
740 const float eps = std::sqrt(0.5f) * std::ldexp(1.0f, -(
int)bit_depth);
741 return alpha_q * m_q + eps;
751 static const float y[19];
757 0.2724f, 0.5128f, 0.5128f,
758 0.6692f, 0.9382f, 0.9382f,
759 1.0888f, 1.3046f, 1.3046f,
760 1.4156f, 1.5594f, 1.5594f,
762 2.0f, 2.0f, 2.0f, 2.0f};
764 0.5196f, 0.8260f, 0.8260f,
765 1.0080f, 1.2928f, 1.2928f,
766 1.4440f, 1.6508f, 1.6508f,
767 1.7538f, 1.8848f, 1.8848f,
769 2.0f, 2.0f, 2.0f, 2.0f};
771 0.1220f, 0.1220f, 0.3626f,
772 0.3626f, 0.3626f, 0.6634f,
773 0.6634f, 0.6634f, 0.9225f,
774 0.9225f, 0.9225f, 1.1027f,
775 1.1027f, 1.1027f, 1.4142f,
776 1.4142f, 1.4142f, 1.4142f, 1.4142f};
778 0.2595f, 0.2595f, 0.5841f,
779 0.5841f, 0.5841f, 0.9141f,
780 0.9141f, 0.9141f, 1.1673f,
781 1.1673f, 1.1673f, 1.3328f,
782 1.3328f, 1.3328f, 1.4142f,
783 1.4142f, 1.4142f, 1.4142f, 1.4142f};
785 0.0263f, 0.0863f, 0.0863f,
786 0.1362f, 0.2564f, 0.2564f,
787 0.3346f, 0.4691f, 0.4691f,
788 0.5444f, 0.6523f, 0.6523f,
789 0.7078f, 0.7797f, 0.7797f,
790 1.0f, 1.0f, 1.0f, 1.0f};
792 0.0773f, 0.1835f, 0.1835f,
793 0.2598f, 0.4130f, 0.4130f,
794 0.5040f, 0.6464f, 0.6464f,
795 0.7220f, 0.8254f, 0.8254f,
796 0.8769f, 0.9424f, 0.9424f,
797 1.0f, 1.0f, 1.0f, 1.0f};
799 0.0901f, 0.2758f, 0.2758f,
800 0.7018f, 0.8378f, 0.8378f,
804 1.0f, 1.0f, 1.0f, 1.0f};
811 1.0f, 1.0f, 1.0f, 1.0f};
834 buf2 = swap_bytes_if_le(buf2);
836 buf2 = swap_bytes_if_le(
Lsiz);
838 buf2 = swap_bytes_if_le(
Rsiz);
840 buf4 = swap_bytes_if_le(
Xsiz);
842 buf4 = swap_bytes_if_le(
Ysiz);
844 buf4 = swap_bytes_if_le(
XOsiz);
846 buf4 = swap_bytes_if_le(
YOsiz);
848 buf4 = swap_bytes_if_le(
XTsiz);
850 buf4 = swap_bytes_if_le(
YTsiz);
852 buf4 = swap_bytes_if_le(
XTOsiz);
854 buf4 = swap_bytes_if_le(
YTOsiz);
856 buf2 = swap_bytes_if_le(
Csiz);
858 for (
int c = 0; c <
Csiz; ++c)
861 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
863 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
865 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
875 OJPH_ERROR(0x00050041,
"error reading SIZ marker");
877 int num_comps = (
Lsiz - 38) / 3;
878 if (
Lsiz != 38 + 3 * num_comps)
879 OJPH_ERROR(0x00050042,
"error in SIZ marker length");
881 OJPH_ERROR(0x00050043,
"error reading SIZ marker");
883 if ((
Rsiz & 0x4000) == 0)
885 "Rsiz bit 14 is not set (this is not a JPH file)");
886 if ((
Rsiz & 0x8000) != 0 && (
Rsiz & 0xD5F) != 0)
887 OJPH_WARN(0x00050001,
"Rsiz in SIZ has unimplemented fields");
889 OJPH_ERROR(0x00050045,
"error reading SIZ marker");
892 OJPH_ERROR(0x00050046,
"error reading SIZ marker");
894 ui32 t_XOsiz, t_YOsiz;
895 if (file->
read(&t_XOsiz, 4) != 4)
896 OJPH_ERROR(0x00050047,
"error reading SIZ marker");
897 if (file->
read(&t_YOsiz, 4) != 4)
898 OJPH_ERROR(0x00050048,
"error reading SIZ marker");
900 swap_bytes_if_le(t_XOsiz),
901 swap_bytes_if_le(t_YOsiz)));
902 ui32 t_XTsiz, t_YTsiz;
903 if (file->
read(&t_XTsiz, 4) != 4)
904 OJPH_ERROR(0x00050049,
"error reading SIZ marker");
905 if (file->
read(&t_YTsiz, 4) != 4)
906 OJPH_ERROR(0x0005004A,
"error reading SIZ marker");
908 swap_bytes_if_le(t_XTsiz),
909 swap_bytes_if_le(t_YTsiz)));
910 ui32 t_XTOsiz, t_YTOsiz;
911 if (file->
read(&t_XTOsiz, 4) != 4)
912 OJPH_ERROR(0x0005004B,
"error reading SIZ marker");
913 if (file->
read(&t_YTOsiz, 4) != 4)
914 OJPH_ERROR(0x0005004C,
"error reading SIZ marker");
916 swap_bytes_if_le(t_XTOsiz),
917 swap_bytes_if_le(t_YTOsiz)));
919 OJPH_ERROR(0x0005004D,
"error reading SIZ marker");
921 if (
Csiz != num_comps)
922 OJPH_ERROR(0x0005004E,
"Csiz does not match the SIZ marker size");
924 OJPH_ERROR(0x0005004F,
"Wrong Csiz value of 0 in SIZ marker segment");
926 for (
int c = 0; c <
Csiz; ++c)
929 OJPH_ERROR(0x00050051,
"error reading SIZ marker");
931 OJPH_ERROR(0x00050052,
"error reading SIZ marker");
933 OJPH_ERROR(0x00050053,
"error reading SIZ marker");
934 if ((
cptr[c].SSiz & 0x7F) > 37)
935 OJPH_ERROR(0x00050054,
"Wrong SIZ-SSiz value of %d",
cptr[c].SSiz);
936 if (
cptr[c].XRsiz == 0)
937 OJPH_ERROR(0x00050055,
"Wrong SIZ-XRsiz value of %d",
cptr[c].XRsiz);
938 if (
cptr[c].YRsiz == 0)
939 OJPH_ERROR(0x00050056,
"Wrong SIZ-YRsiz value of %d",
cptr[c].YRsiz);
996 buf2 = swap_bytes_if_le(buf2);
998 buf2 = swap_bytes_if_le(
Lcap);
1000 buf4 = swap_bytes_if_le(
Pcap);
1003 buf2 = swap_bytes_if_le(
Ccap[0]);
1013 OJPH_ERROR(0x00050061,
"error reading CAP marker");
1016 OJPH_ERROR(0x00050062,
"error reading CAP marker");
1018 ui32 count = population_count(
Pcap);
1019 if (
Pcap & 0xFFFDFFFF)
1021 "error Pcap in CAP has options that are not supported");
1022 if ((
Pcap & 0x00020000) == 0)
1024 "error Pcap should have its 15th MSB set, Pcap^15. "
1025 " This is not a JPH file");
1026 for (
ui32 i = 0; i < count; ++i)
1028 OJPH_ERROR(0x00050065,
"error reading CAP marker");
1029 if (
Lcap != 6 + 2 * count)
1030 OJPH_ERROR(0x00050066,
"error in CAP marker length");
1047 assert(
atk != NULL);
1066 buf2 = swap_bytes_if_le(buf2);
1068 buf2 = swap_bytes_if_le(
Lcod);
1071 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1073 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1077 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1079 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1081 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1083 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1085 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1087 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1092 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1119 Lcod = num_comps < 257 ? 9 : 10;
1127 buf2 = swap_bytes_if_le(buf2);
1129 buf2 = swap_bytes_if_le(
Lcod);
1131 if (num_comps < 257)
1134 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1142 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1144 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1146 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1148 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1150 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1152 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1157 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1169 OJPH_ERROR(0x00050071,
"error reading COD segment");
1172 OJPH_ERROR(0x00050072,
"error reading COD segment");
1174 OJPH_ERROR(0x00050073,
"error reading COD segment");
1176 {
OJPH_ERROR(0x00050074,
"error reading COD segment"); }
1180 OJPH_ERROR(0x00050075,
"error reading COD segment");
1182 OJPH_ERROR(0x00050076,
"error reading COD segment");
1184 OJPH_ERROR(0x00050077,
"error reading COD segment");
1186 OJPH_ERROR(0x00050078,
"error reading COD segment");
1188 OJPH_ERROR(0x00050079,
"error reading COD segment");
1190 OJPH_ERROR(0x0005007A,
"error reading COD segment");
1198 OJPH_ERROR(0x0005007D,
"wrong settings in a COD-SPcod parameter");
1201 OJPH_ERROR(0x0005007E,
"unsupported settings in a COD-SPcod parameter");
1205 for (
int i = 0; i <= num_decompositions; ++i) {
1207 OJPH_ERROR(0x0005007B,
"error reading COD segment");
1212 "Precinct width or height for resolutions other than the"
1213 " coarsest must be larger than 1; here, they are %d and %d,"
1220 OJPH_ERROR(0x0005007C,
"error in COD segment length");
1233 OJPH_ERROR(0x00050121,
"error reading COC segment");
1235 if (num_comps < 257) {
1237 if (file->
read(&t, 1) != 1)
1238 OJPH_ERROR(0x00050122,
"error reading COC segment");
1243 OJPH_ERROR(0x00050123,
"error reading COC segment");
1247 OJPH_ERROR(0x00050124,
"error reading COC segment");
1250 "Unsupported options in Scoc field of the COC segment");
1252 OJPH_ERROR(0x00050125,
"error reading COC segment");
1254 OJPH_ERROR(0x00050126,
"error reading COC segment");
1256 OJPH_ERROR(0x00050127,
"error reading COC segment");
1258 OJPH_ERROR(0x00050128,
"error reading COC segment");
1260 OJPH_ERROR(0x00050129,
"error reading COC segment");
1268 OJPH_ERROR(0x0005012C,
"wrong settings in a COC-SPcoc parameter");
1271 OJPH_ERROR(0x0005012D,
"unsupported settings in a COC-SPcoc parameter");
1275 for (
int i = 0; i <= num_decompositions; ++i) {
1277 OJPH_ERROR(0x0005012A,
"error reading COC segment");
1282 "Precinct width or height for resolutions other than the"
1283 " coarsest must be larger than 1; here, they are %d and %d,"
1290 t += num_comps < 257 ? 0 : 1;
1291 t += (
Scod & 1) ? 1 + num_decompositions : 0;
1293 OJPH_ERROR(0x0005012B,
"error in COC segment length");
1301 if (this->atk == NULL)
1302 OJPH_ERROR(0x00050131,
"A COD segment employs the DWT kernel "
1303 "atk = %d, but a corresponding ATK segment cannot be found.",
1310 OJPH_ERROR(0x00050132,
"A COC segment employs the DWT kernel "
1311 "atk = %d, but a corresponding ATK segment cannot be found",
1345 while (p->
next != NULL)
1387 for (
ui32 c = 0; c < num_comps; ++c)
1402 for (
ui32 i = 0; i < num_comps; ++i)
1412 else if (num_comps >= 3)
1414 for (
ui32 i = 0; i < num_comps; ++i) {
1419 ui8 ci = (
ui8)(i < 3u ? i : 0u);
1432 for (
ui32 c = 0; c < num_comps; ++c)
1457 OJPH_ERROR(0x00040001,
"Quantization step sizes already initialized.");
1480 OJPH_WARN(0x00040002,
"qstep for component %d is ignored, because "
1481 "qfactor is set.", comp_num);
1492 OJPH_ERROR(0x00040001,
"Quantization step sizes not initialized.");
1506 OJPH_ERROR(0x00050181,
"Qfactor must be between 1 and 100, "
1507 "but was set to %i.",
qfactor);
1514 bool is_employing_color_transform)
1517 B += is_employing_color_transform ? 1 : 0;
1520 ui32 X = (
ui32) ceil(log(bibo_l * bibo_l) / M_LN2);
1527 X = (
ui32) ceil(log(bibo_h * bibo_l) / M_LN2);
1529 max_B_plus_X =
ojph_max(max_B_plus_X, B + X);
1531 max_B_plus_X =
ojph_max(max_B_plus_X, B + X);
1532 X = (
ui32) ceil(log(bibo_h * bibo_h) / M_LN2);
1534 max_B_plus_X =
ojph_max(max_B_plus_X, B + X);
1537 if (max_B_plus_X > 38)
1538 OJPH_ERROR(0x00050151,
"The specified combination of bit_depth, "
1539 "colour transform, and type of wavelet transform requires more than "
1540 "38 bits; it requires %d bits. This is beyond what is allowed in "
1541 "the JPEG2000 image coding format.", max_B_plus_X);
1544 Sqcd = (
ui8)(guard_bits << 5);
1563 Sqcd = (
ui8)((guard_bits<<5)|0x2);
1575 OJPH_ERROR(0x00050161,
"Qfactor can only be used on components "
1576 "with 4:4:4, 4:2:2 or 4:2:0 sampling");
1577 if (this->
ctype == comp_type::OJPH_COMP_Y &&
1578 this->
sampling.
x != 1 && this->sampling.y != 1)
1579 OJPH_ERROR(0x00050162,
"Qfactor can only be used for a Y or "
1580 "luminance component when it is not downsampled.");
1597 w_b = std::pow(w_b, power);
1598 encode_SPqcd(b++, delta_ref / (gain_l * gain_l * g_c * w_b));
1608 w_b = std::pow(w_b, power);
1609 encode_SPqcd(b++, delta_ref / (gain_h * gain_l * g_c * w_b));
1611 w_b = std::pow(w_b, power);
1612 encode_SPqcd(b++, delta_ref / (gain_l * gain_h * g_c * w_b));
1614 w_b = std::pow(w_b, power);
1615 encode_SPqcd(b++, delta_ref / (gain_h * gain_h * g_c * w_b));
1622 int exp = 0, mantissa;
1623 while (delta < 1.0f)
1624 { exp++; delta *= 2.0f; }
1625 mantissa = (int)round(delta * (
float)(1<<11)) - (1<<11);
1628 mantissa = mantissa < (1<<11) ? mantissa : 0x7FF;
1629 SPqcd.u16[subband_index] = (
ui16)((exp << 11) | mantissa);
1644 int irrev = p->
Sqcd & 0x1F;
1651 else if (irrev == 2)
1669 ui32 num_decompositions,
ui32 comp_num,
1672 float arr[] = { 1.0f, 2.0f, 2.0f, 4.0f };
1673 if ((
Sqcd & 0x1F) != 2)
1674 OJPH_ERROR(0x00050101,
"There is something wrong in the configuration "
1675 "of the codestream; for component %d, the codestream defines an "
1676 "irreversible transform, for which the codestream provides a "
1677 "reversible (no quantization) step sizes in Sqcd/Sqcc.", comp_num);
1680 if (dfs != NULL && dfs->
exists())
1685 OJPH_INFO(0x00050102,
"Trying to access quantization step size for "
1686 "subband %d when the QCD/QCC marker segment specifies "
1687 "quantization step sizes for %d subbands only. To continue "
1688 "decoding, we are using the step size for subband %d, which can "
1689 "produce incorrect results",
1693 int eps =
SPqcd.u16[idx] >> 11;
1695 mantissa = (float)((
SPqcd.u16[idx] & 0x7FF) | 0x800) * arr[
subband];
1696 mantissa /= (float)(1 << 11);
1697 mantissa /= (float)(1u << eps);
1708 if (
main->is_employing_color_transform() &&
comp_idx < 3)
1710 for (
ui32 i = 0; i < 3; ++i) {
1723 return precision + 1 + 1;
1737 if (dfs != NULL && dfs->
exists())
1742 OJPH_INFO(0x00050111,
"Trying to access quantization step size for "
1743 "subband %d when the QCD/QCC marker segment specifies "
1744 "quantization step sizes for %d subbands only. To continue "
1745 "decoding, we are using the step size for subband %d, which can "
1746 "produce incorrect results",
1751 int irrev =
Sqcd & 0x1F;
1756 num_bits = num_bits == 0 ? 0 : num_bits - 1;
1758 else if (irrev == 1)
1760 else if (irrev == 2)
1761 num_bits = (
SPqcd.u16[idx] >> 11) - 1;
1771 int irrev =
Sqcd & 0x1F;
1777 num_bits =
ojph_max(num_bits, t == 0 ? 0 : t - 1);
1780 else if (irrev == 1)
1782 else if (irrev == 2)
1798 int irrev =
Sqcd & 0x1F;
1804 else if (irrev == 2)
1814 buf2 = swap_bytes_if_le(buf2);
1816 buf2 = swap_bytes_if_le(
Lqcd);
1819 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1825 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1827 else if (irrev == 2)
1830 buf2 = swap_bytes_if_le(
SPqcd.u16[i]);
1857 int irrev =
Sqcd & 0x1F;
1860 Lqcd = (
ui16)(4 + (num_comps < 257 ? 0 : 1));
1863 else if (irrev == 2)
1873 buf2 = swap_bytes_if_le(buf2);
1875 buf2 = swap_bytes_if_le(
Lqcd);
1877 if (num_comps < 257)
1880 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1888 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1893 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
1895 else if (irrev == 2)
1898 buf2 = swap_bytes_if_le(
SPqcd.u16[i]);
1924 OJPH_ERROR(0x00050081,
"error reading QCD marker");
1927 OJPH_ERROR(0x00050082,
"error reading QCD marker");
1928 if ((
Sqcd & 0x1F) == 0)
1932 OJPH_ERROR(0x0005008A,
"QCD marker segment that specifies no "
1933 "quantization informtion");
1935 OJPH_ERROR(0x00050083,
"wrong Lqcd value of %d in QCD marker",
Lqcd);
1938 OJPH_ERROR(0x00050084,
"error reading QCD marker");
1940 else if ((
Sqcd & 0x1F) == 1)
1944 "Scalar derived quantization is not supported yet in QCD marker");
1946 OJPH_ERROR(0x00050085,
"wrong Lqcd value in QCD marker");
1948 else if ((
Sqcd & 0x1F) == 2)
1952 OJPH_ERROR(0x0005008B,
"QCD marker segment that specifies no "
1953 "quantization informtion");
1955 OJPH_ERROR(0x00050086,
"wrong Lqcd value of %d in QCD marker",
Lqcd);
1959 OJPH_ERROR(0x00050087,
"error reading QCD marker");
1960 SPqcd.u16[i] = swap_bytes_if_le(
SPqcd.u16[i]);
1964 OJPH_ERROR(0x00050088,
"wrong Sqcd value in QCD marker");
1971 OJPH_ERROR(0x000500A1,
"error reading QCC marker");
1973 if (num_comps < 257)
1976 if (file->
read(&v, 1) != 1)
1977 OJPH_ERROR(0x000500A2,
"error reading QCC marker");
1983 OJPH_ERROR(0x000500A3,
"error reading QCC marker");
1987 OJPH_ERROR(0x000500A4,
"error reading QCC marker");
1988 ui32 offset = num_comps < 257 ? 4 : 5;
1989 if ((
Sqcd & 0x1F) == 0)
1993 OJPH_ERROR(0x000500AC,
"QCC marker segment that specifies no "
1994 "quantization informtion");
1996 OJPH_ERROR(0x000500A5,
"wrong Lqcd value of %d in QCC marker",
Lqcd);
1999 OJPH_ERROR(0x000500A6,
"error reading QCC marker");
2001 else if ((
Sqcd & 0x1F) == 1)
2005 "Scalar derived quantization is not supported yet in QCC marker");
2007 OJPH_ERROR(0x000500A7,
"wrong Lqcc value in QCC marker");
2009 else if ((
Sqcd & 0x1F) == 2)
2013 OJPH_ERROR(0x000500AD,
"QCC marker segment that specifies no "
2014 "quantization informtion");
2016 OJPH_ERROR(0x000500A8,
"wrong Lqcc value of %d in QCC marker",
Lqcd);
2020 OJPH_ERROR(0x000500A9,
"error reading QCC marker");
2021 SPqcd.u16[i] = swap_bytes_if_le(
SPqcd.u16[i]);
2025 OJPH_ERROR(0x000500AA,
"wrong Sqcc value in QCC marker");
2044 OJPH_ERROR(0x00050191,
"Qfactor must be between 1 and 100, "
2045 "but was set to %i.",
qfactor);
2083 while (p->
next != NULL)
2107 double d = 1.0 / (double)((1ull << 32) - 1);
2118 *dp++ = *sp++ * divider;
2126 *dp++ = *sp++ * divider;
2134 *dp++ = (
float)*sp++ * divider;
2145 double d = 1.0 / (double)((1ull << 32) - 1);
2150 float mul = (float)(1ull <<
pt_val);
2151 float div = 1.0f / mul;
2162 float y_k = (float)p[k] * div, y_kp1 = (
float)p[k + 1] * div;
2172 d_kp1 =
fd_min + (float)(k + 1) * dt;
2174 y_kp1 = (float)p[k + 1] * div;
2176 enc_points[i] = d_k + (z - y_k) * dt / (y_kp1 - y_k);
2188 float y_k = (float)p[k] * div, y_kp1 = (
float)p[k + 1] * div;
2198 d_kp1 =
fd_min + (float)(k + 1) * dt;
2200 y_kp1 = (float)p[k + 1] * div;
2202 enc_points[i] = d_k + (z - y_k) * dt / (y_kp1 - y_k);
2214 float y_k = (float)p[k] * div, y_kp1 = (
float)p[k + 1] * div;
2224 d_kp1 =
fd_min + (float)(k + 1) * dt;
2226 y_kp1 = (float)p[k + 1] * div;
2228 enc_points[i] = d_k + (z - y_k) * dt / (y_kp1 - y_k);;
2238 for (
ui32 c = 0; c < num_comps; ++c)
2246 if ((type == nonlinearity::OJPH_NLT_LUT_STYLE_NLT ||
2247 type == nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT) &&
2267 OJPH_ERROR(0x000501B1,
"The LUT style nonlinearities (type 2, LUT "
2268 "style, and type 4, binary complement followed by a LUT) are "
2269 "supported with the irreversible (9/7) wavelet only; component %d of "
2270 "this codestream is coded with the reversible (5/3) wavelet. Use the "
2271 "irreversible wavelet for that component, use the binary complement "
2272 "nonlinearity (type 3), or do not use a nonlinearity with it.",
2275 if (this->
enabled && this->
rec.
Tnlt == nonlinearity::OJPH_NLT_UNDEFINED)
2279 this->
rec.
Tnlt == nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT)
2281 bool all_same =
true;
2289 bool is_signed =
false;
2290 for (
ui32 c = 0; c < num_comps; ++c)
2299 all_same = all_same && (is_signed == siz.
is_signed(c));
2315 if (all_same && bit_depth != 0)
2323 for (
ui32 c = 0; c < num_comps; ++c)
2331 p->
rec.
Tnlt = nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT;
2341 for (
ui32 c = 0; c < num_comps; ++c)
2363 OJPH_ERROR(0x00050171,
"Nonliearities other than type 0 "
2364 "(No Nonlinearity) or type 3 (Binary Binary Complement to Sign "
2365 "Magnitude Conversion) are not supported in this function call");
2376 ui8 decoded_bit_depth,
2377 bool decoded_signedness,
2379 ui16 num_points,
void* points,
2384 OJPH_ERROR(0x000501A1,
"Nonliearities other than type 1 "
2385 "(LUT Nonlinearity) or type 4 (Binary Binary Complement to Sign "
2386 "Magnitude Conversion followed by LUT Nonlinearity) are not "
2387 "supported in this function call");
2388 if (pt_val == 0 || pt_val > 32)
2389 OJPH_ERROR(0x000501A2,
"pt_val must be larger than 0 and "
2390 "smaller than or equal to 32; you provided, %d", pt_val);
2391 if (decoded_bit_depth == 0 || decoded_bit_depth > 38)
2392 OJPH_ERROR(0x000501A3,
"decoded_bit_depth must be larger than 0 and "
2393 "smaller than or equal to 38; you provided, %d", decoded_bit_depth);
2395 OJPH_ERROR(0x000501A4,
"d_max must be larger than d_min; you "
2396 "provided %d and %d", d_min, d_max);
2397 if (num_points < 2 || num_points > 8192)
2398 OJPH_ERROR(0x000501A5,
"The number of points must be larger or equal "
2399 "to 2 and smaller or equal to 8192 -- the code will convert this "
2400 "number to a number in the range 1 to 8191 for the NLT marker "
2401 "segement; you provided %d", num_points);
2409 (
ui8)((decoded_bit_depth - 1) | (decoded_signedness ? 0x80 : 0));
2419 ui32 v_min = 0, v_max = 0;
2420 ui32 smallest_gap = UINT_MAX;
2424 for (
int k = 0; k < num_points - 1; ++k)
2427 smallest_gap =
ojph_min(smallest_gap, (
ui32)(p[k+1] - p[k]));
2429 OJPH_ERROR(0x000501A6,
"The LUT must have increasing sequence "
2430 "of numbers; here we have at LUT[%d+1] <= LUT[%d], with values "
2431 "%d and %d.", k, k, p[k+1], p[k]);
2433 v_min = (
ui32)p[0]; v_max = (
ui32)p[num_points - 1];
2438 for (
int k = 0; k < num_points - 1; ++k)
2441 smallest_gap =
ojph_min(smallest_gap, (
ui32)(p[k+1] - p[k]));
2443 OJPH_ERROR(0x000501A7,
"The LUT must have increasing sequence "
2444 "of numbers; here we have at LUT[%d+1] <= LUT[%d], with values "
2445 "%d and %d.", k, k, p[k+1], p[k]);
2447 v_min = (
ui32)p[0]; v_max = (
ui32)p[num_points - 1];
2452 for (
int k = 0; k < num_points - 1; ++k)
2455 smallest_gap =
ojph_min(smallest_gap, p[k+1] - p[k]);
2457 OJPH_ERROR(0x000501A8,
"The LUT must have increasing sequence "
2458 "of numbers; here we have at LUT[%d+1] <= LUT[%d], with values "
2459 "%d and %d.", k, k, p[k+1], p[k]);
2461 v_min = (
ui32)p[0]; v_max = (
ui32)p[num_points - 1];
2468 float enc_pnts = std::ceil((
float)(v_max-v_min) / (
float)(smallest_gap));
2469 if (enc_pnts > 8192.0f)
2472 OJPH_WARN(0x000501A1,
"Encoding with LUT is performed with an "
2473 "encoding LUT, derived from the LUT you provided; however, "
2474 "because the provided LUT has almost flat segment or segments, "
2475 "these are hard to invert. We are limiting the encoding "
2476 "LUT to 8192 entries, which means that some segment of the "
2477 "LUT table might be ignored during encoding.")
2480 ienc_pnts = (
ui32)enc_pnts;
2481 ienc_pnts = 32 - count_leading_zeros(ienc_pnts);
2482 ienc_pnts = 1u << ienc_pnts;
2493 OJPH_ERROR(0x000501A9,
"Failed to allocated memory");
2506 bool& is_signed,
ui8& nl_type)
const
2510 assert(
Cnlt == special_comp_num::ALL_COMPS);
2512 p = (p && p->
enabled) ? p :
this;
2516 bit_depth = bit_depth <= 38 ? bit_depth : 38;
2517 is_signed = (p->
rec.
BDnlt & 0x80) == 0x80;
2540 buf2 = swap_bytes_if_le(buf2);
2542 buf2 = swap_bytes_if_le(p->
Lnlt);
2544 buf2 = swap_bytes_if_le(p->
Cnlt);
2548 if (p->
rec.
Tnlt == nonlinearity::OJPH_NLT_LUT_STYLE_NLT ||
2549 p->
rec.
Tnlt == nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT)
2552 buf2 = swap_bytes_if_le(buf2);
2554 buf4 = swap_bytes_if_le(p->
rec.
d_min);
2556 buf4 = swap_bytes_if_le(p->
rec.
d_max);
2563 result &= file->
write(&buf1,
sizeof(
ui8)) ==
sizeof(
ui8);
2573 memcpy(&buf2, sp, 2);
2574 buf2 = swap_bytes_if_le(buf2);
2583 memcpy(&buf4, sp, 4);
2584 buf4 = swap_bytes_if_le(buf4);
2604 result &= file->
read(&buf2_len,
sizeof(
ui16)) ==
sizeof(
ui16);
2605 result &= file->
read(&buf2_comp,
sizeof(
ui16)) ==
sizeof(
ui16);
2606 result &= file->
read(&buf1_BDnlt,
sizeof(
ui8)) ==
sizeof(
ui8);
2607 result &= file->
read(&buf1_Tnlt,
sizeof(
ui8)) ==
sizeof(
ui8);
2609 if (buf1_Tnlt != nonlinearity::OJPH_NLT_NO_NLT &&
2610 buf1_Tnlt != nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT &&
2611 buf1_Tnlt != nonlinearity::OJPH_NLT_LUT_STYLE_NLT &&
2612 buf1_Tnlt != nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT)
2613 OJPH_ERROR(0x00050141,
"Unsupported nonlinearity type in an "
2614 "NLT marker segment, with a value of", buf1_Tnlt);
2616 ui16 length = swap_bytes_if_le(buf2_len);
2617 if (buf1_Tnlt == nonlinearity::OJPH_NLT_NO_NLT ||
2618 buf1_Tnlt == nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_NLT)
2621 OJPH_ERROR(0x00050142,
"Somethins is wrong with this NLT "
2622 "marker segment -- it has an incorrect length of %d",
2626 ui16 comp = swap_bytes_if_le(buf2_comp);
2627 if (comp > 16383 && comp != special_comp_num::ALL_COMPS)
2628 OJPH_ERROR(0x00050143,
"Something is wrong with this NLT "
2629 "marker segment -- it has an incorrect component index of %d",
2638 if ((buf1_BDnlt & 0x7F) + 1 > 38)
2639 OJPH_ERROR(0x00050144,
"The NLT marker segment has an invalid bit "
2640 "depth of %d", (buf1_BDnlt & 0x7F) + 1);
2643 if (buf1_Tnlt == nonlinearity::OJPH_NLT_LUT_STYLE_NLT ||
2644 buf1_Tnlt == nonlinearity::OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT)
2646 ui16 buf2_num_points;
2647 ui32 buf4_d_min, buf4_d_max;
2650 result &= file->
read(&buf2_num_points,
sizeof(
ui16)) ==
sizeof(
ui16);
2651 result &= file->
read(&buf4_d_min,
sizeof(
ui32)) ==
sizeof(
ui32);
2652 result &= file->
read(&buf4_d_max,
sizeof(
ui32)) ==
sizeof(
ui32);
2653 result &= file->
read(&buf_pt_val,
sizeof(
ui8)) ==
sizeof(
ui8);
2655 buf2_num_points = swap_bytes_if_le(buf2_num_points);
2656 buf4_d_min = swap_bytes_if_le(buf4_d_min);
2657 buf4_d_max = swap_bytes_if_le(buf4_d_max);
2659 if (buf2_num_points < 1 || buf2_num_points > 8191)
2660 OJPH_ERROR(0x00050145,
"The NLT marker segment has an invalid "
2661 "number of points field", buf2_num_points);
2662 if (buf4_d_min >= buf4_d_max)
2663 OJPH_ERROR(0x00050146,
"In an NLT marker segment, Dmin must smaller "
2664 "than Dmax; here we have %d and %d", buf4_d_min, buf4_d_max);
2665 if (buf_pt_val == 0 || buf_pt_val > 32)
2666 OJPH_ERROR(0x00050147,
"In an NLT marker segment, the value of "
2667 "pt_val must be larger than 0 and smaller or equal to 32; "
2668 "here, we have %d", buf_pt_val);
2685 OJPH_ERROR(0x00050148,
"Failed to allocated memory");
2698 result &= file->
read(&buf2,
sizeof(
ui16)) ==
sizeof(
ui16);
2699 buf2 = swap_bytes_if_le(buf2);
2700 memcpy(dp, &buf2, 2);
2709 result &= file->
read(&buf4,
sizeof(
ui32)) ==
sizeof(
ui32);
2710 buf4 = swap_bytes_if_le(buf4);
2711 memcpy(dp, &buf4, 4);
2723 assert(
Cnlt == special_comp_num::ALL_COMPS);
2747 assert(
Cnlt == special_comp_num::ALL_COMPS);
2750 while (p && p->
Cnlt != comp_num)
2758 assert(comp_num != special_comp_num::ALL_COMPS);
2759 assert(
Cnlt == special_comp_num::ALL_COMPS);
2761 while (p->
next != NULL) {
2762 assert(p->
Cnlt != comp_num);
2783 while (p && p->
enabled ==
false)
2795 OJPH_INFO(0x00050161,
"The NLT marker segment for the "
2796 "non-existing component %d has been removed.", p->
Cnlt);
2818 this->
Psot = payload_len + 14;
2821 buf2 = swap_bytes_if_le(buf2);
2823 buf2 = swap_bytes_if_le(
Lsot);
2825 buf2 = swap_bytes_if_le(
Isot);
2827 buf4 = swap_bytes_if_le(
Psot);
2844 buf2 = swap_bytes_if_le(buf2);
2846 buf2 = swap_bytes_if_le(
Lsot);
2848 buf2 = swap_bytes_if_le(
Isot);
2850 buf4 = swap_bytes_if_le(payload_len + 14);
2865 OJPH_INFO(0x00050091,
"error reading SOT marker");
2872 OJPH_INFO(0x00050092,
"error in SOT length");
2878 OJPH_INFO(0x00050093,
"error reading tile index");
2885 OJPH_INFO(0x00050094,
"tile index in SOT marker cannot be 0xFFFF");
2891 OJPH_INFO(0x00050095,
"error reading SOT marker");
2898 OJPH_INFO(0x00050096,
"error reading SOT marker");
2904 OJPH_INFO(0x00050097,
"error reading SOT marker");
2912 OJPH_ERROR(0x00050091,
"error reading SOT marker");
2915 OJPH_ERROR(0x00050092,
"error in SOT length");
2917 OJPH_ERROR(0x00050093,
"error reading SOT tile index");
2920 OJPH_ERROR(0x00050094,
"tile index in SOT marker cannot be 0xFFFF");
2922 OJPH_ERROR(0x00050095,
"error reading SOT marker");
2925 OJPH_ERROR(0x00050096,
"error reading SOT marker");
2927 OJPH_ERROR(0x00050097,
"error reading SOT marker");
2944 OJPH_ERROR(0x000500B1,
"Trying to store %d tileparts in TLM markers, "
2945 "but at most %d can be indexed; a codestream can carry "
2946 "%d TLM marker segments of %d entries each.",
2980 buf2 = swap_bytes_if_le(buf2);
2982 buf2 = swap_bytes_if_le((
ui16)(4 + 6 * count));
2984 result &= file->
write(&Ztlm, 1) == 1;
2985 result &= file->
write(&Stlm, 1) == 1;
2986 for (
ui32 i = written; i < written + count; ++i)
2988 buf2 = swap_bytes_if_le(
pairs[i].Ttlm);
2990 buf4 = swap_bytes_if_le(
pairs[i].Ptlm);
3011 while (p && p->
Sdfs != index)
3020 ui32 d = decomp_level - 1;
3022 ui32 bits = d & 0x3;
3023 ui32 val = (
Ddfs[idx] >> (6 - 2 * bits)) & 0x3;
3034 ui32 ns[4] = { 0, 3, 1, 1 };
3056 ui32 decomp_level = 1;
3057 while (skipped_resolutions > 0)
3061 { factor.
x *= 2; factor.
y *= 2; }
3068 --skipped_resolutions;
3078 while (p->
next != NULL)
3089 return p->
read(file);
3093 OJPH_ERROR(0x000500D1,
"error reading DFS-Ldfs parameter");
3096 OJPH_ERROR(0x000500D2,
"error reading DFS-Sdfs parameter");
3099 OJPH_ERROR(0x000500D3,
"The DFS-Sdfs parameter is %d, which is "
3100 "larger than the permissible 15",
Sdfs);
3102 if (file->
read(&l_Ids, 1) != 1)
3103 OJPH_ERROR(0x000500D4,
"error reading DFS-Ids parameter");
3106 "The value of the Ids member in the DFS marker segment cannot be 0");
3107 constexpr int max_Ddfs =
sizeof(
Ddfs) * 4;
3108 if (l_Ids > max_Ddfs)
3109 OJPH_INFO(0x000500D5,
"The DFS-Ids parameter is %d; while this is "
3110 "valid, the number is unnessarily large -- you do not need more "
3111 "than %d. Please contact me regarding this issue.",
3113 Ids = l_Ids < max_Ddfs ? l_Ids : max_Ddfs;
3114 for (
int i = 0; i <
Ids; i += 4)
3115 if (file->
read(&
Ddfs[i / 4], 1) != 1)
3116 OJPH_ERROR(0x000500D6,
"error reading DFS-Ddfs parameters");
3117 for (
int i =
Ids; i < l_Ids; i += 4)
3118 if (file->
read(&t, 1) != 1)
3119 OJPH_ERROR(0x000500D7,
"error reading DFS-Ddfs parameters");
3142 if (index == 0) { this->
init_irv97();
return this; }
3143 else if (index == 1) { this->
init_rev53();
return this; }
3150 if (p == NULL && (index == 0 || index == 1))
3157 else if (index == 1)
3168 if (coeff_type == 0) {
3170 if (file->
read(&v, 1) != 1)
return false;
3174 else if (coeff_type == 1) {
3176 if (file->
read(&v, 2) != 2)
return false;
3178 K = swap_bytes_if_le(v);
3180 else if (coeff_type == 2) {
3182 if (file->
read(&i,
sizeof(
ui32)) !=
sizeof(
ui32))
return false;
3184 i = swap_bytes_if_le(i);
3186 memcpy(&f, &i,
sizeof(
float));
3189 else if (coeff_type == 3) {
3191 if (file->
read(&i,
sizeof(
ui64)) !=
sizeof(
ui64))
return false;
3193 i = swap_bytes_if_le(i);
3195 memcpy(&
d, &i,
sizeof(
double));
3198 else if (coeff_type == 4) {
3200 if (file->
read(&v, 8) != 8)
return false;
3202 if (file->
read(&v1, 8) != 8)
return false;
3204 v = swap_bytes_if_le(v);
3209 si32 e = (
si32)((v >> 48) & 0x7FFF);
3215 i |= ((
ui32)(v >> 32) & 0x80000000);
3217 i |= (
ui32)((v >> 25) & 0x007FFFFF);
3219 memcpy(&f, &i,
sizeof(
float));
3230 if (coeff_type == 0) {
3232 if (file->
read(&v, 1) != 1)
return false;
3236 else if (coeff_type == 1) {
3238 if (file->
read(&v, 2) != 2)
return false;
3240 K = (
si16)swap_bytes_if_le((
ui16)v);
3254 OJPH_ERROR(0x000500E1,
"error reading ATK-Latk parameter");
3258 if (file->
read(&temp_Satk, 2) != 2)
3259 OJPH_ERROR(0x000500E2,
"error reading ATK-Satk parameter");
3261 temp_Satk = swap_bytes_if_le(temp_Satk);
3262 int tmp_idx = temp_Satk & 0xFF;
3264 || tmp_idx == 0 || tmp_idx == 1)
3265 OJPH_ERROR(0x000500F3,
"ATK-Satk parameter sets ATK marker index to "
3266 "the illegal value of %d. ATK-Satk should be in (2-255) and, I "
3267 "believe, must not be repeated; otherwise, it would be unclear "
3268 "what marker segment must be employed when an index is repeated.",
3272 OJPH_ERROR(0x000500E3,
"ATK-Satk parameter sets m_init to 1, "
3273 "requiring odd-indexed subsequence in first reconstruction step, "
3274 "which is not supported yet.");
3276 OJPH_ERROR(0x000500E4,
"ATK-Satk parameter specified ARB filter, "
3277 "which is not supported yet.");
3279 OJPH_ERROR(0x000500E5,
"ATK-Satk parameter does not make sense. "
3280 "It employs floats with reversible filtering.");
3282 OJPH_ERROR(0x000500E6,
"ATK-Satk parameter requires constant "
3283 "boundary extension, which is not supported yet.");
3286 OJPH_ERROR(0x000500E7,
"error reading ATK-Katk parameter");
3288 OJPH_ERROR(0x000500E8,
"error reading ATK-Natk parameter");
3299 for (
int s = 0; s <
Natk; ++s)
3302 OJPH_ERROR(0x000500E9,
"error reading ATK-Eatk parameter");
3305 OJPH_ERROR(0x000500EA,
"error reading ATK-Batk parameter");
3309 if (file->
read(&LCatk, 1) != 1)
3310 OJPH_ERROR(0x000500EB,
"error reading ATK-LCatk parameter");
3313 OJPH_ERROR(0x000500EC,
"Encountered a ATK-LCatk value of zero; "
3314 "something is wrong.");
3316 OJPH_ERROR(0x000500ED,
"ATK-LCatk value greater than 1; "
3317 "that is, a multitap filter is not supported");
3319 OJPH_ERROR(0x000500EE,
"Error reding ATK-Aatk parameter");
3324 for (
int s = 0; s <
Natk; ++s)
3327 if (file->
read(&LCatk, 1) != 1)
3328 OJPH_ERROR(0x000500EF,
"error reading ATK-LCatk parameter");
3331 OJPH_ERROR(0x000500F0,
"Encountered a ATK-LCatk value of zero; "
3332 "something is wrong.");
3334 OJPH_ERROR(0x000500F1,
"ATK-LCatk value greater than 1; "
3335 "that is, a multitap filter is not supported.");
3337 OJPH_ERROR(0x000500F2,
"Error reding ATK-Aatk parameter");
3341 OJPH_ERROR(0x000500F3,
"The length of an ATK marker segment "
3342 "(ATK-Latk) is not correct");
3351 Katk = (float)1.230174104914001;
3355 d[0].
irv.
Aatk = (float)0.443506852043971;
3356 d[1].
irv.
Aatk = (float)0.882911075530934;
3357 d[2].
irv.
Aatk = (float)-0.052980118572961;
3358 d[3].
irv.
Aatk = (float)-1.586134342059924;
3381 while (p->
next != NULL)
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]
static const float * get_weights(ui32 format, ui32 comp_type)
static const float no_weights[19]
static const float * get_no_weights()
static const float cr444[19]
static const float cb422[19]
static const float cr422[19]
static const float cb420[19]
static float get_delta_ref(float qfactor, ui32 bit_depth, float &power)
static const float cr420[19]
static colour_format get_format(const point &component_subsampling)
static const float cb444[19]
param_qcd::comp_type comp_type
static float get_weight(const float *v, ui32 decomposition_level, ui32 subband_idx)
static float get_gain(ui32 comp_type)
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)
@ OJPH_NLT_BINARY_COMPLEMENT_NLT
@ OJPH_NLT_BINARY_COMPLEMENT_PLUS_LUT
bool get_nonlinear_transform(ui32 comp_num, ui8 &decoded_bit_depth, bool &decoded_signedness, ui8 &nl_type) const
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
void set_qfactor(float qfactor)
Sets Qfactor.
void set_irrev_quant(float delta)
Set the irreversible quantization base delta.
static comp_type ui8_2_comp_type(ui8 c)
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
const char OJPH_PO_STRING_PCRL[]
const char OJPH_PO_STRING_RLCP[]
const char OJPH_PO_STRING_RPCL[]
const char OJPH_PO_STRING_CPRL[]
const char OJPH_PO_STRING_LRCP[]
int main(int argc, char *argv[])
#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,...)
ui32 cal_store_size_for_encoding(ui32 enc_num_points)
void assign_pointers_for_decoding()
ui32 cal_store_size_for_decoding()
void prepare_for_decoding()
ui8 get_bit_depth() const
void prepare_for_encoding()
void assign_pointers_for_encoding()
static ui8 get_bpp(ui32 t)
bool read_coefficient(infile_base *file, float &K, si32 &bytes)
void init(param_atk *top_atk)
bool is_reversible() const
bool read(infile_base *file)
int get_coeff_type() const
param_atk * get_atk(int index)
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
const param_cod * get_coc(ui32 comp_idx) const
bool internal_write_coc(outfile_base *file, ui32 num_comps)
size get_log_block_dims() const
ui16 get_dfs_index() const
bool write_coc(outfile_base *file, ui32 num_comps)
void set_reversible(bool reversible)
bool is_employing_color_transform() const
void employ_color_transform(ui8 val)
ui32 get_comp_idx() const
bool get_block_vertical_causality() const
void read(infile_base *file)
size get_log_precinct_size(ui32 res_num) const
void init(param_cod *top_cod, ui16 comp_idx)
void read_coc(infile_base *file, ui32 num_comps, param_cod *top_cod)
void update_atk(param_atk *atk)
bool is_dfs_defined() const
bool packets_use_eph() const
ui8 get_num_decompositions() const
bool packets_may_use_sop() const
bool is_reversible() const
size get_precinct_size(ui32 res_num) const
param_cod * get_or_add_coc(ui32 comp_idx)
param_cod(param_cod *top_cod=NULL, ui16 comp_idx=OJPH_COD_DEFAULT)
ui8 get_wavelet_kern() const
param_cod * add_coc_object(ui32 comp_idx)
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
bool write(outfile_base *file) const
param_nlt * add_object(ui32 comp_num)
void trim_non_existing_components(ui32 num_comps)
ojph::param_nlt::nonlinearity nonlinearity
void check_validity(param_siz &siz, const param_cod &cod)
const param_nlt * get_nlt_object(ui32 comp_num) const
bool read(infile_base *file)
int find_unsupported_nlt(const param_siz &siz, const param_cod &cod) const
bool is_any_enabled() const
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
const nlt_rec * get_nlt_rec(ui32 comp_num) const
bool get_nonlinear_transform(ui32 comp_num, ui8 &decoded_bit_depth, bool &decoded_signedness, ui8 &nl_type) const
const float QFACTOR_UNSET
bool write_qcc(outfile_base *file, ui32 num_comps)
float get_irrev_delta(const param_dfs *dfs, ui32 num_decompositions, ui32 comp_num, ui32 resolution, ui32 subband) 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_largest_Kmax() const
ui32 get_num_guard_bits() const
void set_delta(float delta)
void read_qcc(infile_base *file, ui32 num_comps)
void check_validity(const param_siz &siz, const param_cod &cod)
bool write(outfile_base *file)
ui32 propose_precision(const param_cod *cod) const
void read(infile_base *file)
bool is_qcc_needed(ui32 comp_num, const param_cod &cod, const param_siz &siz)
void make_quant_steps(ui32 comp_num, const param_cod &cod, const param_siz &siz)
void init(param_qcd *top_qcd, ui16 comp_idx)
param_qcd * add_qcc_object(ui32 comp_idx)
ui32 get_Kmax(const param_dfs *dfs, ui32 num_decompositions, ui32 resolution, ui32 subband) const
ojph::param_qcd::comp_type comp_type
void encode_SPqcd(ui32 subband_index, float delta)
ui8 decode_SPqcd(ui8 v) const
param_qcd * get_qcc(ui32 comp_idx)
param_qcd(param_qcd *top_qcd=NULL, ui16 comp_idx=OJPH_QCD_DEFAULT)
void trim_non_existing_components(ui32 num_comps)
void set_qfactor(float qfactor)
bool internal_write_qcc(outfile_base *file, ui32 num_comps)
union ojph::local::param_qcd::@140013103227173134364232343330020031205064137337 SPqcd
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
void set_image_offset(point offset)
bool write(outfile_base *file)
ui16 get_num_components() const
void set_tile_size(size s)
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 set_tile_offset(point offset)
void read(infile_base *file)
void set_num_components(ui32 num_comps)
void set_image_extent(point dims)
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)
point(ui32 x=0, ui32 y=0)