bugfix [#23405] PNG Images bigger then 2gig wont load with blender.

all image formats should be able to load files bigger then 2gig (when its supported)
This commit is contained in:
Campbell Barton 2010-09-15 06:43:36 +00:00
parent 7eb7410002
commit 9234f29e67
24 changed files with 55 additions and 45 deletions

@ -24,9 +24,7 @@
# #
# ***** END GPL LICENSE BLOCK ***** # ***** END GPL LICENSE BLOCK *****
SET(INC . src) SET(INC .)
FILE(GLOB SRC *.c except t1_generate_luts.c) FILE(GLOB SRC *.c)
ADD_DEFINITIONS(-DWITH_OPENJPEG)
BLENDERLIB(extern_openjpeg "${SRC}" "${INC}") BLENDERLIB(extern_openjpeg "${SRC}" "${INC}")
#, libtype=['international','player'], priority=[5, 210])

@ -29,6 +29,7 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */ #include "BLI_storage.h" /* _LARGEFILE_SOURCE */
#include <math.h> #include <math.h>

@ -29,12 +29,14 @@
* *
* ***** END GPL LICENSE BLOCK *****/ * ***** END GPL LICENSE BLOCK *****/
#include <stddef.h>
#include "BLI_storage.h" #include "BLI_storage.h"
#include <stdlib.h>
#include <ctype.h> /* isdigit, isspace */ #include <ctype.h> /* isdigit, isspace */
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>

@ -28,6 +28,7 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */ #include "BLI_storage.h" /* _LARGEFILE_SOURCE */
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"

@ -29,6 +29,7 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */ #include "BLI_storage.h" /* _LARGEFILE_SOURCE */
#include <stdlib.h> #include <stdlib.h>

@ -42,12 +42,13 @@
struct direntry; struct direntry;
void BLI_adddirstrings(void); void BLI_adddirstrings(void);
void BLI_builddir(char *dirname, char *relname); void BLI_builddir(char *dirname, char *relname);
int BLI_compare(struct direntry *entry1, struct direntry *entry2); int BLI_compare(struct direntry *entry1, struct direntry *entry2);
int BLI_filesize(int file); size_t BLI_filesize(int file);
int BLI_filepathsize(const char *path); size_t BLI_filepathsize(const char *path);
double BLI_diskfree(char *dir); double BLI_diskfree(char *dir);
char *BLI_getwdN(char *dir); char *BLI_getwdN(char *dir);

@ -633,7 +633,7 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
if (S_ISREG(status.st_mode)) { /* is file */ if (S_ISREG(status.st_mode)) { /* is file */
if (strncmp(filename, de->d_name, FILE_MAX)==0) { /* name matches */ if (strncmp(filename, de->d_name, FILE_MAX)==0) { /* name matches */
/* open the file to read its size */ /* open the file to read its size */
size = BLI_filepathsize(path); size = status.st_size;
if ((size > 0) && (size > *filesize)) { /* find the biggest file */ if ((size > 0) && (size > *filesize)) { /* find the biggest file */
*filesize = size; *filesize = size;
BLI_strncpy(filename_new, path, FILE_MAX); BLI_strncpy(filename_new, path, FILE_MAX);

@ -421,7 +421,7 @@ unsigned int BLI_getdir(char *dirname, struct direntry **filelist)
} }
int BLI_filesize(int file) size_t BLI_filesize(int file)
{ {
struct stat buf; struct stat buf;
@ -430,11 +430,11 @@ int BLI_filesize(int file)
return (buf.st_size); return (buf.st_size);
} }
int BLI_filepathsize(const char *path) size_t BLI_filepathsize(const char *path)
{ {
int size, file = open(path, O_BINARY|O_RDONLY); int size, file = open(path, O_BINARY|O_RDONLY);
if (file < 0) if (file == -1)
return -1; return -1;
size = BLI_filesize(file); size = BLI_filesize(file);

@ -28,6 +28,7 @@
* .blend file reading entry point * .blend file reading entry point
*/ */
#include <stddef.h>
#include "BLI_storage.h" /* _LARGEFILE_SOURCE */ #include "BLI_storage.h" /* _LARGEFILE_SOURCE */
#include <stdlib.h> #include <stdlib.h>

@ -93,7 +93,7 @@ void IMB_exit(void);
* *
* @attention Defined in readimage.c * @attention Defined in readimage.c
*/ */
struct ImBuf *IMB_ibImageFromMemory(unsigned char *mem, int size, int flags); struct ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags);
/** /**
* *

@ -37,9 +37,9 @@ typedef struct ImFileType {
int (*is_a)(unsigned char *buf); int (*is_a)(unsigned char *buf);
int (*ftype)(struct ImFileType *type, struct ImBuf *ibuf); int (*ftype)(struct ImFileType *type, struct ImBuf *ibuf);
struct ImBuf *(*load)(unsigned char *mem, int size, int flags); struct ImBuf *(*load)(unsigned char *mem, size_t size, int flags);
int (*save)(struct ImBuf *ibuf, char *name, int flags); int (*save)(struct ImBuf *ibuf, char *name, int flags);
void (*load_tile)(struct ImBuf *ibuf, unsigned char *mem, int size, int tx, int ty, unsigned int *rect); void (*load_tile)(struct ImBuf *ibuf, unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect);
int flag; int flag;
int filetype; int filetype;
@ -60,59 +60,59 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty);
/* png */ /* png */
int imb_is_a_png(unsigned char *buf); int imb_is_a_png(unsigned char *buf);
struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags); struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags);
int imb_savepng(struct ImBuf *ibuf, char *name, int flags); int imb_savepng(struct ImBuf *ibuf, char *name, int flags);
/* targa */ /* targa */
int imb_is_a_targa(unsigned char *buf); int imb_is_a_targa(unsigned char *buf);
struct ImBuf *imb_loadtarga(unsigned char *mem, int size, int flags); struct ImBuf *imb_loadtarga(unsigned char *mem, size_t size, int flags);
int imb_savetarga(struct ImBuf * ibuf, char *name, int flags); int imb_savetarga(struct ImBuf * ibuf, char *name, int flags);
/* iris */ /* iris */
int imb_is_a_iris(unsigned char *mem); int imb_is_a_iris(unsigned char *mem);
struct ImBuf *imb_loadiris(unsigned char *mem, int size, int flags); struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags);
int imb_saveiris(struct ImBuf * ibuf, char *name, int flags); int imb_saveiris(struct ImBuf * ibuf, char *name, int flags);
/* jp2 */ /* jp2 */
int imb_is_a_jp2(unsigned char *buf); int imb_is_a_jp2(unsigned char *buf);
struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags); struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags);
int imb_savejp2(struct ImBuf *ibuf, char *name, int flags); int imb_savejp2(struct ImBuf *ibuf, char *name, int flags);
/* jpeg */ /* jpeg */
int imb_is_a_jpeg(unsigned char *mem); int imb_is_a_jpeg(unsigned char *mem);
int imb_savejpeg(struct ImBuf * ibuf, char * name, int flags); int imb_savejpeg(struct ImBuf * ibuf, char * name, int flags);
struct ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags); struct ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags);
struct ImBuf * imb_load_jpeg (unsigned char * buffer, int size, int flags); struct ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags);
/* bmp */ /* bmp */
int imb_is_a_bmp(unsigned char *buf); int imb_is_a_bmp(unsigned char *buf);
struct ImBuf *imb_bmp_decode(unsigned char *mem, int size, int flags); struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags);
int imb_savebmp(struct ImBuf *ibuf, char *name, int flags); int imb_savebmp(struct ImBuf *ibuf, char *name, int flags);
/* cocoa */ /* cocoa */
struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags); struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, size_t size, int flags);
short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags); short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags);
/* cineon */ /* cineon */
int imb_savecineon(struct ImBuf *buf, char *myfil, int flags); int imb_savecineon(struct ImBuf *buf, char *myfil, int flags);
struct ImBuf *imb_loadcineon(unsigned char *mem, int size, int flags); struct ImBuf *imb_loadcineon(unsigned char *mem, size_t size, int flags);
int imb_is_cineon(unsigned char *buf); int imb_is_cineon(unsigned char *buf);
/* dpx */ /* dpx */
int imb_save_dpx(struct ImBuf *buf, char *myfile, int flags); int imb_save_dpx(struct ImBuf *buf, char *myfile, int flags);
struct ImBuf *imb_loaddpx(unsigned char *mem, int size, int flags); struct ImBuf *imb_loaddpx(unsigned char *mem, size_t size, int flags);
int imb_is_dpx(unsigned char *buf); int imb_is_dpx(unsigned char *buf);
/* hdr */ /* hdr */
int imb_is_a_hdr(unsigned char *buf); int imb_is_a_hdr(unsigned char *buf);
struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags); struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags);
int imb_savehdr(struct ImBuf * ibuf, char *name, int flags); int imb_savehdr(struct ImBuf * ibuf, char *name, int flags);
/* tiff */ /* tiff */
void imb_inittiff(void); void imb_inittiff(void);
int imb_is_a_tiff(unsigned char *buf); int imb_is_a_tiff(unsigned char *buf);
struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags); struct ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags);
void imb_loadtiletiff(struct ImBuf *ibuf, unsigned char *mem, int size, void imb_loadtiletiff(struct ImBuf *ibuf, unsigned char *mem, size_t size,
int tx, int ty, unsigned int *rect); int tx, int ty, unsigned int *rect);
int imb_savetiff(struct ImBuf *ibuf, char *name, int flags); int imb_savetiff(struct ImBuf *ibuf, char *name, int flags);
void *libtiff_findsymbol(char *name); void *libtiff_findsymbol(char *name);

@ -32,6 +32,8 @@
/* It's become a bit messy... Basically, only the IMB_ prefixed files /* It's become a bit messy... Basically, only the IMB_ prefixed files
* should remain. */ * should remain. */
#include <stddef.h>
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_imbuf_types.h" #include "IMB_imbuf_types.h"

@ -101,7 +101,7 @@ int imb_is_a_bmp(unsigned char *buf) {
return checkbmp(buf); return checkbmp(buf);
} }
struct ImBuf *imb_bmp_decode(unsigned char *mem, int size, int flags) struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags)
{ {
struct ImBuf *ibuf = 0; struct ImBuf *ibuf = 0;
BMPINFOHEADER bmi; BMPINFOHEADER bmi;

@ -22,6 +22,7 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#include <stddef.h>
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_imbuf_types.h" #include "IMB_imbuf_types.h"
#include "IMB_filetype.h" #include "IMB_filetype.h"

@ -244,7 +244,7 @@ int imb_is_a_iris(unsigned char *mem)
* *
*/ */
struct ImBuf *imb_loadiris(unsigned char *mem, int size, int flags) struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
{ {
unsigned int *base, *lptr = NULL; unsigned int *base, *lptr = NULL;
float *fbase, *fptr = NULL; float *fbase, *fptr = NULL;

@ -90,7 +90,7 @@ void info_callback(const char *msg, void *client_data) {
struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags) struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
{ {
struct ImBuf *ibuf = 0; struct ImBuf *ibuf = 0;
int use_float = 0; /* for precision higher then 8 use float */ int use_float = 0; /* for precision higher then 8 use float */

@ -58,7 +58,7 @@ static void init_source(j_decompress_ptr cinfo);
static boolean fill_input_buffer(j_decompress_ptr cinfo); static boolean fill_input_buffer(j_decompress_ptr cinfo);
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes); static void skip_input_data(j_decompress_ptr cinfo, long num_bytes);
static void term_source(j_decompress_ptr cinfo); static void term_source(j_decompress_ptr cinfo);
static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, int size); static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t size);
static boolean handle_app1 (j_decompress_ptr cinfo); static boolean handle_app1 (j_decompress_ptr cinfo);
static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags); static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags);
@ -167,7 +167,7 @@ static void term_source(j_decompress_ptr cinfo)
{ {
} }
static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, int size) static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t size)
{ {
my_src_ptr src; my_src_ptr src;
@ -459,7 +459,7 @@ ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags)
return(ibuf); return(ibuf);
} }
ImBuf * imb_load_jpeg (unsigned char * buffer, int size, int flags) ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags)
{ {
struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo; struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr; struct my_error_mgr jerr;

@ -22,6 +22,7 @@
* ***** END GPL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/ */
#include <stddef.h>
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_filetype.h" #include "IMB_filetype.h"

@ -286,7 +286,7 @@ int imb_savepng(struct ImBuf *ibuf, char *name, int flags)
return(1); return(1);
} }
struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags) struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
{ {
struct ImBuf *ibuf = 0; struct ImBuf *ibuf = 0;
png_structp png_ptr; png_structp png_ptr;
@ -317,7 +317,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags)
return 0; return 0;
} }
ps.size = size; ps.size = size; /* XXX, 4gig limit! */
ps.data = mem; ps.data = mem;
ps.seek = 0; ps.seek = 0;

@ -173,7 +173,7 @@ int imb_is_a_hdr(unsigned char *buf)
return 0; return 0;
} }
struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags) struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags)
{ {
struct ImBuf* ibuf; struct ImBuf* ibuf;
RGBE* sline; RGBE* sline;

@ -46,7 +46,7 @@
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_filetype.h" #include "IMB_filetype.h"
ImBuf *IMB_ibImageFromMemory(unsigned char *mem, int size, int flags) ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags)
{ {
ImBuf *ibuf; ImBuf *ibuf;
ImFileType *type; ImFileType *type;
@ -79,7 +79,7 @@ ImBuf *IMB_loadifffile(int file, int flags)
{ {
ImBuf *ibuf; ImBuf *ibuf;
unsigned char *mem; unsigned char *mem;
int size; size_t size;
if(file == -1) return 0; if(file == -1) return 0;
@ -166,7 +166,7 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int
{ {
ImFileType *type; ImFileType *type;
unsigned char *mem; unsigned char *mem;
int size; size_t size;
if(file == -1) return; if(file == -1) return;

@ -359,7 +359,7 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
} }
} }
static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, int mem_size, int psize) static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, int psize)
{ {
unsigned char *mem_end = mem+mem_size; unsigned char *mem_end = mem+mem_size;
int count, col, size; int count, col, size;
@ -470,7 +470,7 @@ partial_load:
complete_partial_load(ibuf, rect); complete_partial_load(ibuf, rect);
} }
static void ldtarga(struct ImBuf * ibuf,unsigned char * mem, int mem_size, int psize) static void ldtarga(struct ImBuf * ibuf,unsigned char * mem, size_t mem_size, int psize)
{ {
unsigned char *mem_end = mem+mem_size; unsigned char *mem_end = mem+mem_size;
int col,size; int col,size;
@ -527,7 +527,7 @@ partial_load:
} }
struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags) struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
{ {
TARGA tga; TARGA tga;
struct ImBuf * ibuf; struct ImBuf * ibuf;

@ -262,7 +262,7 @@ static toff_t imb_tiff_SizeProc(thandle_t handle)
return (toff_t)(mfile->size); return (toff_t)(mfile->size);
} }
static TIFF *imb_tiff_client_open(ImbTIFFMemFile *memFile, unsigned char *mem, int size) static TIFF *imb_tiff_client_open(ImbTIFFMemFile *memFile, unsigned char *mem, size_t size)
{ {
/* open the TIFF client layer interface to the in-memory file */ /* open the TIFF client layer interface to the in-memory file */
memFile->mem = mem; memFile->mem = mem;
@ -464,7 +464,7 @@ void imb_inittiff(void)
* *
* @return: A newly allocated ImBuf structure if successful, otherwise NULL. * @return: A newly allocated ImBuf structure if successful, otherwise NULL.
*/ */
ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags) ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags)
{ {
TIFF *image = NULL; TIFF *image = NULL;
ImBuf *ibuf = NULL, *hbuf; ImBuf *ibuf = NULL, *hbuf;
@ -573,7 +573,7 @@ ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
return ibuf; return ibuf;
} }
void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, int size, int tx, int ty, unsigned int *rect) void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect)
{ {
TIFF *image = NULL; TIFF *image = NULL;
uint32 width, height; uint32 width, height;

@ -132,7 +132,8 @@ blo_read_runtime(
ReportList *reports) ReportList *reports)
{ {
BlendFileData *bfd= NULL; BlendFileData *bfd= NULL;
int fd, actualsize, datastart; size_t actualsize;
int fd, datastart;
char buf[8]; char buf[8];
fd= open(path, O_BINARY|O_RDONLY, 0); fd= open(path, O_BINARY|O_RDONLY, 0);