diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-05-07 19:18:04 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-05-07 19:18:04 +0400 |
commit | 008863daec1249d1f17bc69e1105e336db690d63 (patch) | |
tree | 78a4001857b26a287125a3f5fa31496052f6ebdd /source/blender/imbuf/intern/jpeg.c | |
parent | 1613829e8e821321da99cad4790b7e6a1d90cea8 (diff) |
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
Diffstat (limited to 'source/blender/imbuf/intern/jpeg.c')
-rw-r--r-- | source/blender/imbuf/intern/jpeg.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 127145c967d..3803aa9a8b2 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -34,17 +34,24 @@ #include <stdio.h> #include <setjmp.h> +#include "MEM_guardedalloc.h" + #include "BLI_blenlib.h" #include "imbuf.h" -#include "imbuf_patch.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" -#include "IMB_imginfo.h" -#include "IMB_jpeg.h" +#include "IMB_metadata.h" +#include "IMB_filetype.h" #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) + /* the types are from the jpeg lib */ static void jpeg_error (j_common_ptr cinfo); static void init_source(j_decompress_ptr cinfo); @@ -297,11 +304,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f for (y = ibuf->y - 1; y >= 0; y--) { jpeg_read_scanlines(cinfo, row_pointer, 1); - if (flags & IB_ttob) { - rect = (uchar *) (ibuf->rect + (ibuf->y - 1 - y) * ibuf->x); - } else { - rect = (uchar *) (ibuf->rect + y * ibuf->x); - } + rect = (uchar *) (ibuf->rect + y * ibuf->x); buffer = row_pointer[0]; switch(depth) { @@ -378,8 +381,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f * the information when we write * it back to disk. */ - IMB_imginfo_add_field(ibuf, "None", (char *) marker->data); - ibuf->flags |= IB_imginfo; + IMB_metadata_add_field(ibuf, "None", (char *) marker->data); + ibuf->flags |= IB_metadata; goto next_stamp_marker; } @@ -404,8 +407,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f *value = '\0'; /* need finish the key string */ value++; - IMB_imginfo_add_field(ibuf, key, value); - ibuf->flags |= IB_imginfo; + IMB_metadata_add_field(ibuf, key, value); + ibuf->flags |= IB_metadata; MEM_freeN(str); next_stamp_marker: marker= marker->next; @@ -453,11 +456,13 @@ ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags) return(ibuf); } -ImBuf * imb_ibJpegImageFromMemory (unsigned char * buffer, int size, int flags) +ImBuf * imb_load_jpeg (unsigned char * buffer, int size, int flags) { struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo; struct my_error_mgr jerr; ImBuf * ibuf; + + if(!imb_is_a_jpeg(buffer)) return NULL; cinfo->err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = jpeg_error; @@ -487,7 +492,7 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) uchar * rect; int x, y; char neogeo[128]; - ImgInfo *iptr; + ImMetaData *iptr; char *text; jpeg_start_compress(cinfo, TRUE); @@ -498,10 +503,10 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) memcpy(neogeo + 6, &ibuf_ftype, 4); jpeg_write_marker(cinfo, 0xe1, (JOCTET*) neogeo, 10); - if(ibuf->img_info) { + if(ibuf->metadata) { /* key + max value + "Blender" */ text= MEM_mallocN(530, "stamp info read"); - iptr= ibuf->img_info; + iptr= ibuf->metadata; while(iptr) { if (!strcmp (iptr->key, "None")) { jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen (iptr->value) + 1); @@ -526,9 +531,9 @@ next_stamp_info: } row_pointer[0] = - mallocstruct(JSAMPLE, + MEM_mallocN(sizeof(JSAMPLE) * cinfo->input_components * - cinfo->image_width); + cinfo->image_width, "jpeg row_pointer"); for(y = ibuf->y - 1; y >= 0; y--){ rect = (uchar *) (ibuf->rect + y * ibuf->x); @@ -561,7 +566,7 @@ next_stamp_info: } jpeg_finish_compress(cinfo); - free(row_pointer[0]); + MEM_freeN(row_pointer[0]); } @@ -580,7 +585,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct cinfo->image_height = ibuf->y; cinfo->in_color_space = JCS_RGB; - if (ibuf->depth == 8 && ibuf->cmap == 0) cinfo->in_color_space = JCS_GRAYSCALE; + if (ibuf->depth == 8) cinfo->in_color_space = JCS_GRAYSCALE; if (ibuf->depth == 32) cinfo->in_color_space = JCS_UNKNOWN; switch(cinfo->in_color_space){ |