Blender V4.3
image_format.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstring>
10
11#include "DNA_defaults.h"
12#include "DNA_scene_types.h"
13
14#include "BLI_path_utils.hh"
15#include "BLI_string.h"
16#include "BLI_utildefines.h"
17
19#include "IMB_imbuf_types.hh"
20
21#include "BKE_colortools.hh"
22#include "BKE_image_format.hh"
23
24/* Init/Copy/Free */
25
42
51
56
58{
59 /* If the color space is set to a data space, this is probably the user's intention, so leave it
60 * as is. */
61 if (IMB_colormanagement_space_name_is_data(format->linear_colorspace_settings.name)) {
62 return;
63 }
64
65 const bool image_requires_linear = BKE_imtype_requires_linear_float(format->imtype);
67 format->linear_colorspace_settings.name);
68
69 /* The color space is either not set or is linear but the image requires non-linear or vice
70 * versa. So set to the default for the image type. */
71 if (format->linear_colorspace_settings.name[0] == '\0' || image_requires_linear != is_linear) {
72 const int role = image_requires_linear ? COLOR_ROLE_DEFAULT_FLOAT : COLOR_ROLE_DEFAULT_BYTE;
73 const char *default_color_space = IMB_colormanagement_role_colorspace_name_get(role);
74 STRNCPY(format->linear_colorspace_settings.name, default_color_space);
75 }
76}
77
82
87
88/* File Types */
89
90int BKE_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options)
91{
92 memset(r_options, 0, sizeof(*r_options));
93
94 if (imtype == R_IMF_IMTYPE_TARGA) {
95 return IMB_FTYPE_TGA;
96 }
97 if (imtype == R_IMF_IMTYPE_RAWTGA) {
98 r_options->flag = RAWTGA;
99 return IMB_FTYPE_TGA;
100 }
101 if (imtype == R_IMF_IMTYPE_IRIS) {
102 return IMB_FTYPE_IMAGIC;
103 }
104 if (imtype == R_IMF_IMTYPE_RADHDR) {
105 return IMB_FTYPE_RADHDR;
106 }
107 if (imtype == R_IMF_IMTYPE_PNG) {
108 r_options->quality = 15;
109 return IMB_FTYPE_PNG;
110 }
111 if (imtype == R_IMF_IMTYPE_DDS) {
112 return IMB_FTYPE_DDS;
113 }
114 if (imtype == R_IMF_IMTYPE_BMP) {
115 return IMB_FTYPE_BMP;
116 }
117 if (imtype == R_IMF_IMTYPE_TIFF) {
118 return IMB_FTYPE_TIF;
119 }
121 return IMB_FTYPE_OPENEXR;
122 }
123#ifdef WITH_CINEON
124 if (imtype == R_IMF_IMTYPE_CINEON) {
125 return IMB_FTYPE_CINEON;
126 }
127 if (imtype == R_IMF_IMTYPE_DPX) {
128 return IMB_FTYPE_DPX;
129 }
130#endif
131#ifdef WITH_OPENJPEG
132 if (imtype == R_IMF_IMTYPE_JP2) {
133 r_options->flag |= JP2_JP2;
134 r_options->quality = 90;
135 return IMB_FTYPE_JP2;
136 }
137#endif
138#ifdef WITH_WEBP
139 if (imtype == R_IMF_IMTYPE_WEBP) {
140 r_options->quality = 90;
141 return IMB_FTYPE_WEBP;
142 }
143#endif
144
145 r_options->quality = 90;
146 return IMB_FTYPE_JPG;
147}
148
149char BKE_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
150{
151 if (ftype == IMB_FTYPE_NONE) {
152 return R_IMF_IMTYPE_TARGA;
153 }
154 if (ftype == IMB_FTYPE_IMAGIC) {
155 return R_IMF_IMTYPE_IRIS;
156 }
157 if (ftype == IMB_FTYPE_RADHDR) {
158 return R_IMF_IMTYPE_RADHDR;
159 }
160 if (ftype == IMB_FTYPE_PNG) {
161 return R_IMF_IMTYPE_PNG;
162 }
163 if (ftype == IMB_FTYPE_DDS) {
164 return R_IMF_IMTYPE_DDS;
165 }
166 if (ftype == IMB_FTYPE_BMP) {
167 return R_IMF_IMTYPE_BMP;
168 }
169 if (ftype == IMB_FTYPE_TIF) {
170 return R_IMF_IMTYPE_TIFF;
171 }
172 if (ftype == IMB_FTYPE_OPENEXR) {
174 }
175#ifdef WITH_CINEON
176 if (ftype == IMB_FTYPE_CINEON) {
177 return R_IMF_IMTYPE_CINEON;
178 }
179 if (ftype == IMB_FTYPE_DPX) {
180 return R_IMF_IMTYPE_DPX;
181 }
182#endif
183 if (ftype == IMB_FTYPE_TGA) {
184 if (options && (options->flag & RAWTGA)) {
185 return R_IMF_IMTYPE_RAWTGA;
186 }
187
188 return R_IMF_IMTYPE_TARGA;
189 }
190#ifdef WITH_OPENJPEG
191 if (ftype == IMB_FTYPE_JP2) {
192 return R_IMF_IMTYPE_JP2;
193 }
194#endif
195#ifdef WITH_WEBP
196 if (ftype == IMB_FTYPE_WEBP) {
197 return R_IMF_IMTYPE_WEBP;
198 }
199#endif
200
201 return R_IMF_IMTYPE_JPEG90;
202}
203
204bool BKE_imtype_is_movie(const char imtype)
205{
206 switch (imtype) {
213 case R_IMF_IMTYPE_AV1:
214 return true;
215 }
216 return false;
217}
218
219bool 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
228bool BKE_imtype_supports_quality(const char imtype)
229{
230 switch (imtype) {
232 case R_IMF_IMTYPE_JP2:
235 return true;
236 }
237 return false;
238}
239
240bool BKE_imtype_requires_linear_float(const char imtype)
241{
242 switch (imtype) {
244 case R_IMF_IMTYPE_DPX:
248 return true;
249 }
250 return false;
251}
252
253char 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 }
267 case R_IMF_IMTYPE_PNG:
271 case R_IMF_IMTYPE_DDS:
272 case R_IMF_IMTYPE_JP2:
273 case R_IMF_IMTYPE_DPX:
275 chan_flag |= IMA_CHAN_FLAG_RGBA;
276 break;
277 }
278
279 /* BW. */
280 switch (imtype) {
281 case R_IMF_IMTYPE_BMP:
282 case R_IMF_IMTYPE_PNG:
289 chan_flag |= IMA_CHAN_FLAG_BW;
290 break;
291 }
292
293 return chan_flag;
294}
295
296char BKE_imtype_valid_depths(const char imtype)
297{
298 switch (imtype) {
300 return R_IMF_CHAN_DEPTH_32;
307 /* NOTE: CINEON uses an unusual 10bits-LOG per channel. */
308 case R_IMF_IMTYPE_DPX:
311 return R_IMF_CHAN_DEPTH_10;
312 case R_IMF_IMTYPE_JP2:
314 case R_IMF_IMTYPE_PNG:
316 /* Most formats are 8bit only. */
317 default:
318 return R_IMF_CHAN_DEPTH_8;
319 }
320}
321
322char BKE_imtype_from_arg(const char *imtype_arg)
323{
324 if (STREQ(imtype_arg, "TGA")) {
325 return R_IMF_IMTYPE_TARGA;
326 }
327 if (STREQ(imtype_arg, "IRIS")) {
328 return R_IMF_IMTYPE_IRIS;
329 }
330 if (STREQ(imtype_arg, "JPEG")) {
331 return R_IMF_IMTYPE_JPEG90;
332 }
333 if (STREQ(imtype_arg, "RAWTGA")) {
334 return R_IMF_IMTYPE_RAWTGA;
335 }
336 if (STREQ(imtype_arg, "AVIRAW")) {
337 return R_IMF_IMTYPE_AVIRAW;
338 }
339 if (STREQ(imtype_arg, "AVIJPEG")) {
341 }
342 if (STREQ(imtype_arg, "PNG")) {
343 return R_IMF_IMTYPE_PNG;
344 }
345 if (STREQ(imtype_arg, "BMP")) {
346 return R_IMF_IMTYPE_BMP;
347 }
348 if (STREQ(imtype_arg, "HDR")) {
349 return R_IMF_IMTYPE_RADHDR;
350 }
351 if (STREQ(imtype_arg, "TIFF")) {
352 return R_IMF_IMTYPE_TIFF;
353 }
354#ifdef WITH_OPENEXR
355 if (STREQ(imtype_arg, "OPEN_EXR")) {
357 }
358 if (STREQ(imtype_arg, "OPEN_EXR_MULTILAYER")) {
360 }
361 if (STREQ(imtype_arg, "EXR")) {
363 }
364 if (STREQ(imtype_arg, "MULTILAYER")) {
366 }
367#endif
368#ifdef WITH_FFMPEG
369 if (STREQ(imtype_arg, "FFMPEG")) {
370 return R_IMF_IMTYPE_FFMPEG;
371 }
372#endif
373#ifdef WITH_CINEON
374 if (STREQ(imtype_arg, "CINEON")) {
375 return R_IMF_IMTYPE_CINEON;
376 }
377 if (STREQ(imtype_arg, "DPX")) {
378 return R_IMF_IMTYPE_DPX;
379 }
380#endif
381#ifdef WITH_OPENJPEG
382 if (STREQ(imtype_arg, "JP2")) {
383 return R_IMF_IMTYPE_JP2;
384 }
385#endif
386#ifdef WITH_WEBP
387 if (STREQ(imtype_arg, "WEBP")) {
388 return R_IMF_IMTYPE_WEBP;
389 }
390#endif
391
393}
394
395/* File Paths */
396
397static int image_path_ext_from_imformat_impl(const char imtype,
398 const ImageFormatData *im_format,
399 const char *r_ext[BKE_IMAGE_PATH_EXT_MAX])
400{
401 int ext_num = 0;
402 (void)im_format; /* may be unused, depends on build options */
403
404 if (imtype == R_IMF_IMTYPE_IRIS) {
405 r_ext[ext_num++] = ".rgb";
406 }
407 else if (imtype == R_IMF_IMTYPE_IRIZ) {
408 r_ext[ext_num++] = ".rgb";
409 }
410 else if (imtype == R_IMF_IMTYPE_RADHDR) {
411 r_ext[ext_num++] = ".hdr";
412 }
413 else if (ELEM(imtype,
420 {
421 r_ext[ext_num++] = ".png";
422 }
423 else if (imtype == R_IMF_IMTYPE_DDS) {
424 r_ext[ext_num++] = ".dds";
425 }
426 else if (ELEM(imtype, R_IMF_IMTYPE_TARGA, R_IMF_IMTYPE_RAWTGA)) {
427 r_ext[ext_num++] = ".tga";
428 }
429 else if (imtype == R_IMF_IMTYPE_BMP) {
430 r_ext[ext_num++] = ".bmp";
431 }
432 else if (imtype == R_IMF_IMTYPE_TIFF) {
433 r_ext[ext_num++] = ".tif";
434 r_ext[ext_num++] = ".tiff";
435 }
436 else if (imtype == R_IMF_IMTYPE_PSD) {
437 r_ext[ext_num++] = ".psd";
438 }
439#ifdef WITH_OPENEXR
441 r_ext[ext_num++] = ".exr";
442 }
443#endif
444#ifdef WITH_CINEON
445 else if (imtype == R_IMF_IMTYPE_CINEON) {
446 r_ext[ext_num++] = ".cin";
447 }
448 else if (imtype == R_IMF_IMTYPE_DPX) {
449 r_ext[ext_num++] = ".dpx";
450 }
451#endif
452#ifdef WITH_OPENJPEG
453 else if (imtype == R_IMF_IMTYPE_JP2) {
454 if (im_format) {
455 if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) {
456 r_ext[ext_num++] = ".jp2";
457 }
458 else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) {
459 r_ext[ext_num++] = ".j2c";
460 }
461 else {
462 BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec");
463 }
464 }
465 else {
466 r_ext[ext_num++] = ".jp2";
467 }
468 }
469#endif
470#ifdef WITH_WEBP
471 else if (imtype == R_IMF_IMTYPE_WEBP) {
472 r_ext[ext_num++] = ".webp";
473 }
474#endif
475 else {
476 /* Handles: #R_IMF_IMTYPE_AVIRAW, #R_IMF_IMTYPE_AVIJPEG, #R_IMF_IMTYPE_JPEG90 etc. */
477 r_ext[ext_num++] = ".jpg";
478 r_ext[ext_num++] = ".jpeg";
479 }
481 r_ext[ext_num] = nullptr;
482 return ext_num;
483}
484
486 const char *r_ext[BKE_IMAGE_PATH_EXT_MAX])
487{
488 return image_path_ext_from_imformat_impl(im_format->imtype, im_format, r_ext);
489}
490
491int BKE_image_path_ext_from_imtype(const char imtype, const char *r_ext[BKE_IMAGE_PATH_EXT_MAX])
492{
493 return image_path_ext_from_imformat_impl(imtype, nullptr, r_ext);
494}
495
496static bool do_ensure_image_extension(char *filepath,
497 const size_t filepath_maxncpy,
498 const char imtype,
499 const ImageFormatData *im_format)
500{
501 const char *ext_array[BKE_IMAGE_PATH_EXT_MAX];
502 int ext_array_num = image_path_ext_from_imformat_impl(imtype, im_format, ext_array);
503 if (ext_array_num && !BLI_path_extension_check_array(filepath, ext_array)) {
504 /* Removing *any* extension may remove part of the user defined name (if they include '.')
505 * however in the case there is already a known image extension,
506 * remove it to avoid`.png.tga`, for example. */
508 return BLI_path_extension_replace(filepath, filepath_maxncpy, ext_array[0]);
509 }
510 return BLI_path_extension_ensure(filepath, filepath_maxncpy, ext_array[0]);
511 }
512
513 return false;
514}
515
517 const size_t filepath_maxncpy,
518 const ImageFormatData *im_format)
519{
520 return do_ensure_image_extension(filepath, filepath_maxncpy, im_format->imtype, im_format);
521}
522
524 const size_t filepath_maxncpy,
525 const char imtype)
526{
527 return do_ensure_image_extension(filepath, filepath_maxncpy, imtype, nullptr);
528}
529
530static void do_makepicstring(char filepath[FILE_MAX],
531 const char *base,
532 const char *relbase,
533 int frame,
534 const char imtype,
535 const ImageFormatData *im_format,
536 const bool use_ext,
537 const bool use_frames,
538 const char *suffix)
539{
540 if (filepath == nullptr) {
541 return;
542 }
543 BLI_strncpy(filepath, base, FILE_MAX - 10); /* weak assumption */
544 BLI_path_abs(filepath, relbase);
545
546 if (use_frames) {
547 BLI_path_frame(filepath, FILE_MAX, frame, 4);
548 }
549
550 if (suffix) {
551 BLI_path_suffix(filepath, FILE_MAX, suffix, "");
552 }
553
554 if (use_ext) {
555 do_ensure_image_extension(filepath, FILE_MAX, imtype, im_format);
556 }
557}
558
560 const char *base,
561 const char *relbase,
562 int frame,
563 const ImageFormatData *im_format,
564 const bool use_ext,
565 const bool use_frames,
566 const char *suffix)
567{
569 filepath, base, relbase, frame, im_format->imtype, im_format, use_ext, use_frames, suffix);
570}
571
572void BKE_image_path_from_imtype(char *filepath,
573 const char *base,
574 const char *relbase,
575 int frame,
576 const char imtype,
577 const bool use_ext,
578 const bool use_frames,
579 const char *suffix)
580{
581 do_makepicstring(filepath, base, relbase, frame, imtype, nullptr, use_ext, use_frames, suffix);
582}
583
584/* ImBuf Conversion */
585
587{
588 /* Write to ImBuf in preparation for file writing. */
589 char imtype = imf->imtype;
590 char compress = imf->compress;
591 char quality = imf->quality;
592
593 /* initialize all from image format */
594 ibuf->foptions.flag = 0;
595
596 if (imtype == R_IMF_IMTYPE_IRIS) {
597 ibuf->ftype = IMB_FTYPE_IMAGIC;
598 }
599 else if (imtype == R_IMF_IMTYPE_RADHDR) {
600 ibuf->ftype = IMB_FTYPE_RADHDR;
601 }
602 else if (ELEM(imtype,
609 {
610 ibuf->ftype = IMB_FTYPE_PNG;
611
612 if (imtype == R_IMF_IMTYPE_PNG) {
613 if (imf->depth == R_IMF_CHAN_DEPTH_16) {
614 ibuf->foptions.flag |= PNG_16BIT;
615 }
616
617 ibuf->foptions.quality = compress;
618 }
619 }
620 else if (imtype == R_IMF_IMTYPE_DDS) {
621 ibuf->ftype = IMB_FTYPE_DDS;
622 }
623 else if (imtype == R_IMF_IMTYPE_BMP) {
624 ibuf->ftype = IMB_FTYPE_BMP;
625 }
626 else if (imtype == R_IMF_IMTYPE_TIFF) {
627 ibuf->ftype = IMB_FTYPE_TIF;
628
629 if (imf->depth == R_IMF_CHAN_DEPTH_16) {
630 ibuf->foptions.flag |= TIF_16BIT;
631 }
632 if (imf->tiff_codec == R_IMF_TIFF_CODEC_NONE) {
634 }
635 else if (imf->tiff_codec == R_IMF_TIFF_CODEC_DEFLATE) {
637 }
638 else if (imf->tiff_codec == R_IMF_TIFF_CODEC_LZW) {
640 }
641 else if (imf->tiff_codec == R_IMF_TIFF_CODEC_PACKBITS) {
643 }
644 }
645#ifdef WITH_OPENEXR
647 ibuf->ftype = IMB_FTYPE_OPENEXR;
648 if (imf->depth == R_IMF_CHAN_DEPTH_16) {
649 ibuf->foptions.flag |= OPENEXR_HALF;
650 }
651 ibuf->foptions.flag |= (imf->exr_codec & OPENEXR_COMPRESS);
652 }
653#endif
654#ifdef WITH_CINEON
655 else if (imtype == R_IMF_IMTYPE_CINEON) {
656 ibuf->ftype = IMB_FTYPE_CINEON;
658 ibuf->foptions.flag |= CINEON_LOG;
659 }
660 if (imf->depth == R_IMF_CHAN_DEPTH_16) {
661 ibuf->foptions.flag |= CINEON_16BIT;
662 }
663 else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
664 ibuf->foptions.flag |= CINEON_12BIT;
665 }
666 else if (imf->depth == R_IMF_CHAN_DEPTH_10) {
667 ibuf->foptions.flag |= CINEON_10BIT;
668 }
669 }
670 else if (imtype == R_IMF_IMTYPE_DPX) {
671 ibuf->ftype = IMB_FTYPE_DPX;
673 ibuf->foptions.flag |= CINEON_LOG;
674 }
675 if (imf->depth == R_IMF_CHAN_DEPTH_16) {
676 ibuf->foptions.flag |= CINEON_16BIT;
677 }
678 else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
679 ibuf->foptions.flag |= CINEON_12BIT;
680 }
681 else if (imf->depth == R_IMF_CHAN_DEPTH_10) {
682 ibuf->foptions.flag |= CINEON_10BIT;
683 }
684 }
685#endif
686 else if (imtype == R_IMF_IMTYPE_TARGA) {
687 ibuf->ftype = IMB_FTYPE_TGA;
688 }
689 else if (imtype == R_IMF_IMTYPE_RAWTGA) {
690 ibuf->ftype = IMB_FTYPE_TGA;
691 ibuf->foptions.flag = RAWTGA;
692 }
693#ifdef WITH_OPENJPEG
694 else if (imtype == R_IMF_IMTYPE_JP2) {
695 if (quality < 10) {
696 quality = 90;
697 }
698 ibuf->ftype = IMB_FTYPE_JP2;
699 ibuf->foptions.quality = quality;
700
701 if (imf->depth == R_IMF_CHAN_DEPTH_16) {
702 ibuf->foptions.flag |= JP2_16BIT;
703 }
704 else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
705 ibuf->foptions.flag |= JP2_12BIT;
706 }
707
708 if (imf->jp2_flag & R_IMF_JP2_FLAG_YCC) {
709 ibuf->foptions.flag |= JP2_YCC;
710 }
711
713 ibuf->foptions.flag |= JP2_CINE;
714 if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_48) {
715 ibuf->foptions.flag |= JP2_CINE_48FPS;
716 }
717 }
718
719 if (imf->jp2_codec == R_IMF_JP2_CODEC_JP2) {
720 ibuf->foptions.flag |= JP2_JP2;
721 }
722 else if (imf->jp2_codec == R_IMF_JP2_CODEC_J2K) {
723 ibuf->foptions.flag |= JP2_J2K;
724 }
725 else {
726 BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec");
727 }
728 }
729#endif
730#ifdef WITH_WEBP
731 else if (imtype == R_IMF_IMTYPE_WEBP) {
732 ibuf->ftype = IMB_FTYPE_WEBP;
733 ibuf->foptions.quality = quality;
734 }
735#endif
736 else {
737 /* #R_IMF_IMTYPE_JPEG90, etc. default to JPEG. */
738 if (quality < 10) {
739 quality = 90;
740 }
741 ibuf->ftype = IMB_FTYPE_JPG;
742 ibuf->foptions.quality = quality;
743 }
744}
745
747{
748 /* Read from ImBuf after file read. */
749 int ftype = imbuf->ftype;
750 int custom_flags = imbuf->foptions.flag;
751 char quality = imbuf->foptions.quality;
752
753 BKE_image_format_init(im_format, false);
754
755 /* file type */
756 if (ftype == IMB_FTYPE_IMAGIC) {
757 im_format->imtype = R_IMF_IMTYPE_IRIS;
758 }
759 else if (ftype == IMB_FTYPE_RADHDR) {
760 im_format->imtype = R_IMF_IMTYPE_RADHDR;
761 }
762 else if (ftype == IMB_FTYPE_PNG) {
763 im_format->imtype = R_IMF_IMTYPE_PNG;
764
765 if (custom_flags & PNG_16BIT) {
766 im_format->depth = R_IMF_CHAN_DEPTH_16;
767 }
768
769 im_format->compress = quality;
770 }
771 else if (ftype == IMB_FTYPE_DDS) {
772 im_format->imtype = R_IMF_IMTYPE_DDS;
773 }
774 else if (ftype == IMB_FTYPE_BMP) {
775 im_format->imtype = R_IMF_IMTYPE_BMP;
776 }
777 else if (ftype == IMB_FTYPE_TIF) {
778 im_format->imtype = R_IMF_IMTYPE_TIFF;
779 if (custom_flags & TIF_16BIT) {
780 im_format->depth = R_IMF_CHAN_DEPTH_16;
781 }
782 if (custom_flags & TIF_COMPRESS_NONE) {
784 }
785 if (custom_flags & TIF_COMPRESS_DEFLATE) {
787 }
788 if (custom_flags & TIF_COMPRESS_LZW) {
789 im_format->tiff_codec = R_IMF_TIFF_CODEC_LZW;
790 }
791 if (custom_flags & TIF_COMPRESS_PACKBITS) {
793 }
794 }
795
796#ifdef WITH_OPENEXR
797 else if (ftype == IMB_FTYPE_OPENEXR) {
798 im_format->imtype = R_IMF_IMTYPE_OPENEXR;
799 if (custom_flags & OPENEXR_HALF) {
800 im_format->depth = R_IMF_CHAN_DEPTH_16;
801 }
802 if (custom_flags & OPENEXR_COMPRESS) {
803 im_format->exr_codec = R_IMF_EXR_CODEC_ZIP; /* Can't determine compression */
804 }
805 }
806#endif
807
808#ifdef WITH_CINEON
809 else if (ftype == IMB_FTYPE_CINEON) {
810 im_format->imtype = R_IMF_IMTYPE_CINEON;
811 }
812 else if (ftype == IMB_FTYPE_DPX) {
813 im_format->imtype = R_IMF_IMTYPE_DPX;
814 }
815#endif
816 else if (ftype == IMB_FTYPE_TGA) {
817 if (custom_flags & RAWTGA) {
818 im_format->imtype = R_IMF_IMTYPE_RAWTGA;
819 }
820 else {
821 im_format->imtype = R_IMF_IMTYPE_TARGA;
822 }
823 }
824#ifdef WITH_OPENJPEG
825 else if (ftype == IMB_FTYPE_JP2) {
826 im_format->imtype = R_IMF_IMTYPE_JP2;
827 im_format->quality = quality;
828
829 if (custom_flags & JP2_16BIT) {
830 im_format->depth = R_IMF_CHAN_DEPTH_16;
831 }
832 else if (custom_flags & JP2_12BIT) {
833 im_format->depth = R_IMF_CHAN_DEPTH_12;
834 }
835
836 if (custom_flags & JP2_YCC) {
837 im_format->jp2_flag |= R_IMF_JP2_FLAG_YCC;
838 }
839
840 if (custom_flags & JP2_CINE) {
842 if (custom_flags & JP2_CINE_48FPS) {
843 im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_48;
844 }
845 }
846
847 if (custom_flags & JP2_JP2) {
848 im_format->jp2_codec = R_IMF_JP2_CODEC_JP2;
849 }
850 else if (custom_flags & JP2_J2K) {
851 im_format->jp2_codec = R_IMF_JP2_CODEC_J2K;
852 }
853 else {
854 BLI_assert_msg(0, "Unsupported jp2 codec was specified in file type");
855 }
856 }
857#endif
858#ifdef WITH_WEBP
859 else if (ftype == IMB_FTYPE_WEBP) {
860 im_format->imtype = R_IMF_IMTYPE_WEBP;
861 im_format->quality = quality;
862 }
863#endif
864
865 else {
866 im_format->imtype = R_IMF_IMTYPE_JPEG90;
867 im_format->quality = quality;
868 }
869
870 /* planes */
871 im_format->planes = imbuf->planes;
872}
873
875{
876 return (imf->depth == R_IMF_CHAN_DEPTH_8) && (BKE_imtype_valid_depths(imf->imtype) & imf->depth);
877}
878
879/* Color Management */
880
890
900
901/* Output */
902
904 const Scene *scene_src,
905 const ImageFormatData *imf_src)
906{
907 *imf = (imf_src) ? *imf_src : scene_src->r.im_format;
908
909 if (imf_src && imf_src->color_management == R_IMF_COLOR_MANAGEMENT_OVERRIDE) {
910 /* Use settings specific to one node, image save operation, etc. */
915 }
917 /* Use scene settings specific to render output. */
919 &scene_src->r.im_format.display_settings);
921 &scene_src->r.im_format.view_settings);
924 }
925 else {
926 /* Use general scene settings also used for display. */
931 }
932}
void BKE_color_managed_colorspace_settings_init(ColorManagedColorspaceSettings *colorspace_settings)
void BKE_color_managed_view_settings_blend_read_data(BlendDataReader *reader, ColorManagedViewSettings *settings)
void BKE_color_managed_display_settings_copy(ColorManagedDisplaySettings *new_settings, const ColorManagedDisplaySettings *settings)
void BKE_color_managed_display_settings_init(ColorManagedDisplaySettings *settings)
void BKE_color_managed_view_settings_init_default(ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
void BKE_color_managed_view_settings_free(ColorManagedViewSettings *settings)
void BKE_color_managed_view_settings_copy(ColorManagedViewSettings *new_settings, const ColorManagedViewSettings *settings)
void BKE_color_managed_view_settings_init_render(ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const char *view_transform)
void BKE_color_managed_view_settings_blend_write(BlendWriter *writer, ColorManagedViewSettings *settings)
void BKE_color_managed_colorspace_settings_copy(ColorManagedColorspaceSettings *colorspace_settings, const ColorManagedColorspaceSettings *settings)
#define IMA_CHAN_FLAG_RGB
#define IMA_CHAN_FLAG_RGBA
#define IMA_CHAN_FLAG_BW
#define BKE_IMAGE_PATH_EXT_MAX
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
#define ATTR_FALLTHROUGH
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
bool bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const char *sep) ATTR_NONNULL(1
bool BLI_path_extension_check_array(const char *path, const char **ext_array) ATTR_NONNULL(1
#define FILE_MAX
bool BLI_path_extension_replace(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define ELEM(...)
#define STREQ(a, b)
#define DNA_struct_default_get(struct_name)
@ R_IMF_JP2_FLAG_CINE_48
@ R_IMF_JP2_FLAG_CINE_PRESET
@ R_IMF_JP2_FLAG_YCC
@ R_IMF_EXR_CODEC_ZIP
@ 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
@ R_IMF_IMTYPE_DDS
@ R_IMF_IMTYPE_INVALID
@ R_IMF_IMTYPE_IRIS
@ R_IMF_IMTYPE_FFMPEG
@ R_IMF_IMTYPE_WEBP
@ R_IMF_IMTYPE_BMP
@ R_IMF_IMTYPE_AVIJPEG
@ R_IMF_IMTYPE_H264
@ R_IMF_IMTYPE_JPEG90
@ R_IMF_IMTYPE_TIFF
@ R_IMF_IMTYPE_IRIZ
@ R_IMF_IMTYPE_RADHDR
@ R_IMF_IMTYPE_PSD
@ R_IMF_IMTYPE_TARGA
@ R_IMF_IMTYPE_DPX
@ R_IMF_IMTYPE_AVIRAW
@ R_IMF_IMTYPE_THEORA
@ R_IMF_IMTYPE_JP2
@ R_IMF_IMTYPE_OPENEXR
@ R_IMF_IMTYPE_MULTILAYER
@ R_IMF_IMTYPE_PNG
@ R_IMF_IMTYPE_AV1
@ R_IMF_IMTYPE_CINEON
@ R_IMF_IMTYPE_RAWTGA
@ R_IMF_IMTYPE_XVID
@ R_IMF_TIFF_CODEC_PACKBITS
@ R_IMF_TIFF_CODEC_DEFLATE
@ R_IMF_TIFF_CODEC_NONE
@ R_IMF_TIFF_CODEC_LZW
@ R_IMF_JP2_CODEC_JP2
@ R_IMF_JP2_CODEC_J2K
@ R_IMF_CINEON_FLAG_LOG
@ R_IMF_COLOR_MANAGEMENT_OVERRIDE
bool IMB_colormanagement_space_name_is_scene_linear(const char *name)
bool IMB_colormanagement_space_name_is_data(const char *name)
const char * IMB_colormanagement_role_colorspace_name_get(int role)
@ COLOR_ROLE_DEFAULT_FLOAT
@ COLOR_ROLE_DEFAULT_BYTE
@ COLOR_ROLE_SCENE_LINEAR
@ IMB_FTYPE_BMP
@ IMB_FTYPE_IMAGIC
@ IMB_FTYPE_JPG
@ IMB_FTYPE_TGA
@ IMB_FTYPE_RADHDR
@ IMB_FTYPE_TIF
@ IMB_FTYPE_DDS
@ IMB_FTYPE_OPENEXR
@ IMB_FTYPE_NONE
@ IMB_FTYPE_PNG
Contains defines and structs used throughout the imbuf module.
#define TIF_COMPRESS_PACKBITS
#define TIF_COMPRESS_NONE
#define TIF_COMPRESS_DEFLATE
#define RAWTGA
#define TIF_COMPRESS_LZW
#define PNG_16BIT
#define TIF_16BIT
const char * imb_ext_image[]
#define OPENEXR_COMPRESS
CCL_NAMESPACE_BEGIN struct Options options
#define OPENEXR_HALF
void BKE_image_format_free(ImageFormatData *imf)
void BKE_image_format_init(ImageFormatData *imf, const bool render)
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)
void BKE_image_path_from_imtype(char *filepath, const char *base, const char *relbase, int frame, const char imtype, const bool use_ext, const bool use_frames, const char *suffix)
bool BKE_imtype_requires_linear_float(const char imtype)
static int image_path_ext_from_imformat_impl(const char imtype, const ImageFormatData *im_format, const char *r_ext[BKE_IMAGE_PATH_EXT_MAX])
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)
int BKE_image_path_ext_from_imformat(const ImageFormatData *im_format, const char *r_ext[BKE_IMAGE_PATH_EXT_MAX])
void BKE_image_format_blend_write(BlendWriter *writer, ImageFormatData *imf)
void BKE_image_format_blend_read_data(BlendDataReader *reader, ImageFormatData *imf)
char BKE_imtype_from_arg(const char *imtype_arg)
char BKE_imtype_valid_channels(const char imtype, bool write_file)
void BKE_image_format_update_color_space_for_type(ImageFormatData *format)
int BKE_image_path_ext_from_imtype(const char imtype, const char *r_ext[BKE_IMAGE_PATH_EXT_MAX])
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)
int BKE_image_path_ext_from_imtype_ensure(char *filepath, const size_t filepath_maxncpy, const char imtype)
void BKE_image_format_color_management_copy_from_scene(ImageFormatData *imf, const Scene *scene)
bool BKE_image_format_is_byte(const ImageFormatData *imf)
static void do_makepicstring(char filepath[FILE_MAX], 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)
int BKE_image_path_ext_from_imformat_ensure(char *filepath, const size_t filepath_maxncpy, const ImageFormatData *im_format)
void BKE_image_format_copy(ImageFormatData *imf_dst, const ImageFormatData *imf_src)
static bool do_ensure_image_extension(char *filepath, const size_t filepath_maxncpy, const char imtype, const ImageFormatData *im_format)
void BKE_image_path_from_imformat(char *filepath, const char *base, const char *relbase, int frame, const ImageFormatData *im_format, const bool use_ext, const bool use_frames, const char *suffix)
char BKE_ftype_to_imtype(const int ftype, const ImbFormatOptions *options)
format
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