From e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Apr 2019 06:17:24 +0200 Subject: ClangFormat: apply to source, most of intern Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat --- source/blender/imbuf/intern/readimage.c | 382 ++++++++++++++++---------------- 1 file changed, 196 insertions(+), 186 deletions(-) (limited to 'source/blender/imbuf/intern/readimage.c') diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c index ad4e07030d1..34bae007979 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -22,7 +22,6 @@ * \ingroup imbuf */ - #ifdef _WIN32 # include # include @@ -45,256 +44,267 @@ #include "IMB_colormanagement.h" #include "IMB_colormanagement_intern.h" -static void imb_handle_alpha(ImBuf *ibuf, int flags, char colorspace[IM_MAX_SPACE], char effective_colorspace[IM_MAX_SPACE]) +static void imb_handle_alpha(ImBuf *ibuf, + int flags, + char colorspace[IM_MAX_SPACE], + char effective_colorspace[IM_MAX_SPACE]) { - int alpha_flags; - - if (colorspace) { - if (ibuf->rect != NULL && ibuf->rect_float == NULL) { - /* byte buffer is never internally converted to some standard space, - * store pointer to it's color space descriptor instead - */ - ibuf->rect_colorspace = colormanage_colorspace_get_named(effective_colorspace); - } - - BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE); - } - - if (flags & IB_alphamode_detect) - alpha_flags = ibuf->flags & IB_alphamode_premul; - else - alpha_flags = flags & IB_alphamode_premul; - - if (flags & IB_ignore_alpha) { - IMB_rectfill_alpha(ibuf, 1.0f); - } - else { - if (alpha_flags & IB_alphamode_premul) { - if (ibuf->rect) { - IMB_unpremultiply_alpha(ibuf); - } - else { - /* pass, floats are expected to be premul */ - } - } - else { - if (ibuf->rect_float) { - IMB_premultiply_alpha(ibuf); - } - else { - /* pass, bytes are expected to be straight */ - } - } - } - - /* OCIO_TODO: in some cases it's faster to do threaded conversion, - * but how to distinguish such cases */ - colormanage_imbuf_make_linear(ibuf, effective_colorspace); + int alpha_flags; + + if (colorspace) { + if (ibuf->rect != NULL && ibuf->rect_float == NULL) { + /* byte buffer is never internally converted to some standard space, + * store pointer to it's color space descriptor instead + */ + ibuf->rect_colorspace = colormanage_colorspace_get_named(effective_colorspace); + } + + BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE); + } + + if (flags & IB_alphamode_detect) + alpha_flags = ibuf->flags & IB_alphamode_premul; + else + alpha_flags = flags & IB_alphamode_premul; + + if (flags & IB_ignore_alpha) { + IMB_rectfill_alpha(ibuf, 1.0f); + } + else { + if (alpha_flags & IB_alphamode_premul) { + if (ibuf->rect) { + IMB_unpremultiply_alpha(ibuf); + } + else { + /* pass, floats are expected to be premul */ + } + } + else { + if (ibuf->rect_float) { + IMB_premultiply_alpha(ibuf); + } + else { + /* pass, bytes are expected to be straight */ + } + } + } + + /* OCIO_TODO: in some cases it's faster to do threaded conversion, + * but how to distinguish such cases */ + colormanage_imbuf_make_linear(ibuf, effective_colorspace); } -ImBuf *IMB_ibImageFromMemory( - const unsigned char *mem, size_t size, int flags, - char colorspace[IM_MAX_SPACE], const char *descr) +ImBuf *IMB_ibImageFromMemory(const unsigned char *mem, + size_t size, + int flags, + char colorspace[IM_MAX_SPACE], + const char *descr) { - ImBuf *ibuf; - const ImFileType *type; - char effective_colorspace[IM_MAX_SPACE] = ""; - - if (mem == NULL) { - fprintf(stderr, "%s: NULL pointer\n", __func__); - return NULL; - } - - if (colorspace) - BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace)); - - for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { - if (type->load) { - ibuf = type->load(mem, size, flags, effective_colorspace); - if (ibuf) { - imb_handle_alpha(ibuf, flags, colorspace, effective_colorspace); - return ibuf; - } - } - } - - if ((flags & IB_test) == 0) - fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr); - - return NULL; + ImBuf *ibuf; + const ImFileType *type; + char effective_colorspace[IM_MAX_SPACE] = ""; + + if (mem == NULL) { + fprintf(stderr, "%s: NULL pointer\n", __func__); + return NULL; + } + + if (colorspace) + BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace)); + + for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { + if (type->load) { + ibuf = type->load(mem, size, flags, effective_colorspace); + if (ibuf) { + imb_handle_alpha(ibuf, flags, colorspace, effective_colorspace); + return ibuf; + } + } + } + + if ((flags & IB_test) == 0) + fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr); + + return NULL; } -static ImBuf *IMB_ibImageFromFile(const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr) +static ImBuf *IMB_ibImageFromFile(const char *filepath, + int flags, + char colorspace[IM_MAX_SPACE], + const char *descr) { - ImBuf *ibuf; - const ImFileType *type; - char effective_colorspace[IM_MAX_SPACE] = ""; - - if (colorspace) - BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace)); - - for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { - if (type->load_filepath) { - ibuf = type->load_filepath(filepath, flags, effective_colorspace); - if (ibuf) { - imb_handle_alpha(ibuf, flags, colorspace, effective_colorspace); - return ibuf; - } - } - } - - if ((flags & IB_test) == 0) - fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr); - - return NULL; + ImBuf *ibuf; + const ImFileType *type; + char effective_colorspace[IM_MAX_SPACE] = ""; + + if (colorspace) + BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace)); + + for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { + if (type->load_filepath) { + ibuf = type->load_filepath(filepath, flags, effective_colorspace); + if (ibuf) { + imb_handle_alpha(ibuf, flags, colorspace, effective_colorspace); + return ibuf; + } + } + } + + if ((flags & IB_test) == 0) + fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr); + + return NULL; } static bool imb_is_filepath_format(const char *filepath) { - /* return true if this is one of the formats that can't be loaded from memory */ - return BLI_path_extension_check_array(filepath, imb_ext_image_filepath_only); + /* return true if this is one of the formats that can't be loaded from memory */ + return BLI_path_extension_check_array(filepath, imb_ext_image_filepath_only); } -ImBuf *IMB_loadifffile(int file, const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr) +ImBuf *IMB_loadifffile( + int file, const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr) { - ImBuf *ibuf; - unsigned char *mem; - size_t size; + ImBuf *ibuf; + unsigned char *mem; + size_t size; - if (file == -1) return NULL; + if (file == -1) + return NULL; - if (imb_is_filepath_format(filepath)) - return IMB_ibImageFromFile(filepath, flags, colorspace, descr); + if (imb_is_filepath_format(filepath)) + return IMB_ibImageFromFile(filepath, flags, colorspace, descr); - size = BLI_file_descriptor_size(file); + size = BLI_file_descriptor_size(file); - imb_mmap_lock(); - mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); - imb_mmap_unlock(); + imb_mmap_lock(); + mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); + imb_mmap_unlock(); - if (mem == (unsigned char *) -1) { - fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr); - return NULL; - } + if (mem == (unsigned char *)-1) { + fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr); + return NULL; + } - ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr); + ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr); - imb_mmap_lock(); - if (munmap(mem, size)) - fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr); - imb_mmap_unlock(); + imb_mmap_lock(); + if (munmap(mem, size)) + fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr); + imb_mmap_unlock(); - return ibuf; + return ibuf; } static void imb_cache_filename(char *filename, const char *name, int flags) { - /* read .tx instead if it exists and is not older */ - if (flags & IB_tilecache) { - BLI_strncpy(filename, name, IMB_FILENAME_SIZE); - if (!BLI_path_extension_replace(filename, IMB_FILENAME_SIZE, ".tx")) - return; + /* read .tx instead if it exists and is not older */ + if (flags & IB_tilecache) { + BLI_strncpy(filename, name, IMB_FILENAME_SIZE); + if (!BLI_path_extension_replace(filename, IMB_FILENAME_SIZE, ".tx")) + return; - if (BLI_file_older(name, filename)) - return; - } + if (BLI_file_older(name, filename)) + return; + } - BLI_strncpy(filename, name, IMB_FILENAME_SIZE); + BLI_strncpy(filename, name, IMB_FILENAME_SIZE); } ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_SPACE]) { - ImBuf *ibuf; - int file, a; - char filepath_tx[IMB_FILENAME_SIZE]; + ImBuf *ibuf; + int file, a; + char filepath_tx[IMB_FILENAME_SIZE]; - BLI_assert(!BLI_path_is_rel(filepath)); + BLI_assert(!BLI_path_is_rel(filepath)); - imb_cache_filename(filepath_tx, filepath, flags); + imb_cache_filename(filepath_tx, filepath, flags); - file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0); - if (file == -1) - return NULL; + file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0); + if (file == -1) + return NULL; - ibuf = IMB_loadifffile(file, filepath, flags, colorspace, filepath_tx); + ibuf = IMB_loadifffile(file, filepath, flags, colorspace, filepath_tx); - if (ibuf) { - BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); - BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); - for (a = 1; a < ibuf->miptot; a++) - BLI_strncpy(ibuf->mipmap[a - 1]->cachename, filepath_tx, sizeof(ibuf->cachename)); - } + if (ibuf) { + BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); + BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); + for (a = 1; a < ibuf->miptot; a++) + BLI_strncpy(ibuf->mipmap[a - 1]->cachename, filepath_tx, sizeof(ibuf->cachename)); + } - close(file); + close(file); - return ibuf; + return ibuf; } ImBuf *IMB_testiffname(const char *filepath, int flags) { - ImBuf *ibuf; - int file; - char filepath_tx[IMB_FILENAME_SIZE]; - char colorspace[IM_MAX_SPACE] = "\0"; + ImBuf *ibuf; + int file; + char filepath_tx[IMB_FILENAME_SIZE]; + char colorspace[IM_MAX_SPACE] = "\0"; - BLI_assert(!BLI_path_is_rel(filepath)); + BLI_assert(!BLI_path_is_rel(filepath)); - imb_cache_filename(filepath_tx, filepath, flags); + imb_cache_filename(filepath_tx, filepath, flags); - file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0); - if (file == -1) - return NULL; + file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0); + if (file == -1) + return NULL; - ibuf = IMB_loadifffile(file, filepath, flags | IB_test | IB_multilayer, colorspace, filepath_tx); + ibuf = IMB_loadifffile(file, filepath, flags | IB_test | IB_multilayer, colorspace, filepath_tx); - if (ibuf) { - BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); - BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); - } + if (ibuf) { + BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); + BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); + } - close(file); + close(file); - return ibuf; + return ibuf; } static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect) { - const ImFileType *type; - unsigned char *mem; - size_t size; + const ImFileType *type; + unsigned char *mem; + size_t size; - if (file == -1) return; + if (file == -1) + return; - size = BLI_file_descriptor_size(file); + size = BLI_file_descriptor_size(file); - imb_mmap_lock(); - mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); - imb_mmap_unlock(); + imb_mmap_lock(); + mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); + imb_mmap_unlock(); - if (mem == (unsigned char *) -1) { - fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); - return; - } + if (mem == (unsigned char *)-1) { + fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); + return; + } - for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) - if (type->load_tile && type->ftype(type, ibuf)) - type->load_tile(ibuf, mem, size, tx, ty, rect); + for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) + if (type->load_tile && type->ftype(type, ibuf)) + type->load_tile(ibuf, mem, size, tx, ty, rect); - imb_mmap_lock(); - if (munmap(mem, size)) - fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); - imb_mmap_unlock(); + imb_mmap_lock(); + if (munmap(mem, size)) + fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); + imb_mmap_unlock(); } void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect) { - int file; + int file; - file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0); - if (file == -1) - return; + file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0); + if (file == -1) + return; - imb_loadtilefile(ibuf, file, tx, ty, rect); + imb_loadtilefile(ibuf, file, tx, ty, rect); - close(file); + close(file); } -- cgit v1.2.3