Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/readimage.c
| Show All 17 Lines | |||||
| * allocimbuf.c | * allocimbuf.c | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup imbuf | * \ingroup imbuf | ||||
| */ | */ | ||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| # include "mmap_win.h" | |||||
| # include <io.h> | # include <io.h> | ||||
| # include <stddef.h> | # include <stddef.h> | ||||
| # include <sys/types.h> | # include <sys/types.h> | ||||
| #endif | #endif | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_mmap.h" | |||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include "IMB_allocimbuf.h" | #include "IMB_allocimbuf.h" | ||||
| #include "IMB_filetype.h" | #include "IMB_filetype.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| ▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | ImBuf *IMB_loadifffile( | ||||
| if (imb_is_filepath_format(filepath)) { | if (imb_is_filepath_format(filepath)) { | ||||
| return IMB_ibImageFromFile(filepath, flags, colorspace, descr); | return IMB_ibImageFromFile(filepath, flags, colorspace, descr); | ||||
| } | } | ||||
| size = BLI_file_descriptor_size(file); | size = BLI_file_descriptor_size(file); | ||||
| imb_mmap_lock(); | imb_mmap_lock(); | ||||
| mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); | BLI_mmap_file *mmap_file = BLI_mmap_open(file); | ||||
| imb_mmap_unlock(); | imb_mmap_unlock(); | ||||
| if (mmap_file == NULL) { | |||||
| if (mem == (unsigned char *)-1) { | |||||
| fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr); | fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| mem = BLI_mmap_get_pointer(mmap_file); | |||||
| ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr); | ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr); | ||||
| imb_mmap_lock(); | imb_mmap_lock(); | ||||
| if (munmap(mem, size)) { | BLI_mmap_free(mmap_file); | ||||
| 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, int flags) | ||||
| { | { | ||||
| /* read .tx instead if it exists and is not older */ | /* read .tx instead if it exists and is not older */ | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect) | ||||
| if (file == -1) { | if (file == -1) { | ||||
| return; | return; | ||||
| } | } | ||||
| size = BLI_file_descriptor_size(file); | size = BLI_file_descriptor_size(file); | ||||
| imb_mmap_lock(); | imb_mmap_lock(); | ||||
| mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); | BLI_mmap_file *mmap_file = BLI_mmap_open(file); | ||||
| imb_mmap_unlock(); | imb_mmap_unlock(); | ||||
| if (mmap_file == NULL) { | |||||
| if (mem == (unsigned char *)-1) { | |||||
| fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); | fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); | ||||
| return; | return; | ||||
| } | } | ||||
| mem = BLI_mmap_get_pointer(mmap_file); | |||||
| const ImFileType *type = IMB_file_type_from_ibuf(ibuf); | const ImFileType *type = IMB_file_type_from_ibuf(ibuf); | ||||
| if (type != NULL) { | if (type != NULL) { | ||||
| if (type->load_tile != NULL) { | if (type->load_tile != NULL) { | ||||
| type->load_tile(ibuf, mem, size, tx, ty, rect); | type->load_tile(ibuf, mem, size, tx, ty, rect); | ||||
| } | } | ||||
| } | } | ||||
| imb_mmap_lock(); | imb_mmap_lock(); | ||||
| if (munmap(mem, size)) { | BLI_mmap_free(mmap_file); | ||||
| fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); | |||||
| } | |||||
| imb_mmap_unlock(); | imb_mmap_unlock(); | ||||
| } | } | ||||
| void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect) | 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); | file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0); | ||||
| if (file == -1) { | if (file == -1) { | ||||
| return; | return; | ||||
| } | } | ||||
| imb_loadtilefile(ibuf, file, tx, ty, rect); | imb_loadtilefile(ibuf, file, tx, ty, rect); | ||||
| close(file); | close(file); | ||||
| } | } | ||||