Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/readimage.c
| Show All 33 Lines | |||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| # include <io.h> | # include <io.h> | ||||
| # include <stddef.h> | # include <stddef.h> | ||||
| # include <sys/types.h> | # include <sys/types.h> | ||||
| # include "mmap_win.h" | # include "mmap_win.h" | ||||
| #endif | #endif | ||||
| #include "MEM_guardedalloc.h" | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "imbuf.h" | #include "imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | ImBuf *IMB_loadifffile(int file, const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr) | ||||
| if (file == -1) return NULL; | if (file == -1) return NULL; | ||||
| 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); | ||||
| mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); | mem = MEM_mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); | ||||
| if (mem == (unsigned char *) -1) { | 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; | ||||
| } | } | ||||
| ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr); | ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr); | ||||
| if (munmap(mem, size)) | if (MEM_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); | ||||
| 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 70 Lines • ▼ Show 20 Lines | static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect) | ||||
| const ImFileType *type; | const ImFileType *type; | ||||
| unsigned char *mem; | unsigned char *mem; | ||||
| size_t size; | size_t size; | ||||
| if (file == -1) return; | if (file == -1) return; | ||||
| size = BLI_file_descriptor_size(file); | size = BLI_file_descriptor_size(file); | ||||
| mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); | mem = MEM_mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); | ||||
| if (mem == (unsigned char *) -1) { | 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; | ||||
| } | } | ||||
| for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) | for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) | ||||
| if (type->load_tile && type->ftype(type, ibuf)) | if (type->load_tile && type->ftype(type, ibuf)) | ||||
| type->load_tile(ibuf, mem, size, tx, ty, rect); | type->load_tile(ibuf, mem, size, tx, ty, rect); | ||||
| if (munmap(mem, size)) | if (MEM_munmap(mem, size)) | ||||
| fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); | fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); | ||||
| } | } | ||||
| 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); | ||||
| } | } | ||||