Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_imbuf.h13
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h2
-rw-r--r--source/blender/imbuf/IMB_thumbs.h2
-rw-r--r--source/blender/imbuf/intern/allocimbuf.c2
-rw-r--r--source/blender/imbuf/intern/anim_movie.c23
-rw-r--r--source/blender/imbuf/intern/bmp.c2
-rw-r--r--source/blender/imbuf/intern/cache.c2
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.c2
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.c2
-rw-r--r--source/blender/imbuf/intern/colormanagement.c77
-rw-r--r--source/blender/imbuf/intern/dds/ColorBlock.h4
-rw-r--r--source/blender/imbuf/intern/dds/DirectDrawSurface.cpp22
-rw-r--r--source/blender/imbuf/intern/imageprocess.c2
-rw-r--r--source/blender/imbuf/intern/indexer.c49
-rw-r--r--source/blender/imbuf/intern/iris.c2
-rw-r--r--source/blender/imbuf/intern/jp2.c29
-rw-r--r--source/blender/imbuf/intern/jpeg.c2
-rw-r--r--source/blender/imbuf/intern/oiio/openimageio_api.cpp2
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp88
-rw-r--r--source/blender/imbuf/intern/png.c2
-rw-r--r--source/blender/imbuf/intern/rectop.c4
-rw-r--r--source/blender/imbuf/intern/scaling.c10
-rw-r--r--source/blender/imbuf/intern/thumbs_font.c81
-rw-r--r--source/blender/imbuf/intern/tiff.c4
-rw-r--r--source/blender/imbuf/intern/transform.cc19
-rw-r--r--source/blender/imbuf/intern/util_gpu.c27
-rw-r--r--source/blender/imbuf/intern/webp.c2
27 files changed, 249 insertions, 227 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 7e652e31506..a05bc51fcea 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -358,14 +358,14 @@ struct IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
* Will rebuild all used indices and proxies at once.
*/
void IMB_anim_index_rebuild(struct IndexBuildContext *context,
- short *stop,
- short *do_update,
+ bool *stop,
+ bool *do_update,
float *progress);
/**
* Finish rebuilding proxies/time-codes and free temporary contexts used.
*/
-void IMB_anim_index_rebuild_finish(struct IndexBuildContext *context, short stop);
+void IMB_anim_index_rebuild_finish(struct IndexBuildContext *context, bool stop);
/**
* Return the length (in frames) of the given \a anim.
@@ -895,6 +895,13 @@ eGPUTextureFormat IMB_gpu_get_texture_format(const struct ImBuf *ibuf,
bool use_grayscale);
/**
+ * Ensures that values stored in the float rect can safely loaded into half float gpu textures.
+ *
+ * Does nothing when given image_buffer doesn't contain a float rect.
+ */
+void IMB_gpu_clamp_half_float(struct ImBuf *image_buffer);
+
+/**
* The `ibuf` is only here to detect the storage type. The produced texture will have undefined
* content. It will need to be populated by using #IMB_update_gpu_texture_sub().
*/
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 03bb11d0cf6..81e9420c8ba 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -125,7 +125,7 @@ enum eImbFileType {
typedef struct ImbFormatOptions {
short flag;
- /** quality serves dual purpose as quality number for jpeg or compression amount for png */
+ /** Quality serves dual purpose as quality number for JPEG or compression amount for PNG. */
char quality;
} ImbFormatOptions;
diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h
index b55a6f653b8..ac287856fa9 100644
--- a/source/blender/imbuf/IMB_thumbs.h
+++ b/source/blender/imbuf/IMB_thumbs.h
@@ -87,8 +87,6 @@ struct ImBuf *IMB_thumb_load_blend(const char *blen_path,
*/
struct ImBuf *IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y);
bool IMB_thumb_load_font_get_hash(char *r_hash);
-void IMB_thumb_clear_translations(void);
-void IMB_thumb_ensure_translations(void);
/* Threading */
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index 42b587c3c81..2860944e948 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -402,7 +402,7 @@ bool imb_addrectImBuf(ImBuf *ibuf)
ibuf->mall |= IB_rect;
ibuf->flags |= IB_rect;
if (ibuf->planes > 32) {
- return (addzbufImBuf(ibuf));
+ return addzbufImBuf(ibuf);
}
return true;
diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 4e6a52f8464..94c0555dcf0 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -131,7 +131,7 @@ static int an_stringdec(const char *string, char *head, char *tail, ushort *numl
strcpy(head, string);
head[nums] = '\0';
*numlen = nume - nums + 1;
- return ((int)atoi(&(string[nums])));
+ return (int)atoi(&(string[nums]));
}
tail[0] = '\0';
strcpy(head, string);
@@ -1093,12 +1093,19 @@ static int ffmpeg_seek_by_byte(AVFormatContext *pFormatCtx)
static int64_t ffmpeg_get_seek_pts(struct anim *anim, int64_t pts_to_search)
{
- /* Step back half a frame position to make sure that we get the requested
- * frame and not the one after it. This is a workaround as ffmpeg will
- * sometimes not seek to a frame after the requested pts even if
- * AVSEEK_FLAG_BACKWARD is specified.
+ /* FFmpeg seeks internally using DTS values instead of PTS. In some files DTS and PTS values are
+ * offset and sometimes ffmpeg fails to take this into account when seeking.
+ * Therefore we need to seek backwards a certain offset to make sure the frame we want is in
+ * front of us. It is not possible to determine the exact needed offset, this value is determined
+ * experimentally. Note: Too big offset can impact performance. Current 3 frame offset has no
+ * measurable impact.
*/
- return pts_to_search - (ffmpeg_steps_per_frame_get(anim) / 2);
+ int64_t seek_pts = pts_to_search - (ffmpeg_steps_per_frame_get(anim) * 3);
+
+ if (seek_pts < 0) {
+ seek_pts = 0;
+ }
+ return seek_pts;
}
/* This gives us an estimate of which pts our requested frame will have.
@@ -1406,6 +1413,10 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
ffmpeg_decode_video_frame_scan(anim, pts_to_search);
+ /* Update resolution as it can change per-frame with WebM. See T100741 & T100081. */
+ anim->x = anim->pCodecCtx->width;
+ anim->y = anim->pCodecCtx->height;
+
IMB_freeImBuf(anim->cur_frame_final);
/* Certain versions of FFmpeg have a bug in libswscale which ends up in crash
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index af9b62f1a74..495ec286de3 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -135,7 +135,7 @@ ImBuf *imb_bmp_decode(const uchar *mem, size_t size, int flags, char colorspace[
}
/* Validate and cross-check offsets and sizes. */
- if (x < 1 || !(ELEM(depth, 1, 4, 8, 16, 24, 32))) {
+ if (x < 1 || !ELEM(depth, 1, 4, 8, 16, 24, 32)) {
return NULL;
}
diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c
index 4e1563c62ab..98d33ac061f 100644
--- a/source/blender/imbuf/intern/cache.c
+++ b/source/blender/imbuf/intern/cache.c
@@ -167,7 +167,7 @@ void imb_tile_cache_tile_free(ImBuf *ibuf, int tx, int ty)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Init/Exit
+/** \name Initialize/Exit
* \{ */
static void imb_thread_cache_init(ImThreadTileCache *cache)
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c
index 494bf37cfe7..be8fab26301 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.c
+++ b/source/blender/imbuf/intern/cineon/dpxlib.c
@@ -4,7 +4,7 @@
/** \file
* \ingroup imbcineon
*
- * Dpx image file format library routines.
+ * DPX image file format library routines.
*/
#include "dpxlib.h"
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.c b/source/blender/imbuf/intern/cineon/logImageCore.c
index 8188d0d04b9..9ec48447884 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.c
+++ b/source/blender/imbuf/intern/cineon/logImageCore.c
@@ -365,7 +365,7 @@ static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement,
for (size_t y = 0; y < logImage->height; y++) {
for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = swap_ushort(
- ((ushort)float_uint(data[y * logImage->width * logImage->depth + x], 4095)) << 4,
+ (ushort)float_uint(data[y * logImage->width * logImage->depth + x], 4095) << 4,
logImage->isMSB);
}
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index ea5f4ec275d..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"
@@ -668,7 +669,7 @@ void colormanagement_init(void)
configdir = BKE_appdir_folder_id(BLENDER_DATAFILES, "colormanagement");
if (configdir) {
- BLI_join_dirfile(configfile, sizeof(configfile), configdir, BCM_CONFIG_FILE);
+ BLI_path_join(configfile, sizeof(configfile), configdir, BCM_CONFIG_FILE);
#ifdef WIN32
{
@@ -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/dds/ColorBlock.h b/source/blender/imbuf/intern/dds/ColorBlock.h
index 144babf5d92..679028b16d3 100644
--- a/source/blender/imbuf/intern/dds/ColorBlock.h
+++ b/source/blender/imbuf/intern/dds/ColorBlock.h
@@ -21,9 +21,9 @@
/** Uncompressed 4x4 color block. */
struct ColorBlock {
ColorBlock() = default;
- /** Init the color block from an array of colors. */
+ /** Initialize the color block from an array of colors. */
ColorBlock(const uint *linearImage);
- /** Init the color block with the contents of the given block. */
+ /** Initialize the color block with the contents of the given block. */
ColorBlock(const ColorBlock &block);
/** Initialize this color block. */
ColorBlock(const Image *img, uint x, uint y);
diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
index 4e5dc9ce560..272014ea5eb 100644
--- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
+++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
@@ -872,8 +872,8 @@ DirectDrawSurface::DirectDrawSurface(uchar *mem, uint size) : stream(mem, size),
mem_read(stream, header);
/* Some ATI2 compressed normal maps do not have their
- * normal flag set, so force it here (the original nvtt don't do
- * this, but the decompressor has a -forcenormal flag). */
+ * normal flag set, so force it here (the original `nvtt` don't do
+ * this, but the decompressor has a `-forcenormal` flag). */
if (header.pf.fourcc == FOURCC_ATI2) {
header.setNormalFlag(true);
}
@@ -942,7 +942,7 @@ bool DirectDrawSurface::isSupported() const
if (isTextureCube() &&
(header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES) {
- /* Cubemaps must contain all faces. */
+ /* Cube-maps must contain all faces. */
return false;
}
@@ -1464,19 +1464,19 @@ void DirectDrawSurface::printInfo() const
if (header.pf.fourcc != 0) {
/* Display fourcc code even when DDPF_FOURCC flag not set. */
printf("\tFourCC: '%c%c%c%c' (0x%.8X)\n",
- (int)((header.pf.fourcc >> 0) & 0xFF),
- (int)((header.pf.fourcc >> 8) & 0xFF),
- (int)((header.pf.fourcc >> 16) & 0xFF),
- (int)((header.pf.fourcc >> 24) & 0xFF),
+ int((header.pf.fourcc >> 0) & 0xFF),
+ int((header.pf.fourcc >> 8) & 0xFF),
+ int((header.pf.fourcc >> 16) & 0xFF),
+ int((header.pf.fourcc >> 24) & 0xFF),
header.pf.fourcc);
}
if ((header.pf.flags & DDPF_FOURCC) && (header.pf.bitcount != 0)) {
printf("\tSwizzle: '%c%c%c%c' (0x%.8X)\n",
- (int)(header.pf.bitcount >> 0) & 0xFF,
- (int)(header.pf.bitcount >> 8) & 0xFF,
- (int)(header.pf.bitcount >> 16) & 0xFF,
- (int)(header.pf.bitcount >> 24) & 0xFF,
+ int(header.pf.bitcount >> 0) & 0xFF,
+ int(header.pf.bitcount >> 8) & 0xFF,
+ int(header.pf.bitcount >> 16) & 0xFF,
+ int(header.pf.bitcount >> 24) & 0xFF,
header.pf.bitcount);
}
else {
diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c
index 4530959e5ac..f4775fa5fe8 100644
--- a/source/blender/imbuf/intern/imageprocess.c
+++ b/source/blender/imbuf/intern/imageprocess.c
@@ -219,7 +219,7 @@ void bilinear_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int x
return;
}
- /* gcc warns these could be uninitialized, but its ok. */
+ /* GCC warns these could be uninitialized, but its ok. */
pixel_from_buffer(out, &outI, &outF, xout, yout);
bilinear_interpolation_color(in, outI, outF, u, v);
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index 00396c01d99..d824b87f493 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -215,7 +215,7 @@ struct anim_index *IMB_indexer_open(const char *name)
return NULL;
}
- if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) {
+ if ((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V')) {
for (i = 0; i < idx->num_entries; i++) {
BLI_endian_switch_int32(&idx->entries[i].frameno);
BLI_endian_switch_uint64(&idx->entries[i].seek_pos);
@@ -377,9 +377,9 @@ static void get_index_dir(struct anim *anim, char *index_dir, size_t index_dir_l
{
if (!anim->index_dir[0]) {
char filename[FILE_MAXFILE];
- BLI_split_dirfile(anim->name, index_dir, filename, index_dir_len, sizeof(filename));
- BLI_path_append(index_dir, index_dir_len, "BL_proxy");
- BLI_path_append(index_dir, index_dir_len, filename);
+ char dirname[FILE_MAXDIR];
+ BLI_split_dirfile(anim->name, dirname, filename, index_dir_len, sizeof(filename));
+ BLI_path_join(index_dir, index_dir_len, dirname, "BL_proxy", filename);
}
else {
BLI_strncpy(index_dir, anim->index_dir, index_dir_len);
@@ -426,7 +426,7 @@ static bool get_proxy_filepath(struct anim *anim,
return false;
}
- BLI_join_dirfile(filepath, FILE_MAXFILE + FILE_MAXDIR, index_dir, proxy_name);
+ BLI_path_join(filepath, FILE_MAXFILE + FILE_MAXDIR, index_dir, proxy_name);
return true;
}
@@ -457,7 +457,7 @@ static void get_tc_filename(struct anim *anim, IMB_Timecode_Type tc, char *filep
get_index_dir(anim, index_dir, sizeof(index_dir));
- BLI_join_dirfile(filepath, FILE_MAXFILE + FILE_MAXDIR, index_dir, index_name);
+ BLI_path_join(filepath, FILE_MAXFILE + FILE_MAXDIR, index_dir, index_name);
}
/* ----------------------------------------------------------------------
@@ -498,7 +498,9 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
rv->anim = anim;
get_proxy_filepath(rv->anim, rv->proxy_size, filepath, true);
- BLI_make_existing_file(filepath);
+ if (!BLI_make_existing_file(filepath)) {
+ return NULL;
+ }
rv->of = avformat_alloc_context();
rv->of->oformat = av_guess_format("avi", NULL, NULL);
@@ -905,6 +907,14 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
}
}
+ if (context->proxy_ctx[0] == NULL && context->proxy_ctx[1] == NULL &&
+ context->proxy_ctx[2] == NULL && context->proxy_ctx[3] == NULL) {
+ avformat_close_input(&context->iFormatCtx);
+ avcodec_free_context(&context->iCodecCtx);
+ MEM_freeN(context);
+ return NULL; /* Nothing to transcode. */
+ }
+
for (i = 0; i < num_indexers; i++) {
if (tcs_in_use & tc_types[i]) {
char filepath[FILE_MAX];
@@ -921,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;
@@ -1002,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();
@@ -1012,12 +1022,13 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
stream_size = avio_size(context->iFormatCtx->pb);
- context->frame_rate = av_q2d(context->iStream->r_frame_rate);
+ context->frame_rate = av_q2d(av_guess_frame_rate(context->iFormatCtx, context->iStream, NULL));
context->pts_time_base = av_q2d(context->iStream->time_base);
while (av_read_frame(context->iFormatCtx, next_packet) >= 0) {
- float next_progress =
- (float)((int)floor(((double)next_packet->pos) * 100 / ((double)stream_size) + 0.5)) / 100;
+ float next_progress = (float)(int)floor(
+ ((double)next_packet->pos) * 100 / ((double)stream_size) + 0.5) /
+ 100;
if (*progress != next_progress) {
*progress = next_progress;
@@ -1292,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];
@@ -1319,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);
@@ -1459,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)
{
@@ -1483,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/iris.c b/source/blender/imbuf/intern/iris.c
index a8150fd1648..29dfcc1b8f8 100644
--- a/source/blender/imbuf/intern/iris.c
+++ b/source/blender/imbuf/intern/iris.c
@@ -88,7 +88,7 @@ typedef struct MFileOffset {
#define DIRTY_FLAG_EOF (1 << 0)
#define DIRTY_FLAG_ENCODING (1 << 1)
-/* funcs */
+/* Functions. */
static void readheader(MFileOffset *inf, IMAGE *image);
static int writeheader(FILE *outf, IMAGE *image);
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
index f57d4382672..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)
@@ -746,17 +746,17 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,
for (i = 0; i < parameters->tcp_numlayers; i++) {
temp_rate = 0;
if (img_fol->rates[i] == 0) {
- parameters->tcp_rates[0] = ((float)(image->numcomps * image->comps[0].w *
- image->comps[0].h * image->comps[0].prec)) /
+ parameters->tcp_rates[0] = (float)(image->numcomps * image->comps[0].w *
+ image->comps[0].h * image->comps[0].prec) /
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}
else {
- temp_rate = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h *
- image->comps[0].prec)) /
+ temp_rate = (float)(image->numcomps * image->comps[0].w * image->comps[0].h *
+ image->comps[0].prec) /
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_24_CS) {
- parameters->tcp_rates[i] = ((float)(image->numcomps * image->comps[0].w *
- image->comps[0].h * image->comps[0].prec)) /
+ parameters->tcp_rates[i] = (float)(image->numcomps * image->comps[0].w *
+ image->comps[0].h * image->comps[0].prec) /
(CINEMA_24_CS * 8 * image->comps[0].dx *
image->comps[0].dy);
}
@@ -772,17 +772,17 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,
for (i = 0; i < parameters->tcp_numlayers; i++) {
temp_rate = 0;
if (img_fol->rates[i] == 0) {
- parameters->tcp_rates[0] = ((float)(image->numcomps * image->comps[0].w *
- image->comps[0].h * image->comps[0].prec)) /
+ parameters->tcp_rates[0] = (float)(image->numcomps * image->comps[0].w *
+ image->comps[0].h * image->comps[0].prec) /
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}
else {
- temp_rate = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h *
- image->comps[0].prec)) /
+ temp_rate = (float)(image->numcomps * image->comps[0].w * image->comps[0].h *
+ image->comps[0].prec) /
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_48_CS) {
- parameters->tcp_rates[0] = ((float)(image->numcomps * image->comps[0].w *
- image->comps[0].h * image->comps[0].prec)) /
+ parameters->tcp_rates[0] = (float)(image->numcomps * image->comps[0].w *
+ image->comps[0].h * image->comps[0].prec) /
(CINEMA_48_CS * 8 * image->comps[0].dx *
image->comps[0].dy);
}
@@ -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/jpeg.c b/source/blender/imbuf/intern/jpeg.c
index e03765fea92..e2d49cad374 100644
--- a/source/blender/imbuf/intern/jpeg.c
+++ b/source/blender/imbuf/intern/jpeg.c
@@ -209,7 +209,7 @@ static void memory_source(j_decompress_ptr cinfo, const uchar *buffer, size_t si
*/
#define INPUT_2BYTES(cinfo, V, action) \
MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); bytes_in_buffer--; \
- V = ((uint)GETJOCTET(*next_input_byte++)) << 8; \
+ V = (uint)GETJOCTET(*next_input_byte++) << 8; \
MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \
V += GETJOCTET(*next_input_byte++);)
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
index 5c7b7d9fae4..f8d00b5222f 100644
--- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -193,7 +193,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
}
ImageSpec spec, config;
- config.attribute("oiio:UnassociatedAlpha", (int)1);
+ config.attribute("oiio:UnassociatedAlpha", int(1));
if (!in->open(filename, spec, config)) {
std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index b4ccdfab9a5..d2bdb5041c5 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -73,15 +73,6 @@
#include "MEM_guardedalloc.h"
-extern "C" {
-
-/* The following prevents a linking error in debug mode for MSVC using the libs in SVN. */
-#if defined(WITH_OPENEXR) && defined(_WIN32) && defined(DEBUG) && _MSC_VER < 1900
-_CRTIMP void __cdecl _invalid_parameter_noinfo(void)
-{
-}
-#endif
-}
#include "BLI_blenlib.h"
#include "BLI_fileops.h"
#include "BLI_math_color.h"
@@ -465,7 +456,7 @@ static void openexr_header_metadata(Header *header, struct ImBuf *ibuf)
static void openexr_header_metadata_callback(void *data,
const char *propname,
char *prop,
- int UNUSED(len))
+ int /*len*/)
{
Header *header = (Header *)data;
header->insert(propname, StringAttribute(prop));
@@ -552,10 +543,10 @@ static bool imb_save_openexr_half(ImBuf *ibuf, const char *name, const int flags
from = (uchar *)ibuf->rect + 4 * i * width;
for (int j = ibuf->x; j > 0; j--) {
- to->r = srgb_to_linearrgb((float)from[0] / 255.0f);
- to->g = srgb_to_linearrgb((float)from[1] / 255.0f);
- to->b = srgb_to_linearrgb((float)from[2] / 255.0f);
- to->a = channels >= 4 ? (float)from[3] / 255.0f : 1.0f;
+ to->r = srgb_to_linearrgb(float(from[0]) / 255.0f);
+ to->g = srgb_to_linearrgb(float(from[1]) / 255.0f);
+ to->b = srgb_to_linearrgb(float(from[2]) / 255.0f);
+ to->a = channels >= 4 ? float(from[3]) / 255.0f : 1.0f;
to++;
from += 4;
}
@@ -708,7 +699,8 @@ struct ExrHandle {
ListBase channels; /* flattened out, ExrChannel */
ListBase layers; /* hierarchical, pointing in end to ExrChannel */
- int num_half_channels; /* used during filr save, allows faster temporary buffers allocation */
+ /** Used during file save, allows faster temporary buffers allocation. */
+ int num_half_channels;
};
/* flattened out channel */
@@ -819,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));
@@ -837,7 +829,7 @@ static void imb_exr_insert_view_name(char *name_full, const char *passname, cons
len = BLI_str_rpartition(passname, delims, &sep, &token);
if (sep) {
- BLI_snprintf(name_full, EXR_PASS_MAXNAME, "%.*s.%s.%s", (int)len, passname, viewname, token);
+ BLI_snprintf(name_full, EXR_PASS_MAXNAME, "%.*s.%s.%s", int(len), passname, viewname, token);
}
else {
BLI_snprintf(name_full, EXR_PASS_MAXNAME, "%s.%s", passname, viewname);
@@ -1170,7 +1162,7 @@ void IMB_exr_write_channels(void *handle)
ExrChannel *echan;
if (data->channels.first) {
- const size_t num_pixels = ((size_t)data->width) * data->height;
+ const size_t num_pixels = size_t(data->width) * data->height;
half *rect_half = nullptr, *current_rect_half = nullptr;
/* We allocate temporary storage for half pixels for all the channels at once. */
@@ -1441,7 +1433,7 @@ void IMB_exr_close(void *handle)
/* ********* */
-/* get a substring from the end of the name, separated by '.' */
+/** Get a sub-string from the end of the name, separated by '.'. */
static int imb_exr_split_token(const char *str, const char *end, const char **token)
{
const char delims[] = {'.', '\0'};
@@ -1453,7 +1445,7 @@ static int imb_exr_split_token(const char *str, const char *end, const char **to
*token = str;
}
- return (int)(end - *token);
+ return int(end - *token);
}
static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *passname)
@@ -1462,7 +1454,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
const char *end = name + strlen(name);
const char *token;
- /* some multilayers have the combined buffer with names A B G R saved */
+ /* Some multi-layers have the combined buffer with names A B G R saved. */
if (name[1] == 0) {
echan->chan_id = BLI_toupper_ascii(name[0]);
layname[0] = '\0';
@@ -1497,7 +1489,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
bool ok = false;
if (len == 2) {
- /* some multilayers are using two-letter channels name,
+ /* Some multi-layers are using two-letter channels name,
* like, MX or NZ, which is basically has structure of
* <pass_prefix><component>
*
@@ -1550,7 +1542,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
/* all preceding tokens combined as layer name */
if (end > name) {
- BLI_strncpy(layname, name, (int)(end - name) + 1);
+ BLI_strncpy(layname, name, int(end - name) + 1);
}
else {
layname[0] = '\0';
@@ -1669,29 +1661,29 @@ static bool imb_exr_multilayer_parse_channels_from_file(ExrHandle *data)
if (ELEM(pass->totchan, 3, 4)) {
if (pass->chan[0]->chan_id == 'B' || pass->chan[1]->chan_id == 'B' ||
pass->chan[2]->chan_id == 'B') {
- lookup[(uint)'R'] = 0;
- lookup[(uint)'G'] = 1;
- lookup[(uint)'B'] = 2;
- lookup[(uint)'A'] = 3;
+ lookup[uint('R')] = 0;
+ lookup[uint('G')] = 1;
+ lookup[uint('B')] = 2;
+ lookup[uint('A')] = 3;
}
else if (pass->chan[0]->chan_id == 'Y' || pass->chan[1]->chan_id == 'Y' ||
pass->chan[2]->chan_id == 'Y') {
- lookup[(uint)'X'] = 0;
- lookup[(uint)'Y'] = 1;
- lookup[(uint)'Z'] = 2;
- lookup[(uint)'W'] = 3;
+ lookup[uint('X')] = 0;
+ lookup[uint('Y')] = 1;
+ lookup[uint('Z')] = 2;
+ lookup[uint('W')] = 3;
}
else {
- lookup[(uint)'U'] = 0;
- lookup[(uint)'V'] = 1;
- lookup[(uint)'A'] = 2;
+ lookup[uint('U')] = 0;
+ lookup[uint('V')] = 1;
+ lookup[uint('A')] = 2;
}
for (int a = 0; a < pass->totchan; a++) {
echan = pass->chan[a];
- echan->rect = pass->rect + lookup[(uint)echan->chan_id];
+ echan->rect = pass->rect + lookup[uint(echan->chan_id)];
echan->xstride = pass->totchan;
echan->ystride = data->width * pass->totchan;
- pass->chan_id[(uint)lookup[(uint)echan->chan_id]] = echan->chan_id;
+ pass->chan_id[uint(lookup[uint(echan->chan_id)])] = echan->chan_id;
}
}
else { /* unknown */
@@ -1867,7 +1859,7 @@ static bool imb_exr_is_multilayer_file(MultiPartInputFile &file)
* channels without a layer name will be single layer. */
channels.layers(layerNames);
- return (!layerNames.empty());
+ return !layerNames.empty();
}
static void imb_exr_type_by_channels(ChannelList &channels,
@@ -2014,8 +2006,8 @@ struct ImBuf *imb_load_openexr(const uchar *mem,
if (hasXDensity(file->header(0))) {
/* Convert inches to meters. */
- ibuf->ppm[0] = (double)xDensity(file->header(0)) / 0.0254;
- ibuf->ppm[1] = ibuf->ppm[0] * (double)file->header(0).pixelAspectRatio();
+ ibuf->ppm[0] = double(xDensity(file->header(0))) / 0.0254;
+ ibuf->ppm[1] = ibuf->ppm[0] * double(file->header(0).pixelAspectRatio());
}
ibuf->ftype = IMB_FTYPE_OPENEXR;
@@ -2114,7 +2106,7 @@ struct ImBuf *imb_load_openexr(const uchar *mem,
#endif
if (num_rgb_channels == 0 && has_luma && exr_has_chroma(*file)) {
- for (size_t a = 0; a < (size_t)ibuf->x * ibuf->y; a++) {
+ for (size_t a = 0; a < size_t(ibuf->x) * ibuf->y; a++) {
float *color = ibuf->rect_float + a * 4;
ycc_to_rgb(color[0] * 255.0f,
color[1] * 255.0f,
@@ -2127,7 +2119,7 @@ struct ImBuf *imb_load_openexr(const uchar *mem,
}
else if (num_rgb_channels <= 1) {
/* Convert 1 to 3 channels. */
- for (size_t a = 0; a < (size_t)ibuf->x * ibuf->y; a++) {
+ for (size_t a = 0; a < size_t(ibuf->x) * ibuf->y; a++) {
float *color = ibuf->rect_float + a * 4;
if (num_rgb_channels <= 1) {
color[1] = color[0];
@@ -2167,7 +2159,7 @@ struct ImBuf *imb_load_openexr(const uchar *mem,
}
struct ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath,
- const int UNUSED(flags),
+ const int /*flags*/,
const size_t max_thumb_size,
char colorspace[],
size_t *r_width,
@@ -2221,10 +2213,10 @@ struct ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath,
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
}
- float scale_factor = MIN2((float)max_thumb_size / (float)source_w,
- (float)max_thumb_size / (float)source_h);
- int dest_w = (int)(source_w * scale_factor);
- int dest_h = (int)(source_h * scale_factor);
+ float scale_factor = MIN2(float(max_thumb_size) / float(source_w),
+ float(max_thumb_size) / float(source_h));
+ int dest_w = int(source_w * scale_factor);
+ int dest_h = int(source_h * scale_factor);
struct ImBuf *ibuf = IMB_allocImBuf(dest_w, dest_h, 32, IB_rectfloat);
@@ -2235,13 +2227,13 @@ struct ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath,
for (int h = 0; h < dest_h; h++) {
/* Load the single source row that corresponds with destination row. */
- int source_y = (int)((float)h / scale_factor) + dw.min.y;
+ int source_y = int(float(h) / scale_factor) + dw.min.y;
file->setFrameBuffer(&pixels[0] - dw.min.x - source_y * source_w, 1, source_w);
file->readPixels(source_y);
for (int w = 0; w < dest_w; w++) {
/* For each destination pixel find single corresponding source pixel. */
- int source_x = (int)(MIN2((w / scale_factor), dw.max.x - 1));
+ int source_x = int(MIN2((w / scale_factor), dw.max.x - 1));
float *dest_px = &ibuf->rect_float[(h * dest_w + w) * 4];
dest_px[0] = pixels[source_x].r;
dest_px[1] = pixels[source_x].g;
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index df6959ca90b..1736329cbff 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -129,7 +129,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags)
/* use the jpeg quality setting for compression */
int compression;
- compression = (int)(((float)(ibuf->foptions.quality) / 11.1111f));
+ compression = (int)((float)(ibuf->foptions.quality) / 11.1111f);
compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression);
if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c
index 4159aa851c4..81fdac40ee6 100644
--- a/source/blender/imbuf/intern/rectop.c
+++ b/source/blender/imbuf/intern/rectop.c
@@ -810,7 +810,7 @@ void IMB_rectblend(ImBuf *dbuf,
else {
for (x = width; x > 0; x--, dr++, or ++, sr++, cmr++) {
uchar *src = (uchar *)sr;
- float mask = (float)mask_max * ((float)(*cmr));
+ float mask = (float)mask_max * (float)(*cmr);
if (texmaskrect) {
mask *= ((float)(*tmr++) / 65535.0f);
@@ -908,7 +908,7 @@ void IMB_rectblend(ImBuf *dbuf,
/* no destination mask buffer, do regular blend with masktexture if present */
else {
for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, cmr++) {
- float mask = (float)mask_max * ((float)(*cmr));
+ float mask = (float)mask_max * (float)(*cmr);
if (texmaskrect) {
mask *= ((float)(*tmr++) / 65535.0f);
diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c
index 05bee77a6cb..42c19ce1a7e 100644
--- a/source/blender/imbuf/intern/scaling.c
+++ b/source/blender/imbuf/intern/scaling.c
@@ -91,7 +91,7 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
}
if (ibuf1->x <= 1) {
- return (IMB_dupImBuf(ibuf1));
+ return IMB_dupImBuf(ibuf1);
}
ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags);
@@ -244,7 +244,7 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
}
if (ibuf1->y <= 1) {
- return (IMB_dupImBuf(ibuf1));
+ return IMB_dupImBuf(ibuf1);
}
ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
@@ -441,10 +441,10 @@ ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
}
if (ibuf1->x <= 1) {
- return (IMB_half_y(ibuf1));
+ return IMB_half_y(ibuf1);
}
if (ibuf1->y <= 1) {
- return (IMB_half_x(ibuf1));
+ return IMB_half_x(ibuf1);
}
ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
@@ -828,7 +828,7 @@ static void q_scale_float(
}
/**
- * q_scale_linear_interpolation (derived from ppmqscale, http://libdv.sf.net)
+ * q_scale_linear_interpolation (derived from `ppmqscale`, http://libdv.sf.net)
*
* q stands for quick _and_ quality :)
*
diff --git a/source/blender/imbuf/intern/thumbs_font.c b/source/blender/imbuf/intern/thumbs_font.c
index 65848bfb55e..c3ed81698d9 100644
--- a/source/blender/imbuf/intern/thumbs_font.c
+++ b/source/blender/imbuf/intern/thumbs_font.c
@@ -6,94 +6,39 @@
#include "BLI_fileops.h"
#include "BLI_hash_md5.h"
-#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
-#include "IMB_thumbs.h"
+#include "IMB_thumbs.h" /* own include. */
/* XXX, bad level call */
#include "../../blenfont/BLF_api.h"
-#include "../../blentranslation/BLT_translation.h"
-#define THUMB_TXT_ITEMS \
- N_("AaBbCc"), N_("The quick"), N_("brown fox"), N_("jumps over"), N_("the lazy dog"),
+/* Only change if we need to update the previews in the on-disk cache. */
+#define FONT_THUMB_VERSION "1.0.0"
-static const char *thumb_str[] = {THUMB_TXT_ITEMS};
-
-static const char *i18n_thumb_str[] = {THUMB_TXT_ITEMS};
-
-#undef THUMB_TXT_ITEMS
-
-void IMB_thumb_clear_translations(void)
-{
- for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
- i18n_thumb_str[i] = NULL;
- }
-}
-
-void IMB_thumb_ensure_translations(void)
-{
- for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) {
- i18n_thumb_str[i] = BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, thumb_str[i]);
- }
-}
-
-struct ImBuf *IMB_thumb_load_font(const char *filepath, uint x, uint y)
+struct ImBuf *IMB_thumb_load_font(const char *filename, uint x, uint y)
{
- const int font_size = y / 4;
+ struct ImBuf *ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata);
- struct ImBuf *ibuf;
- float font_color[4];
+ /* fill with white and zero alpha */
+ const float col[4] = {1.0f, 1.0f, 1.0f, 0.0f};
+ IMB_rectfill(ibuf, col);
- /* create a white image (theme color is used for drawing) */
- font_color[0] = font_color[1] = font_color[2] = 1.0f;
-
- /* fill with zero alpha */
- font_color[3] = 0.0f;
-
- ibuf = IMB_allocImBuf(x, y, 32, IB_rect | IB_metadata);
- IMB_rectfill(ibuf, font_color);
-
- /* draw with full alpha */
- font_color[3] = 1.0f;
-
- BLF_thumb_preview(filepath,
- thumb_str,
- i18n_thumb_str,
- ARRAY_SIZE(thumb_str),
- font_color,
- font_size,
- (uchar *)ibuf->rect,
- ibuf->x,
- ibuf->y,
- ibuf->channels);
+ if (!BLF_thumb_preview(filename, (uchar *)ibuf->rect, ibuf->x, ibuf->y, ibuf->channels)) {
+ IMB_freeImBuf(ibuf);
+ ibuf = NULL;
+ }
return ibuf;
}
bool IMB_thumb_load_font_get_hash(char *r_hash)
{
- char buf[1024];
- char *str = buf;
- size_t len = 0;
-
- int draw_str_lines = ARRAY_SIZE(thumb_str);
- int i;
-
uchar digest[16];
-
- len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len);
-
- for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) {
- len += BLI_strncpy_rlen(str + len,
- i18n_thumb_str[i] != NULL ? i18n_thumb_str[i] : thumb_str[i],
- sizeof(buf) - len);
- }
-
- BLI_hash_md5_buffer(str, len, digest);
+ BLI_hash_md5_buffer(FONT_THUMB_VERSION, sizeof(FONT_THUMB_VERSION), digest);
r_hash[0] = '\0';
BLI_hash_md5_to_hexdigest(digest, r_hash);
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index f4829386aac..0e20d0748db 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -142,7 +142,7 @@ static tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n)
}
/* all set -> do the read (copy) */
- srcAddr = (void *)(&(mfile->mem[mfile->offset]));
+ srcAddr = (void *)&(mfile->mem[mfile->offset]);
memcpy((void *)data, srcAddr, nCopy);
mfile->offset += nCopy; /* advance file ptr by copied bytes */
return nCopy;
@@ -437,7 +437,7 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image)
}
/* simple RGBA image */
- if (!(ELEM(bitspersample, 32, 16))) {
+ if (!ELEM(bitspersample, 32, 16)) {
success |= TIFFReadRGBAImage(image, ibuf->x, ibuf->y, tmpibuf->rect, 0);
}
/* contiguous channels: RGBRGBRGB */
diff --git a/source/blender/imbuf/intern/transform.cc b/source/blender/imbuf/intern/transform.cc
index 276d31c0557..6d3452c64db 100644
--- a/source/blender/imbuf/intern/transform.cc
+++ b/source/blender/imbuf/intern/transform.cc
@@ -134,8 +134,7 @@ class NoDiscard : public BaseDiscard {
*
* Will never discard any pixels.
*/
- bool should_discard(const TransformUserData &UNUSED(user_data),
- const float UNUSED(uv[2])) override
+ bool should_discard(const TransformUserData & /*user_data*/, const float /*uv*/[2]) override
{
return false;
}
@@ -165,7 +164,7 @@ class PixelPointer {
public:
void init_pixel_pointer(const ImBuf *image_buffer, int x, int y)
{
- const size_t offset = (y * (size_t)image_buffer->x + x) * NumChannels;
+ const size_t offset = (y * size_t(image_buffer->x) + x) * NumChannels;
if constexpr (std::is_same_v<StorageType, float>) {
pointer = image_buffer->rect_float + offset;
@@ -216,12 +215,12 @@ class BaseUVWrapping {
*/
class PassThroughUV : public BaseUVWrapping {
public:
- float modify_u(const ImBuf *UNUSED(source_buffer), float u) override
+ float modify_u(const ImBuf * /*source_buffer*/, float u) override
{
return u;
}
- float modify_v(const ImBuf *UNUSED(source_buffer), float v) override
+ float modify_v(const ImBuf * /*source_buffer*/, float v) override
{
return v;
}
@@ -235,7 +234,7 @@ class WrapRepeatUV : public BaseUVWrapping {
float modify_u(const ImBuf *source_buffer, float u) override
{
- int x = (int)floor(u);
+ int x = int(floor(u));
x = x % source_buffer->x;
if (x < 0) {
x += source_buffer->x;
@@ -245,7 +244,7 @@ class WrapRepeatUV : public BaseUVWrapping {
float modify_v(const ImBuf *source_buffer, float v) override
{
- int y = (int)floor(v);
+ int y = int(floor(v));
y = y % source_buffer->y;
if (y < 0) {
y += source_buffer->y;
@@ -349,8 +348,8 @@ class Sampler {
BLI_STATIC_ASSERT(std::is_same_v<StorageType, float>);
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
- int x1 = (int)(u);
- int y1 = (int)(v);
+ int x1 = int(u);
+ int y1 = int(v);
/* Break when sample outside image is requested. */
if (x1 < 0 || x1 >= source->x || y1 < 0 || y1 >= source->y) {
@@ -360,7 +359,7 @@ class Sampler {
return;
}
- const size_t offset = ((size_t)source->x * y1 + x1) * NumChannels;
+ const size_t offset = (size_t(source->x) * y1 + x1) * NumChannels;
const float *dataF = source->rect_float + offset;
for (int i = 0; i < NumChannels; i++) {
r_sample[i] = dataF[i];
diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c
index 6f1275e1812..35cdefbaaeb 100644
--- a/source/blender/imbuf/intern/util_gpu.c
+++ b/source/blender/imbuf/intern/util_gpu.c
@@ -174,6 +174,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
/* Other colorspace, store as float texture to avoid precision loss. */
data_rect = MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
*r_freedata = freedata = true;
+ is_float_rect = true;
if (data_rect == NULL) {
return NULL;
@@ -300,6 +301,16 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)};
bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]);
+ /* Correct the smaller size to maintain the original aspect ratio of the image. */
+ if (do_rescale && ibuf->x != ibuf->y) {
+ if (size[0] > size[1]) {
+ size[1] = (int)(ibuf->y * ((float)size[0] / ibuf->x));
+ }
+ else {
+ size[0] = (int)(ibuf->x * ((float)size[1] / ibuf->y));
+ }
+ }
+
#ifdef WITH_DDS
if (ibuf->ftype == IMB_FTYPE_DDS) {
eGPUTextureFormat compressed_format;
@@ -370,3 +381,19 @@ eGPUTextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf,
return gpu_texture_format;
}
+
+void IMB_gpu_clamp_half_float(ImBuf *image_buffer)
+{
+ const float half_min = -65504;
+ const float half_max = 65504;
+ if (!image_buffer->rect_float) {
+ return;
+ }
+
+ int rect_float_len = image_buffer->x * image_buffer->y *
+ (image_buffer->channels == 0 ? 4 : image_buffer->channels);
+
+ for (int i = 0; i < rect_float_len; i++) {
+ image_buffer->rect_float[i] = clamp_f(image_buffer->rect_float[i], half_min, half_max);
+ }
+}
diff --git a/source/blender/imbuf/intern/webp.c b/source/blender/imbuf/intern/webp.c
index 27c26fb19c1..3031b8c3e33 100644
--- a/source/blender/imbuf/intern/webp.c
+++ b/source/blender/imbuf/intern/webp.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
- * \ingroup imbuf
+ * \ingroup imbuf
*/
#ifdef _WIN32