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");
474#ifndef OJPH_DISABLE_SIMD
476 #if (defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
478 #ifndef OJPH_DISABLE_SSE4
495 #ifndef OJPH_DISABLE_AVX2
512 #elif defined(OJPH_ARCH_ARM)
524 lptr[comp_num] = line;
530 size_t result = fwrite(
buffer,
550 fh = fopen(filename,
"rb");
552 OJPH_ERROR(0x03000051,
"Unable to open file %s", filename);
557 if (fread(t, 1, 2,
fh) != 2)
560 OJPH_ERROR(0x03000052,
"Error reading file %s", filename);
564 if (t[0] !=
'P' || (t[1] !=
'F' && t[1] !=
'f'))
567 OJPH_ERROR(0x03000053,
"Unknown file type for file %s", filename);
579 "Error reading width and height in file %s", filename);
584 if (fscanf(
fh,
"%f", &
scale) != 1)
587 OJPH_ERROR(0x03000055,
"Error reading scale in file %s", filename);
608 OJPH_ERROR(0x03000056,
"Error allocating memory");
640 * (
size_t)
width *
sizeof(float);
692 *dp.u++ =
be2le(*sp.u);
709 assert(
fh == NULL &&
buffer == NULL);
710 fh = fopen(filename,
"wb");
713 "Unable to open file %s for writing", filename);
715 fprintf(
fh,
"P%c\n%d %d\n%f\n",
718 OJPH_ERROR(0x03000072,
"error writing to file %s", filename);
728 float scale,
ui32* bit_depth)
774 size_t result = fwrite(
buffer,
sizeof(
float), samples_per_line,
fh);
775 if (result != samples_per_line)
790#ifdef OJPH_ENABLE_TIFF_SUPPORT
792 void tif_in::open(
const char* filename)
795 if ((tiff_handle = TIFFOpen(filename,
"r")) == NULL)
796 OJPH_ERROR(0x03000091,
"Unable to open file %s", filename);
800 ui32 tiff_height = 0;
801 TIFFGetField(tiff_handle, TIFFTAG_IMAGEWIDTH, &tiff_width);
802 TIFFGetField(tiff_handle, TIFFTAG_IMAGELENGTH, &tiff_height);
804 ui16 tiff_bits_per_sample = 0;
805 ui16 tiff_samples_per_pixel = 0;
806 TIFFGetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, &tiff_bits_per_sample);
807 TIFFGetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, &tiff_samples_per_pixel);
810 tiff_samples_per_pixel =
811 (tiff_samples_per_pixel < 1) ? 1 : tiff_samples_per_pixel;
813 ui16 tiff_planar_configuration = 0;
814 ui16 tiff_photometric = 0;
815 TIFFGetField(tiff_handle, TIFFTAG_PLANARCONFIG, &tiff_planar_configuration);
816 TIFFGetField(tiff_handle, TIFFTAG_PHOTOMETRIC, &tiff_photometric);
818 planar_configuration = tiff_planar_configuration;
820 ui16 tiff_compression = 0;
821 ui32 tiff_rows_per_strip = 0;
822 TIFFGetField(tiff_handle, TIFFTAG_COMPRESSION, &tiff_compression);
823 TIFFGetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, &tiff_rows_per_strip);
825 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE)
827 bytes_per_line = tiff_samples_per_pixel * TIFFScanlineSize64(tiff_handle);
831 bytes_per_line = TIFFScanlineSize64(tiff_handle);
834 line_buffer = malloc(bytes_per_line);
835 if (NULL == line_buffer)
836 OJPH_ERROR(0x03000092,
"Unable to allocate %d bytes for line_buffer[] "
837 "for file %s", bytes_per_line, filename);
842 if( tiff_bits_per_sample != 8 && tiff_bits_per_sample != 16 )
844 OJPH_ERROR(0x03000093,
"\nTIFF IO is currently limited"
845 " to files with TIFFTAG_BITSPERSAMPLE=8 and TIFFTAG_BITSPERSAMPLE=16 \n"
846 "input file = %s has TIFFTAG_BITSPERSAMPLE=%d",
847 filename, tiff_bits_per_sample);
850 if( TIFFIsTiled( tiff_handle ) )
852 OJPH_ERROR(0x03000094,
"\nTIFF IO is currently limited to TIF files "
853 "without tiles. \nInput file %s has been detected as tiled", filename);
856 if(PHOTOMETRIC_RGB != tiff_photometric &&
857 PHOTOMETRIC_MINISBLACK != tiff_photometric )
859 OJPH_ERROR(0x03000095,
"\nTIFF IO is currently limited to "
860 "TIFFTAG_PHOTOMETRIC=PHOTOMETRIC_MINISBLACK=%d and "
861 "PHOTOMETRIC_RGB=%d. \nInput file %s has been detected "
862 "TIFFTAG_PHOTOMETRIC=%d",
863 PHOTOMETRIC_MINISBLACK, PHOTOMETRIC_RGB, filename, tiff_photometric);
866 if( tiff_samples_per_pixel > 4 )
868 OJPH_ERROR(0x03000096,
"\nTIFF IO is currently limited to "
869 "TIFFTAG_SAMPLESPERPIXEL=4 \nInput file %s has been detected with "
870 "TIFFTAG_SAMPLESPERPIXEL=%d",
871 filename, tiff_samples_per_pixel);
876 height = tiff_height;
877 num_comps = tiff_samples_per_pixel;
878 bytes_per_sample = (tiff_bits_per_sample + 7) / 8;
879 for (
ui32 comp_num = 0; comp_num < num_comps; comp_num++)
880 bit_depth[comp_num] = tiff_bits_per_sample;
884 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
885 bytes_per_sample == 1)
887 line_buffer_for_planar_support_uint8 =
888 (uint8_t*)calloc(width,
sizeof(uint8_t));
889 if (NULL == line_buffer_for_planar_support_uint8)
890 OJPH_ERROR(0x03000097,
"Unable to allocate %d bytes for "
891 "line_buffer_for_planar_support_uint8[] for file %s",
892 width *
sizeof(uint8_t), filename);
894 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
895 bytes_per_sample == 2)
897 line_buffer_for_planar_support_uint16 =
898 (uint16_t*)calloc(width,
sizeof(uint16_t));
899 if (NULL == line_buffer_for_planar_support_uint16)
900 OJPH_ERROR(0x03000098,
"Unable to allocate %d bytes for "
901 "line_buffer_for_planar_support_uint16[] for file %s",
902 width *
sizeof(uint16_t), filename);
909 void tif_in::set_bit_depth(
ui32 num_bit_depths,
ui32* bit_depth)
911 if (num_bit_depths < 1)
912 OJPH_ERROR(0x030000A1,
"one or more bit_depths must be provided");
913 ui32 last_bd_idx = 0;
914 for (
ui32 i = 0; i < 4; ++i)
916 ui32 bd = bit_depth[i < num_bit_depths ? i : last_bd_idx];
917 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
919 if (bd > 32 || bd < 1)
922 "bit_depth = %d, this must be an integer from 1-32", bd);
924 this->bit_depth[i] = bd;
929 ui32 tif_in::read(
const line_buf* line,
ui32 comp_num)
931 assert(bytes_per_line != 0 && tiff_handle != 0 && comp_num < num_comps);
932 assert((
ui32)line->size >= width);
936 if (PLANARCONFIG_SEPARATE == planar_configuration && 0 == comp_num )
938 for (
ui32 color = 0; color < num_comps; color++)
940 if (bytes_per_sample == 1)
942 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint8,
943 cur_line, (
ui16)color);
945 uint8_t* line_buffer_of_interleaved_components =
946 (uint8_t*)line_buffer;
947 for (
ui32 i = 0; i < width; i++, x += num_comps)
949 line_buffer_of_interleaved_components[x] =
950 line_buffer_for_planar_support_uint8[i];
953 else if (bytes_per_sample == 2)
955 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint16,
956 cur_line, (
ui16)color);
958 ui16* line_buffer_of_interleaved_components = (
ui16*)line_buffer;
959 for (
ui32 i = 0; i < width; i++, x += num_comps)
961 line_buffer_of_interleaved_components[x] =
962 line_buffer_for_planar_support_uint16[i];
969 else if (planar_configuration == PLANARCONFIG_CONTIG && 0 == comp_num)
971 TIFFReadScanline(tiff_handle, line_buffer, cur_line++);
973 if (cur_line >= height)
978 if (bytes_per_sample == 1)
980 const ui8* sp = (
ui8*)line_buffer + comp_num;
981 si32* dp = line->i32;
982 if (bit_depth[comp_num] == 8)
984 for (
ui32 i = width; i > 0; --i, sp += num_comps)
987 else if (bit_depth[comp_num] < 8)
990 const int bits_to_shift = 8 - (int)bit_depth[comp_num];
991 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
992 for (
ui32 i = width; i > 0; --i, sp += num_comps)
993 *dp++ = (
si32) (((*sp) >> bits_to_shift) & bit_mask);
995 else if (bit_depth[comp_num] > 8)
997 const int bits_to_shift = (int)bit_depth[comp_num] - 8;
998 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
999 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1000 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1003 else if(bytes_per_sample == 2)
1005 if (bit_depth[comp_num] == 16)
1007 const ui16* sp = (
ui16*)line_buffer + comp_num;
1008 si32* dp = line->i32;
1009 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1012 else if (bit_depth[comp_num] < 16)
1015 const int bits_to_shift = 16 - (int)bit_depth[comp_num];
1016 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1017 const ui16* sp = (
ui16*)line_buffer + comp_num;
1018 si32* dp = line->i32;
1019 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1020 *dp++ = (
si32)(((*sp) >> bits_to_shift) & bit_mask);
1022 else if (bit_depth[comp_num] > 16)
1024 const int bits_to_shift = (int)bit_depth[comp_num] - 16;
1025 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
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)
1029 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1046 void tif_out::open(
char* filename)
1049 ui32 max_bitdepth = 0;
1050 for (
ui32 c = 0; c < num_components; c++)
1052 if (bit_depth_of_data[c] > max_bitdepth)
1053 max_bitdepth = bit_depth_of_data[c];
1055 if (max_bitdepth > 16)
1057 OJPH_WARN(0x030000B1,
"TIFF output is currently limited to files "
1058 "with max_bitdepth = 16, the source codestream has max_bitdepth=%d"
1059 ", the decoded data will be truncated to 16 bits", max_bitdepth);
1061 if (num_components > 4)
1063 OJPH_ERROR(0x030000B2,
"TIFF IO is currently limited to files with "
1064 "num_components=1 to 4");
1067 assert(tiff_handle == NULL && buffer == NULL);
1068 if ((tiff_handle = TIFFOpen(filename,
"w")) == NULL)
1070 OJPH_ERROR(0x030000B3,
"unable to open file %s for writing", filename);
1073 buffer_size = width * (size_t)num_components * (
size_t)bytes_per_sample;
1074 buffer = (
ui8*)malloc(buffer_size);
1081 TIFFSetField(tiff_handle, TIFFTAG_IMAGEWIDTH, width);
1082 TIFFSetField(tiff_handle, TIFFTAG_IMAGELENGTH, height);
1084 TIFFSetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, bytes_per_sample * 8);
1085 TIFFSetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, num_components);
1087 planar_configuration = PLANARCONFIG_CONTIG;
1088 TIFFSetField(tiff_handle, TIFFTAG_PLANARCONFIG, planar_configuration);
1090 if (num_components == 1)
1092 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1094 else if (num_components == 2)
1096 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1099 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1100 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1101 &extra_samples_description);
1103 else if (num_components == 3)
1105 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1107 else if (num_components == 4)
1109 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1112 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1113 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1114 &extra_samples_description);
1117 TIFFSetField(tiff_handle, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1118 TIFFSetField(tiff_handle, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1120 TIFFSetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, height);
1125 void tif_out::configure(
ui32 width,
ui32 height,
ui32 num_components,
1128 assert(tiff_handle == NULL);
1130 this->width = width;
1131 this->height = height;
1132 this->num_components = num_components;
1133 ui32 max_bitdepth = 0;
1134 for (
ui32 c = 0; c < num_components; c++)
1136 this->bit_depth_of_data[c] = bit_depth[c];
1137 if (bit_depth[c] > max_bitdepth)
1138 max_bitdepth = bit_depth[c];
1141 bytes_per_sample = (max_bitdepth + 7) / 8;
1142 if (bytes_per_sample > 2)
1146 bytes_per_sample = 2;
1148 samples_per_line = num_components * width;
1149 bytes_per_line = bytes_per_sample * (size_t)samples_per_line;
1154 ui32 tif_out::write(
const line_buf* line,
ui32 comp_num)
1156 assert(tiff_handle);
1158 if (bytes_per_sample == 1)
1160 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1161 const si32* sp = line->i32;
1162 ui8* dp = buffer + comp_num;
1163 if (bit_depth_of_data[comp_num] == 8)
1165 for (
ui32 i = width; i > 0; --i, dp += num_components)
1169 val = val >= 0 ? val : 0;
1170 val = val <= max_val ? val : max_val;
1174 else if (bit_depth_of_data[comp_num] < 8)
1176 const int bits_to_shift = 8 - (int)bit_depth_of_data[comp_num];
1177 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1178 for (
ui32 i = width; i > 0; --i, dp += num_components)
1182 val = val >= 0 ? val : 0;
1183 val = val <= max_val ? val : max_val;
1186 *dp = (
ui8)((val & bit_mask) << bits_to_shift);
1189 else if (bit_depth_of_data[comp_num] > 8)
1191 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 8;
1192 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1193 for (
ui32 i = width; i > 0; --i, dp += num_components)
1197 val = val >= 0 ? val : 0;
1198 val = val <= max_val ? val : max_val;
1201 *dp = (
ui8)((val >> bits_to_shift) & bit_mask);
1206 else if(bytes_per_sample == 2)
1208 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1209 const si32* sp = line->i32;
1210 ui16* dp = (
ui16*)buffer + comp_num;
1212 if (bit_depth_of_data[comp_num] == 16)
1214 for (
ui32 i = width; i > 0; --i, dp += num_components)
1218 val = val >= 0 ? val : 0;
1219 val = val <= max_val ? val : max_val;
1223 else if (bit_depth_of_data[comp_num] < 16)
1225 const int bits_to_shift = 16 - (int)bit_depth_of_data[comp_num];
1226 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1227 for (
ui32 i = width; i > 0; --i, dp += num_components)
1231 val = val >= 0 ? val : 0;
1232 val = val <= max_val ? val : max_val;
1236 *dp = (
ui16)((val & bit_mask) << bits_to_shift);
1239 else if (bit_depth_of_data[comp_num] > 16)
1241 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 16;
1242 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1243 for (
ui32 i = width; i > 0; --i, dp += num_components)
1247 val = val >= 0 ? val : 0;
1248 val = val <= max_val ? val : max_val;
1252 *dp = (
ui16)((val >> bits_to_shift) & bit_mask);
1258 if (comp_num == num_components-1)
1260 int result = TIFFWriteScanline(tiff_handle, buffer, cur_line++);
1262 OJPH_ERROR(0x030000C1,
"error writing to file %s", fname);
1280 fh = fopen(filename,
"rb");
1282 OJPH_ERROR(0x030000D1,
"Unable to open file %s", filename);
1307 if (result !=
width[comp_num])
1317 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1324 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1328 return width[comp_num];
1333 ui32 num_downsamplings,
const point *subsampling)
1335 if (num_components != 1 && num_components !=3)
1336 OJPH_ERROR(0x030000F1,
"yuv_in support 1 or 3 components");
1337 this->
num_com = num_components;
1339 if (num_downsamplings < 1)
1340 OJPH_ERROR(0x030000F2,
"one or more downsampling must be provided");
1342 ui32 last_downsamp_idx = 0;
1343 for (
ui32 i = 0; i < num_components; ++i)
1346 last_downsamp_idx += last_downsamp_idx + 1 < num_downsamplings ? 1 : 0;
1348 this->subsampling[i] = cp_ds;
1351 for (
ui32 i = 0; i < num_components; ++i)
1361 if (num_bit_depths < 1)
1362 OJPH_ERROR(0x03000101,
"one or more bit_depths must be provided");
1363 ui32 last_bd_idx = 0;
1364 for (
ui32 i = 0; i < 3; ++i)
1367 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
1369 this->bit_depth[i] = bd;
1402 fh = fopen(filename,
"wb");
1404 OJPH_ERROR(0x03000111,
"Unable to open file %s", filename);
1420 tw =
ojph_max(tw, this->comp_width[i]);
1439 for (
ui32 i = w; i > 0; --i)
1442 val = val >= 0 ? val : 0;
1443 val = val <= max_val ? val : max_val;
1453 for (
ui32 i = w; i > 0; --i)
1456 val = val >= 0 ? val : 0;
1457 val = val <= max_val ? val : max_val;
1479 fh = fopen(filename,
"rb");
1481 OJPH_ERROR(0x03000131,
"Unable to open file %s", filename);
1494 assert(comp_num == 0);
1496 if (result !=
width)
1523 si32 val = *sp & 0xFFFFFF;
1524 val |= (val & 0x800000) ? 0xFF000000 : 0;
1533 *dp++ = (
si32)(*sp & 0xFFFFFFu);
1606 fh = fopen(filename,
"wb");
1608 OJPH_ERROR(0x03000141,
"Unable to open file %s", filename);
1618 this->width =
width;
1638 assert(comp_num == 0);
1782 OJPH_ERROR(0x03000161,
"Unable to open file %s", filename);
1790 OJPH_ERROR(0x03000162,
"Error reading file %s", filename);
1794 const ui32 dpx_magic_number = 0x53445058;
1795 if (dpx_magic_number == magic_number)
1800 else if (dpx_magic_number ==
be2le(magic_number))
1809 OJPH_ERROR(0x03000163,
"Error reading file %s - this does not appear "
1810 "to be a valid DPX file. It has magic number = 0x%08X. The magic "
1811 "number of a DPX file is 0x%08X.", filename, magic_number,
1820 OJPH_ERROR(0x03000164,
"Error reading file %s", filename);
1828 OJPH_ERROR(0x03000165,
"Error reading file %s", filename);
1835 OJPH_ERROR(0x03000166,
"Error reading file %s", filename);
1844 OJPH_ERROR(0x03000167,
"Error reading file %s", filename);
1851 OJPH_ERROR(0x03000168,
"Error reading file %s", filename);
1861 OJPH_ERROR(0x03000169,
"Error reading file %s", filename);
1870 OJPH_ERROR(0x0300016A,
"Error reading file %s", filename);
1879 OJPH_ERROR(0x0300016B,
"Error reading file %s", filename);
1888 OJPH_ERROR(0x0300016C,
"Error reading file %s", filename);
1896 OJPH_ERROR(0x0300016E,
"Error reading file %s", filename);
1905 OJPH_ERROR(0x0300016F,
"Error reading file %s", filename);
1913 OJPH_ERROR(0x03000170,
"Error reading file %s", filename);
1921 OJPH_ERROR(0x03000171,
"Error reading file %s", filename);
1929 OJPH_ERROR(0x03000172,
"Error reading file %s", filename);
1937 OJPH_ERROR(0x03000173,
"Error reading file %s", filename);
1945 OJPH_ERROR(0x03000174,
"Error reading file %s", filename);
1955 OJPH_ERROR(0x03000175,
"Error reading file %s", filename);
1965 OJPH_ERROR(0x03000176,
"Error reading file %s", filename);
1975 OJPH_ERROR(0x03000177,
"Error reading file %s", filename);
1994 / number_of_samples_per_32_bit_word;
2001 OJPH_ERROR(0x03000178,
"Unable to allocate %d bytes for line_buffer[] "
2009 OJPH_ERROR(0x03000179,
"Unable to allocate %d bytes for "
2010 "line_buffer_16bit_samples[] for file %s",
2041 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2049 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2056 ui32 word_index = 0;
2065 (
ui16) ((line_buffer_ptr[word_index] & 0xFFC00000) >> 22);
2068 (
ui16) ((line_buffer_ptr[word_index] & 0x003FF000) >> 12);
2071 (
ui16) ((line_buffer_ptr[word_index] & 0x00000FFC) >> 2);
2085 OJPH_ERROR(0x03000182,
"file %s uses DPX image formats that are not "
2086 "yet supported by this software\n bitdepth_for_image_element_1 = "
2087 "%d\n num_comps=%d\npacking_for_image_element_1=%d\n "
2088 "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,...)