57 return (
ui16)((v<<8) | (v>>8));
77 if (c ==
' ' || c ==
'\r' || c ==
'\n' || c ==
'\t')
81 while (c !=
'\n') c = fgetc(fh);
106 int max_val = (1 << bit_depth) - 1;
109 for ( ; count > 0; --count)
112 val = val >= 0 ? val : 0;
113 val = val <= max_val ? val : max_val;
122 int max_val = (1<<bit_depth) - 1;
127 for (; count > 0; --count)
131 val = val >= 0 ? val : 0;
132 val = val <= max_val ? val : max_val;
135 val = val >= 0 ? val : 0;
136 val = val <= max_val ? val : max_val;
139 val = val >= 0 ? val : 0;
140 val = val <= max_val ? val : max_val;
145 void gen_cvrt_32b1c_to_16ub1c_le(
const line_buf *ln0,
const line_buf *ln1,
146 const line_buf *ln2,
void *dp,
151 int max_val = (1<<bit_depth) - 1;
152 const si32 *sp = ln0->i32;
154 for (; count > 0; --count)
157 val = val >= 0 ? val : 0;
158 val = val <= max_val ? val : max_val;
167 int max_val = (1<<bit_depth) - 1;
168 const si32 *sp0 = ln0->i32;
169 const si32 *sp1 = ln1->i32;
170 const si32 *sp2 = ln2->i32;
172 for (; count > 0; --count)
176 val = val >= 0 ? val : 0;
177 val = val <= max_val ? val : max_val;
180 val = val >= 0 ? val : 0;
181 val = val <= max_val ? val : max_val;
184 val = val >= 0 ? val : 0;
185 val = val <= max_val ? val : max_val;
196 int max_val = (1<<bit_depth) - 1;
199 for (; count > 0; --count)
202 val = val >= 0 ? val : 0;
203 val = val <= max_val ? val : max_val;
212 int max_val = (1<<bit_depth) - 1;
217 for (; count > 0; --count)
221 val = val >= 0 ? val : 0;
222 val = val <= max_val ? val : max_val;
225 val = val >= 0 ? val : 0;
226 val = val <= max_val ? val : max_val;
229 val = val >= 0 ? val : 0;
230 val = val <= max_val ? val : max_val;
248 fh = fopen(filename,
"rb");
250 OJPH_ERROR(0x03000001,
"Unable to open file %s", filename);
255 if (fread(t, 1, 2,
fh) != 2)
258 OJPH_ERROR(0x03000002,
"Error reading file %s", filename);
262 if (t[0] !=
'P' || (t[1] !=
'5' && t[1] !=
'6'))
265 OJPH_ERROR(0x03000003,
"unknown file type for file %s", filename);
268 size_t len = strlen(filename);
269 if (t[1] ==
'5' && strncmp(filename + len - 4,
".pgm", 4) != 0)
272 OJPH_ERROR(0x03000004,
"wrong file extension, a file with "
273 "keyword P5 must have a .pgm extension for file %s", filename);
275 if (t[1] ==
'6' && strncmp(filename + len - 4,
".ppm", 4) != 0)
278 OJPH_ERROR(0x03000005,
"wrong file extension, a file with keyword P6 "
279 "must have a .ppm extension for file %s", filename);
290 OJPH_ERROR(0x03000006,
"error in file format for file %s", filename);
312 OJPH_ERROR(0x03000007,
"error allocating memory");
343 if (
planar || comp_num == 0)
345 size_t result = fread(
388 assert(
fh == NULL &&
buffer == NULL);
391 size_t len = strlen(filename);
394 if (strncmp(
".ppm", filename + len - 4, 4) == 0)
396 filename[len - 2] =
'g';
397 OJPH_WARN(0x03000021,
"file was renamed %s\n", filename);
399 if (strncmp(
".PPM", filename + len - 4, 4) == 0)
401 filename[len - 2] =
'G';
402 OJPH_WARN(0x03000022,
"file was renamed %s\n", filename);
405 fh = fopen(filename,
"wb");
408 "unable to open file %s for writing", filename);
416 size_t len = strlen(filename);
419 if (strncmp(
".pgm", filename + len - 4, 4) == 0)
421 filename[len - 2] =
'p';
422 OJPH_WARN(0x03000024,
"file was renamed %s\n", filename);
424 if (strncmp(
".PGM", filename + len - 4, 4) == 0)
426 filename[len - 2] =
'P';
427 OJPH_WARN(0x03000025,
"file was renamed %s\n", filename);
430 fh = fopen(filename,
"wb");
433 "unable to open file %s for writing", filename);
437 OJPH_ERROR(0x03000027,
"error writing to file %s", filename);
452 "ppm supports 3 colour components, while pgm supports 1");
461#if !defined(OJPH_ENABLE_WASM_SIMD) || !defined(OJPH_EMSCRIPTEN)
476 #ifndef OJPH_DISABLE_SIMD
478 #if (defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
480 #ifndef OJPH_DISABLE_SSE4
497 #ifndef OJPH_DISABLE_AVX2
514 #elif defined(OJPH_ARCH_ARM)
543 lptr[comp_num] = line;
549 size_t result = fwrite(
buffer,
569 fh = fopen(filename,
"rb");
571 OJPH_ERROR(0x03000051,
"Unable to open file %s", filename);
576 if (fread(t, 1, 2,
fh) != 2)
579 OJPH_ERROR(0x03000052,
"Error reading file %s", filename);
583 if (t[0] !=
'P' || (t[1] !=
'F' && t[1] !=
'f'))
586 OJPH_ERROR(0x03000053,
"Unknown file type for file %s", filename);
598 "Error reading width and height in file %s", filename);
603 if (fscanf(
fh,
"%f", &
scale) != 1)
606 OJPH_ERROR(0x03000055,
"Error reading scale in file %s", filename);
627 OJPH_ERROR(0x03000056,
"Error allocating memory");
659 * (
size_t)
width *
sizeof(float);
711 *dp.u++ =
be2le(*sp.u);
732 assert(
fh == NULL &&
buffer == NULL);
733 fh = fopen(filename,
"wb");
736 "Unable to open file %s for writing", filename);
738 fprintf(
fh,
"P%c\n%d %d\n%f\n",
741 OJPH_ERROR(0x03000072,
"error writing to file %s", filename);
760 bool is_write_little_endian_on_disk =
763 this->scale = is_write_little_endian_on_disk ? -
scale :
scale;
791 *dp.u = needs_swap ?
be2le(u) : u;
795 *dp.u = needs_swap ?
be2le(*sp.u) : *sp.u;
804 size_t result = fwrite(
buffer,
sizeof(
float), samples_per_line,
fh);
805 if (result != samples_per_line)
820#ifdef OJPH_ENABLE_TIFF_SUPPORT
822 void tif_in::open(
const char* filename)
825 if ((tiff_handle = TIFFOpen(filename,
"r")) == NULL)
826 OJPH_ERROR(0x03000091,
"Unable to open file %s", filename);
830 ui32 tiff_height = 0;
831 TIFFGetField(tiff_handle, TIFFTAG_IMAGEWIDTH, &tiff_width);
832 TIFFGetField(tiff_handle, TIFFTAG_IMAGELENGTH, &tiff_height);
834 ui16 tiff_bits_per_sample = 0;
835 ui16 tiff_samples_per_pixel = 0;
836 TIFFGetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, &tiff_bits_per_sample);
837 TIFFGetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, &tiff_samples_per_pixel);
840 tiff_samples_per_pixel =
841 (tiff_samples_per_pixel < 1) ? 1 : tiff_samples_per_pixel;
843 ui16 tiff_planar_configuration = 0;
844 ui16 tiff_photometric = 0;
845 TIFFGetField(tiff_handle, TIFFTAG_PLANARCONFIG, &tiff_planar_configuration);
846 TIFFGetField(tiff_handle, TIFFTAG_PHOTOMETRIC, &tiff_photometric);
848 planar_configuration = tiff_planar_configuration;
850 ui16 tiff_compression = 0;
851 ui32 tiff_rows_per_strip = 0;
852 TIFFGetField(tiff_handle, TIFFTAG_COMPRESSION, &tiff_compression);
853 TIFFGetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, &tiff_rows_per_strip);
855 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE)
857 bytes_per_line = tiff_samples_per_pixel * TIFFScanlineSize64(tiff_handle);
861 bytes_per_line = TIFFScanlineSize64(tiff_handle);
864 line_buffer = malloc(bytes_per_line);
865 if (NULL == line_buffer)
866 OJPH_ERROR(0x03000092,
"Unable to allocate %d bytes for line_buffer[] "
867 "for file %s", bytes_per_line, filename);
872 if( tiff_bits_per_sample != 8 && tiff_bits_per_sample != 16 )
874 OJPH_ERROR(0x03000093,
"\nTIFF IO is currently limited"
875 " to files with TIFFTAG_BITSPERSAMPLE=8 and TIFFTAG_BITSPERSAMPLE=16 \n"
876 "input file = %s has TIFFTAG_BITSPERSAMPLE=%d",
877 filename, tiff_bits_per_sample);
880 if( TIFFIsTiled( tiff_handle ) )
882 OJPH_ERROR(0x03000094,
"\nTIFF IO is currently limited to TIF files "
883 "without tiles. \nInput file %s has been detected as tiled", filename);
886 if(PHOTOMETRIC_RGB != tiff_photometric &&
887 PHOTOMETRIC_MINISBLACK != tiff_photometric )
889 OJPH_ERROR(0x03000095,
"\nTIFF IO is currently limited to "
890 "TIFFTAG_PHOTOMETRIC=PHOTOMETRIC_MINISBLACK=%d and "
891 "PHOTOMETRIC_RGB=%d. \nInput file %s has been detected "
892 "TIFFTAG_PHOTOMETRIC=%d",
893 PHOTOMETRIC_MINISBLACK, PHOTOMETRIC_RGB, filename, tiff_photometric);
896 if( tiff_samples_per_pixel > 4 )
898 OJPH_ERROR(0x03000096,
"\nTIFF IO is currently limited to "
899 "TIFFTAG_SAMPLESPERPIXEL=4 \nInput file %s has been detected with "
900 "TIFFTAG_SAMPLESPERPIXEL=%d",
901 filename, tiff_samples_per_pixel);
906 height = tiff_height;
907 num_comps = tiff_samples_per_pixel;
908 bytes_per_sample = (tiff_bits_per_sample + 7) / 8;
909 for (
ui32 comp_num = 0; comp_num < num_comps; comp_num++)
910 bit_depth[comp_num] = tiff_bits_per_sample;
914 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
915 bytes_per_sample == 1)
917 line_buffer_for_planar_support_uint8 =
918 (uint8_t*)calloc(width,
sizeof(uint8_t));
919 if (NULL == line_buffer_for_planar_support_uint8)
920 OJPH_ERROR(0x03000097,
"Unable to allocate %d bytes for "
921 "line_buffer_for_planar_support_uint8[] for file %s",
922 width *
sizeof(uint8_t), filename);
924 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
925 bytes_per_sample == 2)
927 line_buffer_for_planar_support_uint16 =
928 (uint16_t*)calloc(width,
sizeof(uint16_t));
929 if (NULL == line_buffer_for_planar_support_uint16)
930 OJPH_ERROR(0x03000098,
"Unable to allocate %d bytes for "
931 "line_buffer_for_planar_support_uint16[] for file %s",
932 width *
sizeof(uint16_t), filename);
939 void tif_in::set_bit_depth(
ui32 num_bit_depths,
ui32* bit_depth)
941 if (num_bit_depths < 1)
942 OJPH_ERROR(0x030000A1,
"one or more bit_depths must be provided");
943 ui32 last_bd_idx = 0;
944 for (
ui32 i = 0; i < 4; ++i)
946 ui32 bd = bit_depth[i < num_bit_depths ? i : last_bd_idx];
947 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
949 if (bd > 32 || bd < 1)
952 "bit_depth = %d, this must be an integer from 1-32", bd);
954 this->bit_depth[i] = bd;
961 assert(bytes_per_line != 0 && tiff_handle != 0 && comp_num < num_comps);
962 assert((
ui32)line->size >= width);
966 if (PLANARCONFIG_SEPARATE == planar_configuration && 0 == comp_num )
968 for (
ui32 color = 0; color < num_comps; color++)
970 if (bytes_per_sample == 1)
972 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint8,
973 cur_line, (
ui16)color);
975 uint8_t* line_buffer_of_interleaved_components =
976 (uint8_t*)line_buffer;
977 for (
ui32 i = 0; i < width; i++, x += num_comps)
979 line_buffer_of_interleaved_components[x] =
980 line_buffer_for_planar_support_uint8[i];
983 else if (bytes_per_sample == 2)
985 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint16,
986 cur_line, (
ui16)color);
988 ui16* line_buffer_of_interleaved_components = (
ui16*)line_buffer;
989 for (
ui32 i = 0; i < width; i++, x += num_comps)
991 line_buffer_of_interleaved_components[x] =
992 line_buffer_for_planar_support_uint16[i];
999 else if (planar_configuration == PLANARCONFIG_CONTIG && 0 == comp_num)
1001 TIFFReadScanline(tiff_handle, line_buffer, cur_line++);
1003 if (cur_line >= height)
1008 if (bytes_per_sample == 1)
1010 const ui8* sp = (
ui8*)line_buffer + comp_num;
1011 si32* dp = line->i32;
1012 if (bit_depth[comp_num] == 8)
1014 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1017 else if (bit_depth[comp_num] < 8)
1020 const int bits_to_shift = 8 - (int)bit_depth[comp_num];
1021 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1022 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1023 *dp++ = (
si32) (((*sp) >> bits_to_shift) & bit_mask);
1025 else if (bit_depth[comp_num] > 8)
1027 const int bits_to_shift = (int)bit_depth[comp_num] - 8;
1028 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1029 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1030 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1033 else if(bytes_per_sample == 2)
1035 if (bit_depth[comp_num] == 16)
1037 const ui16* sp = (
ui16*)line_buffer + comp_num;
1038 si32* dp = line->i32;
1039 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1042 else if (bit_depth[comp_num] < 16)
1045 const int bits_to_shift = 16 - (int)bit_depth[comp_num];
1046 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1047 const ui16* sp = (
ui16*)line_buffer + comp_num;
1048 si32* dp = line->i32;
1049 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1050 *dp++ = (
si32)(((*sp) >> bits_to_shift) & bit_mask);
1052 else if (bit_depth[comp_num] > 16)
1054 const int bits_to_shift = (int)bit_depth[comp_num] - 16;
1055 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1056 const ui16* sp = (
ui16*)line_buffer + comp_num;
1057 si32* dp = line->i32;
1058 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1059 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1076 void tif_out::open(
char* filename)
1079 ui32 max_bitdepth = 0;
1080 for (
ui32 c = 0; c < num_components; c++)
1082 if (bit_depth_of_data[c] > max_bitdepth)
1083 max_bitdepth = bit_depth_of_data[c];
1085 if (max_bitdepth > 16)
1087 OJPH_WARN(0x030000B1,
"TIFF output is currently limited to files "
1088 "with max_bitdepth = 16, the source codestream has max_bitdepth=%d"
1089 ", the decoded data will be truncated to 16 bits", max_bitdepth);
1091 if (num_components > 4)
1093 OJPH_ERROR(0x030000B2,
"TIFF IO is currently limited to files with "
1094 "num_components=1 to 4");
1097 assert(tiff_handle == NULL && buffer == NULL);
1098 if ((tiff_handle = TIFFOpen(filename,
"w")) == NULL)
1100 OJPH_ERROR(0x030000B3,
"unable to open file %s for writing", filename);
1103 buffer_size = width * (size_t)num_components * (
size_t)bytes_per_sample;
1104 buffer = (
ui8*)malloc(buffer_size);
1111 TIFFSetField(tiff_handle, TIFFTAG_IMAGEWIDTH, width);
1112 TIFFSetField(tiff_handle, TIFFTAG_IMAGELENGTH, height);
1114 TIFFSetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, bytes_per_sample * 8);
1115 TIFFSetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, num_components);
1117 planar_configuration = PLANARCONFIG_CONTIG;
1118 TIFFSetField(tiff_handle, TIFFTAG_PLANARCONFIG, planar_configuration);
1120 if (num_components == 1)
1122 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1124 else if (num_components == 2)
1126 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1129 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1130 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1131 &extra_samples_description);
1133 else if (num_components == 3)
1135 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1137 else if (num_components == 4)
1139 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1142 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1143 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1144 &extra_samples_description);
1147 TIFFSetField(tiff_handle, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1148 TIFFSetField(tiff_handle, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1150 TIFFSetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, height);
1155 void tif_out::configure(
ui32 width,
ui32 height,
ui32 num_components,
1158 assert(tiff_handle == NULL);
1160 this->width = width;
1161 this->height = height;
1162 this->num_components = num_components;
1163 ui32 max_bitdepth = 0;
1164 for (
ui32 c = 0; c < num_components; c++)
1166 this->bit_depth_of_data[c] = bit_depth[c];
1167 if (bit_depth[c] > max_bitdepth)
1168 max_bitdepth = bit_depth[c];
1171 bytes_per_sample = (max_bitdepth + 7) / 8;
1172 if (bytes_per_sample > 2)
1176 bytes_per_sample = 2;
1178 samples_per_line = num_components * width;
1179 bytes_per_line = bytes_per_sample * (size_t)samples_per_line;
1186 assert(tiff_handle);
1188 if (bytes_per_sample == 1)
1190 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1191 const si32* sp = line->i32;
1192 ui8* dp = buffer + comp_num;
1193 if (bit_depth_of_data[comp_num] == 8)
1195 for (
ui32 i = width; i > 0; --i, dp += num_components)
1199 val = val >= 0 ? val : 0;
1200 val = val <= max_val ? val : max_val;
1204 else if (bit_depth_of_data[comp_num] < 8)
1206 const int bits_to_shift = 8 - (int)bit_depth_of_data[comp_num];
1207 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1208 for (
ui32 i = width; i > 0; --i, dp += num_components)
1212 val = val >= 0 ? val : 0;
1213 val = val <= max_val ? val : max_val;
1216 *dp = (
ui8)((val & bit_mask) << bits_to_shift);
1219 else if (bit_depth_of_data[comp_num] > 8)
1221 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 8;
1222 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1223 for (
ui32 i = width; i > 0; --i, dp += num_components)
1227 val = val >= 0 ? val : 0;
1228 val = val <= max_val ? val : max_val;
1231 *dp = (
ui8)((val >> bits_to_shift) & bit_mask);
1236 else if(bytes_per_sample == 2)
1238 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1239 const si32* sp = line->i32;
1240 ui16* dp = (
ui16*)buffer + comp_num;
1242 if (bit_depth_of_data[comp_num] == 16)
1244 for (
ui32 i = width; i > 0; --i, dp += num_components)
1248 val = val >= 0 ? val : 0;
1249 val = val <= max_val ? val : max_val;
1253 else if (bit_depth_of_data[comp_num] < 16)
1255 const int bits_to_shift = 16 - (int)bit_depth_of_data[comp_num];
1256 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1257 for (
ui32 i = width; i > 0; --i, dp += num_components)
1261 val = val >= 0 ? val : 0;
1262 val = val <= max_val ? val : max_val;
1266 *dp = (
ui16)((val & bit_mask) << bits_to_shift);
1269 else if (bit_depth_of_data[comp_num] > 16)
1271 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 16;
1272 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1273 for (
ui32 i = width; i > 0; --i, dp += num_components)
1277 val = val >= 0 ? val : 0;
1278 val = val <= max_val ? val : max_val;
1282 *dp = (
ui16)((val >> bits_to_shift) & bit_mask);
1288 if (comp_num == num_components-1)
1290 int result = TIFFWriteScanline(tiff_handle, buffer, cur_line++);
1292 OJPH_ERROR(0x030000C1,
"error writing to file %s", fname);
1310 fh = fopen(filename,
"rb");
1312 OJPH_ERROR(0x030000D1,
"Unable to open file %s", filename);
1337 if (result !=
width[comp_num])
1347 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1355 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1359 return width[comp_num];
1366 if (num_components != 1 && num_components !=3)
1367 OJPH_ERROR(0x030000F1,
"yuv_in support 1 or 3 components");
1368 this->
num_com = num_components;
1370 if (num_downsamplings < 1)
1371 OJPH_ERROR(0x030000F2,
"one or more downsampling must be provided");
1373 ui32 last_downsamp_idx = 0;
1374 for (
ui32 i = 0; i < num_components; ++i)
1377 last_downsamp_idx += last_downsamp_idx + 1 < num_downsamplings ? 1 : 0;
1379 this->subsampling[i] = cp_ds;
1382 for (
ui32 i = 0; i < num_components; ++i)
1392 if (num_bit_depths < 1)
1393 OJPH_ERROR(0x03000101,
"one or more bit_depths must be provided");
1394 ui32 last_bd_idx = 0;
1395 for (
ui32 i = 0; i < 3; ++i)
1398 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
1400 this->bit_depth[i] = bd;
1433 fh = fopen(filename,
"wb");
1435 OJPH_ERROR(0x03000111,
"Unable to open file %s", filename);
1451 tw =
ojph_max(tw, this->comp_width[i]);
1470 for (
ui32 i = w; i > 0; --i)
1473 val = val >= 0 ? val : 0;
1474 val = val <= max_val ? val : max_val;
1484 for (
ui32 i = w; i > 0; --i)
1487 val = val >= 0 ? val : 0;
1488 val = val <= max_val ? val : max_val;
1510 fh = fopen(filename,
"rb");
1512 OJPH_ERROR(0x03000131,
"Unable to open file %s", filename);
1525 assert(comp_num == 0);
1527 if (result !=
width)
1552 for (
ui32 i =
width; i > 0; --i, sp += 3) {
1555 val |= (val & 0x800000) ? (
si32)0xFF000000 : 0;
1560 for (
ui32 i =
width; i > 0; --i, sp += 3)
1632 fh = fopen(filename,
"wb");
1634 OJPH_ERROR(0x03000141,
"Unable to open file %s", filename);
1644 this->width =
width;
1664 assert(comp_num == 0);
1692 *dp++ = (
ui8)(val >> 8);
1693 *dp++ = (
ui8)(val >> 16);
1754 *dp++ = (
ui8)(val >> 8);
1755 *dp++ = (
ui8)(val >> 16);
1809 OJPH_ERROR(0x03000161,
"Unable to open file %s", filename);
1817 OJPH_ERROR(0x03000162,
"Error reading file %s", filename);
1821 const ui32 dpx_magic_number = 0x53445058;
1822 if (dpx_magic_number == magic_number)
1827 else if (dpx_magic_number ==
be2le(magic_number))
1836 OJPH_ERROR(0x03000163,
"Error reading file %s - this does not appear "
1837 "to be a valid DPX file. It has magic number = 0x%08X. The magic "
1838 "number of a DPX file is 0x%08X.", filename, magic_number,
1847 OJPH_ERROR(0x03000164,
"Error reading file %s", filename);
1855 OJPH_ERROR(0x03000165,
"Error reading file %s", filename);
1862 OJPH_ERROR(0x03000166,
"Error reading file %s", filename);
1871 OJPH_ERROR(0x03000167,
"Error reading file %s", filename);
1878 OJPH_ERROR(0x03000168,
"Error reading file %s", filename);
1888 OJPH_ERROR(0x03000169,
"Error reading file %s", filename);
1897 OJPH_ERROR(0x0300016A,
"Error reading file %s", filename);
1906 OJPH_ERROR(0x0300016B,
"Error reading file %s", filename);
1915 OJPH_ERROR(0x0300016C,
"Error reading file %s", filename);
1923 OJPH_ERROR(0x0300016E,
"Error reading file %s", filename);
1932 OJPH_ERROR(0x0300016F,
"Error reading file %s", filename);
1940 OJPH_ERROR(0x03000170,
"Error reading file %s", filename);
1948 OJPH_ERROR(0x03000171,
"Error reading file %s", filename);
1956 OJPH_ERROR(0x03000172,
"Error reading file %s", filename);
1964 OJPH_ERROR(0x03000173,
"Error reading file %s", filename);
1972 OJPH_ERROR(0x03000174,
"Error reading file %s", filename);
1982 OJPH_ERROR(0x03000175,
"Error reading file %s", filename);
1992 OJPH_ERROR(0x03000176,
"Error reading file %s", filename);
2002 OJPH_ERROR(0x03000177,
"Error reading file %s", filename);
2021 / number_of_samples_per_32_bit_word;
2028 OJPH_ERROR(0x03000178,
"Unable to allocate %d bytes for line_buffer[] "
2036 OJPH_ERROR(0x03000179,
"Unable to allocate %d bytes for "
2037 "line_buffer_16bit_samples[] for file %s",
2068 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2076 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2083 ui32 word_index = 0;
2092 (
ui16) ((line_buffer_ptr[word_index] & 0xFFC00000) >> 22);
2095 (
ui16) ((line_buffer_ptr[word_index] & 0x003FF000) >> 12);
2098 (
ui16) ((line_buffer_ptr[word_index] & 0x00000FFC) >> 2);
2112 OJPH_ERROR(0x03000182,
"file %s uses DPX image formats that are not "
2113 "yet supported by this software\n bitdepth_for_image_element_1 = "
2114 "%d\n num_comps=%d\npacking_for_image_element_1=%d\n "
2115 "descriptor_for_image_element_1=%d",
fname,
ui32 get_num_components()
size_t number_of_32_bit_words_per_line
void open(const char *filename)
ui16 packing_for_image_element_1
ui8 descriptor_for_image_element_1
ui32 offset_to_data_for_image_element_1
ui32 total_image_file_size_in_bytes
ui16 number_of_image_elements
ui8 bitdepth_for_image_element_1
virtual ui32 read(const line_buf *line, ui32 comp_num)
ui16 * line_buffer_16bit_samples
ui32 offset_to_image_data_in_bytes
ui16 encoding_for_image_element_1
ui32 number_of_samples_per_line
ui8 transfer_characteristic_for_image_element_1
ui8 colormetric_specification_for_image_element_1
ui32 lines_per_image_element
bool is_byte_swapping_necessary
ui32 data_sign_for_image_element_1
virtual ui32 read(const line_buf *line, ui32 comp_num)
mem_fixed_allocator * alloc_p
void open(const char *filename)
size_t temp_buf_byte_size
void open(char *filename)
void configure(ui32 width, ui32 height, ui32 num_components, float scale, ui32 *bit_depth)
virtual ui32 write(const line_buf *line, ui32 comp_num)
void open(const char *filename)
mem_fixed_allocator * alloc_p
virtual ui32 read(const line_buf *line, ui32 comp_num)
void open(char *filename)
virtual ui32 write(const line_buf *line, ui32 comp_num)
void configure(ui32 width, ui32 height, ui32 num_components, ui32 bit_depth)
void set_img_props(const size &s, ui32 bit_depth, bool is_signed)
void open(const char *filename)
virtual ui32 read(const line_buf *line, ui32 comp_num=0)
void open(char *filename)
void configure(bool is_signed, ui32 bit_depth, ui32 width)
virtual ui32 write(const line_buf *line, ui32 comp_num=0)
virtual ui32 read(const line_buf *line, ui32 comp_num)
void open(const char *filename)
void set_img_props(const size &s, ui32 num_components, ui32 num_downsampling, const point *downsampling)
void set_bit_depth(ui32 num_bit_depths, ui32 *bit_depth)
void open(char *filename)
void configure(ui32 bit_depth, ui32 num_components, ui32 *comp_width)
virtual ui32 write(const line_buf *line, ui32 comp_num)
void sse41_cvrt_32b3c_to_8ub3c(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
static ui16 swap_bytes_if_le(ui16 t)
int ojph_fseek(FILE *stream, si64 offset, int origin)
static void eat_white_spaces(FILE *fh)
si64 ojph_ftell(FILE *stream)
const bool is_machine_little_endian
void avx2_cvrt_32b3c_to_8ub3c(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
void sse41_cvrt_32b1c_to_16ub1c_be(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
void avx2_cvrt_32b1c_to_16ub1c_be(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
void sse41_cvrt_32b1c_to_8ub1c(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
void avx2_cvrt_32b1c_to_8ub1c(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
static ui16 swap_bytes_if_be(ui16 t)
void gen_cvrt_32b3c_to_16ub3c_be(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
static ui16 be2le(const ui16 v)
OJPH_EXPORT int get_cpu_ext_level()
static ui32 count_leading_zeros(ui32 val)
void gen_cvrt_32b1c_to_8ub1c(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
void sse41_cvrt_32b3c_to_16ub3c_be(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
const bool is_force_pfm_write_as_little_endian_on_disk
void gen_cvrt_32b1c_to_16ub1c_be(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
void gen_cvrt_32b3c_to_8ub3c(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
@ X86_CPU_EXT_LEVEL_SSE41
#define ojph_div_ceil(a, b)
#define OJPH_ERROR(t,...)