diff options
Diffstat (limited to 'source/blender/imbuf/intern/jpeg.c')
-rw-r--r-- | source/blender/imbuf/intern/jpeg.c | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index f3a382eaa56..1a96e55e3d1 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -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; |