style cleanup: imbuf

This commit is contained in:
Campbell Barton
2012-05-16 07:38:23 +00:00
parent e6ddad5146
commit d64fd168c9
6 changed files with 268 additions and 252 deletions

View File

@@ -44,13 +44,26 @@
#include "imbuf.h"
static int imb_ftype_default(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype & type->filetype); }
static int imb_ftype_default(ImFileType *type, ImBuf *ibuf)
{
return (ibuf->ftype & type->filetype);
}
#if defined(__APPLE__) && defined(IMBUF_COCOA)
static int imb_ftype_cocoa(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype & TIF); }
static int imb_ftype_cocoa(ImFileType *type, ImBuf *ibuf)
{
return (ibuf->ftype & TIF);
}
#endif
static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf) { (void)type; return (ibuf->ftype == IMAGIC); }
static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf)
{
(void)type;
return (ibuf->ftype == IMAGIC);
}
#ifdef WITH_QUICKTIME
static int imb_ftype_quicktime(ImFileType *type, ImBuf *ibuf) { return 0; } // XXX
static int imb_ftype_quicktime(ImFileType *type, ImBuf *ibuf)
{
return 0; /* XXX */
}
#endif
#ifdef WITH_QUICKTIME
@@ -58,7 +71,7 @@ void quicktime_init(void);
void quicktime_exit(void);
#endif
ImFileType IMB_FILE_TYPES[]= {
ImFileType IMB_FILE_TYPES[] = {
{NULL, NULL, imb_is_a_jpeg, imb_ftype_default, imb_load_jpeg, imb_savejpeg, NULL, 0, JPG},
{NULL, NULL, imb_is_a_png, imb_ftype_default, imb_loadpng, imb_savepng, NULL, 0, PNG},
{NULL, NULL, imb_is_a_bmp, imb_ftype_default, imb_bmp_decode, imb_savebmp, NULL, 0, BMP},
@@ -88,13 +101,14 @@ ImFileType IMB_FILE_TYPES[]= {
#ifdef WITH_QUICKTIME
{quicktime_init, quicktime_exit, imb_is_a_quicktime, imb_ftype_quicktime, imb_quicktime_decode, NULL, NULL, 0, QUICKTIME},
#endif
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0}};
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0}
};
void imb_filetypes_init(void)
{
ImFileType *type;
for (type=IMB_FILE_TYPES; type->is_a; type++)
for (type = IMB_FILE_TYPES; type->is_a; type++)
if (type->init)
type->init();
}
@@ -103,7 +117,7 @@ void imb_filetypes_exit(void)
{
ImFileType *type;
for (type=IMB_FILE_TYPES; type->is_a; type++)
for (type = IMB_FILE_TYPES; type->is_a; type++)
if (type->exit)
type->exit();
}

View File

@@ -47,21 +47,21 @@
#include "jpeglib.h"
#include "jerror.h"
#define IS_jpg(x) (x->ftype & JPG)
#define IS_stdjpg(x) ((x->ftype & JPG_MSK) == JPG_STD)
#define IS_vidjpg(x) ((x->ftype & JPG_MSK) == JPG_VID)
#define IS_jstjpg(x) ((x->ftype & JPG_MSK) == JPG_JST)
#define IS_maxjpg(x) ((x->ftype & JPG_MSK) == JPG_MAX)
#define IS_jpg(x) (x->ftype & JPG)
#define IS_stdjpg(x) ((x->ftype & JPG_MSK) == JPG_STD)
#define IS_vidjpg(x) ((x->ftype & JPG_MSK) == JPG_VID)
#define IS_jstjpg(x) ((x->ftype & JPG_MSK) == JPG_JST)
#define IS_maxjpg(x) ((x->ftype & JPG_MSK) == JPG_MAX)
/* the types are from the jpeg lib */
static void jpeg_error (j_common_ptr cinfo);
static void jpeg_error(j_common_ptr cinfo);
static void init_source(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 term_source(j_decompress_ptr cinfo);
static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t size);
static boolean handle_app1 (j_decompress_ptr cinfo);
static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags);
static boolean handle_app1(j_decompress_ptr cinfo);
static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags);
/*
@@ -82,7 +82,7 @@ static int ibuf_ftype;
int imb_is_a_jpeg(unsigned char *mem)
{
if ((mem[0]== 0xFF) && (mem[1] == 0xD8))return 1;
if ((mem[0] == 0xFF) && (mem[1] == 0xD8)) return 1;
return 0;
}
@@ -91,19 +91,19 @@ int imb_is_a_jpeg(unsigned char *mem)
//----------------------------------------------------------
typedef struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
jmp_buf setjmp_buffer; /* for return to caller */
} my_error_mgr;
typedef my_error_mgr * my_error_ptr;
typedef my_error_mgr *my_error_ptr;
static void jpeg_error (j_common_ptr cinfo)
static void jpeg_error(j_common_ptr cinfo)
{
my_error_ptr err = (my_error_ptr)cinfo->err;
/* Always display the message */
(*cinfo->err->output_message) (cinfo);
(*cinfo->err->output_message)(cinfo);
/* Let the memory manager delete any temp files before we die */
jpeg_destroy(cinfo);
@@ -117,19 +117,19 @@ static void jpeg_error (j_common_ptr cinfo)
//----------------------------------------------------------
typedef struct {
unsigned char *buffer;
int filled;
unsigned char *buffer;
int filled;
} buffer_struct;
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
struct jpeg_source_mgr pub; /* public fields */
unsigned char *buffer;
int size;
JOCTET terminal[2];
unsigned char *buffer;
int size;
JOCTET terminal[2];
} my_source_mgr;
typedef my_source_mgr * my_src_ptr;
typedef my_source_mgr *my_src_ptr;
static void init_source(j_decompress_ptr cinfo)
{
@@ -179,25 +179,25 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t
if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_source_mgr));
((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_source_mgr));
}
src = (my_src_ptr) cinfo->src;
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart;
src->pub.term_source = term_source;
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart;
src->pub.term_source = term_source;
src->pub.bytes_in_buffer = size;
src->pub.next_input_byte = buffer;
src->pub.bytes_in_buffer = size;
src->pub.next_input_byte = buffer;
src->buffer = buffer;
src->size = size;
}
#define MAKESTMT(stuff) do { stuff } while (0)
#define MAKESTMT(stuff) do { stuff } while (0)
#define INPUT_VARS(cinfo) \
struct jpeg_source_mgr * datasrc = (cinfo)->src; \
@@ -229,7 +229,7 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t
/* Read a byte into variable V.
* If must suspend, take the specified action (typically "return FALSE").
*/
#define INPUT_BYTE(cinfo,V,action) \
#define INPUT_BYTE(cinfo, V, action) \
MAKESTMT(MAKE_BYTE_AVAIL(cinfo,action); \
bytes_in_buffer--; \
V = GETJOCTET(*next_input_byte++); )
@@ -237,17 +237,17 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t
/* As above, but read two bytes interpreted as an unsigned 16-bit integer.
* V should be declared unsigned int or perhaps INT32.
*/
#define INPUT_2BYTES(cinfo,V,action) \
#define INPUT_2BYTES(cinfo, V, action) \
MAKESTMT(MAKE_BYTE_AVAIL(cinfo,action); \
bytes_in_buffer--; \
V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
MAKE_BYTE_AVAIL(cinfo,action); \
MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \
V += GETJOCTET(*next_input_byte++); )
static boolean
handle_app1 (j_decompress_ptr cinfo)
handle_app1(j_decompress_ptr cinfo)
{
INT32 length; /* initialized by the macro */
INT32 i;
@@ -264,20 +264,20 @@ handle_app1 (j_decompress_ptr cinfo)
if (strncmp(neogeo, "NeoGeo", 6) == 0) memcpy(&ibuf_ftype, neogeo + 6, 4);
ibuf_ftype = BIG_LONG(ibuf_ftype);
}
INPUT_SYNC(cinfo); /* do before skip_input_data */
if (length > 0) (*cinfo->src->skip_input_data) (cinfo, length);
INPUT_SYNC(cinfo); /* do before skip_input_data */
if (length > 0) (*cinfo->src->skip_input_data)(cinfo, length);
return TRUE;
}
static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags)
static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags)
{
JSAMPARRAY row_pointer;
JSAMPLE * buffer = NULL;
JSAMPLE *buffer = NULL;
int row_stride;
int x, y, depth, r, g, b, k;
struct ImBuf * ibuf = NULL;
uchar * rect;
struct ImBuf *ibuf = NULL;
uchar *rect;
jpeg_saved_marker_ptr marker;
char *str, *key, *value;
@@ -314,7 +314,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
else {
row_stride = cinfo->output_width * depth;
row_pointer = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1);
row_pointer = (*cinfo->mem->alloc_sarray)((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1);
for (y = ibuf->y - 1; y >= 0; y--) {
jpeg_read_scanlines(cinfo, row_pointer, 1);
@@ -323,14 +323,14 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
switch (depth) {
case 1:
for (x=ibuf->x; x >0; x--) {
for (x = ibuf->x; x > 0; x--) {
rect[3] = 255;
rect[0] = rect[1] = rect[2] = *buffer++;
rect += 4;
}
break;
case 3:
for (x=ibuf->x; x >0; x--) {
for (x = ibuf->x; x > 0; x--) {
rect[3] = 255;
rect[0] = *buffer++;
rect[1] = *buffer++;
@@ -339,7 +339,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
}
break;
case 4:
for (x=ibuf->x; x >0; x--) {
for (x = ibuf->x; x > 0; x--) {
r = *buffer++;
g = *buffer++;
b = *buffer++;
@@ -371,7 +371,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
}
}
marker= cinfo->marker_list;
marker = cinfo->marker_list;
while (marker) {
if (marker->marker != JPEG_COM)
goto next_stamp_marker;
@@ -400,8 +400,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
goto next_stamp_marker;
}
str = BLI_strdup ((char *) marker->data);
key = strchr (str, ':');
str = BLI_strdup((char *) marker->data);
key = strchr(str, ':');
/*
* A little paranoid, but the file maybe
* is broken... and a "extra" check is better
@@ -413,7 +413,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
}
key++;
value = strchr (key, ':');
value = strchr(key, ':');
if (!value) {
MEM_freeN(str);
goto next_stamp_marker;
@@ -425,7 +425,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
ibuf->flags |= IB_metadata;
MEM_freeN(str);
next_stamp_marker:
marker= marker->next;
marker = marker->next;
}
jpeg_finish_decompress(cinfo);
@@ -441,11 +441,11 @@ next_stamp_marker:
return(ibuf);
}
ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags)
ImBuf *imb_load_jpeg(unsigned char *buffer, size_t size, int flags)
{
struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;
ImBuf * ibuf;
ImBuf *ibuf;
if (!imb_is_a_jpeg(buffer)) return NULL;
@@ -470,11 +470,11 @@ ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags)
}
static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf)
static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
{
JSAMPLE * buffer = NULL;
JSAMPLE *buffer = NULL;
JSAMPROW row_pointer[1];
uchar * rect;
uchar *rect;
int x, y;
char neogeo[128];
ImMetaData *iptr;
@@ -486,15 +486,15 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf)
ibuf_ftype = BIG_LONG(ibuf->ftype);
memcpy(neogeo + 6, &ibuf_ftype, 4);
jpeg_write_marker(cinfo, 0xe1, (JOCTET*) neogeo, 10);
jpeg_write_marker(cinfo, 0xe1, (JOCTET *) neogeo, 10);
if (ibuf->metadata) {
/* key + max value + "Blender" */
text= MEM_mallocN(530, "stamp info read");
iptr= ibuf->metadata;
text = MEM_mallocN(530, "stamp info read");
iptr = ibuf->metadata;
while (iptr) {
if (!strcmp (iptr->key, "None")) {
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen (iptr->value) + 1);
if (!strcmp(iptr->key, "None")) {
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen(iptr->value) + 1);
goto next_stamp_info;
}
@@ -507,8 +507,8 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf)
* The first "Blender" is a simple identify to help
* in the read process.
*/
sprintf (text, "Blender:%s:%s", iptr->key, iptr->value);
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, strlen (text)+1);
sprintf(text, "Blender:%s:%s", iptr->key, iptr->value);
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, strlen(text) + 1);
next_stamp_info:
iptr = iptr->next;
}
@@ -516,9 +516,9 @@ next_stamp_info:
}
row_pointer[0] =
MEM_mallocN(sizeof(JSAMPLE) *
cinfo->input_components *
cinfo->image_width, "jpeg row_pointer");
MEM_mallocN(sizeof(JSAMPLE) *
cinfo->input_components *
cinfo->image_width, "jpeg row_pointer");
for (y = ibuf->y - 1; y >= 0; y--) {
rect = (uchar *) (ibuf->rect + y * ibuf->x);
@@ -542,7 +542,7 @@ next_stamp_info:
case JCS_UNKNOWN:
memcpy(buffer, rect, 4 * ibuf->x);
break;
/* default was missing... intentional ? */
/* default was missing... intentional ? */
default:
; /* do nothing */
}
@@ -555,7 +555,7 @@ next_stamp_info:
}
static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct ImBuf *ibuf)
static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
{
int quality;
@@ -587,7 +587,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct
case JCS_UNKNOWN:
cinfo->input_components = 4;
break;
/* default was missing... intentional ? */
/* default was missing... intentional ? */
default:
; /* do nothing */
}
@@ -604,7 +604,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct
static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
{
FILE * outfile;
FILE *outfile;
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;
@@ -638,7 +638,7 @@ static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
static int save_vidjpeg(const char *name, struct ImBuf *ibuf)
{
FILE * outfile;
FILE *outfile;
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;
@@ -678,7 +678,7 @@ static int save_vidjpeg(const char *name, struct ImBuf *ibuf)
static int save_jstjpeg(const char *name, struct ImBuf *ibuf)
{
char fieldname[1024];
struct ImBuf * tbuf;
struct ImBuf *tbuf;
int oldy, returnval;
tbuf = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 24, IB_rect);
@@ -708,7 +708,7 @@ static int save_jstjpeg(const char *name, struct ImBuf *ibuf)
static int save_maxjpeg(const char *name, struct ImBuf *ibuf)
{
FILE * outfile;
FILE *outfile;
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;

View File

@@ -43,7 +43,7 @@
void IMB_metadata_free(struct ImBuf* img)
void IMB_metadata_free(struct ImBuf *img)
{
ImMetaData *info;
@@ -54,7 +54,7 @@ void IMB_metadata_free(struct ImBuf* img)
}
info = img->metadata;
while (info) {
ImMetaData* next = info->next;
ImMetaData *next = info->next;
MEM_freeN(info->key);
MEM_freeN(info->value);
MEM_freeN(info);
@@ -62,7 +62,7 @@ void IMB_metadata_free(struct ImBuf* img)
}
}
int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* field, int len)
int IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, int len)
{
ImMetaData *info;
int retval = 0;
@@ -84,7 +84,7 @@ int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* field, int
return retval;
}
int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* value)
int IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value)
{
ImMetaData *info;
ImMetaData *last;
@@ -121,7 +121,7 @@ int IMB_metadata_del_field(struct ImBuf *img, const char *key)
p = img->metadata;
p1 = NULL;
while (p) {
if (!strcmp (key, p->key)) {
if (!strcmp(key, p->key)) {
if (p1)
p1->next = p->next;
else
@@ -146,18 +146,18 @@ int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *fi
return (0);
if (!img->metadata)
return (IMB_metadata_add_field (img, key, field));
return (IMB_metadata_add_field(img, key, field));
p = img->metadata;
while (p) {
if (!strcmp (key, p->key)) {
MEM_freeN (p->value);
p->value = BLI_strdup (field);
if (!strcmp(key, p->key)) {
MEM_freeN(p->value);
p->value = BLI_strdup(field);
return (1);
}
p = p->next;
}
return (IMB_metadata_add_field (img, key, field));
return (IMB_metadata_add_field(img, key, field));
}

View File

@@ -60,9 +60,9 @@ ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags, const c
return NULL;
}
for (type=IMB_FILE_TYPES; type->is_a; type++) {
for (type = IMB_FILE_TYPES; type->is_a; type++) {
if (type->load) {
ibuf= type->load(mem, size, flags);
ibuf = type->load(mem, size, flags);
if (ibuf) {
if (flags & IB_premul) {
IMB_premultiply_alpha(ibuf);
@@ -87,15 +87,15 @@ ImBuf *IMB_loadifffile(int file, int flags, const char *descr)
if (file == -1) return NULL;
size= BLI_file_descriptor_size(file);
size = BLI_file_descriptor_size(file);
mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0);
if (mem==(unsigned char*)-1) {
mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0);
if (mem == (unsigned char *)-1) {
fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr);
return NULL;
}
ibuf= IMB_ibImageFromMemory(mem, size, flags, descr);
ibuf = IMB_ibImageFromMemory(mem, size, flags, descr);
if (munmap(mem, size))
fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr);
@@ -126,16 +126,16 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags)
imb_cache_filename(filepath_tx, filepath, flags);
file = BLI_open(filepath_tx, O_BINARY|O_RDONLY, 0);
file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0);
if (file < 0) return NULL;
ibuf= IMB_loadifffile(file, flags, filepath_tx);
ibuf = IMB_loadifffile(file, flags, 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));
for (a = 1; a < ibuf->miptot; a++)
BLI_strncpy(ibuf->mipmap[a - 1]->cachename, filepath_tx, sizeof(ibuf->cachename));
if (flags & IB_fields) IMB_de_interlace(ibuf);
}
@@ -152,10 +152,10 @@ ImBuf *IMB_testiffname(const char *filepath, int flags)
imb_cache_filename(filepath_tx, filepath, flags);
file = BLI_open(filepath_tx, O_BINARY|O_RDONLY, 0);
file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0);
if (file < 0) return NULL;
ibuf=IMB_loadifffile(file, flags|IB_test|IB_multilayer, filepath_tx);
ibuf = IMB_loadifffile(file, flags | IB_test | IB_multilayer, filepath_tx);
if (ibuf) {
BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name));
@@ -175,15 +175,15 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int
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);
if (mem==(unsigned char*)-1) {
mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0);
if (mem == (unsigned char *)-1) {
fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename);
return;
}
for (type=IMB_FILE_TYPES; type->is_a; type++)
for (type = IMB_FILE_TYPES; type->is_a; type++)
if (type->load_tile && type->ftype(type, ibuf))
type->load_tile(ibuf, mem, size, tx, ty, rect);
@@ -195,7 +195,7 @@ void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
{
int file;
file = BLI_open(ibuf->cachename, O_BINARY|O_RDONLY, 0);
file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0);
if (file < 0) return;
imb_loadtilefile(ibuf, file, tx, ty, rect);

View File

@@ -50,8 +50,7 @@
/***/
typedef struct TARGA
{
typedef struct TARGA {
unsigned char numid;
unsigned char maptyp;
unsigned char imgtyp;
@@ -72,27 +71,27 @@ static int tga_out1(unsigned int data, FILE *file)
{
uchar *p;
p = (uchar *) & data;
p = (uchar *) &data;
if (putc(p[0], file) == EOF) return(EOF);
return (~EOF);
}
static int tga_out2(unsigned int data, FILE * file)
static int tga_out2(unsigned int data, FILE *file)
{
uchar *p;
p = (uchar *) & data;
p = (uchar *) &data;
if (putc(p[0], file) == EOF) return(EOF);
if (putc(p[1], file) == EOF) return(EOF);
return (~EOF);
}
static int tga_out3(unsigned int data, FILE * file)
static int tga_out3(unsigned int data, FILE *file)
{
uchar *p;
p = (uchar *) & data;
p = (uchar *) &data;
if (putc(p[2], file) == EOF) return(EOF);
if (putc(p[1], file) == EOF) return(EOF);
if (putc(p[0], file) == EOF) return(EOF);
@@ -100,11 +99,11 @@ static int tga_out3(unsigned int data, FILE * file)
}
static int tga_out4(unsigned int data, FILE * file)
static int tga_out4(unsigned int data, FILE *file)
{
uchar *p;
p = (uchar *) & data;
p = (uchar *) &data;
/* order = bgra */
if (putc(p[2], file) == EOF) return(EOF);
if (putc(p[1], file) == EOF) return(EOF);
@@ -113,7 +112,7 @@ static int tga_out4(unsigned int data, FILE * file)
return (~EOF);
}
static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FILE*))
static short makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE *))
{
register int last, this;
register int copy, bytes;
@@ -125,22 +124,22 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
rectstart = rect = ibuf->rect + (y * ibuf->x);
last = *rect++;
this = *rect++;
copy = last^this;
copy = last ^ this;
while (bytes > 0) {
if (copy) {
do {
last = this;
this = *rect++;
if (last == this) {
if (this == rect[-3]) { /* three the same? */
bytes --; /* set bytes */
if (this == rect[-3]) { /* three the same? */
bytes--; /* set bytes */
break;
}
}
} while (--bytes != 0);
copy = rect-rectstart;
copy --;
copy = rect - rectstart;
copy--;
if (bytes) copy -= 2;
temp = rect;
@@ -148,9 +147,9 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
while (copy) {
last = copy;
if (copy>=128) last = 128;
if (copy >= 128) last = 128;
copy -= last;
if (fputc(last-1, file) == EOF) return(0);
if (fputc(last - 1, file) == EOF) return(0);
do {
if (out(*rect++, file) == EOF) return(0);
} while (--last != 0);
@@ -162,17 +161,17 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
copy = FALSE;
}
else {
while (*rect++ == this) { /* seek for first different byte */
if (--bytes == 0) break; /* oor end of line */
while (*rect++ == this) { /* seek for first different byte */
if (--bytes == 0) break; /* oor end of line */
}
rect --;
copy = rect-rectstart;
rect--;
copy = rect - rectstart;
rectstart = rect;
bytes --;
bytes--;
this = *rect++;
while (copy) {
if (copy>128) {
if (copy > 128) {
if (fputc(255, file) == EOF) return(0);
copy -= 128;
}
@@ -185,14 +184,14 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
}
if (out(last, file) == EOF) return(0);
}
copy=TRUE;
copy = TRUE;
}
}
}
return (1);
}
static int dumptarga(struct ImBuf * ibuf, FILE * file)
static int dumptarga(struct ImBuf *ibuf, FILE *file)
{
int size;
uchar *rect;
@@ -243,16 +242,16 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file)
}
int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
int imb_savetarga(struct ImBuf *ibuf, const char *name, int flags)
{
char buf[20]= {0};
char buf[20] = {0};
FILE *fildes;
short ok = 0;
(void)flags; /* unused */
buf[16] = (ibuf->planes + 0x7 ) & ~0x7;
if (ibuf->planes > 8 ) {
buf[16] = (ibuf->planes + 0x7) & ~0x7;
if (ibuf->planes > 8) {
buf[2] = 10;
}
else {
@@ -273,11 +272,11 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
/* Don't forget to indicate that your 32 bit
* targa uses 8 bits for the alpha channel! */
if (ibuf->planes==32) {
if (ibuf->planes == 32) {
buf[17] |= 0x08;
}
fildes = BLI_fopen(name, "wb");
if (!fildes) return 0;
if (!fildes) return 0;
if (fwrite(buf, 1, 18, fildes) != 18) {
fclose(fildes);
@@ -289,18 +288,18 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
}
else {
switch ((ibuf->planes + 7) >> 3) {
case 1:
ok = makebody_tga(ibuf, fildes, tga_out1);
break;
case 2:
ok = makebody_tga(ibuf, fildes, tga_out2);
break;
case 3:
ok = makebody_tga(ibuf, fildes, tga_out3);
break;
case 4:
ok = makebody_tga(ibuf, fildes, tga_out4);
break;
case 1:
ok = makebody_tga(ibuf, fildes, tga_out1);
break;
case 2:
ok = makebody_tga(ibuf, fildes, tga_out2);
break;
case 3:
ok = makebody_tga(ibuf, fildes, tga_out3);
break;
case 4:
ok = makebody_tga(ibuf, fildes, tga_out4);
break;
}
}
@@ -315,27 +314,27 @@ static int checktarga(TARGA *tga, unsigned char *mem)
tga->maptyp = mem[1];
tga->imgtyp = mem[2];
tga->maporig = GSS(mem+3);
tga->mapsize = GSS(mem+5);
tga->maporig = GSS(mem + 3);
tga->mapsize = GSS(mem + 5);
tga->mapbits = mem[7];
tga->xorig = GSS(mem+8);
tga->yorig = GSS(mem+10);
tga->xsize = GSS(mem+12);
tga->ysize = GSS(mem+14);
tga->xorig = GSS(mem + 8);
tga->yorig = GSS(mem + 10);
tga->xsize = GSS(mem + 12);
tga->ysize = GSS(mem + 14);
tga->pixsize = mem[16];
tga->imgdes = mem[17];
if (tga->maptyp > 1) return(0);
switch (tga->imgtyp) {
case 1: /* raw cmap */
case 2: /* raw rgb */
case 3: /* raw b&w */
case 9: /* cmap */
case 10: /* rgb */
case 11: /* b&w */
break;
default:
return(0);
case 1: /* raw cmap */
case 2: /* raw rgb */
case 3: /* raw b&w */
case 9: /* cmap */
case 10: /* rgb */
case 11: /* b&w */
break;
default:
return(0);
}
if (tga->mapsize && tga->mapbits > 32) return(0);
if (tga->xsize <= 0 || tga->xsize >= 8192) return(0);
@@ -356,7 +355,7 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
{
int size = (ibuf->x * ibuf->y) - (rect - ibuf->rect);
if (size) {
printf("decodetarga: incomplete file, %.1f%% missing\n", 100*((float)size / (ibuf->x * ibuf->y)));
printf("decodetarga: incomplete file, %.1f%% missing\n", 100 * ((float)size / (ibuf->x * ibuf->y)));
/* not essential but makes displaying partially rendered TGA's less ugly */
memset(rect, 0, size);
@@ -369,10 +368,10 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
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;
unsigned int *rect;
uchar * cp = (uchar *) &col;
uchar *cp = (uchar *) &col;
if (ibuf == NULL) return;
if (ibuf->rect == NULL) return;
@@ -387,7 +386,7 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size,
while (size > 0) {
count = *mem++;
if (mem>mem_end)
if (mem > mem_end)
goto partial_load;
if (count >= 128) {
@@ -432,7 +431,7 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size,
}
}
else {
count ++;
count++;
size -= count;
if (size >= 0) {
while (count > 0) {
@@ -465,13 +464,13 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size,
}
}
*rect++ = col;
count --;
count--;
if (mem>mem_end)
if (mem > mem_end)
goto partial_load;
}
if (mem>mem_end)
if (mem > mem_end)
goto partial_load;
}
}
@@ -485,12 +484,12 @@ partial_load:
complete_partial_load(ibuf, rect);
}
static void ldtarga(struct ImBuf * ibuf, unsigned char * mem, size_t 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;
unsigned int *rect;
uchar * cp = (uchar *) &col;
uchar *cp = (uchar *) &col;
if (ibuf == NULL) return;
if (ibuf->rect == NULL) return;
@@ -503,7 +502,7 @@ static void ldtarga(struct ImBuf * ibuf, unsigned char * mem, size_t mem_size, i
cp[1] = cp[2] = 0;
while (size > 0) {
if (mem>mem_end)
if (mem > mem_end)
goto partial_load;
if (psize & 2) {
@@ -545,13 +544,12 @@ partial_load:
}
struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
{
struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags){
TARGA tga;
struct ImBuf * ibuf;
struct ImBuf *ibuf;
int col, count, size;
unsigned int *rect, *cmap= NULL /*, mincol= 0*/, maxcol= 0;
uchar * cp = (uchar *) &col;
unsigned int *rect, *cmap = NULL /*, mincol= 0*/, maxcol = 0;
uchar *cp = (uchar *) &col;
if (checktarga(&tga, mem) == 0) return(NULL);
@@ -570,9 +568,9 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
/* load color map */
/*mincol = tga.maporig;*/ /*UNUSED*/
maxcol = tga.mapsize;
cmap = MEM_callocN(sizeof(unsigned int)*maxcol, "targa cmap");
cmap = MEM_callocN(sizeof(unsigned int) * maxcol, "targa cmap");
for (count = 0 ; count < maxcol ; count ++) {
for (count = 0; count < maxcol; count++) {
switch (tga.mapbits >> 3) {
case 4:
cp[0] = mem[3];
@@ -603,7 +601,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
for (col = maxcol - 1; col > 0; col >>= 1) size++;
ibuf->planes = size;
if (tga.mapbits != 32) { /* set alpha bits */
if (tga.mapbits != 32) { /* set alpha bits */
cmap[0] &= BIG_LONG(0x00ffffffl);
}
}
@@ -613,33 +611,33 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
if (tga.imgtyp != 1 && tga.imgtyp != 9) { /* happens sometimes (beuh) */
if (cmap) {
MEM_freeN(cmap);
cmap= NULL;
cmap = NULL;
}
}
switch (tga.imgtyp) {
case 1:
case 2:
case 3:
if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0);
else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1);
else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2);
else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3);
break;
case 9:
case 10:
case 11:
if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0);
else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1);
else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2);
else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3);
break;
case 1:
case 2:
case 3:
if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0);
else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1);
else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2);
else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3);
break;
case 9:
case 10:
case 11:
if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0);
else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1);
else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2);
else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3);
break;
}
if (cmap) {
/* apply color map */
rect = ibuf->rect;
for (size = ibuf->x * ibuf->y; size>0; --size, ++rect) {
for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) {
col = *rect;
if (col >= 0 && col < maxcol) *rect = cmap[col];
}
@@ -651,8 +649,8 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
rect = ibuf->rect;
for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) {
col = *rect;
cp = (uchar*)rect;
mem = (uchar*)&col;
cp = (uchar *)rect;
mem = (uchar *)&col;
cp[3] = ((mem[1] << 1) & 0xf8);
cp[2] = ((mem[0] & 0xe0) >> 2) + ((mem[1] & 0x03) << 6);
@@ -672,7 +670,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
crect = (uchar *) ibuf->rect;
lrect = (unsigned int *) ibuf->rect;
for (size = ibuf->x * ibuf->y; size > 0; size --) {
for (size = ibuf->x * ibuf->y; size > 0; size--) {
col = *lrect++;
crect[0] = 255;

View File

@@ -93,7 +93,8 @@ const char *imb_ext_image[] = {
#ifdef WITH_OPENEXR
".exr",
#endif
NULL};
NULL
};
const char *imb_ext_image_qt[] = {
".gif",
@@ -101,7 +102,8 @@ const char *imb_ext_image_qt[] = {
".pct", ".pict",
".pntg",
".qtif",
NULL};
NULL
};
const char *imb_ext_movie[] = {
".avi",
@@ -128,7 +130,8 @@ const char *imb_ext_movie[] = {
".divx",
".xvid",
".mxf",
NULL};
NULL
};
/* sort of wrong being here... */
const char *imb_ext_audio[] = {
@@ -145,7 +148,8 @@ const char *imb_ext_audio[] = {
".aif",
".aiff",
".m4a",
NULL};
NULL
};
static int IMB_ispic_name(const char *name)
{
@@ -160,7 +164,7 @@ static int IMB_ispic_name(const char *name)
if (((st.st_mode) & S_IFMT) != S_IFREG)
return FALSE;
if ((fp = BLI_open(name, O_BINARY|O_RDONLY, 0)) < 0)
if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) < 0)
return FALSE;
if (read(fp, buf, 32) != 32) {
@@ -174,8 +178,8 @@ static int IMB_ispic_name(const char *name)
if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0)
return JPG;
for (type=IMB_FILE_TYPES; type->is_a; type++)
if (type->is_a((uchar*)buf))
for (type = IMB_FILE_TYPES; type->is_a; type++)
if (type->is_a((uchar *)buf))
return type->filetype;
return FALSE;
@@ -184,9 +188,9 @@ static int IMB_ispic_name(const char *name)
int IMB_ispic(const char *filename)
{
if (U.uiflag & USER_FILTERFILEEXTS) {
if ( (BLI_testextensie_array(filename, imb_ext_image)) ||
(G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt))
) {
if ( (BLI_testextensie_array(filename, imb_ext_image)) ||
(G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt))
) {
return IMB_ispic_name(filename);
}
else {
@@ -200,15 +204,15 @@ int IMB_ispic(const char *filename)
static int isavi (const char *name)
static int isavi(const char *name)
{
return AVI_is_avi (name);
return AVI_is_avi(name);
}
#ifdef WITH_QUICKTIME
static int isqtime (const char *name)
static int isqtime(const char *name)
{
return anim_is_quicktime (name);
return anim_is_quicktime(name);
}
#endif
@@ -241,7 +245,7 @@ void do_init_ffmpeg(void)
}
}
static int isffmpeg (const char *filename)
static int isffmpeg(const char *filename)
{
AVFormatContext *pFormatCtx;
unsigned int i;
@@ -252,24 +256,24 @@ static int isffmpeg (const char *filename)
do_init_ffmpeg();
if (BLI_testextensie(filename, ".swf") ||
BLI_testextensie(filename, ".jpg") ||
BLI_testextensie(filename, ".png") ||
BLI_testextensie(filename, ".dds") ||
BLI_testextensie(filename, ".tga") ||
BLI_testextensie(filename, ".bmp") ||
BLI_testextensie(filename, ".exr") ||
BLI_testextensie(filename, ".cin") ||
BLI_testextensie(filename, ".jpg") ||
BLI_testextensie(filename, ".png") ||
BLI_testextensie(filename, ".dds") ||
BLI_testextensie(filename, ".tga") ||
BLI_testextensie(filename, ".bmp") ||
BLI_testextensie(filename, ".exr") ||
BLI_testextensie(filename, ".cin") ||
BLI_testextensie(filename, ".wav"))
{
return 0;
}
if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) {
if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL) != 0) {
if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n");
return 0;
}
if (av_find_stream_info(pFormatCtx)<0) {
if (av_find_stream_info(pFormatCtx) < 0) {
if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_find_stream_info failed\n");
av_close_input_file(pFormatCtx);
return 0;
@@ -278,32 +282,32 @@ static int isffmpeg (const char *filename)
if (UTIL_DEBUG) av_dump_format(pFormatCtx, 0, filename, 0);
/* Find the first video stream */
videoStream=-1;
for (i=0; i<pFormatCtx->nb_streams; i++)
/* Find the first video stream */
videoStream = -1;
for (i = 0; i < pFormatCtx->nb_streams; i++)
if (pFormatCtx->streams[i] &&
pFormatCtx->streams[i]->codec &&
(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO))
pFormatCtx->streams[i]->codec &&
(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO))
{
videoStream=i;
videoStream = i;
break;
}
if (videoStream==-1) {
if (videoStream == -1) {
av_close_input_file(pFormatCtx);
return 0;
}
pCodecCtx = pFormatCtx->streams[videoStream]->codec;
/* Find the decoder for the video stream */
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec==NULL) {
/* Find the decoder for the video stream */
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec == NULL) {
av_close_input_file(pFormatCtx);
return 0;
}
if (avcodec_open(pCodecCtx, pCodec)<0) {
if (avcodec_open(pCodecCtx, pCodec) < 0) {
av_close_input_file(pFormatCtx);
return 0;
}
@@ -316,9 +320,9 @@ static int isffmpeg (const char *filename)
#endif
#ifdef WITH_REDCODE
static int isredcode(const char * filename)
static int isredcode(const char *filename)
{
struct redcode_handle * h = redcode_open(filename);
struct redcode_handle *h = redcode_open(filename);
if (!h) {
return 0;
}
@@ -328,7 +332,7 @@ static int isredcode(const char * filename)
#endif
int imb_get_anim_type(const char * name)
int imb_get_anim_type(const char *name)
{
int type;
struct stat st;
@@ -336,13 +340,13 @@ int imb_get_anim_type(const char * name)
if (UTIL_DEBUG) printf("in getanimtype: %s\n", name);
#ifndef _WIN32
# ifdef WITH_QUICKTIME
# ifdef WITH_QUICKTIME
if (isqtime(name)) return (ANIM_QTIME);
# endif
# ifdef WITH_FFMPEG
# endif
# ifdef WITH_FFMPEG
/* stat test below fails on large files > 4GB */
if (isffmpeg(name)) return (ANIM_FFMPEG);
# endif
# endif
if (BLI_stat(name, &st) == -1) return(0);
if (((st.st_mode) & S_IFMT) != S_IFREG) return(0);
@@ -354,12 +358,12 @@ int imb_get_anim_type(const char * name)
if (((st.st_mode) & S_IFMT) != S_IFREG) return(0);
if (ismovie(name)) return (ANIM_MOVIE);
# ifdef WITH_QUICKTIME
# ifdef WITH_QUICKTIME
if (isqtime(name)) return (ANIM_QTIME);
# endif
# ifdef WITH_FFMPEG
# endif
# ifdef WITH_FFMPEG
if (isffmpeg(name)) return (ANIM_FFMPEG);
# endif
# endif
if (isavi(name)) return (ANIM_AVI);
@@ -412,5 +416,5 @@ int IMB_isanim(const char *filename)
type = imb_get_anim_type(filename);
}
return (type && type!=ANIM_SEQUENCE);
return (type && type != ANIM_SEQUENCE);
}