Blender  V3.3
image_format.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <cstring>
9 
10 #include "DNA_defaults.h"
11 #include "DNA_scene_types.h"
12 
13 #include "BLI_path_util.h"
14 #include "BLI_string.h"
15 #include "BLI_utildefines.h"
16 
17 #include "IMB_colormanagement.h"
18 #include "IMB_imbuf.h"
19 #include "IMB_imbuf_types.h"
20 
21 #include "BKE_colortools.h"
22 #include "BKE_image_format.h"
23 
24 /* Init/Copy/Free */
25 
26 void BKE_image_format_init(ImageFormatData *imf, const bool render)
27 {
29 
31 
32  if (render) {
34  &imf->view_settings, &imf->display_settings, "Filmic");
35  }
36  else {
38  }
39 
41 }
42 
44 {
45  memcpy(imf_dst, imf_src, sizeof(*imf_dst));
49  &imf_src->linear_colorspace_settings);
50 }
51 
53 {
55 }
56 
58 {
60 }
61 
63 {
65 }
66 
67 /* File Types */
68 
69 int BKE_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options)
70 {
71  memset(r_options, 0, sizeof(*r_options));
72 
73  if (imtype == R_IMF_IMTYPE_TARGA) {
74  return IMB_FTYPE_TGA;
75  }
76  if (imtype == R_IMF_IMTYPE_RAWTGA) {
77  r_options->flag = RAWTGA;
78  return IMB_FTYPE_TGA;
79  }
80  if (imtype == R_IMF_IMTYPE_IRIS) {
81  return IMB_FTYPE_IMAGIC;
82  }
83 #ifdef WITH_HDR
84  if (imtype == R_IMF_IMTYPE_RADHDR) {
85  return IMB_FTYPE_RADHDR;
86  }
87 #endif
88  if (imtype == R_IMF_IMTYPE_PNG) {
89  r_options->quality = 15;
90  return IMB_FTYPE_PNG;
91  }
92 #ifdef WITH_DDS
93  if (imtype == R_IMF_IMTYPE_DDS) {
94  return IMB_FTYPE_DDS;
95  }
96 #endif
97  if (imtype == R_IMF_IMTYPE_BMP) {
98  return IMB_FTYPE_BMP;
99  }
100 #ifdef WITH_TIFF
101  if (imtype == R_IMF_IMTYPE_TIFF) {
102  return IMB_FTYPE_TIF;
103  }
104 #endif
106  return IMB_FTYPE_OPENEXR;
107  }
108 #ifdef WITH_CINEON
109  if (imtype == R_IMF_IMTYPE_CINEON) {
110  return IMB_FTYPE_CINEON;
111  }
112  if (imtype == R_IMF_IMTYPE_DPX) {
113  return IMB_FTYPE_DPX;
114  }
115 #endif
116 #ifdef WITH_OPENJPEG
117  if (imtype == R_IMF_IMTYPE_JP2) {
118  r_options->flag |= JP2_JP2;
119  r_options->quality = 90;
120  return IMB_FTYPE_JP2;
121  }
122 #endif
123 #ifdef WITH_WEBP
124  if (imtype == R_IMF_IMTYPE_WEBP) {
125  r_options->quality = 90;
126  return IMB_FTYPE_WEBP;
127  }
128 #endif
129 
130  r_options->quality = 90;
131  return IMB_FTYPE_JPG;
132 }
133 
134 char BKE_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
135 {
136  if (ftype == IMB_FTYPE_NONE) {
137  return R_IMF_IMTYPE_TARGA;
138  }
139  if (ftype == IMB_FTYPE_IMAGIC) {
140  return R_IMF_IMTYPE_IRIS;
141  }
142 #ifdef WITH_HDR
143  if (ftype == IMB_FTYPE_RADHDR) {
144  return R_IMF_IMTYPE_RADHDR;
145  }
146 #endif
147  if (ftype == IMB_FTYPE_PNG) {
148  return R_IMF_IMTYPE_PNG;
149  }
150 #ifdef WITH_DDS
151  if (ftype == IMB_FTYPE_DDS) {
152  return R_IMF_IMTYPE_DDS;
153  }
154 #endif
155  if (ftype == IMB_FTYPE_BMP) {
156  return R_IMF_IMTYPE_BMP;
157  }
158 #ifdef WITH_TIFF
159  if (ftype == IMB_FTYPE_TIF) {
160  return R_IMF_IMTYPE_TIFF;
161  }
162 #endif
163  if (ftype == IMB_FTYPE_OPENEXR) {
164  return R_IMF_IMTYPE_OPENEXR;
165  }
166 #ifdef WITH_CINEON
167  if (ftype == IMB_FTYPE_CINEON) {
168  return R_IMF_IMTYPE_CINEON;
169  }
170  if (ftype == IMB_FTYPE_DPX) {
171  return R_IMF_IMTYPE_DPX;
172  }
173 #endif
174  if (ftype == IMB_FTYPE_TGA) {
175  if (options && (options->flag & RAWTGA)) {
176  return R_IMF_IMTYPE_RAWTGA;
177  }
178 
179  return R_IMF_IMTYPE_TARGA;
180  }
181 #ifdef WITH_OPENJPEG
182  if (ftype == IMB_FTYPE_JP2) {
183  return R_IMF_IMTYPE_JP2;
184  }
185 #endif
186 #ifdef WITH_WEBP
187  if (ftype == IMB_FTYPE_WEBP) {
188  return R_IMF_IMTYPE_WEBP;
189  }
190 #endif
191 
192  return R_IMF_IMTYPE_JPEG90;
193 }
194 
195 bool BKE_imtype_is_movie(const char imtype)
196 {
197  switch (imtype) {
198  case R_IMF_IMTYPE_AVIRAW:
200  case R_IMF_IMTYPE_FFMPEG:
201  case R_IMF_IMTYPE_H264:
202  case R_IMF_IMTYPE_THEORA:
203  case R_IMF_IMTYPE_XVID:
204  return true;
205  }
206  return false;
207 }
208 
209 bool BKE_imtype_supports_zbuf(const char imtype)
210 {
211  switch (imtype) {
212  case R_IMF_IMTYPE_IRIZ:
213  case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */
214  return true;
215  }
216  return false;
217 }
218 
219 bool BKE_imtype_supports_compress(const char imtype)
220 {
221  switch (imtype) {
222  case R_IMF_IMTYPE_PNG:
223  return true;
224  }
225  return false;
226 }
227 
228 bool BKE_imtype_supports_quality(const char imtype)
229 {
230  switch (imtype) {
231  case R_IMF_IMTYPE_JPEG90:
232  case R_IMF_IMTYPE_JP2:
234  case R_IMF_IMTYPE_WEBP:
235  return true;
236  }
237  return false;
238 }
239 
240 bool BKE_imtype_requires_linear_float(const char imtype)
241 {
242  switch (imtype) {
243  case R_IMF_IMTYPE_CINEON:
244  case R_IMF_IMTYPE_DPX:
245  case R_IMF_IMTYPE_RADHDR:
248  return true;
249  }
250  return false;
251 }
252 
253 char BKE_imtype_valid_channels(const char imtype, bool write_file)
254 {
255  char chan_flag = IMA_CHAN_FLAG_RGB; /* Assume all support RGB. */
256 
257  /* Alpha. */
258  switch (imtype) {
259  case R_IMF_IMTYPE_BMP:
260  if (write_file) {
261  break;
262  }
264  case R_IMF_IMTYPE_TARGA:
265  case R_IMF_IMTYPE_RAWTGA:
266  case R_IMF_IMTYPE_IRIS:
267  case R_IMF_IMTYPE_PNG:
268  case R_IMF_IMTYPE_TIFF:
271  case R_IMF_IMTYPE_DDS:
272  case R_IMF_IMTYPE_JP2:
273  case R_IMF_IMTYPE_DPX:
274  case R_IMF_IMTYPE_WEBP:
275  chan_flag |= IMA_CHAN_FLAG_ALPHA;
276  break;
277  }
278 
279  /* BW. */
280  switch (imtype) {
281  case R_IMF_IMTYPE_BMP:
282  case R_IMF_IMTYPE_PNG:
283  case R_IMF_IMTYPE_JPEG90:
284  case R_IMF_IMTYPE_TARGA:
285  case R_IMF_IMTYPE_RAWTGA:
286  case R_IMF_IMTYPE_TIFF:
287  case R_IMF_IMTYPE_IRIS:
288  chan_flag |= IMA_CHAN_FLAG_BW;
289  break;
290  }
291 
292  return chan_flag;
293 }
294 
295 char BKE_imtype_valid_depths(const char imtype)
296 {
297  switch (imtype) {
298  case R_IMF_IMTYPE_RADHDR:
299  return R_IMF_CHAN_DEPTH_32;
300  case R_IMF_IMTYPE_TIFF:
306  /* NOTE: CINEON uses an unusual 10bits-LOG per channel. */
307  case R_IMF_IMTYPE_DPX:
309  case R_IMF_IMTYPE_CINEON:
310  return R_IMF_CHAN_DEPTH_10;
311  case R_IMF_IMTYPE_JP2:
313  case R_IMF_IMTYPE_PNG:
315  /* Most formats are 8bit only. */
316  default:
317  return R_IMF_CHAN_DEPTH_8;
318  }
319 }
320 
321 char BKE_imtype_from_arg(const char *imtype_arg)
322 {
323  if (STREQ(imtype_arg, "TGA")) {
324  return R_IMF_IMTYPE_TARGA;
325  }
326  if (STREQ(imtype_arg, "IRIS")) {
327  return R_IMF_IMTYPE_IRIS;
328  }
329 #ifdef WITH_DDS
330  if (STREQ(imtype_arg, "DDS")) {
331  return R_IMF_IMTYPE_DDS;
332  }
333 #endif
334  if (STREQ(imtype_arg, "JPEG")) {
335  return R_IMF_IMTYPE_JPEG90;
336  }
337  if (STREQ(imtype_arg, "IRIZ")) {
338  return R_IMF_IMTYPE_IRIZ;
339  }
340  if (STREQ(imtype_arg, "RAWTGA")) {
341  return R_IMF_IMTYPE_RAWTGA;
342  }
343  if (STREQ(imtype_arg, "AVIRAW")) {
344  return R_IMF_IMTYPE_AVIRAW;
345  }
346  if (STREQ(imtype_arg, "AVIJPEG")) {
347  return R_IMF_IMTYPE_AVIJPEG;
348  }
349  if (STREQ(imtype_arg, "PNG")) {
350  return R_IMF_IMTYPE_PNG;
351  }
352  if (STREQ(imtype_arg, "BMP")) {
353  return R_IMF_IMTYPE_BMP;
354  }
355 #ifdef WITH_HDR
356  if (STREQ(imtype_arg, "HDR")) {
357  return R_IMF_IMTYPE_RADHDR;
358  }
359 #endif
360 #ifdef WITH_TIFF
361  if (STREQ(imtype_arg, "TIFF")) {
362  return R_IMF_IMTYPE_TIFF;
363  }
364 #endif
365 #ifdef WITH_OPENEXR
366  if (STREQ(imtype_arg, "OPEN_EXR")) {
367  return R_IMF_IMTYPE_OPENEXR;
368  }
369  if (STREQ(imtype_arg, "OPEN_EXR_MULTILAYER")) {
371  }
372  if (STREQ(imtype_arg, "EXR")) {
373  return R_IMF_IMTYPE_OPENEXR;
374  }
375  if (STREQ(imtype_arg, "MULTILAYER")) {
377  }
378 #endif
379  if (STREQ(imtype_arg, "FFMPEG")) {
380  return R_IMF_IMTYPE_FFMPEG;
381  }
382 #ifdef WITH_CINEON
383  if (STREQ(imtype_arg, "CINEON")) {
384  return R_IMF_IMTYPE_CINEON;
385  }
386  if (STREQ(imtype_arg, "DPX")) {
387  return R_IMF_IMTYPE_DPX;
388  }
389 #endif
390 #ifdef WITH_OPENJPEG
391  if (STREQ(imtype_arg, "JP2")) {
392  return R_IMF_IMTYPE_JP2;
393  }
394 #endif
395 #ifdef WITH_WEBP
396  if (STREQ(imtype_arg, "WEBP")) {
397  return R_IMF_IMTYPE_WEBP;
398  }
399 #endif
400 
401  return R_IMF_IMTYPE_INVALID;
402 }
403 
404 /* File Paths */
405 
406 static bool do_add_image_extension(char *string,
407  const char imtype,
408  const ImageFormatData *im_format)
409 {
410  const char *extension = nullptr;
411  const char *extension_test;
412  (void)im_format; /* may be unused, depends on build options */
413 
414  if (imtype == R_IMF_IMTYPE_IRIS) {
415  if (!BLI_path_extension_check(string, extension_test = ".rgb")) {
416  extension = extension_test;
417  }
418  }
419  else if (imtype == R_IMF_IMTYPE_IRIZ) {
420  if (!BLI_path_extension_check(string, extension_test = ".rgb")) {
421  extension = extension_test;
422  }
423  }
424 #ifdef WITH_HDR
425  else if (imtype == R_IMF_IMTYPE_RADHDR) {
426  if (!BLI_path_extension_check(string, extension_test = ".hdr")) {
427  extension = extension_test;
428  }
429  }
430 #endif
431  else if (ELEM(imtype,
437  if (!BLI_path_extension_check(string, extension_test = ".png")) {
438  extension = extension_test;
439  }
440  }
441 #ifdef WITH_DDS
442  else if (imtype == R_IMF_IMTYPE_DDS) {
443  if (!BLI_path_extension_check(string, extension_test = ".dds")) {
444  extension = extension_test;
445  }
446  }
447 #endif
448  else if (ELEM(imtype, R_IMF_IMTYPE_TARGA, R_IMF_IMTYPE_RAWTGA)) {
449  if (!BLI_path_extension_check(string, extension_test = ".tga")) {
450  extension = extension_test;
451  }
452  }
453  else if (imtype == R_IMF_IMTYPE_BMP) {
454  if (!BLI_path_extension_check(string, extension_test = ".bmp")) {
455  extension = extension_test;
456  }
457  }
458 #ifdef WITH_TIFF
459  else if (imtype == R_IMF_IMTYPE_TIFF) {
460  if (!BLI_path_extension_check_n(string, extension_test = ".tif", ".tiff", nullptr)) {
461  extension = extension_test;
462  }
463  }
464 #endif
465 #ifdef WITH_OPENIMAGEIO
466  else if (imtype == R_IMF_IMTYPE_PSD) {
467  if (!BLI_path_extension_check(string, extension_test = ".psd")) {
468  extension = extension_test;
469  }
470  }
471 #endif
472 #ifdef WITH_OPENEXR
474  if (!BLI_path_extension_check(string, extension_test = ".exr")) {
475  extension = extension_test;
476  }
477  }
478 #endif
479 #ifdef WITH_CINEON
480  else if (imtype == R_IMF_IMTYPE_CINEON) {
481  if (!BLI_path_extension_check(string, extension_test = ".cin")) {
482  extension = extension_test;
483  }
484  }
485  else if (imtype == R_IMF_IMTYPE_DPX) {
486  if (!BLI_path_extension_check(string, extension_test = ".dpx")) {
487  extension = extension_test;
488  }
489  }
490 #endif
491 #ifdef WITH_OPENJPEG
492  else if (imtype == R_IMF_IMTYPE_JP2) {
493  if (im_format) {
494  if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) {
495  if (!BLI_path_extension_check(string, extension_test = ".jp2")) {
496  extension = extension_test;
497  }
498  }
499  else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) {
500  if (!BLI_path_extension_check(string, extension_test = ".j2c")) {
501  extension = extension_test;
502  }
503  }
504  else {
505  BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec");
506  }
507  }
508  else {
509  if (!BLI_path_extension_check(string, extension_test = ".jp2")) {
510  extension = extension_test;
511  }
512  }
513  }
514 #endif
515 #ifdef WITH_WEBP
516  else if (imtype == R_IMF_IMTYPE_WEBP) {
517  if (!BLI_path_extension_check(string, extension_test = ".webp")) {
518  extension = extension_test;
519  }
520  }
521 #endif
522  else { // R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90 etc
523  if (!(BLI_path_extension_check_n(string, extension_test = ".jpg", ".jpeg", nullptr))) {
524  extension = extension_test;
525  }
526  }
527 
528  if (extension) {
529  /* prefer this in many cases to avoid .png.tga, but in certain cases it breaks */
530  /* remove any other known image extension */
532  return BLI_path_extension_replace(string, FILE_MAX, extension);
533  }
534 
535  return BLI_path_extension_ensure(string, FILE_MAX, extension);
536  }
537 
538  return false;
539 }
540 
541 int BKE_image_path_ensure_ext_from_imformat(char *string, const ImageFormatData *im_format)
542 {
543  return do_add_image_extension(string, im_format->imtype, im_format);
544 }
545 
546 int BKE_image_path_ensure_ext_from_imtype(char *string, const char imtype)
547 {
548  return do_add_image_extension(string, imtype, nullptr);
549 }
550 
551 static void do_makepicstring(char *string,
552  const char *base,
553  const char *relbase,
554  int frame,
555  const char imtype,
556  const ImageFormatData *im_format,
557  const bool use_ext,
558  const bool use_frames,
559  const char *suffix)
560 {
561  if (string == nullptr) {
562  return;
563  }
564  BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */
565  BLI_path_abs(string, relbase);
566 
567  if (use_frames) {
568  BLI_path_frame(string, frame, 4);
569  }
570 
571  if (suffix) {
572  BLI_path_suffix(string, FILE_MAX, suffix, "");
573  }
574 
575  if (use_ext) {
576  do_add_image_extension(string, imtype, im_format);
577  }
578 }
579 
581  const char *base,
582  const char *relbase,
583  int frame,
584  const ImageFormatData *im_format,
585  const bool use_ext,
586  const bool use_frames,
587  const char *suffix)
588 {
590  string, base, relbase, frame, im_format->imtype, im_format, use_ext, use_frames, suffix);
591 }
592 
593 void BKE_image_path_from_imtype(char *string,
594  const char *base,
595  const char *relbase,
596  int frame,
597  const char imtype,
598  const bool use_ext,
599  const bool use_frames,
600  const char *suffix)
601 {
602  do_makepicstring(string, base, relbase, frame, imtype, nullptr, use_ext, use_frames, suffix);
603 }
604 
605 /* ImBuf Conversion */
606 
608 {
609  /* Write to ImBuf in preparation for file writing. */
610  char imtype = imf->imtype;
611  char compress = imf->compress;
612  char quality = imf->quality;
613 
614  /* initialize all from image format */
615  ibuf->foptions.flag = 0;
616 
617  if (imtype == R_IMF_IMTYPE_IRIS) {
618  ibuf->ftype = IMB_FTYPE_IMAGIC;
619  }
620 #ifdef WITH_HDR
621  else if (imtype == R_IMF_IMTYPE_RADHDR) {
622  ibuf->ftype = IMB_FTYPE_RADHDR;
623  }
624 #endif
625  else if (ELEM(imtype,
631  ibuf->ftype = IMB_FTYPE_PNG;
632 
633  if (imtype == R_IMF_IMTYPE_PNG) {
634  if (imf->depth == R_IMF_CHAN_DEPTH_16) {
635  ibuf->foptions.flag |= PNG_16BIT;
636  }
637 
638  ibuf->foptions.quality = compress;
639  }
640  }
641 #ifdef WITH_DDS
642  else if (imtype == R_IMF_IMTYPE_DDS) {
643  ibuf->ftype = IMB_FTYPE_DDS;
644  }
645 #endif
646  else if (imtype == R_IMF_IMTYPE_BMP) {
647  ibuf->ftype = IMB_FTYPE_BMP;
648  }
649 #ifdef WITH_TIFF
650  else if (imtype == R_IMF_IMTYPE_TIFF) {
651  ibuf->ftype = IMB_FTYPE_TIF;
652 
653  if (imf->depth == R_IMF_CHAN_DEPTH_16) {
654  ibuf->foptions.flag |= TIF_16BIT;
655  }
656  if (imf->tiff_codec == R_IMF_TIFF_CODEC_NONE) {
657  ibuf->foptions.flag |= TIF_COMPRESS_NONE;
658  }
659  else if (imf->tiff_codec == R_IMF_TIFF_CODEC_DEFLATE) {
660  ibuf->foptions.flag |= TIF_COMPRESS_DEFLATE;
661  }
662  else if (imf->tiff_codec == R_IMF_TIFF_CODEC_LZW) {
663  ibuf->foptions.flag |= TIF_COMPRESS_LZW;
664  }
665  else if (imf->tiff_codec == R_IMF_TIFF_CODEC_PACKBITS) {
666  ibuf->foptions.flag |= TIF_COMPRESS_PACKBITS;
667  }
668  }
669 #endif
670 #ifdef WITH_OPENEXR
672  ibuf->ftype = IMB_FTYPE_OPENEXR;
673  if (imf->depth == R_IMF_CHAN_DEPTH_16) {
674  ibuf->foptions.flag |= OPENEXR_HALF;
675  }
676  ibuf->foptions.flag |= (imf->exr_codec & OPENEXR_COMPRESS);
677 
678  if (!(imf->flag & R_IMF_FLAG_ZBUF)) {
679  /* Signal for exr saving. */
681  }
682  }
683 #endif
684 #ifdef WITH_CINEON
685  else if (imtype == R_IMF_IMTYPE_CINEON) {
686  ibuf->ftype = IMB_FTYPE_CINEON;
687  if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) {
688  ibuf->foptions.flag |= CINEON_LOG;
689  }
690  if (imf->depth == R_IMF_CHAN_DEPTH_16) {
691  ibuf->foptions.flag |= CINEON_16BIT;
692  }
693  else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
694  ibuf->foptions.flag |= CINEON_12BIT;
695  }
696  else if (imf->depth == R_IMF_CHAN_DEPTH_10) {
697  ibuf->foptions.flag |= CINEON_10BIT;
698  }
699  }
700  else if (imtype == R_IMF_IMTYPE_DPX) {
701  ibuf->ftype = IMB_FTYPE_DPX;
702  if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) {
703  ibuf->foptions.flag |= CINEON_LOG;
704  }
705  if (imf->depth == R_IMF_CHAN_DEPTH_16) {
706  ibuf->foptions.flag |= CINEON_16BIT;
707  }
708  else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
709  ibuf->foptions.flag |= CINEON_12BIT;
710  }
711  else if (imf->depth == R_IMF_CHAN_DEPTH_10) {
712  ibuf->foptions.flag |= CINEON_10BIT;
713  }
714  }
715 #endif
716  else if (imtype == R_IMF_IMTYPE_TARGA) {
717  ibuf->ftype = IMB_FTYPE_TGA;
718  }
719  else if (imtype == R_IMF_IMTYPE_RAWTGA) {
720  ibuf->ftype = IMB_FTYPE_TGA;
721  ibuf->foptions.flag = RAWTGA;
722  }
723 #ifdef WITH_OPENJPEG
724  else if (imtype == R_IMF_IMTYPE_JP2) {
725  if (quality < 10) {
726  quality = 90;
727  }
728  ibuf->ftype = IMB_FTYPE_JP2;
729  ibuf->foptions.quality = quality;
730 
731  if (imf->depth == R_IMF_CHAN_DEPTH_16) {
732  ibuf->foptions.flag |= JP2_16BIT;
733  }
734  else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
735  ibuf->foptions.flag |= JP2_12BIT;
736  }
737 
738  if (imf->jp2_flag & R_IMF_JP2_FLAG_YCC) {
739  ibuf->foptions.flag |= JP2_YCC;
740  }
741 
743  ibuf->foptions.flag |= JP2_CINE;
744  if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_48) {
745  ibuf->foptions.flag |= JP2_CINE_48FPS;
746  }
747  }
748 
749  if (imf->jp2_codec == R_IMF_JP2_CODEC_JP2) {
750  ibuf->foptions.flag |= JP2_JP2;
751  }
752  else if (imf->jp2_codec == R_IMF_JP2_CODEC_J2K) {
753  ibuf->foptions.flag |= JP2_J2K;
754  }
755  else {
756  BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec");
757  }
758  }
759 #endif
760 #ifdef WITH_WEBP
761  else if (imtype == R_IMF_IMTYPE_WEBP) {
762  ibuf->ftype = IMB_FTYPE_WEBP;
763  ibuf->foptions.quality = quality;
764  }
765 #endif
766  else {
767  /* #R_IMF_IMTYPE_JPEG90, etc. default to JPEG. */
768  if (quality < 10) {
769  quality = 90;
770  }
771  ibuf->ftype = IMB_FTYPE_JPG;
772  ibuf->foptions.quality = quality;
773  }
774 }
775 
776 void BKE_image_format_from_imbuf(ImageFormatData *im_format, const ImBuf *imbuf)
777 {
778  /* Read from ImBuf after file read. */
779  int ftype = imbuf->ftype;
780  int custom_flags = imbuf->foptions.flag;
781  char quality = imbuf->foptions.quality;
782 
783  BKE_image_format_init(im_format, false);
784 
785  /* file type */
786  if (ftype == IMB_FTYPE_IMAGIC) {
787  im_format->imtype = R_IMF_IMTYPE_IRIS;
788  }
789 #ifdef WITH_HDR
790  else if (ftype == IMB_FTYPE_RADHDR) {
791  im_format->imtype = R_IMF_IMTYPE_RADHDR;
792  }
793 #endif
794  else if (ftype == IMB_FTYPE_PNG) {
795  im_format->imtype = R_IMF_IMTYPE_PNG;
796 
797  if (custom_flags & PNG_16BIT) {
798  im_format->depth = R_IMF_CHAN_DEPTH_16;
799  }
800 
801  im_format->compress = quality;
802  }
803 
804 #ifdef WITH_DDS
805  else if (ftype == IMB_FTYPE_DDS) {
806  im_format->imtype = R_IMF_IMTYPE_DDS;
807  }
808 #endif
809  else if (ftype == IMB_FTYPE_BMP) {
810  im_format->imtype = R_IMF_IMTYPE_BMP;
811  }
812 #ifdef WITH_TIFF
813  else if (ftype == IMB_FTYPE_TIF) {
814  im_format->imtype = R_IMF_IMTYPE_TIFF;
815  if (custom_flags & TIF_16BIT) {
816  im_format->depth = R_IMF_CHAN_DEPTH_16;
817  }
818  if (custom_flags & TIF_COMPRESS_NONE) {
819  im_format->tiff_codec = R_IMF_TIFF_CODEC_NONE;
820  }
821  if (custom_flags & TIF_COMPRESS_DEFLATE) {
823  }
824  if (custom_flags & TIF_COMPRESS_LZW) {
825  im_format->tiff_codec = R_IMF_TIFF_CODEC_LZW;
826  }
827  if (custom_flags & TIF_COMPRESS_PACKBITS) {
829  }
830  }
831 #endif
832 
833 #ifdef WITH_OPENEXR
834  else if (ftype == IMB_FTYPE_OPENEXR) {
835  im_format->imtype = R_IMF_IMTYPE_OPENEXR;
836  if (custom_flags & OPENEXR_HALF) {
837  im_format->depth = R_IMF_CHAN_DEPTH_16;
838  }
839  if (custom_flags & OPENEXR_COMPRESS) {
840  im_format->exr_codec = R_IMF_EXR_CODEC_ZIP; /* Can't determine compression */
841  }
842  if (imbuf->zbuf_float) {
843  im_format->flag |= R_IMF_FLAG_ZBUF;
844  }
845  }
846 #endif
847 
848 #ifdef WITH_CINEON
849  else if (ftype == IMB_FTYPE_CINEON) {
850  im_format->imtype = R_IMF_IMTYPE_CINEON;
851  }
852  else if (ftype == IMB_FTYPE_DPX) {
853  im_format->imtype = R_IMF_IMTYPE_DPX;
854  }
855 #endif
856  else if (ftype == IMB_FTYPE_TGA) {
857  if (custom_flags & RAWTGA) {
858  im_format->imtype = R_IMF_IMTYPE_RAWTGA;
859  }
860  else {
861  im_format->imtype = R_IMF_IMTYPE_TARGA;
862  }
863  }
864 #ifdef WITH_OPENJPEG
865  else if (ftype == IMB_FTYPE_JP2) {
866  im_format->imtype = R_IMF_IMTYPE_JP2;
867  im_format->quality = quality;
868 
869  if (custom_flags & JP2_16BIT) {
870  im_format->depth = R_IMF_CHAN_DEPTH_16;
871  }
872  else if (custom_flags & JP2_12BIT) {
873  im_format->depth = R_IMF_CHAN_DEPTH_12;
874  }
875 
876  if (custom_flags & JP2_YCC) {
877  im_format->jp2_flag |= R_IMF_JP2_FLAG_YCC;
878  }
879 
880  if (custom_flags & JP2_CINE) {
881  im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_PRESET;
882  if (custom_flags & JP2_CINE_48FPS) {
883  im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_48;
884  }
885  }
886 
887  if (custom_flags & JP2_JP2) {
888  im_format->jp2_codec = R_IMF_JP2_CODEC_JP2;
889  }
890  else if (custom_flags & JP2_J2K) {
891  im_format->jp2_codec = R_IMF_JP2_CODEC_J2K;
892  }
893  else {
894  BLI_assert_msg(0, "Unsupported jp2 codec was specified in file type");
895  }
896  }
897 #endif
898 #ifdef WITH_WEBP
899  else if (ftype == IMB_FTYPE_WEBP) {
900  im_format->imtype = R_IMF_IMTYPE_WEBP;
901  im_format->quality = quality;
902  }
903 #endif
904 
905  else {
906  im_format->imtype = R_IMF_IMTYPE_JPEG90;
907  im_format->quality = quality;
908  }
909 
910  /* planes */
911  im_format->planes = imbuf->planes;
912 }
913 
915 {
916  return (imf->depth == R_IMF_CHAN_DEPTH_8) && (BKE_imtype_valid_depths(imf->imtype) & imf->depth);
917 }
918 
919 /* Color Management */
920 
922 {
924 
928  &imf_src->linear_colorspace_settings);
929 }
930 
932 {
934 
939 }
940 
941 /* Output */
942 
944  const Scene *scene_src,
945  const ImageFormatData *imf_src)
946 {
947  *imf = (imf_src) ? *imf_src : scene_src->r.im_format;
948 
949  if (imf_src && imf_src->color_management == R_IMF_COLOR_MANAGEMENT_OVERRIDE) {
950  /* Use settings specific to one node, image save operation, etc. */
954  &imf_src->linear_colorspace_settings);
955  }
957  /* Use scene settings specific to render output. */
959  &scene_src->r.im_format.display_settings);
961  &scene_src->r.im_format.view_settings);
964  }
965  else {
966  /* Use general scene settings also used for display. */
971  }
972 }
void BKE_color_managed_display_settings_copy(struct ColorManagedDisplaySettings *new_settings, const struct ColorManagedDisplaySettings *settings)
void BKE_color_managed_view_settings_init_default(struct ColorManagedViewSettings *settings, const struct ColorManagedDisplaySettings *display_settings)
Definition: colortools.c:1829
void BKE_color_managed_colorspace_settings_copy(struct ColorManagedColorspaceSettings *colorspace_settings, const struct ColorManagedColorspaceSettings *settings)
void BKE_color_managed_colorspace_settings_init(struct ColorManagedColorspaceSettings *colorspace_settings)
Definition: colortools.c:1882
void BKE_color_managed_view_settings_blend_read_data(struct BlendDataReader *reader, struct ColorManagedViewSettings *settings)
Definition: colortools.c:1872
void BKE_color_managed_view_settings_free(struct ColorManagedViewSettings *settings)
Definition: colortools.c:1856
void BKE_color_managed_view_settings_blend_write(struct BlendWriter *writer, struct ColorManagedViewSettings *settings)
Definition: colortools.c:1864
void BKE_color_managed_view_settings_copy(struct ColorManagedViewSettings *new_settings, const struct ColorManagedViewSettings *settings)
void BKE_color_managed_view_settings_init_render(struct ColorManagedViewSettings *settings, const struct ColorManagedDisplaySettings *display_settings, const char *view_transform)
void BKE_color_managed_display_settings_init(struct ColorManagedDisplaySettings *settings)
Definition: colortools.c:1789
#define IMA_CHAN_FLAG_RGB
#define IMA_CHAN_FLAG_ALPHA
#define IMA_CHAN_FLAG_BW
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
#define ATTR_FALLTHROUGH
bool BLI_path_extension_check_array(const char *str, const char **ext_array) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1326
bool BLI_path_frame(char *path, int frame, int digits) ATTR_NONNULL()
Definition: path_util.c:709
#define FILE_MAX
bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
Definition: path_util.c:1420
bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
Definition: path_util.c:1393
bool BLI_path_extension_check(const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1299
bool BLI_path_extension_check_n(const char *str,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
Definition: path_util.c:1304
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
Definition: path_util.c:897
bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep) ATTR_NONNULL()
Definition: path_util.c:588
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
#define ELEM(...)
#define STREQ(a, b)
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:29
#define R_IMF_IMTYPE_TARGA
#define R_IMF_IMTYPE_FFMPEG
#define R_IMF_IMTYPE_H264
@ R_IMF_TIFF_CODEC_PACKBITS
@ R_IMF_TIFF_CODEC_DEFLATE
@ R_IMF_TIFF_CODEC_NONE
@ R_IMF_TIFF_CODEC_LZW
#define R_IMF_IMTYPE_THEORA
#define R_IMF_IMTYPE_CINEON
#define R_IMF_IMTYPE_AVIJPEG
#define R_IMF_IMTYPE_TIFF
#define R_IMF_IMTYPE_JP2
#define R_IMF_JP2_CODEC_J2K
#define R_IMF_EXR_CODEC_ZIP
#define R_IMF_IMTYPE_RAWTGA
#define R_IMF_IMTYPE_PNG
#define R_IMF_COLOR_MANAGEMENT_OVERRIDE
#define R_IMF_IMTYPE_IRIZ
#define R_IMF_IMTYPE_MULTILAYER
#define R_IMF_JP2_FLAG_CINE_PRESET
#define R_IMF_IMTYPE_BMP
#define R_IMF_IMTYPE_IRIS
@ R_IMF_CHAN_DEPTH_8
@ R_IMF_CHAN_DEPTH_16
@ R_IMF_CHAN_DEPTH_12
@ R_IMF_CHAN_DEPTH_10
@ R_IMF_CHAN_DEPTH_32
#define R_IMF_IMTYPE_XVID
#define R_IMF_IMTYPE_WEBP
#define R_IMF_CINEON_FLAG_LOG
#define R_IMF_IMTYPE_AVIRAW
#define R_IMF_IMTYPE_DPX
#define R_IMF_IMTYPE_DDS
#define R_IMF_IMTYPE_RADHDR
#define R_IMF_JP2_FLAG_YCC
#define R_IMF_JP2_CODEC_JP2
#define R_IMF_JP2_FLAG_CINE_48
#define R_IMF_IMTYPE_INVALID
#define R_IMF_FLAG_ZBUF
#define R_IMF_IMTYPE_OPENEXR
#define R_IMF_IMTYPE_PSD
#define R_IMF_IMTYPE_JPEG90
@ COLOR_ROLE_SCENE_LINEAR
const char * IMB_colormanagement_role_colorspace_name_get(int role)
void IMB_freezbuffloatImBuf(struct ImBuf *ibuf)
Definition: allocimbuf.c:168
Contains defines and structs used throughout the imbuf module.
#define OPENEXR_HALF
#define RAWTGA
#define PNG_16BIT
const char * imb_ext_image[]
Definition: util.c:43
#define OPENEXR_COMPRESS
#define IMB_FTYPE_NONE
CCL_NAMESPACE_BEGIN struct Options options
Scene scene
SyclQueue void void size_t num_bytes void
@ IMB_FTYPE_BMP
@ IMB_FTYPE_IMAGIC
@ IMB_FTYPE_JPG
@ IMB_FTYPE_TGA
@ IMB_FTYPE_OPENEXR
@ IMB_FTYPE_PNG
void BKE_image_format_free(ImageFormatData *imf)
Definition: image_format.cc:52
void BKE_image_format_init(ImageFormatData *imf, const bool render)
Definition: image_format.cc:26
bool BKE_imtype_supports_compress(const char imtype)
void BKE_image_format_init_for_write(ImageFormatData *imf, const Scene *scene_src, const ImageFormatData *imf_src)
bool BKE_imtype_supports_zbuf(const char imtype)
bool BKE_imtype_requires_linear_float(const char imtype)
void BKE_image_format_color_management_copy(ImageFormatData *imf, const ImageFormatData *imf_src)
char BKE_imtype_valid_depths(const char imtype)
void BKE_image_format_from_imbuf(ImageFormatData *im_format, const ImBuf *imbuf)
void BKE_image_format_blend_write(BlendWriter *writer, ImageFormatData *imf)
Definition: image_format.cc:62
void BKE_image_format_blend_read_data(BlendDataReader *reader, ImageFormatData *imf)
Definition: image_format.cc:57
int BKE_image_path_ensure_ext_from_imformat(char *string, const ImageFormatData *im_format)
char BKE_imtype_from_arg(const char *imtype_arg)
static bool do_add_image_extension(char *string, const char imtype, const ImageFormatData *im_format)
char BKE_imtype_valid_channels(const char imtype, bool write_file)
void BKE_image_path_from_imtype(char *string, const char *base, const char *relbase, int frame, const char imtype, const bool use_ext, const bool use_frames, const char *suffix)
static void do_makepicstring(char *string, const char *base, const char *relbase, int frame, const char imtype, const ImageFormatData *im_format, const bool use_ext, const bool use_frames, const char *suffix)
bool BKE_imtype_is_movie(const char imtype)
bool BKE_imtype_supports_quality(const char imtype)
void BKE_image_format_to_imbuf(ImBuf *ibuf, const ImageFormatData *imf)
int BKE_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options)
Definition: image_format.cc:69
void BKE_image_format_color_management_copy_from_scene(ImageFormatData *imf, const Scene *scene)
bool BKE_image_format_is_byte(const ImageFormatData *imf)
void BKE_image_path_from_imformat(char *string, const char *base, const char *relbase, int frame, const ImageFormatData *im_format, const bool use_ext, const bool use_frames, const char *suffix)
void BKE_image_format_copy(ImageFormatData *imf_dst, const ImageFormatData *imf_src)
Definition: image_format.cc:43
int BKE_image_path_ensure_ext_from_imtype(char *string, const char imtype)
char BKE_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
float * zbuf_float
ImbFormatOptions foptions
unsigned char planes
enum eImbFileType ftype
ColorManagedColorspaceSettings linear_colorspace_settings
ColorManagedDisplaySettings display_settings
ColorManagedViewSettings view_settings
struct ImageFormatData im_format
ColorManagedViewSettings view_settings
struct RenderData r
ColorManagedDisplaySettings display_settings