diff options
Diffstat (limited to 'source/blender/blenkernel/intern/image.c')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 133 |
1 files changed, 106 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index f3cdf11d664..dbc423f98b3 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -312,10 +312,6 @@ static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame) break; ibuf->index = index; - if (ima->flag & IMA_CM_PREDIVIDE) - ibuf->flags |= IB_cm_predivide; - else - ibuf->flags &= ~IB_cm_predivide; /* this function accepts (link == NULL) */ BLI_insertlinkbefore(&ima->ibufs, link, ibuf); @@ -552,6 +548,26 @@ int BKE_image_scale(Image *image, int width, int height) return (ibuf != NULL); } +static void image_init_color_management(Image *ima) +{ + ImBuf *ibuf; + char name[FILE_MAX]; + + BKE_image_user_file_path(NULL, ima, name); + + /* will set input color space to image format default's */ + ibuf = IMB_loadiffname(name, IB_test | IB_alphamode_detect, ima->colorspace_settings.name); + + if (ibuf) { + if (ibuf->flags & IB_alphamode_premul) + ima->alpha_mode = IMA_ALPHA_PREMUL; + else + ima->alpha_mode = IMA_ALPHA_STRAIGHT; + + IMB_freeImBuf(ibuf); + } +} + Image *BKE_image_load(const char *filepath) { Image *ima; @@ -579,6 +595,8 @@ Image *BKE_image_load(const char *filepath) if (BLI_testextensie_array(filepath, imb_ext_movie)) ima->source = IMA_SRC_MOVIE; + image_init_color_management(ima); + return ima; } @@ -666,7 +684,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char /* both byte and float buffers are filling in sRGB space, need to linearize float buffer after BKE_image_buf_fill* functions */ IMB_buffer_float_from_float(rect_float, rect_float, ibuf->channels, IB_PROFILE_LINEAR_RGB, IB_PROFILE_SRGB, - ibuf->flags & IB_cm_predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x); + TRUE, ibuf->x, ibuf->y, ibuf->x, ibuf->x); } return ibuf; @@ -1119,6 +1137,8 @@ char BKE_imtype_valid_depths(const char imtype) return R_IMF_CHAN_DEPTH_10; case R_IMF_IMTYPE_JP2: return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; + case R_IMF_IMTYPE_PNG: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; /* most formats are 8bit only */ default: return R_IMF_CHAN_DEPTH_8; @@ -1165,9 +1185,10 @@ char BKE_imtype_from_arg(const char *imtype_arg) else return R_IMF_IMTYPE_INVALID; } -int BKE_add_image_extension(char *string, const char imtype) +static int do_add_image_extension(char *string, const char imtype, const ImageFormatData *im_format) { const char *extension = NULL; + (void)im_format; /* may be unused, depends on build options */ if (imtype == R_IMF_IMTYPE_IRIS) { if (!BLI_testextensie(string, ".rgb")) @@ -1232,8 +1253,22 @@ int BKE_add_image_extension(char *string, const char imtype) } #ifdef WITH_OPENJPEG else if (imtype == R_IMF_IMTYPE_JP2) { - if (!BLI_testextensie(string, ".jp2")) - extension = ".jp2"; + if (im_format) { + if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) { + if (!BLI_testextensie(string, ".jp2")) + extension = ".jp2"; + } + else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) { + if (!BLI_testextensie(string, ".j2c")) + extension = ".j2c"; + } + else + BLI_assert(!"Unsupported jp2 codec was specified in im_format->jp2_codec"); + } + else { + if (!BLI_testextensie(string, ".jp2")) + extension = ".jp2"; + } } #endif else { // R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc @@ -1259,11 +1294,22 @@ int BKE_add_image_extension(char *string, const char imtype) } } +int BKE_add_image_extension(char *string, const ImageFormatData *im_format) +{ + return do_add_image_extension(string, im_format->imtype, im_format); +} + +int BKE_add_image_extension_from_type(char *string, const char imtype) +{ + return do_add_image_extension(string, imtype, NULL); +} + void BKE_imformat_defaults(ImageFormatData *im_format) { memset(im_format, 0, sizeof(*im_format)); im_format->planes = R_IMF_PLANES_RGB; im_format->imtype = R_IMF_IMTYPE_PNG; + im_format->depth = R_IMF_CHAN_DEPTH_8; im_format->quality = 90; im_format->compress = 90; @@ -1288,9 +1334,13 @@ void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *i im_format->imtype = R_IMF_IMTYPE_RADHDR; #endif - else if (ftype == PNG) + else if (ftype == PNG) { im_format->imtype = R_IMF_IMTYPE_PNG; + if (custom_flags & PNG_16BIT) + im_format->depth = R_IMF_CHAN_DEPTH_16; + } + #ifdef WITH_DDS else if (ftype == DDS) im_format->imtype = R_IMF_IMTYPE_DDS; @@ -1351,6 +1401,13 @@ void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *i if (ftype & JP2_CINE_48FPS) im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_48; } + + if (ftype & JP2_JP2) + im_format->jp2_codec = R_IMF_JP2_CODEC_JP2; + else if (ftype & JP2_J2K) + im_format->jp2_codec = R_IMF_JP2_CODEC_J2K; + else + BLI_assert(!"Unsupported jp2 codec was specified in file type"); } #endif @@ -1815,8 +1872,12 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) else if (ELEM5(imtype, R_IMF_IMTYPE_PNG, R_IMF_IMTYPE_FFMPEG, R_IMF_IMTYPE_H264, R_IMF_IMTYPE_THEORA, R_IMF_IMTYPE_XVID)) { ibuf->ftype = PNG; - if (imtype == R_IMF_IMTYPE_PNG) + if (imtype == R_IMF_IMTYPE_PNG) { + if (imf->depth == R_IMF_CHAN_DEPTH_16) + ibuf->ftype |= PNG_16BIT; + ibuf->ftype |= compress; + } } #ifdef WITH_DDS @@ -1906,6 +1967,13 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_48) ibuf->ftype |= JP2_CINE_48FPS; } + + if (imf->jp2_codec == R_IMF_JP2_CODEC_JP2) + ibuf->ftype |= JP2_JP2; + else if (imf->jp2_codec == R_IMF_JP2_CODEC_J2K) + ibuf->ftype |= JP2_J2K; + else + BLI_assert(!"Unsupported jp2 codec was specified in im_format->jp2_codec"); } #endif else { @@ -1956,7 +2024,8 @@ int BKE_imbuf_write_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, cons } -void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, const char imtype, const short use_ext, const short use_frames) +static void do_makepicstring(char *string, const char *base, const char *relbase, int frame, const char imtype, + const ImageFormatData *im_format, const short use_ext, const short use_frames) { if (string == NULL) return; BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ @@ -1966,8 +2035,17 @@ void BKE_makepicstring(char *string, const char *base, const char *relbase, int BLI_path_frame(string, frame, 4); if (use_ext) - BKE_add_image_extension(string, imtype); + do_add_image_extension(string, imtype, im_format); +} +void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, const ImageFormatData *im_format, const short use_ext, const short use_frames) +{ + do_makepicstring(string, base, relbase, frame, im_format->imtype, im_format, use_ext, use_frames); +} + +void BKE_makepicstring_from_type(char *string, const char *base, const char *relbase, int frame, const char imtype, const short use_ext, const short use_frames) +{ + do_makepicstring(string, base, relbase, frame, imtype, NULL, use_ext, use_frames); } /* used by sequencer too */ @@ -2284,7 +2362,7 @@ void BKE_image_backup_render(Scene *scene, Image *ima) static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr) { const char *colorspace = ima->colorspace_settings.name; - int predivide = ima->flag & IMA_CM_PREDIVIDE; + int predivide = ima->alpha_mode == IMA_ALPHA_PREMUL; ima->rr = RE_MultilayerConvert(ibuf->userdata, colorspace, predivide, ibuf->x, ibuf->y); @@ -2316,6 +2394,18 @@ static void image_initialize_after_load(Image *ima, ImBuf *ibuf) } +static int imbuf_alpha_flags_for_image(Image *ima) +{ + int flag = 0; + + if (ima->flag & IMA_IGNORE_ALPHA) + flag |= IB_ignore_alpha; + else if (ima->alpha_mode == IMA_ALPHA_PREMUL) + flag |= IB_alphamode_premul; + + return flag; +} + static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) { struct ImBuf *ibuf; @@ -2330,8 +2420,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) BKE_image_user_file_path(iuser, ima, name); flag = IB_rect | IB_multilayer; - if (ima->flag & IMA_DO_PREMUL) - flag |= IB_premul; + flag |= imbuf_alpha_flags_for_image(ima); /* read ibuf */ ibuf = IMB_loadiffname(name, flag, ima->colorspace_settings.name); @@ -2490,15 +2579,14 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) /* is there a PackedFile with this image ? */ if (ima->packedfile) { flag = IB_rect | IB_multilayer; - if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul; + flag |= imbuf_alpha_flags_for_image(ima); ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data, ima->packedfile->size, flag, ima->colorspace_settings.name, "<packed data>"); } else { flag = IB_rect | IB_multilayer | IB_metadata; - if (ima->flag & IMA_DO_PREMUL) - flag |= IB_premul; + flag |= imbuf_alpha_flags_for_image(ima); /* get the right string */ BKE_image_user_frame_calc(iuser, cfra, 0); @@ -2718,15 +2806,6 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **lock_ ibuf->dither = dither; - if (iuser->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE) { - ibuf->flags |= IB_cm_predivide; - ima->flag |= IMA_CM_PREDIVIDE; - } - else { - ibuf->flags &= ~IB_cm_predivide; - ima->flag &= ~IMA_CM_PREDIVIDE; - } - ima->ok = IMA_OK_LOADED; return ibuf; |