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);
677 float* dp = line->
f32;
686 memcpy(&s, sp,
sizeof(
si32));
688 memcpy(dp, &s,
sizeof(
si32));
700 memcpy(&s, sp,
sizeof(
si32));
703 memcpy(dp, &s,
sizeof(
si32));
709 memcpy(&u, sp,
sizeof(
ui32));
711 memcpy(dp, &u,
sizeof(
ui32));
734 assert(
fh == NULL &&
buffer == NULL);
735 fh = fopen(filename,
"wb");
738 "Unable to open file %s for writing", filename);
740 fprintf(
fh,
"P%c\n%d %d\n%f\n",
743 OJPH_ERROR(0x03000072,
"error writing to file %s", filename);
762 bool is_write_little_endian_on_disk =
765 this->scale = is_write_little_endian_on_disk ? -
scale :
scale;
776 float* sp = line->
f32;
777 float* dp =
buffer + comp_num;
788 memcpy(&u, sp,
sizeof(
ui32));
791 memcpy(dp, &u,
sizeof(
ui32));
797 memcpy(&u, sp,
sizeof(
ui32));
799 memcpy(dp, &u,
sizeof(
ui32));
807 memcpy(&u, sp,
sizeof(
ui32));
809 memcpy(dp, &u,
sizeof(
ui32));
822 size_t result = fwrite(
buffer,
sizeof(
float), samples_per_line,
fh);
823 if (result != samples_per_line)
838#ifdef OJPH_ENABLE_TIFF_SUPPORT
840 void tif_in::open(
const char* filename)
843 if ((tiff_handle = TIFFOpen(filename,
"r")) == NULL)
844 OJPH_ERROR(0x03000091,
"Unable to open file %s", filename);
848 ui32 tiff_height = 0;
849 TIFFGetField(tiff_handle, TIFFTAG_IMAGEWIDTH, &tiff_width);
850 TIFFGetField(tiff_handle, TIFFTAG_IMAGELENGTH, &tiff_height);
852 ui16 tiff_bits_per_sample = 0;
853 ui16 tiff_samples_per_pixel = 0;
854 TIFFGetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, &tiff_bits_per_sample);
855 TIFFGetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, &tiff_samples_per_pixel);
858 tiff_samples_per_pixel =
859 (tiff_samples_per_pixel < 1) ? 1 : tiff_samples_per_pixel;
861 ui16 tiff_planar_configuration = 0;
862 ui16 tiff_photometric = 0;
863 TIFFGetField(tiff_handle, TIFFTAG_PLANARCONFIG, &tiff_planar_configuration);
864 TIFFGetField(tiff_handle, TIFFTAG_PHOTOMETRIC, &tiff_photometric);
866 planar_configuration = tiff_planar_configuration;
868 ui16 tiff_compression = 0;
869 ui32 tiff_rows_per_strip = 0;
870 TIFFGetField(tiff_handle, TIFFTAG_COMPRESSION, &tiff_compression);
871 TIFFGetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, &tiff_rows_per_strip);
873 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE)
875 bytes_per_line = tiff_samples_per_pixel * TIFFScanlineSize64(tiff_handle);
879 bytes_per_line = TIFFScanlineSize64(tiff_handle);
882 line_buffer = malloc(bytes_per_line);
883 if (NULL == line_buffer)
884 OJPH_ERROR(0x03000092,
"Unable to allocate %d bytes for line_buffer[] "
885 "for file %s", bytes_per_line, filename);
890 if( tiff_bits_per_sample != 8 && tiff_bits_per_sample != 16 )
892 OJPH_ERROR(0x03000093,
"\nTIFF IO is currently limited"
893 " to files with TIFFTAG_BITSPERSAMPLE=8 and TIFFTAG_BITSPERSAMPLE=16 \n"
894 "input file = %s has TIFFTAG_BITSPERSAMPLE=%d",
895 filename, tiff_bits_per_sample);
898 if( TIFFIsTiled( tiff_handle ) )
900 OJPH_ERROR(0x03000094,
"\nTIFF IO is currently limited to TIF files "
901 "without tiles. \nInput file %s has been detected as tiled", filename);
904 if(PHOTOMETRIC_RGB != tiff_photometric &&
905 PHOTOMETRIC_MINISBLACK != tiff_photometric )
907 OJPH_ERROR(0x03000095,
"\nTIFF IO is currently limited to "
908 "TIFFTAG_PHOTOMETRIC=PHOTOMETRIC_MINISBLACK=%d and "
909 "PHOTOMETRIC_RGB=%d. \nInput file %s has been detected "
910 "TIFFTAG_PHOTOMETRIC=%d",
911 PHOTOMETRIC_MINISBLACK, PHOTOMETRIC_RGB, filename, tiff_photometric);
914 if( tiff_samples_per_pixel > 4 )
916 OJPH_ERROR(0x03000096,
"\nTIFF IO is currently limited to "
917 "TIFFTAG_SAMPLESPERPIXEL=4 \nInput file %s has been detected with "
918 "TIFFTAG_SAMPLESPERPIXEL=%d",
919 filename, tiff_samples_per_pixel);
924 height = tiff_height;
925 num_comps = tiff_samples_per_pixel;
926 bytes_per_sample = (tiff_bits_per_sample + 7) / 8;
927 for (
ui32 comp_num = 0; comp_num < num_comps; comp_num++)
928 bit_depth[comp_num] = tiff_bits_per_sample;
932 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
933 bytes_per_sample == 1)
935 line_buffer_for_planar_support_uint8 =
936 (uint8_t*)calloc(width,
sizeof(uint8_t));
937 if (NULL == line_buffer_for_planar_support_uint8)
938 OJPH_ERROR(0x03000097,
"Unable to allocate %d bytes for "
939 "line_buffer_for_planar_support_uint8[] for file %s",
940 width *
sizeof(uint8_t), filename);
942 if (tiff_planar_configuration == PLANARCONFIG_SEPARATE &&
943 bytes_per_sample == 2)
945 line_buffer_for_planar_support_uint16 =
946 (uint16_t*)calloc(width,
sizeof(uint16_t));
947 if (NULL == line_buffer_for_planar_support_uint16)
948 OJPH_ERROR(0x03000098,
"Unable to allocate %d bytes for "
949 "line_buffer_for_planar_support_uint16[] for file %s",
950 width *
sizeof(uint16_t), filename);
957 void tif_in::set_bit_depth(
ui32 num_bit_depths,
ui32* bit_depth)
959 if (num_bit_depths < 1)
960 OJPH_ERROR(0x030000A1,
"one or more bit_depths must be provided");
961 ui32 last_bd_idx = 0;
962 for (
ui32 i = 0; i < 4; ++i)
964 ui32 bd = bit_depth[i < num_bit_depths ? i : last_bd_idx];
965 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
967 if (bd > 32 || bd < 1)
970 "bit_depth = %d, this must be an integer from 1-32", bd);
972 this->bit_depth[i] = bd;
979 assert(bytes_per_line != 0 && tiff_handle != 0 && comp_num < num_comps);
980 assert((
ui32)line->size >= width);
984 if (PLANARCONFIG_SEPARATE == planar_configuration && 0 == comp_num )
986 for (
ui32 color = 0; color < num_comps; color++)
988 if (bytes_per_sample == 1)
990 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint8,
991 cur_line, (
ui16)color);
993 uint8_t* line_buffer_of_interleaved_components =
994 (uint8_t*)line_buffer;
995 for (
ui32 i = 0; i < width; i++, x += num_comps)
997 line_buffer_of_interleaved_components[x] =
998 line_buffer_for_planar_support_uint8[i];
1001 else if (bytes_per_sample == 2)
1003 TIFFReadScanline(tiff_handle, line_buffer_for_planar_support_uint16,
1004 cur_line, (
ui16)color);
1006 ui16* line_buffer_of_interleaved_components = (
ui16*)line_buffer;
1007 for (
ui32 i = 0; i < width; i++, x += num_comps)
1009 line_buffer_of_interleaved_components[x] =
1010 line_buffer_for_planar_support_uint16[i];
1017 else if (planar_configuration == PLANARCONFIG_CONTIG && 0 == comp_num)
1019 TIFFReadScanline(tiff_handle, line_buffer, cur_line++);
1021 if (cur_line >= height)
1026 if (bytes_per_sample == 1)
1028 const ui8* sp = (
ui8*)line_buffer + comp_num;
1029 si32* dp = line->i32;
1030 if (bit_depth[comp_num] == 8)
1032 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1035 else if (bit_depth[comp_num] < 8)
1038 const int bits_to_shift = 8 - (int)bit_depth[comp_num];
1039 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1040 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1041 *dp++ = (
si32) (((*sp) >> bits_to_shift) & bit_mask);
1043 else if (bit_depth[comp_num] > 8)
1045 const int bits_to_shift = (int)bit_depth[comp_num] - 8;
1046 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1047 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1048 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1051 else if(bytes_per_sample == 2)
1053 if (bit_depth[comp_num] == 16)
1055 const ui16* sp = (
ui16*)line_buffer + comp_num;
1056 si32* dp = line->i32;
1057 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1060 else if (bit_depth[comp_num] < 16)
1063 const int bits_to_shift = 16 - (int)bit_depth[comp_num];
1064 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1065 const ui16* sp = (
ui16*)line_buffer + comp_num;
1066 si32* dp = line->i32;
1067 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1068 *dp++ = (
si32)(((*sp) >> bits_to_shift) & bit_mask);
1070 else if (bit_depth[comp_num] > 16)
1072 const int bits_to_shift = (int)bit_depth[comp_num] - 16;
1073 const int bit_mask = (1 << bit_depth[comp_num]) - 1;
1074 const ui16* sp = (
ui16*)line_buffer + comp_num;
1075 si32* dp = line->i32;
1076 for (
ui32 i = width; i > 0; --i, sp += num_comps)
1077 *dp++ = (
si32)(((*sp) << bits_to_shift) & bit_mask);
1094 void tif_out::open(
char* filename)
1097 ui32 max_bitdepth = 0;
1098 for (
ui32 c = 0; c < num_components; c++)
1100 if (bit_depth_of_data[c] > max_bitdepth)
1101 max_bitdepth = bit_depth_of_data[c];
1103 if (max_bitdepth > 16)
1105 OJPH_WARN(0x030000B1,
"TIFF output is currently limited to files "
1106 "with max_bitdepth = 16, the source codestream has max_bitdepth=%d"
1107 ", the decoded data will be truncated to 16 bits", max_bitdepth);
1109 if (num_components > 4)
1111 OJPH_ERROR(0x030000B2,
"TIFF IO is currently limited to files with "
1112 "num_components=1 to 4");
1115 assert(tiff_handle == NULL && buffer == NULL);
1116 if ((tiff_handle = TIFFOpen(filename,
"w")) == NULL)
1118 OJPH_ERROR(0x030000B3,
"unable to open file %s for writing", filename);
1121 buffer_size = width * (size_t)num_components * (
size_t)bytes_per_sample;
1122 buffer = (
ui8*)malloc(buffer_size);
1129 TIFFSetField(tiff_handle, TIFFTAG_IMAGEWIDTH, width);
1130 TIFFSetField(tiff_handle, TIFFTAG_IMAGELENGTH, height);
1132 TIFFSetField(tiff_handle, TIFFTAG_BITSPERSAMPLE, bytes_per_sample * 8);
1133 TIFFSetField(tiff_handle, TIFFTAG_SAMPLESPERPIXEL, num_components);
1135 planar_configuration = PLANARCONFIG_CONTIG;
1136 TIFFSetField(tiff_handle, TIFFTAG_PLANARCONFIG, planar_configuration);
1138 if (num_components == 1)
1140 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1142 else if (num_components == 2)
1144 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
1147 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1148 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1149 &extra_samples_description);
1151 else if (num_components == 3)
1153 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1155 else if (num_components == 4)
1157 TIFFSetField(tiff_handle, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
1160 const ui16 extra_samples_description[1] = { EXTRASAMPLE_ASSOCALPHA };
1161 TIFFSetField(tiff_handle, TIFFTAG_EXTRASAMPLES, (uint16_t)1,
1162 &extra_samples_description);
1165 TIFFSetField(tiff_handle, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
1166 TIFFSetField(tiff_handle, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
1168 TIFFSetField(tiff_handle, TIFFTAG_ROWSPERSTRIP, height);
1173 void tif_out::configure(
ui32 width,
ui32 height,
ui32 num_components,
1176 assert(tiff_handle == NULL);
1178 this->width = width;
1179 this->height = height;
1180 this->num_components = num_components;
1181 ui32 max_bitdepth = 0;
1182 for (
ui32 c = 0; c < num_components; c++)
1184 this->bit_depth_of_data[c] = bit_depth[c];
1185 if (bit_depth[c] > max_bitdepth)
1186 max_bitdepth = bit_depth[c];
1189 bytes_per_sample = (max_bitdepth + 7) / 8;
1190 if (bytes_per_sample > 2)
1194 bytes_per_sample = 2;
1196 samples_per_line = num_components * width;
1197 bytes_per_line = bytes_per_sample * (size_t)samples_per_line;
1204 assert(tiff_handle);
1206 if (bytes_per_sample == 1)
1208 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1209 const si32* sp = line->i32;
1210 ui8* dp = buffer + comp_num;
1211 if (bit_depth_of_data[comp_num] == 8)
1213 for (
ui32 i = width; i > 0; --i, dp += num_components)
1217 val = val >= 0 ? val : 0;
1218 val = val <= max_val ? val : max_val;
1222 else if (bit_depth_of_data[comp_num] < 8)
1224 const int bits_to_shift = 8 - (int)bit_depth_of_data[comp_num];
1225 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1226 for (
ui32 i = width; i > 0; --i, dp += num_components)
1230 val = val >= 0 ? val : 0;
1231 val = val <= max_val ? val : max_val;
1234 *dp = (
ui8)((val & bit_mask) << bits_to_shift);
1237 else if (bit_depth_of_data[comp_num] > 8)
1239 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 8;
1240 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1241 for (
ui32 i = width; i > 0; --i, dp += num_components)
1245 val = val >= 0 ? val : 0;
1246 val = val <= max_val ? val : max_val;
1249 *dp = (
ui8)((val >> bits_to_shift) & bit_mask);
1254 else if(bytes_per_sample == 2)
1256 int max_val = (1 << bit_depth_of_data[comp_num]) - 1;
1257 const si32* sp = line->i32;
1258 ui16* dp = (
ui16*)buffer + comp_num;
1260 if (bit_depth_of_data[comp_num] == 16)
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 else if (bit_depth_of_data[comp_num] < 16)
1273 const int bits_to_shift = 16 - (int)bit_depth_of_data[comp_num];
1274 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1275 for (
ui32 i = width; i > 0; --i, dp += num_components)
1279 val = val >= 0 ? val : 0;
1280 val = val <= max_val ? val : max_val;
1284 *dp = (
ui16)((val & bit_mask) << bits_to_shift);
1287 else if (bit_depth_of_data[comp_num] > 16)
1289 const int bits_to_shift = (int)bit_depth_of_data[comp_num] - 16;
1290 const int bit_mask = (1 << bit_depth_of_data[comp_num]) - 1;
1291 for (
ui32 i = width; i > 0; --i, dp += num_components)
1295 val = val >= 0 ? val : 0;
1296 val = val <= max_val ? val : max_val;
1300 *dp = (
ui16)((val >> bits_to_shift) & bit_mask);
1306 if (comp_num == num_components-1)
1308 int result = TIFFWriteScanline(tiff_handle, buffer, cur_line++);
1310 OJPH_ERROR(0x030000C1,
"error writing to file %s", fname);
1328 fh = fopen(filename,
"rb");
1330 OJPH_ERROR(0x030000D1,
"Unable to open file %s", filename);
1355 if (result !=
width[comp_num])
1365 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1373 for (
ui32 i =
width[comp_num]; i > 0; --i, ++sp)
1377 return width[comp_num];
1384 if (num_components != 1 && num_components !=3)
1385 OJPH_ERROR(0x030000F1,
"yuv_in support 1 or 3 components");
1386 this->
num_com = num_components;
1388 if (num_downsamplings < 1)
1389 OJPH_ERROR(0x030000F2,
"one or more downsampling must be provided");
1391 ui32 last_downsamp_idx = 0;
1392 for (
ui32 i = 0; i < num_components; ++i)
1395 last_downsamp_idx += last_downsamp_idx + 1 < num_downsamplings ? 1 : 0;
1397 this->subsampling[i] = cp_ds;
1400 for (
ui32 i = 0; i < num_components; ++i)
1410 if (num_bit_depths < 1)
1411 OJPH_ERROR(0x03000101,
"one or more bit_depths must be provided");
1412 ui32 last_bd_idx = 0;
1413 for (
ui32 i = 0; i < 3; ++i)
1416 last_bd_idx += last_bd_idx + 1 < num_bit_depths ? 1 : 0;
1418 this->bit_depth[i] = bd;
1451 fh = fopen(filename,
"wb");
1453 OJPH_ERROR(0x03000111,
"Unable to open file %s", filename);
1469 tw =
ojph_max(tw, this->comp_width[i]);
1488 for (
ui32 i = w; i > 0; --i)
1491 val = val >= 0 ? val : 0;
1492 val = val <= max_val ? val : max_val;
1502 for (
ui32 i = w; i > 0; --i)
1505 val = val >= 0 ? val : 0;
1506 val = val <= max_val ? val : max_val;
1528 fh = fopen(filename,
"rb");
1530 OJPH_ERROR(0x03000131,
"Unable to open file %s", filename);
1543 assert(comp_num == 0);
1545 if (result !=
width)
1570 for (
ui32 i =
width; i > 0; --i, sp += 3) {
1573 val |= (val & 0x800000) ? (
si32)0xFF000000 : 0;
1578 for (
ui32 i =
width; i > 0; --i, sp += 3)
1650 fh = fopen(filename,
"wb");
1652 OJPH_ERROR(0x03000141,
"Unable to open file %s", filename);
1662 this->width =
width;
1682 assert(comp_num == 0);
1710 *dp++ = (
ui8)(val >> 8);
1711 *dp++ = (
ui8)(val >> 16);
1772 *dp++ = (
ui8)(val >> 8);
1773 *dp++ = (
ui8)(val >> 16);
1827 OJPH_ERROR(0x03000161,
"Unable to open file %s", filename);
1835 OJPH_ERROR(0x03000162,
"Error reading file %s", filename);
1839 const ui32 dpx_magic_number = 0x53445058;
1840 if (dpx_magic_number == magic_number)
1845 else if (dpx_magic_number ==
be2le(magic_number))
1854 OJPH_ERROR(0x03000163,
"Error reading file %s - this does not appear "
1855 "to be a valid DPX file. It has magic number = 0x%08X. The magic "
1856 "number of a DPX file is 0x%08X.", filename, magic_number,
1865 OJPH_ERROR(0x03000164,
"Error reading file %s", filename);
1873 OJPH_ERROR(0x03000165,
"Error reading file %s", filename);
1880 OJPH_ERROR(0x03000166,
"Error reading file %s", filename);
1889 OJPH_ERROR(0x03000167,
"Error reading file %s", filename);
1896 OJPH_ERROR(0x03000168,
"Error reading file %s", filename);
1906 OJPH_ERROR(0x03000169,
"Error reading file %s", filename);
1915 OJPH_ERROR(0x0300016A,
"Error reading file %s", filename);
1924 OJPH_ERROR(0x0300016B,
"Error reading file %s", filename);
1933 OJPH_ERROR(0x0300016C,
"Error reading file %s", filename);
1941 OJPH_ERROR(0x0300016E,
"Error reading file %s", filename);
1950 OJPH_ERROR(0x0300016F,
"Error reading file %s", filename);
1958 OJPH_ERROR(0x03000170,
"Error reading file %s", filename);
1966 OJPH_ERROR(0x03000171,
"Error reading file %s", filename);
1974 OJPH_ERROR(0x03000172,
"Error reading file %s", filename);
1982 OJPH_ERROR(0x03000173,
"Error reading file %s", filename);
1990 OJPH_ERROR(0x03000174,
"Error reading file %s", filename);
2000 OJPH_ERROR(0x03000175,
"Error reading file %s", filename);
2010 OJPH_ERROR(0x03000176,
"Error reading file %s", filename);
2020 OJPH_ERROR(0x03000177,
"Error reading file %s", filename);
2039 / number_of_samples_per_32_bit_word;
2046 OJPH_ERROR(0x03000178,
"Unable to allocate %d bytes for line_buffer[] "
2054 OJPH_ERROR(0x03000179,
"Unable to allocate %d bytes for "
2055 "line_buffer_16bit_samples[] for file %s",
2086 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2094 line_buffer_ptr[i] =
be2le(line_buffer_ptr[i]);
2101 ui32 word_index = 0;
2110 (
ui16) ((line_buffer_ptr[word_index] & 0xFFC00000) >> 22);
2113 (
ui16) ((line_buffer_ptr[word_index] & 0x003FF000) >> 12);
2116 (
ui16) ((line_buffer_ptr[word_index] & 0x00000FFC) >> 2);
2130 OJPH_ERROR(0x03000182,
"file %s uses DPX image formats that are not "
2131 "yet supported by this software\n bitdepth_for_image_element_1 = "
2132 "%d\n num_comps=%d\npacking_for_image_element_1=%d\n "
2133 "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,...)