diff options
Diffstat (limited to 'source/blender/imbuf/intern')
23 files changed, 567 insertions, 341 deletions
diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h index d89393b9903..b10ae4f6fe9 100644 --- a/source/blender/imbuf/intern/IMB_anim.h +++ b/source/blender/imbuf/intern/IMB_anim.h @@ -40,10 +40,7 @@ # include <mmsystem.h> # include <memory.h> # include <commdlg.h> - -# ifndef FREE_WINDOWS -# include <vfw.h> -# endif +# include <vfw.h> # undef AVIIF_KEYFRAME // redefined in AVI_avi.h # undef AVIIF_LIST // redefined in AVI_avi.h @@ -66,12 +63,6 @@ # include "AVI_avi.h" #endif -#ifdef WITH_QUICKTIME -# if defined(_WIN32) || defined(__APPLE__) -# include "quicktime_import.h" -# endif /* _WIN32 || __APPLE__ */ -#endif /* WITH_QUICKTIME */ - #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -130,7 +121,7 @@ struct anim { /* avi */ struct _AviMovie *avi; -#if defined(_WIN32) && !defined(FREE_WINDOWS) +#if defined(_WIN32) /* windows avi */ int avistreams; int firstvideo; @@ -140,11 +131,6 @@ struct anim { PGETFRAME pgf; #endif -#ifdef WITH_QUICKTIME - /* quicktime */ - struct _QuicktimeMovie *qtime; -#endif /* WITH_QUICKTIME */ - #ifdef WITH_FFMPEG AVFormatContext *pFormatCtx; AVCodecContext *pCodecCtx; diff --git a/source/blender/imbuf/intern/IMB_colormanagement_intern.h b/source/blender/imbuf/intern/IMB_colormanagement_intern.h index b75f12b239d..0b4557e7bef 100644 --- a/source/blender/imbuf/intern/IMB_colormanagement_intern.h +++ b/source/blender/imbuf/intern/IMB_colormanagement_intern.h @@ -79,6 +79,8 @@ typedef struct ColorManagedLook { struct ColorManagedLook *next, *prev; int index; char name[MAX_COLORSPACE_NAME]; + char ui_name[MAX_COLORSPACE_NAME]; + char view[MAX_COLORSPACE_NAME]; char process_space[MAX_COLORSPACE_NAME]; bool is_noop; } ColorManagedLook; diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index ef3743d9c8a..6e9bfa1fc4e 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -89,11 +89,14 @@ void imb_mmap_unlock(void) void imb_freemipmapImBuf(ImBuf *ibuf) { int a; - - for (a = 1; a < ibuf->miptot; a++) { - if (ibuf->mipmap[a - 1]) - IMB_freeImBuf(ibuf->mipmap[a - 1]); - ibuf->mipmap[a - 1] = NULL; + + /* Do not trust ibuf->miptot, in some cases IMB_remakemipmap can leave unfreed unused levels, + * leading to memory leaks... */ + for (a = 0; a < IMB_MIPMAP_LEVELS; a++) { + if (ibuf->mipmap[a] != NULL) { + IMB_freeImBuf(ibuf->mipmap[a]); + ibuf->mipmap[a] = NULL; + } } ibuf->miptot = 0; @@ -503,7 +506,7 @@ bool IMB_initImBuf(struct ImBuf *ibuf, } /* does no zbuffers? */ -ImBuf *IMB_dupImBuf(ImBuf *ibuf1) +ImBuf *IMB_dupImBuf(const ImBuf *ibuf1) { ImBuf *ibuf2, tbuf; int flags = 0; diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index a40b257b75b..25b0c0d7b1a 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -37,10 +37,7 @@ #include <mmsystem.h> #include <memory.h> #include <commdlg.h> - -#ifndef FREE_WINDOWS #include <vfw.h> -#endif #undef AVIIF_KEYFRAME /* redefined in AVI_avi.h */ #undef AVIIF_LIST /* redefined in AVI_avi.h */ @@ -76,12 +73,6 @@ # include "AVI_avi.h" #endif -#ifdef WITH_QUICKTIME -#if defined(_WIN32) || defined(__APPLE__) -#include "quicktime_import.h" -#endif /* _WIN32 || __APPLE__ */ -#endif /* WITH_QUICKTIME */ - #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -173,7 +164,7 @@ static void an_stringenc(char *string, const char *head, const char *tail, unsig #ifdef WITH_AVI static void free_anim_avi(struct anim *anim) { -#if defined(_WIN32) && !defined(FREE_WINDOWS) +#if defined(_WIN32) int i; #endif @@ -184,7 +175,7 @@ static void free_anim_avi(struct anim *anim) MEM_freeN(anim->avi); anim->avi = NULL; -#if defined(_WIN32) && !defined(FREE_WINDOWS) +#if defined(_WIN32) if (anim->pgf) { AVIStreamGetFrameClose(anim->pgf); @@ -224,9 +215,6 @@ void IMB_free_anim(struct anim *anim) free_anim_avi(anim); #endif -#ifdef WITH_QUICKTIME - free_anim_quicktime(anim); -#endif #ifdef WITH_FFMPEG free_anim_ffmpeg(anim); #endif @@ -283,7 +271,7 @@ static int startavi(struct anim *anim) { AviError avierror; -#if defined(_WIN32) && !defined(FREE_WINDOWS) +#if defined(_WIN32) HRESULT hr; int i, firstvideo = -1; int streamcount; @@ -304,7 +292,7 @@ static int startavi(struct anim *anim) avierror = AVI_open_movie(anim->name, anim->avi); -#if defined(_WIN32) && !defined(FREE_WINDOWS) +#if defined(_WIN32) if (avierror == AVI_ERROR_COMPRESSION) { AVIFileInit(); hr = AVIFileOpen(&anim->pfile, anim->name, OF_READ, 0L); @@ -401,7 +389,7 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position) return NULL; } -#if defined(_WIN32) && !defined(FREE_WINDOWS) +#if defined(_WIN32) if (anim->avistreams) { LPBITMAPINFOHEADER lpbi; @@ -516,6 +504,11 @@ static int startffmpeg(struct anim *anim) avformat_close_input(&pFormatCtx); return -1; } + if (pCodecCtx->pix_fmt == AV_PIX_FMT_NONE) { + avcodec_close(anim->pCodecCtx); + avformat_close_input(&pFormatCtx); + return -1; + } frame_rate = av_get_r_frame_rate_compat(pFormatCtx->streams[videoStream]); if (pFormatCtx->streams[videoStream]->nb_frames != 0) { @@ -1217,9 +1210,6 @@ static ImBuf *anim_getnew(struct anim *anim) free_anim_avi(anim); #endif -#ifdef WITH_QUICKTIME - free_anim_quicktime(anim); -#endif #ifdef WITH_FFMPEG free_anim_ffmpeg(anim); #endif @@ -1248,12 +1238,6 @@ static ImBuf *anim_getnew(struct anim *anim) ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); break; #endif -#ifdef WITH_QUICKTIME - case ANIM_QTIME: - if (startquicktime(anim)) return (0); - ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); - break; -#endif #ifdef WITH_FFMPEG case ANIM_FFMPEG: if (startffmpeg(anim)) return (0); @@ -1343,21 +1327,6 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int position, anim->curposition = position; break; #endif -#ifdef WITH_QUICKTIME - case ANIM_QTIME: - ibuf = qtime_fetchibuf(anim, position); - if (ibuf) { - if (ibuf->rect) { - /* OCIO_TODO: should happen in quicktime module, but it currently doesn't have access - * to color management's internals - */ - ibuf->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace); - } - - anim->curposition = position; - } - break; -#endif #ifdef WITH_FFMPEG case ANIM_FFMPEG: ibuf = ffmpeg_fetchibuf(anim, position, tc); diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c index 8b4e95ac452..429a19936a5 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.c +++ b/source/blender/imbuf/intern/cineon/dpxlib.c @@ -183,7 +183,7 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf if (verbose) printf("DPX: File is LSB.\n"); } else { - if (verbose) { + if (verbose) { printf("DPX: Bad magic number %u in \"%s\".\n", header.fileHeader.magic_num, byteStuff); } diff --git a/source/blender/imbuf/intern/cineon/logImageCore.c b/source/blender/imbuf/intern/cineon/logImageCore.c index 6fb1bccf491..600642f5e44 100644 --- a/source/blender/imbuf/intern/cineon/logImageCore.c +++ b/source/blender/imbuf/intern/cineon/logImageCore.c @@ -177,19 +177,18 @@ unsigned int getRowLength(int width, LogImageElement logElement) return ((width * logElement.depth * 10 - 1) / 32 + 1) * 4; else if (logElement.packing == 1 || logElement.packing == 2) return ((width * logElement.depth - 1) / 3 + 1) * 4; - + break; case 12: if (logElement.packing == 0) return ((width * logElement.depth * 12 - 1) / 32 + 1) * 4; else if (logElement.packing == 1 || logElement.packing == 2) return width * logElement.depth * 2; - + break; case 16: return width * logElement.depth * 2; - default: - return 0; } + return 0; } @@ -572,20 +571,20 @@ static int logImageElementGetData(LogImageFile *logImage, LogImageElement logEle return logImageElementGetData10Packed(logImage, logElement, data); else if (logElement.packing == 1 || logElement.packing == 2) return logImageElementGetData10(logImage, logElement, data); + break; case 12: if (logElement.packing == 0) return logImageElementGetData12Packed(logImage, logElement, data); else if (logElement.packing == 1 || logElement.packing == 2) return logImageElementGetData12(logImage, logElement, data); + break; case 16: return logImageElementGetData16(logImage, logElement, data); - - default: - /* format not supported */ - return 1; } + /* format not supported */ + return 1; } static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logElement, float *data) diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 01348549bc4..863bce125c5 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -47,6 +47,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" #include "IMB_filetype.h" +#include "IMB_filter.h" #include "IMB_moviecache.h" #include "MEM_guardedalloc.h" @@ -63,6 +64,7 @@ #include "BKE_context.h" #include "BKE_image.h" #include "BKE_main.h" +#include "BKE_sequencer.h" #include "RNA_define.h" @@ -214,7 +216,7 @@ typedef struct ColormanageCacheKey { int display; /* display device name */ } ColormanageCacheKey; -typedef struct ColormnaageCacheData { +typedef struct ColormanageCacheData { int flag; /* view flags of cached buffer */ int look; /* Additional artistics transform */ float exposure; /* exposure value cached buffer is calculated with */ @@ -222,12 +224,12 @@ typedef struct ColormnaageCacheData { float dither; /* dither value cached buffer is calculated with */ CurveMapping *curve_mapping; /* curve mapping used for cached buffer */ int curve_mapping_timestamp; /* time stamp of curve mapping used for cached buffer */ -} ColormnaageCacheData; +} ColormanageCacheData; typedef struct ColormanageCache { struct MovieCache *moviecache; - ColormnaageCacheData *data; + ColormanageCacheData *data; } ColormanageCache; static struct MovieCache *colormanage_moviecache_get(const ImBuf *ibuf) @@ -238,7 +240,7 @@ static struct MovieCache *colormanage_moviecache_get(const ImBuf *ibuf) return ibuf->colormanage_cache->moviecache; } -static ColormnaageCacheData *colormanage_cachedata_get(const ImBuf *ibuf) +static ColormanageCacheData *colormanage_cachedata_get(const ImBuf *ibuf) { if (!ibuf->colormanage_cache) return NULL; @@ -281,7 +283,7 @@ static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf) return ibuf->colormanage_cache->moviecache; } -static void colormanage_cachedata_set(ImBuf *ibuf, ColormnaageCacheData *data) +static void colormanage_cachedata_set(ImBuf *ibuf, ColormanageCacheData *data) { if (!ibuf->colormanage_cache) ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache"); @@ -361,7 +363,7 @@ static unsigned char *colormanage_cache_get(ImBuf *ibuf, const ColormanageCacheV cache_ibuf = colormanage_cache_get_ibuf(ibuf, &key, cache_handle); if (cache_ibuf) { - ColormnaageCacheData *cache_data; + ColormanageCacheData *cache_data; BLI_assert(cache_ibuf->x == ibuf->x && cache_ibuf->y == ibuf->y); @@ -402,7 +404,7 @@ static void colormanage_cache_put(ImBuf *ibuf, const ColormanageCacheViewSetting { ColormanageCacheKey key; ImBuf *cache_ibuf; - ColormnaageCacheData *cache_data; + ColormanageCacheData *cache_data; int view_flag = 1 << (view_settings->view - 1); struct MovieCache *moviecache = colormanage_moviecache_ensure(ibuf); CurveMapping *curve_mapping = view_settings->curve_mapping; @@ -421,7 +423,7 @@ static void colormanage_cache_put(ImBuf *ibuf, const ColormanageCacheViewSetting cache_ibuf->flags |= IB_rect; /* store data which is needed to check whether cached buffer could be used for color managed display settings */ - cache_data = MEM_callocN(sizeof(ColormnaageCacheData), "color manage cache imbuf data"); + cache_data = MEM_callocN(sizeof(ColormanageCacheData), "color manage cache imbuf data"); cache_data->look = view_settings->look; cache_data->exposure = view_settings->exposure; cache_data->gamma = view_settings->gamma; @@ -710,7 +712,7 @@ void colormanage_cache_free(ImBuf *ibuf) } if (ibuf->colormanage_cache) { - ColormnaageCacheData *cache_data = colormanage_cachedata_get(ibuf); + ColormanageCacheData *cache_data = colormanage_cachedata_get(ibuf); struct MovieCache *moviecache = colormanage_moviecache_get(ibuf); if (cache_data) { @@ -1112,6 +1114,7 @@ void IMB_colormanagement_check_file_config(Main *bmain) for (scene = bmain->scene.first; scene; scene = scene->id.next) { ColorManagedColorspaceSettings *sequencer_colorspace_settings; + /* check scene color management settings */ colormanage_check_display_settings(&scene->display_settings, "scene", default_display); colormanage_check_view_settings(&scene->display_settings, &scene->view_settings, "scene"); @@ -1122,6 +1125,15 @@ void IMB_colormanagement_check_file_config(Main *bmain) if (sequencer_colorspace_settings->name[0] == '\0') { BLI_strncpy(sequencer_colorspace_settings->name, global_role_default_sequencer, MAX_COLORSPACE_NAME); } + + /* check sequencer strip input color space settings */ + Sequence *seq; + SEQ_BEGIN (scene->ed, seq) { + if (seq->strip) { + colormanage_check_colorspace_settings(&seq->strip->colorspace_settings, "sequencer strip"); + } + } + SEQ_END } /* ** check input color space settings ** */ @@ -1227,7 +1239,12 @@ const char *IMB_colormanagement_get_float_colorspace(ImBuf *ibuf) const char *IMB_colormanagement_get_rect_colorspace(ImBuf *ibuf) { - return ibuf->rect_colorspace->name; + if (ibuf->rect_colorspace) { + return ibuf->rect_colorspace->name; + } + else { + return IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE); + } } /*********************** Threaded display buffer transform routines *************************/ @@ -1401,7 +1418,7 @@ static void *do_display_buffer_apply_thread(void *handle_v) bool is_data = handle->is_data; if (cm_processor == NULL) { - if (display_buffer_byte) { + if (display_buffer_byte && display_buffer_byte != handle->byte_buffer) { IMB_buffer_byte_from_byte(display_buffer_byte, handle->byte_buffer, IB_PROFILE_SRGB, IB_PROFILE_SRGB, false, width, height, width, width); } @@ -1505,6 +1522,10 @@ static bool is_ibuf_rect_in_display_space(ImBuf *ibuf, const ColorManagedViewSet { const char *from_colorspace = ibuf->rect_colorspace->name; const char *to_colorspace = IMB_colormanagement_get_display_colorspace_name(view_settings, display_settings); + ColorManagedLook *look_descr = colormanage_look_get_named(view_settings->look); + if (look_descr != NULL && !STREQ(look_descr->process_space, "")) { + return false; + } if (to_colorspace && STREQ(from_colorspace, to_colorspace)) return true; @@ -1550,21 +1571,25 @@ static void colormanage_display_buffer_process(ImBuf *ibuf, unsigned char *displ typedef struct ProcessorTransformThread { ColormanageProcessor *cm_processor; - float *buffer; + unsigned char *byte_buffer; + float *float_buffer; int width; int start_line; int tot_line; int channels; bool predivide; + bool float_from_byte; } ProcessorTransformThread; typedef struct ProcessorTransformInit { ColormanageProcessor *cm_processor; - float *buffer; + unsigned char *byte_buffer; + float *float_buffer; int width; int height; int channels; bool predivide; + bool float_from_byte; } ProcessorTransformInitData; static void processor_transform_init_handle(void *handle_v, int start_line, int tot_line, void *init_data_v) @@ -1572,17 +1597,24 @@ static void processor_transform_init_handle(void *handle_v, int start_line, int ProcessorTransformThread *handle = (ProcessorTransformThread *) handle_v; ProcessorTransformInitData *init_data = (ProcessorTransformInitData *) init_data_v; - int channels = init_data->channels; - int width = init_data->width; - bool predivide = init_data->predivide; + const int channels = init_data->channels; + const int width = init_data->width; + const bool predivide = init_data->predivide; + const bool float_from_byte = init_data->float_from_byte; - size_t offset = ((size_t)channels) * start_line * width; + const size_t offset = ((size_t)channels) * start_line * width; memset(handle, 0, sizeof(ProcessorTransformThread)); handle->cm_processor = init_data->cm_processor; - handle->buffer = init_data->buffer + offset; + if (init_data->byte_buffer != NULL) { + /* TODO(serge): Offset might be different for byte and float buffers. */ + handle->byte_buffer = init_data->byte_buffer + offset; + } + if (init_data->float_buffer != NULL) { + handle->float_buffer = init_data->float_buffer + offset; + } handle->width = width; @@ -1591,33 +1623,63 @@ static void processor_transform_init_handle(void *handle_v, int start_line, int handle->channels = channels; handle->predivide = predivide; + handle->float_from_byte = float_from_byte; } static void *do_processor_transform_thread(void *handle_v) { ProcessorTransformThread *handle = (ProcessorTransformThread *) handle_v; - float *buffer = handle->buffer; - int channels = handle->channels; - int width = handle->width; - int height = handle->tot_line; - bool predivide = handle->predivide; - - IMB_colormanagement_processor_apply(handle->cm_processor, buffer, width, height, channels, predivide); + unsigned char *byte_buffer = handle->byte_buffer; + float *float_buffer = handle->float_buffer; + const int channels = handle->channels; + const int width = handle->width; + const int height = handle->tot_line; + const bool predivide = handle->predivide; + const bool float_from_byte = handle->float_from_byte; + + if (float_from_byte) { + IMB_buffer_float_from_byte(float_buffer, byte_buffer, + IB_PROFILE_SRGB, IB_PROFILE_SRGB, + false, + width, height, width, width); + IMB_colormanagement_processor_apply(handle->cm_processor, + float_buffer, + width, height, channels, + predivide); + IMB_premultiply_rect_float(float_buffer, 4, width, height); + } + else { + if (byte_buffer != NULL) { + IMB_colormanagement_processor_apply_byte(handle->cm_processor, + byte_buffer, + width, height, channels); + } + if (float_buffer != NULL) { + IMB_colormanagement_processor_apply(handle->cm_processor, + float_buffer, + width, height, channels, + predivide); + } + } return NULL; } -static void processor_transform_apply_threaded(float *buffer, int width, int height, int channels, - ColormanageProcessor *cm_processor, bool predivide) +static void processor_transform_apply_threaded(unsigned char *byte_buffer, float *float_buffer, + const int width, const int height, const int channels, + ColormanageProcessor *cm_processor, + const bool predivide, const bool float_from_byte) { ProcessorTransformInitData init_data; init_data.cm_processor = cm_processor; - init_data.buffer = buffer; + init_data.byte_buffer = byte_buffer; + init_data.float_buffer = float_buffer; init_data.width = width; init_data.height = height; init_data.channels = channels; init_data.predivide = predivide; + init_data.float_from_byte = float_from_byte; IMB_processor_apply_threaded(height, sizeof(ProcessorTransformThread), &init_data, processor_transform_init_handle, do_processor_transform_thread); @@ -1626,8 +1688,10 @@ static void processor_transform_apply_threaded(float *buffer, int width, int hei /*********************** Color space transformation functions *************************/ /* convert the whole buffer from specified by name color space to another - internal implementation */ -static void colormanagement_transform_ex(float *buffer, int width, int height, int channels, const char *from_colorspace, - const char *to_colorspace, bool predivide, bool do_threaded) +static void colormanagement_transform_ex(unsigned char *byte_buffer, float *float_buffer, + int width, int height, int channels, + const char *from_colorspace, const char *to_colorspace, + bool predivide, bool do_threaded) { ColormanageProcessor *cm_processor; @@ -1644,10 +1708,19 @@ static void colormanagement_transform_ex(float *buffer, int width, int height, i cm_processor = IMB_colormanagement_colorspace_processor_new(from_colorspace, to_colorspace); - if (do_threaded) - processor_transform_apply_threaded(buffer, width, height, channels, cm_processor, predivide); - else - IMB_colormanagement_processor_apply(cm_processor, buffer, width, height, channels, predivide); + if (do_threaded) { + processor_transform_apply_threaded(byte_buffer, float_buffer, + width, height, channels, + cm_processor, predivide, false); + } + else { + if (byte_buffer != NULL) { + IMB_colormanagement_processor_apply_byte(cm_processor, byte_buffer, width, height, channels); + } + if (float_buffer != NULL) { + IMB_colormanagement_processor_apply(cm_processor, float_buffer, width, height, channels, predivide); + } + } IMB_colormanagement_processor_free(cm_processor); } @@ -1656,7 +1729,7 @@ static void colormanagement_transform_ex(float *buffer, int width, int height, i void IMB_colormanagement_transform(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide) { - colormanagement_transform_ex(buffer, width, height, channels, from_colorspace, to_colorspace, predivide, false); + colormanagement_transform_ex(NULL, buffer, width, height, channels, from_colorspace, to_colorspace, predivide, false); } /* convert the whole buffer from specified by name color space to another @@ -1665,7 +1738,60 @@ void IMB_colormanagement_transform(float *buffer, int width, int height, int cha void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide) { - colormanagement_transform_ex(buffer, width, height, channels, from_colorspace, to_colorspace, predivide, true); + colormanagement_transform_ex(NULL, buffer, width, height, channels, from_colorspace, to_colorspace, predivide, true); +} + +/* Similar to functions above, but operates on byte buffer. */ +void IMB_colormanagement_transform_byte(unsigned char *buffer, int width, int height, int channels, + const char *from_colorspace, const char *to_colorspace) +{ + colormanagement_transform_ex(buffer, NULL, width, height, channels, from_colorspace, to_colorspace, false, false); +} +void IMB_colormanagement_transform_byte_threaded(unsigned char *buffer, int width, int height, int channels, + const char *from_colorspace, const char *to_colorspace) +{ + colormanagement_transform_ex(buffer, NULL, width, height, channels, from_colorspace, to_colorspace, false, true); +} + +/* Similar to above, but gets float buffer from display one. */ +void IMB_colormanagement_transform_from_byte(float *float_buffer, unsigned char *byte_buffer, + int width, int height, int channels, + const char *from_colorspace, const char *to_colorspace) +{ + IMB_buffer_float_from_byte(float_buffer, byte_buffer, + IB_PROFILE_SRGB, IB_PROFILE_SRGB, + true, + width, height, width, width); + IMB_colormanagement_transform(float_buffer, + width, height, channels, + from_colorspace, to_colorspace, + true); +} +void IMB_colormanagement_transform_from_byte_threaded(float *float_buffer, unsigned char *byte_buffer, + int width, int height, int channels, + const char *from_colorspace, const char *to_colorspace) +{ + ColormanageProcessor *cm_processor; + if (from_colorspace == NULL || from_colorspace[0] == '\0') { + return; + } + if (STREQ(from_colorspace, to_colorspace)) { + /* Because this function always takes a byte buffer and returns a float buffer, it must + * always do byte-to-float conversion of some kind. To avoid threading overhead + * IMB_buffer_float_from_byte is used when color spaces are identical. See T51002. + */ + IMB_buffer_float_from_byte(float_buffer, byte_buffer, + IB_PROFILE_SRGB, IB_PROFILE_SRGB, + false, + width, height, width, width); + IMB_premultiply_rect_float(float_buffer, 4, width, height); + return; + } + cm_processor = IMB_colormanagement_colorspace_processor_new(from_colorspace, to_colorspace); + processor_transform_apply_threaded(byte_buffer, float_buffer, + width, height, channels, + cm_processor, false, true); + IMB_colormanagement_processor_free(cm_processor); } void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace) @@ -1957,6 +2083,10 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, boo } } + if (colormanaged_ibuf != ibuf) { + IMB_metadata_copy(colormanaged_ibuf, ibuf); + } + return colormanaged_ibuf; } @@ -1969,12 +2099,14 @@ void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char size_t float_buffer_size = ((size_t)width) * height * channels * sizeof(float); float *display_buffer_float = MEM_mallocN(float_buffer_size, "byte_buffer_make_display_space"); + /* TODO(sergey): Convert float directly to byte buffer. */ + memcpy(display_buffer_float, buffer, float_buffer_size); cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings); - processor_transform_apply_threaded(display_buffer_float, width, height, channels, - cm_processor, true); + processor_transform_apply_threaded(NULL, display_buffer_float, width, height, channels, + cm_processor, true, false); IMB_buffer_byte_from_float(display_buffer, display_buffer_float, channels, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, @@ -2440,6 +2572,14 @@ const char *IMB_colormanagement_colorspace_get_indexed_name(int index) void IMB_colormanagment_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf) { + /* Don't modify non-color data space, it does not change with file type. */ + ColorSpace *colorspace = colormanage_colorspace_get_named(colorspace_settings->name); + + if (colorspace && colorspace->is_data) { + return; + } + + /* Get color space from file type. */ const ImFileType *type; for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { @@ -2463,9 +2603,17 @@ ColorManagedLook *colormanage_look_add(const char *name, const char *process_spa look = MEM_callocN(sizeof(ColorManagedLook), "ColorManagedLook"); look->index = index + 1; BLI_strncpy(look->name, name, sizeof(look->name)); + BLI_strncpy(look->ui_name, name, sizeof(look->ui_name)); BLI_strncpy(look->process_space, process_space, sizeof(look->process_space)); look->is_noop = is_noop; + /* Detect view specific looks. */ + const char *separator_offset = strstr(look->name, " - "); + if (separator_offset) { + BLI_strncpy(look->view, look->name, separator_offset - look->name + 1); + BLI_strncpy(look->ui_name, separator_offset + strlen(" - "), sizeof(look->ui_name)); + } + BLI_addtail(&global_looks, look); global_tot_looks++; @@ -2566,15 +2714,27 @@ void IMB_colormanagement_view_items_add(EnumPropertyItem **items, int *totitem, } } -void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem) +void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem, const char *view_name) { ColorManagedLook *look; + const char *view_filter = NULL; + + /* Test if this view transform is limited to specific looks. */ + for (look = global_looks.first; look; look = look->next) { + if (STREQ(look->view, view_name)) { + view_filter = view_name; + } + } for (look = global_looks.first; look; look = look->next) { + if (!look->is_noop && view_filter && !STREQ(look->view, view_filter)) { + continue; + } + EnumPropertyItem item; item.value = look->index; - item.name = look->name; + item.name = look->ui_name; item.identifier = look->name; item.icon = 0; item.description = ""; @@ -3095,6 +3255,25 @@ void IMB_colormanagement_processor_apply(ColormanageProcessor *cm_processor, flo } } +void IMB_colormanagement_processor_apply_byte(ColormanageProcessor *cm_processor, + unsigned char *buffer, + int width, int height, int channels) +{ + /* TODO(sergey): Would be nice to support arbitrary channels configurations, + * but for now it's not so important. + */ + BLI_assert(channels == 4); + float pixel[4]; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + size_t offset = channels * (((size_t)y) * width + x); + rgba_uchar_to_float(pixel, buffer + offset); + IMB_colormanagement_processor_apply_v4(cm_processor, pixel); + rgba_float_to_uchar(buffer + offset, pixel); + } + } +} + void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor) { if (cm_processor->curve_mapping) diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp index 12e03f55450..67a0b0ffd00 100644 --- a/source/blender/imbuf/intern/dds/dds_api.cpp +++ b/source/blender/imbuf/intern/dds/dds_api.cpp @@ -37,7 +37,7 @@ extern "C" { #include <stdio.h> // printf #include <fstream> -#if defined (WIN32) && !defined(FREE_WINDOWS) +#if defined (WIN32) #include "utfconv.h" #endif @@ -62,7 +62,7 @@ int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/) /* open file for writing */ std::ofstream fildes; -#if defined (WIN32) && !defined(FREE_WINDOWS) +#if defined (WIN32) wchar_t *wname = alloc_utf16_from_8(name, 0); fildes.open(wname); free(wname); diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c index 3d3e8a0646a..7ed5c8ffbcb 100644 --- a/source/blender/imbuf/intern/filetype.c +++ b/source/blender/imbuf/intern/filetype.c @@ -47,10 +47,6 @@ #include "dds/dds_api.h" #endif -#ifdef WITH_QUICKTIME -#include "quicktime_import.h" -#endif - static int imb_ftype_default(const ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype == type->filetype); @@ -101,10 +97,6 @@ void imb_filetypes_init(void) for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) if (type->init) type->init(); - -#ifdef WITH_QUICKTIME - quicktime_init(); -#endif } void imb_filetypes_exit(void) @@ -114,9 +106,5 @@ void imb_filetypes_exit(void) for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) if (type->exit) type->exit(); - -#ifdef WITH_QUICKTIME - quicktime_exit(); -#endif } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 1987c6d2a9a..38609d0a342 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -406,7 +406,7 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) const int height = ibuf->y; const int depth = 4; /* always 4 channels */ const int chsize = ibuf->rect_float ? sizeof(float) : sizeof(unsigned char); - const int bsize = width * height * depth * chsize; + const size_t bsize = ((size_t)width) * height * depth * chsize; const bool is_float = (ibuf->rect_float != NULL); void *dstbuf = (void *) MEM_dupallocN(ibuf->rect_float ? (void *) ibuf->rect_float : (void *) ibuf->rect); char *dstmask = mask == NULL ? NULL : (char *) MEM_dupallocN(mask); @@ -499,7 +499,9 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) /* keep the original buffer up to date. */ memcpy(srcbuf, dstbuf, bsize); - if (dstmask != NULL) memcpy(srcmask, dstmask, width * height); + if (dstmask != NULL) { + memcpy(srcmask, dstmask, ((size_t)width) * height); + } } /* free memory */ diff --git a/source/blender/imbuf/intern/imbuf.h b/source/blender/imbuf/intern/imbuf.h index 897a149a45c..90dad70fa61 100644 --- a/source/blender/imbuf/intern/imbuf.h +++ b/source/blender/imbuf/intern/imbuf.h @@ -67,8 +67,6 @@ # define BIG_LONG SWAP_LONG #endif -typedef unsigned char uchar; - #define IMB_DPI_DEFAULT 72.0f #endif /* __IMBUF_H__ */ diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 7a9fa2b9768..6c0849358a5 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -48,36 +48,24 @@ #define IMAGIC 0732 typedef struct { - unsigned short imagic; /* stuff saved on disk . . */ - unsigned short type; - unsigned short dim; - unsigned short xsize; - unsigned short ysize; - unsigned short zsize; - unsigned int min; - unsigned int max; - unsigned int wastebytes; - char name[80]; - unsigned int colormap; - - int file; /* stuff used in core only */ - unsigned short flags; - short dorev; - short x; - short y; - short z; - short cnt; - unsigned short *ptr; - unsigned short *base; - unsigned short *tmpbuf; - unsigned int offset; - unsigned int rleend; /* for rle images */ - unsigned int *rowstart; /* for rle images */ - const int *rowsize; /* for rle images */ + ushort imagic; /* stuff saved on disk . . */ + ushort type; + ushort dim; + ushort xsize; + ushort ysize; + ushort zsize; + uint min; + uint max; + uchar _pad1[4]; + char name[80]; + uint colormap; + uchar _pad2[404]; } IMAGE; #define HEADER_SIZE 512 +BLI_STATIC_ASSERT(sizeof(IMAGE) == HEADER_SIZE, "Invalid header size"); + #define RINTLUM (79) #define GINTLUM (156) #define BINTLUM (21) @@ -106,68 +94,72 @@ typedef struct { /* local struct for mem access */ typedef struct MFileOffset { const uchar *_file_data; - unsigned int _file_offset; + uint _file_offset; } MFileOffset; -#define MFILE_DATA(inf) ((void)0, (inf)->_file_data + (inf)->_file_offset) +#define MFILE_DATA(inf) ((void)0, ((inf)->_file_data + (inf)->_file_offset)) #define MFILE_STEP(inf, step) { (inf)->_file_offset += step; } ((void)0) #define MFILE_SEEK(inf, pos) { (inf)->_file_offset = pos; } ((void)0) +/* error flags */ +#define DIRTY_FLAG_EOF (1 << 0) +#define DIRTY_FLAG_ENCODING (1 << 1) + /* funcs */ static void readheader(MFileOffset *inf, IMAGE *image); static int writeheader(FILE *outf, IMAGE *image); -static unsigned short getshort(MFileOffset *inf); -static unsigned int getlong(MFileOffset *inf); -static void putshort(FILE *outf, unsigned short val); -static int putlong(FILE *outf, unsigned int val); -static int writetab(FILE *outf, unsigned int *tab, int len); -static void readtab(MFileOffset *inf, unsigned int *tab, int len); +static ushort getshort(MFileOffset *inf); +static uint getlong(MFileOffset *inf); +static void putshort(FILE *outf, ushort val); +static int putlong(FILE *outf, uint val); +static int writetab(FILE *outf, uint *tab, int len); +static void readtab(MFileOffset *inf, uint *tab, int len); -static void expandrow(unsigned char *optr, const unsigned char *iptr, int z); -static void expandrow2(float *optr, const unsigned char *iptr, int z); -static void interleaverow(unsigned char *lptr, const unsigned char *cptr, int z, int n); -static void interleaverow2(float *lptr, const unsigned char *cptr, int z, int n); -static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cnt); -static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, int n); +static int expandrow(uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z); +static int expandrow2(float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z); +static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n); +static void interleaverow2(float *lptr, const uchar *cptr, int z, int n); +static int compressrow(uchar *lbuf, uchar *rlebuf, int z, int cnt); +static void lumrow(uchar *rgbptr, uchar *lumptr, int n); /* * byte order independent read/write of shorts and ints. * */ -static unsigned short getshort(MFileOffset *inf) +static ushort getshort(MFileOffset *inf) { - const unsigned char *buf; + const uchar *buf; buf = MFILE_DATA(inf); MFILE_STEP(inf, 2); - - return (buf[0] << 8) + (buf[1] << 0); + + return ((ushort)buf[0] << 8) + ((ushort)buf[1] << 0); } -static unsigned int getlong(MFileOffset *mofs) +static uint getlong(MFileOffset *mofs) { - const unsigned char *buf; + const uchar *buf; buf = MFILE_DATA(mofs); MFILE_STEP(mofs, 4); - - return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0); + + return ((uint)buf[0] << 24) + ((uint)buf[1] << 16) + ((uint)buf[2] << 8) + ((uint)buf[3] << 0); } -static void putshort(FILE *outf, unsigned short val) +static void putshort(FILE *outf, ushort val) { - unsigned char buf[2]; + uchar buf[2]; buf[0] = (val >> 8); buf[1] = (val >> 0); fwrite(buf, 2, 1, outf); } -static int putlong(FILE *outf, unsigned int val) +static int putlong(FILE *outf, uint val) { - unsigned char buf[4]; + uchar buf[4]; buf[0] = (val >> 24); buf[1] = (val >> 16); @@ -205,7 +197,7 @@ static int writeheader(FILE *outf, IMAGE *image) return fwrite("no name", 8, 1, outf); } -static int writetab(FILE *outf, unsigned int *tab, int len) +static int writetab(FILE *outf, uint *tab, int len) { int r = 0; @@ -216,7 +208,7 @@ static int writetab(FILE *outf, unsigned int *tab, int len) return r; } -static void readtab(MFileOffset *inf, unsigned int *tab, int len) +static void readtab(MFileOffset *inf, uint *tab, int len) { while (len) { *tab++ = getlong(inf); @@ -242,12 +234,12 @@ static void test_endian_zbuf(struct ImBuf *ibuf) } /* from misc_util: flip the bytes from x */ -#define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) +#define GS(x) (((uchar *)(x))[0] << 8 | ((uchar *)(x))[1]) /* this one is only def-ed once, strangely... */ #define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0]) -int imb_is_a_iris(const unsigned char *mem) +int imb_is_a_iris(const uchar *mem) { return ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)); } @@ -259,46 +251,52 @@ int imb_is_a_iris(const unsigned char *mem) * */ -struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]) +struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]) { - unsigned int *base, *lptr = NULL; + uint *base, *lptr = NULL; float *fbase, *fptr = NULL; - unsigned int *zbase, *zptr; - const unsigned char *rledat; - unsigned int *starttab, *lengthtab; + uint *zbase, *zptr; + const uchar *rledat; + const uchar *mem_end = mem + size; MFileOffset _inf_data = {mem, 0}, *inf = &_inf_data; IMAGE image; int x, y, z, tablen; - int xsize, ysize, zsize; int bpp, rle, cur, badorder; ImBuf *ibuf; + uchar dirty_flag = 0; - (void)size; /* unused */ - - if (!imb_is_a_iris(mem)) return NULL; + if (size < HEADER_SIZE) { + return NULL; + } + + if (!imb_is_a_iris(mem)) { + return NULL; + } /* OCIO_TODO: only tested with 1 byte per pixel, not sure how to test with other settings */ colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE); - /*printf("new iris\n");*/ - readheader(inf, &image); if (image.imagic != IMAGIC) { fprintf(stderr, "longimagedata: bad magic number in image file\n"); return(NULL); } - + rle = ISRLE(image.type); bpp = BPP(image.type); if (bpp != 1 && bpp != 2) { fprintf(stderr, "longimagedata: image must have 1 or 2 byte per pix chan\n"); return(NULL); } - - xsize = image.xsize; - ysize = image.ysize; - zsize = image.zsize; - + if ((uint)image.zsize > 8) { + fprintf(stderr, "longimagedata: channels over 8 not supported\n"); + return(NULL); + } + + const int xsize = image.xsize; + const int ysize = image.ysize; + const int zsize = image.zsize; + if (flags & IB_test) { ibuf = IMB_allocImBuf(image.xsize, image.ysize, 8 * image.zsize, 0); if (ibuf) ibuf->ftype = IMB_FTYPE_IMAGIC; @@ -306,12 +304,17 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha } if (rle) { - tablen = ysize * zsize * sizeof(int); - starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab"); - lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris endtab"); MFILE_SEEK(inf, HEADER_SIZE); - + + uint *starttab = MEM_mallocN(tablen, "iris starttab"); + uint *lengthtab = MEM_mallocN(tablen, "iris endtab"); + +#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \ + if (UNLIKELY((p) > mem_end)) { dirty_flag |= DIRTY_FLAG_EOF; goto fail_rle; } ((void)0) + + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(MFILE_DATA(inf) + ((4 * 2) * tablen)); + readtab(inf, starttab, tablen); readtab(inf, lengthtab, tablen); @@ -335,7 +338,7 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize, IB_rect); if (ibuf->planes > 32) ibuf->planes = 32; base = ibuf->rect; - zbase = (unsigned int *)ibuf->zbuf; + zbase = (uint *)ibuf->zbuf; if (badorder) { for (z = 0; z < zsize; z++) { @@ -344,9 +347,11 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha MFILE_SEEK(inf, starttab[y + z * ysize]); rledat = MFILE_DATA(inf); MFILE_STEP(inf, lengthtab[y + z * ysize]); - - expandrow((uchar *)lptr, rledat, 3 - z); - lptr += xsize; + const uchar *rledat_next = MFILE_DATA(inf); + uint *lptr_next = lptr + xsize; + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next); + dirty_flag |= expandrow((uchar *)lptr, (uchar *)lptr_next, rledat, rledat_next, 3 - z); + lptr = lptr_next; } } } @@ -354,17 +359,25 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha lptr = base; zptr = zbase; for (y = 0; y < ysize; y++) { - + + uint *lptr_next = lptr + xsize; + uint *zptr_next = zptr + xsize; + for (z = 0; z < zsize; z++) { MFILE_SEEK(inf, starttab[y + z * ysize]); rledat = MFILE_DATA(inf); MFILE_STEP(inf, lengthtab[y + z * ysize]); - - if (z < 4) expandrow((uchar *)lptr, rledat, 3 - z); - else if (z < 8) expandrow((uchar *)zptr, rledat, 7 - z); + const uchar *rledat_next = MFILE_DATA(inf); + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next); + if (z < 4) { + dirty_flag |= expandrow((uchar *)lptr, (uchar *)lptr_next, rledat, rledat_next, 3 - z); + } + else if (z < 8) { + dirty_flag |= expandrow((uchar *)zptr, (uchar *)zptr_next, rledat, rledat_next, 7 - z); + } } - lptr += xsize; - zptr += xsize; + lptr = lptr_next; + zptr = zptr_next; } } @@ -383,14 +396,17 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha MFILE_SEEK(inf, starttab[y + z * ysize]); rledat = MFILE_DATA(inf); MFILE_STEP(inf, lengthtab[y + z * ysize]); - - expandrow2(fptr, rledat, 3 - z); - fptr += xsize * 4; + const uchar *rledat_next = MFILE_DATA(inf); + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next); + float *fptr_next = fptr + (xsize * 4); + dirty_flag |= expandrow2(fptr, fptr_next, rledat, rledat_next, 3 - z); + fptr = fptr_next; } } } else { fptr = fbase; + float *fptr_next = fptr + (xsize * 4); for (y = 0; y < ysize; y++) { @@ -398,27 +414,31 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha MFILE_SEEK(inf, starttab[y + z * ysize]); rledat = MFILE_DATA(inf); MFILE_STEP(inf, lengthtab[y + z * ysize]); - - expandrow2(fptr, rledat, 3 - z); - + const uchar *rledat_next = MFILE_DATA(inf); + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next); + dirty_flag |= expandrow2(fptr, fptr_next, rledat, rledat_next, 3 - z); } - fptr += xsize * 4; + fptr = fptr_next; } } } - +#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL +fail_rle: MEM_freeN(starttab); MEM_freeN(lengthtab); - } else { + +#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \ + if (UNLIKELY((p) > mem_end)) { dirty_flag |= DIRTY_FLAG_EOF; goto fail_uncompressed; } ((void)0) + if (bpp == 1) { ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize, IB_rect); if (ibuf->planes > 32) ibuf->planes = 32; base = ibuf->rect; - zbase = (unsigned int *)ibuf->zbuf; + zbase = (uint *)ibuf->zbuf; MFILE_SEEK(inf, HEADER_SIZE); rledat = MFILE_DATA(inf); @@ -427,12 +447,13 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha if (z < 4) lptr = base; else if (z < 8) lptr = zbase; - - for (y = 0; y < ysize; y++) { - interleaverow((uchar *)lptr, rledat, 3 - z, xsize); - rledat += xsize; - + for (y = 0; y < ysize; y++) { + const uchar *rledat_next = rledat + xsize; + const int z_ofs = 3 - z; + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next + z_ofs); + interleaverow((uchar *)lptr, rledat, z_ofs, xsize); + rledat = rledat_next; lptr += xsize; } } @@ -450,20 +471,23 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha for (z = 0; z < zsize; z++) { fptr = fbase; - - for (y = 0; y < ysize; y++) { - interleaverow2(fptr, rledat, 3 - z, xsize); - rledat += xsize * 2; - + for (y = 0; y < ysize; y++) { + const uchar *rledat_next = rledat + xsize * 2; + const int z_ofs = 3 - z; + MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next + z_ofs); + interleaverow2(fptr, rledat, z_ofs, xsize); + rledat = rledat_next; fptr += xsize * 4; } } } +#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL +fail_uncompressed: + (void)0; } - - + if (bpp == 1) { uchar *rect; @@ -528,6 +552,9 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha } + if (dirty_flag) { + fprintf(stderr, "longimagedata: corrupt file content (%d)\n", dirty_flag); + } ibuf->ftype = IMB_FTYPE_IMAGIC; test_endian_zbuf(ibuf); @@ -541,7 +568,7 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, cha /* static utility functions for longimagedata */ -static void interleaverow(unsigned char *lptr, const unsigned char *cptr, int z, int n) +static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n) { lptr += z; while (n--) { @@ -550,7 +577,7 @@ static void interleaverow(unsigned char *lptr, const unsigned char *cptr, int z, } } -static void interleaverow2(float *lptr, const unsigned char *cptr, int z, int n) +static void interleaverow2(float *lptr, const uchar *cptr, int z, int n) { lptr += z; while (n--) { @@ -560,19 +587,34 @@ static void interleaverow2(float *lptr, const unsigned char *cptr, int z, int n) } } -static void expandrow2(float *optr, const unsigned char *iptr, int z) +static int expandrow2( + float *optr, const float *optr_end, + const uchar *iptr, const uchar *iptr_end, int z) { - unsigned short pixel, count; + ushort pixel, count; float pixel_f; +#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \ + if (UNLIKELY(iptr_next > iptr_end)) { goto fail; } + +#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \ + if (UNLIKELY(optr_next > optr_end)) { goto fail; } + optr += z; + optr_end += z; while (1) { + const uchar *iptr_next = iptr + 2; + EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next); pixel = (iptr[0] << 8) | (iptr[1] << 0); - iptr += 2; - + iptr = iptr_next; + if (!(count = (pixel & 0x7f)) ) - return; + return false; + const float *optr_next = optr + count; + EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next); if (pixel & 0x80) { + iptr_next = iptr + (count * 2); + EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next); while (count >= 8) { optr[0 * 4] = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF; optr[1 * 4] = ((iptr[2] << 8) | (iptr[3] << 0)) / (float)0xFFFF; @@ -591,10 +633,13 @@ static void expandrow2(float *optr, const unsigned char *iptr, int z) iptr += 2; optr += 4; } + BLI_assert(iptr == iptr_next); } else { + iptr_next = iptr + 2; + EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next); pixel_f = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF; - iptr += 2; + iptr = iptr_next; while (count >= 8) { optr[0 * 4] = pixel_f; @@ -612,20 +657,45 @@ static void expandrow2(float *optr, const unsigned char *iptr, int z) *optr = pixel_f; optr += 4; } + BLI_assert(iptr == iptr_next); } + BLI_assert(optr == optr_next); } + return false; + +#undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL +#undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL +fail: + return DIRTY_FLAG_ENCODING; } -static void expandrow(unsigned char *optr, const unsigned char *iptr, int z) +static int expandrow( + uchar *optr, const uchar *optr_end, + const uchar *iptr, const uchar *iptr_end, int z) { - unsigned char pixel, count; + uchar pixel, count; + +#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \ + if (UNLIKELY(iptr_next > iptr_end)) { goto fail; } + +#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \ + if (UNLIKELY(optr_next > optr_end)) { goto fail; } optr += z; + optr_end += z; while (1) { - pixel = *iptr++; + const uchar *iptr_next = iptr + 1; + EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next); + pixel = *iptr; + iptr = iptr_next; if (!(count = (pixel & 0x7f)) ) - return; + return false; + const uchar *optr_next = optr + ((int)count * 4); + EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next); + if (pixel & 0x80) { + iptr_next = iptr + count; + EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next); while (count >= 8) { optr[0 * 4] = iptr[0]; optr[1 * 4] = iptr[1]; @@ -643,8 +713,11 @@ static void expandrow(unsigned char *optr, const unsigned char *iptr, int z) *optr = *iptr++; optr += 4; } + BLI_assert(iptr == iptr_next); } else { + iptr_next = iptr + 1; + EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next); pixel = *iptr++; while (count >= 8) { optr[0 * 4] = pixel; @@ -662,8 +735,17 @@ static void expandrow(unsigned char *optr, const unsigned char *iptr, int z) *optr = pixel; optr += 4; } + BLI_assert(iptr == iptr_next); } + BLI_assert(optr == optr_next); } + + return false; + +#undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL +#undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL +fail: + return DIRTY_FLAG_ENCODING; } /* @@ -679,14 +761,14 @@ static void expandrow(unsigned char *optr, const unsigned char *iptr, int z) * Added: zbuf write */ -static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, const char *name, int *zptr) +static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *name, int *zptr) { FILE *outf; IMAGE *image; int tablen, y, z, pos, len = 0; - unsigned int *starttab, *lengthtab; - unsigned char *rlebuf; - unsigned int *lumbuf; + uint *starttab, *lengthtab; + uchar *rlebuf; + uint *lumbuf; int rlebuflen, goodwrite; goodwrite = 1; @@ -696,14 +778,14 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons tablen = ysize * zsize * sizeof(int); image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image"); - starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab"); - lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris lengthtab"); + starttab = (uint *)MEM_mallocN(tablen, "iris starttab"); + lengthtab = (uint *)MEM_mallocN(tablen, "iris lengthtab"); rlebuflen = 1.05 * xsize + 10; - rlebuf = (unsigned char *)MEM_mallocN(rlebuflen, "iris rlebuf"); - lumbuf = (unsigned int *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf"); + rlebuf = (uchar *)MEM_mallocN(rlebuflen, "iris rlebuf"); + lumbuf = (uint *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf"); memset(image, 0, sizeof(IMAGE)); - image->imagic = IMB_FTYPE_IMAGIC; + image->imagic = IMAGIC; image->type = RLE(1); if (zsize > 1) image->dim = 3; @@ -765,7 +847,7 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons /* static utility functions for output_iris */ -static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, int n) +static void lumrow(uchar *rgbptr, uchar *lumptr, int n) { lumptr += CHANOFFSET(0); while (n--) { @@ -775,9 +857,9 @@ static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, int n) } } -static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cnt) +static int compressrow(uchar *lbuf, uchar *rlebuf, int z, int cnt) { - unsigned char *iptr, *ibufend, *sptr, *optr; + uchar *iptr, *ibufend, *sptr, *optr; short todo, cc; int count; @@ -830,7 +912,7 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn } } *optr++ = 0; - return optr - (unsigned char *)rlebuf; + return optr - (uchar *)rlebuf; } int imb_saveiris(struct ImBuf *ibuf, const char *name, int flags) diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 390f2502ee7..388c2734fe9 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -588,7 +588,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) img_fol_t img_fol; /* only needed for cinema presets */ memset(&img_fol, 0, sizeof(img_fol_t)); - if (ibuf->float_colorspace) { + if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) { /* float buffer was managed already, no need in color space conversion */ chanel_colormanage_cb = channel_colormanage_noop; } diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c index 134bbe88f15..da39967a4fe 100644 --- a/source/blender/imbuf/intern/metadata.c +++ b/source/blender/imbuf/intern/metadata.c @@ -81,7 +81,9 @@ bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, con void IMB_metadata_copy(struct ImBuf *dimb, struct ImBuf *simb) { + BLI_assert(dimb != simb); if (simb->metadata) { + IMB_metadata_free(dimb); dimb->metadata = IDP_CopyProperty(simb->metadata); } } diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 4b49076dcd6..89955711384 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -49,7 +49,7 @@ #include "IMB_imbuf.h" #ifdef DEBUG_MESSAGES -# if defined __GNUC__ || defined __sun +# if defined __GNUC__ # define PRINT(format, args ...) printf(format, ##args) # else # define PRINT(format, ...) printf(__VA_ARGS__) diff --git a/source/blender/imbuf/intern/oiio/CMakeLists.txt b/source/blender/imbuf/intern/oiio/CMakeLists.txt index c873fa3f32d..a4fb9c5aee1 100644 --- a/source/blender/imbuf/intern/oiio/CMakeLists.txt +++ b/source/blender/imbuf/intern/oiio/CMakeLists.txt @@ -49,6 +49,11 @@ if(WITH_OPENIMAGEIO) ${OPENIMAGEIO_INCLUDE_DIRS} ${BOOST_INCLUDE_DIR} ) + if(WITH_IMAGE_OPENEXR) + list(APPEND INC_SYS + ${OPENEXR_INCLUDE_DIRS} + ) + endif() add_definitions(-DWITH_OPENIMAGEIO) endif() diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp index 11bf45418d6..b123d508f99 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp +++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp @@ -31,7 +31,7 @@ #include <set> -#if defined(WIN32) && !defined(FREE_WINDOWS) +#if defined(WIN32) #include "utfconv.h" #endif @@ -213,7 +213,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac in = ImageInput::create(filename); if (!in) { std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl - << OpenImageIO::geterror() << std::endl; + << OIIO_NAMESPACE::geterror() << std::endl; return NULL; } diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 89e796fb7ee..1fa3b943524 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -69,7 +69,7 @@ #include <openexr_api.h> -#if defined (WIN32) && !defined(FREE_WINDOWS) +#if defined (WIN32) #include "utfconv.h" #endif @@ -77,7 +77,7 @@ extern "C" { // The following prevents a linking error in debug mode for MSVC using the libs in CVS -#if defined(WITH_OPENEXR) && defined(_WIN32) && defined(DEBUG) && !defined(__MINGW32__) && _MSC_VER < 1900 +#if defined(WITH_OPENEXR) && defined(_WIN32) && defined(DEBUG) && _MSC_VER < 1900 _CRTIMP void __cdecl _invalid_parameter_noinfo(void) { } @@ -180,7 +180,7 @@ public: : IStream(filename) { /* utf-8 file path support on windows */ -#if defined (WIN32) && !defined(FREE_WINDOWS) +#if defined (WIN32) wchar_t *wfilename = alloc_utf16_from_8(filename, 0); ifs.open(wfilename, std::ios_base::binary); free(wfilename); @@ -243,7 +243,7 @@ public: : OStream(filename) { /* utf-8 file path support on windows */ -#if defined (WIN32) && !defined(FREE_WINDOWS) +#if defined (WIN32) wchar_t *wfilename = alloc_utf16_from_8(filename, 0); ofs.open(wfilename, std::ios_base::binary); free(wfilename); @@ -1026,15 +1026,16 @@ void IMB_exr_set_channel(void *handle, const char *layname, const char *passname ExrChannel *echan; char name[EXR_TOT_MAXNAME + 1]; - if (layname) { + if (layname && layname[0] != '\0') { char lay[EXR_LAY_MAXNAME + 1], pass[EXR_PASS_MAXNAME + 1]; BLI_strncpy(lay, layname, EXR_LAY_MAXNAME); BLI_strncpy(pass, passname, EXR_PASS_MAXNAME); BLI_snprintf(name, sizeof(name), "%s.%s", lay, pass); } - else + else { BLI_strncpy(name, passname, EXR_TOT_MAXNAME - 1); + } echan = (ExrChannel *)BLI_findstring(&data->channels, name, offsetof(ExrChannel, name)); @@ -1043,8 +1044,9 @@ void IMB_exr_set_channel(void *handle, const char *layname, const char *passname echan->ystride = ystride; echan->rect = rect; } - else + else { printf("IMB_exr_set_channel error %s\n", name); + } } float *IMB_exr_channel_rect(void *handle, const char *layname, const char *passname, const char *viewname) @@ -1102,7 +1104,7 @@ void IMB_exr_write_channels(void *handle) if (data->channels.first) { const size_t num_pixels = ((size_t)data->width) * data->height; - half *rect_half = NULL, *current_rect_half; + half *rect_half = NULL, *current_rect_half = NULL; /* We allocate teporary storage for half pixels for all the channels at once. */ if (data->num_half_channels != 0) { diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 5192e3f2d26..dded0f7aecf 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -152,7 +152,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) compression = (int)(((float)(ibuf->foptions.quality) / 11.1111f)); compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression); - if (ibuf->float_colorspace) { + if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) { /* float buffer was managed already, no need in color space conversion */ chanel_colormanage_cb = channel_colormanage_noop; } @@ -613,11 +613,12 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors int unit_type; png_uint_32 xres, yres; - if (png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) + if (png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) { if (unit_type == PNG_RESOLUTION_METER) { ibuf->ppm[0] = xres; ibuf->ppm[1] = yres; } + } } } else { diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 71e74928e20..a21468e474c 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -340,13 +340,14 @@ static int fwritecolrs(FILE *file, int width, int channels, unsigned char *ibufs } if (((beg - j) > 1) && ((beg - j) < MINRUN)) { c2 = j + 1; - while (rgbe_scan[c2++][i] == rgbe_scan[j][i]) + while (rgbe_scan[c2++][i] == rgbe_scan[j][i]) { if (c2 == beg) { /* short run */ putc((unsigned char)(128 + beg - j), file); putc((unsigned char)(rgbe_scan[j][i]), file); j = beg; break; } + } } while (j < beg) { /* write out non-run */ if ((c2 = beg - j) > 128) c2 = 128; diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index 3360fd7548e..c4325caac91 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -301,8 +301,8 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, int destx, int desty, int origx, int origy, int srcx, int srcy, int width, int height, IMB_BlendMode mode, bool accumulate) { - unsigned int *drect = NULL, *orect, *srect = NULL, *dr, *or, *sr; - float *drectf = NULL, *orectf, *srectf = NULL, *drf, *orf, *srf; + unsigned int *drect = NULL, *orect = NULL, *srect = NULL, *dr, *or, *sr; + float *drectf = NULL, *orectf = NULL, *srectf = NULL, *drf, *orf, *srf; unsigned short *cmaskrect = curvemask, *cmr; unsigned short *dmaskrect = dmask, *dmr; unsigned short *texmaskrect = texmask, *tmr; @@ -424,6 +424,7 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, else { switch (mode) { case IMB_BLEND_MIX: + case IMB_BLEND_INTERPOLATE: func = blend_color_mix_byte; func_float = blend_color_mix_float; break; @@ -563,9 +564,15 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, mask_src[0] = src[0]; mask_src[1] = src[1]; mask_src[2] = src[2]; - mask_src[3] = divide_round_i(src[3] * mask, 65535); - func((unsigned char *)dr, (unsigned char *)or, mask_src); + if (mode == IMB_BLEND_INTERPOLATE) { + mask_src[3] = src[3]; + blend_color_interpolate_byte((unsigned char *)dr, (unsigned char *)or, mask_src, mask / 65535.0f); + } + else { + mask_src[3] = divide_round_i(src[3] * mask, 65535); + func((unsigned char *)dr, (unsigned char *)or, mask_src); + } } } } @@ -588,9 +595,15 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, mask_src[0] = src[0]; mask_src[1] = src[1]; mask_src[2] = src[2]; - mask_src[3] = divide_round_i(src[3] * mask, 65535); - func((unsigned char *)dr, (unsigned char *)or, mask_src); + if (mode == IMB_BLEND_INTERPOLATE) { + mask_src[3] = src[3]; + blend_color_interpolate_byte((unsigned char *)dr, (unsigned char *)or, mask_src, mask / 65535.0f); + } + else { + mask_src[3] = divide_round_i(src[3] * mask, 65535); + func((unsigned char *)dr, (unsigned char *)or, mask_src); + } } } } @@ -642,12 +655,16 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, mask = min_ff(mask, 65535.0); if (mask > *dmr) { - float mask_srf[4]; - *dmr = mask; - mul_v4_v4fl(mask_srf, srf, mask / 65535.0f); - func_float(drf, orf, mask_srf); + if (mode == IMB_BLEND_INTERPOLATE) { + blend_color_interpolate_float(drf, orf, srf, mask / 65535.0f); + } + else { + float mask_srf[4]; + mul_v4_v4fl(mask_srf, srf, mask / 65535.0f); + func_float(drf, orf, mask_srf); + } } } } @@ -664,11 +681,15 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, mask = min_ff(mask, 65535.0); if (srf[3] && (mask > 0.0f)) { - float mask_srf[4]; - - mul_v4_v4fl(mask_srf, srf, mask / 65535.0f); + if (mode == IMB_BLEND_INTERPOLATE) { + blend_color_interpolate_float(drf, orf, srf, mask / 65535.0f); + } + else { + float mask_srf[4]; + mul_v4_v4fl(mask_srf, srf, mask / 65535.0f); + func_float(drf, orf, mask_srf); + } - func_float(drf, orf, mask_srf); } } } diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index 4368a428186..98aa7c5353b 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -813,26 +813,51 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) } /* copy pixel data. While copying, we flip the image vertically. */ + const int channels_in_float = ibuf->channels ? ibuf->channels : 4; for (x = 0; x < ibuf->x; x++) { for (y = 0; y < ibuf->y; y++) { - from_i = 4 * (y * ibuf->x + x); + from_i = ((size_t)channels_in_float) * (y * ibuf->x + x); to_i = samplesperpixel * ((ibuf->y - y - 1) * ibuf->x + x); if (pixels16) { /* convert from float source */ float rgb[4]; - - if (ibuf->float_colorspace) { - /* float buffer was managed already, no need in color space conversion */ - copy_v3_v3(rgb, &fromf[from_i]); + + if (channels_in_float == 3 || channels_in_float == 4) { + if (ibuf->float_colorspace || + (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) + { + /* Float buffer was managed already, no need in color + * space conversion. + */ + copy_v3_v3(rgb, &fromf[from_i]); + } + else { + /* Standard linear-to-srgb conversion if float buffer + * wasn't managed. + */ + linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]); + } + if (channels_in_float == 4) { + rgb[3] = fromf[from_i + 3]; + } + else { + rgb[3] = 1.0f; + } } else { - /* standard linear-to-srgb conversion if float buffer wasn't managed */ - linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]); + if (ibuf->float_colorspace || + (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) + { + rgb[0] = fromf[from_i]; + } + else { + rgb[0] = linearrgb_to_srgb(fromf[from_i]); + } + rgb[1] = rgb[2] = rgb[0]; + rgb[3] = 1.0f; } - rgb[3] = fromf[from_i + 3]; - for (i = 0; i < samplesperpixel; i++, to_i++) to16[to_i] = FTOUSHORT(rgb[i]); } diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index ba8480b636f..76a44aa81f7 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -52,10 +52,6 @@ #include "IMB_anim.h" -#ifdef WITH_QUICKTIME -#include "quicktime_import.h" -#endif - #ifdef WITH_FFMPEG #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> @@ -107,28 +103,6 @@ const char *imb_ext_image_filepath_only[] = { NULL }; -const char *imb_ext_image_qt[] = { - ".gif", - ".psd", - ".pct", ".pict", - ".pntg", - ".qtif", - NULL -}; - -#if 0 /* UNUSED */ -const char *imb_ext_movie_qt[] = { - ".avi", - ".flc", - ".dv", - ".r3d", - ".mov", - ".movie", - ".mv", - NULL -}; -#endif - const char *imb_ext_movie[] = { ".avi", ".flc", @@ -247,13 +221,6 @@ static int isavi(const char *name) #endif } -#ifdef WITH_QUICKTIME -static int isqtime(const char *name) -{ - return anim_is_quicktime(name); -} -#endif - #ifdef WITH_FFMPEG /* BLI_vsnprintf in ffmpeg_log_callback() causes invalid warning */ @@ -383,9 +350,6 @@ int imb_get_anim_type(const char *name) if (UTIL_DEBUG) printf("%s: %s\n", __func__, name); #ifndef _WIN32 -# ifdef WITH_QUICKTIME - if (isqtime(name)) return (ANIM_QTIME); -# endif # ifdef WITH_FFMPEG /* stat test below fails on large files > 4GB */ if (isffmpeg(name)) return (ANIM_FFMPEG); @@ -401,9 +365,6 @@ int imb_get_anim_type(const char *name) if (((st.st_mode) & S_IFMT) != S_IFREG) return(0); if (ismovie(name)) return (ANIM_MOVIE); -# ifdef WITH_QUICKTIME - if (isqtime(name)) return (ANIM_QTIME); -# endif # ifdef WITH_FFMPEG if (isffmpeg(name)) return (ANIM_FFMPEG); # endif |