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 |
2 files changed, 61 insertions, 32 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 |