Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/readimage.c
| Show All 39 Lines | |||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_filetype.h" | #include "IMB_filetype.h" | ||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "IMB_colormanagement_intern.h" | #include "IMB_colormanagement_intern.h" | ||||
| static void imb_handle_alpha(ImBuf *ibuf, | static void imb_handle_alpha(ImBuf *ibuf, | ||||
| int flags, | eImBufFlags flags, | ||||
| char colorspace[IM_MAX_SPACE], | char colorspace[IM_MAX_SPACE], | ||||
| char effective_colorspace[IM_MAX_SPACE]) | char effective_colorspace[IM_MAX_SPACE]) | ||||
| { | { | ||||
| if (colorspace) { | if (colorspace) { | ||||
| if (ibuf->rect != NULL && ibuf->rect_float == NULL) { | if (ibuf->rect != NULL && ibuf->rect_float == NULL) { | ||||
| /* byte buffer is never internally converted to some standard space, | /* byte buffer is never internally converted to some standard space, | ||||
| * store pointer to it's color space descriptor instead | * store pointer to it's color space descriptor instead | ||||
| */ | */ | ||||
| ibuf->rect_colorspace = colormanage_colorspace_get_named(effective_colorspace); | ibuf->rect_colorspace = colormanage_colorspace_get_named(effective_colorspace); | ||||
| } | } | ||||
| BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE); | BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE); | ||||
| } | } | ||||
| bool is_data = (colorspace && IMB_colormanagement_space_name_is_data(colorspace)); | bool is_data = (colorspace && IMB_colormanagement_space_name_is_data(colorspace)); | ||||
| int alpha_flags = (flags & IB_alphamode_detect) ? ibuf->flags : flags; | eImBufFlags alpha_flags = (flags & IB_alphamode_detect) ? ibuf->flags : flags; | ||||
| if (is_data || (flags & IB_alphamode_channel_packed)) { | if (is_data || (flags & IB_alphamode_channel_packed)) { | ||||
| /* Don't touch alpha. */ | /* Don't touch alpha. */ | ||||
| ibuf->flags |= IB_alphamode_channel_packed; | ibuf->flags |= IB_alphamode_channel_packed; | ||||
| } | } | ||||
| else if (flags & IB_alphamode_ignore) { | else if (flags & IB_alphamode_ignore) { | ||||
| /* Make opaque. */ | /* Make opaque. */ | ||||
| IMB_rectfill_alpha(ibuf, 1.0f); | IMB_rectfill_alpha(ibuf, 1.0f); | ||||
| Show All 20 Lines | static void imb_handle_alpha(ImBuf *ibuf, | ||||
| /* OCIO_TODO: in some cases it's faster to do threaded conversion, | /* OCIO_TODO: in some cases it's faster to do threaded conversion, | ||||
| * but how to distinguish such cases */ | * but how to distinguish such cases */ | ||||
| colormanage_imbuf_make_linear(ibuf, effective_colorspace); | colormanage_imbuf_make_linear(ibuf, effective_colorspace); | ||||
| } | } | ||||
| ImBuf *IMB_ibImageFromMemory(const unsigned char *mem, | ImBuf *IMB_ibImageFromMemory(const unsigned char *mem, | ||||
| size_t size, | size_t size, | ||||
| int flags, | eImBufFlags flags, | ||||
| char colorspace[IM_MAX_SPACE], | char colorspace[IM_MAX_SPACE], | ||||
| const char *descr) | const char *descr) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| const ImFileType *type; | const ImFileType *type; | ||||
| char effective_colorspace[IM_MAX_SPACE] = ""; | char effective_colorspace[IM_MAX_SPACE] = ""; | ||||
| if (mem == NULL) { | if (mem == NULL) { | ||||
| Show All 18 Lines | ImBuf *IMB_ibImageFromMemory(const unsigned char *mem, | ||||
| if ((flags & IB_test) == 0) { | if ((flags & IB_test) == 0) { | ||||
| fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr); | fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr); | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static ImBuf *IMB_ibImageFromFile(const char *filepath, | static ImBuf *IMB_ibImageFromFile(const char *filepath, | ||||
| int flags, | eImBufFlags flags, | ||||
| char colorspace[IM_MAX_SPACE], | char colorspace[IM_MAX_SPACE], | ||||
| const char *descr) | const char *descr) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| const ImFileType *type; | const ImFileType *type; | ||||
| char effective_colorspace[IM_MAX_SPACE] = ""; | char effective_colorspace[IM_MAX_SPACE] = ""; | ||||
| if (colorspace) { | if (colorspace) { | ||||
| Show All 18 Lines | |||||
| } | } | ||||
| static bool imb_is_filepath_format(const char *filepath) | 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 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 BLI_path_extension_check_array(filepath, imb_ext_image_filepath_only); | ||||
| } | } | ||||
| ImBuf *IMB_loadifffile( | ImBuf *IMB_loadifffile(int file, | ||||
| int file, const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr) | const char *filepath, | ||||
| eImBufFlags flags, | |||||
| char colorspace[IM_MAX_SPACE], | |||||
| const char *descr) | |||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| unsigned char *mem; | unsigned char *mem; | ||||
| size_t size; | size_t size; | ||||
| if (file == -1) { | if (file == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Show All 19 Lines | ImBuf *IMB_loadifffile(int file, | ||||
| if (munmap(mem, size)) { | if (munmap(mem, size)) { | ||||
| fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr); | fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr); | ||||
| } | } | ||||
| imb_mmap_unlock(); | imb_mmap_unlock(); | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| static void imb_cache_filename(char *filename, const char *name, int flags) | static void imb_cache_filename(char *filename, const char *name, eImBufFlags flags) | ||||
| { | { | ||||
| /* read .tx instead if it exists and is not older */ | /* read .tx instead if it exists and is not older */ | ||||
| if (flags & IB_tilecache) { | if (flags & IB_tilecache) { | ||||
| BLI_strncpy(filename, name, IMB_FILENAME_SIZE); | BLI_strncpy(filename, name, IMB_FILENAME_SIZE); | ||||
| if (!BLI_path_extension_replace(filename, IMB_FILENAME_SIZE, ".tx")) { | if (!BLI_path_extension_replace(filename, IMB_FILENAME_SIZE, ".tx")) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (BLI_file_older(name, filename)) { | if (BLI_file_older(name, filename)) { | ||||
| return; | 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 *IMB_loadiffname(const char *filepath, eImBufFlags flags, char colorspace[IM_MAX_SPACE]) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| int file, a; | int file, a; | ||||
| char filepath_tx[IMB_FILENAME_SIZE]; | 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); | ||||
| Show All 13 Lines | if (ibuf) { | ||||
| } | } | ||||
| } | } | ||||
| close(file); | close(file); | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| ImBuf *IMB_testiffname(const char *filepath, int flags) | ImBuf *IMB_testiffname(const char *filepath, eImBufFlags flags) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| int file; | int file; | ||||
| char filepath_tx[IMB_FILENAME_SIZE]; | char filepath_tx[IMB_FILENAME_SIZE]; | ||||
| char colorspace[IM_MAX_SPACE] = "\0"; | char colorspace[IM_MAX_SPACE] = "\0"; | ||||
| BLI_assert(!BLI_path_is_rel(filepath)); | BLI_assert(!BLI_path_is_rel(filepath)); | ||||
| ▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines | |||||