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;
151 int max_val = (1<<bit_depth) - 1;
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;
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);
728 assert(
fh == NULL &&
buffer == NULL);
729 fh = fopen(filename,
"wb");
732 "Unable to open file %s for writing", filename);
734 fprintf(
fh,
"P%c\n%d %d\n%f\n",
737 OJPH_ERROR(0x03000072,
"error writing to file %s", filename);
747 float scale,
ui32* bit_depth)
793 size_t result = fwrite(
buffer,
sizeof(
float), samples_per_line,
fh);
794 if (result != samples_per_line)
809#ifdef OJPH_ENABLE_TIFF_SUPPORT
811 void tif_in::open(
const char* filename)
814 if ((tiff_handle = TIFFOpen(filename,
"r")) == NULL)
815 OJPH_ERROR(0x03000091,
"Unable to open file %s", filename);
819 ui32 tiff_height = 0;
820 TIFFGetField(tiff_handle, TIFFTAG_IMAGEWIDTH, &tiff_width);
821 TIFFGetField(tiff_handle, TIFFTAG_IMAGELENGTH, &tiff_height);
823 ui16 tiff_bits_per_sample = 0;
824 ui16 tiff_samples_per_pixel = 0;
825 TIFFGetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, &tiff_bits_per_sample);
826 TIFFGetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, &tiff_samples_per_pixel);
829 tiff_samples_per_pixel =
830 (tiff_samples_per_pixel < 1) ? 1 : tiff_samples_per_pixel;
832 ui16 tiff_planar_configuration = 0;
833 ui16 tiff_photometric = 0;
834 TIFFGetField(tiff_handle, TIFFTAG_PLANARCONFIG, &tiff_planar_configuration);
835 TIFFGetField(tiff_handle, TIFFTAG_PHOTOMETRIC, &tiff_photometric);
837 planar_configuration = tiff_planar_configuration;
839 ui16 tiff_compression = 0;
840 ui32 tiff_rows_per_strip = 0;
841 TIFFGetField(tiff_handle, TIFFTAG_COMPRESSION, &tiff_compression);
842 TIFFGetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, &tiff_rows_per_strip);
844 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE)
846 bytes_per_line = tiff_samples_per_pixel * TIFFScanlineSize64(tiff_handle);
850 bytes_per_line = TIFFScanlineSize64(tiff_handle);
853 line_buffer = malloc(bytes_per_line);
854 if (NULL == line_buffer)
855 OJPH_ERROR(0x03000092,
"Unable to allocate %d bytes for line_buffer[] "
856 "for file %s", bytes_per_line, filename);
861 if( tiff_bits_per_sample != 8 && tiff_bits_per_sample != 16 )
863 OJPH_ERROR(0x03000093,
"\nTIFF IO is currently limited"
864 " to files with TIFFTAG_BITSPERSAMPLE=8 and TIFFTAG_BITSPERSAMPLE=16 \n"
865 "input file = %s has TIFFTAG_BITSPERSAMPLE=%d",
866 filename, tiff_bits_per_sample);
869 if( TIFFIsTiled( tiff_handle ) )
871 OJPH_ERROR(0x03000094,
"\nTIFF IO is currently limited to TIF files "
872 "without tiles. \nInput file %s has been detected as tiled", filename);
875 if(PHOTOMETRIC_RGB != tiff_photometric &&
876 PHOTOMETRIC_MINISBLACK != tiff_photometric )
878 OJPH_ERROR(0x03000095,
"\nTIFF IO is currently limited to "
879 "TIFFTAG_PHOTOMETRIC=PHOTOMETRIC_MINISBLACK=%d and "
880 "PHOTOMETRIC_RGB=%d. \nInput file %s has been detected "
881 "TIFFTAG_PHOTOMETRIC=%d",
882 PHOTOMETRIC_MINISBLACK, PHOTOMETRIC_RGB, filename, tiff_photometric);
885 if( tiff_samples_per_pixel > 4 )
887 OJPH_ERROR(0x03000096,
"\nTIFF IO is currently limited to "
888 "TIFFTAG_SAMPLESPERPIXEL=4 \nInput file %s has been detected with "
889 "TIFFTAG_SAMPLESPERPIXEL=%d",
890 filename, tiff_samples_per_pixel);
895 height = tiff_height;
896 num_comps = tiff_samples_per_pixel;
897 bytes_per_sample = (tiff_bits_per_sample + 7) / 8;
898 for (
ui32 comp_num = 0; comp_num < num_comps; comp_num++)
899 bit_depth[comp_num] = tiff_bits_per_sample;
903 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
904 bytes_per_sample == 1)
906 line_buffer_for_planar_support_uint8 =
907 (uint8_t*)calloc(width,
sizeof(uint8_t));
908 if (NULL == line_buffer_for_planar_support_uint8)
909 OJPH_ERROR(0x03000097,
"Unable to allocate %d bytes for "
910 "line_buffer_for_planar_support_uint8[] for file %s",
911 width *
sizeof(uint8_t), filename);
913 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
914 bytes_per_sample == 2)
916 line_buffer_for_planar_support_uint16 =
917 (uint16_t*)calloc(width,
sizeof(uint16_t));
918 if (NULL == line_buffer_for_planar_support_uint16)
919 OJPH_ERROR(0x03000098,
"Unable to allocate %d bytes for "
920 "line_buffer_for_planar_support_uint16[] for file %s",
921 width *
sizeof(uint16_t), filename);
928 void tif_in::set_bit_depth(
ui32 num_bit_depths,
ui32* bit_depth)
930 if (num_bit_depths < 1)
931 OJPH_ERROR(0x030000A1,
"one or more bit_depths must be provided");
932 ui32 last_bd_idx = 0;
933 for (
ui32 i = 0; i < 4; ++i)
935 ui32 bd = bit_depth[i < num_bit_depths ? i : last_bd_idx];
936 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
938 if (bd > 32 || bd < 1)
941 "bit_depth = %d, this must be an integer from 1-32", bd);
943 this->bit_depth[i] = bd;
948 ui32 tif_in::read(
const line_buf* line,
ui32 comp_num)
950 assert(bytes_per_line != 0 && tiff_handle != 0 && comp_num < num_comps);
951 assert((
ui32)line->size >= width);
955 if (PLANARCONFIG_SEPARATE == planar_configuration && 0 == comp_num )
957 for (
ui32 color = 0; color < num_comps; color++)
959 if (bytes_per_sample == 1)
961 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint8,
962 cur_line, (
ui16)color);
964 uint8_t* line_buffer_of_interleaved_components =
965 (uint8_t*)line_buffer;
966 for (
ui32 i = 0; i < width; i++, x += num_comps)
968 line_buffer_of_interleaved_components[x] =
969 line_buffer_for_planar_support_uint8[i];
972 else if (bytes_per_sample == 2)
974 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint16,
975 cur_line, (
ui16)color);
977 ui16* line_buffer_of_interleaved_components = (
ui16*)line_buffer;
978 for (
ui32 i = 0; i < width; i++, x += num_comps)
980 line_buffer_of_interleaved_components[x] =
981 line_buffer_for_planar_support_uint16[i];
988 else if (planar_configuration == PLANARCONFIG_CONTIG && 0 == comp_num)
990 TIFFReadScanline(tiff_handle, line_buffer, cur_line++);
992 if (cur_line >= height)
997 if (bytes_per_sample == 1)
999 const ui8* sp = (
ui8*)line_buffer + comp_num;
1000 si32* dp = line->i32;
1001 if (bit_depth[comp_num] == 8)
1003 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1006 else if (bit_depth[comp_num] < 8)
1009 const int bits_to_shift = 8 - (int)bit_depth[comp_num];
1010 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1011 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1012 *dp++ = (
si32) (((*sp) >> bits_to_shift) & bit_mask);
1014 else if (bit_depth[comp_num] > 8)
1016 const int bits_to_shift = (int)bit_depth[comp_num] - 8;
1017 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1018 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1019 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1022 else if(bytes_per_sample == 2)
1024 if (bit_depth[comp_num] == 16)
1026 const ui16* sp = (
ui16*)line_buffer + comp_num;
1027 si32* dp = line->i32;
1028 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1031 else if (bit_depth[comp_num] < 16)
1034 const int bits_to_shift = 16 - (int)bit_depth[comp_num];
1035 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1036 const ui16* sp = (
ui16*)line_buffer + comp_num;
1037 si32* dp = line->i32;
1038 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1039 *dp++ = (
si32)(((*sp) >> bits_to_shift) & bit_mask);
1041 else if (bit_depth[comp_num] > 16)
1043 const int bits_to_shift = (int)bit_depth[comp_num] - 16;
1044 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1045 const ui16* sp = (
ui16*)line_buffer + comp_num;
1046 si32* dp = line->i32;
1047 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1048 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1065 void tif_out::open(
char* filename)
1068 ui32 max_bitdepth = 0;
1069 for (
ui32 c = 0; c < num_components; c++)
1071 if (bit_depth_of_data[c] > max_bitdepth)
1072 max_bitdepth = bit_depth_of_data[c];
1074 if (max_bitdepth > 16)
1076 OJPH_WARN(0x030000B1,
"TIFF output is currently limited to files "
1077 "with max_bitdepth = 16, the source codestream has max_bitdepth=%d"
1078 ", the decoded data will be truncated to 16 bits", max_bitdepth);
1080 if (num_components > 4)
1082 OJPH_ERROR(0x030000B2,
"TIFF IO is currently limited to files with "
1083 "num_components=1 to 4");
1086 assert(tiff_handle == NULL && buffer == NULL);
1087 if ((tiff_handle = TIFFOpen(filename,
"w")) == NULL)
1089 OJPH_ERROR(0x030000B3,
"unable to open file %s for writing", filename);
1092 buffer_size = width * (size_t)num_components * (
size_t)bytes_per_sample;
1093 buffer = (
ui8*)malloc(buffer_size);
1100 TIFFSetField(tiff_handle, TIFFTAG_IMAGEWIDTH, width);
1101 TIFFSetField(tiff_handle, TIFFTAG_IMAGELENGTH, height);
1103 TIFFSetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, bytes_per_sample * 8);
1104 TIFFSetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, num_components);
1106 planar_configuration = PLANARCONFIG_CONTIG;
1107 TIFFSetField(tiff_handle, TIFFTAG_PLANARCONFIG, planar_configuration);
1109 if (num_components == 1)
1111 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1113 else if (num_components == 2)
1115 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1118 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1119 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1120 &extra_samples_description);
1122 else if (num_components == 3)
1124 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1126 else if (num_components == 4)
1128 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1131 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1132 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1133 &extra_samples_description);
1136 TIFFSetField(tiff_handle, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1137 TIFFSetField(tiff_handle, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1139 TIFFSetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, height);
1144 void tif_out::configure(
ui32 width,
ui32 height,
ui32 num_components,
1147 assert(tiff_handle == NULL);
1149 this->width = width;
1150 this->height = height;
1151 this->num_components = num_components;
1152 ui32 max_bitdepth = 0;
1153 for (
ui32 c = 0; c < num_components; c++)
1155 this->bit_depth_of_data[c] = bit_depth[c];
1156 if (bit_depth[c] > max_bitdepth)
1157 max_bitdepth = bit_depth[c];
1160 bytes_per_sample = (max_bitdepth + 7) / 8;
1161 if (bytes_per_sample > 2)
1165 bytes_per_sample = 2;
1167 samples_per_line = num_components * width;
1168 bytes_per_line = bytes_per_sample * (size_t)samples_per_line;
1173 ui32 tif_out::write(
const line_buf* line,
ui32 comp_num)
1175 assert(tiff_handle);
1177 if (bytes_per_sample == 1)
1179 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1180 const si32* sp = line->i32;
1181 ui8* dp = buffer + comp_num;
1182 if (bit_depth_of_data[comp_num] == 8)
1184 for (
ui32 i = width; i > 0; --i, dp += num_components)
1188 val = val >= 0 ? val : 0;
1189 val = val <= max_val ? val : max_val;
1193 else if (bit_depth_of_data[comp_num] < 8)
1195 const int bits_to_shift = 8 - (int)bit_depth_of_data[comp_num];
1196 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1197 for (
ui32 i = width; i > 0; --i, dp += num_components)
1201 val = val >= 0 ? val : 0;
1202 val = val <= max_val ? val : max_val;
1205 *dp = (
ui8)((val & bit_mask) << bits_to_shift);
1208 else if (bit_depth_of_data[comp_num] > 8)
1210 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 8;
1211 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1212 for (
ui32 i = width; i > 0; --i, dp += num_components)
1216 val = val >= 0 ? val : 0;
1217 val = val <= max_val ? val : max_val;
1220 *dp = (
ui8)((val >> bits_to_shift) & bit_mask);
1225 else if(bytes_per_sample == 2)
1227 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1228 const si32* sp = line->i32;
1229 ui16* dp = (
ui16*)buffer + comp_num;
1231 if (bit_depth_of_data[comp_num] == 16)
1233 for (
ui32 i = width; i > 0; --i, dp += num_components)
1237 val = val >= 0 ? val : 0;
1238 val = val <= max_val ? val : max_val;
1242 else if (bit_depth_of_data[comp_num] < 16)
1244 const int bits_to_shift = 16 - (int)bit_depth_of_data[comp_num];
1245 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1246 for (
ui32 i = width; i > 0; --i, dp += num_components)
1250 val = val >= 0 ? val : 0;
1251 val = val <= max_val ? val : max_val;
1255 *dp = (
ui16)((val & bit_mask) << bits_to_shift);
1258 else if (bit_depth_of_data[comp_num] > 16)
1260 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 16;
1261 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1262 for (
ui32 i = width; i > 0; --i, dp += num_components)
1266 val = val >= 0 ? val : 0;
1267 val = val <= max_val ? val : max_val;
1271 *dp = (
ui16)((val >> bits_to_shift) & bit_mask);
1277 if (comp_num == num_components-1)
1279 int result = TIFFWriteScanline(tiff_handle, buffer, cur_line++);
1281 OJPH_ERROR(0x030000C1,
"error writing to file %s", fname);
1299 fh = fopen(filename,
"rb");
1301 OJPH_ERROR(0x030000D1,
"Unable to open file %s", filename);
1326 if (result !=
width[comp_num])
1336 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1343 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1347 return width[comp_num];
1352 ui32 num_downsamplings,
const point *subsampling)
1354 if (num_components != 1 && num_components !=3)
1355 OJPH_ERROR(0x030000F1,
"yuv_in support 1 or 3 components");
1356 this->
num_com = num_components;
1358 if (num_downsamplings < 1)
1359 OJPH_ERROR(0x030000F2,
"one or more downsampling must be provided");
1361 ui32 last_downsamp_idx = 0;
1362 for (
ui32 i = 0; i < num_components; ++i)
1365 last_downsamp_idx += last_downsamp_idx + 1 < num_downsamplings ? 1 : 0;
1367 this->subsampling[i] = cp_ds;
1370 for (
ui32 i = 0; i < num_components; ++i)
1380 if (num_bit_depths < 1)
1381 OJPH_ERROR(0x03000101,
"one or more bit_depths must be provided");
1382 ui32 last_bd_idx = 0;
1383 for (
ui32 i = 0; i < 3; ++i)
1386 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
1388 this->bit_depth[i] = bd;
1421 fh = fopen(filename,
"wb");
1423 OJPH_ERROR(0x03000111,
"Unable to open file %s", filename);
1439 tw =
ojph_max(tw, this->comp_width[i]);
1458 for (
ui32 i = w; i > 0; --i)
1461 val = val >= 0 ? val : 0;
1462 val = val <= max_val ? val : max_val;
1472 for (
ui32 i = w; i > 0; --i)
1475 val = val >= 0 ? val : 0;
1476 val = val <= max_val ? val : max_val;
1498 fh = fopen(filename,
"rb");
1500 OJPH_ERROR(0x03000131,
"Unable to open file %s", filename);
1513 assert(comp_num == 0);
1515 if (result !=
width)
1542 si32 val = *sp & 0xFFFFFF;
1543 val |= (val & 0x800000) ? 0xFF000000 : 0;
1552 *dp++ = (
si32)(*sp & 0xFFFFFFu);
1625 fh = fopen(filename,
"wb");
1627 OJPH_ERROR(0x03000141,
"Unable to open file %s", filename);
1637 this->width =
width;
1657 assert(comp_num == 0);
1801 OJPH_ERROR(0x03000161,
"Unable to open file %s", filename);
1809 OJPH_ERROR(0x03000162,
"Error reading file %s", filename);
1813 const ui32 dpx_magic_number = 0x53445058;
1814 if (dpx_magic_number == magic_number)
1819 else if (dpx_magic_number ==
be2le(magic_number))
1828 OJPH_ERROR(0x03000163,
"Error reading file %s - this does not appear "
1829 "to be a valid DPX file. It has magic number = 0x%08X. The magic "
1830 "number of a DPX file is 0x%08X.", filename, magic_number,
1839 OJPH_ERROR(0x03000164,
"Error reading file %s", filename);
1847 OJPH_ERROR(0x03000165,
"Error reading file %s", filename);
1854 OJPH_ERROR(0x03000166,
"Error reading file %s", filename);
1863 OJPH_ERROR(0x03000167,
"Error reading file %s", filename);
1870 OJPH_ERROR(0x03000168,
"Error reading file %s", filename);
1880 OJPH_ERROR(0x03000169,
"Error reading file %s", filename);
1889 OJPH_ERROR(0x0300016A,
"Error reading file %s", filename);
1898 OJPH_ERROR(0x0300016B,
"Error reading file %s", filename);
1907 OJPH_ERROR(0x0300016C,
"Error reading file %s", filename);
1915 OJPH_ERROR(0x0300016E,
"Error reading file %s", filename);
1924 OJPH_ERROR(0x0300016F,
"Error reading file %s", filename);
1932 OJPH_ERROR(0x03000170,
"Error reading file %s", filename);
1940 OJPH_ERROR(0x03000171,
"Error reading file %s", filename);
1948 OJPH_ERROR(0x03000172,
"Error reading file %s", filename);
1956 OJPH_ERROR(0x03000173,
"Error reading file %s", filename);
1964 OJPH_ERROR(0x03000174,
"Error reading file %s", filename);
1974 OJPH_ERROR(0x03000175,
"Error reading file %s", filename);
1984 OJPH_ERROR(0x03000176,
"Error reading file %s", filename);
1994 OJPH_ERROR(0x03000177,
"Error reading file %s", filename);
2013 / number_of_samples_per_32_bit_word;
2020 OJPH_ERROR(0x03000178,
"Unable to allocate %d bytes for line_buffer[] "
2028 OJPH_ERROR(0x03000179,
"Unable to allocate %d bytes for "
2029 "line_buffer_16bit_samples[] for file %s",
2060 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2068 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2075 ui32 word_index = 0;
2084 (
ui16) ((line_buffer_ptr[word_index] & 0xFFC00000) >> 22);
2087 (
ui16) ((line_buffer_ptr[word_index] & 0x003FF000) >> 12);
2090 (
ui16) ((line_buffer_ptr[word_index] & 0x00000FFC) >> 2);
2104 OJPH_ERROR(0x03000182,
"file %s uses DPX image formats that are not "
2105 "yet supported by this software\n bitdepth_for_image_element_1 = "
2106 "%d\n num_comps=%d\npacking_for_image_element_1=%d\n "
2107 "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
void pre_alloc_data(size_t num_ele, ui32 pre_size)
T * post_alloc_data(size_t num_ele, ui32 pre_size)
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)
@ X86_CPU_EXT_LEVEL_SSE41
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)
int ojph_fseek(FILE *stream, si64 offset, int origin)
static void eat_white_spaces(FILE *fh)
si64 ojph_ftell(FILE *stream)
void gen_cvrt_32b3c_to_16ub3c_le(const line_buf *ln0, const line_buf *ln1, const line_buf *ln2, void *dp, ui32 bit_depth, ui32 count)
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 gen_cvrt_32b1c_to_16ub1c_le(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)
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)
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)
#define ojph_div_ceil(a, b)
#define OJPH_ERROR(t,...)