diff options
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 75 | ||||
-rw-r--r-- | source/blender/imbuf/intern/indexer.c | 18 | ||||
-rw-r--r-- | source/blender/imbuf/intern/jp2.c | 5 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 2 |
4 files changed, 66 insertions, 34 deletions
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 5e132826a4c..0678c224e6b 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -31,6 +31,7 @@ #include "BLI_math_color.h" #include "BLI_rect.h" #include "BLI_string.h" +#include "BLI_task.h" #include "BLI_threads.h" #include "BKE_appdir.h" @@ -2249,6 +2250,43 @@ void IMB_colormanagement_imbuf_to_byte_texture(uchar *out_buffer, } } +typedef struct ImbufByteToFloatData { + OCIO_ConstCPUProcessorRcPtr *processor; + int width; + int offset, stride; + const uchar *in_buffer; + float *out_buffer; + bool use_premultiply; +} ImbufByteToFloatData; + +static void imbuf_byte_to_float_cb(void *__restrict userdata, + const int y, + const TaskParallelTLS *__restrict UNUSED(tls)) +{ + ImbufByteToFloatData *data = userdata; + + const size_t in_offset = data->offset + y * data->stride; + const size_t out_offset = y * data->width; + const uchar *in = data->in_buffer + in_offset * 4; + float *out = data->out_buffer + out_offset * 4; + + /* Convert to scene linear, to sRGB and premultiply. */ + for (int x = 0; x < data->width; x++, in += 4, out += 4) { + float pixel[4]; + rgba_uchar_to_float(pixel, in); + if (data->processor) { + OCIO_cpuProcessorApplyRGB(data->processor, pixel); + } + else { + srgb_to_linearrgb_v3_v3(pixel, pixel); + } + if (data->use_premultiply) { + mul_v3_fl(pixel, pixel[3]); + } + copy_v4_v4(out, pixel); + } +} + void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, const int offset_x, const int offset_y, @@ -2307,34 +2345,25 @@ void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, const uchar *in_buffer = (uchar *)ibuf->rect; const bool use_premultiply = IMB_alpha_affects_rgb(ibuf) && store_premultiplied; - /* TODO(brecht): make this multi-threaded, or at least process in batches. */ OCIO_ConstCPUProcessorRcPtr *processor = (ibuf->rect_colorspace) ? colorspace_to_scene_linear_cpu_processor( ibuf->rect_colorspace) : NULL; - for (int y = 0; y < height; y++) { - const size_t in_offset = (offset_y + y) * ibuf->x + offset_x; - const size_t out_offset = y * width; - const uchar *in = in_buffer + in_offset * 4; - float *out = out_buffer + out_offset * 4; - - /* Convert to scene linear, to sRGB and premultiply. */ - for (int x = 0; x < width; x++, in += 4, out += 4) { - float pixel[4]; - rgba_uchar_to_float(pixel, in); - if (processor) { - OCIO_cpuProcessorApplyRGB(processor, pixel); - } - else { - srgb_to_linearrgb_v3_v3(pixel, pixel); - } - if (use_premultiply) { - mul_v3_fl(pixel, pixel[3]); - } - copy_v4_v4(out, pixel); - } - } + ImbufByteToFloatData data = { + .processor = processor, + .width = width, + .offset = offset_y * ibuf->x + offset_x, + .stride = ibuf->x, + .in_buffer = in_buffer, + .out_buffer = out_buffer, + .use_premultiply = use_premultiply, + }; + + TaskParallelSettings settings; + BLI_parallel_range_settings_defaults(&settings); + settings.use_threading = (height > 128); + BLI_task_parallel_range(0, height, &data, imbuf_byte_to_float_cb, &settings); } } diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 63836690ee4..d824b87f493 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -931,7 +931,7 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, return (IndexBuildContext *)context; } -static void index_rebuild_ffmpeg_finish(FFmpegIndexBuilderContext *context, int stop) +static void index_rebuild_ffmpeg_finish(FFmpegIndexBuilderContext *context, const bool stop) { int i; @@ -1012,8 +1012,8 @@ static void index_rebuild_ffmpeg_proc_decoded_frame(FFmpegIndexBuilderContext *c } static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, - const short *stop, - short *do_update, + const bool *stop, + bool *do_update, float *progress) { AVFrame *in_frame = av_frame_alloc(); @@ -1303,7 +1303,7 @@ static IndexBuildContext *index_fallback_create_context(struct anim *anim, return (IndexBuildContext *)context; } -static void index_rebuild_fallback_finish(FallbackIndexBuilderContext *context, int stop) +static void index_rebuild_fallback_finish(FallbackIndexBuilderContext *context, const bool stop) { struct anim *anim = context->anim; char filepath[FILE_MAX]; @@ -1330,8 +1330,8 @@ static void index_rebuild_fallback_finish(FallbackIndexBuilderContext *context, } static void index_rebuild_fallback(FallbackIndexBuilderContext *context, - const short *stop, - short *do_update, + const bool *stop, + bool *do_update, float *progress) { int count = IMB_anim_get_duration(context->anim, IMB_TC_NONE); @@ -1470,9 +1470,9 @@ IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim, void IMB_anim_index_rebuild(struct IndexBuildContext *context, /* NOLINTNEXTLINE: readability-non-const-parameter. */ - short *stop, + bool *stop, /* NOLINTNEXTLINE: readability-non-const-parameter. */ - short *do_update, + bool *do_update, /* NOLINTNEXTLINE: readability-non-const-parameter. */ float *progress) { @@ -1494,7 +1494,7 @@ void IMB_anim_index_rebuild(struct IndexBuildContext *context, UNUSED_VARS(stop, do_update, progress); } -void IMB_anim_index_rebuild_finish(IndexBuildContext *context, short stop) +void IMB_anim_index_rebuild_finish(IndexBuildContext *context, const bool stop) { switch (context->anim_type) { #ifdef WITH_FFMPEG diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index d2b94355f85..4320f870d64 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -125,7 +125,7 @@ struct BufInfo { static void opj_read_from_buffer_free(void *UNUSED(p_user_data)) { - /* nop */ + /* NOP. */ } static OPJ_SIZE_T opj_read_from_buffer(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) @@ -885,7 +885,10 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) memset(&cmptparm, 0, sizeof(opj_image_cmptparm_t[4])); for (i = 0; i < numcomps; i++) { cmptparm[i].prec = prec; + /* Deprecated in openjpeg 2.5. */ +#if (OPJ_VERSION_MAJOR < 2) || (OPJ_VERSION_MAJOR == 2 && OPJ_VERSION_MINOR < 5) cmptparm[i].bpp = prec; +#endif cmptparm[i].sgnd = 0; cmptparm[i].dx = subsampling_dx; cmptparm[i].dy = subsampling_dy; diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index d4a89c9e1c9..d2bdb5041c5 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -811,7 +811,7 @@ static void imb_exr_get_views(MultiPartInputFile &file, StringVector &views) } } -/* Multilayer Blender files have the view name in all the passes (even the default view one) */ +/* Multi-layer Blender files have the view name in all the passes (even the default view one). */ static void imb_exr_insert_view_name(char *name_full, const char *passname, const char *viewname) { BLI_assert(!ELEM(name_full, passname, viewname)); |