Blender  V2.93
logImageCore.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 1999,2000,2001 David Hodson <hodsond@acm.org>
17  */
18 
25 #include "logImageCore.h"
26 #include "cineonlib.h"
27 #include "dpxlib.h"
28 #include "logmemfile.h"
29 
30 #include <math.h>
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #include "BLI_fileops.h"
35 #include "BLI_utildefines.h"
36 
37 #include "IMB_imbuf.h"
38 
39 #include "MEM_guardedalloc.h"
40 
41 /*
42  * Declaration of static functions
43  */
44 
45 static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement, float *data);
46 static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement, float *data);
47 static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement, float *data);
48 static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement, float *data);
49 static int logImageElementGetData(LogImageFile *logImage, LogImageElement logElement, float *data);
50 static int logImageElementGetData1(LogImageFile *logImage,
51  LogImageElement logElement,
52  float *data);
53 static int logImageElementGetData8(LogImageFile *logImage,
54  LogImageElement logElement,
55  float *data);
56 static int logImageElementGetData10(LogImageFile *logImage,
57  LogImageElement logElement,
58  float *data);
59 static int logImageElementGetData10Packed(LogImageFile *logImage,
60  LogImageElement logElement,
61  float *data);
62 static int logImageElementGetData12(LogImageFile *logImage,
63  LogImageElement logElement,
64  float *data);
65 static int logImageElementGetData12Packed(LogImageFile *logImage,
66  LogImageElement logElement,
67  float *data);
68 static int logImageElementGetData16(LogImageFile *logImage,
69  LogImageElement logElement,
70  float *data);
71 static int convertLogElementToRGBA(float *src,
72  float *dst,
73  LogImageFile *logImage,
74  LogImageElement logElement,
75  int dstIsLinearRGB);
76 static int convertRGBAToLogElement(float *src,
77  float *dst,
78  LogImageFile *logImage,
79  LogImageElement logElement,
80  int srcIsLinearRGB);
81 
82 /*
83  * For debug purpose
84  */
85 
86 static int verbose = 0;
87 
88 void logImageSetVerbose(int verbosity)
89 {
90  verbose = verbosity;
91  cineonSetVerbose(verbosity);
92  dpxSetVerbose(verbosity);
93 }
94 
95 /*
96  * IO stuff
97  */
98 
99 int logImageIsDpx(const void *buffer, const unsigned int size)
100 {
101  unsigned int magicNum;
102  if (size < sizeof(magicNum)) {
103  return 0;
104  }
105  magicNum = *(unsigned int *)buffer;
106  return (magicNum == DPX_FILE_MAGIC || magicNum == swap_uint(DPX_FILE_MAGIC, 1));
107 }
108 
109 int logImageIsCineon(const void *buffer, const unsigned int size)
110 {
111  unsigned int magicNum;
112  if (size < sizeof(magicNum)) {
113  return 0;
114  }
115  magicNum = *(unsigned int *)buffer;
116  return (magicNum == CINEON_FILE_MAGIC || magicNum == swap_uint(CINEON_FILE_MAGIC, 1));
117 }
118 
119 LogImageFile *logImageOpenFromFile(const char *filename, int cineon)
120 {
121  unsigned int magicNum;
122  FILE *f = BLI_fopen(filename, "rb");
123 
124  (void)cineon;
125 
126  if (f == NULL) {
127  return NULL;
128  }
129 
130  if (fread(&magicNum, sizeof(magicNum), 1, f) != 1) {
131  fclose(f);
132  return NULL;
133  }
134 
135  fclose(f);
136 
137  if (logImageIsDpx(&magicNum, sizeof(magicNum))) {
138  return dpxOpen((const unsigned char *)filename, 0, 0);
139  }
140  if (logImageIsCineon(&magicNum, sizeof(magicNum))) {
141  return cineonOpen((const unsigned char *)filename, 0, 0);
142  }
143 
144  return NULL;
145 }
146 
147 LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size)
148 {
149  if (logImageIsDpx(buffer, size)) {
150  return dpxOpen(buffer, 1, size);
151  }
152  if (logImageIsCineon(buffer, size)) {
153  return cineonOpen(buffer, 1, size);
154  }
155 
156  return NULL;
157 }
158 
159 LogImageFile *logImageCreate(const char *filename,
160  int cineon,
161  int width,
162  int height,
163  int bitsPerSample,
164  int isLogarithmic,
165  int hasAlpha,
166  int referenceWhite,
167  int referenceBlack,
168  float gamma,
169  const char *creator)
170 {
171  /* referenceWhite, referenceBlack and gamma values are only supported for DPX file */
172  if (cineon) {
173  return cineonCreate(filename, width, height, bitsPerSample, creator);
174  }
175 
176  return dpxCreate(filename,
177  width,
178  height,
179  bitsPerSample,
180  isLogarithmic,
181  hasAlpha,
182  referenceWhite,
183  referenceBlack,
184  gamma,
185  creator);
186 
187  return NULL;
188 }
189 
191 {
192  if (logImage != NULL) {
193  if (logImage->file) {
194  fclose(logImage->file);
195  logImage->file = NULL;
196  }
197  MEM_freeN(logImage);
198  }
199 }
200 
201 void logImageGetSize(LogImageFile *logImage, int *width, int *height, int *depth)
202 {
203  *width = logImage->width;
204  *height = logImage->height;
205  *depth = logImage->depth;
206 }
207 
208 /*
209  * Helper
210  */
211 
212 size_t getRowLength(size_t width, LogImageElement logElement)
213 {
214  /* return the row length in bytes according to width and packing method */
215  switch (logElement.bitsPerSample) {
216  case 1:
217  return ((width * logElement.depth - 1) / 32 + 1) * 4;
218 
219  case 8:
220  return ((width * logElement.depth - 1) / 4 + 1) * 4;
221 
222  case 10:
223  if (logElement.packing == 0) {
224  return ((width * logElement.depth * 10 - 1) / 32 + 1) * 4;
225  }
226  else if (ELEM(logElement.packing, 1, 2)) {
227  return ((width * logElement.depth - 1) / 3 + 1) * 4;
228  }
229  break;
230  case 12:
231  if (logElement.packing == 0) {
232  return ((width * logElement.depth * 12 - 1) / 32 + 1) * 4;
233  }
234  else if (ELEM(logElement.packing, 1, 2)) {
235  return width * logElement.depth * 2;
236  }
237  break;
238  case 16:
239  return width * logElement.depth * 2;
240  }
241  return 0;
242 }
243 
244 /*
245  * Data writing
246  */
247 
248 int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
249 {
250  float *elementData;
251  int returnValue;
252 
253  elementData = (float *)imb_alloc_pixels(
254  logImage->width, logImage->height, logImage->depth, sizeof(float), __func__);
255  if (elementData == NULL) {
256  return 1;
257  }
258 
260  data, elementData, logImage, logImage->element[0], dataIsLinearRGB) != 0) {
261  MEM_freeN(elementData);
262  return 1;
263  }
264 
265  switch (logImage->element[0].bitsPerSample) {
266  case 8:
267  returnValue = logImageSetData8(logImage, logImage->element[0], elementData);
268  break;
269 
270  case 10:
271  returnValue = logImageSetData10(logImage, logImage->element[0], elementData);
272  break;
273 
274  case 12:
275  returnValue = logImageSetData12(logImage, logImage->element[0], elementData);
276  break;
277 
278  case 16:
279  returnValue = logImageSetData16(logImage, logImage->element[0], elementData);
280  break;
281 
282  default:
283  returnValue = 1;
284  break;
285  }
286 
287  MEM_freeN(elementData);
288  return returnValue;
289 }
290 
291 static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement, float *data)
292 {
293  size_t rowLength = getRowLength(logImage->width, logElement);
294  unsigned char *row;
295 
296  row = (unsigned char *)MEM_mallocN(rowLength, __func__);
297  if (row == NULL) {
298  if (verbose) {
299  printf("DPX/Cineon: Cannot allocate row.\n");
300  }
301  return 1;
302  }
303  memset(row, 0, rowLength);
304 
305  for (size_t y = 0; y < logImage->height; y++) {
306  for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
307  row[x] = (unsigned char)float_uint(data[y * logImage->width * logImage->depth + x], 255);
308  }
309 
310  if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
311  if (verbose) {
312  printf("DPX/Cineon: Error while writing file.\n");
313  }
314  MEM_freeN(row);
315  return 1;
316  }
317  }
318  MEM_freeN(row);
319  return 0;
320 }
321 
322 static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement, float *data)
323 {
324  size_t rowLength = getRowLength(logImage->width, logElement);
325  unsigned int pixel, index;
326  unsigned int *row;
327 
328  row = (unsigned int *)MEM_mallocN(rowLength, __func__);
329  if (row == NULL) {
330  if (verbose) {
331  printf("DPX/Cineon: Cannot allocate row.\n");
332  }
333  return 1;
334  }
335 
336  for (size_t y = 0; y < logImage->height; y++) {
337  int offset = 22;
338  index = 0;
339  pixel = 0;
340 
341  for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
342  pixel |= (unsigned int)float_uint(data[y * logImage->width * logImage->depth + x], 1023)
343  << offset;
344  offset -= 10;
345  if (offset < 0) {
346  row[index] = swap_uint(pixel, logImage->isMSB);
347  index++;
348  pixel = 0;
349  offset = 22;
350  }
351  }
352  if (pixel != 0) {
353  row[index] = swap_uint(pixel, logImage->isMSB);
354  }
355 
356  if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
357  if (verbose) {
358  printf("DPX/Cineon: Error while writing file.\n");
359  }
360  MEM_freeN(row);
361  return 1;
362  }
363  }
364  MEM_freeN(row);
365  return 0;
366 }
367 
368 static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement, float *data)
369 {
370  size_t rowLength = getRowLength(logImage->width, logElement);
371  unsigned short *row;
372 
373  row = (unsigned short *)MEM_mallocN(rowLength, __func__);
374  if (row == NULL) {
375  if (verbose) {
376  printf("DPX/Cineon: Cannot allocate row.\n");
377  }
378  return 1;
379  }
380 
381  for (size_t y = 0; y < logImage->height; y++) {
382  for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
383  row[x] = swap_ushort(
384  ((unsigned short)float_uint(data[y * logImage->width * logImage->depth + x], 4095)) << 4,
385  logImage->isMSB);
386  }
387 
388  if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
389  if (verbose) {
390  printf("DPX/Cineon: Error while writing file.\n");
391  }
392  MEM_freeN(row);
393  return 1;
394  }
395  }
396  MEM_freeN(row);
397  return 0;
398 }
399 
400 static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement, float *data)
401 {
402  size_t rowLength = getRowLength(logImage->width, logElement);
403  unsigned short *row;
404 
405  row = (unsigned short *)MEM_mallocN(rowLength, __func__);
406  if (row == NULL) {
407  if (verbose) {
408  printf("DPX/Cineon: Cannot allocate row.\n");
409  }
410  return 1;
411  }
412 
413  for (size_t y = 0; y < logImage->height; y++) {
414  for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
415  row[x] = swap_ushort(
416  (unsigned short)float_uint(data[y * logImage->width * logImage->depth + x], 65535),
417  logImage->isMSB);
418  }
419 
420  if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
421  if (verbose) {
422  printf("DPX/Cineon: Error while writing file.\n");
423  }
424  MEM_freeN(row);
425  return 1;
426  }
427  }
428  MEM_freeN(row);
429  return 0;
430 }
431 
432 /*
433  * Data reading
434  */
435 
436 int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
437 {
438  /* Fills data with 32 bits float RGBA values */
439  int i, j, returnValue, sortedElementData[8], hasAlpha;
440  float *elementData[8];
441  float *elementData_ptr[8];
442  float *mergedData;
443  unsigned int sampleIndex;
444  LogImageElement mergedElement;
445 
446  /* Determine the depth of the picture and if there's a separate alpha element.
447  * If the element is supported, load it into an unsigned ints array. */
448  memset(&elementData, 0, 8 * sizeof(float *));
449  hasAlpha = 0;
450 
451  for (i = 0; i < logImage->numElements; i++) {
452  /* descriptor_Depth and descriptor_Composite are not supported */
454  /* Allocate memory */
455  elementData[i] = imb_alloc_pixels(
456  logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__);
457  if (elementData[i] == NULL) {
458  if (verbose) {
459  printf("DPX/Cineon: Cannot allocate memory for elementData[%d]\n.", i);
460  }
461  for (j = 0; j < i; j++) {
462  if (elementData[j] != NULL) {
463  MEM_freeN(elementData[j]);
464  }
465  }
466  return 1;
467  }
468  elementData_ptr[i] = elementData[i];
469 
470  /* Load data */
471  if (logImageElementGetData(logImage, logImage->element[i], elementData[i]) != 0) {
472  if (verbose) {
473  printf("DPX/Cineon: Cannot read elementData[%d]\n.", i);
474  }
475  for (j = 0; j < i; j++) {
476  if (elementData[j] != NULL) {
477  MEM_freeN(elementData[j]);
478  }
479  }
480  return 1;
481  }
482  }
483 
484  if (logImage->element[i].descriptor == descriptor_Alpha) {
485  hasAlpha = 1;
486  }
487  }
488 
489  /* only one element, easy case, no need to do anything */
490  if (logImage->numElements == 1) {
491  returnValue = convertLogElementToRGBA(
492  elementData[0], data, logImage, logImage->element[0], dataIsLinearRGB);
493  MEM_freeN(elementData[0]);
494  }
495  else {
496  /* The goal here is to merge every elements into only one
497  * to recreate a classic 16 bits RGB, RGBA or YCbCr element.
498  * Unsupported elements are skipped (depth, composite) */
499 
500  memcpy(&mergedElement, &logImage->element[0], sizeof(LogImageElement));
501  mergedElement.descriptor = -1;
502  mergedElement.depth = logImage->depth;
503  memset(&sortedElementData, -1, sizeof(int[8]));
504 
505  /* Try to know how to assemble the elements */
506  for (i = 0; i < logImage->numElements; i++) {
507  switch (logImage->element[i].descriptor) {
508  case descriptor_Red:
509  case descriptor_RGB:
510  if (hasAlpha == 0) {
511  mergedElement.descriptor = descriptor_RGB;
512  }
513  else {
514  mergedElement.descriptor = descriptor_RGBA;
515  }
516 
517  sortedElementData[0] = i;
518  break;
519 
520  case descriptor_Green:
521  if (hasAlpha == 0) {
522  mergedElement.descriptor = descriptor_RGB;
523  }
524  else {
525  mergedElement.descriptor = descriptor_RGBA;
526  }
527 
528  sortedElementData[1] = i;
529  break;
530 
531  case descriptor_Blue:
532  if (hasAlpha == 0) {
533  mergedElement.descriptor = descriptor_RGB;
534  }
535  else {
536  mergedElement.descriptor = descriptor_RGBA;
537  }
538 
539  sortedElementData[2] = i;
540  break;
541 
542  case descriptor_Alpha:
543  /* Alpha component is always the last one */
544  sortedElementData[mergedElement.depth - 1] = i;
545  break;
546 
548  if (mergedElement.descriptor == -1) {
549  if (hasAlpha == 0) {
550  mergedElement.descriptor = descriptor_Luminance;
551  }
552  else {
553  mergedElement.descriptor = descriptor_YA;
554  }
555  }
556  else if (mergedElement.descriptor == descriptor_Chrominance) {
557  if (mergedElement.depth == 2) {
558  mergedElement.descriptor = descriptor_CbYCrY;
559  }
560  else if (mergedElement.depth == 3) {
561  if (hasAlpha == 0) {
562  mergedElement.descriptor = descriptor_CbYCr;
563  }
564  else {
565  mergedElement.descriptor = descriptor_CbYACrYA;
566  }
567  }
568  else if (mergedElement.depth == 4) {
569  mergedElement.descriptor = descriptor_CbYCrA;
570  }
571  }
572 
573  /* Y component always in 1 except if it's alone or with alpha */
574  if (mergedElement.depth == 1 || (mergedElement.depth == 2 && hasAlpha == 1)) {
575  sortedElementData[0] = i;
576  }
577  else {
578  sortedElementData[1] = i;
579  }
580  break;
581 
583  if (mergedElement.descriptor == -1) {
584  mergedElement.descriptor = descriptor_Chrominance;
585  }
586  else if (mergedElement.descriptor == descriptor_Luminance) {
587  if (mergedElement.depth == 2) {
588  mergedElement.descriptor = descriptor_CbYCrY;
589  }
590  else if (mergedElement.depth == 3) {
591  if (hasAlpha == 0) {
592  mergedElement.descriptor = descriptor_CbYCr;
593  }
594  else {
595  mergedElement.descriptor = descriptor_CbYACrYA;
596  }
597  }
598  else if (mergedElement.depth == 4) {
599  mergedElement.descriptor = descriptor_CbYCrA;
600  }
601  }
602 
603  /* Cb and Cr always in 0 or 2 */
604  if (sortedElementData[0] == -1) {
605  sortedElementData[0] = i;
606  }
607  else {
608  sortedElementData[2] = i;
609  }
610  break;
611 
612  case descriptor_CbYCr:
613  if (hasAlpha == 0) {
614  mergedElement.descriptor = descriptor_CbYCr;
615  }
616  else {
617  mergedElement.descriptor = descriptor_CbYCrA;
618  }
619 
620  sortedElementData[0] = i;
621  break;
622 
623  case descriptor_RGBA:
624  case descriptor_ABGR:
625  case descriptor_CbYACrYA:
626  case descriptor_CbYCrY:
627  case descriptor_CbYCrA:
628  /* I don't think these ones can be seen in a planar image */
629  mergedElement.descriptor = logImage->element[i].descriptor;
630  sortedElementData[0] = i;
631  break;
632 
633  case descriptor_Depth:
635  /* Not supported */
636  break;
637  }
638  }
639 
640  mergedData = (float *)imb_alloc_pixels(
641  logImage->width, logImage->height, mergedElement.depth, sizeof(float), __func__);
642  if (mergedData == NULL) {
643  if (verbose) {
644  printf("DPX/Cineon: Cannot allocate mergedData.\n");
645  }
646  for (i = 0; i < logImage->numElements; i++) {
647  if (elementData[i] != NULL) {
648  MEM_freeN(elementData[i]);
649  }
650  }
651  return 1;
652  }
653 
654  sampleIndex = 0;
655  while (sampleIndex < logImage->width * logImage->height * mergedElement.depth) {
656  for (i = 0; i < logImage->numElements; i++) {
657  for (j = 0; j < logImage->element[sortedElementData[i]].depth; j++) {
658  mergedData[sampleIndex++] = *(elementData_ptr[sortedElementData[i]]++);
659  }
660  }
661  }
662 
663  /* Done with elements data, clean-up */
664  for (i = 0; i < logImage->numElements; i++) {
665  if (elementData[i] != NULL) {
666  MEM_freeN(elementData[i]);
667  }
668  }
669 
670  returnValue = convertLogElementToRGBA(
671  mergedData, data, logImage, mergedElement, dataIsLinearRGB);
672  MEM_freeN(mergedData);
673  }
674  return returnValue;
675 }
676 
677 static int logImageElementGetData(LogImageFile *logImage, LogImageElement logElement, float *data)
678 {
679  switch (logElement.bitsPerSample) {
680  case 1:
681  return logImageElementGetData1(logImage, logElement, data);
682 
683  case 8:
684  return logImageElementGetData8(logImage, logElement, data);
685 
686  case 10:
687  if (logElement.packing == 0) {
688  return logImageElementGetData10Packed(logImage, logElement, data);
689  }
690  else if (ELEM(logElement.packing, 1, 2)) {
691  return logImageElementGetData10(logImage, logElement, data);
692  }
693  break;
694 
695  case 12:
696  if (logElement.packing == 0) {
697  return logImageElementGetData12Packed(logImage, logElement, data);
698  }
699  else if (ELEM(logElement.packing, 1, 2)) {
700  return logImageElementGetData12(logImage, logElement, data);
701  }
702  break;
703 
704  case 16:
705  return logImageElementGetData16(logImage, logElement, data);
706  }
707  /* format not supported */
708  return 1;
709 }
710 
711 static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logElement, float *data)
712 {
713  unsigned int pixel;
714 
715  /* seek at the right place */
716  if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
717  if (verbose) {
718  printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
719  }
720  return 1;
721  }
722 
723  /* read 1 bit data padded to 32 bits */
724  for (size_t y = 0; y < logImage->height; y++) {
725  for (size_t x = 0; x < logImage->width * logElement.depth; x += 32) {
726  if (logimage_read_uint(&pixel, logImage) != 0) {
727  if (verbose) {
728  printf("DPX/Cineon: EOF reached\n");
729  }
730  return 1;
731  }
732  pixel = swap_uint(pixel, logImage->isMSB);
733  for (int offset = 0; offset < 32 && x + offset < logImage->width; offset++) {
734  data[y * logImage->width * logElement.depth + x + offset] = (float)((pixel >> offset) &
735  0x01);
736  }
737  }
738  }
739  return 0;
740 }
741 
742 static int logImageElementGetData8(LogImageFile *logImage, LogImageElement logElement, float *data)
743 {
744  size_t rowLength = getRowLength(logImage->width, logElement);
745  unsigned char pixel;
746 
747  /* extract required pixels */
748  for (size_t y = 0; y < logImage->height; y++) {
749  /* 8 bits are 32-bits padded so we need to seek at each row */
750  if (logimage_fseek(logImage, logElement.dataOffset + y * rowLength, SEEK_SET) != 0) {
751  if (verbose) {
752  printf("DPX/Cineon: Couldn't seek at %d\n", (int)(logElement.dataOffset + y * rowLength));
753  }
754  return 1;
755  }
756 
757  for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
758  if (logimage_read_uchar(&pixel, logImage) != 0) {
759  if (verbose) {
760  printf("DPX/Cineon: EOF reached\n");
761  }
762  return 1;
763  }
764  data[y * logImage->width * logElement.depth + x] = (float)pixel / 255.0f;
765  }
766  }
767  return 0;
768 }
769 
771  LogImageElement logElement,
772  float *data)
773 {
774  unsigned int pixel;
775 
776  /* seek to data */
777  if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
778  if (verbose) {
779  printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
780  }
781  return 1;
782  }
783 
784  if (logImage->depth == 1 && logImage->srcFormat == format_DPX) {
785  for (size_t y = 0; y < logImage->height; y++) {
786  int offset = 32;
787  for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
788  /* we need to read the next long */
789  if (offset >= 30) {
790  if (logElement.packing == 1) {
791  offset = 2;
792  }
793  else if (logElement.packing == 2) {
794  offset = 0;
795  }
796 
797  if (logimage_read_uint(&pixel, logImage) != 0) {
798  if (verbose) {
799  printf("DPX/Cineon: EOF reached\n");
800  }
801  return 1;
802  }
803  pixel = swap_uint(pixel, logImage->isMSB);
804  }
805  data[y * logImage->width * logElement.depth + x] = (float)((pixel >> offset) & 0x3ff) /
806  1023.0f;
807  offset += 10;
808  }
809  }
810  }
811  else {
812  for (size_t y = 0; y < logImage->height; y++) {
813  int offset = -1;
814  for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
815  /* we need to read the next long */
816  if (offset < 0) {
817  if (logElement.packing == 1) {
818  offset = 22;
819  }
820  else if (logElement.packing == 2) {
821  offset = 20;
822  }
823 
824  if (logimage_read_uint(&pixel, logImage) != 0) {
825  if (verbose) {
826  printf("DPX/Cineon: EOF reached\n");
827  }
828  return 1;
829  }
830  pixel = swap_uint(pixel, logImage->isMSB);
831  }
832  data[y * logImage->width * logElement.depth + x] = (float)((pixel >> offset) & 0x3ff) /
833  1023.0f;
834  offset -= 10;
835  }
836  }
837  }
838 
839  return 0;
840 }
841 
843  LogImageElement logElement,
844  float *data)
845 {
846  size_t rowLength = getRowLength(logImage->width, logElement);
847  unsigned int pixel, oldPixel;
848 
849  /* converting bytes to pixels */
850  for (size_t y = 0; y < logImage->height; y++) {
851  /* seek to data */
852  if (logimage_fseek(logImage, y * rowLength + logElement.dataOffset, SEEK_SET) != 0) {
853  if (verbose) {
854  printf("DPX/Cineon: Couldn't seek at %u\n",
855  (unsigned int)(y * rowLength + logElement.dataOffset));
856  }
857  return 1;
858  }
859 
860  oldPixel = 0;
861  int offset = 0;
862  int offset2 = 0;
863 
864  for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
865  if (offset2 != 0) {
866  offset = 10 - offset2;
867  offset2 = 0;
868  oldPixel = 0;
869  }
870  else if (offset == 32) {
871  offset = 0;
872  }
873  else if (offset + 10 > 32) {
874  /* next pixel is on two different longs */
875  oldPixel = (pixel >> offset);
876  offset2 = 32 - offset;
877  offset = 0;
878  }
879 
880  if (offset == 0) {
881  /* we need to read the next long */
882  if (logimage_read_uint(&pixel, logImage) != 0) {
883  if (verbose) {
884  printf("DPX/Cineon: EOF reached\n");
885  }
886  return 1;
887  }
888  pixel = swap_uint(pixel, logImage->isMSB);
889  }
890  data[y * logImage->width * logElement.depth + x] =
891  (float)((((pixel << offset2) >> offset) & 0x3ff) | oldPixel) / 1023.0f;
892  offset += 10;
893  }
894  }
895  return 0;
896 }
897 
899  LogImageElement logElement,
900  float *data)
901 {
902  unsigned int sampleIndex;
903  unsigned int numSamples = logImage->width * logImage->height * logElement.depth;
904  unsigned short pixel;
905 
906  /* seek to data */
907  if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
908  if (verbose) {
909  printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
910  }
911  return 1;
912  }
913 
914  /* convert bytes to pixels */
915  sampleIndex = 0;
916 
917  for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
918  if (logimage_read_ushort(&pixel, logImage) != 0) {
919  if (verbose) {
920  printf("DPX/Cineon: EOF reached\n");
921  }
922  return 1;
923  }
924  pixel = swap_ushort(pixel, logImage->isMSB);
925 
926  if (logElement.packing == 1) { /* padded to the right */
927  data[sampleIndex] = (float)(pixel >> 4) / 4095.0f;
928  }
929  else if (logElement.packing == 2) { /* padded to the left */
930  data[sampleIndex] = (float)pixel / 4095.0f;
931  }
932  }
933  return 0;
934 }
935 
937  LogImageElement logElement,
938  float *data)
939 {
940  size_t rowLength = getRowLength(logImage->width, logElement);
941  unsigned int pixel, oldPixel;
942 
943  /* converting bytes to pixels */
944  for (size_t y = 0; y < logImage->height; y++) {
945  /* seek to data */
946  if (logimage_fseek(logImage, y * rowLength + logElement.dataOffset, SEEK_SET) != 0) {
947  if (verbose) {
948  printf("DPX/Cineon: Couldn't seek at %u\n",
949  (unsigned int)(y * rowLength + logElement.dataOffset));
950  }
951  return 1;
952  }
953 
954  oldPixel = 0;
955  int offset = 0;
956  int offset2 = 0;
957 
958  for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
959  if (offset2 != 0) {
960  offset = 12 - offset2;
961  offset2 = 0;
962  oldPixel = 0;
963  }
964  else if (offset == 32) {
965  offset = 0;
966  }
967  else if (offset + 12 > 32) {
968  /* next pixel is on two different longs */
969  oldPixel = (pixel >> offset);
970  offset2 = 32 - offset;
971  offset = 0;
972  }
973 
974  if (offset == 0) {
975  /* we need to read the next long */
976  if (logimage_read_uint(&pixel, logImage) != 0) {
977  if (verbose) {
978  printf("DPX/Cineon: EOF reached\n");
979  }
980  return 1;
981  }
982  pixel = swap_uint(pixel, logImage->isMSB);
983  }
984  data[y * logImage->width * logElement.depth + x] =
985  (float)((((pixel << offset2) >> offset) & 0xfff) | oldPixel) / 4095.0f;
986  offset += 12;
987  }
988  }
989  return 0;
990 }
991 
993  LogImageElement logElement,
994  float *data)
995 {
996  unsigned int numSamples = logImage->width * logImage->height * logElement.depth;
997  unsigned int sampleIndex;
998  unsigned short pixel;
999 
1000  /* seek to data */
1001  if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
1002  if (verbose) {
1003  printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
1004  }
1005  return 1;
1006  }
1007 
1008  for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
1009  if (logimage_read_ushort(&pixel, logImage) != 0) {
1010  if (verbose) {
1011  printf("DPX/Cineon: EOF reached\n");
1012  }
1013  return 1;
1014  }
1015  pixel = swap_ushort(pixel, logImage->isMSB);
1016  data[sampleIndex] = (float)pixel / 65535.0f;
1017  }
1018 
1019  return 0;
1020 }
1021 
1022 /*
1023  * Color conversion
1024  */
1025 
1026 static int getYUVtoRGBMatrix(float *matrix, LogImageElement logElement)
1027 {
1028  float scaleY, scaleCbCr;
1029  float refHighData = (float)logElement.refHighData / logElement.maxValue;
1030  float refLowData = (float)logElement.refLowData / logElement.maxValue;
1031 
1032  scaleY = 1.0f / (refHighData - refLowData);
1033  scaleCbCr = scaleY * ((940.0f - 64.0f) / (960.0f - 64.0f));
1034 
1035  switch (logElement.transfer) {
1036  case 2: /* linear */
1037  matrix[0] = 1.0f * scaleY;
1038  matrix[1] = 1.0f * scaleCbCr;
1039  matrix[2] = 1.0f * scaleCbCr;
1040  matrix[3] = 1.0f * scaleY;
1041  matrix[4] = 1.0f * scaleCbCr;
1042  matrix[5] = 1.0f * scaleCbCr;
1043  matrix[6] = 1.0f * scaleY;
1044  matrix[7] = 1.0f * scaleCbCr;
1045  matrix[8] = 1.0f * scaleCbCr;
1046  return 0;
1047 
1048  case 5: /* SMPTE 240M */
1049  matrix[0] = 1.0000f * scaleY;
1050  matrix[1] = 0.0000f * scaleCbCr;
1051  matrix[2] = 1.5756f * scaleCbCr;
1052  matrix[3] = 1.0000f * scaleY;
1053  matrix[4] = -0.2253f * scaleCbCr;
1054  matrix[5] = -0.5000f * scaleCbCr;
1055  matrix[6] = 1.0000f * scaleY;
1056  matrix[7] = 1.8270f * scaleCbCr;
1057  matrix[8] = 0.0000f * scaleCbCr;
1058  return 0;
1059 
1060  case 6: /* CCIR 709-1 */
1061  matrix[0] = 1.000000f * scaleY;
1062  matrix[1] = 0.000000f * scaleCbCr;
1063  matrix[2] = 1.574800f * scaleCbCr;
1064  matrix[3] = 1.000000f * scaleY;
1065  matrix[4] = -0.187324f * scaleCbCr;
1066  matrix[5] = -0.468124f * scaleCbCr;
1067  matrix[6] = 1.000000f * scaleY;
1068  matrix[7] = 1.855600f * scaleCbCr;
1069  matrix[8] = 0.000000f * scaleCbCr;
1070  return 0;
1071 
1072  case 7: /* CCIR 601 */
1073  case 8: /* I'm not sure 7 and 8 should share the same matrix */
1074  matrix[0] = 1.000000f * scaleY;
1075  matrix[1] = 0.000000f * scaleCbCr;
1076  matrix[2] = 1.402000f * scaleCbCr;
1077  matrix[3] = 1.000000f * scaleY;
1078  matrix[4] = -0.344136f * scaleCbCr;
1079  matrix[5] = -0.714136f * scaleCbCr;
1080  matrix[6] = 1.000000f * scaleY;
1081  matrix[7] = 1.772000f * scaleCbCr;
1082  matrix[8] = 0.000000f * scaleCbCr;
1083  return 0;
1084 
1085  default:
1086  return 1;
1087  }
1088 }
1089 
1090 static float *getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
1091 {
1092  float *lut;
1093  float gain, negativeFilmGamma, offset, step;
1094  unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
1095  unsigned int i;
1096 
1097  lut = MEM_mallocN(sizeof(float) * lutsize, "getLinToLogLut");
1098 
1099  negativeFilmGamma = 0.6;
1100  step = logElement.refHighQuantity / logElement.maxValue;
1101  gain = logElement.maxValue /
1102  (1.0f - powf(10,
1103  (logImage->referenceBlack - logImage->referenceWhite) * step /
1104  negativeFilmGamma * logImage->gamma / 1.7f));
1105  offset = gain - logElement.maxValue;
1106 
1107  for (i = 0; i < lutsize; i++) {
1108  lut[i] = (logImage->referenceWhite +
1109  log10f(powf((i + offset) / gain, 1.7f / logImage->gamma)) /
1110  (step / negativeFilmGamma)) /
1111  logElement.maxValue;
1112  }
1113 
1114  return lut;
1115 }
1116 
1117 static float *getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
1118 {
1119  float *lut;
1120  float breakPoint, gain, kneeGain, kneeOffset, negativeFilmGamma, offset, step, softClip;
1121  /* float filmGamma; unused */
1122  unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
1123  unsigned int i;
1124 
1125  lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
1126 
1127  /* Building the Log -> Lin LUT */
1128  step = logElement.refHighQuantity / logElement.maxValue;
1129  negativeFilmGamma = 0.6;
1130 
1131  /* these are default values */
1132  /* filmGamma = 2.2f; unused */
1133  softClip = 0;
1134 
1135  breakPoint = logImage->referenceWhite - softClip;
1136  gain = logElement.maxValue /
1137  (1.0f - powf(10,
1138  (logImage->referenceBlack - logImage->referenceWhite) * step /
1139  negativeFilmGamma * logImage->gamma / 1.7f));
1140  offset = gain - logElement.maxValue;
1141  kneeOffset = powf(10,
1142  (breakPoint - logImage->referenceWhite) * step / negativeFilmGamma *
1143  logImage->gamma / 1.7f) *
1144  gain -
1145  offset;
1146  kneeGain = (logElement.maxValue - kneeOffset) / powf(5 * softClip, softClip / 100);
1147 
1148  for (i = 0; i < lutsize; i++) {
1149  if (i < logImage->referenceBlack) {
1150  lut[i] = 0.0f;
1151  }
1152  else if (i > breakPoint) {
1153  lut[i] = (powf(i - breakPoint, softClip / 100) * kneeGain + kneeOffset) /
1154  logElement.maxValue;
1155  }
1156  else {
1157  lut[i] = (powf(10,
1158  ((float)i - logImage->referenceWhite) * step / negativeFilmGamma *
1159  logImage->gamma / 1.7f) *
1160  gain -
1161  offset) /
1162  logElement.maxValue;
1163  }
1164  }
1165 
1166  return lut;
1167 }
1168 
1169 static float *getLinToSrgbLut(LogImageElement logElement)
1170 {
1171  float col, *lut;
1172  unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
1173  unsigned int i;
1174 
1175  lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
1176 
1177  for (i = 0; i < lutsize; i++) {
1178  col = (float)i / logElement.maxValue;
1179  if (col < 0.0031308f) {
1180  lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
1181  }
1182  else {
1183  lut[i] = 1.055f * powf(col, 1.0f / 2.4f) - 0.055f;
1184  }
1185  }
1186 
1187  return lut;
1188 }
1189 
1190 static float *getSrgbToLinLut(LogImageElement logElement)
1191 {
1192  float col, *lut;
1193  unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
1194  unsigned int i;
1195 
1196  lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
1197 
1198  for (i = 0; i < lutsize; i++) {
1199  col = (float)i / logElement.maxValue;
1200  if (col < 0.04045f) {
1201  lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
1202  }
1203  else {
1204  lut[i] = powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
1205  }
1206  }
1207 
1208  return lut;
1209 }
1210 
1211 static int convertRGBA_RGB(float *src,
1212  float *dst,
1213  LogImageFile *logImage,
1214  LogImageElement logElement,
1215  int elementIsSource)
1216 {
1217  unsigned int i;
1218  float *src_ptr = src;
1219  float *dst_ptr = dst;
1220 
1221  switch (logElement.transfer) {
1222  case transfer_Unspecified:
1223  case transfer_UserDefined:
1224  case transfer_Linear:
1225  case transfer_Logarithmic: {
1226  for (i = 0; i < logImage->width * logImage->height; i++) {
1227  *(dst_ptr++) = *(src_ptr++);
1228  *(dst_ptr++) = *(src_ptr++);
1229  *(dst_ptr++) = *(src_ptr++);
1230  src_ptr++;
1231  }
1232 
1233  return 0;
1234  }
1235 
1236  case transfer_PrintingDensity: {
1237  float *lut;
1238 
1239  if (elementIsSource == 1) {
1240  lut = getLogToLinLut(logImage, logElement);
1241  }
1242  else {
1243  lut = getLinToLogLut(logImage, logElement);
1244  }
1245 
1246  for (i = 0; i < logImage->width * logImage->height; i++) {
1247  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1248  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1249  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1250  src_ptr++;
1251  }
1252 
1253  MEM_freeN(lut);
1254 
1255  return 0;
1256  }
1257 
1258  default:
1259  if (verbose) {
1260  printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
1261  }
1262  return 1;
1263  }
1264 }
1265 
1266 static int convertRGB_RGBA(float *src,
1267  float *dst,
1268  LogImageFile *logImage,
1269  LogImageElement logElement,
1270  int elementIsSource)
1271 {
1272  unsigned int i;
1273  float *src_ptr = src;
1274  float *dst_ptr = dst;
1275 
1276  switch (logElement.transfer) {
1277  case transfer_Unspecified:
1278  case transfer_UserDefined:
1279  case transfer_Linear:
1280  case transfer_Logarithmic: {
1281  for (i = 0; i < logImage->width * logImage->height; i++) {
1282  *(dst_ptr++) = *(src_ptr++);
1283  *(dst_ptr++) = *(src_ptr++);
1284  *(dst_ptr++) = *(src_ptr++);
1285  *(dst_ptr++) = 1.0f;
1286  }
1287 
1288  return 0;
1289  }
1290 
1291  case transfer_PrintingDensity: {
1292  float *lut;
1293 
1294  if (elementIsSource == 1) {
1295  lut = getLogToLinLut(logImage, logElement);
1296  }
1297  else {
1298  lut = getLinToLogLut(logImage, logElement);
1299  }
1300 
1301  for (i = 0; i < logImage->width * logImage->height; i++) {
1302  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1303  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1304  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1305  *(dst_ptr++) = 1.0f;
1306  }
1307 
1308  MEM_freeN(lut);
1309 
1310  return 0;
1311  }
1312 
1313  default:
1314  if (verbose) {
1315  printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
1316  }
1317  return 1;
1318  }
1319 }
1320 
1321 static int convertRGBA_RGBA(float *src,
1322  float *dst,
1323  LogImageFile *logImage,
1324  LogImageElement logElement,
1325  int elementIsSource)
1326 {
1327  unsigned int i;
1328  float *src_ptr = src;
1329  float *dst_ptr = dst;
1330 
1331  switch (logElement.transfer) {
1332  case transfer_UserDefined:
1333  case transfer_Linear:
1334  case transfer_Logarithmic: {
1335  memcpy(dst, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
1336  return 0;
1337  }
1338 
1339  case transfer_PrintingDensity: {
1340  float *lut;
1341 
1342  if (elementIsSource == 1) {
1343  lut = getLogToLinLut(logImage, logElement);
1344  }
1345  else {
1346  lut = getLinToLogLut(logImage, logElement);
1347  }
1348 
1349  for (i = 0; i < logImage->width * logImage->height; i++) {
1350  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1351  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1352  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1353  *(dst_ptr++) = *(src_ptr++);
1354  }
1355 
1356  MEM_freeN(lut);
1357 
1358  return 0;
1359  }
1360 
1361  default:
1362  return 1;
1363  }
1364 }
1365 
1366 static int convertABGR_RGBA(float *src,
1367  float *dst,
1368  LogImageFile *logImage,
1369  LogImageElement logElement,
1370  int elementIsSource)
1371 {
1372  unsigned int i;
1373  float *src_ptr = src;
1374  float *dst_ptr = dst;
1375 
1376  switch (logElement.transfer) {
1377  case transfer_UserDefined:
1378  case transfer_Linear:
1379  case transfer_Logarithmic: {
1380  for (i = 0; i < logImage->width * logImage->height; i++) {
1381  src_ptr += 4;
1382  *(dst_ptr++) = *(src_ptr--);
1383  *(dst_ptr++) = *(src_ptr--);
1384  *(dst_ptr++) = *(src_ptr--);
1385  *(dst_ptr++) = *(src_ptr--);
1386  src_ptr += 4;
1387  }
1388  return 0;
1389  }
1390 
1391  case transfer_PrintingDensity: {
1392  float *lut;
1393 
1394  if (elementIsSource == 1) {
1395  lut = getLogToLinLut(logImage, logElement);
1396  }
1397  else {
1398  lut = getLinToLogLut(logImage, logElement);
1399  }
1400 
1401  for (i = 0; i < logImage->width * logImage->height; i++) {
1402  src_ptr += 4;
1403  *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
1404  *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
1405  *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
1406  *(dst_ptr++) = *(src_ptr--);
1407  src_ptr += 4;
1408  }
1409 
1410  MEM_freeN(lut);
1411 
1412  return 0;
1413  }
1414 
1415  default:
1416  return 1;
1417  }
1418 }
1419 
1420 static int convertCbYCr_RGBA(float *src,
1421  float *dst,
1422  LogImageFile *logImage,
1423  LogImageElement logElement)
1424 {
1425  unsigned int i;
1426  float conversionMatrix[9], refLowData, y, cb, cr;
1427  float *src_ptr = src;
1428  float *dst_ptr = dst;
1429 
1430  if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
1431  return 1;
1432  }
1433 
1434  refLowData = (float)logElement.refLowData / logElement.maxValue;
1435 
1436  for (i = 0; i < logImage->width * logImage->height; i++) {
1437  cb = *(src_ptr++) - 0.5f;
1438  y = *(src_ptr++) - refLowData;
1439  cr = *(src_ptr++) - 0.5f;
1440 
1441  *(dst_ptr++) = clamp_float(
1442  y * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
1443  *(dst_ptr++) = clamp_float(
1444  y * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
1445  *(dst_ptr++) = clamp_float(
1446  y * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
1447  *(dst_ptr++) = 1.0f;
1448  }
1449  return 0;
1450 }
1451 
1452 static int convertCbYCrA_RGBA(float *src,
1453  float *dst,
1454  LogImageFile *logImage,
1455  LogImageElement logElement)
1456 {
1457  unsigned int i;
1458  float conversionMatrix[9], refLowData, y, cb, cr, a;
1459  float *src_ptr = src;
1460  float *dst_ptr = dst;
1461 
1462  if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
1463  return 1;
1464  }
1465 
1466  refLowData = (float)logElement.refLowData / logElement.maxValue;
1467 
1468  for (i = 0; i < logImage->width * logImage->height; i++) {
1469  cb = *(src_ptr++) - 0.5f;
1470  y = *(src_ptr++) - refLowData;
1471  cr = *(src_ptr++) - 0.5f;
1472  a = *(src_ptr++);
1473 
1474  *(dst_ptr++) = clamp_float(
1475  y * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
1476  *(dst_ptr++) = clamp_float(
1477  y * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
1478  *(dst_ptr++) = clamp_float(
1479  y * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
1480  *(dst_ptr++) = a;
1481  }
1482  return 0;
1483 }
1484 
1485 static int convertCbYCrY_RGBA(float *src,
1486  float *dst,
1487  LogImageFile *logImage,
1488  LogImageElement logElement)
1489 {
1490  unsigned int i;
1491  float conversionMatrix[9], refLowData, y1, y2, cb, cr;
1492  float *src_ptr = src;
1493  float *dst_ptr = dst;
1494 
1495  if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
1496  return 1;
1497  }
1498 
1499  refLowData = (float)logElement.refLowData / logElement.maxValue;
1500 
1501  for (i = 0; i < logImage->width * logImage->height / 2; i++) {
1502  cb = *(src_ptr++) - 0.5f;
1503  y1 = *(src_ptr++) - refLowData;
1504  cr = *(src_ptr++) - 0.5f;
1505  y2 = *(src_ptr++) - refLowData;
1506 
1507  *(dst_ptr++) = clamp_float(y1 * conversionMatrix[0] + cb * conversionMatrix[1] +
1508  cr * conversionMatrix[2],
1509  0.0f,
1510  1.0f);
1511  *(dst_ptr++) = clamp_float(y1 * conversionMatrix[3] + cb * conversionMatrix[4] +
1512  cr * conversionMatrix[5],
1513  0.0f,
1514  1.0f);
1515  *(dst_ptr++) = clamp_float(y1 * conversionMatrix[6] + cb * conversionMatrix[7] +
1516  cr * conversionMatrix[8],
1517  0.0f,
1518  1.0f);
1519  *(dst_ptr++) = 1.0f;
1520  *(dst_ptr++) = clamp_float(y2 * conversionMatrix[0] + cb * conversionMatrix[1] +
1521  cr * conversionMatrix[2],
1522  0.0f,
1523  1.0f);
1524  *(dst_ptr++) = clamp_float(y2 * conversionMatrix[3] + cb * conversionMatrix[4] +
1525  cr * conversionMatrix[5],
1526  0.0f,
1527  1.0f);
1528  *(dst_ptr++) = clamp_float(y2 * conversionMatrix[6] + cb * conversionMatrix[7] +
1529  cr * conversionMatrix[8],
1530  0.0f,
1531  1.0f);
1532  *(dst_ptr++) = 1.0f;
1533  }
1534  return 0;
1535 }
1536 
1537 static int convertCbYACrYA_RGBA(float *src,
1538  float *dst,
1539  LogImageFile *logImage,
1540  LogImageElement logElement)
1541 {
1542  unsigned int i;
1543  float conversionMatrix[9], refLowData, y1, y2, cb, cr, a1, a2;
1544  float *src_ptr = src;
1545  float *dst_ptr = dst;
1546 
1547  if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
1548  return 1;
1549  }
1550 
1551  refLowData = (float)logElement.refLowData / logElement.maxValue;
1552 
1553  for (i = 0; i < logImage->width * logImage->height / 2; i++) {
1554  cb = *(src_ptr++) - 0.5f;
1555  y1 = *(src_ptr++) - refLowData;
1556  a1 = *(src_ptr++);
1557  cr = *(src_ptr++) - 0.5f;
1558  y2 = *(src_ptr++) - refLowData;
1559  a2 = *(src_ptr++);
1560 
1561  *(dst_ptr++) = clamp_float(y1 * conversionMatrix[0] + cb * conversionMatrix[1] +
1562  cr * conversionMatrix[2],
1563  0.0f,
1564  1.0f);
1565  *(dst_ptr++) = clamp_float(y1 * conversionMatrix[3] + cb * conversionMatrix[4] +
1566  cr * conversionMatrix[5],
1567  0.0f,
1568  1.0f);
1569  *(dst_ptr++) = clamp_float(y1 * conversionMatrix[6] + cb * conversionMatrix[7] +
1570  cr * conversionMatrix[8],
1571  0.0f,
1572  1.0f);
1573  *(dst_ptr++) = a1;
1574  *(dst_ptr++) = clamp_float(y2 * conversionMatrix[0] + cb * conversionMatrix[1] +
1575  cr * conversionMatrix[2],
1576  0.0f,
1577  1.0f);
1578  *(dst_ptr++) = clamp_float(y2 * conversionMatrix[3] + cb * conversionMatrix[4] +
1579  cr * conversionMatrix[5],
1580  0.0f,
1581  1.0f);
1582  *(dst_ptr++) = clamp_float(y2 * conversionMatrix[6] + cb * conversionMatrix[7] +
1583  cr * conversionMatrix[8],
1584  0.0f,
1585  1.0f);
1586  *(dst_ptr++) = a2;
1587  }
1588  return 0;
1589 }
1590 
1591 static int convertLuminance_RGBA(float *src,
1592  float *dst,
1593  LogImageFile *logImage,
1594  LogImageElement logElement)
1595 {
1596  unsigned int i;
1597  float conversionMatrix[9], value, refLowData;
1598  float *src_ptr = src;
1599  float *dst_ptr = dst;
1600 
1601  if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
1602  return 1;
1603  }
1604 
1605  refLowData = (float)logElement.refLowData / logElement.maxValue;
1606 
1607  for (i = 0; i < logImage->width * logImage->height; i++) {
1608  value = clamp_float((*(src_ptr++) - refLowData) * conversionMatrix[0], 0.0f, 1.0f);
1609  *(dst_ptr++) = value;
1610  *(dst_ptr++) = value;
1611  *(dst_ptr++) = value;
1612  *(dst_ptr++) = 1.0f;
1613  }
1614  return 0;
1615 }
1616 
1617 static int convertYA_RGBA(float *src,
1618  float *dst,
1619  LogImageFile *logImage,
1620  LogImageElement logElement)
1621 {
1622  unsigned int i;
1623  float conversionMatrix[9], value, refLowData;
1624  float *src_ptr = src;
1625  float *dst_ptr = dst;
1626 
1627  if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
1628  return 1;
1629  }
1630 
1631  refLowData = (float)logElement.refLowData / logElement.maxValue;
1632 
1633  for (i = 0; i < logImage->width * logImage->height; i++) {
1634  value = clamp_float((*(src_ptr++) - refLowData) * conversionMatrix[0], 0.0f, 1.0f);
1635  *(dst_ptr++) = value;
1636  *(dst_ptr++) = value;
1637  *(dst_ptr++) = value;
1638  *(dst_ptr++) = *(src_ptr++);
1639  }
1640  return 0;
1641 }
1642 
1644  float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int dstIsLinearRGB)
1645 {
1646  int rvalue;
1647  unsigned int i;
1648  float *src_ptr;
1649  float *dst_ptr;
1650 
1651  /* Convert data in src to linear RGBA in dst */
1652  switch (logElement.descriptor) {
1653  case descriptor_RGB:
1654  rvalue = convertRGB_RGBA(src, dst, logImage, logElement, 1);
1655  break;
1656 
1657  case descriptor_RGBA:
1658  rvalue = convertRGBA_RGBA(src, dst, logImage, logElement, 1);
1659  break;
1660 
1661  case descriptor_ABGR:
1662  rvalue = convertABGR_RGBA(src, dst, logImage, logElement, 1);
1663  break;
1664 
1665  case descriptor_Luminance:
1666  rvalue = convertLuminance_RGBA(src, dst, logImage, logElement);
1667  break;
1668 
1669  case descriptor_CbYCr:
1670  rvalue = convertCbYCr_RGBA(src, dst, logImage, logElement);
1671  break;
1672 
1673  case descriptor_CbYCrY:
1674  rvalue = convertCbYCrY_RGBA(src, dst, logImage, logElement);
1675  break;
1676 
1677  case descriptor_CbYACrYA:
1678  rvalue = convertCbYACrYA_RGBA(src, dst, logImage, logElement);
1679  break;
1680 
1681  case descriptor_CbYCrA:
1682  rvalue = convertCbYCrA_RGBA(src, dst, logImage, logElement);
1683  break;
1684 
1685  case descriptor_YA: /* this descriptor is for internal use only */
1686  rvalue = convertYA_RGBA(src, dst, logImage, logElement);
1687  break;
1688 
1689  default:
1690  return 1;
1691  }
1692 
1693  if (rvalue == 1) {
1694  return 1;
1695  }
1696  if (dstIsLinearRGB) {
1697  /* convert data from sRGB to Linear RGB via lut */
1698  float *lut = getSrgbToLinLut(logElement);
1699  src_ptr = dst; /* no error here */
1700  dst_ptr = dst;
1701  for (i = 0; i < logImage->width * logImage->height; i++) {
1702  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1703  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1704  *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1705  dst_ptr++;
1706  src_ptr++;
1707  }
1708  MEM_freeN(lut);
1709  }
1710  return 0;
1711 }
1712 
1714  float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int srcIsLinearRGB)
1715 {
1716  unsigned int i;
1717  int rvalue;
1718  float *srgbSrc;
1719  float *srgbSrc_ptr;
1720  float *src_ptr = src;
1721  float *lut;
1722 
1723  if (srcIsLinearRGB != 0) {
1724  /* we need to convert src to sRGB */
1725  srgbSrc = (float *)imb_alloc_pixels(
1726  logImage->width, logImage->height, 4, sizeof(float), __func__);
1727  if (srgbSrc == NULL) {
1728  return 1;
1729  }
1730 
1731  memcpy(srgbSrc, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
1732  srgbSrc_ptr = srgbSrc;
1733 
1734  /* convert data from Linear RGB to sRGB via lut */
1735  lut = getLinToSrgbLut(logElement);
1736  for (i = 0; i < logImage->width * logImage->height; i++) {
1737  *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1738  *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1739  *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
1740  srgbSrc_ptr++;
1741  src_ptr++;
1742  }
1743  MEM_freeN(lut);
1744  }
1745  else {
1746  srgbSrc = src;
1747  }
1748 
1749  /* Convert linear RGBA data in src to format described by logElement in dst */
1750  switch (logElement.descriptor) {
1751  case descriptor_RGB:
1752  rvalue = convertRGBA_RGB(srgbSrc, dst, logImage, logElement, 0);
1753  break;
1754 
1755  case descriptor_RGBA:
1756  rvalue = convertRGBA_RGBA(srgbSrc, dst, logImage, logElement, 0);
1757  break;
1758 
1759  /* these ones are not supported for the moment */
1760  case descriptor_ABGR:
1761  case descriptor_Luminance:
1762  case descriptor_CbYCr:
1763  case descriptor_CbYCrY:
1764  case descriptor_CbYACrYA:
1765  case descriptor_CbYCrA:
1766  case descriptor_YA: /* this descriptor is for internal use only */
1767  default:
1768  rvalue = 1;
1769  break;
1770  }
1771 
1772  if (srcIsLinearRGB != 0) {
1773  MEM_freeN(srgbSrc);
1774  }
1775 
1776  return rvalue;
1777 }
typedef float(TangentPoint)[2]
File and directory operations.
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:1003
#define ELEM(...)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble y1
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void * imb_alloc_pixels(unsigned int x, unsigned int y, unsigned int channels, size_t typesize, const char *name)
Definition: allocimbuf.c:373
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void cineonSetVerbose(int verbosity)
Definition: cineonlib.c:46
LogImageFile * cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t bufferSize)
Definition: cineonlib.c:140
LogImageFile * cineonCreate(const char *filename, int width, int height, int bitsPerSample, const char *creator)
Definition: cineonlib.c:367
#define CINEON_FILE_MAGIC
Definition: cineonlib.h:34
void dpxSetVerbose(int verbosity)
Definition: dpxlib.c:46
LogImageFile * dpxCreate(const char *filename, int width, int height, int bitsPerSample, int hasAlpha, int isLogarithmic, int referenceWhite, int referenceBlack, float gamma, const char *creator)
Definition: dpxlib.c:424
LogImageFile * dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t bufferSize)
Definition: dpxlib.c:138
#define DPX_FILE_MAGIC
Definition: dpxlib.h:35
uint col
#define powf(x, y)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
static int logImageElementGetData10Packed(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:842
static int convertRGBA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int elementIsSource)
static float * getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
static int logImageElementGetData10(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:770
static int verbose
Definition: logImageCore.c:86
static int convertABGR_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int elementIsSource)
LogImageFile * logImageCreate(const char *filename, int cineon, int width, int height, int bitsPerSample, int isLogarithmic, int hasAlpha, int referenceWhite, int referenceBlack, float gamma, const char *creator)
Definition: logImageCore.c:159
static int logImageElementGetData12Packed(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:936
static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:368
static int convertRGBAToLogElement(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int srcIsLinearRGB)
static float * getLinToSrgbLut(LogImageElement logElement)
static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:400
void logImageSetVerbose(int verbosity)
Definition: logImageCore.c:88
static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:711
int logImageIsCineon(const void *buffer, const unsigned int size)
Definition: logImageCore.c:109
static float * getSrgbToLinLut(LogImageElement logElement)
static int convertLogElementToRGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int dstIsLinearRGB)
static int convertCbYCrA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
static int convertRGB_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int elementIsSource)
static int convertRGBA_RGB(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int elementIsSource)
LogImageFile * logImageOpenFromMemory(const unsigned char *buffer, unsigned int size)
Definition: logImageCore.c:147
static int logImageElementGetData(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:677
static int convertCbYACrYA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
static int convertLuminance_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
LogImageFile * logImageOpenFromFile(const char *filename, int cineon)
Definition: logImageCore.c:119
static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:322
static float * getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
void logImageClose(LogImageFile *logImage)
Definition: logImageCore.c:190
static int convertCbYCrY_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
static int logImageElementGetData16(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:992
int logImageIsDpx(const void *buffer, const unsigned int size)
Definition: logImageCore.c:99
static int logImageElementGetData12(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:898
size_t getRowLength(size_t width, LogImageElement logElement)
Definition: logImageCore.c:212
static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:291
void logImageGetSize(LogImageFile *logImage, int *width, int *height, int *depth)
Definition: logImageCore.c:201
int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
Definition: logImageCore.c:248
int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
Definition: logImageCore.c:436
static int convertYA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
static int convertCbYCr_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
static int logImageElementGetData8(LogImageFile *logImage, LogImageElement logElement, float *data)
Definition: logImageCore.c:742
static int getYUVtoRGBMatrix(float *matrix, LogImageElement logElement)
BLI_INLINE float clamp_float(float x, float low, float high)
Definition: logImageCore.h:268
@ format_DPX
Definition: logImageCore.h:48
@ descriptor_Chrominance
Definition: logImageCore.h:160
@ descriptor_CbYCr
Definition: logImageCore.h:168
@ descriptor_Red
Definition: logImageCore.h:155
@ descriptor_YA
Definition: logImageCore.h:178
@ descriptor_Composite
Definition: logImageCore.h:162
@ descriptor_Depth
Definition: logImageCore.h:161
@ descriptor_CbYCrA
Definition: logImageCore.h:169
@ descriptor_Luminance
Definition: logImageCore.h:159
@ descriptor_Green
Definition: logImageCore.h:156
@ descriptor_ABGR
Definition: logImageCore.h:165
@ descriptor_CbYCrY
Definition: logImageCore.h:166
@ descriptor_Blue
Definition: logImageCore.h:157
@ descriptor_RGB
Definition: logImageCore.h:163
@ descriptor_CbYACrYA
Definition: logImageCore.h:167
@ descriptor_Alpha
Definition: logImageCore.h:158
@ descriptor_RGBA
Definition: logImageCore.h:164
@ transfer_PrintingDensity
Definition: logImageCore.h:113
@ transfer_UserDefined
Definition: logImageCore.h:112
@ transfer_Linear
Definition: logImageCore.h:114
@ transfer_Logarithmic
Definition: logImageCore.h:115
@ transfer_Unspecified
Definition: logImageCore.h:116
BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
Definition: logImageCore.h:213
BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
Definition: logImageCore.h:223
BLI_INLINE unsigned int float_uint(float value, unsigned int max)
Definition: logImageCore.h:281
int logimage_read_ushort(unsigned short *x, LogImageFile *logFile)
Definition: logmemfile.c:107
int logimage_read_uchar(unsigned char *x, LogImageFile *logFile)
Definition: logmemfile.c:95
int logimage_fseek(LogImageFile *logFile, intptr_t offset, int origin)
Definition: logmemfile.c:32
int logimage_read_uint(unsigned int *x, LogImageFile *logFile)
Definition: logmemfile.c:119
int logimage_fwrite(void *buffer, size_t size, unsigned int count, LogImageFile *logFile)
Definition: logmemfile.c:62
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static unsigned a[3]
Definition: RandGen.cpp:92
unsigned int refLowData
Definition: logImageCore.h:59
float refHighQuantity
Definition: logImageCore.h:62
unsigned int refHighData
Definition: logImageCore.h:60
float referenceWhite
Definition: logImageCore.h:76
LogImageElement element[8]
Definition: logImageCore.h:72
float referenceBlack
Definition: logImageCore.h:75