Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/CMakeLists.txt42
-rw-r--r--source/blender/imbuf/IMB_imbuf.h264
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h212
-rw-r--r--source/blender/imbuf/IMB_thumbs.h11
-rw-r--r--source/blender/imbuf/Makefile2
-rw-r--r--source/blender/imbuf/SConscript12
-rw-r--r--source/blender/imbuf/intern/IMB_amiga.h47
-rw-r--r--source/blender/imbuf/intern/IMB_anim.h19
-rw-r--r--source/blender/imbuf/intern/IMB_anim5.h20
-rw-r--r--source/blender/imbuf/intern/IMB_bitplanes.h47
-rw-r--r--source/blender/imbuf/intern/IMB_bmp.h47
-rw-r--r--source/blender/imbuf/intern/IMB_cmap.h46
-rw-r--r--source/blender/imbuf/intern/IMB_cocoa.h43
-rw-r--r--source/blender/imbuf/intern/IMB_divers.h45
-rw-r--r--source/blender/imbuf/intern/IMB_dpxcineon.h47
-rw-r--r--source/blender/imbuf/intern/IMB_filetype.h121
-rw-r--r--source/blender/imbuf/intern/IMB_filter.h3
-rw-r--r--source/blender/imbuf/intern/IMB_hamx.h47
-rw-r--r--source/blender/imbuf/intern/IMB_iff.h46
-rw-r--r--source/blender/imbuf/intern/IMB_iris.h46
-rw-r--r--source/blender/imbuf/intern/IMB_jp2.h49
-rw-r--r--source/blender/imbuf/intern/IMB_jpeg.h49
-rw-r--r--source/blender/imbuf/intern/IMB_metadata.h (renamed from source/blender/imbuf/intern/IMB_imginfo.h)29
-rw-r--r--source/blender/imbuf/intern/IMB_png.h48
-rw-r--r--source/blender/imbuf/intern/IMB_radiance_hdr.h42
-rw-r--r--source/blender/imbuf/intern/IMB_targa.h48
-rw-r--r--source/blender/imbuf/intern/IMB_tiff.h45
-rw-r--r--source/blender/imbuf/intern/Makefile19
-rw-r--r--source/blender/imbuf/intern/allocimbuf.c406
-rw-r--r--source/blender/imbuf/intern/amiga.c540
-rw-r--r--source/blender/imbuf/intern/anim.c393
-rw-r--r--source/blender/imbuf/intern/anim5.c539
-rw-r--r--source/blender/imbuf/intern/antialias.c466
-rw-r--r--source/blender/imbuf/intern/bitplanes.c356
-rw-r--r--source/blender/imbuf/intern/bmp.c8
-rw-r--r--source/blender/imbuf/intern/cache.c444
-rw-r--r--source/blender/imbuf/intern/cineon/CMakeLists.txt1
-rw-r--r--source/blender/imbuf/intern/cineon/Makefile2
-rw-r--r--source/blender/imbuf/intern/cineon/cineon_dpx.c6
-rw-r--r--source/blender/imbuf/intern/cmap.c580
-rw-r--r--source/blender/imbuf/intern/cspace.c176
-rw-r--r--source/blender/imbuf/intern/data.c142
-rw-r--r--source/blender/imbuf/intern/dds/CMakeLists.txt5
-rw-r--r--source/blender/imbuf/intern/dds/Makefile2
-rw-r--r--source/blender/imbuf/intern/dds/dds_api.cpp6
-rw-r--r--source/blender/imbuf/intern/dds/dds_api.h2
-rw-r--r--source/blender/imbuf/intern/dither.c130
-rw-r--r--source/blender/imbuf/intern/divers.c151
-rw-r--r--source/blender/imbuf/intern/dynlibtiff.c249
-rw-r--r--source/blender/imbuf/intern/dynlibtiff.h55
-rw-r--r--source/blender/imbuf/intern/filetype.c106
-rw-r--r--source/blender/imbuf/intern/filter.c96
-rwxr-xr-xsource/blender/imbuf/intern/gen_dynlibtiff.py303
-rw-r--r--source/blender/imbuf/intern/ham.c276
-rw-r--r--source/blender/imbuf/intern/hamx.c581
-rw-r--r--source/blender/imbuf/intern/iff.c224
-rw-r--r--source/blender/imbuf/intern/imageprocess.c10
-rw-r--r--source/blender/imbuf/intern/imbuf.h93
-rw-r--r--source/blender/imbuf/intern/imbuf_cocoa.m4
-rw-r--r--source/blender/imbuf/intern/imbuf_patch.h111
-rw-r--r--source/blender/imbuf/intern/iris.c53
-rw-r--r--source/blender/imbuf/intern/jp2.c68
-rw-r--r--source/blender/imbuf/intern/jpeg.c50
-rw-r--r--source/blender/imbuf/intern/matrix.h84
-rw-r--r--source/blender/imbuf/intern/md5.c4
-rw-r--r--source/blender/imbuf/intern/metadata.c (renamed from source/blender/imbuf/intern/imginfo.c)61
-rw-r--r--source/blender/imbuf/intern/module.c (renamed from source/blender/imbuf/intern/IMB_ham.h)33
-rw-r--r--source/blender/imbuf/intern/openexr/CMakeLists.txt5
-rw-r--r--source/blender/imbuf/intern/openexr/Makefile2
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp186
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.h2
-rw-r--r--source/blender/imbuf/intern/png.c48
-rw-r--r--source/blender/imbuf/intern/radiance_hdr.c15
-rw-r--r--source/blender/imbuf/intern/readimage.c326
-rw-r--r--source/blender/imbuf/intern/rectop.c1
-rw-r--r--source/blender/imbuf/intern/rotate.c4
-rw-r--r--source/blender/imbuf/intern/scaling.c190
-rw-r--r--source/blender/imbuf/intern/targa.c93
-rw-r--r--source/blender/imbuf/intern/thumbs.c64
-rw-r--r--source/blender/imbuf/intern/thumbs_blend.c192
-rw-r--r--source/blender/imbuf/intern/tiff.c502
-rw-r--r--source/blender/imbuf/intern/util.c259
-rw-r--r--source/blender/imbuf/intern/writeimage.c172
83 files changed, 2630 insertions, 7743 deletions
diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt
index 9cb98c258de..49886bdc46f 100644
--- a/source/blender/imbuf/CMakeLists.txt
+++ b/source/blender/imbuf/CMakeLists.txt
@@ -28,22 +28,35 @@ FILE(GLOB SRC intern/*.c)
SET(INC
- . ../makesdna ../../../intern/guardedalloc ../../../intern/memutil ../blenlib
- ../avi ../blenkernel
+ .
+ ../makesdna
+ ../../../intern/guardedalloc
+ ../../../intern/memutil
+ ../blenlib
+ ../avi
+ ../blenkernel
${JPEG_INC}
${PNG_INC}
- ${TIFF_INC}
${ZLIB_INC}
- ${OPENJPEG_INC}
)
-IF(WITH_OPENEXR)
+IF(WIN32)
+ SET(INC ${INC} ${PTHREADS_INC})
+ENDIF(WIN32)
+
+IF(WITH_IMAGE_OPENEXR)
ADD_DEFINITIONS(-DWITH_OPENEXR)
-ENDIF(WITH_OPENEXR)
+ENDIF(WITH_IMAGE_OPENEXR)
+
+IF(WITH_IMAGE_TIFF)
+ SET(INC ${INC} ${TIFF_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_TIFF)
+ENDIF(WITH_IMAGE_TIFF)
-IF(WITH_OPENJPEG)
+IF(WITH_IMAGE_OPENJPEG)
+ SET(INC ${INC} ${OPENJPEG_INC})
ADD_DEFINITIONS(-DWITH_OPENJPEG)
-ENDIF(WITH_OPENJPEG)
+ENDIF(WITH_IMAGE_OPENJPEG)
IF(WITH_QUICKTIME)
SET(INC ${INC} ../quicktime ${QUICKTIME_INC})
@@ -55,9 +68,16 @@ IF(WITH_FFMPEG)
ADD_DEFINITIONS(-DWITH_FFMPEG)
ENDIF(WITH_FFMPEG)
-IF(WITH_DDS)
+IF(WITH_IMAGE_DDS)
ADD_DEFINITIONS(-DWITH_DDS)
-ENDIF(WITH_DDS)
+ENDIF(WITH_IMAGE_DDS)
+
+IF(WITH_IMAGE_CINEON)
+ ADD_DEFINITIONS(-DWITH_CINEON)
+ENDIF(WITH_IMAGE_CINEON)
+
+IF(WITH_IMAGE_HDR)
+ ADD_DEFINITIONS(-DWITH_HDR)
+ENDIF(WITH_IMAGE_HDR)
BLENDERLIB(bf_imbuf "${SRC}" "${INC}")
-#env.BlenderLib ( libname = 'bf_imbuf', sources = sources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [80, 40] )
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 14c58496352..07b99dddfa5 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -37,40 +37,6 @@
* blenlib handles guarded memory management in blender-style.
* BLI_winstuff.h makes a few windows specific behaviours
* posix-compliant.
- * - avi
- * avi defines import/export to the avi format. Only anim.c
- * needs this. It uses the following functions:
- * - avi_close
- * - avi_is_avi
- * - avi_print_error
- * - avi_open_movie
- * - avi_read_frame
- * - avi_get_stream
- * Additionally, it needs the types from the avi module.
- * - external jpeg library
- * The jpeg lib defines import/export to the jpeg format.
- * only jpeg.c needs these. Used functions are:
- * - jpeg_destroy
- * - jpeg_resync_to_restart
- * - jpeg_set_marker_processor
- * - jpeg_read_header
- * - jpeg_start_decompress
- * - jpeg_abort_decompress
- * - jpeg_read_scanlines
- * - jpeg_finish_decompress
- * - jpeg_std_error
- * - jpeg_create_decompress
- * - jpeg_stdio_src
- * - jpeg_start_compress
- * - jpeg_write_marker
- * - jpeg_write_scanlines
- * - jpeg_finish_compress
- * - jpeg_create_compress
- * - jpeg_stdio_dest
- * - jpeg_set_defaults
- * - jpeg_set_quality
- * - jpeg_destroy_compress
- * Additionally, it needs the types from the jpeg lib.
*/
/*
* $Id$
@@ -100,6 +66,7 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
#ifndef IMB_IMBUF_H
#define IMB_IMBUF_H
@@ -117,33 +84,16 @@ struct anim;
/**
*
- * @attention Defined in cmap.c
- */
-void IMB_freeImBufdata(void);
-
-/**
- *
- * @attention Defined in cmap.c
- */
-void IMB_applycmap(struct ImBuf *ibuf);
-
-/**
- *
- * @attention Defined in cmap.c
- */
-short IMB_converttocmap(struct ImBuf *ibuf);
-
-/**
- *
- * @attention Defined in cmap.c
+ * @attention Defined in allocimbuf.c
*/
-int IMB_alpha_to_col0(int value);
+void IMB_init(void);
+void IMB_exit(void);
/**
*
* @attention Defined in readimage.c
*/
-struct ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags);
+struct ImBuf *IMB_ibImageFromMemory(unsigned char *mem, int size, int flags);
/**
*
@@ -161,7 +111,7 @@ struct ImBuf *IMB_loadiffname(const char *naam, int flags);
*
* @attention Defined in allocimbuf.c
*/
-void IMB_freeImBuf(struct ImBuf * ibuf);
+void IMB_freeImBuf(struct ImBuf *ibuf);
/**
*
@@ -180,37 +130,33 @@ struct ImBuf *IMB_allocImBuf(short x, short y,
* @attention Defined in allocimbuf.c
*/
-void IMB_refImBuf(struct ImBuf * ibuf);
+void IMB_refImBuf(struct ImBuf *ibuf);
/**
*
* @attention Defined in allocimbuf.c
*/
-void IMB_cache_limiter_insert(struct ImBuf * i);
-void IMB_cache_limiter_unmanage(struct ImBuf * i);
-void IMB_cache_limiter_touch(struct ImBuf * i);
-void IMB_cache_limiter_ref(struct ImBuf * i);
-void IMB_cache_limiter_unref(struct ImBuf * i);
-int IMB_cache_limiter_get_refcount(struct ImBuf * i);
+void IMB_cache_limiter_insert(struct ImBuf *i);
+void IMB_cache_limiter_unmanage(struct ImBuf *i);
+void IMB_cache_limiter_touch(struct ImBuf *i);
+void IMB_cache_limiter_ref(struct ImBuf *i);
+void IMB_cache_limiter_unref(struct ImBuf *i);
+int IMB_cache_limiter_get_refcount(struct ImBuf *i);
-/**
- *
- * @attention Defined in allocimbuf.c
- */
-struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1);
+void IMB_free_cache_limiter(void);
/**
*
* @attention Defined in allocimbuf.c
*/
-short addzbufImBuf(struct ImBuf * ibuf);
-short addzbuffloatImBuf(struct ImBuf * ibuf);
+struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1);
/**
*
* @attention Defined in allocimbuf.c
*/
-void IMB_freecmapImBuf(struct ImBuf * ibuf);
+short addzbufImBuf(struct ImBuf *ibuf);
+short addzbuffloatImBuf(struct ImBuf *ibuf);
/**
*
@@ -253,8 +199,8 @@ int IMB_anim_get_duration(struct anim *anim);
*
* @attention Defined in anim.c
*/
-struct anim * IMB_open_anim(const char * name, int ib_flags);
-void IMB_close_anim(struct anim * anim);
+struct anim *IMB_open_anim(const char *name, int ib_flags);
+void IMB_close_anim(struct anim *anim);
/**
*
@@ -262,53 +208,34 @@ void IMB_close_anim(struct anim * anim);
*/
int ismovie(char *name);
-void IMB_anim_set_preseek(struct anim * anim, int preseek);
-int IMB_anim_get_preseek(struct anim * anim);
+void IMB_anim_set_preseek(struct anim *anim, int preseek);
+int IMB_anim_get_preseek(struct anim *anim);
/**
*
* @attention Defined in anim.c
*/
-struct ImBuf * IMB_anim_absolute(struct anim * anim, int position);
+struct ImBuf *IMB_anim_absolute(struct anim *anim, int position);
/**
*
* @attention Defined in anim.c
* fetches a define previewframe, usually half way into the movie
*/
-struct ImBuf * IMB_anim_previewframe(struct anim * anim);
+struct ImBuf *IMB_anim_previewframe(struct anim *anim);
/**
*
* @attention Defined in anim.c
*/
-void IMB_free_anim_ibuf(struct anim * anim);
+void IMB_free_anim_ibuf(struct anim *anim);
/**
*
* @attention Defined in anim.c
*/
-void IMB_free_anim(struct anim * anim);
-
-/**
- *
- * @attention Defined in anim.c
- */
-struct ImBuf * IMB_anim_nextpic(struct anim * anim);
-
-
-/**
- *
- * @attention Defined in antialias.c
- */
-void IMB_clever_double (struct ImBuf * ibuf);
-
-/**
- *
- * @attention Defined in antialias.c
- */
-void IMB_antialias(struct ImBuf * ibuf);
+void IMB_free_anim(struct anim *anim);
/**
*
@@ -318,30 +245,34 @@ void IMB_filter(struct ImBuf *ibuf);
void IMB_filterN(struct ImBuf *out, struct ImBuf *in);
void IMB_filter_extend(struct ImBuf *ibuf, char *mask);
void IMB_makemipmap(struct ImBuf *ibuf, int use_filter);
+struct ImBuf *IMB_getmipmap(struct ImBuf *ibuf, int level);
/**
*
- * @attention Defined in filter.c
+ * @attention Defined in cache.c
*/
-void IMB_filtery(struct ImBuf *ibuf);
+
+void IMB_tile_cache_params(int totthread, int maxmem);
+unsigned int *IMB_gettile(struct ImBuf *ibuf, int tx, int ty, int thread);
+void IMB_tiles_to_rect(struct ImBuf *ibuf);
/**
*
- * @attention Defined in scaling.c
+ * @attention Defined in filter.c
*/
-struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1);
+void IMB_filtery(struct ImBuf *ibuf);
/**
*
* @attention Defined in scaling.c
*/
-struct ImBuf *IMB_scaleImBuf(struct ImBuf * ibuf, short newx, short newy);
+struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1);
/**
*
* @attention Defined in scaling.c
*/
-struct ImBuf *IMB_scalefieldImBuf(struct ImBuf *ibuf, short newx, short newy);
+struct ImBuf *IMB_scaleImBuf(struct ImBuf *ibuf, short newx, short newy);
/**
*
@@ -372,13 +303,13 @@ int IMB_ispic(char *name);
*
* @attention Defined in util.c
*/
-int IMB_isanim(char * name);
+int IMB_isanim(char *name);
/**
*
* @attention Defined in util.c
*/
-int imb_get_anim_type(char * name);
+int imb_get_anim_type(char *name);
/**
*
@@ -386,9 +317,11 @@ int imb_get_anim_type(char * name);
*/
void IMB_de_interlace(struct ImBuf *ibuf);
void IMB_interlace(struct ImBuf *ibuf);
-void IMB_gamwarp(struct ImBuf *ibuf, double gamma);
void IMB_rect_from_float(struct ImBuf *ibuf);
void IMB_float_from_rect(struct ImBuf *ibuf);
+void IMB_float_from_rect_simple(struct ImBuf *ibuf); /* no profile conversion */
+/* note, check that the conversion exists, only some are supported */
+void IMB_convert_profile(struct ImBuf *ibuf, int profile);
/**
* Change the ordering of the color bytes pointed to by rect from
@@ -397,18 +330,6 @@ void IMB_float_from_rect(struct ImBuf *ibuf);
* @attention Defined in imageprocess.c
*/
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf);
-/**
- *
- * @attention defined in imageprocess.c
- */
-void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
-void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
-void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
-
-void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
-void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
-void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
-void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
/**
* Change the ordering of the color bytes pointed to by rect from
@@ -420,11 +341,16 @@ void IMB_convert_bgra_to_rgba(int size, unsigned int *rect);
/**
*
- * @attention defined in scaling.c
+ * @attention defined in imageprocess.c
*/
-struct ImBuf *IMB_scalefastfieldImBuf(struct ImBuf *ibuf,
- short newx,
- short newy);
+void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
+void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
+void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
+
+void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
+void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
+void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
+void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
/**
*
@@ -480,66 +406,21 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1);
/**
*
- * @attention defined in scaling.c
- */
-struct ImBuf *IMB_onethird(struct ImBuf *ibuf1);
-
-/**
- *
- * @attention defined in scaling.c
- */
-struct ImBuf *IMB_halflace(struct ImBuf *ibuf1);
-
-/**
- *
- * @attention defined in dither.c
- */
-void IMB_dit2(struct ImBuf * ibuf, short ofs, short bits);
-
-/**
- *
- * @attention defined in dither.c
- */
-void IMB_dit0(struct ImBuf * ibuf, short ofs, short bits);
-
-/** Externally used vars: fortunately they do not use funny types */
-
-/**
- * boolean toggle that tells whether or not to
- * scale the color map in the y-direction.
- *
- * @attention declared in hamx.c
- */
-extern int scalecmapY;
-
-/**
- * This 'matrix' defines the transformation from rgb to bw color
- * maps. You need to do a sort of dot-product for that. It is a matrix
- * with fixed coefficients, extracted from some book.
- *
- * @attention Defined in matrix.h, only included in hamx.c
- */
-extern float rgb_to_bw[4][4];
-
-/**
- *
* @attention Defined in rotate.c
*/
void IMB_flipx(struct ImBuf *ibuf);
-void IMB_flipy(struct ImBuf * ibuf);
+void IMB_flipy(struct ImBuf *ibuf);
-/**
- *
- * @attention Defined in cspace.c
- */
-void IMB_cspace(struct ImBuf *ibuf, float mat[][4]);
+/* Premultiply alpha */
+
+void IMB_premultiply_alpha(struct ImBuf *ibuf);
/**
*
* @attention Defined in allocimbuf.c
*/
-void IMB_freezbufImBuf(struct ImBuf * ibuf);
-void IMB_freezbuffloatImBuf(struct ImBuf * ibuf);
+void IMB_freezbufImBuf(struct ImBuf *ibuf);
+void IMB_freezbuffloatImBuf(struct ImBuf *ibuf);
/**
*
@@ -551,34 +432,19 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i
/* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */
void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2);
-/* defined in imginfo.c */
-int IMB_imginfo_change_field(struct ImBuf *img, const char *key, const char *field);
+/* defined in metadata.c */
+int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field);
/* exported for image tools in blender, to quickly allocate 32 bits rect */
-short imb_addrectImBuf(struct ImBuf * ibuf);
-void imb_freerectImBuf(struct ImBuf * ibuf);
+short imb_addrectImBuf(struct ImBuf *ibuf);
+void imb_freerectImBuf(struct ImBuf *ibuf);
-short imb_addrectfloatImBuf(struct ImBuf * ibuf);
-void imb_freerectfloatImBuf(struct ImBuf * ibuf);
-void imb_freemipmapImBuf(struct ImBuf * ibuf);
+short imb_addrectfloatImBuf(struct ImBuf *ibuf);
+void imb_freerectfloatImBuf(struct ImBuf *ibuf);
+void imb_freemipmapImBuf(struct ImBuf *ibuf);
-#ifdef WITH_QUICKTIME
-/**
- *
- * @attention Defined in quicktime_import.c
- */
-void quicktime_init(void);
-
-/**
- *
- * @attention Defined in quicktime_import.c
- */
-void quicktime_exit(void);
-
-#endif //WITH_QUICKTIME
-
-/* intern/dynlibtiff.c */
-void libtiff_init(void);
-void libtiff_exit(void);
+short imb_addtilesImBuf(struct ImBuf *ibuf);
+void imb_freetilesImBuf(struct ImBuf *ibuf);
#endif
+
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 6c58641a0d5..203a7268581 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -48,14 +48,10 @@
#ifndef IMB_IMBUF_TYPES_H
#define IMB_IMBUF_TYPES_H
-#include <stdio.h> /* for size_t */
-#include "DNA_listBase.h" /* for ListBase */
-struct _AviMovie;
-struct Mdec;
+struct ImMetaData;
-struct ImgInfo;
-
-#define IB_MIPMAP_LEVELS 10
+#define IB_MIPMAP_LEVELS 20
+#define IB_FILENAME_SIZE 1023
/**
* \brief The basic imbuf type
@@ -73,56 +69,69 @@ struct ImgInfo;
*/
typedef struct ImBuf {
struct ImBuf *next, *prev; /**< allow lists of ImBufs, for caches or flipbooks */
- short x, y; /**< width and Height of our image buffer */
- short skipx; /**< Width in ints to get to the next scanline */
- unsigned char depth; /**< Active amount of bits/bitplanes */
- unsigned char cbits; /**< Amount of active bits in cmap */
- unsigned short mincol; /**< smallest color in colormap */
- unsigned short maxcol; /**< Largest color in colormap */
- int type; /**< 0=abgr, 1=bitplanes */
- int ftype; /**< File type we are going to save as */
- unsigned int *cmap; /**< Color map data. */
- unsigned int *rect; /**< pixel values stored here */
- unsigned int *crect; /**< color corrected pixel values stored here */
- unsigned int **planes; /**< bitplanes */
- int flags; /**< Controls which components should exist. */
- int mall; /**< what is malloced internal, and can be freed */
- short xorig, yorig; /**< Cordinates of first pixel of an image used in some formats (example: targa) */
- char name[1023]; /**< The file name assocated with this image */
- char namenull; /**< Unused don't want to remove it thought messes things up */
- int userflags; /**< Used to set imbuf to Dirty and other stuff */
- int *zbuf; /**< z buffer data, original zbuffer */
- float *zbuf_float; /**< z buffer data, camera coordinates */
- void *userdata; /**< temporary storage, only used by baking at the moment */
- unsigned char *encodedbuffer; /**< Compressed image only used with png currently */
- unsigned int encodedsize; /**< Size of data written to encodedbuffer */
- unsigned int encodedbuffersize; /**< Size of encodedbuffer */
-
- float *rect_float; /**< floating point Rect equivalent
- Linear RGB color space - may need gamma correction to
- sRGB when generating 8bit representations */
- int channels; /**< amount of channels in rect_float (0 = 4 channel default) */
- float dither; /**< random dither value, for conversion from float -> byte rect */
- short profile; /** color space/profile preset that the byte rect buffer represents */
- char profile_filename[256]; /** to be implemented properly, specific filename for custom profiles */
-
- struct MEM_CacheLimiterHandle_s * c_handle; /**< handle for cache limiter */
- struct ImgInfo * img_info;
- int refcounter; /**< Refcounter for multiple users */
- int index; /**< reference index for ImBuf lists */
+
+ /* dimensions */
+ short x, y; /* width and Height of our image buffer */
+ unsigned char depth; /* Active amount of bits/bitplanes */
+ int channels; /* amount of channels in rect_float (0 = 4 channel default) */
+
+ /* flags */
+ int flags; /* Controls which components should exist. */
+ int mall; /* what is malloced internal, and can be freed */
+
+ /* pixels */
+ unsigned int *rect; /* pixel values stored here */
+ unsigned int *crect; /* color corrected pixel values stored here */
+ float *rect_float; /* floating point Rect equivalent
+ Linear RGB color space - may need gamma correction to
+ sRGB when generating 8bit representations */
- struct ImBuf *mipmap[IB_MIPMAP_LEVELS]; /**< MipMap levels, a series of halved images */
+ /* tiled pixel storage */
+ int tilex, tiley;
+ int xtiles, ytiles;
+ unsigned int **tiles;
+
+ /* zbuffer */
+ int *zbuf; /* z buffer data, original zbuffer */
+ float *zbuf_float; /* z buffer data, camera coordinates */
+
+ /* parameters used by conversion between byte and float */
+ float dither; /* random dither value, for conversion from float -> byte rect */
+ short profile; /* color space/profile preset that the byte rect buffer represents */
+ char profile_filename[256]; /* to be implemented properly, specific filename for custom profiles */
+
+ /* mipmapping */
+ struct ImBuf *mipmap[IB_MIPMAP_LEVELS]; /* MipMap levels, a series of halved images */
+ int miptot, miplevel;
+
+ /* externally used data */
+ int index; /* reference index for ImBuf lists */
+ int userflags; /* used to set imbuf to dirty and other stuff */
+ struct ImMetaData *metadata; /* image metadata */
+ void *userdata; /* temporary storage, only used by baking at the moment */
+
+ /* file information */
+ int ftype; /* file type we are going to save as */
+ char name[IB_FILENAME_SIZE]; /* filename associated with this image */
+ char cachename[IB_FILENAME_SIZE]; /* full filename used for reading from cache */
+
+ /* memory cache limiter */
+ struct MEM_CacheLimiterHandle_s *c_handle; /* handle for cache limiter */
+ int refcounter; /* reference counter for multiple users */
+
+ /* some parameters to pass along for packing images */
+ unsigned char *encodedbuffer; /* Compressed image only used with png currently */
+ unsigned int encodedsize; /* Size of data written to encodedbuffer */
+ unsigned int encodedbuffersize; /* Size of encodedbuffer */
} ImBuf;
/* Moved from BKE_bmfont_types.h because it is a userflag bit mask. */
/**
* \brief Flags used internally by blender for imagebuffers
*/
-typedef enum {
- IB_BITMAPFONT = 1 << 0, /* This image is a font */
- IB_BITMAPDIRTY = 1 << 1 /* Image needs to be saved is not the same as filename */
-} ImBuf_userflagsMask;
+#define IB_BITMAPFONT (1 << 0) /* this image is a font */
+#define IB_BITMAPDIRTY (1 << 1) /* image needs to be saved is not the same as filename */
/* From iff.h. This was once moved away by Frank, now Nzc moves it
* back. Such is the way it is... It is a long list of defines, and
@@ -136,33 +145,26 @@ typedef enum {
*/
/**@{*/
/** \brief Flag defining the components of the ImBuf struct. */
-#define IB_rect (1 << 0)
-#define IB_planes (1 << 1)
-#define IB_cmap (1 << 2)
-
-#define IB_vert (1 << 4)
-#define IB_freem (1 << 6)
-#define IB_test (1 << 7)
-
-#define IB_ttob (1 << 8)
-#define IB_subdlta (1 << 9)
-#define IB_fields (1 << 11)
-#define IB_zbuf (1 << 13)
-
-#define IB_mem (1 << 14)
-#define IB_rectfloat (1 << 15)
-#define IB_zbuffloat (1 << 16)
-#define IB_multilayer (1 << 17)
-#define IB_imginfo (1 << 18)
-#define IB_animdeinterlace (1 << 19)
+
+#define IB_rect (1 << 0)
+#define IB_test (1 << 1)
+#define IB_fields (1 << 2)
+#define IB_zbuf (1 << 3)
+#define IB_mem (1 << 4)
+#define IB_rectfloat (1 << 5)
+#define IB_zbuffloat (1 << 6)
+#define IB_multilayer (1 << 7)
+#define IB_metadata (1 << 8)
+#define IB_animdeinterlace (1 << 9)
+#define IB_tiles (1 << 10)
+#define IB_tilecache (1 << 11)
+#define IB_premul (1 << 12)
/*
* The bit flag is stored in the ImBuf.ftype variable.
* Note that the lower 10 bits is used for storing custom flags
*/
-#define AMI (1 << 31)
#define PNG (1 << 30)
-#define Anim (1 << 29)
#define TGA (1 << 28)
#define JPG (1 << 27)
#define BMP (1 << 26)
@@ -171,16 +173,22 @@ typedef enum {
#define QUICKTIME (1 << 25)
#endif
+#ifdef WITH_HDR
#define RADHDR (1 << 24)
+#endif
+#ifdef WITH_TIFF
#define TIF (1 << 23)
#define TIF_16BIT (1 << 8 )
+#endif
#define OPENEXR (1 << 22)
#define OPENEXR_HALF (1 << 8 )
#define OPENEXR_COMPRESS (7)
+#ifdef WITH_CINEON
#define CINEON (1 << 21)
#define DPX (1 << 20)
+#endif
#ifdef WITH_DDS
#define DDS (1 << 19)
@@ -188,11 +196,11 @@ typedef enum {
#ifdef WITH_OPENJPEG
#define JP2 (1 << 18)
-#define JP2_12BIT (1 << 17)
-#define JP2_16BIT (1 << 16)
+#define JP2_12BIT (1 << 17)
+#define JP2_16BIT (1 << 16)
#define JP2_YCC (1 << 15)
-#define JP2_CINE (1 << 14)
-#define JP2_CINE_48FPS (1 << 13)
+#define JP2_CINE (1 << 14)
+#define JP2_CINE_48FPS (1 << 13)
#endif
#define RAWTGA (TGA | 1)
@@ -203,66 +211,20 @@ typedef enum {
#define JPG_MAX (JPG | (3 << 8))
#define JPG_MSK (0xffffff00)
-#define AM_ham (0x0800 | AMI)
-#define AM_hbrite (0x0080 | AMI)
-
-#define C233 1
-#define YUVX 2
-#define HAMX 3
-#define TANX 4
-
-#define AN_c233 (Anim | C233)
-#define AN_yuvx (Anim | YUVX)
-#define AN_hamx (Anim | HAMX)
-#define AN_tanx (Anim | TANX)
-/**@}*/
+#define IMAGIC 0732
/**
* \name Imbuf preset profile tags
* \brief Some predefined color space profiles that 8 bit imbufs can represent
*/
-/**@{*/
#define IB_PROFILE_NONE 0
#define IB_PROFILE_LINEAR_RGB 1
#define IB_PROFILE_SRGB 2
#define IB_PROFILE_CUSTOM 3
-/**@}*/
+extern const char *imb_ext_image[];
+extern const char *imb_ext_image_qt[];
+extern const char *imb_ext_movie[];
+extern const char *imb_ext_audio[];
-/** \name Imbuf File Type Tests
- * \brief These macros test if an ImBuf struct is the corresponding file type.
- */
-/**@{*/
-/** \brief Tests the ImBuf.ftype variable for the file format. */
-#define IS_amiga(x) (x->ftype & AMI)
-#define IS_ham(x) ((x->ftype & AM_ham) == AM_ham)
-#define IS_hbrite(x) ((x->ftype & AM_hbrite) == AM_hbrite)
-
-#define IS_anim(x) (x->ftype & Anim)
-#define IS_hamx(x) (x->ftype == AN_hamx)
-#define IS_tga(x) (x->ftype & TGA)
-#define IS_png(x) (x->ftype & PNG)
-#define IS_openexr(x) (x->ftype & OPENEXR)
-#define IS_jp2(x) (x->ftype & JP2)
-#define IS_cineon(x) (x->ftype & CINEON)
-#define IS_dpx(x) (x->ftype & DPX)
-#define IS_bmp(x) (x->ftype & BMP)
-#define IS_tiff(x) (x->ftype & TIF)
-#define IS_radhdr(x) (x->ftype & RADHDR)
-
-#ifdef WITH_DDS
-#define IS_dds(x) (x->ftype & DDS)
#endif
-
-#define IMAGIC 0732
-#define IS_iris(x) (x->ftype == IMAGIC)
-
-#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)
-/**@}*/
-
-#endif
-
diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h
index 165accc9e17..9248b768cb6 100644
--- a/source/blender/imbuf/IMB_thumbs.h
+++ b/source/blender/imbuf/IMB_thumbs.h
@@ -50,13 +50,14 @@ typedef enum ThumbSize {
typedef enum ThumbSource {
THB_SOURCE_IMAGE,
- THB_SOURCE_MOVIE
+ THB_SOURCE_MOVIE,
+ THB_SOURCE_BLEND
} ThumbSource;
-// IB_imginfo
+// IB_metadata
/* create thumbnail for file and returns new imbuf for thumbnail */
-ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source);
+ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, ImBuf *ibuf);
/* read thumbnail for file and returns new imbuf for thumbnail */
ImBuf* IMB_thumb_read(const char* path, ThumbSize size);
@@ -70,6 +71,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source);
/* create the necessary dirs to store the thumbnails */
void IMB_thumb_makedirs();
+/* special function for loading a thumbnail embedded into a blend file */
+ImBuf *IMB_loadblend_thumb(const char *path);
+void IMB_overlayblend_thumb(unsigned int *thumb, int width, int height, float aspect);
+
#endif /* _IMB_THUMBS_H */
diff --git a/source/blender/imbuf/Makefile b/source/blender/imbuf/Makefile
index cc9b56b3cd8..78eea89173f 100644
--- a/source/blender/imbuf/Makefile
+++ b/source/blender/imbuf/Makefile
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
diff --git a/source/blender/imbuf/SConscript b/source/blender/imbuf/SConscript
index a8d91b2d31e..6b3360a16c5 100644
--- a/source/blender/imbuf/SConscript
+++ b/source/blender/imbuf/SConscript
@@ -14,12 +14,24 @@ incs += ' ' + env['BF_ZLIB_INC']
defs = []
+if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
+ incs += ' ' + env['BF_PTHREADS_INC']
+
if env['WITH_BF_OPENEXR']:
defs.append('WITH_OPENEXR')
+if env['WITH_BF_TIFF']:
+ defs.append('WITH_TIFF')
+
if env['WITH_BF_DDS']:
defs.append('WITH_DDS')
+if env['WITH_BF_CINEON']:
+ defs.append('WITH_CINEON')
+
+if env['WITH_BF_HDR']:
+ defs.append('WITH_HDR')
+
if env['WITH_BF_FFMPEG']:
defs.append('WITH_FFMPEG')
incs += ' ' + env['BF_FFMPEG_INC']
diff --git a/source/blender/imbuf/intern/IMB_amiga.h b/source/blender/imbuf/intern/IMB_amiga.h
deleted file mode 100644
index e8d908df4c3..00000000000
--- a/source/blender/imbuf/intern/IMB_amiga.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * IMB_amiga.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_amiga.h
- * \ingroup imbuf
- * \brief Function declarations for amiga.c
- */
-
-#ifndef IMB_AMIGA_H
-#define IMB_AMIGA_H
-
-struct ImBuf;
-
-struct ImBuf *imb_loadamiga(int *iffmem,int flags);
-short imb_encodebodyh(struct ImBuf *ibuf, int file);
-short imb_encodebodyv(struct ImBuf *ibuf, int file);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h
index 39b8e48fb7f..c9eac2c1399 100644
--- a/source/blender/imbuf/intern/IMB_anim.h
+++ b/source/blender/imbuf/intern/IMB_anim.h
@@ -65,7 +65,6 @@
BLI_countlist BLI_stringdec */
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "AVI_avi.h"
@@ -93,7 +92,6 @@
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_bitplanes.h"
@@ -117,7 +115,7 @@
#define ANIM_NONE (0)
#define ANIM_SEQUENCE (1 << 0)
#define ANIM_DIR (1 << 1)
-#define ANIM_ANIM5 (1 << 2)
+#define ANIM_DEPRECATED (1 << 2)
#define ANIM_TGA (1 << 3)
#define ANIM_MOVIE (1 << 4)
#define ANIM_MDEC (1 << 5)
@@ -126,13 +124,10 @@
#define ANIM_FFMPEG (1 << 8)
#define ANIM_REDCODE (1 << 9)
-#define ANIM5_MMAP 0
-#define ANIM5_MALLOC 1
-#define ANIM5_SNGBUF 2
-#define ANIM5_XOR 4
-
#define MAXNUMSTREAMS 50
+struct _AviMovie;
+
struct anim {
int ib_flags;
int curtype;
@@ -145,14 +140,6 @@ struct anim {
/* voor sequence */
char first[256];
- /* anim5 */
- struct ListBase anim5base;
- void * anim5mmap;
- int anim5len;
- struct Anim5Delta *anim5curdlta;
- void (*anim5decode)(struct ImBuf *, unsigned char *);
- int anim5flags;
-
/* movie */
void *movie;
void *track;
diff --git a/source/blender/imbuf/intern/IMB_anim5.h b/source/blender/imbuf/intern/IMB_anim5.h
deleted file mode 100644
index 245b3b9a9be..00000000000
--- a/source/blender/imbuf/intern/IMB_anim5.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* IMB_anim.h */
-#ifndef IMB_ANIM5_H
-#define IMB_ANIM5_H
-
-struct anim;
-
-/**
- *
- * @attention Defined in anim5.c
- */
-int nextanim5(struct anim * anim);
-int rewindanim5(struct anim * anim);
-int startanim5(struct anim * anim);
-void free_anim_anim5(struct anim * anim);
-struct ImBuf * anim5_fetchibuf(struct anim * anim);
-
-
-#endif
-
-
diff --git a/source/blender/imbuf/intern/IMB_bitplanes.h b/source/blender/imbuf/intern/IMB_bitplanes.h
deleted file mode 100644
index c8deb6f9a02..00000000000
--- a/source/blender/imbuf/intern/IMB_bitplanes.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * IMB_bitplanes.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_bitplanes.h
- * \ingroup imbuf
- * \brief Function declarations for bitplanes.c
- */
-
-#ifndef IMB_BITPLANES_H
-#define IMB_BITPLANES_H
-
-struct ImBuf;
-
-void imb_bptolong(struct ImBuf *ibuf);
-void imb_longtobp(struct ImBuf *ibuf);
-unsigned int **imb_copyplanelist(struct ImBuf *ibuf);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_bmp.h b/source/blender/imbuf/intern/IMB_bmp.h
deleted file mode 100644
index 99561eeead2..00000000000
--- a/source/blender/imbuf/intern/IMB_bmp.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * IMB_bmp.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_bmp.h
- * \ingroup imbuf
- * \brief Function declarations for bmp.c
- */
-
-#ifndef IMB_BMP_H
-#define IMB_BMP_H
-
-struct ImBuf;
-
-int imb_is_a_bmp(void *buf);
-struct ImBuf *imb_bmp_decode(unsigned char *mem, int size, int flags);
-short imb_savebmp(struct ImBuf *ibuf, char *name, int flags);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_cmap.h b/source/blender/imbuf/intern/IMB_cmap.h
deleted file mode 100644
index 5e30e66f58e..00000000000
--- a/source/blender/imbuf/intern/IMB_cmap.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * IMB_cmap.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_cmap.h
- * \ingroup imbuf
- * \brief Function declarations for cmap.c
- */
-#ifndef IMB_CMAP_H
-#define IMB_CMAP_H
-
-struct ImBuf;
-
-void imb_makecolarray(struct ImBuf *ibuf, unsigned char *mem, short nocols);
-void imb_losecmapbits(struct ImBuf *ibuf, unsigned int *coltab);
-short *imb_coldeltatab(unsigned char *coltab, short mincol, short maxcol, short cbits);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_cocoa.h b/source/blender/imbuf/intern/IMB_cocoa.h
deleted file mode 100644
index a62e7028143..00000000000
--- a/source/blender/imbuf/intern/IMB_cocoa.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * IMB_cocoa.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Damien Plisson 10/2009
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_cocoa.h
- * \ingroup imbuf
- * \brief Function declarations for imbuf_cocoa.m
- */
-
-#ifndef IMB_COCOA_H
-#define IMB_COCOA_H
-
-/* Foward declaration of ImBuf structure. */
-struct ImBuf;
-
-/* Declarations for imbuf_cocoa.m */
-struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags);
-short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags);
-
-#endif /* IMB_COCOA_H */
-
diff --git a/source/blender/imbuf/intern/IMB_divers.h b/source/blender/imbuf/intern/IMB_divers.h
deleted file mode 100644
index 5ab0ce25484..00000000000
--- a/source/blender/imbuf/intern/IMB_divers.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * divers.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_divers.h
- * \ingroup imbuf
- * \brief Function declarations for divers.c
- */
-
-#ifndef IMB_DIVERS_H
-#define IMB_DIVERS_H
-
-struct ImBuf;
-
-void imb_checkncols(struct ImBuf *ibuf);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_dpxcineon.h b/source/blender/imbuf/intern/IMB_dpxcineon.h
deleted file mode 100644
index 4719ecd49f3..00000000000
--- a/source/blender/imbuf/intern/IMB_dpxcineon.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * IMB_dpxcineon.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_dpxcineon.h
- * \ingroup imbuf
- */
-#ifndef _IMB_DPX_CINEON_H
-#define _IMB_DPX_CINEON_H
-
-struct ImBuf;
-
-short imb_savecineon(struct ImBuf *buf, char *myfil, int flags);
-struct ImBuf *imb_loadcineon(unsigned char *mem, int size, int flags);
-int imb_is_cineon(void *buf);
-short imb_save_dpx(struct ImBuf *buf, char *myfile, int flags);
-struct ImBuf *imb_loaddpx(unsigned char *mem, int size, int flags);
-int imb_is_dpx(void *buf);
-
-#endif /*_IMB_DPX_CINEON_H*/
diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h
new file mode 100644
index 00000000000..9fd4108bee9
--- /dev/null
+++ b/source/blender/imbuf/intern/IMB_filetype.h
@@ -0,0 +1,121 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation 2010.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef IMB_FILETYPE_H
+#define IMB_FILETYPE_H
+
+/* Generic File Type */
+
+struct ImBuf;
+
+#define IM_FTYPE_FLOAT 1
+
+typedef struct ImFileType {
+ void (*init)(void);
+ void (*exit)(void);
+
+ int (*is_a)(unsigned char *buf);
+ int (*ftype)(struct ImFileType *type, struct ImBuf *ibuf);
+ struct ImBuf *(*load)(unsigned char *mem, int size, 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);
+
+ int flag;
+ int filetype;
+} ImFileType;
+
+extern ImFileType IMB_FILE_TYPES[];
+
+void imb_filetypes_init(void);
+void imb_filetypes_exit(void);
+
+void imb_tile_cache_init(void);
+void imb_tile_cache_exit(void);
+
+void imb_loadtile(struct ImBuf *ibuf, int tx, int ty, unsigned int *rect);
+void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty);
+
+/* Type Specific Functions */
+
+/* png */
+int imb_is_a_png(unsigned char *buf);
+struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags);
+int imb_savepng(struct ImBuf *ibuf, char *name, int flags);
+
+/* targa */
+int imb_is_a_targa(unsigned char *buf);
+struct ImBuf *imb_loadtarga(unsigned char *mem, int size, int flags);
+int imb_savetarga(struct ImBuf * ibuf, char *name, int flags);
+
+/* iris */
+int imb_is_a_iris(unsigned char *mem);
+struct ImBuf *imb_loadiris(unsigned char *mem, int size, int flags);
+int imb_saveiris(struct ImBuf * ibuf, char *name, int flags);
+
+/* jp2 */
+int imb_is_a_jp2(unsigned char *buf);
+struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags);
+int imb_savejp2(struct ImBuf *ibuf, char *name, int flags);
+
+/* jpeg */
+int imb_is_a_jpeg(unsigned char *mem);
+int imb_savejpeg(struct ImBuf * ibuf, char * name, int flags);
+struct ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags);
+struct ImBuf * imb_load_jpeg (unsigned char * buffer, int size, int flags);
+
+/* bmp */
+int imb_is_a_bmp(unsigned char *buf);
+struct ImBuf *imb_bmp_decode(unsigned char *mem, int size, int flags);
+int imb_savebmp(struct ImBuf *ibuf, char *name, int flags);
+
+/* cocoa */
+struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags);
+short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags);
+
+/* cineon */
+int imb_savecineon(struct ImBuf *buf, char *myfil, int flags);
+struct ImBuf *imb_loadcineon(unsigned char *mem, int size, int flags);
+int imb_is_cineon(unsigned char *buf);
+
+/* dpx */
+int imb_save_dpx(struct ImBuf *buf, char *myfile, int flags);
+struct ImBuf *imb_loaddpx(unsigned char *mem, int size, int flags);
+int imb_is_dpx(unsigned char *buf);
+
+/* hdr */
+int imb_is_a_hdr(unsigned char *buf);
+struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags);
+int imb_savehdr(struct ImBuf * ibuf, char *name, int flags);
+
+/* tiff */
+void imb_inittiff(void);
+int imb_is_a_tiff(unsigned char *buf);
+struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags);
+void imb_loadtiletiff(struct ImBuf *ibuf, unsigned char *mem, int size,
+ int tx, int ty, unsigned int *rect);
+int imb_savetiff(struct ImBuf *ibuf, char *name, int flags);
+void *libtiff_findsymbol(char *name);
+
+#endif /* IMB_FILETYPE_H */
+
diff --git a/source/blender/imbuf/intern/IMB_filter.h b/source/blender/imbuf/intern/IMB_filter.h
index 4f54ea91a1f..84ad72c520a 100644
--- a/source/blender/imbuf/intern/IMB_filter.h
+++ b/source/blender/imbuf/intern/IMB_filter.h
@@ -41,5 +41,8 @@ struct ImBuf;
void imb_filterx(struct ImBuf *ibuf);
+void IMB_premultiply_rect(unsigned int *rect, int depth, int w, int h);
+void IMB_premultiply_rect_float(float *rect_float, int depth, int w, int h);
+
#endif
diff --git a/source/blender/imbuf/intern/IMB_hamx.h b/source/blender/imbuf/intern/IMB_hamx.h
deleted file mode 100644
index e39aef8355d..00000000000
--- a/source/blender/imbuf/intern/IMB_hamx.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * IMB_hamx.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_hamx.h
- * \ingroup imbuf
- * \brief Function declarations for hamx.c
- */
-
-#ifndef IMB_HAMX_H
-#define IMB_HAMX_H
-
-struct ImBuf;
-
-struct ImBuf *imb_loadanim(int *iffmem, int flags);
-short imb_enc_anim(struct ImBuf *ibuf, int file);
-void imb_convhamx(struct ImBuf *ibuf, unsigned char *coltab, short *deltab);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_iff.h b/source/blender/imbuf/intern/IMB_iff.h
deleted file mode 100644
index 7d0a74dc00b..00000000000
--- a/source/blender/imbuf/intern/IMB_iff.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * IMB_iff.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_iff.h
- * \ingroup imbuf
- * \brief Function declarations for iff.c
- */
-
-#ifndef IMB_IFF_H
-#define IMB_IFF_H
-
-struct ImBuf;
-
-unsigned short imb_start_iff(struct ImBuf *ibuf, int file);
-unsigned short imb_update_iff(int file, int code);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_iris.h b/source/blender/imbuf/intern/IMB_iris.h
deleted file mode 100644
index 3aa157cb959..00000000000
--- a/source/blender/imbuf/intern/IMB_iris.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * IMB_iris.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_iris.h
- * \ingroup imbuf
- * \brief Function declarations for iris.c
- */
-
-#ifndef IMB_IRIS_H
-#define IMB_IRIS_H
-
-struct ImBuf;
-
-struct ImBuf *imb_loadiris(unsigned char *mem, int flags);
-short imb_saveiris(struct ImBuf * ibuf, char *name, int flags);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_jp2.h b/source/blender/imbuf/intern/IMB_jp2.h
deleted file mode 100644
index 66ff69314ae..00000000000
--- a/source/blender/imbuf/intern/IMB_jp2.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * IMB_jp2.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_jp2.h
- * \ingroup imbuf
- * \brief Function declarations for jp2.c
- */
-
-#ifndef IMB_JP2_H
-#define IMB_JP2_H
-
-#ifdef WITH_OPENJPEG
-struct ImBuf;
-
-int imb_is_a_jp2(void *buf);
-struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags);
-short imb_savejp2(struct ImBuf *ibuf, char *name, int flags);
-#endif /* WITH_OPENJPEG */
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_jpeg.h b/source/blender/imbuf/intern/IMB_jpeg.h
deleted file mode 100644
index 8e0ba3451ae..00000000000
--- a/source/blender/imbuf/intern/IMB_jpeg.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * IMB_jpeg.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_jpeg.h
- * \ingroup imbuf
- * \brief Function declarations for jpeg.c
- */
-
-#ifndef IMB_JPEG_H
-#define IMB_JPEG_H
-
-struct ImBuf;
-struct jpeg_compress_struct;
-
-int imb_is_a_jpeg(unsigned char *mem);
-int imb_savejpeg(struct ImBuf * ibuf, char * name, int flags);
-struct ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags);
-struct ImBuf * imb_ibJpegImageFromMemory (unsigned char * buffer, int size, int flags);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_imginfo.h b/source/blender/imbuf/intern/IMB_metadata.h
index 2884abcaf6e..625e0791e07 100644
--- a/source/blender/imbuf/intern/IMB_imginfo.h
+++ b/source/blender/imbuf/intern/IMB_metadata.h
@@ -1,5 +1,5 @@
/**
- * $Id$
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -30,20 +30,16 @@
#ifndef _IMB_IMGINFO_H
#define _IMB_IMGINFO_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
struct ImBuf;
-typedef struct ImgInfo {
- struct ImgInfo *next, *prev;
+typedef struct ImMetaData {
+ struct ImMetaData *next, *prev;
char* key;
char* value;
int len;
-} ImgInfo;
+} ImMetaData;
-/** The imginfo is a list of key/value pairs (both char*) that can me
+/** The metadata is a list of key/value pairs (both char*) that can me
saved in the header of several image formats.
Apart from some common keys like
'Software' and 'Description' (png standard) we'll use keys within the
@@ -52,8 +48,8 @@ typedef struct ImgInfo {
*/
-/* free blender ImgInfo struct */
-void IMB_imginfo_free(struct ImBuf* img);
+/* free blender ImMetaData struct */
+void IMB_metadata_free(struct ImBuf* img);
/** read the field from the image info into the field
* @param img - the ImBuf that contains the image data
@@ -63,23 +59,22 @@ void IMB_imginfo_free(struct ImBuf* img);
* @param len - length of value buffer allocated by user.
* @return - 1 (true) if ImageInfo present and value for the key found, 0 (false) otherwise
*/
-int IMB_imginfo_get_field(struct ImBuf* img, const char* key, char* value, int len);
+int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* value, int len);
-/** set user data in the ImgInfo struct, which has to be allocated with IMB_imginfo_create
+/** set user data in the ImMetaData struct, which has to be allocated with IMB_metadata_create
* before calling this function.
* @param img - the ImBuf that contains the image data
* @param key - the key of the field
* @param value - the data to be written to the field. zero terminated string
* @return - 1 (true) if ImageInfo present, 0 (false) otherwise
*/
-int IMB_imginfo_add_field(struct ImBuf* img, const char* key, const char* field);
+int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* field);
-/** delete the key/field par in the ImgInfo struct.
+/** delete the key/field par in the ImMetaData struct.
* @param img - the ImBuf that contains the image data
* @param key - the key of the field
* @return - 1 (true) if delete the key/field, 0 (false) otherwise
*/
-int IMB_imginfo_del_field(struct ImBuf *img, const char *key);
+int IMB_metadata_del_field(struct ImBuf *img, const char *key);
#endif /* _IMB_IMGINFO_H */
-
diff --git a/source/blender/imbuf/intern/IMB_png.h b/source/blender/imbuf/intern/IMB_png.h
deleted file mode 100644
index 28e3adb2722..00000000000
--- a/source/blender/imbuf/intern/IMB_png.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * IMB_png.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_png.h
- * \ingroup imbuf
- * \brief Function declarations for png.c
- */
-
-#ifndef IMB_PNG_H
-#define IMB_PNG_H
-
-struct ImBuf;
-
-int imb_is_a_png(void *buf);
-struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags);
-
-short imb_savepng(struct ImBuf *ibuf, char *name, int flags);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_radiance_hdr.h b/source/blender/imbuf/intern/IMB_radiance_hdr.h
deleted file mode 100644
index 325715906a0..00000000000
--- a/source/blender/imbuf/intern/IMB_radiance_hdr.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * IMB_radiance_hdr.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef IMB_RADIANCE_HDR_H
-#define IMB_RADIANCE_HDR_H
-
-struct ImBuf;
-
-int imb_is_a_hdr(void *buf);
-
-struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags);
-short imb_savehdr(struct ImBuf * ibuf, char *name, int flags);
-
-#endif
diff --git a/source/blender/imbuf/intern/IMB_targa.h b/source/blender/imbuf/intern/IMB_targa.h
deleted file mode 100644
index a81801eedac..00000000000
--- a/source/blender/imbuf/intern/IMB_targa.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * IMB_targa.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_targa.h
- * \ingroup imbuf
- * \brief Function declarations for targa.c
- */
-
-#ifndef IMB_TARGA_H
-#define IMB_TARGA_H
-
-struct ImBuf;
-
-int imb_is_a_targa(void *buf);
-
-struct ImBuf *imb_loadtarga(unsigned char *mem, int size, int flags);
-short imb_savetarga(struct ImBuf * ibuf, char *name, int flags);
-
-#endif
-
diff --git a/source/blender/imbuf/intern/IMB_tiff.h b/source/blender/imbuf/intern/IMB_tiff.h
deleted file mode 100644
index ccd993fe477..00000000000
--- a/source/blender/imbuf/intern/IMB_tiff.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * IMB_tiff.h
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Jonathan Merritt.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/**
- * \file IMB_tiff.h
- * \ingroup imbuf
- * \brief Function declarations for tiff.c
- */
-
-#ifndef IMB_TIFF_H
-#define IMB_TIFF_H
-
-/* Foward declaration of ImBuf structure. */
-struct ImBuf;
-
-/* Declarations for tiff.c */
-int imb_is_a_tiff(void *buf);
-struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags);
-short imb_savetiff(struct ImBuf *ibuf, char *name, int flags);
-void* libtiff_findsymbol(char *name);
-
-#endif /* IMB_TIFF_H */
-
diff --git a/source/blender/imbuf/intern/Makefile b/source/blender/imbuf/intern/Makefile
index 0f2020c799a..8e7272100b9 100644
--- a/source/blender/imbuf/intern/Makefile
+++ b/source/blender/imbuf/intern/Makefile
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
@@ -36,7 +36,12 @@ include nan_subdirs.mk
include nan_compile.mk
include nan_definitions.mk
-DIRS = cineon
+DIRS =
+
+ifeq ($(WITH_CINEON), true)
+ DIRS += cineon
+ CPPFLAGS += -DWITH_CINEON
+endif
ifeq ($(WITH_OPENEXR), true)
DIRS += openexr
@@ -61,7 +66,6 @@ CFLAGS += $(LEVEL_1_C_WARNINGS)
CPPFLAGS += -I$(NAN_JPEG)/include
CPPFLAGS += -I$(NAN_PNG)/include
CPPFLAGS += -I$(NAN_ZLIB)/include
-CPPFLAGS += -I$(NAN_TIFF)/include
CPPFLAGS += -I../../include
CPPFLAGS += -I../../blenkernel
CPPFLAGS += -I../../blenlib
@@ -85,3 +89,12 @@ ifeq ($(WITH_FFMPEG), true)
CPPFLAGS += -DWITH_FFMPEG
CPPFLAGS += $(NAN_FFMPEGCFLAGS)
endif
+
+ifeq ($(WITH_TIFF), true)
+ CPPFLAGS += -DWITH_TIFF
+ CPPFLAGS += -I$(NAN_TIFF)/include
+endif
+
+ifeq ($(WITH_HDR), true)
+ CPPFLAGS += -DWITH_HDR
+endif
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index 710dbde21b2..3f440c0bf6f 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -32,54 +32,39 @@
/* It's become a bit messy... Basically, only the IMB_ prefixed files
* should remain. */
-#include "IMB_imbuf_types.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
-#include "IMB_divers.h"
#include "IMB_allocimbuf.h"
-#include "IMB_imginfo.h"
-#include "MEM_CacheLimiterC-Api.h"
+#include "IMB_filetype.h"
+#include "IMB_metadata.h"
-static unsigned int dfltcmap[16] = {
- 0x00000000, 0xffffffff, 0x777777ff, 0xccccccff,
- 0xcc3344ff, 0xdd8844ff, 0xccdd44ff, 0x888833ff,
- 0x338844ff, 0x44dd44ff, 0x44ddccff, 0x3388ccff,
- 0x8888ddff, 0x4433ccff, 0xcc33ccff, 0xcc88ddff
-};
+#include "imbuf.h"
-void imb_freeplanesImBuf(struct ImBuf * ibuf)
-{
- if (ibuf==NULL) return;
- if (ibuf->planes){
- if (ibuf->mall & IB_planes) MEM_freeN(ibuf->planes);
- }
- ibuf->planes = 0;
- ibuf->mall &= ~IB_planes;
-}
+#include "MEM_CacheLimiterC-Api.h"
+#include "MEM_guardedalloc.h"
-void imb_freemipmapImBuf(struct ImBuf * ibuf)
+void imb_freemipmapImBuf(ImBuf *ibuf)
{
int a;
- for(a=0; a<IB_MIPMAP_LEVELS; a++) {
- if(ibuf->mipmap[a]) IMB_freeImBuf(ibuf->mipmap[a]);
- ibuf->mipmap[a]= NULL;
+ for(a=1; a<ibuf->miptot; a++) {
+ if(ibuf->mipmap[a-1])
+ IMB_freeImBuf(ibuf->mipmap[a-1]);
+ ibuf->mipmap[a-1]= NULL;
}
+
+ ibuf->miptot= 0;
}
/* any free rect frees mipmaps to be sure, creation is in render on first request */
-void imb_freerectfloatImBuf(struct ImBuf * ibuf)
+void imb_freerectfloatImBuf(ImBuf *ibuf)
{
- if (ibuf==NULL) return;
+ if(ibuf==NULL) return;
- if (ibuf->rect_float) {
- if (ibuf->mall & IB_rectfloat) {
- MEM_freeN(ibuf->rect_float);
- ibuf->rect_float=NULL;
- }
+ if(ibuf->rect_float && (ibuf->mall & IB_rectfloat)) {
+ MEM_freeN(ibuf->rect_float);
+ ibuf->rect_float=NULL;
}
imb_freemipmapImBuf(ibuf);
@@ -89,19 +74,15 @@ void imb_freerectfloatImBuf(struct ImBuf * ibuf)
}
/* any free rect frees mipmaps to be sure, creation is in render on first request */
-void imb_freerectImBuf(struct ImBuf * ibuf)
+void imb_freerectImBuf(ImBuf *ibuf)
{
- if (ibuf==NULL) return;
+ if(ibuf==NULL) return;
- if (ibuf->crect && ibuf->crect != ibuf->rect) {
+ if(ibuf->crect)
MEM_freeN(ibuf->crect);
- }
- if (ibuf->rect) {
- if (ibuf->mall & IB_rect) {
- MEM_freeN(ibuf->rect);
- }
- }
+ if(ibuf->rect && (ibuf->mall & IB_rect))
+ MEM_freeN(ibuf->rect);
imb_freemipmapImBuf(ibuf);
@@ -110,150 +91,166 @@ void imb_freerectImBuf(struct ImBuf * ibuf)
ibuf->mall &= ~IB_rect;
}
-static void freeencodedbufferImBuf(struct ImBuf * ibuf)
+void imb_freetilesImBuf(ImBuf *ibuf)
{
- if (ibuf==NULL) return;
- if (ibuf->encodedbuffer){
- if (ibuf->mall & IB_mem) MEM_freeN(ibuf->encodedbuffer);
+ int tx, ty;
+
+ if(ibuf==NULL) return;
+
+ if(ibuf->tiles && (ibuf->mall & IB_tiles)) {
+ for(ty=0; ty<ibuf->ytiles; ty++) {
+ for(tx=0; tx<ibuf->xtiles; tx++) {
+ if(ibuf->tiles[ibuf->xtiles*ty + tx]) {
+ imb_tile_cache_tile_free(ibuf, tx, ty);
+ MEM_freeN(ibuf->tiles[ibuf->xtiles*ty + tx]);
+ }
+ }
+ }
+
+ MEM_freeN(ibuf->tiles);
}
+
+ ibuf->tiles= NULL;
+ ibuf->mall &= ~IB_tiles;
+}
+
+static void freeencodedbufferImBuf(ImBuf *ibuf)
+{
+ if(ibuf==NULL) return;
+
+ if(ibuf->encodedbuffer && (ibuf->mall & IB_mem))
+ MEM_freeN(ibuf->encodedbuffer);
+
ibuf->encodedbuffer = 0;
ibuf->encodedbuffersize = 0;
ibuf->encodedsize = 0;
ibuf->mall &= ~IB_mem;
}
-void IMB_freezbufImBuf(struct ImBuf * ibuf)
+void IMB_freezbufImBuf(ImBuf *ibuf)
{
- if (ibuf==NULL) return;
- if (ibuf->zbuf){
- if (ibuf->mall & IB_zbuf) MEM_freeN(ibuf->zbuf);
- }
+ if(ibuf==NULL) return;
+
+ if(ibuf->zbuf && (ibuf->mall & IB_zbuf))
+ MEM_freeN(ibuf->zbuf);
+
ibuf->zbuf= NULL;
ibuf->mall &= ~IB_zbuf;
}
-void IMB_freezbuffloatImBuf(struct ImBuf * ibuf)
+void IMB_freezbuffloatImBuf(ImBuf *ibuf)
{
- if (ibuf==NULL) return;
- if (ibuf->zbuf_float){
- if (ibuf->mall & IB_zbuffloat) MEM_freeN(ibuf->zbuf_float);
- }
+ if(ibuf==NULL) return;
+
+ if(ibuf->zbuf_float && (ibuf->mall & IB_zbuffloat))
+ MEM_freeN(ibuf->zbuf_float);
+
ibuf->zbuf_float= NULL;
ibuf->mall &= ~IB_zbuffloat;
}
-void IMB_freecmapImBuf(struct ImBuf * ibuf)
-{
- if (ibuf==NULL) return;
- if (ibuf->cmap){
- if (ibuf->mall & IB_cmap) MEM_freeN(ibuf->cmap);
- }
- ibuf->cmap = 0;
- ibuf->mall &= ~IB_cmap;
-}
-
-void IMB_freeImBuf(struct ImBuf * ibuf)
+void IMB_freeImBuf(ImBuf *ibuf)
{
- if (ibuf){
- if (ibuf->refcounter > 0) {
+ if(ibuf) {
+ if(ibuf->refcounter > 0) {
ibuf->refcounter--;
- } else {
- imb_freeplanesImBuf(ibuf);
+ }
+ else {
imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
+ imb_freetilesImBuf(ibuf);
IMB_freezbufImBuf(ibuf);
IMB_freezbuffloatImBuf(ibuf);
- IMB_freecmapImBuf(ibuf);
freeencodedbufferImBuf(ibuf);
IMB_cache_limiter_unmanage(ibuf);
- IMB_imginfo_free(ibuf);
+ IMB_metadata_free(ibuf);
MEM_freeN(ibuf);
}
}
}
-void IMB_refImBuf(struct ImBuf * ibuf)
+void IMB_refImBuf(ImBuf *ibuf)
{
ibuf->refcounter++;
}
-short addzbufImBuf(struct ImBuf * ibuf)
+short addzbufImBuf(ImBuf *ibuf)
{
int size;
- if (ibuf==NULL) return(FALSE);
+ if(ibuf==NULL) return FALSE;
IMB_freezbufImBuf(ibuf);
- size = ibuf->x * ibuf->y * sizeof(unsigned int);
- if ( (ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf")) ){
+ size = ibuf->x *ibuf->y *sizeof(unsigned int);
+ if((ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf"))) {
ibuf->mall |= IB_zbuf;
ibuf->flags |= IB_zbuf;
- return (TRUE);
+ return TRUE;
}
- return (FALSE);
+ return FALSE;
}
-short addzbuffloatImBuf(struct ImBuf * ibuf)
+short addzbuffloatImBuf(ImBuf *ibuf)
{
int size;
- if (ibuf==NULL) return(FALSE);
+ if(ibuf==NULL) return FALSE;
IMB_freezbuffloatImBuf(ibuf);
- size = ibuf->x * ibuf->y * sizeof(float);
- if ( (ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf")) ){
+ size = ibuf->x *ibuf->y *sizeof(float);
+ if((ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf"))) {
ibuf->mall |= IB_zbuffloat;
ibuf->flags |= IB_zbuffloat;
- return (TRUE);
+ return TRUE;
}
- return (FALSE);
+ return FALSE;
}
-short imb_addencodedbufferImBuf(struct ImBuf * ibuf)
+short imb_addencodedbufferImBuf(ImBuf *ibuf)
{
- if (ibuf==NULL) return(FALSE);
+ if(ibuf==NULL) return FALSE;
freeencodedbufferImBuf(ibuf);
- if (ibuf->encodedbuffersize == 0)
+ if(ibuf->encodedbuffersize == 0)
ibuf->encodedbuffersize = 10000;
ibuf->encodedsize = 0;
- if ( (ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, "addencodedbufferImBuf") )){
+ if((ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, "addencodedbufferImBuf"))) {
ibuf->mall |= IB_mem;
ibuf->flags |= IB_mem;
- return (TRUE);
+ return TRUE;
}
- return (FALSE);
+ return FALSE;
}
-short imb_enlargeencodedbufferImBuf(struct ImBuf * ibuf)
+short imb_enlargeencodedbufferImBuf(ImBuf *ibuf)
{
unsigned int newsize, encodedsize;
void *newbuffer;
- if (ibuf==NULL) return(FALSE);
+ if(ibuf==NULL) return FALSE;
- if (ibuf->encodedbuffersize < ibuf->encodedsize) {
+ if(ibuf->encodedbuffersize < ibuf->encodedsize) {
printf("imb_enlargeencodedbufferImBuf: error in parameters\n");
- return(FALSE);
+ return FALSE;
}
- newsize = 2 * ibuf->encodedbuffersize;
- if (newsize < 10000) newsize = 10000;
+ newsize = 2 *ibuf->encodedbuffersize;
+ if(newsize < 10000) newsize = 10000;
newbuffer = MEM_mallocN(newsize, "enlargeencodedbufferImBuf");
- if (newbuffer == NULL) return(FALSE);
+ if(newbuffer == NULL) return FALSE;
- if (ibuf->encodedbuffer) {
+ if(ibuf->encodedbuffer) {
memcpy(newbuffer, ibuf->encodedbuffer, ibuf->encodedsize);
} else {
ibuf->encodedsize = 0;
@@ -269,153 +266,98 @@ short imb_enlargeencodedbufferImBuf(struct ImBuf * ibuf)
ibuf->mall |= IB_mem;
ibuf->flags |= IB_mem;
- return (TRUE);
+ return TRUE;
}
-short imb_addrectfloatImBuf(struct ImBuf * ibuf)
+short imb_addrectfloatImBuf(ImBuf *ibuf)
{
int size;
- if (ibuf==NULL) return(FALSE);
+ if(ibuf==NULL) return FALSE;
imb_freerectfloatImBuf(ibuf);
- size = ibuf->x * ibuf->y;
- size = size * 4 * sizeof(float);
+ size = ibuf->x *ibuf->y;
+ size = size *4 *sizeof(float);
ibuf->channels= 4;
- if ( (ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf")) ){
+ if((ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf"))) {
ibuf->mall |= IB_rectfloat;
ibuf->flags |= IB_rectfloat;
- return (TRUE);
+ return TRUE;
}
- return (FALSE);
+ return FALSE;
}
/* question; why also add zbuf? */
-short imb_addrectImBuf(struct ImBuf * ibuf)
+short imb_addrectImBuf(ImBuf *ibuf)
{
int size;
- if (ibuf==NULL) return(FALSE);
+ if(ibuf==NULL) return FALSE;
imb_freerectImBuf(ibuf);
- size = ibuf->x * ibuf->y;
- size = size * sizeof(unsigned int);
+ size = ibuf->x*ibuf->y;
+ size = size*sizeof(unsigned int);
- if ( (ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf")) ){
+ if((ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf"))) {
ibuf->mall |= IB_rect;
ibuf->flags |= IB_rect;
- if (ibuf->depth > 32) return (addzbufImBuf(ibuf));
- else return (TRUE);
- }
-
- return (FALSE);
-}
-
-
-short imb_addcmapImBuf(struct ImBuf *ibuf)
-{
- int min;
-
- if (ibuf==NULL) return(FALSE);
- IMB_freecmapImBuf(ibuf);
-
- imb_checkncols(ibuf);
- if (ibuf->maxcol == 0) return (TRUE);
-
- if ( (ibuf->cmap = MEM_callocN(sizeof(unsigned int) * ibuf->maxcol, "imb_addcmapImBuf") ) ){
- min = ibuf->maxcol * sizeof(unsigned int);
- if (min > sizeof(dfltcmap)) min = sizeof(dfltcmap);
- memcpy(ibuf->cmap, dfltcmap, min);
- ibuf->mall |= IB_cmap;
- ibuf->flags |= IB_cmap;
- return (TRUE);
+ if(ibuf->depth > 32) return (addzbufImBuf(ibuf));
+ else return TRUE;
}
- return (FALSE);
+ return FALSE;
}
-
-short imb_addplanesImBuf(struct ImBuf *ibuf)
+short imb_addtilesImBuf(ImBuf *ibuf)
{
- int size;
- short skipx,d,y;
- unsigned int **planes;
- unsigned int *point2;
-
- if (ibuf==NULL) return(FALSE);
- imb_freeplanesImBuf(ibuf);
+ if(ibuf==NULL) return FALSE;
- skipx = ((ibuf->x+31) >> 5);
- ibuf->skipx=skipx;
- y=ibuf->y;
- d=ibuf->depth;
-
- planes = MEM_mallocN( (d*skipx*y)*sizeof(int) + d*sizeof(int *), "imb_addplanesImBuf");
-
- ibuf->planes = planes;
- if (planes==0) return (FALSE);
+ if(!ibuf->tiles)
+ if((ibuf->tiles = MEM_callocN(sizeof(unsigned int*)*ibuf->xtiles*ibuf->ytiles, "imb_tiles")))
+ ibuf->mall |= IB_tiles;
- point2 = (unsigned int *)(planes+d);
- size = skipx*y;
-
- for (;d>0;d--){
- *(planes++) = point2;
- point2 += size;
- }
- ibuf->mall |= IB_planes;
- ibuf->flags |= IB_planes;
-
- return (TRUE);
+ return (ibuf->tiles != NULL);
}
-
-struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, uchar bitmap)
+ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, uchar bitmap) /* XXX bitmap argument is deprecated */
{
- struct ImBuf *ibuf;
+ ImBuf *ibuf;
- ibuf = MEM_callocN(sizeof(struct ImBuf), "ImBuf_struct");
- if (bitmap) flags |= IB_planes;
+ ibuf = MEM_callocN(sizeof(ImBuf), "ImBuf_struct");
- if (ibuf){
+ if(ibuf) {
ibuf->x= x;
ibuf->y= y;
ibuf->depth= d;
ibuf->ftype= TGA;
ibuf->channels= 4; /* float option, is set to other values when buffers get assigned */
- if (flags & IB_rect){
- if (imb_addrectImBuf(ibuf)==FALSE){
+ if(flags & IB_rect) {
+ if(imb_addrectImBuf(ibuf)==FALSE) {
IMB_freeImBuf(ibuf);
return NULL;
}
}
- if (flags & IB_rectfloat){
- if (imb_addrectfloatImBuf(ibuf)==FALSE){
+ if(flags & IB_rectfloat) {
+ if(imb_addrectfloatImBuf(ibuf)==FALSE) {
IMB_freeImBuf(ibuf);
return NULL;
}
}
- if (flags & IB_zbuf){
- if (addzbufImBuf(ibuf)==FALSE){
+ if(flags & IB_zbuf) {
+ if(addzbufImBuf(ibuf)==FALSE) {
IMB_freeImBuf(ibuf);
return NULL;
}
}
- if (flags & IB_zbuffloat){
- if (addzbuffloatImBuf(ibuf)==FALSE){
- IMB_freeImBuf(ibuf);
- return NULL;
- }
- }
-
- if (flags & IB_planes){
- if (imb_addplanesImBuf(ibuf)==FALSE){
+ if(flags & IB_zbuffloat) {
+ if(addzbuffloatImBuf(ibuf)==FALSE) {
IMB_freeImBuf(ibuf);
return NULL;
}
@@ -425,37 +367,33 @@ struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, ucha
}
/* does no zbuffers? */
-struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
+ImBuf *IMB_dupImBuf(ImBuf *ibuf1)
{
- struct ImBuf *ibuf2, tbuf;
+ ImBuf *ibuf2, tbuf;
int flags = 0;
int a, x, y;
- if (ibuf1 == NULL) return NULL;
+ if(ibuf1 == NULL) return NULL;
- if (ibuf1->rect) flags |= IB_rect;
- if (ibuf1->rect_float) flags |= IB_rectfloat;
- if (ibuf1->planes) flags |= IB_planes;
+ if(ibuf1->rect) flags |= IB_rect;
+ if(ibuf1->rect_float) flags |= IB_rectfloat;
x = ibuf1->x;
y = ibuf1->y;
- if (ibuf1->flags & IB_fields) y *= 2;
+ if(ibuf1->flags & IB_fields) y *= 2;
ibuf2 = IMB_allocImBuf(x, y, ibuf1->depth, flags, 0);
- if (ibuf2 == NULL) return NULL;
+ if(ibuf2 == NULL) return NULL;
- if (flags & IB_rect)
- memcpy(ibuf2->rect, ibuf1->rect, x * y * sizeof(int));
+ if(flags & IB_rect)
+ memcpy(ibuf2->rect, ibuf1->rect, x *y *sizeof(int));
- if (flags & IB_rectfloat)
- memcpy(ibuf2->rect_float, ibuf1->rect_float, ibuf1->channels * x * y * sizeof(float));
+ if(flags & IB_rectfloat)
+ memcpy(ibuf2->rect_float, ibuf1->rect_float, ibuf1->channels *x *y *sizeof(float));
- if (flags & IB_planes)
- memcpy(*(ibuf2->planes),*(ibuf1->planes),ibuf1->depth * ibuf1->skipx * y * sizeof(int));
-
- if (ibuf1->encodedbuffer) {
+ if(ibuf1->encodedbuffer) {
ibuf2->encodedbuffersize = ibuf1->encodedbuffersize;
- if (imb_addencodedbufferImBuf(ibuf2) == FALSE) {
+ if(imb_addencodedbufferImBuf(ibuf2) == FALSE) {
IMB_freeImBuf(ibuf2);
return NULL;
}
@@ -469,8 +407,6 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
// fix pointers
tbuf.rect = ibuf2->rect;
tbuf.rect_float = ibuf2->rect_float;
- tbuf.planes = ibuf2->planes;
- tbuf.cmap = ibuf2->cmap;
tbuf.encodedbuffer = ibuf2->encodedbuffer;
tbuf.zbuf= NULL;
tbuf.zbuf_float= NULL;
@@ -482,42 +418,36 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
tbuf.c_handle = 0;
tbuf.refcounter = 0;
- // for now don't duplicate image info
- tbuf.img_info = 0;
+ // for now don't duplicate metadata
+ tbuf.metadata = 0;
*ibuf2 = tbuf;
- if (ibuf1->cmap){
- imb_addcmapImBuf(ibuf2);
- if (ibuf2->cmap) memcpy(ibuf2->cmap,ibuf1->cmap,ibuf2->maxcol * sizeof(int));
- }
-
return(ibuf2);
}
/* support for cache limiting */
-static void imbuf_cache_destructor(void * data)
+static void imbuf_cache_destructor(void *data)
{
- struct ImBuf * ibuf = (struct ImBuf*) data;
+ ImBuf *ibuf = (ImBuf*) data;
- imb_freeplanesImBuf(ibuf);
imb_freerectImBuf(ibuf);
imb_freerectfloatImBuf(ibuf);
IMB_freezbufImBuf(ibuf);
IMB_freezbuffloatImBuf(ibuf);
- IMB_freecmapImBuf(ibuf);
freeencodedbufferImBuf(ibuf);
ibuf->c_handle = 0;
}
-static MEM_CacheLimiterC ** get_imbuf_cache_limiter()
+static MEM_CacheLimiterC **get_imbuf_cache_limiter()
{
- static MEM_CacheLimiterC * c = 0;
- if (!c) {
+ static MEM_CacheLimiterC *c = 0;
+
+ if(!c)
c = new_MEM_CacheLimiter(imbuf_cache_destructor);
- }
+
return &c;
}
@@ -527,9 +457,9 @@ void IMB_free_cache_limiter()
*get_imbuf_cache_limiter() = 0;
}
-void IMB_cache_limiter_insert(struct ImBuf * i)
+void IMB_cache_limiter_insert(ImBuf *i)
{
- if (!i->c_handle) {
+ if(!i->c_handle) {
i->c_handle = MEM_CacheLimiter_insert(
*get_imbuf_cache_limiter(), i);
MEM_CacheLimiter_ref(i->c_handle);
@@ -539,39 +469,37 @@ void IMB_cache_limiter_insert(struct ImBuf * i)
}
}
-void IMB_cache_limiter_unmanage(struct ImBuf * i)
+void IMB_cache_limiter_unmanage(ImBuf *i)
{
- if (i->c_handle) {
+ if(i->c_handle) {
MEM_CacheLimiter_unmanage(i->c_handle);
i->c_handle = 0;
}
}
-void IMB_cache_limiter_touch(struct ImBuf * i)
+void IMB_cache_limiter_touch(ImBuf *i)
{
- if (i->c_handle) {
+ if(i->c_handle)
MEM_CacheLimiter_touch(i->c_handle);
- }
}
-void IMB_cache_limiter_ref(struct ImBuf * i)
+void IMB_cache_limiter_ref(ImBuf *i)
{
- if (i->c_handle) {
+ if(i->c_handle)
MEM_CacheLimiter_ref(i->c_handle);
- }
}
-void IMB_cache_limiter_unref(struct ImBuf * i)
+void IMB_cache_limiter_unref(ImBuf *i)
{
- if (i->c_handle) {
+ if(i->c_handle)
MEM_CacheLimiter_unref(i->c_handle);
- }
}
-int IMB_cache_limiter_get_refcount(struct ImBuf * i)
+int IMB_cache_limiter_get_refcount(ImBuf *i)
{
- if (i->c_handle) {
+ if(i->c_handle)
return MEM_CacheLimiter_get_refcount(i->c_handle);
- }
+
return 0;
}
+
diff --git a/source/blender/imbuf/intern/amiga.c b/source/blender/imbuf/intern/amiga.c
deleted file mode 100644
index 4b9e1d85df3..00000000000
--- a/source/blender/imbuf/intern/amiga.c
+++ /dev/null
@@ -1,540 +0,0 @@
-/**
- * amiga.c
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifdef _WIN32
-#include <io.h>
-#define open _open
-#define read _read
-#define close _close
-#define write _write
-#endif
-#include "imbuf.h"
-#include "imbuf_patch.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-#include "BKE_global.h"
-
-#include "IMB_cmap.h"
-#include "IMB_allocimbuf.h"
-#include "IMB_bitplanes.h"
-#include "IMB_amiga.h"
-
-/* actually hard coded endianness */
-#define GET_BIG_LONG(x) (((uchar *) (x))[0] << 24 | ((uchar *) (x))[1] << 16 | ((uchar *) (x))[2] << 8 | ((uchar *) (x))[3])
-#define GET_LITTLE_LONG(x) (((uchar *) (x))[3] << 24 | ((uchar *) (x))[2] << 16 | ((uchar *) (x))[1] << 8 | ((uchar *) (x))[0])
-#define SWAP_L(x) (((x << 24) & 0xff000000) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff))
-#define SWAP_S(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff))
-
-/* more endianness... should move to a separate file... */
-#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__hppa__) || defined (__BIG_ENDIAN__)
-#define GET_ID GET_BIG_LONG
-#define LITTLE_LONG SWAP_LONG
-#else
-#define GET_ID GET_LITTLE_LONG
-#define LITTLE_LONG ENDIAN_NOP
-#endif
-
-static uchar *decodebodyscanl(uchar *body, short bytes, uchar **list, short d)
-{
- for (;d>0;d--){
- uchar *point;
- short todo;
- uchar i,j;
-
- point = *(list++);
- todo=bytes;
- while (todo>0){
- i = *body++;
-
- if (i & 128){ /* fill */
- if (i==128) continue; /* nop */
-
- i=257-i;
- todo-=i;
- j = *(body++);
- do{
- *(point++) = j;
- i--;
- }while (i);
- } else{ /* copy */
- i++;
- todo-=i;
-
- do{
- *(point++) = *(body++);
- i--;
- }while (i);
- }
- }
- if (todo) return (0);
- }
- return(body);
-}
-
-
-static uchar *decodebodyh(struct ImBuf *ibuf, uchar *body)
-{
- if (ibuf->y==1) {
- body=decodebodyscanl(body, WIDTHB(ibuf->x), (uchar **)ibuf->planes, ibuf->depth);
- }
- else {
- unsigned int **list;
- short skipx,i,bytes,y;
-
- list = imb_copyplanelist(ibuf);
- if (list == 0) return (0);
-
- y=ibuf->y;
- bytes = WIDTHB(ibuf->x);
- skipx = ibuf->skipx;
-
- for (;y>0;y--){
- body=decodebodyscanl(body, bytes, (uchar **)list, ibuf->depth);
- if (body == 0) return (0);
-
- for (i=ibuf->depth-1;i>=0;i--){
- list[i] += skipx;
- }
- }
- free(list);
- }
- return(body);
-}
-
-
-static uchar *decodebodykolum(uchar *body, short bytes, uchar **list, short d, int next)
-{
- for (;d>0;d--){
- uchar *point;
- short todo;
- uchar i,j;
-
- point = *(list++);
- todo=bytes;
- while (todo>0){
- i = *body++;
-
- if (i & 128){ /* fill */
- if (i==128) continue; /* nop */
-
- i=257-i;
- todo-=i;
- j = *body++;
- do{
- *point = j;
- point += next;
- i--;
- }while (i);
- }
- else{ /* copy */
- i++;
- todo-=i;
-
- do{
- *point = *body++;
- point += next;
- i--;
- }while (i);
- }
- }
- if (todo) return (0);
- }
- return(body);
-}
-
-
-static uchar *decodebodyv(struct ImBuf *ibuf, uchar *body)
-{
- uchar **list;
- int skipx, i, bytes, times;
-
- list = (uchar **)imb_copyplanelist(ibuf);
- if (list == 0) return (0);
-
- bytes = ibuf->y;
- times = WIDTHB(ibuf->x);
- skipx = ibuf->skipx << 2;
-
- for (;times>0;times--){
- body=decodebodykolum(body,bytes,list,ibuf->depth,skipx);
- if (body == 0) return (0);
-
- for (i=ibuf->depth-1;i>=0;i--){
- list[i] += 1;
- }
- }
- free(list);
- return(body);
-}
-
-static uchar *makebody(uchar **planes, short bytes, short depth, uchar *buf)
-{
- uchar *bitplstart,*temp;
-
- register uchar last,this,*bitpl;
- register short todo;
- register int copy;
-
- bytes--;
- for (;depth>0;depth--){
- bitpl = *(planes++);
- bitplstart = bitpl;
- todo = bytes;
- last = *bitpl++;
- this = *bitpl++;
- copy = last^this;
- while (todo>0){
-
- if (copy){
- do{
- last = this;
- this = *bitpl++;
- if (last == this){
- if (this == bitpl[-3]){ /* three identical ones? */
- todo -= 1; /* set todo */
- break;
- }
- }
- }while (--todo != 0);
-
- copy=bitpl-bitplstart;
- copy -= 1;
- if (todo) copy -= 2;
-
- temp = bitpl;
- bitpl = bitplstart;
-
- while (copy){
- last = copy;
- if (copy>MAXDAT) last = MAXDAT;
- copy -= last;
- *buf++ = last-1;
- do{
- *buf++ = *bitpl++;
- }while(--last != 0);
- }
- bitplstart = bitpl;
- bitpl = temp;
- last = this;
-
- copy = FALSE;
- }
- else{
- while (*bitpl++ == this){ /* search for first different bye */
- if (--todo == 0) break; /* or end of line */
- }
- bitpl -= 1;
- copy = bitpl-bitplstart;
- bitplstart = bitpl;
- todo -= 1;
- this = *bitpl++;
-
- while (copy){
- if (copy>MAXRUN){
- *buf++ = -(MAXRUN-1);
- *buf++ = last;
- copy -= MAXRUN;
- }
- else{
- *buf++ = -(copy-1);
- *buf++ = last;
- break;
- }
- }
- copy=TRUE;
- }
- }
- }
- return (buf);
-}
-
-
-short imb_encodebodyh(struct ImBuf *ibuf, int file)
-{
- uchar *buf, *endbuf, *max;
- int size, line, ok = TRUE;
- unsigned int **list;
- short skipx,i,y;
-
- line = WIDTHB(ibuf->x) * ibuf->depth;
- line += (line >> 6) + 10;
- size = 16 * line;
- if (size < 16384) size = 16384;
-
- buf = (uchar *) malloc(size);
- if (buf == 0) return (0);
-
- max = buf + size - line;
-
- list = imb_copyplanelist(ibuf);
- if (list == 0){
- free(buf);
- return (0);
- }
-
- y=ibuf->y;
- skipx = ibuf->skipx;
- endbuf = buf;
-
- for (y=ibuf->y;y>0;y--){
- endbuf = makebody((uchar **)list, WIDTHB(ibuf->x), ibuf->depth, endbuf);
- if (endbuf==0){
- ok = -20;
- break;
- }
- if (endbuf >= max || y == 1){
- size = endbuf-buf;
- if (write(file,buf,size)!=size) ok = -19;
- endbuf = buf;
- }
- for (i=ibuf->depth-1;i>=0;i--){
- list[i] += skipx;
- }
- if (ok != TRUE) break;
- }
- free(list);
-
- free(buf);
- return(ok);
-}
-
-
-short imb_encodebodyv(struct ImBuf *ibuf, int file)
-{
- struct ImBuf *ibufv;
- uchar *buf,*endbuf;
- short x,offset;
-
- buf = (uchar *) malloc((ibuf->y + (ibuf->y >> 6) + 10) * ibuf->depth);
- if (buf == 0) return (0);
-
- ibufv=IMB_allocImBuf((ibuf->y)<<3,1, ibuf->depth, 0, 1);
- if (ibufv == 0){
- free(buf);
- return (0);
- }
-
- offset=0;
-
- for(x = WIDTHB(ibuf->x);x>0;x--){
- register short i;
-
- for(i = ibuf->depth-1 ;i>=0;i--){
- register uchar *p1,*p2;
- register int skipx;
- register short y;
-
- skipx = (ibuf->skipx)*sizeof(int *);
- p1=(uchar *)ibuf->planes[i];
- p2=(uchar *)ibufv->planes[i];
- p1 += offset;
-
- for (y=ibuf->y;y>0;y--){
- *(p2++) = *p1;
- p1 += skipx;
- }
- }
- offset += 1;
-
- endbuf=makebody((uchar **)ibufv->planes, ibuf->y, ibuf->depth, buf);
- if (endbuf==0) return (-20);
- if (write(file,buf,endbuf-buf)!=endbuf-buf) return (-19);
- }
- free(buf);
- IMB_freeImBuf(ibufv);
- return (TRUE);
-}
-
-static uchar *readbody(struct ImBuf *ibuf, uchar *body)
-{
- int skipbuf,skipbdy,depth,y,offset = 0;
-
- skipbuf = ibuf->skipx;
- skipbdy = WIDTHB(ibuf->x);
-
- for (y = ibuf->y; y> 0; y--){
- for( depth = 0; depth < ibuf->depth; depth ++){
- memcpy(ibuf->planes[depth] + offset, body, skipbdy);
- body += skipbdy;
- }
- offset += skipbuf;
- }
- return body;
-}
-
-struct ImBuf *imb_loadamiga(int *iffmem,int flags)
-{
- int chunk,totlen,len,*cmap=0,cmaplen =0,*mem,ftype=0;
- uchar *body=0;
- struct BitMapHeader bmhd;
- struct ImBuf *ibuf=0;
-
- mem = iffmem;
- bmhd.w = 0;
-
- if (GET_ID(mem) != FORM) return (0);
- if (GET_ID(mem+2) != ILBM) return (0);
- totlen= (GET_BIG_LONG(mem+1) + 1) & ~1;
- mem += 3;
- totlen -= 4;
-
-
- while(totlen > 0){
- chunk = GET_ID(mem);
- len= (GET_BIG_LONG(mem+1) + 1) & ~1;
- mem += 2;
-
- totlen -= len+8;
-
- switch (chunk){
- case BMHD:
- memcpy(&bmhd, mem, sizeof(struct BitMapHeader));
-
- bmhd.w = BIG_SHORT(bmhd.w);
- bmhd.h = BIG_SHORT(bmhd.h);
- bmhd.x = BIG_SHORT(bmhd.x);
- bmhd.y = BIG_SHORT(bmhd.y);
- bmhd.transparentColor = BIG_SHORT(bmhd.transparentColor);
- bmhd.pageWidth = BIG_SHORT(bmhd.pageWidth);
- bmhd.pageHeight = BIG_SHORT(bmhd.pageHeight);
-
- break;
- case BODY:
- body = (uchar *)mem;
- break;
- case CMAP:
- cmap = mem;
- cmaplen = len/3;
- break;
- case CAMG:
- ftype = GET_BIG_LONG(mem);
- break;
- }
- mem = (int *)((uchar *)mem +len);
- if (body) break;
- }
- if (bmhd.w == 0) return (0);
- if (body == 0) return (0);
-
- if (flags & IB_test) ibuf = IMB_allocImBuf(bmhd.w, bmhd.h, bmhd.nPlanes, 0, 0);
- else ibuf = IMB_allocImBuf(bmhd.w, bmhd.h, bmhd.nPlanes + (bmhd.masking & 1),0,1);
-
- if (ibuf == 0) return (0);
-
- ibuf->ftype = (ftype | AMI);
- ibuf->profile = IB_PROFILE_SRGB;
-
- if (cmap){
- ibuf->mincol = 0;
- ibuf->maxcol = cmaplen;
- imb_addcmapImBuf(ibuf);
- imb_makecolarray(ibuf, (uchar *)cmap, 0);
- }
-
- if (flags & IB_test){
- if (flags & IB_freem) free(iffmem);
- return(ibuf);
- }
-
- switch (bmhd.compression){
- case 0:
- body= readbody(ibuf, body);
- break;
- case 1:
- body= decodebodyh(ibuf,body);
- break;
- case 2:
- body= decodebodyv(ibuf,body);
- ibuf->type |= IB_subdlta;
- break;
- }
-
- if (flags & IB_freem) free(iffmem);
-
- if (body == 0){
- free (ibuf);
- return(0);
- }
-
- /* forget stencil */
- ibuf->depth = bmhd.nPlanes;
-
- if (flags & IB_rect){
- imb_addrectImBuf(ibuf);
- imb_bptolong(ibuf);
- imb_freeplanesImBuf(ibuf);
- if (ibuf->cmap){
- if ((flags & IB_cmap) == 0) IMB_applycmap(ibuf);
- } else if (ibuf->depth == 18){
- int i,col;
- unsigned int *rect;
-
- rect = ibuf->rect;
- for(i=ibuf->x * ibuf->y ; i>0 ; i--){
- col = *rect;
- col = ((col & 0x3f000) << 6) + ((col & 0xfc0) << 4) + ((col & 0x3f) << 2);
- col += (col & 0xc0c0c0) >> 6;
- *rect++ = col;
- }
- ibuf->depth = 24;
- } else if (ibuf->depth <= 8) { /* no colormap and no 24 bits: b&w */
- uchar *rect;
- int size, shift;
-
- if (ibuf->depth < 8){
- rect = (uchar *) ibuf->rect;
- rect += 3;
- shift = 8 - ibuf->depth;
- for (size = ibuf->x * ibuf->y; size > 0; size --){
- rect[0] <<= shift;
- rect += 4;
- }
- }
- rect = (uchar *) ibuf->rect;
- for (size = ibuf->x * ibuf->y; size > 0; size --){
- rect[1] = rect[2] = rect[3];
- rect += 4;
- }
- ibuf->depth = 8;
- }
- }
-
- if ((flags & IB_ttob) == 0) IMB_flipy(ibuf);
-
- if (ibuf) {
- if (ibuf->rect)
- if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
- }
-
- return (ibuf);
-}
diff --git a/source/blender/imbuf/intern/anim.c b/source/blender/imbuf/intern/anim.c
index 5a5b5ada4a1..096ed499f85 100644
--- a/source/blender/imbuf/intern/anim.c
+++ b/source/blender/imbuf/intern/anim.c
@@ -60,11 +60,13 @@
#include "BLI_blenlib.h" /* BLI_remlink BLI_filesize BLI_addtail
BLI_countlist BLI_stringdec */
+#include "MEM_guardedalloc.h"
+
#include "DNA_userdef_types.h"
#include "BKE_global.h"
+#include "BKE_depsgraph.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "AVI_avi.h"
@@ -78,9 +80,7 @@
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_bitplanes.h"
#include "IMB_anim.h"
-#include "IMB_anim5.h"
#ifdef WITH_FFMPEG
#include <libavformat/avformat.h>
@@ -94,8 +94,13 @@
#define FFMPEG_CODEC_IS_POINTER 1
#endif
+#if (LIBAVCODEC_VERSION_MAJOR >= 52) && (LIBAVCODEC_VERSION_MINOR >= 29) && \
+ (LIBSWSCALE_VERSION_MAJOR >= 0) && (LIBSWSCALE_VERSION_MINOR >= 10)
+#define FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
#endif
+#endif //WITH_FFMPEG
+
#ifdef WITH_REDCODE
#ifdef _WIN32 /* on windows we use the ones in extern instead */
#include "libredcode/format.h"
@@ -220,7 +225,13 @@ static void free_anim_movie(struct anim * anim) { ; }
#endif
-static int an_stringdec(char *string, char* kop, char *staart,unsigned short *numlen) {
+#if defined(_WIN32)
+# define PATHSEPERATOR '\\'
+#else
+# define PATHSEPERATOR '/'
+#endif
+
+static int an_stringdec(const char *string, char* head, char *tail, unsigned short *numlen) {
unsigned short len,nume,nums=0;
short i,found=FALSE;
@@ -228,7 +239,7 @@ static int an_stringdec(char *string, char* kop, char *staart,unsigned short *nu
nume = len;
for(i=len-1;i>=0;i--){
- if (string[i]=='/') break;
+ if (string[i]==PATHSEPERATOR) break;
if (isdigit(string[i])) {
if (found){
nums=i;
@@ -242,21 +253,21 @@ static int an_stringdec(char *string, char* kop, char *staart,unsigned short *nu
}
}
if (found){
- strcpy(staart,&string[nume+1]);
- strcpy(kop,string);
- kop[nums]=0;
+ strcpy(tail ,&string[nume+1]);
+ strcpy(head, string);
+ head[nums]= '\0';
*numlen=nume-nums+1;
return ((int)atoi(&(string[nums])));
}
- staart[0]=0;
- strcpy(kop,string);
+ tail[0]= '\0';
+ strcpy(head, string);
*numlen=0;
- return (1);
+ return TRUE;
}
-static void an_stringenc(char *string, char *head, char *start, unsigned short numlen, int pic) {
- BLI_stringenc(string, head, start, numlen, pic);
+static void an_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) {
+ BLI_stringenc(string, head, tail, numlen, pic);
}
static void free_anim_avi (struct anim *anim) {
@@ -316,7 +327,6 @@ void IMB_free_anim(struct anim * anim) {
}
IMB_free_anim_ibuf(anim);
- free_anim_anim5(anim);
free_anim_movie(anim);
free_anim_avi(anim);
@@ -330,7 +340,7 @@ void IMB_free_anim(struct anim * anim) {
free_anim_redcode(anim);
#endif
- free(anim);
+ MEM_freeN(anim);
}
void IMB_close_anim(struct anim * anim) {
@@ -465,7 +475,7 @@ static ImBuf * avi_fetchibuf (struct anim *anim, int position) {
if (anim->pgf) {
lpbi = AVIStreamGetFrame(anim->pgf, position + AVIStreamStart(anim->pavi[anim->firstvideo]));
if (lpbi) {
- ibuf = IMB_ibImageFromMemory((int *) lpbi, 100, IB_rect);
+ ibuf = IMB_ibImageFromMemory((unsigned char *) lpbi, 100, IB_rect);
//Oh brother...
}
}
@@ -520,6 +530,13 @@ static int startffmpeg(struct anim * anim) {
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
+#ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
+ /* The following for color space determination */
+ int srcRange, dstRange, brightness, contrast, saturation;
+ int *table;
+ const int *inv_table;
+#endif
+
if (anim == 0) return(-1);
do_init_ffmpeg();
@@ -574,9 +591,9 @@ static int startffmpeg(struct anim * anim) {
anim->duration = pFormatCtx->duration * pCodecCtx->frame_rate
/ pCodecCtx->frame_rate_base / AV_TIME_BASE;
#else
- anim->duration = pFormatCtx->duration
+ anim->duration = ceil(pFormatCtx->duration
* av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate)
- / AV_TIME_BASE;
+ / AV_TIME_BASE);
#endif
anim->params = 0;
@@ -647,10 +664,139 @@ static int startffmpeg(struct anim * anim) {
anim->pCodecCtx = NULL;
return -1;
}
+
+#ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
+ /* Try do detect if input has 0-255 YCbCR range (JFIF Jpeg MotionJpeg) */
+ if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int**)&inv_table, &srcRange,
+ &table, &dstRange, &brightness, &contrast, &saturation)) {
+
+ srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG;
+ inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace);
+
+ if(sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange,
+ table, dstRange, brightness, contrast, saturation)) {
+
+ printf("Warning: Could not set libswscale colorspace details.\n");
+ }
+ }
+ else {
+ printf("Warning: Could not set libswscale colorspace details.\n");
+ }
+#endif
return (0);
}
+static void ffmpeg_postprocess(struct anim * anim, ImBuf * ibuf,
+ int * filter_y)
+{
+ AVFrame * input = anim->pFrame;
+
+ /* This means the data wasnt read properly,
+ this check stops crashing */
+ if (input->data[0]==0 && input->data[1]==0
+ && input->data[2]==0 && input->data[3]==0){
+ fprintf(stderr, "ffmpeg_fetchibuf: "
+ "data not read properly...\n");
+ return;
+ }
+
+ if (anim->ib_flags & IB_animdeinterlace) {
+ if (avpicture_deinterlace(
+ (AVPicture*)
+ anim->pFrameDeinterlaced,
+ (const AVPicture*)
+ anim->pFrame,
+ anim->pCodecCtx->pix_fmt,
+ anim->pCodecCtx->width,
+ anim->pCodecCtx->height)
+ < 0) {
+ *filter_y = 1;
+ } else {
+ input = anim->pFrameDeinterlaced;
+ }
+ }
+
+ if (ENDIAN_ORDER == B_ENDIAN) {
+ int * dstStride = anim->pFrameRGB->linesize;
+ uint8_t** dst = anim->pFrameRGB->data;
+ int dstStride2[4] = { dstStride[0], 0, 0, 0 };
+ uint8_t* dst2[4] = { dst[0], 0, 0, 0 };
+ int x,y,h,w;
+ unsigned char* bottom;
+ unsigned char* top;
+
+ sws_scale(anim->img_convert_ctx,
+ (const uint8_t * const *)input->data,
+ input->linesize,
+ 0,
+ anim->pCodecCtx->height,
+ dst2,
+ dstStride2);
+
+ /* workaround: sws_scale bug
+ sets alpha = 0 and compensate
+ for altivec-bugs and flipy... */
+
+ bottom = (unsigned char*) ibuf->rect;
+ top = bottom + ibuf->x * (ibuf->y-1) * 4;
+
+ h = (ibuf->y + 1) / 2;
+ w = ibuf->x;
+
+ for (y = 0; y < h; y++) {
+ unsigned char tmp[4];
+ unsigned int * tmp_l =
+ (unsigned int*) tmp;
+ tmp[3] = 0xff;
+
+ for (x = 0; x < w; x++) {
+ tmp[0] = bottom[0];
+ tmp[1] = bottom[1];
+ tmp[2] = bottom[2];
+
+ bottom[0] = top[0];
+ bottom[1] = top[1];
+ bottom[2] = top[2];
+ bottom[3] = 0xff;
+
+ *(unsigned int*) top = *tmp_l;
+
+ bottom +=4;
+ top += 4;
+ }
+ top -= 8 * w;
+ }
+ } else {
+ int * dstStride = anim->pFrameRGB->linesize;
+ uint8_t** dst = anim->pFrameRGB->data;
+ int dstStride2[4] = { -dstStride[0], 0, 0, 0 };
+ uint8_t* dst2[4] = { dst[0] + (anim->y - 1)*dstStride[0],
+ 0, 0, 0 };
+ int i;
+ unsigned char* r;
+
+ sws_scale(anim->img_convert_ctx,
+ (const uint8_t * const *)input->data,
+ input->linesize,
+ 0,
+ anim->pCodecCtx->height,
+ dst2,
+ dstStride2);
+
+ r = (unsigned char*) ibuf->rect;
+
+ /* workaround sws_scale bug: older version of
+ sws_scale set alpha = 0... */
+ if (r[3] == 0) {
+ for (i = 0; i < ibuf->x * ibuf->y; i++) {
+ r[3] = 0xff;
+ r += 4;
+ }
+ }
+ }
+}
+
static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
ImBuf * ibuf;
int frameFinished;
@@ -658,6 +804,8 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
int64_t pts_to_search = 0;
int pos_found = 1;
int filter_y = 0;
+ int seek_by_bytes= 0;
+ int preseek_count = 0;
if (anim == 0) return (0);
@@ -690,6 +838,8 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
}
}
+ seek_by_bytes = !!(anim->pFormatCtx->iformat->flags & AVFMT_TS_DISCONT);
+
if (position != anim->curposition + 1) {
#ifdef FFMPEG_OLD_FRAME_RATE
double frame_rate =
@@ -703,21 +853,41 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
double time_base =
av_q2d(anim->pFormatCtx->streams[anim->videoStream]
->time_base);
- long long pos = (long long) (position - anim->preseek)
- * AV_TIME_BASE / frame_rate;
+ long long pos;
long long st_time = anim->pFormatCtx
->streams[anim->videoStream]->start_time;
+ int ret;
- if (pos < 0) {
- pos = 0;
- }
+ if (seek_by_bytes) {
+ pos = position - anim->preseek;
+ if (pos < 0) {
+ pos = 0;
+ }
+ preseek_count = position - pos;
- if (st_time != AV_NOPTS_VALUE) {
- pos += st_time * AV_TIME_BASE * time_base;
+ pos *= anim->pFormatCtx->bit_rate / frame_rate;
+ pos /= 8;
+ } else {
+ pos = (long long) (position - anim->preseek)
+ * AV_TIME_BASE / frame_rate;
+ if (pos < 0) {
+ pos = 0;
+ }
+
+ if (st_time != AV_NOPTS_VALUE) {
+ pos += st_time * AV_TIME_BASE * time_base;
+ }
}
- av_seek_frame(anim->pFormatCtx, -1,
- pos, AVSEEK_FLAG_BACKWARD);
+ ret = av_seek_frame(anim->pFormatCtx, -1,
+ pos,
+ AVSEEK_FLAG_BACKWARD | (
+ seek_by_bytes
+ ? AVSEEK_FLAG_ANY
+ | AVSEEK_FLAG_BYTE : 0));
+ if (ret < 0) {
+ fprintf(stderr, "error while seeking: %d\n", ret);
+ }
pts_to_search = (long long)
(((double) position) / time_base / frame_rate);
@@ -735,132 +905,28 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
anim->pFrame, &frameFinished,
packet.data, packet.size);
- if (frameFinished && !pos_found) {
- if (packet.dts >= pts_to_search) {
- pos_found = 1;
- anim->curposition = position;
- }
- }
-
- if(frameFinished && pos_found == 1) {
- AVFrame * input = anim->pFrame;
-
- /* This means the data wasnt read properly,
- this check stops crashing */
- if (input->data[0]==0 && input->data[1]==0
- && input->data[2]==0 && input->data[3]==0){
- av_free_packet(&packet);
- break;
- }
-
- if (anim->ib_flags & IB_animdeinterlace) {
- if (avpicture_deinterlace(
- (AVPicture*)
- anim->pFrameDeinterlaced,
- (const AVPicture*)
- anim->pFrame,
- anim->pCodecCtx->pix_fmt,
- anim->pCodecCtx->width,
- anim->pCodecCtx->height)
- < 0) {
- filter_y = 1;
- } else {
- input = anim->pFrameDeinterlaced;
- }
- }
+ if (seek_by_bytes && preseek_count > 0) {
+ preseek_count--;
+ }
- if (ENDIAN_ORDER == B_ENDIAN) {
- int * dstStride
- = anim->pFrameRGB->linesize;
- uint8_t** dst = anim->pFrameRGB->data;
- int dstStride2[4]
- = { dstStride[0], 0, 0, 0 };
- uint8_t* dst2[4]= {
- dst[0], 0, 0, 0 };
- int x,y,h,w;
- unsigned char* bottom;
- unsigned char* top;
-
- sws_scale(anim->img_convert_ctx,
- input->data,
- input->linesize,
- 0,
- anim->pCodecCtx->height,
- dst2,
- dstStride2);
-
- /* workaround: sws_scale
- sets alpha = 0 and compensate
- for altivec-bugs and flipy... */
-
- bottom = (unsigned char*) ibuf->rect;
- top = bottom
- + ibuf->x * (ibuf->y-1) * 4;
-
- h = (ibuf->y + 1) / 2;
- w = ibuf->x;
-
- for (y = 0; y < h; y++) {
- unsigned char tmp[4];
- unsigned int * tmp_l =
- (unsigned int*) tmp;
- tmp[3] = 0xff;
-
- for (x = 0; x < w; x++) {
- tmp[0] = bottom[0];
- tmp[1] = bottom[1];
- tmp[2] = bottom[2];
-
- bottom[0] = top[0];
- bottom[1] = top[1];
- bottom[2] = top[2];
- bottom[3] = 0xff;
-
- *(unsigned int*) top
- = *tmp_l;
-
- bottom +=4;
- top += 4;
- }
- top -= 8 * w;
+ if (frameFinished && !pos_found) {
+ if (seek_by_bytes) {
+ if (!preseek_count) {
+ pos_found = 1;
+ anim->curposition = position;
}
-
- av_free_packet(&packet);
- break;
} else {
- int * dstStride
- = anim->pFrameRGB->linesize;
- uint8_t** dst = anim->pFrameRGB->data;
- int dstStride2[4]
- = { -dstStride[0], 0, 0, 0 };
- uint8_t* dst2[4]= {
- dst[0]
- + (anim->y - 1)*dstStride[0],
- 0, 0, 0 };
- int i;
- unsigned char* r;
-
- sws_scale(anim->img_convert_ctx,
- input->data,
- input->linesize,
- 0,
- anim->pCodecCtx->height,
- dst2,
- dstStride2);
-
- /* workaround: sws_scale
- sets alpha = 0... */
-
- r = (unsigned char*) ibuf->rect;
-
- for (i = 0; i < ibuf->x * ibuf->y;i++){
- r[3] = 0xff;
- r+=4;
+ if (packet.dts >= pts_to_search) {
+ pos_found = 1;
+ anim->curposition = position;
}
-
- av_free_packet(&packet);
- break;
}
+ }
+
+ if(frameFinished && pos_found == 1) {
+ ffmpeg_postprocess(anim, ibuf, &filter_y);
+ av_free_packet(&packet);
+ break;
}
}
@@ -958,7 +1024,6 @@ static struct ImBuf * anim_getnew(struct anim * anim) {
if (anim == NULL) return(0);
- free_anim_anim5(anim);
free_anim_movie(anim);
free_anim_avi(anim);
#ifdef WITH_QUICKTIME
@@ -976,10 +1041,6 @@ static struct ImBuf * anim_getnew(struct anim * anim) {
anim->curtype = imb_get_anim_type(anim->name);
switch (anim->curtype) {
- case ANIM_ANIM5:
- if (startanim5(anim)) return (0);
- ibuf = anim5_fetchibuf(anim);
- break;
case ANIM_SEQUENCE:
ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
if (ibuf) {
@@ -1057,26 +1118,13 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) {
if (position >= anim->duration) return(0);
switch(anim->curtype) {
- case ANIM_ANIM5:
- if (anim->curposition > position) rewindanim5(anim);
- while (anim->curposition < position) {
- if (nextanim5(anim)) return (0);
- }
- ibuf = anim5_fetchibuf(anim);
- ibuf->profile = IB_PROFILE_SRGB;
- break;
case ANIM_SEQUENCE:
pic = an_stringdec(anim->first, head, tail, &digits);
pic += position;
an_stringenc(anim->name, head, tail, digits, pic);
- ibuf = IMB_loadiffname(anim->name, LI_rect);
+ ibuf = IMB_loadiffname(anim->name, IB_rect);
if (ibuf) {
anim->curposition = position;
- /* patch... by freeing the cmap you prevent a double apply cmap... */
- /* probably the IB_CMAP option isn't working proper
- * after the abgr->rgba reconstruction
- */
- IMB_freecmapImBuf(ibuf);
}
break;
case ANIM_MOVIE:
@@ -1116,7 +1164,6 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) {
}
if (ibuf) {
- if (anim->ib_flags & IB_ttob) IMB_flipy(ibuf);
if (filter_y) IMB_filtery(ibuf);
sprintf(ibuf->name, "%s.%04d", anim->name, anim->curposition + 1);
@@ -1124,16 +1171,6 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) {
return(ibuf);
}
-struct ImBuf * IMB_anim_nextpic(struct anim * anim) {
- struct ImBuf * ibuf = 0;
-
- if (anim == 0) return(0);
-
- ibuf = IMB_anim_absolute(anim, anim->curposition + 1);
-
- return(ibuf);
-}
-
/***/
int IMB_anim_get_duration(struct anim *anim) {
diff --git a/source/blender/imbuf/intern/anim5.c b/source/blender/imbuf/intern/anim5.c
deleted file mode 100644
index 41c4c2c610b..00000000000
--- a/source/blender/imbuf/intern/anim5.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/**
- * anim5.c
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): phase, code torn apart from anim.c
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "BLI_blenlib.h" /* BLI_remlink BLI_filesize BLI_addtail
- BLI_countlist BLI_stringdec */
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-#include "IMB_cmap.h"
-#include "IMB_allocimbuf.h"
-#include "IMB_bitplanes.h"
-#include "IMB_amiga.h"
-
-#include "IMB_anim.h"
-
-#include "IMB_anim5.h"
-
-#ifdef _WIN32
-#include <io.h>
-#include "BLI_winstuff.h"
-#endif
-
-typedef struct Anhd{
- unsigned char type, mask;
- unsigned short w, h;
- unsigned short x, y;
- unsigned short abs16, abs, reala6, real;
- unsigned char interleave, pad0;
- unsigned short bits16, bits;
- unsigned char pad[16];
-}Anhd;
-
-typedef struct Anim5Delta {
- struct Anim5Delta * next, * prev;
- void * data;
- int type;
-}Anim5Delta;
-
-
-/* om anim5's te kunnen lezen, moet een aantal gegevens bijgehouden worden:
- * Een lijst van pointers naar delta's, in geheugen of ge'mmap'ed
- *
- * Mogelijk kan er ook een 'skiptab' aangelegd worden, om sneller
- * sprongen te kunnen maken.
- *
- * Er moeten niet direct al plaatjes gegenereed worden, dit maakt de
- * routines onbruikbaar om snel naar het goede plaatje te springen.
- * Een routine voert dus de delta's uit, een andere routine maakt van
- * voorgrondplaatje een ibuf;
- */
-
-
-/*
- een aantal functie pointers moet geinporteerd worden, zodat er niet
- nog meer library's / objects meegelinkt hoeven te worden.
-
- Dezelfde structuur moet ook gebruikt kunnen worden voor het wegschrijven
- van animaties. Hoe geef je dit aan ?
-
- Hoe snel kunnen 10 .dlta's gedecomprimeerd worden
- (zonder omzetten naar rect).
-
- 1 - zoek naar 1e plaatje, animatie die aan de eisen voldoet
- 2 - probeer volgende plaatje te vinden:
- anim5 - decomprimeer
- sequence - teller ophogen
- directory - volgende entry
- 3 - geen succes ? ga naar 1.
-
-
-*/
-
-/*
- 1. Initialiseer routine met toegestane reeksen, en eerste naam
- - series op naam (.0001)
- - directories
- - anim5 animaties
- - TGA delta's
- - iff 24bits delta's (.delta)
-
- 2. haal volgende (vorige ?) plaatje op.
-
- 3. vrijgeven
-*/
-
-/* selectie volgorde is:
- 1 - anim5()
- 2 - name
- 3 - dir
-*/
-
-void free_anim_anim5(struct anim * anim) {
- ListBase * animbase;
- Anim5Delta * delta, * next;
-
- if (anim == NULL) return;
-
- animbase = &anim->anim5base;
- delta = animbase->first;
-
- while (delta) {
- next = delta->next;
-
- if (delta->type == ANIM5_MALLOC) free(delta->data);
- BLI_remlink(animbase, delta);
- free(delta);
-
- delta = next;
- }
-
- if (anim->anim5mmap && anim->anim5len) {
- MEM_freeN(anim->anim5mmap);
- }
-
- anim->anim5mmap = NULL;
- anim->anim5len = 0;
- anim->anim5curdlta = 0;
- anim->duration = 0;
-}
-
-static void planes_to_rect(struct ImBuf * ibuf, int flags) {
- if (ibuf == 0) return;
-
- /* dit komt regelrecht uit de amiga.c */
-
- if (flags & IB_rect && ibuf->rect == 0) {
- imb_addrectImBuf(ibuf);
- imb_bptolong(ibuf);
- IMB_flipy(ibuf);
- imb_freeplanesImBuf(ibuf);
-
- if (ibuf->cmap){
- if ((flags & IB_cmap) == 0) {
- IMB_applycmap(ibuf);
- IMB_convert_rgba_to_abgr(ibuf);
- }
- } else if (ibuf->depth == 18){
- int i,col;
- unsigned int *rect;
-
- rect = ibuf->rect;
- for(i=ibuf->x * ibuf->y ; i>0 ; i--){
- col = *rect;
- col = ((col & 0x3f000) << 6) + ((col & 0xfc0) << 4)
- + ((col & 0x3f) << 2);
- col += (col & 0xc0c0c0) >> 6;
- *rect++ = col;
- }
- ibuf->depth = 24;
- } else if (ibuf->depth <= 8) {
- /* geen colormap en geen 24 bits: zwartwit */
- uchar *rect;
- int size, shift;
-
- if (ibuf->depth < 8){
- rect = (uchar *) ibuf->rect;
- rect += 3;
- shift = 8 - ibuf->depth;
- for (size = ibuf->x * ibuf->y; size > 0; size --){
- rect[0] <<= shift;
- rect += 4;
- }
- }
- rect = (uchar *) ibuf->rect;
- for (size = ibuf->x * ibuf->y; size > 0; size --){
- rect[1] = rect[2] = rect[3];
- rect += 4;
- }
- ibuf->depth = 8;
- }
- }
-}
-
-
-static void anim5decode(struct ImBuf * ibuf, uchar * dlta) {
- uchar depth;
- int skip;
- int *ofspoint;
- uchar **planes;
-
- /* composition delta:
- list with ofsets for delta' s by bitplane (ofspoint)
- by column in delta (point)
- number of operations (noops)
- code
- associated data
- ...
- ...
- */
-
- dlta += 8;
-
- ofspoint = (int *)dlta;
- skip = ibuf->skipx * sizeof(int *);
- planes = (uchar **)ibuf->planes;
-
- for(depth=ibuf->depth ; depth>0 ; depth--){
- if (GET_BIG_LONG(ofspoint)){
- uchar *planestart;
- uchar *point;
- uchar x;
-
- point = dlta + GET_BIG_LONG(ofspoint);
- planestart = planes[0];
- x = (ibuf->x + 7) >> 3;
-
- do{
- uchar noop;
-
- if ( (noop = *(point++)) ){
- uchar *plane;
- uchar code;
-
- plane = planestart;
- do{
- if ((code = *(point++))==0){
- uchar val;
-
- code = *(point++);
- val = *(point++);
- do {
- plane[0] = val;
- plane += skip;
- } while(--code);
-
- } else if (code & 128){
-
- code &= 0x7f;
- do{
- plane[0] = *(point++);
- plane += skip;
- } while(--code);
-
- } else plane += code * skip;
-
- } while(--noop);
- }
- planestart++;
- } while(--x);
- }
- ofspoint++;
- planes++;
- }
-}
-
-
-static void anim5xordecode(struct ImBuf * ibuf, uchar * dlta) {
- uchar depth;
- int skip;
- int *ofspoint;
- uchar **planes;
-
- /* samenstelling delta:
- lijst met ofsets voor delta's per bitplane (ofspoint)
- per kolom in delta (point)
- aantal handelingen (noops)
- code
- bijbehorende data
- ...
- ...
- */
-
- dlta += 8;
-
- ofspoint = (int *)dlta;
- skip = ibuf->skipx * sizeof(int *);
- planes = (uchar **)ibuf->planes;
-
- for(depth=ibuf->depth ; depth>0 ; depth--){
-
- if (GET_BIG_LONG(ofspoint)){
- uchar *planestart;
- uchar *point;
- uchar x;
-
- point = dlta + GET_BIG_LONG(ofspoint);
- planestart = planes[0];
- x = (ibuf->x + 7) >> 3;
-
- do{
- uchar noop;
-
- if ( (noop = *(point++)) ){
- uchar *plane;
- uchar code;
-
- plane = planestart;
- do{
- if ((code = *(point++))==0){
- uchar val;
-
- code = *(point++);
- val = *(point++);
- do{
- plane[0] ^= val;
- plane += skip;
- }while(--code);
-
- } else if (code & 128){
-
- code &= 0x7f;
- do{
- plane[0] ^= *(point++);
- plane += skip;
- }while(--code);
-
- } else plane += code * skip;
-
- }while(--noop);
- }
- planestart++;
- }while(--x);
- }
- ofspoint++;
- planes++;
- }
-}
-
-
-int nextanim5(struct anim * anim) {
- Anim5Delta * delta;
- struct ImBuf * ibuf;
-
- if (anim == 0) return(-1);
-
- delta = anim->anim5curdlta;
-
- if (delta == 0) return (-1);
-
- if (anim->anim5flags & ANIM5_SNGBUF) {
- ibuf = anim->ibuf1;
- if (ibuf == 0) return (0);
- anim->anim5decode(ibuf, delta->data);
- } else {
- ibuf = anim->ibuf2;
- if (ibuf == 0) return (0);
- anim->anim5decode(ibuf, delta->data);
- anim->ibuf2 = anim->ibuf1;
- anim->ibuf1 = ibuf;
- }
-
- anim->anim5curdlta = anim->anim5curdlta->next;
- anim->curposition++;
-
- return(0);
-}
-
-int rewindanim5(struct anim * anim) {
- Anim5Delta * delta;
- struct ImBuf * ibuf;
-
- if (anim == 0) return (-1);
-
- IMB_free_anim_ibuf(anim);
-
- delta = anim->anim5base.first;
- if (delta == 0) return (-1);
-
- ibuf = IMB_loadiffmem(delta->data, IB_planes);
- if (ibuf == 0) return(-1);
-
- anim->ibuf1 = ibuf;
- if ((anim->anim5flags & ANIM5_SNGBUF) == 0) anim->ibuf2 = IMB_dupImBuf(ibuf);
-
- anim->anim5curdlta = delta->next;
- anim->curposition = 0;
-
- return(0);
-}
-
-
-int startanim5(struct anim * anim) {
- int file, buf[20], totlen;
- unsigned int len;
- short * mem;
- ListBase * animbase;
- Anim5Delta * delta;
- Anhd anhd;
-
- /* Controles */
-
- if (anim == 0) return(-1);
-
- file = open(anim->name,O_BINARY|O_RDONLY);
- if (file < 0) return (-1);
-
- if (read(file, buf, 24) != 24) {
- close(file);
- return(-1);
- }
-
- if ((GET_ID(buf) != FORM) || (GET_ID(buf + 2) != ANIM)
- || (GET_ID(buf + 3) != FORM) || (GET_ID(buf + 5) != ILBM)){
- printf("No anim5 file %s\n",anim->name);
- close(file);
- return (-1);
- }
-
- /* de hele file wordt in het geheugen gemapped */
-
- totlen = BLI_filesize(file);
- if (totlen>0 && file>=0) {
- lseek(file, 0L, SEEK_SET);
-
- mem= MEM_mallocN(totlen, "mmap");
- if (read(file, mem, totlen) != totlen) {
- MEM_freeN(mem);
- mem = NULL;
- }
- } else {
- mem = NULL;
- }
- close (file);
-
- if (!mem) return (-1);
-
- anhd.interleave = 0;
- anhd.bits = 0;
- anhd.type = 5;
-
- anim->anim5mmap = mem;
- anim->anim5len = totlen;
- anim->anim5flags = 0;
- anim->duration = 0;
-
- animbase = & anim->anim5base;
- animbase->first = animbase->last = 0;
-
- /* eerste plaatje inlezen */
-
- mem = mem + 6;
- totlen -= 12;
-
- len = GET_BIG_LONG(mem + 2);
- len = (len + 8 + 1) & ~1;
- delta = NEW(Anim5Delta);
-
- delta->data = mem;
- delta->type = ANIM5_MMAP;
-
- BLI_addtail(animbase, delta);
-
- mem += (len >> 1);
- totlen -= len;
-
- while (totlen > 0) {
- len = GET_BIG_LONG(mem + 2);
- len = (len + 8 + 1) & ~1;
-
- switch(GET_ID(mem)){
- case FORM:
- len = 12;
- break;
- case ANHD:
- memcpy(&anhd, mem + 4, sizeof(Anhd));
- break;
- case DLTA:
- delta = NEW(Anim5Delta);
- delta->data = mem;
- delta->type = ANIM5_MMAP;
- BLI_addtail(animbase, delta);
- break;
- }
-
- mem += (len >> 1);
- totlen -= len;
- }
-
- if (anhd.interleave == 1) anim->anim5flags |= ANIM5_SNGBUF;
- if (BIG_SHORT(anhd.bits) & 2) anim->anim5decode = anim5xordecode;
- else anim->anim5decode = anim5decode;
-
- /* laatste twee delta's wissen */
-
- delta = animbase->last;
- if (delta) {
- BLI_remlink(animbase, delta);
- free(delta);
- }
-
- if ((anim->anim5flags & ANIM5_SNGBUF) == 0) {
- delta = animbase->last;
- if (delta) {
- BLI_remlink(animbase, delta);
- free(delta);
- }
- }
-
- anim->duration = BLI_countlist(animbase);
-
- return(rewindanim5(anim));
-}
-
-
-struct ImBuf * anim5_fetchibuf(struct anim * anim) {
- struct ImBuf * ibuf;
-
- if (anim == 0) return (0);
-
- ibuf = IMB_dupImBuf(anim->ibuf1);
- planes_to_rect(ibuf, anim->ib_flags);
-
- ibuf->profile = IB_PROFILE_SRGB;
-
- return(ibuf);
-}
-
diff --git a/source/blender/imbuf/intern/antialias.c b/source/blender/imbuf/intern/antialias.c
deleted file mode 100644
index e3a878d0ac4..00000000000
--- a/source/blender/imbuf/intern/antialias.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/**
- * antialias.c
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "imbuf.h"
-
-#include "BLI_blenlib.h"
-#include "DNA_listBase.h"
-
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-#include "IMB_allocimbuf.h"
-
-/* how it works:
-
-1 - seek for a transistion in a collumn
-2 - check the relationship with left and right,
-
-Is pixel above transition to the left or right equal to the top color, seek down
-
-Is pixel below transition to the left or right equal to the bottom color, seek up
-
-*/
-
-/* there should be a funcion * to indicate if two colors are
- * equal or not.
- * For now we use a define
- */
-
-
-static unsigned int anti_mask = 0xffffffff;
-static int anti_a, anti_b, anti_g, anti_r;
-
-#define compare(x, y) ((x ^ y) & anti_mask)
-
-typedef struct Edge
-{
- struct Edge * next, * prev;
- short position;
- int col1, col2;
-}Edge;
-
-static void anti_free_listarray(int count, ListBase * listarray)
-{
- int i;
-
- if (listarray == 0) return;
-
- for (i = 0; i < count; i++) BLI_freelistN(listarray + i);
- MEM_freeN(listarray);
-}
-
-static ListBase * scanimage(struct ImBuf * ibuf, int dir)
-{
- int step, pixels, lines, nextline, x, y, col1, col2;
- unsigned int * rect;
- ListBase * listarray, * curlist;
- Edge * edge;
- int count;
-
- switch (dir) {
- case 'h':
- step = 1; nextline = ibuf->x;
- pixels = ibuf->x; lines = ibuf->y;
- break;
-/* case 'v': changed so assured values for step etc.. */
- default:
- step = ibuf->x; nextline = 1;
- pixels = ibuf->y; lines = ibuf->x;
- }
-
- listarray = (ListBase*)MEM_callocN((lines)* sizeof(ListBase), "listarray");
- for (y = 0; y < lines; y++){
- rect = ibuf->rect;
- rect += y * nextline;
- curlist = listarray + y;
-
- col1 = rect[0];
- count = 0;
-
- for (x = 0; x < pixels; x++) {
- col2 = rect[0];
- if (compare(col1, col2)) {
- edge = NEW(Edge);
-
- if (edge == NULL) return(0);
-
- edge->position = x;
- edge->col1 = col1;
- edge->col2 = col2;
- BLI_addtail(curlist, edge);
- col1 = col2;
- count++;
- if (count > 100) {
- printf("\n\n%s: Aborting antialias !\n", ibuf->name);
- printf("To many transitions.\nIs this a natural image ?\n\n"),
- anti_free_listarray(lines, listarray);
- return(0);
- }
- }
- rect += step;
- }
- }
-
- return(listarray);
-}
-
-
-static Edge * findmatch(Edge * first, Edge * edge)
-{
- Edge * match = 0;
- int in = 0, out = 65535;
-
- if (edge->prev) in = edge->prev->position;
- if (edge->next) out = edge->next->position;
-
- while (first) {
- if (first->position < edge->position) {
- if (first->col1 == edge->col1) {
- if (first->position >= in) match = first;
- } else if (first->col2 == edge->col2) {
- if (first->next == 0) match = first;
- else if (first->next->position >= edge->position) match = first;
- } else if (first->col2 == edge->col1) {
- match = 0; /* at 'sig saw' situations this one can be wrongly set */
- }
- } else if (first->position == edge->position) {
- if (first->col1 == edge->col1 || first->col2 == edge->col2) match = first;
- } else {
- if (match) break; /* there is one */
-
- if (first->col1 == edge->col1) {
- if (first->prev == 0) match = first;
- else if (first->prev->position <= edge->position) match = first;
- } else if (first->col2 == edge->col2) {
- if (first->position <= out) match = first;
- }
- }
-
- first = first->next;
- }
-
- return(match);
-}
-
-
-static void filterdraw(unsigned int * ldest, unsigned int * lsrce, int zero, int half, int step)
-{
- uchar * src, * dst;
- int count;
- double weight, add;
-
- /* we filter the pixels at ldest between in and out with pixels from lsrce
- * weight values go from 0 to 1
- */
-
-
- count = half - zero;
- if (count < 0) count = -count;
- if (count <= 1) return;
-
- if (zero < half) {
- src = (uchar *) (lsrce + (step * zero));
- dst = (uchar *) (ldest + (step * zero));
- } else {
- zero--;
- src = (uchar *) (lsrce + (step * zero));
- dst = (uchar *) (ldest + (step * zero));
- step = -step;
- }
-
- step = 4 * step;
-
- dst += step * (count >> 1);
- src += step * (count >> 1);
-
- count = (count + 1) >> 1;
- add = 0.5 / count;
- weight = 0.5 * add;
-
- /* this of course gamma corrected */
-
- for(; count > 0; count --) {
- if (anti_a) dst[0] += weight * (src[0] - dst[0]);
- if (anti_b) dst[1] += weight * (src[1] - dst[1]);
- if (anti_g) dst[2] += weight * (src[2] - dst[2]);
- if (anti_r) dst[3] += weight * (src[3] - dst[3]);
- dst += step;
- src += step;
- weight += add;
- }
-}
-
-static void filterimage(struct ImBuf * ibuf, struct ImBuf * cbuf, ListBase * listarray, int dir)
-{
- int step, pixels, lines, nextline, y, pos, drawboth;
- unsigned int * irect, * crect;
- Edge * left, * middle, * right, temp, * any;
-
- switch (dir) {
- case 'h':
- step = 1; nextline = ibuf->x;
- pixels = ibuf->x; lines = ibuf->y;
- break;
-/* case 'v': changed so have values */
- default:
- step = ibuf->x; nextline = 1;
- pixels = ibuf->y; lines = ibuf->x;
- }
-
- for (y = 1; y < lines - 1; y++){
- irect = ibuf->rect;
- irect += y * nextline;
- crect = cbuf->rect;
- crect += y * nextline;
-
- middle = listarray[y].first;
- while (middle) {
- left = findmatch(listarray[y - 1].first, middle);
- right = findmatch(listarray[y + 1].first, middle);
- drawboth = FALSE;
-
- if (left == 0 || right == 0) {
- /* edge */
- any = left;
- if (right) any = right;
- if (any) {
- /* mirroring */
- pos = 2 * middle->position - any->position;
-
- if (any->position < middle->position) {
- if (pos > pixels - 1) pos = pixels - 1;
- if (middle->next) {
- if (pos > middle->next->position) pos = middle->next->position;
- }
-/* if (any->next) {
- if (pos > any->next->position) pos = any->next->position;
- }
-*/ } else {
- if (pos < 0) pos = 0;
- if (middle->prev) {
- if (pos < middle->prev->position) pos = middle->prev->position;
- }
-/* if (any->prev) {
- if (pos < any->prev->position) pos = any->prev->position;
- }
-*/ }
- temp.position = pos;
- if (left) right = &temp;
- else left = &temp;
- drawboth = TRUE;
- }
- } else if (left->position == middle->position || right->position == middle->position) {
- /* straight piece */
- /* small corner, with one of the two at distance 2 (the other is at dist 0) ? */
-
- if (abs(left->position - right->position) == 2) drawboth = TRUE;
- } else if (left->position < middle->position && right->position > middle->position){
- /* stair 1 */
- drawboth = TRUE;
- } else if (left->position > middle->position && right->position < middle->position){
- /* stair 2 */
- drawboth = TRUE;
- } else {
- /* a peek */
- drawboth = TRUE;
- }
-
- if (drawboth) {
- filterdraw(irect, crect - nextline, left->position, middle->position, step);
- filterdraw(irect, crect + nextline, right->position, middle->position, step);
- }
-
- middle = middle->next;
- }
- }
-}
-
-
-void IMB_antialias(struct ImBuf * ibuf)
-{
- struct ImBuf * cbuf;
- ListBase * listarray;
-
- if (ibuf == 0) return;
- cbuf = IMB_dupImBuf(ibuf);
- if (cbuf == 0) return;
-
- anti_a = (anti_mask >> 24) & 0xff;
- anti_b = (anti_mask >> 16) & 0xff;
- anti_g = (anti_mask >> 8) & 0xff;
- anti_r = (anti_mask >> 0) & 0xff;
-
- listarray = scanimage(cbuf, 'h');
- if (listarray) {
- filterimage(ibuf, cbuf, listarray, 'h');
- anti_free_listarray(ibuf->y, listarray);
-
- listarray = scanimage(cbuf, 'v');
- if (listarray) {
- filterimage(ibuf, cbuf, listarray, 'v');
- anti_free_listarray(ibuf->x, listarray);
- }
- }
-
- IMB_freeImBuf(cbuf);
-}
-
-
-/* intelligent scaling */
-
-static void _intel_scale(struct ImBuf * ibuf, ListBase * listarray, int dir)
-{
- int step, lines, nextline, x, y, col;
- unsigned int * irect, * trect;
- int start, end;
- Edge * left, * right;
- struct ImBuf * tbuf;
-
- switch (dir) {
- case 'h':
- step = 1; nextline = ibuf->x;
- lines = ibuf->y;
- tbuf = IMB_double_fast_y(ibuf);
- break;
- case 'v':
- step = 2 * ibuf->x; nextline = 1;
- lines = ibuf->x;
- tbuf = IMB_double_fast_x(ibuf);
- break;
- default:
- return;
- }
-
- if (tbuf == NULL) return;
-
- imb_freerectImBuf(ibuf);
-
- ibuf->rect = tbuf->rect;
- ibuf->mall |= IB_rect;
-
- ibuf->x = tbuf->x;
- ibuf->y = tbuf->y;
- tbuf->rect = 0;
- IMB_freeImBuf(tbuf);
-
- for (y = 0; y < lines - 2; y++){
- irect = ibuf->rect;
- irect += ((2 * y) + 1) * nextline;
-
- left = listarray[y].first;
- while (left) {
- right = findmatch(listarray[y + 1].first, left);
- if (right) {
- if (left->col2 == right->col2) {
- if (left->next && right->next) {
- if (left->next->position >= right->position) {
- start = ((left->position + right->position) >> 1);
- end = ((left->next->position + right->next->position) >> 1);
- col = left->col2;
- trect = irect + (start * step);
- for (x = start; x < end; x++) {
- *trect = col;
- trect += step;
- }
- }
- }
- }
-
- if (left->col1 == right->col1) {
- if (left->prev && right->prev) {
- if (left->prev->position <= right->position) {
- end = ((left->position + right->position) >> 1);
- start = ((left->prev->position + right->prev->position) >> 1);
- col = left->col1;
- trect = irect + (start * step);
- for (x = start; x < end; x++) {
- *trect = col;
- trect += step;
- }
- }
- }
- }
-
- }
- left = left->next;
- }
- }
-}
-
-
-void IMB_clever_double(struct ImBuf * ibuf)
-{
- ListBase * listarray, * curlist;
- Edge * new;
- int size;
- int i;
-
- if (ibuf == 0) return;
-
- size = ibuf->x;
- listarray = scanimage(ibuf, 'v');
- if (listarray) {
- for (i = 0; i < size; i++) {
- curlist = listarray + i;
- new = (Edge*)MEM_callocN(sizeof(Edge),"Edge");
- new->col2 = ibuf->rect[i]; /* upper pixel */
- new->col1 = new->col2 - 1;
- BLI_addhead(curlist, new);
- new = (Edge*)MEM_callocN(sizeof(Edge),"Edge");
- new->position = ibuf->y - 1;
- new->col1 = ibuf->rect[i + ((ibuf->y -1) * ibuf->x)]; /* bottom pixel */
- new->col2 = new->col1 - 1;
- BLI_addtail(curlist, new);
- }
- _intel_scale(ibuf, listarray, 'v');
- anti_free_listarray(size, listarray);
-
- size = ibuf->y;
- listarray = scanimage(ibuf, 'h');
- if (listarray) {
- for (i = 0; i < size; i++) {
- curlist = listarray + i;
- new = (Edge*)MEM_callocN(sizeof(Edge),"Edge");
- new->col2 = ibuf->rect[i * ibuf->x]; /* left pixel */
- new->col1 = new->col2 - 1;
- BLI_addhead(curlist, new);
- new = (Edge*)MEM_callocN(sizeof(Edge),"Edge");
- new->position = ibuf->x - 1;
- new->col1 = ibuf->rect[((i + 1) * ibuf->x) - 1]; /* right pixel */
- new->col2 = new->col1 - 1;
- BLI_addtail(curlist, new);
- }
- _intel_scale(ibuf, listarray, 'h');
- anti_free_listarray(size, listarray);
- }
- }
-}
diff --git a/source/blender/imbuf/intern/bitplanes.c b/source/blender/imbuf/intern/bitplanes.c
deleted file mode 100644
index 91fd2a0f563..00000000000
--- a/source/blender/imbuf/intern/bitplanes.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/**
- * bitplanes.c
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "imbuf.h"
-#include "BLI_blenlib.h"
-
-#include "imbuf_patch.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-#include "IMB_allocimbuf.h"
-#include "IMB_bitplanes.h"
-
-unsigned int **imb_copyplanelist(struct ImBuf *ibuf)
-{
- int nobp,i;
- unsigned int **listn,**listo;
-
- nobp=ibuf->depth;
- listn= malloc(nobp*sizeof(int *)); /* make copy of bitmap */
- if (listn==0) return (0);
-
- listo=ibuf->planes;
- for (i=nobp;i>0;i--){
- *(listn++) = *(listo++);
- }
- listn -= nobp;
-
- return (listn);
-}
-
-static void bptolscanl(unsigned int *buf, int size, unsigned int **list, int nobp, int offset)
-{
- /* converts bitplanes to a buffer with ints
- by 4 dividiable amount of bitplanes,
- the width of bitplanes is rounded at ints */
-
- list += nobp;
-
- for (;nobp>0;)
- {
- int todo,i;
- register int bp1, bp2, bp3, bp4, data;
- register unsigned int *point;
- int loffset;
- /*register unsigned int bp1, bp2, bp3, bp4;*/
-
- bp1 = bp2 = bp3 = bp4 = todo = 0;
- point = buf;
- loffset = offset;
-
- if (nobp & 1){
- list -= 1;
- nobp -= 1;
- for(i=size;i>0;i--)
- {
- if (todo==0)
- {
- bp1 = BIG_LONG((list[0])[loffset]);
- loffset++;
- todo=32;
- }
-
- data = *point;
- data<<=1;
-
- if (bp1<0) data+=1;
- bp1<<=1;
-
- /* data += (bp1 >> 31);
- bp1 <<= 1;
- */
- *(point++)=data;
- todo--;
- }
- } else if (nobp & 2){
- list -= 2;
- nobp -= 2;
- for(i=size;i>0;i--)
- {
- if (todo==0)
- {
- bp1 = BIG_LONG((list[0])[loffset]);
- bp2 = BIG_LONG((list[1])[loffset]);
- loffset++;
- todo=32;
- }
-
- data = *point;
- data<<=2;
-
- if (bp1<0) data+=1;
- bp1<<=1;
- if (bp2<0) data+=2;
- bp2<<=1;
-
- /* data += (bp1 >> 31) + ((bp2 & 0x80000000) >> 30);
- bp1 <<= 1; bp2 <<= 1;
- */
- *(point++)=data;
- todo--;
- }
- } else{
- list -= 4;
- nobp -= 4;
- for(i=size;i>0;i--)
- {
- if (todo==0) {
- bp1 = BIG_LONG((list[0])[loffset]);
- bp2 = BIG_LONG((list[1])[loffset]);
- bp3 = BIG_LONG((list[2])[loffset]);
- bp4 = BIG_LONG((list[3])[loffset]);
- loffset++;
- todo=32;
- }
-
- data = *point;
- data<<=4;
-
- if (bp1<0) data+=1;
- bp1<<=1;
- if (bp2<0) data+=2;
- bp2<<=1;
- if (bp3<0) data+=4;
- bp3<<=1;
- if (bp4<0) data+=8;
- bp4<<=1;
-
- /* data += (bp1 >> 31) \
- + ((bp2 & 0x80000000) >> 30) \
- + ((bp3 & 0x80000000) >> 29) \
- + ((bp4 & 0x80000000) >> 28);
-
- bp1 <<= 1; bp2 <<= 1;
- bp3 <<= 1; bp4 <<= 1;
- */
-
- *(point++)=data;
- todo--;
- }
- }
- }
-}
-
-
-void imb_bptolong(struct ImBuf *ibuf)
-{
- int nobp,i,x;
- unsigned int *rect,offset;
- float black[4] = {0.0,0.0,0.0,1.0};
- float clear[4] = {0.0,0.0,0.0,0.0};
-
- /* first clear all ints */
-
- if (ibuf == 0) return;
- if (ibuf->planes == 0) return;
- if (ibuf->rect == 0) imb_addrectImBuf(ibuf);
-
- nobp=ibuf->depth;
- if (nobp != 32){
- if (nobp == 24) IMB_rectfill(ibuf, black); /* set alpha */
- else IMB_rectfill(ibuf, clear);
- }
-
- rect= ibuf->rect;
- x= ibuf->x;
- offset=0;
-
- for (i= ibuf->y; i>0; i--){
- bptolscanl(rect, x, ibuf->planes, nobp, offset);
- rect += x;
- offset += ibuf->skipx;
- }
-}
-
-
-static void ltobpscanl(unsigned int *rect, int x, unsigned int **list, int nobp, int offset)
-{
- /* converts a buffer with ints to bitplanes. Take care, buffer
- will be destroyed !*/
-
- if (nobp != 32)
- {
- int *rect2;
- int todo,j;
-
- rect2 = (int*)rect;
-
- todo = 32-nobp;
- for (j = x;j>0;j--){
- *(rect2++) <<= todo;
- }
- }
-
- list += nobp;
- for (;nobp>0;){
- register int bp1=0, bp2=0, bp3=0, data;
- register unsigned int *point;
- int i,todo;
- int bp4=0,loffset;
-
- point = rect;
- todo=32;
- loffset=offset;
-
- if (nobp & 1){
- list -= 1;
- nobp -= 1;
-
- for(i=x;i>0;i--){
- data = *point;
-
- bp1 <<= 1;
- if (data<0) bp1 += 1;
- data <<= 1;
-
- *(point++) = data;
-
- todo--;
- if (todo == 0){
- (list[0])[loffset] = bp1;
- loffset++;
- todo=32;
- }
- }
- if (todo != 32)
- {
- bp1 <<= todo;
- (list[0])[loffset] = bp1;
- }
- } else if (nobp & 2){
- list -= 2;
- nobp -= 2;
- for(i=x;i>0;i--){
- data = *point;
-
- bp2 <<= 1;
- if (data<0) bp2 += 1;
- data <<= 1;
- bp1 <<= 1;
- if (data<0) bp1 += 1;
- data <<= 1;
-
- *(point++) = data;
-
- todo--;
- if (todo == 0){
- (list[0])[loffset] = bp1;
- (list[1])[loffset] = bp2;
- loffset++;
- todo=32;
- }
- }
- if (todo != 32){
- bp1 <<= todo;
- bp2 <<= todo;
- (list[0])[loffset] = bp1;
- (list[1])[loffset] = bp2;
- }
- } else{
- list -= 4;
- nobp -= 4;
- for(i=x;i>0;i--){
- data = *point;
-
- bp4 <<= 1;
- if (data<0) bp4 += 1;
- data <<= 1;
- bp3 <<= 1;
- if (data<0) bp3 += 1;
- data <<= 1;
- bp2 <<= 1;
- if (data<0) bp2 += 1;
- data <<= 1;
- bp1 <<= 1;
- if (data<0) bp1 += 1;
- data <<= 1;
-
- *(point++) = data;
-
- todo--;
- if (todo == 0){
- (list[0])[loffset] = bp1;
- (list[1])[loffset] = bp2;
- (list[2])[loffset] = bp3;
- (list[3])[loffset] = bp4;
- loffset++;
- todo=32;
- }
- }
- if (todo != 32){
- bp1 <<= todo;
- bp2 <<= todo;
- bp3 <<= todo;
- bp4 <<= todo;
- (list[0])[loffset] = bp1;
- (list[1])[loffset] = bp2;
- (list[2])[loffset] = bp3;
- (list[3])[loffset] = bp4;
- }
- }
- }
-}
-
-
-void imb_longtobp(struct ImBuf *ibuf)
-{
- /* converts a buffer with ints to bitplanes. Take care, buffer
- will be destroyed !*/
-
- int nobp,i,x;
- unsigned int *rect,offset,*buf;
- ;
-
- nobp = ibuf->depth;
- rect=ibuf->rect;
- x=ibuf->x;
- offset=0;
- if ((buf=malloc(x*sizeof(int)))==0) return;
-
- for (i=ibuf->y;i>0;i--){
- memcpy(buf, rect, x*sizeof(int));
- rect +=x ;
- ltobpscanl(buf, x, ibuf->planes, nobp, offset);
- offset += ibuf->skipx;
- }
- free(buf);
-}
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index 606cce645ee..bdcf60090c3 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -30,13 +30,11 @@
#include "BLI_blenlib.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_cmap.h"
-#include "IMB_bmp.h"
+#include "IMB_filetype.h"
/* some code copied from article on microsoft.com, copied
here for enhanced BMP support in the future
@@ -98,7 +96,7 @@ static int checkbmp(unsigned char *mem)
return(ret_val);
}
-int imb_is_a_bmp(void *buf) {
+int imb_is_a_bmp(unsigned char *buf) {
return checkbmp(buf);
}
@@ -195,7 +193,7 @@ static int putShortLSB(unsigned short us,FILE *ofile) {
}
/* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */
-short imb_savebmp(struct ImBuf *ibuf, char *name, int flags) {
+int imb_savebmp(struct ImBuf *ibuf, char *name, int flags) {
BMPINFOHEADER infoheader;
int bytesize, extrabytes, x, y, t, ptr;
diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c
new file mode 100644
index 00000000000..77e01d8ebef
--- /dev/null
+++ b/source/blender/imbuf/intern/cache.c
@@ -0,0 +1,444 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+#include "BLI_memarena.h"
+#include "BLI_threads.h"
+
+#include "BKE_utildefines.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+#include "IMB_filetype.h"
+
+#include "imbuf.h"
+
+/* We use a two level cache here. A per-thread cache with limited number of
+ tiles. This can be accessed without locking and so is hoped to lead to most
+ tile access being lock-free. The global cache is shared between all threads
+ and requires slow locking to access, and contains all tiles.
+
+ The per-thread cache should be big enough that one might hope to not fall
+ back to the global cache every pixel, but not to big to keep too many tiles
+ locked and using memory. */
+
+#define IB_THREAD_CACHE_SIZE 100
+
+typedef struct ImGlobalTile {
+ struct ImGlobalTile *next, *prev;
+
+ ImBuf *ibuf;
+ int tx, ty;
+ int refcount;
+ volatile int loading;
+} ImGlobalTile;
+
+typedef struct ImThreadTile {
+ struct ImThreadTile *next, *prev;
+
+ ImBuf *ibuf;
+ int tx, ty;
+
+ ImGlobalTile *global;
+} ImThreadTile;
+
+typedef struct ImThreadTileCache {
+ ListBase tiles;
+ ListBase unused;
+ GHash *tilehash;
+} ImThreadTileCache;
+
+typedef struct ImGlobalTileCache {
+ ListBase tiles;
+ ListBase unused;
+ GHash *tilehash;
+
+ MemArena *memarena;
+ uintptr_t totmem, maxmem;
+
+ ImThreadTileCache thread_cache[BLENDER_MAX_THREADS+1];
+ int totthread;
+
+ ThreadMutex mutex;
+} ImGlobalTileCache;
+
+static ImGlobalTileCache GLOBAL_CACHE;
+
+/***************************** Hash Functions ********************************/
+
+static unsigned int imb_global_tile_hash(void *gtile_p)
+{
+ ImGlobalTile *gtile= gtile_p;
+
+ return ((unsigned int)(intptr_t)gtile->ibuf)*769 + gtile->tx*53 + gtile->ty*97;
+}
+
+static int imb_global_tile_cmp(void *a_p, void *b_p)
+{
+ ImGlobalTile *a= a_p;
+ ImGlobalTile *b= b_p;
+
+ if(a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0;
+ else if(a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1;
+ else return 1;
+}
+
+static unsigned int imb_thread_tile_hash(void *ttile_p)
+{
+ ImThreadTile *ttile= ttile_p;
+
+ return ((unsigned int)(intptr_t)ttile->ibuf)*769 + ttile->tx*53 + ttile->ty*97;
+}
+
+static int imb_thread_tile_cmp(void *a_p, void *b_p)
+{
+ ImThreadTile *a= a_p;
+ ImThreadTile *b= b_p;
+
+ if(a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0;
+ else if(a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1;
+ else return 1;
+}
+
+/******************************** Load/Unload ********************************/
+
+static void imb_global_cache_tile_load(ImGlobalTile *gtile)
+{
+ ImBuf *ibuf= gtile->ibuf;
+ int toffs= ibuf->xtiles*gtile->ty + gtile->tx;
+ unsigned int *rect;
+
+ rect = MEM_callocN(sizeof(unsigned int)*ibuf->tilex*ibuf->tiley, "imb_tile");
+ imb_loadtile(ibuf, gtile->tx, gtile->ty, rect);
+ ibuf->tiles[toffs]= rect;
+}
+
+static void imb_global_cache_tile_unload(ImGlobalTile *gtile)
+{
+ ImBuf *ibuf= gtile->ibuf;
+ int toffs= ibuf->xtiles*gtile->ty + gtile->tx;
+
+ MEM_freeN(ibuf->tiles[toffs]);
+ ibuf->tiles[toffs]= NULL;
+
+ GLOBAL_CACHE.totmem -= sizeof(unsigned int)*ibuf->tilex*ibuf->tiley;
+}
+
+/* external free */
+void imb_tile_cache_tile_free(ImBuf *ibuf, int tx, int ty)
+{
+ ImGlobalTile *gtile, lookuptile;
+
+ BLI_mutex_lock(&GLOBAL_CACHE.mutex);
+
+ lookuptile.ibuf = ibuf;
+ lookuptile.tx = tx;
+ lookuptile.ty = ty;
+ gtile= BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
+
+ if(gtile) {
+ /* in case another thread is loading this */
+ while(gtile->loading)
+ ;
+
+ BLI_ghash_remove(GLOBAL_CACHE.tilehash, gtile, NULL, NULL);
+ BLI_remlink(&GLOBAL_CACHE.tiles, gtile);
+ BLI_addtail(&GLOBAL_CACHE.unused, gtile);
+ }
+
+ BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
+}
+
+/******************************* Init/Exit ***********************************/
+
+static void imb_thread_cache_init(ImThreadTileCache *cache)
+{
+ ImThreadTile *ttile;
+ int a;
+
+ memset(cache, 0, sizeof(ImThreadTileCache));
+
+ cache->tilehash= BLI_ghash_new(imb_thread_tile_hash, imb_thread_tile_cmp, "imb_thread_cache_init gh");
+
+ /* pre-allocate all thread local tiles in unused list */
+ for(a=0; a<IB_THREAD_CACHE_SIZE; a++) {
+ ttile= BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImThreadTile));
+ BLI_addtail(&cache->unused, ttile);
+ }
+}
+
+static void imb_thread_cache_exit(ImThreadTileCache *cache)
+{
+ BLI_ghash_free(cache->tilehash, NULL, NULL);
+}
+
+void imb_tile_cache_init(void)
+{
+ memset(&GLOBAL_CACHE, 0, sizeof(ImGlobalTileCache));
+
+ BLI_mutex_init(&GLOBAL_CACHE.mutex);
+
+ /* initialize for one thread, for places that access textures
+ outside of rendering (displace modifier, painting, ..) */
+ IMB_tile_cache_params(0, 0);
+}
+
+void imb_tile_cache_exit(void)
+{
+ ImGlobalTile *gtile;
+ int a;
+
+ for(gtile=GLOBAL_CACHE.tiles.first; gtile; gtile=gtile->next)
+ imb_global_cache_tile_unload(gtile);
+
+ for(a=0; a<GLOBAL_CACHE.totthread; a++)
+ imb_thread_cache_exit(&GLOBAL_CACHE.thread_cache[a]);
+
+ if(GLOBAL_CACHE.memarena)
+ BLI_memarena_free(GLOBAL_CACHE.memarena);
+
+ if(GLOBAL_CACHE.tilehash)
+ BLI_ghash_free(GLOBAL_CACHE.tilehash, NULL, NULL);
+
+ BLI_mutex_end(&GLOBAL_CACHE.mutex);
+}
+
+/* presumed to be called when no threads are running */
+void IMB_tile_cache_params(int totthread, int maxmem)
+{
+ int a;
+
+ /* always one cache for non-threaded access */
+ totthread++;
+
+ /* lazy initialize cache */
+ if(GLOBAL_CACHE.totthread == totthread && GLOBAL_CACHE.maxmem == maxmem)
+ return;
+
+ imb_tile_cache_exit();
+
+ memset(&GLOBAL_CACHE, 0, sizeof(ImGlobalTileCache));
+
+ GLOBAL_CACHE.tilehash= BLI_ghash_new(imb_global_tile_hash, imb_global_tile_cmp, "tile_cache_params gh");
+
+ GLOBAL_CACHE.memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "ImTileCache arena");
+ BLI_memarena_use_calloc(GLOBAL_CACHE.memarena);
+
+ GLOBAL_CACHE.maxmem= maxmem*1024*1024;
+
+ GLOBAL_CACHE.totthread= totthread;
+ for(a=0; a<totthread; a++)
+ imb_thread_cache_init(&GLOBAL_CACHE.thread_cache[a]);
+
+ BLI_mutex_init(&GLOBAL_CACHE.mutex);
+}
+
+/***************************** Global Cache **********************************/
+
+static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGlobalTile *replacetile)
+{
+ ImGlobalTile *gtile, lookuptile;
+
+ BLI_mutex_lock(&GLOBAL_CACHE.mutex);
+
+ if(replacetile)
+ replacetile->refcount--;
+
+ /* find tile in global cache */
+ lookuptile.ibuf = ibuf;
+ lookuptile.tx = tx;
+ lookuptile.ty = ty;
+ gtile= BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
+
+ if(gtile) {
+ /* found tile. however it may be in the process of being loaded
+ by another thread, in that case we do stupid busy loop waiting
+ for the other thread to load the tile */
+ gtile->refcount++;
+
+ BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
+
+ while(gtile->loading)
+ ;
+ }
+ else {
+ /* not found, let's load it from disk */
+
+ /* first check if we hit the memory limit */
+ if(GLOBAL_CACHE.maxmem && GLOBAL_CACHE.totmem > GLOBAL_CACHE.maxmem) {
+ /* find an existing tile to unload */
+ for(gtile=GLOBAL_CACHE.tiles.last; gtile; gtile=gtile->prev)
+ if(gtile->refcount == 0 && gtile->loading == 0)
+ break;
+ }
+
+ if(gtile) {
+ /* found a tile to unload */
+ imb_global_cache_tile_unload(gtile);
+ BLI_ghash_remove(GLOBAL_CACHE.tilehash, gtile, NULL, NULL);
+ BLI_remlink(&GLOBAL_CACHE.tiles, gtile);
+ }
+ else {
+ /* allocate a new tile or reuse unused */
+ if(GLOBAL_CACHE.unused.first) {
+ gtile= GLOBAL_CACHE.unused.first;
+ BLI_remlink(&GLOBAL_CACHE.unused, gtile);
+ }
+ else
+ gtile= BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImGlobalTile));
+ }
+
+ /* setup new tile */
+ gtile->ibuf= ibuf;
+ gtile->tx= tx;
+ gtile->ty= ty;
+ gtile->refcount= 1;
+ gtile->loading= 1;
+
+ BLI_ghash_insert(GLOBAL_CACHE.tilehash, gtile, gtile);
+ BLI_addhead(&GLOBAL_CACHE.tiles, gtile);
+
+ /* mark as being loaded and unlock to allow other threads to load too */
+ GLOBAL_CACHE.totmem += sizeof(unsigned int)*ibuf->tilex*ibuf->tiley;
+
+ BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
+
+ /* load from disk */
+ imb_global_cache_tile_load(gtile);
+
+ /* mark as done loading */
+ gtile->loading= 0;
+ }
+
+ return gtile;
+}
+
+/***************************** Per-Thread Cache ******************************/
+
+static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf *ibuf, int tx, int ty)
+{
+ ImThreadTile *ttile, lookuptile;
+ ImGlobalTile *gtile, *replacetile;
+ int toffs= ibuf->xtiles*ty + tx;
+
+ /* test if it is already in our thread local cache */
+ if((ttile=cache->tiles.first)) {
+ /* check last used tile before going to hash */
+ if(ttile->ibuf == ibuf && ttile->tx == tx && ttile->ty == ty)
+ return ibuf->tiles[toffs];
+
+ /* find tile in hash */
+ lookuptile.ibuf = ibuf;
+ lookuptile.tx = tx;
+ lookuptile.ty = ty;
+
+ if((ttile=BLI_ghash_lookup(cache->tilehash, &lookuptile))) {
+ BLI_remlink(&cache->tiles, ttile);
+ BLI_addhead(&cache->tiles, ttile);
+
+ return ibuf->tiles[toffs];
+ }
+ }
+
+ /* not found, have to do slow lookup in global cache */
+ if(cache->unused.first == NULL) {
+ ttile= cache->tiles.last;
+ replacetile= ttile->global;
+ BLI_remlink(&cache->tiles, ttile);
+ BLI_ghash_remove(cache->tilehash, ttile, NULL, NULL);
+ }
+ else {
+ ttile= cache->unused.first;
+ replacetile= NULL;
+ BLI_remlink(&cache->unused, ttile);
+ }
+
+ BLI_addhead(&cache->tiles, ttile);
+ BLI_ghash_insert(cache->tilehash, ttile, ttile);
+
+ gtile= imb_global_cache_get_tile(ibuf, tx, ty, replacetile);
+
+ ttile->ibuf= gtile->ibuf;
+ ttile->tx= gtile->tx;
+ ttile->ty= gtile->ty;
+ ttile->global= gtile;
+
+ return ibuf->tiles[toffs];
+}
+
+unsigned int *IMB_gettile(ImBuf *ibuf, int tx, int ty, int thread)
+{
+ return imb_thread_cache_get_tile(&GLOBAL_CACHE.thread_cache[thread+1], ibuf, tx, ty);
+}
+
+void IMB_tiles_to_rect(ImBuf *ibuf)
+{
+ ImBuf *mipbuf;
+ ImGlobalTile *gtile;
+ unsigned int *to, *from;
+ int a, tx, ty, y, w, h;
+
+ for(a=0; a<ibuf->miptot; a++) {
+ mipbuf= IMB_getmipmap(ibuf, a);
+
+ /* don't call imb_addrectImBuf, it frees all mipmaps */
+ if(!mipbuf->rect) {
+ if((mipbuf->rect = MEM_mapallocN(ibuf->x*ibuf->y*sizeof(unsigned int), "imb_addrectImBuf"))) {
+ mipbuf->mall |= IB_rect;
+ mipbuf->flags |= IB_rect;
+ }
+ else
+ break;
+ }
+
+ for(ty=0; ty<mipbuf->ytiles; ty++) {
+ for(tx=0; tx<mipbuf->xtiles; tx++) {
+ /* acquire tile through cache, this assumes cache is initialized,
+ which it is always now but it's a weak assumption ... */
+ gtile= imb_global_cache_get_tile(mipbuf, tx, ty, NULL);
+
+ /* setup pointers */
+ from= mipbuf->tiles[mipbuf->xtiles*ty + tx];
+ to= mipbuf->rect + mipbuf->x*ty*mipbuf->tiley + tx*mipbuf->tilex;
+
+ /* exception in tile width/height for tiles at end of image */
+ w= (tx == mipbuf->xtiles-1)? mipbuf->x - tx*mipbuf->tilex: mipbuf->tilex;
+ h= (ty == mipbuf->ytiles-1)? mipbuf->y - ty*mipbuf->tiley: mipbuf->tiley;
+
+ for(y=0; y<h; y++) {
+ memcpy(to, from, sizeof(unsigned int)*w);
+ from += mipbuf->tilex;
+ to += mipbuf->x;
+ }
+
+ /* decrease refcount for tile again */
+ BLI_mutex_lock(&GLOBAL_CACHE.mutex);
+ gtile->refcount--;
+ BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
+ }
+ }
+ }
+}
+
diff --git a/source/blender/imbuf/intern/cineon/CMakeLists.txt b/source/blender/imbuf/intern/cineon/CMakeLists.txt
index 588be3305d9..cd887b6fc4e 100644
--- a/source/blender/imbuf/intern/cineon/CMakeLists.txt
+++ b/source/blender/imbuf/intern/cineon/CMakeLists.txt
@@ -38,4 +38,3 @@ SET(INC
)
BLENDERLIB(bf_cineon "${SRC}" "${INC}")
-#env.BlenderLib ('bf_cineon', source_files, incs, defs, libtype=['core','player'], priority = [90, 200])
diff --git a/source/blender/imbuf/intern/cineon/Makefile b/source/blender/imbuf/intern/cineon/Makefile
index 99a9a5dbd46..6e940d530a9 100644
--- a/source/blender/imbuf/intern/cineon/Makefile
+++ b/source/blender/imbuf/intern/cineon/Makefile
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c
index 2acd4dfda75..a9b229536cb 100644
--- a/source/blender/imbuf/intern/cineon/cineon_dpx.c
+++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c
@@ -53,7 +53,7 @@ static void cineon_conversion_parameters(LogImageByteConversionParameters *param
params->blackPoint = 95;
params->whitePoint = 685;
- params->gamma = 1.7f;
+ params->gamma = 1.0f;
params->doLogarithm = 0;
}
@@ -186,7 +186,7 @@ short imb_savecineon(struct ImBuf *buf, char *myfile, int flags)
}
-int imb_is_cineon(void *buf)
+int imb_is_cineon(unsigned char *buf)
{
return cineonIsMemFileCineon(buf);
}
@@ -203,7 +203,7 @@ short imb_save_dpx(struct ImBuf *buf, char *myfile, int flags)
return imb_save_dpx_cineon(buf, myfile, 0, flags);
}
-int imb_is_dpx(void *buf)
+int imb_is_dpx(unsigned char *buf)
{
return dpxIsMemFileCineon(buf);
}
diff --git a/source/blender/imbuf/intern/cmap.c b/source/blender/imbuf/intern/cmap.c
deleted file mode 100644
index 49edc93b507..00000000000
--- a/source/blender/imbuf/intern/cmap.c
+++ /dev/null
@@ -1,580 +0,0 @@
-/**
- * cmap.c
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include <ctype.h>
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-#include "IMB_cmap.h"
-
-static short *lastcube = 0;
-static uchar *lastcoltab = 0;
-static short lastmaxcol;
-static short lastmincol;
-static short lastcbits;
-short alpha_col0 = FALSE;
-
-extern void IMB_free_cache_limiter();
-
-/*
- * there still is a bug here. If you want to convert an image to a 1 bit colormap you get
- * a black image. All conversion to less than 4 bits is too dark anyway.
- */
-
-void IMB_freeImBufdata(void)
-{
- if (lastcube) free(lastcube);
- lastcube= 0;
- if (lastcoltab) free(lastcoltab);
- lastcoltab= 0;
- IMB_free_cache_limiter();
-}
-
-
-int IMB_alpha_to_col0(int value)
-{
- int old;
-
- old = alpha_col0;
- alpha_col0 = value;
- return (old);
-}
-
-
-void imb_losecmapbits(struct ImBuf *ibuf, unsigned int *coltab)
-{
- int i,bits;
- unsigned int col, and1, and2, *rect;
-
- if (ibuf == 0) return;
- if (ibuf->rect == 0) return;
- if (ibuf->cbits == 0) return;
- if (ibuf->cbits >= 8) return;
-
-/*
- bij cbits = 5:
- and1 = 11100000;
- bij cbits = 6:
- and1 = 11000000;
-*/
-
- bits = ibuf->cbits;
- and1 = ((1 << (8-bits)) - 1) & 0xff;
- and1 |= (and1 << 24) + (and1 << 16) + (and1 << 8);
- and2 = ~and1;
- and1 <<= bits;
-
- rect = ibuf->rect;
- for (i = ibuf->x * ibuf->y ; i > 0; i--) {
- col = rect[0];
- *rect++ = col - ((col & and1) >> bits);
- }
-
- if (coltab){
- for (i = 0 ; i < ibuf->maxcol ; i++) {
- col = coltab[i];
- coltab[i] = (col - ((col & and1) >> bits)) & and2;
- }
- }
-}
-
-
-static void addcmapbits(struct ImBuf *ibuf)
-{
- int i,bits;
- int div,mul;
- uchar * cmap;
-
- if (ibuf == 0) return;
- if (ibuf->cmap == 0) return;
- if (ibuf->cbits == 0) return;
- if (ibuf->cbits >= 8) return;
-
- bits = ibuf->cbits;
-
- /* bits = 4 -> div = 0xf0
- * bits = 5 -> div = 0xf8
- */
-
- div = ((1 << bits) - 1) << (8 - bits);
- mul = 0xffff / div;
-
- if (ibuf->cmap){
- cmap = (uchar *) ibuf->cmap;
- for (i = 0 ; i < ibuf->maxcol ; i++){
- cmap[1] = (mul * cmap[1]) >> 8;
- cmap[2] = (mul * cmap[2]) >> 8;
- cmap[3] = (mul * cmap[3]) >> 8;
- cmap += 4;
- }
- }
-}
-
-
-static short addplanetocube(short *cube, short *plane, int minx, int miny, int sizep, int addcx, int addcy, int sizec, int col)
-{
- short done = FALSE;
- int x, numx, numy, skipc, skipp, temp;
-
- /* clip first */
-
- numx = numy = sizep;
-
- temp = minx + sizep - 1;
- if (temp > sizec) numx -= temp - sizec;
-
- temp = miny + sizep - 1;
- if (temp > sizec) numy -= temp - sizec;
-
- if (minx < 0){
- plane -= minx;
- cube -= minx * addcx;
- numx += minx;
- }
-
- if (miny < 0){
- plane -= miny * sizep;
- cube -= miny * addcy;
- numy += miny;
- }
-
- skipc = addcy - (numx * addcx);
- skipp = sizep - numx;
-
- for (; numy > 0 ; numy--){
- for (x = numx ; x > 0; x--) {
-
- if (plane[0] < cube[1]) {
-
- cube[0] = col;
- cube[1] = plane[0];
- done = TRUE;
- }
- plane ++;
- cube += addcx;
- }
- plane += skipp;
- cube += skipc;
- }
-
- return (done);
-}
-
-
-
-short *imb_coldeltatab(unsigned char *coltab, short mincol, short maxcol, short cbits)
-{
- short max, *quadr, *_quadr, *_cube, *cube, *_plane, done, nocol;
- unsigned int addcb, addcg, addcr, sizep;
- uchar *_colp, *colp, *col;
- int i, j, k, addcube;
- int r, g, b;
-
- max = (1 << cbits) - 1;
- nocol = maxcol - mincol;
- coltab += 4 * mincol;
-
- /* reduce colors to the right amount of bits */
-
- {
- unsigned int * lctab, and;
-
- lctab = (unsigned int *) coltab;
- and = max << (8 - cbits);
- and = and + (and << 8) + (and << 16) + (and << 24);
- for (i=nocol-1 ; i >= 0 ; i--) lctab[i] = (lctab[i] & and) >> (8 - cbits);
- }
-
- /* is this data the same as previous ? */
-
- if (lastcube){
- if (mincol == lastmincol && maxcol == lastmaxcol && cbits == lastcbits){
- if (lastcoltab){
- if (memcmp(lastcoltab, coltab, 4 * nocol) == 0) return(lastcube);
- }
- }
- }
- if (lastcube) free(lastcube);
- if (lastcoltab) free(lastcoltab);
-
- lastcube = 0;
- lastcoltab = 0;
- _cube = malloc(2 * (1 << (3 * cbits)) * sizeof(short));
- _plane = malloc((2 * max + 1) * (2 * max + 1) * sizeof(short));
- _quadr = malloc((2 * max + 1) * sizeof(short));
- _colp = malloc(6 * nocol);
-
- if (_cube == 0 || _plane == 0 || _quadr == 0 || _colp == 0){
- if (_cube) free(_cube);
- if (_plane) free(_plane);
- if (_quadr) free(_quadr);
- if (_colp) free(_colp);
- return(0);
- }
-
- lastcoltab = malloc(4 * nocol);
- if (lastcoltab) memcpy(lastcoltab, coltab, 4 * nocol);
- lastcube = _cube;
- lastmincol = mincol;
- lastmaxcol = maxcol;
- lastcbits = cbits;
-
- /* cube initialise */
-
- cube = _cube;
- for (i = (1 << (3 * cbits)); i > 0 ; i--){
- cube[0] = 0;
- cube[1] = 32767;
- cube += 2;
- }
-
- /* mak error look up table */
-
- {
- unsigned int delta;
-
- quadr = _quadr + max + 1;
- quadr[0] = 0;
- delta = 3;
- for (i = 1 ; i <= max ; i++){
- quadr[i] = quadr[-i] = delta;
- delta += i + 3;
- }
- }
-
- /* colorplane initialise */
-
- for (i = 6 * nocol - 1; i >= 0; i--) _colp[i] = 1;
-
- addcr = 2;
- addcg = (addcr << cbits);
- addcb = (addcg << cbits);
-
- /* fill in first round */
-
- {
- unsigned int ofs;
-
- col = coltab;
- cube = _cube;
-
- for (i = 0 ; i < nocol ; i++){
- ofs = (col[3] * addcr) + (col[2] * addcg) + (col[1] * addcb);
- /* color been filled in -> then skip */
- if (cube[ofs + 1]) cube[ofs] = i + mincol;
- cube[ofs + 1] = 0;
- col += 4;
- }
- }
-
- for (i = 1; i <= max ; i++){
- colp = _colp;
- col = coltab;
- done = FALSE;
- sizep = 2*i +1;
-
- /* plane initialise */
- {
- unsigned int delta;
- short *plane;
-
- plane = _plane;
- for (j = -i ; j <= i; j++){
- delta = quadr[i] + quadr[j];
- for (k = -i; k <= i; k++){
- *plane++ = delta + quadr[k];
- }
- }
- }
-
- for (j = mincol; j < maxcol; j++){
- b = col[1] - i;
- g = col[2] - i;
- r = col[3] - i;
-
- addcube= (addcr * r) + (addcg * g) + (addcb * b);
- /* PRINT4(d, d, d, d, addcube, r, g, b); */
- /* if(addcube >= 2 * (1 << (3 * cbits))) { */
- /* printf("maxerror: %d %d\n", addcube, 2 * (1 << (3 * cbits))); */
- /* add_cube= 2 * (1 << (3 * cbits)) -1; */
- /* } */
- cube = _cube + addcube;
-
- if (colp[0]){
- if (b < 0) colp[0] = 0;
- else done |= colp[0] = addplanetocube(cube, _plane, r, g, sizep, addcr, addcg, max, j);
- }
- if (colp[1]){
- if (g < 0) colp[1] = 0;
- else done |= colp[1] = addplanetocube(cube, _plane, r, b, sizep, addcr, addcb, max, j);
- }
- if (colp[2]){
- if (r < 0) colp[2] = 0;
- else done |= colp[2] = addplanetocube(cube, _plane, b, g, sizep, addcb, addcg, max, j);
- }
- if (colp[3]){
- if ((b + sizep - 1) > max) colp[3] = 0;
- else done |= colp[3] = addplanetocube(cube + (sizep -1) * addcb, _plane, r, g, sizep, addcr,
- addcg, max, j);
- }
- if (colp[4]){
- if ((g + sizep - 1) > max) colp[4] = 0;
- else done |= colp[4] = addplanetocube(cube + (sizep -1) * addcg, _plane, r, b, sizep, addcr,
- addcb, max, j);
- }
- if (colp[5]){
- if ((r + sizep - 1) > max) colp[5] = 0;
- else done |= colp[5] = addplanetocube(cube + (sizep -1) * addcr, _plane, b, g, sizep, addcb,
- addcg, max, j);
- }
-
- colp += 6;
- col += 4;
- }
- if (done == 0) break;
- }
-
- free(_quadr);
- free(_plane);
- free(_colp);
- return(_cube);
-}
-
-
-static void convcmap(struct ImBuf* ibuf, short *deltab, short cbits)
-{
- unsigned int *rect;
- short x,y;
- unsigned int col;
- unsigned int bbits,gbits,rbits;
- unsigned int bmask,gmask,rmask;
-
- bbits = 24 - 3 * cbits - 1;
- gbits = 16 - 2 * cbits - 1;
- rbits = 8 - cbits - 1;
-
- rmask = ((1 << cbits) - 1) << (8 - cbits);
- gmask = rmask << 8;
- bmask = gmask << 8;
-
- rect =(unsigned int *)ibuf->rect;
-
- for(y=ibuf->y;y>0;y--){
- for(x=ibuf->x;x>0;x--){
- col = *rect;
- col = ((col & bmask) >> bbits) + ((col & gmask) >> gbits) + ((col & rmask) >> rbits);
- *rect++ = deltab[col];
- }
- }
-}
-
-short IMB_converttocmap(struct ImBuf *ibuf)
-{
- unsigned int *coltab;
- short *deltab=0, cbits;
- int i;
- int mincol, mask = 0;
- struct ImBuf * abuf = 0;
- unsigned int * rect, * arect;
-
- cbits = 5;
- if (ibuf->cmap == 0) return(0);
-
- if ((ibuf->cbits > 0) && (ibuf->cbits <8)) cbits = ibuf->cbits;
-
- coltab = calloc(ibuf->maxcol, sizeof(unsigned int));
- if (coltab == 0) return(0);
- memcpy(coltab, ibuf->cmap, ibuf->maxcol * sizeof(unsigned int));
-
- mincol = ibuf->mincol;
- if (alpha_col0) {
- if (mincol == 0) mincol = 1;
- abuf = IMB_dupImBuf(ibuf);
- }
-
- imb_losecmapbits(ibuf, coltab);
- deltab = imb_coldeltatab((uchar *) coltab, mincol ,ibuf->maxcol, cbits);
-
- if (deltab == 0) {
- free(coltab);
- if (abuf) IMB_freeImBuf(abuf);
- return(0);
- }
-
-
- IMB_dit0(ibuf,1,cbits);
- IMB_dit0(ibuf,2,cbits);
- IMB_dit0(ibuf,3,cbits);
- convcmap(ibuf, deltab, cbits);
-
- if (abuf) {
- /* convert alpha to color 0 */
- rect = ibuf->rect;
- arect = abuf->rect;
-
- if (alpha_col0 == 1) mask = 0xff000000; /* alpha == 0 -> 0 */
- if (alpha_col0 == 2) mask = 0x80000000; /* alpha < 128 -> 0 */
-
- for (i = ibuf->x * ibuf->y; i > 0; i--) {
- if ((*arect++ & mask) == 0) rect[0] = 0;
- rect++;
- }
-
- IMB_freeImBuf(abuf);
- }
-
- free(coltab);
-
- return (TRUE);
-}
-
-
-void imb_makecolarray(struct ImBuf *ibuf, unsigned char *mem, short nocols)
-{
- short i,bits = 0;
- uchar *cmap;
-
- /* what's the theory behind this? */
-
- nocols = ibuf->maxcol;
-
- if (ibuf->cmap){
- cmap = (uchar *) ibuf->cmap;
- for (i = 0; i < nocols; i++){
- cmap[3] = mem[0];
- cmap[2] = mem[1];
- cmap[1] = mem[2];
- cmap[0] = 0;
-
- bits |= mem[0] | mem[1] | mem[2];
- mem += 3;
- cmap += 4;
- }
-
- /* patch voor AdPro II */
- if (IS_ham(ibuf)){
- i = ibuf->depth - 2;
- bits = ((1 << i) - 1) << (8 - i);
- for (i=0 ; i<nocols ; i++) ibuf->cmap[i] &= (bits << 24) + (bits << 16) + (bits << 8) + bits;
- }
-
- if ((bits & 0x1f) == 0){
- ibuf->cbits = 3;
- } else if ((bits & 0x0f) == 0){
- ibuf->cbits = 4;
- } else if ((bits & 0x07) == 0){
- ibuf->cbits = 5;
- } else if ((bits & 0x03) == 0){
- ibuf->cbits = 6;
- } else ibuf->cbits = 8;
-
- addcmapbits(ibuf);
-
- if (IS_hbrite(ibuf)){
- for (i=31;i>=0;i--){
- ibuf->cmap[i+32] = (ibuf->cmap[i] & 0xfefefefe) >> 1;
- }
- }
-
- if (IS_amiga(ibuf)){
- cmap = (uchar * ) (ibuf->cmap + 1);
- for (i = 1; i < nocols; i++){
- cmap[0] = 0xff;
- cmap += 4;
- }
- }
- }
-}
-
-/* temporal... rects now are rgba, cmaps are abgr */
-#define SWITCH_INT(a) {char s_i, *p_i; p_i= (char *)&(a); s_i= p_i[0]; p_i[0]= p_i[3]; p_i[3]= s_i; s_i= p_i[1]; p_i[1]= p_i[2]; p_i[2]= s_i; }
-
-void IMB_applycmap(struct ImBuf *ibuf)
-{
- unsigned int *rect, *cmap;
- int x, y, i, col, code;
- int *mask = 0;
-
- if (ibuf == 0) return;
- if (ibuf->rect == 0 || ibuf->cmap == 0) return;
-
- rect = ibuf->rect;
- cmap = ibuf->cmap;
-
- if (IS_ham(ibuf)){
-
- /* generate mask of max (8 + 2) bits */
- mask = malloc(1024 * 2 * sizeof(int));
-
- x = 1 << (ibuf->depth - 2);
- y = 65535 / (x - 1);
-
- for (i = 0; i < x; i++){
- mask[i] = 0;
- mask[i + x] = 0x00ffff;
- mask[i + x + x] = 0xffff00;
- mask[i + x + x + x] = 0xff00ff;
-
- col = (y * i) >> 8;
-
- mask[i + 1024] = 0xff000000 | ibuf->cmap[i];
- mask[i + x + 1024] = 0xff000000 | col << 16;
- mask[i + x + x + 1024] = 0xff000000 | col;
- mask[i + x + x + x + 1024] = 0xff000000 | col << 8;
- }
-
- /* only color 0 transparant */
- mask[0+1024] =ibuf->cmap[0];
-
- for (y = ibuf->y ; y>0 ; y--){
- col = cmap[0];
- for (x=ibuf->x ; x>0 ; x--){
- code = *rect;
- *rect++ = col = (col & mask[code]) | mask[code + 1024];
- }
- }
- free(mask);
- } else {
-
- for(i = ibuf->x * ibuf->y; i>0; i--){
- col = *rect;
- if (col >= 0 && col < ibuf->maxcol) *rect = cmap[col];
- rect++;
-
- /* *(rect++) = cmap[*rect]; */
- }
- }
-}
-
diff --git a/source/blender/imbuf/intern/cspace.c b/source/blender/imbuf/intern/cspace.c
deleted file mode 100644
index 46017fec5ec..00000000000
--- a/source/blender/imbuf/intern/cspace.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-
-void IMB_cspace(struct ImBuf *ibuf, float mat[][4]);
-
-/************************************************************************/
-/* COLORSPACE */
-/************************************************************************/
-
-static void fillmattab(double val, unsigned short *mattab)
-{
- int tot,ival;
- int i;
-
- val *= (1 << 22);
- ival = val;
- tot = 32767; /* een half */
-
- for(i = 256; i > 0; i--){
- *(mattab) = (tot >> 16);
- mattab += 3;
- tot += ival;
- }
-}
-
-
-static void cspfill(short *buf, unsigned short *fill, int x)
-{
- unsigned short r,g,b;
-
- b = fill[0];
- g = fill[1];
- r = fill[2];
- for (;x>0;x--){
- buf[0] = b;
- buf[1] = g;
- buf[2] = r;
- buf += 3;
- }
-}
-
-
-static void cspadd(short *buf, unsigned short *cont, unsigned char *rect, int x)
-{
- short i;
- for (;x>0;x--){
- i = *(rect);
- rect += 4;
- buf[0] += cont[i*3];
- buf[1] += cont[i*3 + 1];
- buf[2] += cont[i*3 + 2];
- buf += 3;
- }
-}
-
-
-static void cspret(short *buf, unsigned char *rect, int x)
-{
- int r,g,b;
-
- for(; x > 0; x--){
- b = buf[0];
- g = buf[1];
- r = buf[2];
-
- if (b & 0x4000){
- if (b<0) rect[2]=0;
- else rect[2]=255;
- } else rect[2] = b >> 6;
-
- if (g & 0x4000){
- if (g<0) rect[1]=0;
- else rect[1]=255;
- } else rect[1] = g >> 6;
-
- if (r & 0x4000){
- if (r<0) rect[0]=0;
- else rect[0]=255;
- } else rect[0] = r >> 6;
-
- buf += 3;
- rect += 4;
- }
-}
-
-
-static void rotcspace(struct ImBuf *ibuf, unsigned short *cont_1, unsigned short *cont_2, unsigned short *cont_3, unsigned short *add)
-{
- short x,y,*buf;
- uchar *rect;
-
- x=ibuf->x;
- rect= (uchar *)ibuf->rect;
-
- buf=(short *)malloc(x*3*sizeof(short));
- if (buf){
- for(y=ibuf->y;y>0;y--){
- cspfill(buf,add,x);
- cspadd(buf,cont_1,rect+0,x);
- cspadd(buf,cont_2,rect+1,x);
- cspadd(buf,cont_3,rect+2,x);
- cspret(buf,rect,x);
- rect += x<<2;
- }
- free(buf);
- }
-}
-
-
-void IMB_cspace(struct ImBuf *ibuf, float mat[][4])
-{
- unsigned short *cont_1,*cont_2,*cont_3,add[3];
-
- cont_1=(unsigned short *)malloc(256*3*sizeof(short));
- cont_2=(unsigned short *)malloc(256*3*sizeof(short));
- cont_3=(unsigned short *)malloc(256*3*sizeof(short));
-
- if (cont_1 && cont_2 && cont_3){
-
- fillmattab(mat[0][0],cont_1);
- fillmattab(mat[0][1],cont_1+1);
- fillmattab(mat[0][2],cont_1+2);
-
- fillmattab(mat[1][0],cont_2);
- fillmattab(mat[1][1],cont_2+1);
- fillmattab(mat[1][2],cont_2+2);
-
- fillmattab(mat[2][0],cont_3);
- fillmattab(mat[2][1],cont_3+1);
- fillmattab(mat[2][2],cont_3+2);
-
- add[0] = (mat[3][0] * 64.0) + .5;
- add[1] = (mat[3][1] * 64.0) + .5;
- add[2] = (mat[3][2] * 64.0) + .5;
-
- rotcspace(ibuf, cont_1, cont_2, cont_3, add);
- }
-
- if (cont_1) free(cont_1);
- if (cont_2) free(cont_2);
- if (cont_3) free(cont_3);
-}
-
diff --git a/source/blender/imbuf/intern/data.c b/source/blender/imbuf/intern/data.c
deleted file mode 100644
index 3b1f3035d62..00000000000
--- a/source/blender/imbuf/intern/data.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * data.c
- *
- * $Id$
- */
-
-#include "imbuf.h"
-#include "matrix.h"
-
-/*
-static short quadbase[31] = {
- 150,133,117,102,
- 88,75,63,52,
- 42,33,25,18,
- 12,7,3,0,
- 3,7,12,18,
- 25,33,42,52,
- 63,75,88,102,
- 117,133,150,
-};
-
-short *quadr = quadbase+15;
-*/
-/*
-main()
-{
- ushort _quadr[511], *quadr;
- int i, delta;
-
- quadr = _quadr + 255;
-
- delta = 0;
- for (i = 0 ; i <= 255 ; i++){
- quadr[i] = quadr[-i] = delta;
- delta += i + 3;
- }
-
- delta = 0;
- for (i = 0; i < 511; i++){
- printf("%6d, ", _quadr[i]);
- delta++;
- if (delta == 8){
- delta = 0;
- printf("\n");
- }
- }
-}
-*/
-
-static unsigned short quadbase[511] = {
- 33150, 32893, 32637, 32382, 32128, 31875, 31623, 31372,
- 31122, 30873, 30625, 30378, 30132, 29887, 29643, 29400,
- 29158, 28917, 28677, 28438, 28200, 27963, 27727, 27492,
- 27258, 27025, 26793, 26562, 26332, 26103, 25875, 25648,
- 25422, 25197, 24973, 24750, 24528, 24307, 24087, 23868,
- 23650, 23433, 23217, 23002, 22788, 22575, 22363, 22152,
- 21942, 21733, 21525, 21318, 21112, 20907, 20703, 20500,
- 20298, 20097, 19897, 19698, 19500, 19303, 19107, 18912,
- 18718, 18525, 18333, 18142, 17952, 17763, 17575, 17388,
- 17202, 17017, 16833, 16650, 16468, 16287, 16107, 15928,
- 15750, 15573, 15397, 15222, 15048, 14875, 14703, 14532,
- 14362, 14193, 14025, 13858, 13692, 13527, 13363, 13200,
- 13038, 12877, 12717, 12558, 12400, 12243, 12087, 11932,
- 11778, 11625, 11473, 11322, 11172, 11023, 10875, 10728,
- 10582, 10437, 10293, 10150, 10008, 9867, 9727, 9588,
- 9450, 9313, 9177, 9042, 8908, 8775, 8643, 8512,
- 8382, 8253, 8125, 7998, 7872, 7747, 7623, 7500,
- 7378, 7257, 7137, 7018, 6900, 6783, 6667, 6552,
- 6438, 6325, 6213, 6102, 5992, 5883, 5775, 5668,
- 5562, 5457, 5353, 5250, 5148, 5047, 4947, 4848,
- 4750, 4653, 4557, 4462, 4368, 4275, 4183, 4092,
- 4002, 3913, 3825, 3738, 3652, 3567, 3483, 3400,
- 3318, 3237, 3157, 3078, 3000, 2923, 2847, 2772,
- 2698, 2625, 2553, 2482, 2412, 2343, 2275, 2208,
- 2142, 2077, 2013, 1950, 1888, 1827, 1767, 1708,
- 1650, 1593, 1537, 1482, 1428, 1375, 1323, 1272,
- 1222, 1173, 1125, 1078, 1032, 987, 943, 900,
- 858, 817, 777, 738, 700, 663, 627, 592,
- 558, 525, 493, 462, 432, 403, 375, 348,
- 322, 297, 273, 250, 228, 207, 187, 168,
- 150, 133, 117, 102, 88, 75, 63, 52,
- 42, 33, 25, 18, 12, 7, 3, 0,
- 3, 7, 12, 18, 25, 33, 42, 52,
- 63, 75, 88, 102, 117, 133, 150, 168,
- 187, 207, 228, 250, 273, 297, 322, 348,
- 375, 403, 432, 462, 493, 525, 558, 592,
- 627, 663, 700, 738, 777, 817, 858, 900,
- 943, 987, 1032, 1078, 1125, 1173, 1222, 1272,
- 1323, 1375, 1428, 1482, 1537, 1593, 1650, 1708,
- 1767, 1827, 1888, 1950, 2013, 2077, 2142, 2208,
- 2275, 2343, 2412, 2482, 2553, 2625, 2698, 2772,
- 2847, 2923, 3000, 3078, 3157, 3237, 3318, 3400,
- 3483, 3567, 3652, 3738, 3825, 3913, 4002, 4092,
- 4183, 4275, 4368, 4462, 4557, 4653, 4750, 4848,
- 4947, 5047, 5148, 5250, 5353, 5457, 5562, 5668,
- 5775, 5883, 5992, 6102, 6213, 6325, 6438, 6552,
- 6667, 6783, 6900, 7018, 7137, 7257, 7378, 7500,
- 7623, 7747, 7872, 7998, 8125, 8253, 8382, 8512,
- 8643, 8775, 8908, 9042, 9177, 9313, 9450, 9588,
- 9727, 9867, 10008, 10150, 10293, 10437, 10582, 10728,
- 10875, 11023, 11172, 11322, 11473, 11625, 11778, 11932,
- 12087, 12243, 12400, 12558, 12717, 12877, 13038, 13200,
- 13363, 13527, 13692, 13858, 14025, 14193, 14362, 14532,
- 14703, 14875, 15048, 15222, 15397, 15573, 15750, 15928,
- 16107, 16287, 16468, 16650, 16833, 17017, 17202, 17388,
- 17575, 17763, 17952, 18142, 18333, 18525, 18718, 18912,
- 19107, 19303, 19500, 19698, 19897, 20097, 20298, 20500,
- 20703, 20907, 21112, 21318, 21525, 21733, 21942, 22152,
- 22363, 22575, 22788, 23002, 23217, 23433, 23650, 23868,
- 24087, 24307, 24528, 24750, 24973, 25197, 25422, 25648,
- 25875, 26103, 26332, 26562, 26793, 27025, 27258, 27492,
- 27727, 27963, 28200, 28438, 28677, 28917, 29158, 29400,
- 29643, 29887, 30132, 30378, 30625, 30873, 31122, 31372,
- 31623, 31875, 32128, 32382, 32637, 32893, 33150,
-};
-
-unsigned short *quadr = quadbase + 255;
diff --git a/source/blender/imbuf/intern/dds/CMakeLists.txt b/source/blender/imbuf/intern/dds/CMakeLists.txt
index 364dd41e744..376dd3d61f4 100644
--- a/source/blender/imbuf/intern/dds/CMakeLists.txt
+++ b/source/blender/imbuf/intern/dds/CMakeLists.txt
@@ -37,9 +37,8 @@ SET(INC
../../../../../intern/guardedalloc
)
-if(WITH_DDS)
+if(WITH_IMAGE_DDS)
ADD_DEFINITIONS(-DWITH_DDS)
-ENDIF(WITH_DDS)
+ENDIF(WITH_IMAGE_DDS)
BLENDERLIB(bf_dds "${SRC}" "${INC}")
-#env.BlenderLib ('bf_dds', source_files, incs, defs, libtype=['core','player'], priority = [90, 200])
diff --git a/source/blender/imbuf/intern/dds/Makefile b/source/blender/imbuf/intern/dds/Makefile
index e14f9320d19..d4f04382899 100644
--- a/source/blender/imbuf/intern/dds/Makefile
+++ b/source/blender/imbuf/intern/dds/Makefile
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp
index 56880c57f1b..9a106253397 100644
--- a/source/blender/imbuf/intern/dds/dds_api.cpp
+++ b/source/blender/imbuf/intern/dds/dds_api.cpp
@@ -31,13 +31,12 @@
extern "C" {
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-short imb_save_dds(struct ImBuf * ibuf, char *name, int flags)
+int imb_save_dds(struct ImBuf * ibuf, char *name, int flags)
{
return(0); /* todo: finish this function */
@@ -78,6 +77,9 @@ struct ImBuf *imb_load_dds(unsigned char *mem, int size, int flags)
Color32 pixel;
Color32 *pixels = 0;
+ if(!imb_is_a_dds(mem))
+ return (0);
+
/* check if DDS is valid and supported */
if (!dds.isValid()) {
/* no need to print error here, just testing if it is a DDS */
diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h
index b8a61c6fc1a..6d9fa0839dd 100644
--- a/source/blender/imbuf/intern/dds/dds_api.h
+++ b/source/blender/imbuf/intern/dds/dds_api.h
@@ -29,7 +29,7 @@
extern "C" {
#endif
-short imb_save_dds(struct ImBuf *ibuf, char *name, int flags);
+int imb_save_dds(struct ImBuf *ibuf, char *name, int flags);
int imb_is_a_dds(unsigned char *mem); /* use only first 32 bytes of mem */
struct ImBuf *imb_load_dds(unsigned char *mem, int size, int flags);
diff --git a/source/blender/imbuf/intern/dither.c b/source/blender/imbuf/intern/dither.c
deleted file mode 100644
index ccd7982ea07..00000000000
--- a/source/blender/imbuf/intern/dither.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * dither.c
- *
- * $Id$
- */
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-void IMB_dit0(struct ImBuf * ibuf, short ofs, short bits)
-{
- int x, y, and, add, pix;
- uchar *rect;
-
- rect= (uchar *)ibuf->rect;
- rect +=ofs;
-
- bits = 8 - bits;
- and = ~((1 << bits)-1);
- add = 1 << (bits - 1);
-
- for (y = ibuf->y; y > 0; y--){
- for (x = ibuf->x; x > 0; x--) {
- pix = *rect + add;
- if (pix > 255) pix = 255;
- *rect = pix & and;
- rect += 4;
- }
- }
-}
-
-void IMB_dit2(struct ImBuf * ibuf, short ofs, short bits)
-{
- short x,y,pix,and,add1,add2;
- uchar *rect;
- uchar dit[4];
-
- rect= (uchar *)ibuf->rect;
- rect +=ofs;
-
- bits = 8 - bits;
- and = ~((1<<bits)-1);
- bits -= 2;
-
- ofs = 0;
-
- switch(ofs){
- case 3:
- break;
- case 2:
- dit[0]=0;
- dit[1]=1;
- dit[2]=2;
- dit[3]=3;
- break;
- case 1:
- dit[0]=3;
- dit[1]=1;
- dit[2]=0;
- dit[3]=2;
- break;
- case 0:
- dit[0]=0;
- dit[1]=2;
- dit[2]=3;
- dit[3]=1;
- break;
- }
-
- if (bits < 0){
- dit[0] >>= -bits;
- dit[1] >>= -bits;
- dit[2] >>= -bits;
- dit[3] >>= -bits;
- } else{
- dit[0] <<= bits;
- dit[1] <<= bits;
- dit[2] <<= bits;
- dit[3] <<= bits;
- }
-
- for(y=ibuf->y;y>0;y--){
- if(y & 1){
- add1=dit[0];
- add2=dit[1];
- }
- else{
- add1=dit[2];
- add2=dit[3];
- }
- for(x=ibuf->x;x>0;x--){
- pix = *rect;
- if (x & 1) pix += add1;
- else pix += add2;
-
- if (pix>255) pix=255;
- *rect = pix & and;
- rect += 4;
- }
- }
-}
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 4e8d61f8675..7b3a07f10ad 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -34,55 +34,12 @@
#include "BLI_math.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_divers.h"
#include "BKE_utildefines.h"
#include "BKE_colortools.h"
-void imb_checkncols(struct ImBuf *ibuf)
-{
- unsigned int i;
-
- if (ibuf==0) return;
-
- if (IS_amiga(ibuf)){
- if (IS_ham(ibuf)){
- if (ibuf->depth == 0) ibuf->depth = 6;
- ibuf->mincol = 0;
- ibuf->maxcol = 1 << (ibuf->depth - 2);
- /*printf("%d %d\n", ibuf->maxcol, ibuf->depth);*/
- return;
- } else if (IS_hbrite(ibuf)){
- ibuf->mincol = 0;
- ibuf->maxcol = 64;
- ibuf->depth = 6;
- return;
- }
- }
-
- if (ibuf->maxcol == 0){
- if (ibuf->depth <= 8){
- ibuf->mincol = 0;
- ibuf->maxcol = (1 << ibuf->depth);
- return;
- } else if (ibuf->depth == 0){
- ibuf->depth = 5;
- ibuf->mincol = 0;
- ibuf->maxcol = 32;
- }
- return;
- } else {
- /* ibuf->maxcol defines the depth */
- for (i=1 ; ibuf->maxcol > (1 << i); i++);
- ibuf->depth = i;
- return;
- }
-}
-
-
void IMB_de_interlace(struct ImBuf *ibuf)
{
struct ImBuf * tbuf1, * tbuf2;
@@ -138,43 +95,6 @@ void IMB_interlace(struct ImBuf *ibuf)
}
-void IMB_gamwarp(struct ImBuf *ibuf, double gamma)
-{
- uchar gam[256];
- int i;
- uchar *rect;
- float *rectf;
-
- if (ibuf == 0) return;
- if (gamma == 1.0) return;
-
- rect = (uchar *) ibuf->rect;
- rectf = ibuf->rect_float;
-
- gamma = 1.0 / gamma;
-
- if (rect) {
- for (i = 255 ; i >= 0 ; i--)
- gam[i] = (255.0 * pow(i / 255.0 ,
- gamma)) + 0.5;
-
- for (i = ibuf->x * ibuf->y ; i>0 ; i--, rect+=4){
- rect[0] = gam[rect[0]];
- rect[1] = gam[rect[1]];
- rect[2] = gam[rect[2]];
- }
- }
-
- if (rectf) {
- for (i = ibuf->x * ibuf->y ; i>0 ; i--, rectf+=4){
- rectf[0] = pow(rectf[0] / 255.0, gamma);
- rectf[1] = pow(rectf[1] / 255.0, gamma);
- rectf[2] = pow(rectf[2] / 255.0, gamma);
- }
- }
-}
-
-
/* assume converting from linear float to sRGB byte */
void IMB_rect_from_float(struct ImBuf *ibuf)
{
@@ -302,3 +222,74 @@ void IMB_float_from_rect(struct ImBuf *ibuf)
}
}
+/* no profile conversion */
+void IMB_float_from_rect_simple(struct ImBuf *ibuf)
+{
+ int profile = IB_PROFILE_NONE;
+
+ /* no color management:
+ * don't disturb the existing profiles */
+ SWAP(int, ibuf->profile, profile);
+
+ IMB_float_from_rect(ibuf);
+
+ SWAP(int, ibuf->profile, profile);
+}
+
+void IMB_convert_profile(struct ImBuf *ibuf, int profile)
+{
+ int ok= FALSE;
+ int i;
+
+ unsigned char *rct= (unsigned char *)ibuf->rect;
+ float *rctf= ibuf->rect_float;
+
+ if(ibuf->profile == profile)
+ return;
+
+ if(ELEM(ibuf->profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* from */
+ if(profile == IB_PROFILE_LINEAR_RGB) { /* to */
+ if(ibuf->rect_float) {
+ for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) {
+ rctf[0]= srgb_to_linearrgb(rctf[0]);
+ rctf[1]= srgb_to_linearrgb(rctf[1]);
+ rctf[2]= srgb_to_linearrgb(rctf[2]);
+ }
+ }
+ if(ibuf->rect) {
+ for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
+ rctf[0]= (unsigned char)((srgb_to_linearrgb((float)rctf[0]/255.0f) * 255.0f) + 0.5f);
+ rctf[1]= (unsigned char)((srgb_to_linearrgb((float)rctf[1]/255.0f) * 255.0f) + 0.5f);
+ rctf[2]= (unsigned char)((srgb_to_linearrgb((float)rctf[2]/255.0f) * 255.0f) + 0.5f);
+ }
+ }
+ ok= TRUE;
+ }
+ }
+ else if (ibuf->profile == IB_PROFILE_LINEAR_RGB) { /* from */
+ if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) { /* to */
+ if(ibuf->rect_float) {
+ for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) {
+ rctf[0]= linearrgb_to_srgb(rctf[0]);
+ rctf[1]= linearrgb_to_srgb(rctf[1]);
+ rctf[2]= linearrgb_to_srgb(rctf[2]);
+ }
+ }
+ if(ibuf->rect) {
+ for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
+ rctf[0]= (unsigned char)((linearrgb_to_srgb((float)rctf[0]/255.0f) * 255.0f) + 0.5f);
+ rctf[1]= (unsigned char)((linearrgb_to_srgb((float)rctf[1]/255.0f) * 255.0f) + 0.5f);
+ rctf[2]= (unsigned char)((linearrgb_to_srgb((float)rctf[2]/255.0f) * 255.0f) + 0.5f);
+ }
+ }
+ ok= TRUE;
+ }
+ }
+
+ if(ok==FALSE){
+ printf("IMB_convert_profile: failed profile conversion %d -> %d\n", ibuf->profile, profile);
+ return;
+ }
+
+ ibuf->profile= profile;
+}
diff --git a/source/blender/imbuf/intern/dynlibtiff.c b/source/blender/imbuf/intern/dynlibtiff.c
deleted file mode 100644
index 31da262ffdb..00000000000
--- a/source/blender/imbuf/intern/dynlibtiff.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * Dynamically loaded libtiff support.
- *
- * This file is automatically generated by the gen_dynlibtiff.py script.
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Jonathan Merritt.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/**
- * To use the dynamic libtiff support, you must initialize the library using:
- * libtiff_init()
- * This attempts to load libtiff dynamically at runtime. G.have_libtiff will
- * be set to indicate whether or not libtiff is available. If libtiff is
- * not available, Blender can proceed with no ill effects, provided that
- * it does not attempt to use any of the libtiff_ functions. When you're
- * finished, close the library with:
- * libtiff_exit()
- * These functions are both declared in IMB_imbuf.h
- *
- * The functions provided by dyn_libtiff.h are the same as those in the
- * normal static / shared libtiff, except that they are prefixed by the
- * string "libtiff_" to indicate that they belong to a dynamically-loaded
- * version.
- */
-#include "dynlibtiff.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf.h"
-
-#include "BKE_global.h"
-#include "PIL_dynlib.h"
-
-/*********************
- * LOCAL DEFINITIONS *
- *********************/
-PILdynlib *libtiff = NULL;
-void libtiff_loadlibtiff(void);
-void* libtiff_findsymbol(char*);
-int libtiff_load_symbols(void);
-
-
-/**************************
- * LIBRARY INITIALIZATION *
- **************************/
-
-void libtiff_loadlibtiff(void)
-{
- char *filename;
- libtiff = NULL;
-
- filename = getenv("BF_TIFF_LIB");
- if (filename) libtiff = PIL_dynlib_open(filename);
- if (libtiff != NULL) return;
-
- /* Try to find libtiff in a couple of standard places */
-#ifdef __APPLE__
- /* OSX has version specific library */
- //standard install location
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.4.dylib");
- if (libtiff != NULL) return;
- //inside the blender app package contents/resources
- libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.4.dylib");
- if (libtiff != NULL) return;
- //inside the blender app package contents/frameworks
- libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.4.dylib");
- if (libtiff != NULL) return;
- //along side the blender app package
- libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.4.dylib");
- if (libtiff != NULL) return;
- //inside the blender app package contents/MacOS
- libtiff = PIL_dynlib_open("@executable_path/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/libtiff.4.dylib");
- if (libtiff != NULL) return;
-#else
- libtiff = PIL_dynlib_open("libtiff.so");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("libtiff.so.3");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("libtiff.so.4");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("libtiff.dll");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib/libtiff.so");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.3");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.4");
- if (libtiff != NULL) return;
-#ifdef __x86_64__
- libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.3");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.4");
- if (libtiff != NULL) return;
-#endif
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.so");
- if (libtiff != NULL) return;
- /* For solaris */
- libtiff = PIL_dynlib_open("/usr/openwin/lib/libtiff.so");
-#endif
-
-}
-
-void *libtiff_findsymbol(char *name)
-{
- void *symbol = NULL;
- assert(libtiff != NULL);
- symbol = PIL_dynlib_find_symbol(libtiff, name);
- if (symbol == NULL) {
- char *err = PIL_dynlib_get_error_as_string(libtiff);
-
- if (err) printf("libtiff_findsymbol: error %s\n",err);
- else printf("libtiff_findsymbol: error Unknown.\n");
-
- libtiff = NULL;
- G.have_libtiff = (0);
- return NULL;
- }
- return symbol;
-}
-
-void libtiff_init(void)
-{
- if (libtiff != NULL) {
- printf("libtiff_init: Attempted to load libtiff twice!\n");
- return;
- }
- libtiff_loadlibtiff();
- G.have_libtiff = ((libtiff != NULL) && (libtiff_load_symbols()));
-}
-
-void libtiff_exit(void)
-{
- if (libtiff != NULL) {
- PIL_dynlib_close(libtiff);
- libtiff = NULL;
- }
-}
-
-
-int libtiff_load_symbols(void)
-{
- /* Attempt to load TIFFClientOpen */
- libtiff_TIFFClientOpen = libtiff_findsymbol("TIFFClientOpen");
- if (libtiff_TIFFClientOpen == NULL) {
- return (0);
- }
- /* Attempt to load TIFFClose */
- libtiff_TIFFClose = libtiff_findsymbol("TIFFClose");
- if (libtiff_TIFFClose == NULL) {
- return (0);
- }
- /* Attempt to load TIFFGetField */
- libtiff_TIFFGetField = libtiff_findsymbol("TIFFGetField");
- if (libtiff_TIFFGetField == NULL) {
- return (0);
- }
- /* Attempt to load TIFFOpen */
- libtiff_TIFFOpen = libtiff_findsymbol("TIFFOpen");
- if (libtiff_TIFFOpen == NULL) {
- return (0);
- }
- /* Attempt to load TIFFReadRGBAImage */
- libtiff_TIFFReadRGBAImage = libtiff_findsymbol("TIFFReadRGBAImage");
- if (libtiff_TIFFReadRGBAImage == NULL) {
- return (0);
- }
- /* Attempt to load TIFFSetField */
- libtiff_TIFFSetField = libtiff_findsymbol("TIFFSetField");
- if (libtiff_TIFFSetField == NULL) {
- return (0);
- }
- /* Attempt to load TIFFWriteEncodedStrip */
- libtiff_TIFFWriteEncodedStrip = libtiff_findsymbol("TIFFWriteEncodedStrip");
- if (libtiff_TIFFWriteEncodedStrip == NULL) {
- return (0);
- }
- /* Attempt to load _TIFFfree */
- libtiff__TIFFfree = libtiff_findsymbol("_TIFFfree");
- if (libtiff__TIFFfree == NULL) {
- return (0);
- }
- /* Attempt to load _TIFFmalloc */
- libtiff__TIFFmalloc = libtiff_findsymbol("_TIFFmalloc");
- if (libtiff__TIFFmalloc == NULL) {
- return (0);
- }
- return (1);
-}
-
-
-/*******************
- * SYMBOL POINTERS *
- *******************/
-
-TIFF* (*libtiff_TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc) = NULL;
-void (*libtiff_TIFFClose)(TIFF*) = NULL;
-int (*libtiff_TIFFGetField)(TIFF*, ttag_t, ...) = NULL;
-TIFF* (*libtiff_TIFFOpen)(const char*, const char*) = NULL;
-int (*libtiff_TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int) = NULL;
-int (*libtiff_TIFFSetField)(TIFF*, ttag_t, ...) = NULL;
-tsize_t (*libtiff_TIFFWriteEncodedStrip)(TIFF*, tstrip_t, tdata_t, tsize_t) = NULL;
-void (*libtiff__TIFFfree)(tdata_t) = NULL;
-tdata_t (*libtiff__TIFFmalloc)(tsize_t) = NULL;
diff --git a/source/blender/imbuf/intern/dynlibtiff.h b/source/blender/imbuf/intern/dynlibtiff.h
deleted file mode 100644
index 6c8cd184463..00000000000
--- a/source/blender/imbuf/intern/dynlibtiff.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Dynamically loaded libtiff support.
- *
- * This file is automatically generated by the gen_dynlibtiff.py script.
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Jonathan Merritt.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/**
- * To use the dynamic libtiff support, you must initialize the library using:
- * libtiff_init()
- * This attempts to load libtiff dynamically at runtime. G.have_libtiff will
- * be set to indicate whether or not libtiff is available. If libtiff is
- * not available, Blender can proceed with no ill effects, provided that
- * it does not attempt to use any of the libtiff_ functions. When you're
- * finished, close the library with:
- * libtiff_exit()
- * These functions are both declared in IMB_imbuf.h
- *
- * The functions provided by dyn_libtiff.h are the same as those in the
- * normal static / shared libtiff, except that they are prefixed by the
- * string "libtiff_" to indicate that they belong to a dynamically-loaded
- * version.
- */
-#ifndef DYN_LIBTIFF_H
-#include "tiffio.h"
-extern TIFF* (*libtiff_TIFFClientOpen)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc);
-extern void (*libtiff_TIFFClose)(TIFF*);
-extern int (*libtiff_TIFFGetField)(TIFF*, ttag_t, ...);
-extern TIFF* (*libtiff_TIFFOpen)(const char*, const char*);
-extern int (*libtiff_TIFFReadRGBAImage)(TIFF*, uint32, uint32, uint32*, int);
-extern int (*libtiff_TIFFSetField)(TIFF*, ttag_t, ...);
-extern tsize_t (*libtiff_TIFFWriteEncodedStrip)(TIFF*, tstrip_t, tdata_t, tsize_t);
-extern void (*libtiff__TIFFfree)(tdata_t);
-extern tdata_t (*libtiff__TIFFmalloc)(tsize_t);
-#endif /* DYN_LIBTIFF_H */
-
diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c
new file mode 100644
index 00000000000..db2eef759dc
--- /dev/null
+++ b/source/blender/imbuf/intern/filetype.c
@@ -0,0 +1,106 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation, 2010.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+#include "IMB_filetype.h"
+
+#ifdef WITH_OPENEXR
+#include "openexr/openexr_api.h"
+#endif
+
+#ifdef WITH_DDS
+#include "dds/dds_api.h"
+#endif
+
+#ifdef WITH_QUICKTIME
+#include "quicktime_import.h"
+#endif
+
+#include "imbuf.h"
+
+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); }
+#endif
+static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype == IMAGIC); }
+#ifdef WITH_QUICKTIME
+static int imb_ftype_quicktime(ImFileType *type, ImBuf *ibuf) { return 0; } // XXX
+#endif
+
+#ifdef WITH_QUICKTIME
+void quicktime_init(void);
+void quicktime_exit(void);
+#endif
+
+ImFileType IMB_FILE_TYPES[]= {
+ {NULL, NULL, imb_is_a_iris, imb_ftype_iris, imb_loadiris, imb_saveiris, NULL, 0, IMAGIC},
+ {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},
+ {NULL, NULL, imb_is_a_targa, imb_ftype_default, imb_loadtarga, imb_savetarga, NULL, 0, TGA},
+#ifdef WITH_CINEON
+ {NULL, NULL, imb_is_dpx, imb_ftype_default, imb_loaddpx, imb_save_dpx, NULL, IM_FTYPE_FLOAT, DPX},
+ {NULL, NULL, imb_is_cineon, imb_ftype_default, imb_loadcineon, imb_savecineon, NULL, IM_FTYPE_FLOAT, CINEON},
+#endif
+#ifdef WITH_TIFF
+ {imb_inittiff, NULL, imb_is_a_tiff, imb_ftype_default, imb_loadtiff, imb_savetiff, imb_loadtiletiff, 0, TIF},
+#elif defined(__APPLE__) && defined(IMBUF_COCOA)
+ {NULL, NULL, imb_is_a_cocoa, imb_ftype_cocoa, imb_imb_cocoaLoadImage, imb_savecocoa, NULL, 0, TIF},
+#endif
+#ifdef WITH_HDR
+ {NULL, NULL, imb_is_a_hdr, imb_ftype_default, imb_loadhdr, imb_savehdr, NULL, IM_FTYPE_FLOAT, RADHDR},
+#endif
+#ifdef WITH_OPENEXR
+ {NULL, NULL, imb_is_a_openexr, imb_ftype_default, imb_load_openexr, imb_save_openexr, NULL, IM_FTYPE_FLOAT, OPENEXR},
+#endif
+#ifdef WITH_OPENJPEG
+ {NULL, NULL, imb_is_a_jp2, imb_ftype_default, imb_jp2_decode, imb_savejp2, NULL, IM_FTYPE_FLOAT, JP2},
+#endif
+#ifdef WITH_DDS
+ {NULL, NULL, imb_is_a_dds, imb_ftype_default, imb_load_dds, NULL, NULL, 0, DDS},
+#endif
+#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, 0}};
+
+void imb_filetypes_init(void)
+{
+ ImFileType *type;
+
+ for(type=IMB_FILE_TYPES; type->is_a; type++)
+ if(type->init)
+ type->init();
+}
+
+void imb_filetypes_exit(void)
+{
+ ImFileType *type;
+
+ for(type=IMB_FILE_TYPES; type->is_a; type++)
+ if(type->exit)
+ type->exit();
+}
+
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c
index 5692686a9bc..3cc266e460e 100644
--- a/source/blender/imbuf/intern/filter.c
+++ b/source/blender/imbuf/intern/filter.c
@@ -29,14 +29,14 @@
* $Id$
*/
-#include "BLI_blenlib.h"
+#include "BKE_utildefines.h"
+#include "MEM_guardedalloc.h"
-#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_filter.h"
+#include "imbuf.h"
/************************************************************************/
/* FILTERS */
@@ -375,17 +375,97 @@ void IMB_makemipmap(ImBuf *ibuf, int use_filter)
{
ImBuf *hbuf = ibuf;
int curmap = 0;
- while (curmap < IB_MIPMAP_LEVELS) {
- if (use_filter) {
+
+ ibuf->miptot= 1;
+
+ while(curmap < IB_MIPMAP_LEVELS) {
+ if(use_filter) {
ImBuf *nbuf= IMB_allocImBuf(hbuf->x, hbuf->y, 32, IB_rect, 0);
IMB_filterN(nbuf, hbuf);
ibuf->mipmap[curmap] = IMB_onehalf(nbuf);
IMB_freeImBuf(nbuf);
}
- else ibuf->mipmap[curmap] = IMB_onehalf(hbuf);
- hbuf = ibuf->mipmap[curmap];
- if (hbuf->x == 1 && hbuf->y == 1) break;
+ else
+ ibuf->mipmap[curmap] = IMB_onehalf(hbuf);
+
+ ibuf->miptot= curmap+2;
+ hbuf= ibuf->mipmap[curmap];
+ hbuf->miplevel= curmap+1;
+
+ if(!hbuf || (hbuf->x == 1 && hbuf->y == 1))
+ break;
+
curmap++;
}
}
+ImBuf *IMB_getmipmap(ImBuf *ibuf, int level)
+{
+ CLAMP(level, 0, ibuf->miptot-1);
+ return (level == 0)? ibuf: ibuf->mipmap[level-1];
+}
+
+void IMB_premultiply_rect(unsigned int *rect, int depth, int w, int h)
+{
+ char *cp;
+ int x, y, val;
+
+ if(depth == 24) { /* put alpha at 255 */
+ cp= (char *)(rect);
+
+ for(y=0; y<h; y++)
+ for(x=0; x<w; x++, cp+=4)
+ cp[3]= 255;
+ }
+ else {
+ cp= (char *)(rect);
+
+ for(y=0; y<h; y++) {
+ for(x=0; x<w; x++, cp+=4) {
+ val= cp[3];
+ cp[0]= (cp[0]*val)>>8;
+ cp[1]= (cp[1]*val)>>8;
+ cp[2]= (cp[2]*val)>>8;
+ }
+ }
+ }
+}
+
+void IMB_premultiply_rect_float(float *rect_float, int depth, int w, int h)
+{
+ float val, *cp;
+ int x, y;
+
+ if(depth==24) { /* put alpha at 1.0 */
+ cp= rect_float;
+
+ for(y=0; y<h; y++)
+ for(x=0; x<w; x++, cp+=4)
+ cp[3]= 1.0;
+ }
+ else {
+ cp= rect_float;
+ for(y=0; y<h; y++) {
+ for(x=0; x<w; x++, cp+=4) {
+ val= cp[3];
+ cp[0]= cp[0]*val;
+ cp[1]= cp[1]*val;
+ cp[2]= cp[2]*val;
+ }
+ }
+ }
+
+}
+
+void IMB_premultiply_alpha(ImBuf *ibuf)
+{
+ if(ibuf==NULL)
+ return;
+
+ if(ibuf->rect)
+ IMB_premultiply_rect(ibuf->rect, ibuf->depth, ibuf->x, ibuf->y);
+
+ if(ibuf->rect_float)
+ IMB_premultiply_rect_float(ibuf->rect_float, ibuf->depth, ibuf->x, ibuf->y);
+}
+
diff --git a/source/blender/imbuf/intern/gen_dynlibtiff.py b/source/blender/imbuf/intern/gen_dynlibtiff.py
deleted file mode 100755
index fd69a353bfd..00000000000
--- a/source/blender/imbuf/intern/gen_dynlibtiff.py
+++ /dev/null
@@ -1,303 +0,0 @@
-#!/usr/bin/env python
-
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# Contributor(s): Jonathan Merritt.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-#
-# This script generates a C source file and a header file that implement
-# dynamic loading functionality for libtiff.
-# If you need to make more functions from libtiff available, then simply add
-# them to the tiff_functions[] list below.
-#
-
-
-FILENAME = 'dynlibtiff'
-C_FILENAME = '%s.c' % FILENAME
-H_FILENAME = '%s.h' % FILENAME
-
-
-COMMENT = \
-"""/**
- * Dynamically loaded libtiff support.
- *
- * This file is automatically generated by the gen_dynlibtiff.py script.
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Jonathan Merritt.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/**
- * To use the dynamic libtiff support, you must initialize the library using:
- * libtiff_init()
- * This attempts to load libtiff dynamically at runtime. G.have_libtiff will
- * be set to indicate whether or not libtiff is available. If libtiff is
- * not available, Blender can proceed with no ill effects, provided that
- * it does not attempt to use any of the libtiff_ functions. When you're
- * finished, close the library with:
- * libtiff_exit()
- * These functions are both declared in IMB_imbuf.h
- *
- * The functions provided by dyn_libtiff.h are the same as those in the
- * normal static / shared libtiff, except that they are prefixed by the
- * string "libtiff_" to indicate that they belong to a dynamically-loaded
- * version.
- */
-"""
-
-
-C_EXTRA = \
-"""
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf.h"
-
-#include "BKE_global.h"
-#include "PIL_dynlib.h"
-
-/*********************
- * LOCAL DEFINITIONS *
- *********************/
-PILdynlib *libtiff = NULL;
-void libtiff_loadlibtiff(void);
-void* libtiff_findsymbol(char*);
-int libtiff_load_symbols(void);
-
-
-/**************************
- * LIBRARY INITIALIZATION *
- **************************/
-
-void libtiff_loadlibtiff(void)
-{
- char *filename;
- libtiff = NULL;
-
- filename = getenv("BF_TIFF_LIB");
- if (filename) libtiff = PIL_dynlib_open(filename);
- if (libtiff != NULL) return;
-
- /* Try to find libtiff in a couple of standard places */
-#ifdef __APPLE__
- /* OSX has version specific library */
- //standard install location
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.4.dylib");
- if (libtiff != NULL) return;
- //inside the blender app package contents/resources
- libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../resources/libtiff.4.dylib");
- if (libtiff != NULL) return;
- //inside the blender app package contents/frameworks
- libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../frameworks/libtiff.4.dylib");
- if (libtiff != NULL) return;
- //along side the blender app package
- libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/../../../libtiff.4.dylib");
- if (libtiff != NULL) return;
- //inside the blender app package contents/MacOS
- libtiff = PIL_dynlib_open("@executable_path/libtiff.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/libtiff.3.dylib");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("@executable_path/libtiff.4.dylib");
- if (libtiff != NULL) return;
-#else
- libtiff = PIL_dynlib_open("libtiff.so");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("libtiff.so.3");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("libtiff.so.4");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("libtiff.dll");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib/libtiff.so");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.3");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib/libtiff.so.4");
- if (libtiff != NULL) return;
-#ifdef __x86_64__
- libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.3");
- if (libtiff != NULL) return;
- libtiff = PIL_dynlib_open("/usr/lib64/libtiff.so.4");
- if (libtiff != NULL) return;
-#endif
- libtiff = PIL_dynlib_open("/usr/local/lib/libtiff.so");
- if (libtiff != NULL) return;
- /* For solaris */
- libtiff = PIL_dynlib_open("/usr/openwin/lib/libtiff.so");
-#endif
-
-}
-
-void *libtiff_findsymbol(char *name)
-{
- void *symbol = NULL;
- assert(libtiff != NULL);
- symbol = PIL_dynlib_find_symbol(libtiff, name);
- if (symbol == NULL) {
- char *err = PIL_dynlib_get_error_as_string(libtiff);
-
- if (err) printf("libtiff_findsymbol: error %s\\n",err);
- else printf("libtiff_findsymbol: error Unknown.\\n");
-
- libtiff = NULL;
- G.have_libtiff = (0);
- return NULL;
- }
- return symbol;
-}
-
-void libtiff_init(void)
-{
- if (libtiff != NULL) {
- printf("libtiff_init: Attempted to load libtiff twice!\\n");
- return;
- }
- libtiff_loadlibtiff();
- G.have_libtiff = ((libtiff != NULL) && (libtiff_load_symbols()));
-}
-
-void libtiff_exit(void)
-{
- if (libtiff != NULL) {
- PIL_dynlib_close(libtiff);
- libtiff = NULL;
- }
-}
-
-
-"""
-
-
-class CFun:
- def __init__(self, name, retType, args):
- self.name = name
- self.retType = retType
- self.args = args
- def getDynamicName(self):
- return ('libtiff_%s' % self.name)
- def getDynamicDecl(self):
- argstr = (('%s, '*len(self.args)) % tuple(self.args))[:-2]
- return ('%s (*%s)(%s)' % (self.retType,
- self.getDynamicName(), argstr))
- def getLoadSymbol(self):
- dname = self.getDynamicName()
- return (
- """\t/* Attempt to load %s */
- %s = libtiff_findsymbol("%s");
- if (%s == NULL) {
- return (0);
- }\n""" % (self.name, dname, self.name, dname))
-
-
-# If you need more functions, add them to the list below, based upon entries
-# in either tiffio.h or tiff.h.
-tiff_functions = [
- CFun('TIFFClientOpen', 'TIFF*', ['const char*', 'const char*',
- 'thandle_t', 'TIFFReadWriteProc', 'TIFFReadWriteProc',
- 'TIFFSeekProc', 'TIFFCloseProc', 'TIFFSizeProc',
- 'TIFFMapFileProc', 'TIFFUnmapFileProc']),
- CFun('TIFFClose', 'void', ['TIFF*']),
- CFun('TIFFGetField', 'int', ['TIFF*', 'ttag_t', '...']),
- CFun('TIFFOpen', 'TIFF*', ['const char*', 'const char*']),
- CFun('TIFFReadRGBAImage', 'int', ['TIFF*', 'uint32', 'uint32',
- 'uint32*', 'int']),
- CFun('TIFFSetField', 'int', ['TIFF*', 'ttag_t', '...']),
- CFun('TIFFWriteEncodedStrip', 'tsize_t', ['TIFF*', 'tstrip_t',
- 'tdata_t', 'tsize_t']),
- CFun('_TIFFfree', 'void', ['tdata_t']),
- CFun('_TIFFmalloc', 'tdata_t', ['tsize_t']),
-]
-
-
-def outputDynCFile(outfile, header_file_name):
- outfile.write(COMMENT)
- outfile.write('#include "%s"\n' % header_file_name)
- outfile.write(C_EXTRA)
- outfile.write('int libtiff_load_symbols(void)\n')
- outfile.write('{\n')
- for function in tiff_functions:
- outfile.write(function.getLoadSymbol())
- outfile.write('\treturn (1);\n')
- outfile.write('}\n')
- outfile.write("""
-
-/*******************
- * SYMBOL POINTERS *
- *******************/\n\n""")
- for function in tiff_functions:
- outfile.write('%s = NULL;\n' % function.getDynamicDecl())
-
-
-def outputDynHFile(outfile):
- outfile.write(COMMENT)
- outfile.write('#ifndef DYN_LIBTIFF_H\n')
- outfile.write('#include "tiffio.h"\n')
- for function in tiff_functions:
- outfile.write('extern %s;\n' % function.getDynamicDecl())
- outfile.write('#endif /* DYN_LIBTIFF_H */\n\n')
-
-
-if __name__ == '__main__':
- outfile = file(C_FILENAME, 'w')
- outputDynCFile(outfile, H_FILENAME)
- outfile.close()
- outfile = file(H_FILENAME, 'w')
- outputDynHFile(outfile)
- outfile.close()
diff --git a/source/blender/imbuf/intern/ham.c b/source/blender/imbuf/intern/ham.c
deleted file mode 100644
index 27f6d9c691a..00000000000
--- a/source/blender/imbuf/intern/ham.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/**
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * ham.c
- *
- * $Id$
- */
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-#include "IMB_cmap.h"
-#include "IMB_hamx.h"
-#include "IMB_ham.h"
-
-extern short alpha_col0;
-
-#define HAMB 0x0100
-#define HAMG 0x0400
-#define HAMR 0x0200
-#define HAMC 0x1000
-#define HAMFREE 0x2000
-
-static void addhamdither(short x, unsigned char *dit,
- short dmax, unsigned char *rgb,
- unsigned short *ham,
- short type, short round, short shift)
-{
- short dx = 0;
- short c1, c2;
-
- for (;x>0;x--){
- if (ham[0] & (HAMFREE | type)){
- c2 = c1 = *rgb;
-
- /* wrap dither */
- while (dx >= dmax) dx -= dmax;
-
- c1 += dit[dx];
- if (c1 > 255) c1 = 255;
- c2 += round;
- if (c2 > 255) c2 = 255;
-
- if (c1 != c2){
- c1 >>= shift; c2 >>= shift;
- if (ham[1] & HAMFREE){
- ham[0] = type + c1;
- ham[1] = type + c2;
- } else if (ham[1] & type){
- ham[0] = type + c1;
- } else if ((ham[2] & (type | HAMFREE)) == type){
- ham[0] = type + c1;
- } else if ((ham[1] & HAMC) | (ham[2] & HAMC)){
- ham[0] = type + c1;
- }
- }
- }
- rgb += 4;
- ham ++;
- dx ++;
- }
-}
-
-static void convhamscanl(short x, short y,
- unsigned char *rgbbase,
- unsigned char *coltab,
- short *deltab,
- short bits)
-{
- int a, r, g, b, lr, lg, lb, dr, dg, db, col, fout, type, x2;
- int round, shift;
- uchar *rgb, dit[2];
- unsigned short *ham, *hambase;
-
- /* Concept:
- first we check the entire image, where color transitions are coded: FGRB XXXX XXXX
- F - free color value, can be changed by anyone
- G/R/B - green/red/blue ham transition, only to be changed by this color
- XXXX XXXX - N bits value.
-
- 0000 XXXX XXXX is palette color.
-
- after that first the green dither is added, then the red dither, and finally blue dither
- */
-
- if ((hambase = (unsigned short *) malloc((x+4) * sizeof(unsigned short)))==0) return;
-
- lb = coltab[1];
- lg = coltab[2];
- lr = coltab[3];
- type = col = 0;
-
- ham = hambase;
- rgb = rgbbase;
-
- shift = 8 - bits;
- round = 1 << (shift - 1);
-
- /* to prevent 'noise' at the end of the line */
- for (x2 = 3; x2 >= 0; x2 --) hambase[x + x2] = HAMFREE;
-
- for (x2 = x ;x2 > 0; x2--){
- r = rgb[0] + round;
- g = rgb[1] + round;
- b = rgb[2] + round;
- a = rgb[3];
-
- if (a < 128 && alpha_col0) {
- a = 1;
- } else a = 0;
-
- if (b > 255) b = 255;
- if (g > 255) {
- g = 255;
- }
- if (r > 255) r = 255;
-
- r >>= shift;
- g >>= shift;
- b >>= shift;
-
- if ((b-lb) | (g-lg) | (r-lr) | a){
- if (a) {
- col = 0;
- type = HAMC;
- } else {
- col = ((b << (2 * bits)) + (g << bits) + r) << 1;
- fout = deltab[col + 1];
- col = deltab[col];
- type = HAMC;
-
- dr = quadr[lr-r];
- dg = quadr[lg-g];
- db = quadr[lb-b];
-
- if ((dr+dg) <= fout){
- fout = dr+dg;
- col = b;
- type = HAMB;
- }
- if ((dg+db) <= fout){
- fout = dg+db;
- col = r;
- type = HAMR;
- }
- if ((dr+db) <= fout){
- fout = dr+db;
- col = g;
- type = HAMG;
- }
- }
-
- switch(type){
- case HAMG:
- lg = g;
- break;
- case HAMR:
- lr = r;
- break;
- case HAMB:
- lb = b;
- break;
- default:
- lb = coltab[col*4 + 1];
- lg = coltab[col*4 + 2];
- lr = coltab[col*4 + 3];
- }
- *ham = type + col;
- } else *ham = HAMG + HAMFREE + g;
-
- rgb += 4;
- ham ++;
- }
-
-
- if (y & 1){
- dit[0] = 0 << (shift - 2);
- dit[1] = 3 << (shift - 2);
- } else {
- dit[0] = 2 << (shift - 2);
- dit[1] = 1 << (shift - 2);
- }
-
- addhamdither(x,dit,2,rgbbase+2,hambase,HAMG, round, shift);
-
- if ((y & 1)==0){
- dit[0] = 3 << (shift - 2);
- dit[1] = 0 << (shift - 2);
- } else {
- dit[0] = 1 << (shift - 2);
- dit[1] = 2 << (shift - 2);
- }
-
- addhamdither(x,dit,2,rgbbase+3,hambase,HAMR, round, shift);
- addhamdither(x,dit,2,rgbbase+1,hambase,HAMB, round, shift);
-
-
- ham = hambase;
- rgb = rgbbase;
- rgb += 3;
-
- for (x2=x;x2>0;x2--){
- type = *(ham++);
- if (type & HAMG) type |= HAMR | HAMB;
-
- *rgb = (type & 0xff) | ((type & (HAMR | HAMB)) >> shift);
- rgb += 4;
- }
-
- free (hambase);
-}
-
-
-short imb_converttoham(struct ImBuf *ibuf)
-{
- unsigned int coltab[256],*rect;
- short x,y,* deltab;
- int mincol;
-
- memcpy(coltab,ibuf->cmap,4 * ibuf->maxcol);
-
- mincol = ibuf->mincol;
- if (alpha_col0 && mincol == 0) mincol = 1;
-
- if (ibuf->ftype == AN_hamx) {
- deltab = imb_coldeltatab((uchar *) coltab, 0, ibuf->maxcol, 4);
- } else {
- ibuf->cbits = ibuf->depth - 2;
- imb_losecmapbits(ibuf, coltab);
- deltab = imb_coldeltatab((uchar *) coltab, mincol, ibuf->maxcol, ibuf->cbits);
- }
-
- rect = ibuf->rect;
- x=ibuf->x;
- y=ibuf->y;
-
- if (ibuf->ftype == AN_hamx){
- IMB_dit2(ibuf, 2, 4);
- IMB_dit2(ibuf, 1, 4);
- IMB_dit2(ibuf, 0, 4);
- imb_convhamx(ibuf, (uchar *)coltab, deltab);
- } else {
- for(;y > 0; y--){
- convhamscanl(x, y, (uchar *)rect, (uchar *)coltab, deltab, ibuf->cbits);
- rect += x;
- }
- }
-
- return (TRUE);
-}
diff --git a/source/blender/imbuf/intern/hamx.c b/source/blender/imbuf/intern/hamx.c
deleted file mode 100644
index 57672f54999..00000000000
--- a/source/blender/imbuf/intern/hamx.c
+++ /dev/null
@@ -1,581 +0,0 @@
-/**
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * hamx.c
- *
- * $Id$
- */
-
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-#include "IMB_allocimbuf.h"
-#include "IMB_filter.h"
-#include "IMB_ham.h"
-#include "IMB_hamx.h"
-
-#ifdef WIN32
-#include <io.h>
-#include "BLI_winstuff.h"
-#endif
-
-/* actually hard coded endianness */
-#define GET_BIG_LONG(x) (((uchar *) (x))[0] << 24 | ((uchar *) (x))[1] << 16 | ((uchar *) (x))[2] << 8 | ((uchar *) (x))[3])
-#define GET_LITTLE_LONG(x) (((uchar *) (x))[3] << 24 | ((uchar *) (x))[2] << 16 | ((uchar *) (x))[1] << 8 | ((uchar *) (x))[0])
-#define SWAP_L(x) (((x << 24) & 0xff000000) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff))
-#define SWAP_S(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff))
-
-/* more endianness... should move to a separate file... */
-#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__hppa__) || defined (__BIG_ENDIAN__)
-#define GET_ID GET_BIG_LONG
-#define LITTLE_LONG SWAP_LONG
-#else
-#define GET_ID GET_LITTLE_LONG
-#define LITTLE_LONG ENDIAN_NOP
-#endif
-
-#ifndef ABS
-#define ABS(x) ((x) < 0 ? -(x) : (x))
-#endif
-
-static uchar hamx_array_char[] = {
- 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF,
- 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF,
- 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF,
- 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF, 0x00,0xFF,0x00,0xFF,
- 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00,
- 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00, 0x00,0xFF,0xFF,0x00,
-
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
-
- 0x00,0x00,0x00,0x00, 0x00,0x10,0x00,0x00, 0x00,0x20,0x00,0x00, 0x00,0x30,0x00,0x00, 0x00,0x40,0x00,0x00, 0x00,0x50,0x00,0x00, 0x00,0x60,0x00,0x00, 0x00,0x70,0x00,0x00,
- 0x00,0x80,0x00,0x00, 0x00,0x90,0x00,0x00, 0x00,0xA0,0x00,0x00, 0x00,0xB0,0x00,0x00, 0x00,0xC0,0x00,0x00, 0x00,0xD0,0x00,0x00, 0x00,0xE0,0x00,0x00, 0x00,0xF0,0x00,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x10,0x00, 0x00,0x00,0x20,0x00, 0x00,0x00,0x30,0x00, 0x00,0x00,0x40,0x00, 0x00,0x00,0x50,0x00, 0x00,0x00,0x60,0x00, 0x00,0x00,0x70,0x00,
- 0x00,0x00,0x80,0x00, 0x00,0x00,0x90,0x00, 0x00,0x00,0xA0,0x00, 0x00,0x00,0xB0,0x00, 0x00,0x00,0xC0,0x00, 0x00,0x00,0xD0,0x00, 0x00,0x00,0xE0,0x00, 0x00,0x00,0xF0,0x00,
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x10, 0x00,0x00,0x00,0x20, 0x00,0x00,0x00,0x30, 0x00,0x00,0x00,0x40, 0x00,0x00,0x00,0x50, 0x00,0x00,0x00,0x60, 0x00,0x00,0x00,0x70,
- 0x00,0x00,0x00,0x80, 0x00,0x00,0x00,0x90, 0x00,0x00,0x00,0xA0, 0x00,0x00,0x00,0xB0, 0x00,0x00,0x00,0xC0, 0x00,0x00,0x00,0xD0, 0x00,0x00,0x00,0xE0, 0x00,0x00,0x00,0xF0,
-
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x30, 0x00,0x00,0x00,0x60, 0x00,0x00,0x00,0x90, 0x00,0x00,0x00,0xC0, 0x00,0x00,0x00,0xF0,
- 0x00,0x00,0x20,0x00, 0x00,0x00,0x20,0x30, 0x00,0x00,0x20,0x60, 0x00,0x00,0x20,0x90, 0x00,0x00,0x20,0xC0, 0x00,0x00,0x20,0xF0,
- 0x00,0x00,0x40,0x00, 0x00,0x00,0x40,0x30, 0x00,0x00,0x40,0x60, 0x00,0x00,0x40,0x90, 0x00,0x00,0x40,0xC0, 0x00,0x00,0x40,0xF0,
- 0x00,0x00,0x60,0x00, 0x00,0x00,0x60,0x30, 0x00,0x00,0x60,0x60, 0x00,0x00,0x60,0x90, 0x00,0x00,0x60,0xC0, 0x00,0x00,0x60,0xF0,
- 0x00,0x00,0x90,0x00, 0x00,0x00,0x90,0x30, 0x00,0x00,0x90,0x60, 0x00,0x00,0x90,0x90, 0x00,0x00,0x90,0xC0, 0x00,0x00,0x90,0xF0,
- 0x00,0x00,0xB0,0x00, 0x00,0x00,0xB0,0x30, 0x00,0x00,0xB0,0x60, 0x00,0x00,0xB0,0x90, 0x00,0x00,0xB0,0xC0, 0x00,0x00,0xB0,0xF0,
- 0x00,0x00,0xD0,0x00, 0x00,0x00,0xD0,0x30, 0x00,0x00,0xD0,0x60, 0x00,0x00,0xD0,0x90, 0x00,0x00,0xD0,0xC0, 0x00,0x00,0xD0,0xF0,
- 0x00,0x00,0xF0,0x00, 0x00,0x00,0xF0,0x30, 0x00,0x00,0xF0,0x60, 0x00,0x00,0xF0,0x90, 0x00,0x00,0xF0,0xC0, 0x00,0x00,0xF0,0xF0,
- 0x00,0x50,0x00,0x00, 0x00,0x50,0x00,0x30, 0x00,0x50,0x00,0x60, 0x00,0x50,0x00,0x90, 0x00,0x50,0x00,0xC0, 0x00,0x50,0x00,0xF0,
- 0x00,0x50,0x20,0x00, 0x00,0x50,0x20,0x30, 0x00,0x50,0x20,0x60, 0x00,0x50,0x20,0x90, 0x00,0x50,0x20,0xC0, 0x00,0x50,0x20,0xF0,
- 0x00,0x50,0x40,0x00, 0x00,0x50,0x40,0x30, 0x00,0x50,0x40,0x60, 0x00,0x50,0x40,0x90, 0x00,0x50,0x40,0xC0, 0x00,0x50,0x40,0xF0,
- 0x00,0x50,0x60,0x00, 0x00,0x50,0x60,0x30, 0x00,0x50,0x60,0x60, 0x00,0x50,0x60,0x90, 0x00,0x50,0x60,0xC0, 0x00,0x50,0x60,0xF0,
- 0x00,0x50,0x90,0x00, 0x00,0x50,0x90,0x30, 0x00,0x50,0x90,0x60, 0x00,0x50,0x90,0x90, 0x00,0x50,0x90,0xC0, 0x00,0x50,0x90,0xF0,
- 0x00,0x50,0xB0,0x00, 0x00,0x50,0xB0,0x30, 0x00,0x50,0xB0,0x60, 0x00,0x50,0xB0,0x90, 0x00,0x50,0xB0,0xC0, 0x00,0x50,0xB0,0xF0,
- 0x00,0x50,0xD0,0x00, 0x00,0x50,0xD0,0x30, 0x00,0x50,0xD0,0x60, 0x00,0x50,0xD0,0x90, 0x00,0x50,0xD0,0xC0, 0x00,0x50,0xD0,0xF0,
- 0x00,0x50,0xF0,0x00, 0x00,0x50,0xF0,0x30, 0x00,0x50,0xF0,0x60, 0x00,0x50,0xF0,0x90, 0x00,0x50,0xF0,0xC0, 0x00,0x50,0xF0,0xF0,
- 0x00,0xA0,0x00,0x00, 0x00,0xA0,0x00,0x30, 0x00,0xA0,0x00,0x60, 0x00,0xA0,0x00,0x90, 0x00,0xA0,0x00,0xC0, 0x00,0xA0,0x00,0xF0,
- 0x00,0xA0,0x20,0x00, 0x00,0xA0,0x20,0x30, 0x00,0xA0,0x20,0x60, 0x00,0xA0,0x20,0x90, 0x00,0xA0,0x20,0xC0, 0x00,0xA0,0x20,0xF0,
- 0x00,0xA0,0x40,0x00, 0x00,0xA0,0x40,0x30, 0x00,0xA0,0x40,0x60, 0x00,0xA0,0x40,0x90, 0x00,0xA0,0x40,0xC0, 0x00,0xA0,0x40,0xF0,
- 0x00,0xA0,0x60,0x00, 0x00,0xA0,0x60,0x30, 0x00,0xA0,0x60,0x60, 0x00,0xA0,0x60,0x90, 0x00,0xA0,0x60,0xC0, 0x00,0xA0,0x60,0xF0,
- 0x00,0xA0,0x90,0x00, 0x00,0xA0,0x90,0x30, 0x00,0xA0,0x90,0x60, 0x00,0xA0,0x90,0x90, 0x00,0xA0,0x90,0xC0, 0x00,0xA0,0x90,0xF0,
- 0x00,0xA0,0xB0,0x00, 0x00,0xA0,0xB0,0x30, 0x00,0xA0,0xB0,0x60, 0x00,0xA0,0xB0,0x90, 0x00,0xA0,0xB0,0xC0, 0x00,0xA0,0xB0,0xF0,
- 0x00,0xA0,0xD0,0x00, 0x00,0xA0,0xD0,0x30, 0x00,0xA0,0xD0,0x60, 0x00,0xA0,0xD0,0x90, 0x00,0xA0,0xD0,0xC0, 0x00,0xA0,0xD0,0xF0,
- 0x00,0xA0,0xF0,0x00, 0x00,0xA0,0xF0,0x30, 0x00,0xA0,0xF0,0x60, 0x00,0xA0,0xF0,0x90, 0x00,0xA0,0xF0,0xC0, 0x00,0xA0,0xF0,0xF0,
- 0x00,0xF0,0x00,0x00, 0x00,0xF0,0x00,0x30, 0x00,0xF0,0x00,0x60, 0x00,0xF0,0x00,0x90, 0x00,0xF0,0x00,0xC0, 0x00,0xF0,0x00,0xF0,
- 0x00,0xF0,0x20,0x00, 0x00,0xF0,0x20,0x30, 0x00,0xF0,0x20,0x60, 0x00,0xF0,0x20,0x90, 0x00,0xF0,0x20,0xC0, 0x00,0xF0,0x20,0xF0,
- 0x00,0xF0,0x40,0x00, 0x00,0xF0,0x40,0x30, 0x00,0xF0,0x40,0x60, 0x00,0xF0,0x40,0x90, 0x00,0xF0,0x40,0xC0, 0x00,0xF0,0x40,0xF0,
- 0x00,0xF0,0x60,0x00, 0x00,0xF0,0x60,0x30, 0x00,0xF0,0x60,0x60, 0x00,0xF0,0x60,0x90, 0x00,0xF0,0x60,0xC0, 0x00,0xF0,0x60,0xF0,
- 0x00,0xF0,0x90,0x00, 0x00,0xF0,0x90,0x30, 0x00,0xF0,0x90,0x60, 0x00,0xF0,0x90,0x90, 0x00,0xF0,0x90,0xC0, 0x00,0xF0,0x90,0xF0,
- 0x00,0xF0,0xB0,0x00, 0x00,0xF0,0xB0,0x30, 0x00,0xF0,0xB0,0x60, 0x00,0xF0,0xB0,0x90, 0x00,0xF0,0xB0,0xC0, 0x00,0xF0,0xB0,0xF0,
- 0x00,0xF0,0xD0,0x00, 0x00,0xF0,0xD0,0x30, 0x00,0xF0,0xD0,0x60, 0x00,0xF0,0xD0,0x90, 0x00,0xF0,0xD0,0xC0, 0x00,0xF0,0xD0,0xF0,
- 0x00,0xF0,0xF0,0x00, 0x00,0xF0,0xF0,0x30, 0x00,0xF0,0xF0,0x60, 0x00,0xF0,0xF0,0x90, 0x00,0xF0,0xF0,0xC0, 0x00,0xF0,0xF0,0xF0,
-
- 0x00,0x10,0x10,0x10, 0x00,0x20,0x20,0x20, 0x00,0x30,0x30,0x30, 0x00,0x40,0x40,0x40,
- 0x00,0x50,0x50,0x50, 0x00,0x60,0x60,0x60, 0x00,0x70,0x70,0x70, 0x00,0x80,0x80,0x80,
- 0x00,0x90,0x90,0x90, 0x00,0xA0,0xA0,0xA0, 0x00,0xB0,0xB0,0xB0, 0x00,0xC0,0xC0,0xC0,
- 0x00,0xD0,0xD0,0xD0, 0x00,0xE0,0xE0,0xE0
-};
-
-static int * hamx_array = (int *) (hamx_array_char);
-
-static uchar cmap_hamx[] = {
- 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x30, 0x00,0x00,0x00,0x60, 0x00,0x00,0x00,0x90, 0x00,0x00,0x00,0xC0, 0x00,0x00,0x00,0xF0,
- 0x00,0x00,0x20,0x00, 0x00,0x00,0x20,0x30, 0x00,0x00,0x20,0x60, 0x00,0x00,0x20,0x90, 0x00,0x00,0x20,0xC0, 0x00,0x00,0x20,0xF0,
- 0x00,0x00,0x40,0x00, 0x00,0x00,0x40,0x30, 0x00,0x00,0x40,0x60, 0x00,0x00,0x40,0x90, 0x00,0x00,0x40,0xC0, 0x00,0x00,0x40,0xF0,
- 0x00,0x00,0x60,0x00, 0x00,0x00,0x60,0x30, 0x00,0x00,0x60,0x60, 0x00,0x00,0x60,0x90, 0x00,0x00,0x60,0xC0, 0x00,0x00,0x60,0xF0,
- 0x00,0x00,0x90,0x00, 0x00,0x00,0x90,0x30, 0x00,0x00,0x90,0x60, 0x00,0x00,0x90,0x90, 0x00,0x00,0x90,0xC0, 0x00,0x00,0x90,0xF0,
- 0x00,0x00,0xB0,0x00, 0x00,0x00,0xB0,0x30, 0x00,0x00,0xB0,0x60, 0x00,0x00,0xB0,0x90, 0x00,0x00,0xB0,0xC0, 0x00,0x00,0xB0,0xF0,
- 0x00,0x00,0xD0,0x00, 0x00,0x00,0xD0,0x30, 0x00,0x00,0xD0,0x60, 0x00,0x00,0xD0,0x90, 0x00,0x00,0xD0,0xC0, 0x00,0x00,0xD0,0xF0,
- 0x00,0x00,0xF0,0x00, 0x00,0x00,0xF0,0x30, 0x00,0x00,0xF0,0x60, 0x00,0x00,0xF0,0x90, 0x00,0x00,0xF0,0xC0, 0x00,0x00,0xF0,0xF0,
- 0x00,0x50,0x00,0x00, 0x00,0x50,0x00,0x30, 0x00,0x50,0x00,0x60, 0x00,0x50,0x00,0x90, 0x00,0x50,0x00,0xC0, 0x00,0x50,0x00,0xF0,
- 0x00,0x50,0x20,0x00, 0x00,0x50,0x20,0x30, 0x00,0x50,0x20,0x60, 0x00,0x50,0x20,0x90, 0x00,0x50,0x20,0xC0, 0x00,0x50,0x20,0xF0,
- 0x00,0x50,0x40,0x00, 0x00,0x50,0x40,0x30, 0x00,0x50,0x40,0x60, 0x00,0x50,0x40,0x90, 0x00,0x50,0x40,0xC0, 0x00,0x50,0x40,0xF0,
- 0x00,0x50,0x60,0x00, 0x00,0x50,0x60,0x30, 0x00,0x50,0x60,0x60, 0x00,0x50,0x60,0x90, 0x00,0x50,0x60,0xC0, 0x00,0x50,0x60,0xF0,
- 0x00,0x50,0x90,0x00, 0x00,0x50,0x90,0x30, 0x00,0x50,0x90,0x60, 0x00,0x50,0x90,0x90, 0x00,0x50,0x90,0xC0, 0x00,0x50,0x90,0xF0,
- 0x00,0x50,0xB0,0x00, 0x00,0x50,0xB0,0x30, 0x00,0x50,0xB0,0x60, 0x00,0x50,0xB0,0x90, 0x00,0x50,0xB0,0xC0, 0x00,0x50,0xB0,0xF0,
- 0x00,0x50,0xD0,0x00, 0x00,0x50,0xD0,0x30, 0x00,0x50,0xD0,0x60, 0x00,0x50,0xD0,0x90, 0x00,0x50,0xD0,0xC0, 0x00,0x50,0xD0,0xF0,
- 0x00,0x50,0xF0,0x00, 0x00,0x50,0xF0,0x30, 0x00,0x50,0xF0,0x60, 0x00,0x50,0xF0,0x90, 0x00,0x50,0xF0,0xC0, 0x00,0x50,0xF0,0xF0,
- 0x00,0xA0,0x00,0x00, 0x00,0xA0,0x00,0x30, 0x00,0xA0,0x00,0x60, 0x00,0xA0,0x00,0x90, 0x00,0xA0,0x00,0xC0, 0x00,0xA0,0x00,0xF0,
- 0x00,0xA0,0x20,0x00, 0x00,0xA0,0x20,0x30, 0x00,0xA0,0x20,0x60, 0x00,0xA0,0x20,0x90, 0x00,0xA0,0x20,0xC0, 0x00,0xA0,0x20,0xF0,
- 0x00,0xA0,0x40,0x00, 0x00,0xA0,0x40,0x30, 0x00,0xA0,0x40,0x60, 0x00,0xA0,0x40,0x90, 0x00,0xA0,0x40,0xC0, 0x00,0xA0,0x40,0xF0,
- 0x00,0xA0,0x60,0x00, 0x00,0xA0,0x60,0x30, 0x00,0xA0,0x60,0x60, 0x00,0xA0,0x60,0x90, 0x00,0xA0,0x60,0xC0, 0x00,0xA0,0x60,0xF0,
- 0x00,0xA0,0x90,0x00, 0x00,0xA0,0x90,0x30, 0x00,0xA0,0x90,0x60, 0x00,0xA0,0x90,0x90, 0x00,0xA0,0x90,0xC0, 0x00,0xA0,0x90,0xF0,
- 0x00,0xA0,0xB0,0x00, 0x00,0xA0,0xB0,0x30, 0x00,0xA0,0xB0,0x60, 0x00,0xA0,0xB0,0x90, 0x00,0xA0,0xB0,0xC0, 0x00,0xA0,0xB0,0xF0,
- 0x00,0xA0,0xD0,0x00, 0x00,0xA0,0xD0,0x30, 0x00,0xA0,0xD0,0x60, 0x00,0xA0,0xD0,0x90, 0x00,0xA0,0xD0,0xC0, 0x00,0xA0,0xD0,0xF0,
- 0x00,0xA0,0xF0,0x00, 0x00,0xA0,0xF0,0x30, 0x00,0xA0,0xF0,0x60, 0x00,0xA0,0xF0,0x90, 0x00,0xA0,0xF0,0xC0, 0x00,0xA0,0xF0,0xF0,
- 0x00,0xF0,0x00,0x00, 0x00,0xF0,0x00,0x30, 0x00,0xF0,0x00,0x60, 0x00,0xF0,0x00,0x90, 0x00,0xF0,0x00,0xC0, 0x00,0xF0,0x00,0xF0,
- 0x00,0xF0,0x20,0x00, 0x00,0xF0,0x20,0x30, 0x00,0xF0,0x20,0x60, 0x00,0xF0,0x20,0x90, 0x00,0xF0,0x20,0xC0, 0x00,0xF0,0x20,0xF0,
- 0x00,0xF0,0x40,0x00, 0x00,0xF0,0x40,0x30, 0x00,0xF0,0x40,0x60, 0x00,0xF0,0x40,0x90, 0x00,0xF0,0x40,0xC0, 0x00,0xF0,0x40,0xF0,
- 0x00,0xF0,0x60,0x00, 0x00,0xF0,0x60,0x30, 0x00,0xF0,0x60,0x60, 0x00,0xF0,0x60,0x90, 0x00,0xF0,0x60,0xC0, 0x00,0xF0,0x60,0xF0,
- 0x00,0xF0,0x90,0x00, 0x00,0xF0,0x90,0x30, 0x00,0xF0,0x90,0x60, 0x00,0xF0,0x90,0x90, 0x00,0xF0,0x90,0xC0, 0x00,0xF0,0x90,0xF0,
- 0x00,0xF0,0xB0,0x00, 0x00,0xF0,0xB0,0x30, 0x00,0xF0,0xB0,0x60, 0x00,0xF0,0xB0,0x90, 0x00,0xF0,0xB0,0xC0, 0x00,0xF0,0xB0,0xF0,
- 0x00,0xF0,0xD0,0x00, 0x00,0xF0,0xD0,0x30, 0x00,0xF0,0xD0,0x60, 0x00,0xF0,0xD0,0x90, 0x00,0xF0,0xD0,0xC0, 0x00,0xF0,0xD0,0xF0,
- 0x00,0xF0,0xF0,0x00, 0x00,0xF0,0xF0,0x30, 0x00,0xF0,0xF0,0x60, 0x00,0xF0,0xF0,0x90, 0x00,0xF0,0xF0,0xC0, 0x00,0xF0,0xF0,0xF0,
- 0x00,0x10,0x10,0x10, 0x00,0x20,0x20,0x20, 0x00,0x30,0x30,0x30, 0x00,0x40,0x40,0x40, 0x00,0x50,0x50,0x50, 0x00,0x60,0x60,0x60,
- 0x00,0x70,0x70,0x70, 0x00,0x80,0x80,0x80, 0x00,0x90,0x90,0x90, 0x00,0xA0,0xA0,0xA0, 0x00,0xB0,0xB0,0xB0, 0x00,0xC0,0xC0,0xC0,
- 0x00,0xD0,0xD0,0xD0, 0x00,0xE0,0xE0,0xE0
-};
-
-
-float adat_gamma = 1.0;
-float adat_distort = 1.0;
-
-/*
- *
- * New version:
- *
- * 32 brighntesses Y 15 with direct access (black and white are specials)
- * 16 colors H ue
- * 7 intensities S aturation
- *
- * Total 3584 'different' colors. First 512 colors free.
- *
- *
- */
-
-void imb_convhamx(struct ImBuf *ibuf, unsigned char *coltab, short *deltab)
-{
- short r,g,b,lr,lg,lb,dr,dg,db,col,fout,type,step;
- int i;
- uchar *rect;
-
- /*
- b = 0000 xxxx
- g = 0001 xxxx
- r = 0010 xxxx
- cmap >= 48
- */
-
- for (step = 0 ; step < 2 ; step ++){
- rect = (uchar *) ibuf->rect;
- rect += 4*step;
- i = ((ibuf->x * ibuf->y) + 2 - step - 1) / 2;
-
- lb = coltab[1];
- lg = coltab[2];
- lr = coltab[3];
- type = col = 0;
-
- for ( ;i>0;i--){
- b = rect[2] >> 4;
- g = rect[1] >> 4;
- r = rect[0] >> 4;
-
- if ((b-lb) | (g-lg) | (r-lr)){
- col = ((b<<8) + (g<<4) + r) << 1;
- fout = deltab[col + 1];
- col = deltab[col];
- type = 0;
- dr = quadr[lr-r] ;
- dg = quadr[lg-g] ;
- db = quadr[lb-b];
-
- if ((dr+dg)<=fout) {
- fout = dr+dg ;
- type = 1;
- }
- if ((dg+db)<=fout) {
- fout = dg+db;
- type = 2;
- }
- if ((dr+db)<=fout) {
- fout = dr+db;
- type = 4;
- }
-
- switch(type){
- case 1:
- lb = b ;
- col = b;
- break;
- case 4:
- lg = g ;
- col = g+16;
- break;
- case 2:
- lr = r ;
- col = r + 32;
- break;
- default:
- /*printf("%04x %5d %5d ", (b<<8) + (g<<4) + r, col, fout);*/
-
- lb = coltab[col*4 + 1];
- lg = coltab[col*4 + 2];
- lr = coltab[col*4 + 3];
- /*printf("%01x%01x%01x %01x%01x%01x\n", b, g, r, lb, lg, lr);*/
- col += 48;
- }
- }
- rect[3] = col;
- rect += 8;
- }
- }
-}
-
-static short dec_hamx(struct ImBuf * ibuf, unsigned char *body, int cmap[])
-{
- int todo,i;
- int j,step,col;
- unsigned int *rect;
-
- for (step = 0 ; step < 2 ; step ++){
- rect = ibuf->rect;
- rect += step;
- todo = (ibuf->x * ibuf->y + 2 - step - 1) / 2;
- col = cmap[0];
- while (todo>0){
- i = *body++;
-
- if (i & 128){ /* fill */
-
- i = 257-i;
- todo -= i;
- j = *(body++);
-
- col = ((col & hamx_array[j]) | hamx_array[j + 256]);
-
- do{
- *rect = col;
- rect += 2;
- }while (--i);
- } else{ /* copy */
- i++;
- todo-=i;
-
- do{
- j = *(body++);
- *rect = col = ((col & hamx_array[j]) | hamx_array[j + 256]);
- rect += 2;
- }while (--i);
- }
- }
- if (todo) return (0);
- }
- return(1);
-}
-
-
-struct ImBuf *imb_loadanim(int *iffmem, int flags)
-{
- int chunk, totlen, len, *mem, cmaplen = 0;
- unsigned int *cmap = NULL;
- uchar *body = 0;
- struct Adat adat;
- struct ImBuf *ibuf=0;
- static int is_flipped = FALSE;
-
- mem=iffmem;
- if (GET_ID(mem) != FORM) return (0);
- if (GET_ID(mem + 2) != ANIM) return (0);
- totlen= (GET_BIG_LONG(mem + 1) + 1) & ~1;
- mem += 3;
- totlen -= 4;
- adat.w = 0;
- adat.xorig = 0;
- adat.yorig = 0;
- adat.gamma = adat_gamma;
- adat.distort = adat_distort;
-
- while(totlen > 0){
- chunk = GET_ID(mem);
- len = (GET_BIG_LONG(mem + 1) + 1) & ~1;
- mem += 2;
-
- totlen -= len+8;
- switch (chunk){
- case ADAT:
- if (len > sizeof(struct Adat)){
- memcpy(&adat,mem,sizeof(struct Adat));
- } else{
- memcpy(&adat,mem,len);
- }
- adat.w = BIG_SHORT(adat.w);
- adat.h = BIG_SHORT(adat.h);
- adat.type = BIG_SHORT(adat.type);
- adat.xorig = BIG_SHORT(adat.xorig);
- adat.yorig = BIG_SHORT(adat.yorig);
- break;
- case CMAP:
- cmap = (unsigned int *) mem;
- cmaplen = len;
- break;
- case BODY:
- body = (uchar *) mem;
- break;
- }
- mem = (int *)((uchar *)mem +len);
- }
-
- if (body == 0) return (0);
- if (adat.w == 0) return (0);
-
- adat_gamma = adat.gamma;
- adat_distort = adat.distort;
-
- if (flags & IB_test) ibuf=IMB_allocImBuf(adat.w, adat.h, 24, 0, 0);
- else ibuf=IMB_allocImBuf(adat.w, adat.h, 24, IB_rect, 0);
- if (ibuf==0) return (0);
-
- ibuf->ftype = (Anim | adat.type);
- ibuf->profile = IB_PROFILE_SRGB;
- ibuf->xorig = adat.xorig;
- ibuf->yorig = adat.yorig;
- ibuf->flags = flags;
-
- if (cmaplen){
- ibuf->cmap = malloc(cmaplen);
- memcpy(ibuf->cmap, cmap, cmaplen);
- ibuf->maxcol = cmaplen >> 2;
- }
-
- if (flags & IB_test){
- if (flags & IB_freem) free(iffmem);
- return(ibuf);
- }
-
- switch (adat.type){
- case HAMX:
- if (flags & IB_rect){
- if (!is_flipped) {
- int i;
- unsigned int * t;
- t = (unsigned int *) hamx_array_char;
- for (i = 0; i < sizeof(hamx_array_char) / sizeof(int) ; i++) {
- t[i] = SWAP_LONG(t[i]);
- }
-
- t = (unsigned int *) cmap_hamx;
-
- for (i = 0; i < sizeof(cmap_hamx) / sizeof(int) ; i++) {
- t[i] = SWAP_LONG(t[i]);
- }
-
- is_flipped= TRUE;
- }
-
- if (dec_hamx(ibuf,body,(int*) cmap_hamx) == 0){
- IMB_freeImBuf(ibuf);
- ibuf = 0;
- }
- if (flags & IB_ttob) IMB_flipy(ibuf);
- }
- break;
- default:
- IMB_freeImBuf(ibuf);
- ibuf = 0;
- }
-
- if (flags & IB_freem) free(iffmem);
-
- return (ibuf);
-}
-
-
-static unsigned char *makebody_anim(int bytes,
- unsigned char *buf,
- unsigned char *rect)
-{
- register uchar last,this;
- register int copy;
- register uchar *rectstart,*temp;
-
- bytes--;
- rectstart = rect;
- last = *rect++;
- this = *rect++;
- copy = last^this;
- while (bytes>0){
- if (copy){
- do{
- last = this;
- this = *rect++;
- if (last == this){
- if (this == rect[-3]){ /* three the same? */
- bytes --; /* init bytes */
- break;
- }
- }
- }while (--bytes != 0);
-
- copy = rect-rectstart;
- copy --;
- if (bytes) copy -= 2;
-
- temp = rect;
- rect = rectstart;
-
- while (copy){
- last = copy;
- if (copy>MAXDAT) last = MAXDAT;
- copy -= last;
- *buf++ = last-1;
- do{
- *buf++ = *rect++;
- }while(--last != 0);
- }
- rectstart = rect;
- rect = temp;
- last = this;
-
- copy = FALSE;
- } else {
- while (*rect++ == this){ /* seek first different byte */
- if (--bytes == 0) break; /* or end of line */
- }
- rect --;
- copy = rect-rectstart;
- rectstart = rect;
- bytes --;
- this = *rect++;
-
- while (copy){
- if (copy>MAXRUN){
- *buf++ = -(MAXRUN-1);
- *buf++ = last;
- copy -= MAXRUN;
- } else {
- *buf++ = -(copy-1);
- *buf++ = last;
- break;
- }
- }
- copy=TRUE;
- }
- }
- return (buf);
-}
-
-
-short imb_enc_anim(struct ImBuf *ibuf, int file)
-{
- int step, size, i, skip, steps = 0;
- uchar *buf1, *crect, *_buf1, *_buf2, *bufend;
- short ok = TRUE;
-
- if (ibuf == 0) return (0);
- if (file < 0 ) return (0);
- if (ibuf->rect == 0) return(0);
-
- /* add dither */
-
- switch(ibuf->ftype){
- case AN_hamx:
- ibuf->cmap = (unsigned int *) cmap_hamx;
- ibuf->mincol = 0;
- ibuf->maxcol = sizeof(cmap_hamx) / 4;
- imb_converttoham(ibuf);
- steps = 2;
- break;
- }
- if (steps == 0) return 0;
-
- size = ((ibuf->x + 1)* (ibuf->y + 1)) / steps + 1024;
- if ((_buf1 = malloc(size)) == 0) return(0);
- if ((_buf2 = malloc(size)) == 0){
- free(_buf1);
- return(0);
- }
-
- skip = 4 * steps;
- for (step = 0 ; step < steps ; step ++){
- crect = (uchar *) ibuf->rect;
- crect += 4 * step;
- size = (ibuf->x * ibuf->y + steps - step - 1) / steps;
- buf1 = _buf1;
- if ((ibuf->ftype == AN_hamx) || (ibuf->ftype == AN_yuvx)){
- crect += 3;
- for (i = size ; i>0 ; i--){
- *(buf1 ++) = *crect;
- crect += skip;
- }
- } else{
- for (i = size ; i>0 ; i--){
- *(buf1 ++) = crect[1] + (crect[2] >> 2) + (crect[3] >> 5);
- crect += skip;
- }
- }
- bufend = makebody_anim(size,_buf2,_buf1);
- if (bufend == 0){
- ok = FALSE;
- break;
- }
- size = bufend - _buf2;
- if (write(file, _buf2, size) != size){
- ok = FALSE;
- break;
- }
- }
- free(_buf1);
- free(_buf2);
- return (ok);
-}
diff --git a/source/blender/imbuf/intern/iff.c b/source/blender/imbuf/intern/iff.c
deleted file mode 100644
index 7297d7d6dd1..00000000000
--- a/source/blender/imbuf/intern/iff.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/**
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * iff.c
- *
- * $Id$
- */
-
-#include "BLI_blenlib.h"
-#include "imbuf.h"
-#include "imbuf_patch.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_iff.h"
-#ifdef WIN32
-#include <io.h>
-#include "BLI_winstuff.h"
-#endif
-
-unsigned short imb_start_iff(struct ImBuf *ibuf, int file)
-{
- unsigned int *point, size, *buf;
-
- if ((point=buf=(unsigned int *)malloc(32768))==0) return FALSE;
-
- *point++ = FORM; /* FORMxxxxILBM in buffer */
- *point++ = 0;
-
- if (IS_amiga(ibuf)){
- struct BitMapHeader *bmhd;
-
- *point++ = ILBM;
- *point++ = CAMG;
- *point++ = 4;
- *point++ = (ibuf->ftype & 0xffff);
-
- *point++=BMHD;
- *point++=sizeof(struct BitMapHeader);
-
- bmhd=(struct BitMapHeader *)point; /* bmhd points to location where bmhd will be */
- point=(unsigned int *)((char *)point+sizeof(struct BitMapHeader)); /* advance pointer already */
-
- bmhd->w=ibuf->x;
- bmhd->h=ibuf->y;
- bmhd->pageWidth=ibuf->x;
- bmhd->pageHeight=ibuf->y;
- bmhd->x=0;
- bmhd->y=0;
- bmhd->nPlanes=ibuf->depth;
- bmhd->masking=0;
- if (ibuf->flags & IB_vert){
- bmhd->compression=2;
- }
- else{
- bmhd->compression=1;
- }
- bmhd->pad1=0;
- bmhd->transparentColor=0;
- bmhd->xAspect=1;
- bmhd->yAspect=1;
- } else if (IS_anim(ibuf)){
- struct Adat *adat;
- extern float adat_gamma;
- extern float adat_distort;
-
- *point++ = ANIM;
- *point++ = ADAT;
- *point++ = BIG_LONG(sizeof(struct Adat));
-
- adat = (struct Adat *)point;
- point = (unsigned int *)((char *)point+sizeof(struct Adat)); /* advance pointer already */
-
- adat->w = BIG_SHORT(ibuf->x);
- adat->h = BIG_SHORT(ibuf->y);
-
- adat->type = BIG_SHORT(ibuf->ftype);
- adat->xorig = BIG_SHORT(ibuf->xorig);
- adat->yorig = BIG_SHORT(ibuf->yorig);
- adat->pad = 0;
- adat->gamma = adat_gamma;
- adat->distort = adat_distort;
- }
-
- size=((uchar *)point-(uchar *)buf);
- if (write(file,buf,size)!=size){
- free(buf);
- return (FALSE);
- }
-
- if (ibuf->cmap){
- if (IS_anim(ibuf)){
- size = ibuf->maxcol * sizeof(int);
- buf[0] = CMAP;
- buf[1] = BIG_LONG(size);
- if (write(file,buf,8) != 8){
- free(buf);
- return (FALSE);
- }
- if (write(file,ibuf->cmap,size) != size){
- free(buf);
- return (FALSE);
- }
- } else{
- uchar *cpoint,*cols;
- unsigned int i,bits;
-
- point = buf;
- if (IS_amiga(ibuf)){
- *(point++) = CMAP;
- *(point++) = BIG_LONG(3*ibuf->maxcol);
- }
-
- cpoint = (uchar *) point;
- cols = (uchar *)ibuf->cmap;
- if ((ibuf->cbits > 0) && (ibuf->cbits < 8)){
- bits = ~((1 << (8-ibuf->cbits)) - 1);
- } else bits = -1;
-
- if (IS_ham(ibuf)) bits = -1;
-
- for (i=0 ; i<ibuf->maxcol ; i++){
- *(cpoint++) = cols[0] & bits;
- *(cpoint++) = cols[1] & bits;
- *(cpoint++) = cols[2] & bits;
- cols += 4;
- }
- if (ibuf->maxcol & 1) *(cpoint++)=0;
-
- size=(cpoint-(uchar *)buf);
- if (write(file,buf,size)!=size){
- free(buf);
- return (FALSE);
- }
- }
- }
-
- if (IS_amiga(ibuf)) buf[0] = BODY;
- if (IS_anim(ibuf)) buf[0] = BODY;
- buf[1]=0;
-
- if (write(file,buf,8)!=8){
- free(buf);
- return(FALSE);
- }
-
- free(buf);
- return (TRUE);
-}
-
-
-unsigned short imb_update_iff(int file, int code)
-{
- int buf[2], filelen, skip;
- uchar nop;
-
- if (file<=0) return (FALSE);
-
- filelen = BLI_filesize(file)-8; /* calc filelength */
-
- lseek(file,0L,2); /* seek end */
-
- if (filelen & 1){ /* make length 'even' */
- switch(code){
- case BODY:
- nop = IFFNOP;
- break;
- }
- if (write(file,&nop,1)!=1) return (FALSE);
- filelen++;
- }
- lseek(file,4L,0);
-
- buf[0] = BIG_LONG(filelen);
-
- if (write(file, buf, 4) != 4) return (FALSE);
- if (code == 0) return (TRUE);
-
- filelen-=4;
- if(lseek(file,4L,1) == -1) return (FALSE);
-
- while (filelen>0){ /* seek BODY */
- if(read(file, buf, 8) != 8) return (FALSE);
- filelen -= 8;
- if (buf[0] == code) break;
-
- skip = (BIG_LONG(buf[1]) + 1) & ~1;
- filelen -= skip;
- if(lseek(file, skip, 1) == -1) return (FALSE);
- }
- if (filelen <= 0) {
- printf("update_iff: couldn't find chunk\n");
- return (FALSE);
- }
-
- lseek(file, -4L, 1);
-
- buf[0] = BIG_LONG(filelen);
-
- if (write(file, buf, 4)!=4) return (FALSE);
-
- return (TRUE);
-}
diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c
index e52cab0bdd3..8fa76fa4502 100644
--- a/source/blender/imbuf/intern/imageprocess.c
+++ b/source/blender/imbuf/intern/imageprocess.c
@@ -37,6 +37,8 @@
* $Id$
*/
+#include <stdlib.h>
+
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "math.h"
@@ -127,7 +129,7 @@ void bicubic_interpolation_color(struct ImBuf *in, unsigned char *outI, float *o
unsigned char *dataI;
float a,b,w,wx,wy[4], outR,outG,outB,outA,*dataF;
- /* ImBuf in must have a valid rect or rect_float, assume this is alredy checked */
+ /* ImBuf in must have a valid rect or rect_float, assume this is already checked */
i= (int)floor(u);
j= (int)floor(v);
@@ -243,7 +245,7 @@ void bilinear_interpolation_color(struct ImBuf *in, unsigned char *outI, float *
int y1, y2, x1, x2;
- /* ImBuf in must have a valid rect or rect_float, assume this is alredy checked */
+ /* ImBuf in must have a valid rect or rect_float, assume this is already checked */
x1= (int)floor(u);
x2= (int)ceil(u);
@@ -317,7 +319,7 @@ void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *outI, fl
int y1, y2, x1, x2;
- /* ImBuf in must have a valid rect or rect_float, assume this is alredy checked */
+ /* ImBuf in must have a valid rect or rect_float, assume this is already checked */
x1= (int)floor(u);
x2= (int)ceil(u);
@@ -391,7 +393,7 @@ void neareast_interpolation_color(struct ImBuf *in, unsigned char *outI, float *
unsigned char *dataI;
int y1, x1;
- /* ImBuf in must have a valid rect or rect_float, assume this is alredy checked */
+ /* ImBuf in must have a valid rect or rect_float, assume this is already checked */
x1= (int)(u);
y1= (int)(v);
diff --git a/source/blender/imbuf/intern/imbuf.h b/source/blender/imbuf/intern/imbuf.h
index aba4784d7d7..1e2f3ec461a 100644
--- a/source/blender/imbuf/intern/imbuf.h
+++ b/source/blender/imbuf/intern/imbuf.h
@@ -72,97 +72,10 @@
#define BIG_LONG SWAP_LONG
#endif
-#define malloc(x) MEM_mallocN(x, __FILE__)
-#define free(x) MEM_freeN(x)
-#define calloc(x,y) MEM_callocN((x)*(y), __FILE__)
-#define freelist(x) BLI_freelistN(x)
+typedef unsigned char uchar;
-#ifdef SHLIB
-void *(*ib_calloc)();
-#define calloc(x,y) ib_calloc((x),(y))
-void *(*ib_malloc)();
-#define malloc(x) ib_malloc(x)
-void (*ib_free)();
-#define free(x) ib_free(x)
-void (*ib_memcpy)();
-#define memcpy(x,y,z) ib_memcpy((x),(y),(z))
-int (*ib_abs)();
-#define abs(x) ib_abs(x)
-void (*ib_fprin_tf)();
-#define fprintf ib_fprin_tf
-int (*ib_sprin_tf)();
-#define sprintf ib_sprin_tf
-void (*ib_prin_tf)();
-#define printf ib_prin_tf
-int (*ib_lseek)();
-#define lseek(x,y,z) ib_lseek((x),(y),(z))
-void *(*ib_mmap)();
-#define mmap(u,v,w,x,y,z) ib_mmap((u),(v),(w),(x),(y),(z))
-int (*ib_munmap)();
-#define munmap(x,y) ib_munmap((x),(y))
-int (*ib_open)();
-#define open(x,y) ib_open((x),(y))
-void (*ib_close)();
-#define close(x) ib_close(x)
-int (*ib_write)();
-#define write(x,y,z) ib_write((x),(y),(z))
-int (*ib_read)();
-#define read(x,y,z) ib_read((x),(y),(z))
-int (*ib_fchmod)();
-#define fchmod(x,y) ib_fchmod((x),(y))
-int (*ib_remove)();
-#define remove(x) ib_remove(x)
-size_t (*ib_strlen)();
-#define strlen(x) ib_strlen(x)
-int (*ib_isdigit)();
-#define isdigit(x) ib_isdigit(x)
-char *(*ib_strcpy)();
-#define strcpy(x,y) ib_strcpy((x),(y))
-int (*ib_atoi)();
-#define atoi(x) ib_atoi(x)
-char *(*ib_strcat)();
-#define strcat(x,y) ib_strcat((x),(y))
-int (*ib_stat)();
-/* #define stat(x,y) ib_stat((x),(y)) */
-FILE *ib_iob;
-#define _iob ib_iob
-
-#else
-
-#define ib_stat stat
-
-#endif /* SHLIB */
-
-
-#define WIDTHB(x) (((x+15)>>4)<<1)
-
-extern unsigned short *quadr;
-extern float dyuvrgb[4][4];
-extern float rgbdyuv[4][4];
-
-
-typedef struct Adat
-{
- unsigned short w, h;
- unsigned short type;
- unsigned short xorig, yorig;
- unsigned short pad;
- float gamma;
- float distort;
-}Adat;
-
-struct BitMapHeader
-{
- unsigned short w, h; /* in pixels */
- unsigned short x, y;
- char nPlanes;
- char masking;
- char compression;
- char pad1;
- unsigned short transparentColor;
- char xAspect, yAspect;
- short pageWidth, pageHeight;
-};
+#define TRUE 1
+#define FALSE 0
#endif /* IMBUF_H */
diff --git a/source/blender/imbuf/intern/imbuf_cocoa.m b/source/blender/imbuf/intern/imbuf_cocoa.m
index 44ce8e061ce..02c90c5bd09 100644
--- a/source/blender/imbuf/intern/imbuf_cocoa.m
+++ b/source/blender/imbuf/intern/imbuf_cocoa.m
@@ -34,7 +34,6 @@
#import <Cocoa/Cocoa.h>
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_cocoa.h"
@@ -185,6 +184,9 @@ struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags)
if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
+ ibuf->ftype = TIF;
+ ibuf->profile = IB_PROFILE_SRGB;
+
/* return successfully */
return (ibuf);
}
diff --git a/source/blender/imbuf/intern/imbuf_patch.h b/source/blender/imbuf/intern/imbuf_patch.h
deleted file mode 100644
index 2c8d9efbfbd..00000000000
--- a/source/blender/imbuf/intern/imbuf_patch.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * imbuf_patch.h
- *
- * These are some definitions to make imbuf more independent from the
- * rest of the blender code. Most of these are dirty and should not
- * really exist.
- *
- * $Id$ *
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef IMBUF_PATCH_H
-#define IMBUF_PATCH_H
-
-/* most of imbuf uses this aloc, and it will disappear soon
- * (hopefully) (25-10-2001 nzc) */
-#include "MEM_guardedalloc.h"
-
-struct ImBuf;
-
-/* originally, these were defines ... */
-typedef unsigned char uchar;
-
-/* should not be used at all */
-#define TRUE 1
-#define FALSE 0
-
-/* Endianness: flip the byte order. It's strange that this is needed..
- * After all, there is an internal endian.{c,h}... */
-#if defined(__sgi) || defined (__sparc) || defined(__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__hppa__) || defined (__BIG_ENDIAN__)
-#define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
-#else
-#define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
-#endif
-
-/* These defines loop back to the internal Blender memory management
- * system, implemented in blenlib. */
-#define NEW(x) (x*)MEM_mallocN(sizeof(x),# x)
-#define mallocstruct(x,y) (x*)malloc((y)* sizeof(x))
-#define callocstruct(x,y) (x*)calloc((y), sizeof(x))
-
-/* These vars are used thoughout the image buffer for conversions. */
-extern float rgbyuv[4][4];
-extern float yuvrgb[4][4];
-extern float rgbbeta[4][4];
-
-/* This one helps debugging. */
-extern int IB_verbose;
-
-/* These ID's are used for checking memory blocks. See blenlib for
- * more details. This set is only used in the imbuf internally. */
-
-#define CAT MAKE_ID('C','A','T',' ')
-#define FORM MAKE_ID('F','O','R','M')
-#define ILBM MAKE_ID('I','L','B','M')
-#define BMHD MAKE_ID('B','M','H','D')
-#define CMAP MAKE_ID('C','M','A','P')
-#define CAMG MAKE_ID('C','A','M','G')
-#define BODY MAKE_ID('B','O','D','Y')
-
-#define ANIM MAKE_ID('A','N','I','M')
-#define ADAT MAKE_ID('A','D','A','T')
-#define CODE MAKE_ID('C','O','D','E')
-#define ANHD MAKE_ID('A','N','H','D')
-#define DLTA MAKE_ID('D','L','T','A')
-#define BLCK MAKE_ID('B','L','C','K')
-
-#define MAXRUN 126
-#define MAXDAT 126
-#define IFFNOP 128
-
-#define camg ftype
-
-#define LI_rect IB_rect
-#define LI_planes IB_planes
-#define LI_kcmap IB_cmap
-#define LI_cmap IB_cmap
-#define LI_freem IB_freem
-#define LI_test IB_test
-
-#define SI_rect IB_rect
-#define SI_planes IB_planes
-#define SI_kcmap IB_cmap
-#define SI_cmap IB_cmap
-#define SI_vert IB_vert
-
-#endif
-
diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c
index 01232786070..c676c401ccd 100644
--- a/source/blender/imbuf/intern/iris.c
+++ b/source/blender/imbuf/intern/iris.c
@@ -30,13 +30,15 @@
*/
#include <string.h>
+
#include "BLI_blenlib.h"
+#include "MEM_guardedalloc.h"
+
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_iris.h"
+#include "IMB_filetype.h"
typedef struct {
unsigned short imagic; /* stuff saved on disk . . */
@@ -224,6 +226,16 @@ static void test_endian_zbuf(struct ImBuf *ibuf)
}
}
+/* from misc_util: flip the bytes from x */
+#define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1])
+
+/* this one is only def-ed once, strangely... */
+#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
+
+int imb_is_a_iris(unsigned char *mem)
+{
+ return ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC));
+}
/*
* longimagedata -
@@ -232,7 +244,7 @@ static void test_endian_zbuf(struct ImBuf *ibuf)
*
*/
-struct ImBuf *imb_loadiris(unsigned char *mem, int flags)
+struct ImBuf *imb_loadiris(unsigned char *mem, int size, int flags)
{
unsigned int *base, *lptr = NULL;
float *fbase, *fptr = NULL;
@@ -245,7 +257,9 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags)
int xsize, ysize, zsize;
int bpp, rle, cur, badorder;
ImBuf * ibuf;
-
+
+ if(!imb_is_a_iris(mem)) return NULL;
+
/*printf("new iris\n");*/
file_data = mem;
@@ -277,8 +291,8 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags)
if (rle) {
tablen = ysize*zsize*sizeof(int);
- starttab = (unsigned int *)malloc(tablen);
- lengthtab = (unsigned int *)malloc(tablen);
+ starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab");
+ lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris endtab");
file_offset = 512;
readtab(inf,starttab,tablen);
@@ -379,8 +393,8 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags)
}
}
- free(starttab);
- free(lengthtab);
+ MEM_freeN(starttab);
+ MEM_freeN(lengthtab);
} else {
if (bpp == 1) {
@@ -495,7 +509,6 @@ struct ImBuf *imb_loadiris(unsigned char *mem, int flags)
ibuf->ftype = IMAGIC;
ibuf->profile = IB_PROFILE_SRGB;
- if (flags & IB_ttob) IMB_flipy(ibuf);
test_endian_zbuf(ibuf);
@@ -661,12 +674,12 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, char
tablen = ysize*zsize*sizeof(int);
- image = (IMAGE *)malloc(sizeof(IMAGE));
- starttab = (unsigned int *)malloc(tablen);
- lengthtab = (unsigned int *)malloc(tablen);
+ image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image");
+ starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab");
+ lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris lengthtab");
rlebuflen = 1.05*xsize+10;
- rlebuf = (unsigned char *)malloc(rlebuflen);
- lumbuf = (unsigned int *)malloc(xsize*sizeof(int));
+ rlebuf = (unsigned char *)MEM_mallocN(rlebuflen, "iris rlebuf");
+ lumbuf = (unsigned int *)MEM_mallocN(xsize*sizeof(int), "iris lumbuf");
memset(image, 0, sizeof(IMAGE));
image->imagic = IMAGIC;
@@ -715,11 +728,11 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, char
fseek(outf,512,SEEK_SET);
goodwrite *= writetab(outf,starttab,tablen);
goodwrite *= writetab(outf,lengthtab,tablen);
- free(image);
- free(starttab);
- free(lengthtab);
- free(rlebuf);
- free(lumbuf);
+ MEM_freeN(image);
+ MEM_freeN(starttab);
+ MEM_freeN(lengthtab);
+ MEM_freeN(rlebuf);
+ MEM_freeN(lumbuf);
fclose(outf);
if(goodwrite)
return 1;
@@ -799,7 +812,7 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn
return optr - (unsigned char *)rlebuf;
}
-short imb_saveiris(struct ImBuf * ibuf, char *name, int flags)
+int imb_saveiris(struct ImBuf * ibuf, char *name, int flags)
{
short zsize;
int ret;
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
index b2ed8b87d0f..558eaedf8b2 100644
--- a/source/blender/imbuf/intern/jp2.c
+++ b/source/blender/imbuf/intern/jp2.c
@@ -23,15 +23,17 @@
#ifdef WITH_OPENJPEG
+#include "MEM_guardedalloc.h"
+
#include "BLI_blenlib.h"
+#include "BLI_math.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_jp2.h"
+#include "IMB_filetype.h"
#include "openjpeg.h"
@@ -58,7 +60,7 @@ static int checkj2p(unsigned char *mem) /* J2K_CFMT */
return memcmp(JP2_HEAD, mem, 12) ? 0 : 1;
}
-int imb_is_a_jp2(void *buf)
+int imb_is_a_jp2(unsigned char *buf)
{
return checkj2p(buf);
}
@@ -92,8 +94,6 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
{
struct ImBuf *ibuf = 0;
int use_float = 0; /* for precision higher then 8 use float */
- unsigned char *rect= NULL;
- float *rect_float= NULL;
long signed_offsets[4] = {0,0,0,0};
int float_divs[4];
@@ -159,7 +159,7 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
return NULL;
}
- w = image->comps[0].w;
+ w = image->comps[0].w;
h = image->comps[0].h;
switch (image->numcomps) {
@@ -189,13 +189,7 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
float_divs[i]= (1<<image->comps[i].prec)-1;
}
- if (use_float) {
- ibuf= IMB_allocImBuf(w, h, depth, IB_rectfloat, 0);
- rect_float = ibuf->rect_float;
- } else {
- ibuf= IMB_allocImBuf(w, h, depth, IB_rect, 0);
- rect = (unsigned char *) ibuf->rect;
- }
+ ibuf= IMB_allocImBuf(w, h, depth, use_float ? IB_rectfloat : IB_rect, 0);
if (ibuf==NULL) {
if(dinfo)
@@ -206,8 +200,8 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
ibuf->ftype = JP2;
if (use_float) {
- rect_float = ibuf->rect_float;
-
+ float *rect_float= ibuf->rect_float;
+
if (image->numcomps < 3) {
/* greyscale 12bits+ */
for (i = 0; i < w * h; i++, rect_float+=4) {
@@ -237,13 +231,14 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
}
} else {
-
+ unsigned char *rect= (unsigned char *)ibuf->rect;
+
if (image->numcomps < 3) {
/* greyscale */
for (i = 0; i < w * h; i++, rect+=4) {
index = w * h - ((i) / (w) + 1) * w + (i) % (w);
- rect_float[0]= rect_float[1]= rect_float[2]= (image->comps[0].data[index] + signed_offsets[0]);
+ rect[0]= rect[1]= rect[2]= (image->comps[0].data[index] + signed_offsets[0]);
if (image->numcomps == 2)
rect[3]= image->comps[1].data[index] + signed_offsets[1];
@@ -294,7 +289,7 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
/*
-2048x1080 (2K) at 24 fps or 48 fps, or 4096x2160 (4K) at 24 fps; 3×12 bits per pixel, XYZ color space
+2048x1080 (2K) at 24 fps or 48 fps, or 4096x2160 (4K) at 24 fps; 3x12 bits per pixel, XYZ color space
* In 2K, for Scope (2.39:1) presentation 2048x858 pixels of the imager is used
* In 2K, for Flat (1.85:1) presentation 1998x1080 pixels of the imager is used
@@ -540,16 +535,23 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
if (rect_float) {
+ float rgb[3];
+
switch (prec) {
case 8: /* Convert blenders float color channels to 8,12 or 16bit ints */
for(y=h-1; y>=0; y--) {
y_row = y*w;
for(x=0; x<w; x++, rect_float+=4) {
i = y_row + x;
+
+ if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ linearrgb_to_srgb_v3_v3(rgb, rect_float);
+ else
+ copy_v3_v3(rgb, rect_float);
- image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[0]);
- image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[1]);
- image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[2]);
+ image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[0]);
+ image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[1]);
+ image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[2]);
if (numcomps>3)
image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
}
@@ -561,10 +563,15 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
y_row = y*w;
for(x=0; x<w; x++, rect_float+=4) {
i = y_row + x;
+
+ if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ linearrgb_to_srgb_v3_v3(rgb, rect_float);
+ else
+ copy_v3_v3(rgb, rect_float);
- image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[0]);
- image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[1]);
- image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[2]);
+ image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[0]);
+ image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[1]);
+ image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[2]);
if (numcomps>3)
image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
}
@@ -575,10 +582,15 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
y_row = y*w;
for(x=0; x<w; x++, rect_float+=4) {
i = y_row + x;
+
+ if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ linearrgb_to_srgb_v3_v3(rgb, rect_float);
+ else
+ copy_v3_v3(rgb, rect_float);
- image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[0]);
- image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[1]);
- image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[2]);
+ image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[0]);
+ image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[1]);
+ image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[2]);
if (numcomps>3)
image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
}
@@ -649,7 +661,7 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
/* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */
-short imb_savejp2(struct ImBuf *ibuf, char *name, int flags) {
+int imb_savejp2(struct ImBuf *ibuf, char *name, int flags) {
int quality = ibuf->ftype & 0xff;
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c
index 127145c967d..2bae7228220 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);
@@ -149,7 +156,10 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
- src->pub.next_input_byte = src->pub.next_input_byte + num_bytes;
+ if(num_bytes > 0) {
+ src->pub.next_input_byte = src->pub.next_input_byte + num_bytes;
+ src->pub.bytes_in_buffer = src->pub.bytes_in_buffer - num_bytes;
+ }
}
@@ -297,11 +307,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 +384,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 +410,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 +459,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 +495,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 +506,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 +534,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 +569,7 @@ next_stamp_info:
}
jpeg_finish_compress(cinfo);
- free(row_pointer[0]);
+ MEM_freeN(row_pointer[0]);
}
@@ -580,7 +588,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){
diff --git a/source/blender/imbuf/intern/matrix.h b/source/blender/imbuf/intern/matrix.h
deleted file mode 100644
index 79b9b2dbc14..00000000000
--- a/source/blender/imbuf/intern/matrix.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * matrix.c
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/* rgbyuv is identiek aan rgbbeta */
-
-float rgbyuv[4][4]={ /* afgeleid uit videoframer = Y Cr Cb in kopieen van Francois*/
- /* is identriek aan matrix van jpeg */
- { .50000, .11400, -.08131, 0.0,}, /* b */
- {-.33126, .58700, -.41869, 0.0,}, /* g */
- {-.16874, .29900, .50000, 0.0,}, /* r */
- { 128.0, 0.0, 128.0, 1.0}};
-
- /* b-y (u) y r-y (v) */
-
-
-float rgbbeta[4][4]={ /* afgeleid uit videoframer = Y Cr Cb in kopieen van Francois*/
- /* is identriek aan matrix van jpeg */
- {.50000, .11400, -.08131, 0.0,}, /* b-y -> b */
- {-.33126, .58700, -.41869, 0.0,}, /* y -> g */
- {-.16874, .29900, .50000, 0.0,}, /* r-y -> r */
- { 128.0, 0.0, 128.0, 1.0}};
-
- /* b-y y r-y */
-
-
-
-float yuvrgb[4][4]={
- {1.77200, -0.34414, 0.0, 0.0, },
- {1.0, 1.0, 1.0, 0.0, },
- {0.0, -0.71414, 1.40200, 0.0, },
- {-226.816, 135.460, -179.456, 1.0}};
-
-float rgb_to_bw[4][4]={
- {.299, .299, .299, 0.0,},
- {.587, .587, .587, 0.0,},
- {.114, .114, .114, 0.0,},
- { 0.5, 0.5, 0.5, 1.0}};
-
-float dyuvrgb_oud[4][4]={
- {1.0 , 1.0 , 1.0, 0.0,},
- {1.733, -0.337, 0.0, 0.0,},
- {0.0, -.698, 1.371, 0.0,},
- {-221.8, 132.47, -175.5, 1.0}};
-
-float dyuvrgb[4][4]={
- {1.164 , 1.164 , 1.164, 0.0,},
- {2.018, -0.391, 0.0, 0.0,},
- {0.0, -0.813, 1.596, 0.0,},
- {-276.7, 135.6, -222.7, 1.0}};
-
-float rgbdyuv[4][4]={
- {0.439, 0.098, -0.071, 0.0,},
- {-0.291, 0.504, -0.368, 0.0,},
- {-0.148, 0.257, 0.439, 0.0,},
- {128.0, 16.0, 128.0, 1.0}};
-
diff --git a/source/blender/imbuf/intern/md5.c b/source/blender/imbuf/intern/md5.c
index a2528fbd93c..19a5f25e7a4 100644
--- a/source/blender/imbuf/intern/md5.c
+++ b/source/blender/imbuf/intern/md5.c
@@ -18,10 +18,6 @@
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>. */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <sys/types.h>
# include <stdlib.h>
diff --git a/source/blender/imbuf/intern/imginfo.c b/source/blender/imbuf/intern/metadata.c
index 4101045b45e..38ffa2fe2fa 100644
--- a/source/blender/imbuf/intern/imginfo.c
+++ b/source/blender/imbuf/intern/metadata.c
@@ -1,5 +1,5 @@
/**
- * $Id$
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -36,22 +36,22 @@
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
-#include "IMB_imginfo.h"
+#include "IMB_metadata.h"
-void IMB_imginfo_free(struct ImBuf* img)
+void IMB_metadata_free(struct ImBuf* img)
{
- ImgInfo *info;
+ ImMetaData *info;
if (!img)
return;
- if (!img->img_info) {
+ if (!img->metadata) {
return;
}
- info = img->img_info;
+ info = img->metadata;
while (info) {
- ImgInfo* next = info->next;
+ ImMetaData* next = info->next;
MEM_freeN(info->key);
MEM_freeN(info->value);
MEM_freeN(info);
@@ -59,17 +59,17 @@ void IMB_imginfo_free(struct ImBuf* img)
}
}
-int IMB_imginfo_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)
{
- ImgInfo *info;
+ ImMetaData *info;
int retval = 0;
if (!img)
return 0;
- if (!img->img_info) {
+ if (!img->metadata) {
return 0;
}
- info = img->img_info;
+ info = img->metadata;
while (info) {
if (strcmp(key, info->key) == 0) {
BLI_strncpy(field, info->value, len);
@@ -81,25 +81,25 @@ int IMB_imginfo_get_field(struct ImBuf* img, const char* key, char* field, int l
return retval;
}
-int IMB_imginfo_add_field(struct ImBuf* img, const char* key, const char* field)
+int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* field)
{
- ImgInfo *info;
- ImgInfo *last;
+ ImMetaData *info;
+ ImMetaData *last;
if (!img)
return 0;
- if (!img->img_info) {
- img->img_info = MEM_callocN(sizeof(ImgInfo), "ImgInfo");
- info = img->img_info;
+ if (!img->metadata) {
+ img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData");
+ info = img->metadata;
} else {
- info = img->img_info;
+ info = img->metadata;
last = info;
while (info) {
last = info;
info = info->next;
}
- info = MEM_callocN(sizeof(ImgInfo), "ImgInfo");
+ info = MEM_callocN(sizeof(ImMetaData), "ImMetaData");
last->next = info;
}
info->key = BLI_strdup(key);
@@ -107,21 +107,21 @@ int IMB_imginfo_add_field(struct ImBuf* img, const char* key, const char* field)
return 1;
}
-int IMB_imginfo_del_field(struct ImBuf *img, const char *key)
+int IMB_metadata_del_field(struct ImBuf *img, const char *key)
{
- ImgInfo *p, *p1;
+ ImMetaData *p, *p1;
- if ((!img) || (!img->img_info))
+ if ((!img) || (!img->metadata))
return (0);
- p = img->img_info;
+ p = img->metadata;
p1 = NULL;
while (p) {
if (!strcmp (key, p->key)) {
if (p1)
p1->next = p->next;
else
- img->img_info = p->next;
+ img->metadata = p->next;
MEM_freeN(p->key);
MEM_freeN(p->value);
@@ -134,17 +134,17 @@ int IMB_imginfo_del_field(struct ImBuf *img, const char *key)
return (0);
}
-int IMB_imginfo_change_field(struct ImBuf *img, const char *key, const char *field)
+int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field)
{
- ImgInfo *p;
+ ImMetaData *p;
if (!img)
return (0);
- if (!img->img_info)
- return (IMB_imginfo_add_field (img, key, field));
+ if (!img->metadata)
+ return (IMB_metadata_add_field (img, key, field));
- p = img->img_info;
+ p = img->metadata;
while (p) {
if (!strcmp (key, p->key)) {
MEM_freeN (p->value);
@@ -154,5 +154,6 @@ int IMB_imginfo_change_field(struct ImBuf *img, const char *key, const char *fie
p = p->next;
}
- return (IMB_imginfo_add_field (img, key, field));
+ return (IMB_metadata_add_field (img, key, field));
}
+
diff --git a/source/blender/imbuf/intern/IMB_ham.h b/source/blender/imbuf/intern/module.c
index d455f9b519a..5438066d164 100644
--- a/source/blender/imbuf/intern/IMB_ham.h
+++ b/source/blender/imbuf/intern/module.c
@@ -1,6 +1,4 @@
/*
- * IMB_ham.h
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -19,27 +17,24 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
+ * Contributor(s): Blender Foundation, 2010.
*
* ***** END GPL LICENSE BLOCK *****
*/
-/**
- * \file IMB_ham.h
- * \ingroup imbuf
- * \brief Function declarations for ham.c
- */
-
-#ifndef IMB_HAM_H
-#define IMB_HAM_H
-struct ImBuf;
+#include "IMB_imbuf.h"
+#include "IMB_filetype.h"
-short imb_converttoham(struct ImBuf *ibuf);
+void IMB_init(void)
+{
+ imb_filetypes_init();
+ imb_tile_cache_init();
+}
-#endif
+void IMB_exit(void)
+{
+ IMB_free_cache_limiter();
+ imb_tile_cache_exit();
+ imb_filetypes_exit();
+}
diff --git a/source/blender/imbuf/intern/openexr/CMakeLists.txt b/source/blender/imbuf/intern/openexr/CMakeLists.txt
index 7dc295a8aae..cfc977ff155 100644
--- a/source/blender/imbuf/intern/openexr/CMakeLists.txt
+++ b/source/blender/imbuf/intern/openexr/CMakeLists.txt
@@ -38,9 +38,8 @@ SET(INC
${OPENEXR_INC}
)
-IF(WITH_OPENEXR)
+IF(WITH_IMAGE_OPENEXR)
ADD_DEFINITIONS(-DWITH_OPENEXR)
-ENDIF(WITH_OPENEXR)
+ENDIF(WITH_IMAGE_OPENEXR)
BLENDERLIB(bf_openexr "${SRC}" "${INC}")
-#env.BlenderLib ('bf_openexr', source_files, incs, defs, libtype=['core','player'], priority = [90, 200])
diff --git a/source/blender/imbuf/intern/openexr/Makefile b/source/blender/imbuf/intern/openexr/Makefile
index 083089b11d5..820b2aeb003 100644
--- a/source/blender/imbuf/intern/openexr/Makefile
+++ b/source/blender/imbuf/intern/openexr/Makefile
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index c9859f8d5bd..9b68e0e45eb 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -46,10 +46,12 @@ _CRTIMP void __cdecl _invalid_parameter_noinfo(void)
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_math_color.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
+#include "IMB_metadata.h"
#include "openexr_multi.h"
}
@@ -177,7 +179,15 @@ static void openexr_header_compression(Header *header, int compression)
}
}
-static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
+static void openexr_header_metadata(Header *header, struct ImBuf *ibuf)
+{
+ ImMetaData* info;
+
+ for(info= ibuf->metadata; info; info= info->next)
+ header->insert(info->key, StringAttribute(info->value));
+}
+
+static int imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
{
int channels = ibuf->channels;
int width = ibuf->x;
@@ -189,6 +199,7 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
Header header (width, height);
openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
+ openexr_header_metadata(&header, ibuf);
header.channels().insert ("R", Channel (HALF));
header.channels().insert ("G", Channel (HALF));
@@ -218,35 +229,69 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
sizeof(float), sizeof(float) * -width));
if(ibuf->rect_float) {
float *from;
-
- for (int i = ibuf->y-1; i >= 0; i--)
- {
- from= ibuf->rect_float + channels*i*width;
-
- for (int j = ibuf->x; j > 0; j--)
+
+ if(ibuf->profile == IB_PROFILE_LINEAR_RGB) {
+ for (int i = ibuf->y-1; i >= 0; i--)
+ {
+ from= ibuf->rect_float + channels*i*width;
+
+ for (int j = ibuf->x; j > 0; j--)
+ {
+ to->r = from[0];
+ to->g = from[1];
+ to->b = from[2];
+ to->a = (channels >= 4)? from[3]: 1.0f;
+ to++; from += 4;
+ }
+ }
+ }
+ else {
+ for (int i = ibuf->y-1; i >= 0; i--)
{
- to->r = from[0];
- to->g = (channels >= 2)? from[1]: from[0];
- to->b = (channels >= 3)? from[2]: from[0];
- to->a = (channels >= 4)? from[3]: from[0];
- to++; from += 4;
+ from= ibuf->rect_float + channels*i*width;
+
+ for (int j = ibuf->x; j > 0; j--)
+ {
+ to->r = srgb_to_linearrgb(from[0]);
+ to->g = srgb_to_linearrgb(from[1]);
+ to->b = srgb_to_linearrgb(from[2]);
+ to->a = (channels >= 4)? from[3]: 1.0f;
+ to++; from += 4;
+ }
}
}
}
else {
unsigned char *from;
-
- for (int i = ibuf->y-1; i >= 0; i--)
- {
- from= (unsigned char *)ibuf->rect + channels*i*width;
-
- for (int j = ibuf->x; j > 0; j--)
+
+ if(ibuf->profile == IB_PROFILE_LINEAR_RGB) {
+ for (int i = ibuf->y-1; i >= 0; i--)
+ {
+ from= (unsigned char *)ibuf->rect + channels*i*width;
+
+ for (int j = ibuf->x; j > 0; j--)
+ {
+ to->r = (float)(from[0])/255.0;
+ to->g = (float)(from[1])/255.0;
+ to->b = (float)(from[2])/255.0;
+ to->a = (float)(channels >= 4) ? from[3]/255.0 : 1.0f;
+ to++; from += 4;
+ }
+ }
+ }
+ else {
+ for (int i = ibuf->y-1; i >= 0; i--)
{
- to->r = (float)(from[0])/255.0;
- to->g = (float)((channels >= 2)? from[1]: from[0])/255.0;
- to->b = (float)((channels >= 3)? from[2]: from[0])/255.0;
- to->a = (float)((channels >= 4)? from[3]: from[0])/255.0;
- to++; from += 4;
+ from= (unsigned char *)ibuf->rect + channels*i*width;
+
+ for (int j = ibuf->x; j > 0; j--)
+ {
+ to->r = srgb_to_linearrgb((float)from[0] / 255.0);
+ to->g = srgb_to_linearrgb((float)from[1] / 255.0);
+ to->b = srgb_to_linearrgb((float)from[2] / 255.0);
+ to->a = channels >= 4 ? (float)from[3]/255.0 : 1.0f;
+ to++; from += 4;
+ }
}
}
}
@@ -269,7 +314,7 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
return (1);
}
-static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
+static int imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
{
int channels = ibuf->channels;
int width = ibuf->x;
@@ -281,6 +326,7 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
Header header (width, height);
openexr_header_compression(&header, ibuf->ftype & OPENEXR_COMPRESS);
+ openexr_header_metadata(&header, ibuf);
header.channels().insert ("R", Channel (FLOAT));
header.channels().insert ("G", Channel (FLOAT));
@@ -297,9 +343,9 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
float *rect[4] = {NULL, NULL, NULL, NULL};
rect[0]= ibuf->rect_float + channels*(height-1)*width;
- rect[1]= (channels >= 2)? rect[0]+1: rect[0];
- rect[2]= (channels >= 3)? rect[0]+2: rect[0];
- rect[3]= (channels >= 4)? rect[0]+3: rect[0];
+ rect[1]= rect[0]+1;
+ rect[2]= rect[0]+2;
+ rect[3]= (channels >= 4)? rect[0]+3:rect[0]; /* red as alpha, is this needed since alpha isnt written? */
frameBuffer.insert ("R", Slice (FLOAT, (char *)rect[0], xstride, ystride));
frameBuffer.insert ("G", Slice (FLOAT, (char *)rect[1], xstride, ystride));
@@ -326,7 +372,7 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
}
-short imb_save_openexr(struct ImBuf *ibuf, char *name, int flags)
+int imb_save_openexr(struct ImBuf *ibuf, char *name, int flags)
{
if (flags & IB_mem)
{
@@ -435,6 +481,7 @@ void IMB_exr_add_channel(void *handle, const char *layname, const char *passname
BLI_addtail(&data->channels, echan);
}
+/* only used for writing temp. render results (not image files) */
void IMB_exr_begin_write(void *handle, char *filename, int width, int height, int compress)
{
ExrHandle *data= (ExrHandle *)handle;
@@ -448,6 +495,7 @@ void IMB_exr_begin_write(void *handle, char *filename, int width, int height, in
header.channels().insert (echan->name, Channel (FLOAT));
openexr_header_compression(&header, compress);
+ // openexr_header_metadata(&header, ibuf); // no imbuf. cant write
/* header.lineOrder() = DECREASING_Y; this crashes in windows for file read! */
header.insert ("BlenderMultiChannel", StringAttribute ("Blender V2.43 and newer"));
@@ -518,12 +566,9 @@ void IMB_exr_set_channel(void *handle, char *layname, char *passname, int xstrid
}
else
BLI_strncpy(name, passname, EXR_TOT_MAXNAME-1);
-
-
- for(echan= (ExrChannel *)data->channels.first; echan; echan= echan->next)
- if(strcmp(echan->name, name)==0)
- break;
-
+
+ echan= (ExrChannel *)BLI_findstring(&data->channels, name, offsetof(ExrChannel, name));
+
if(echan) {
echan->xstride= xstride;
echan->ystride= ystride;
@@ -575,7 +620,12 @@ void IMB_exr_write_channels(void *handle)
echan->xstride*sizeof(float), echan->ystride*sizeof(float)));
data->ofile->setFrameBuffer (frameBuffer);
- data->ofile->writePixels (data->height);
+ try {
+ data->ofile->writePixels (data->height);
+ }
+ catch (const std::exception &exc) {
+ std::cerr << "OpenEXR-writePixels: ERROR: " << exc.what() << std::endl;
+ }
}
else {
printf("Error: attempt to save MultiLayer without layers.\n");
@@ -598,7 +648,13 @@ void IMB_exr_read_channels(void *handle)
}
data->ifile->setFrameBuffer (frameBuffer);
- data->ifile->readPixels (0, data->height-1);
+
+ try {
+ data->ifile->readPixels (0, data->height-1);
+ }
+ catch (const std::exception &exc) {
+ std::cerr << "OpenEXR-readPixels: ERROR: " << exc.what() << std::endl;
+ }
}
void IMB_exr_multilayer_convert(void *handle, void *base,
@@ -700,35 +756,30 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
static ExrLayer *imb_exr_get_layer(ListBase *lb, char *layname)
{
- ExrLayer *lay;
-
- for(lay= (ExrLayer *)lb->first; lay; lay= lay->next) {
- if( strcmp(lay->name, layname)==0 )
- return lay;
+ ExrLayer *lay= (ExrLayer *)BLI_findstring(lb, layname, offsetof(ExrLayer, name));
+
+ if(lay==NULL) {
+ lay= (ExrLayer *)MEM_callocN(sizeof(ExrLayer), "exr layer");
+ BLI_addtail(lb, lay);
+ BLI_strncpy(lay->name, layname, EXR_LAY_MAXNAME);
}
- lay= (ExrLayer *)MEM_callocN(sizeof(ExrLayer), "exr layer");
- BLI_addtail(lb, lay);
- BLI_strncpy(lay->name, layname, EXR_LAY_MAXNAME);
-
+
return lay;
}
static ExrPass *imb_exr_get_pass(ListBase *lb, char *passname)
{
- ExrPass *pass;
+ ExrPass *pass= (ExrPass *)BLI_findstring(lb, passname, offsetof(ExrPass, name));
- for(pass= (ExrPass *)lb->first; pass; pass= pass->next) {
- if( strcmp(pass->name, passname)==0 )
- return pass;
+ if(pass==NULL) {
+ pass= (ExrPass *)MEM_callocN(sizeof(ExrPass), "exr pass");
+
+ if(strcmp(passname, "Combined")==0)
+ BLI_addhead(lb, pass);
+ else
+ BLI_addtail(lb, pass);
}
-
- pass= (ExrPass *)MEM_callocN(sizeof(ExrPass), "exr pass");
- if(strcmp(passname, "Combined")==0)
- BLI_addhead(lb, pass);
- else
- BLI_addtail(lb, pass);
-
BLI_strncpy(pass->name, passname, EXR_LAY_MAXNAME);
return pass;
@@ -880,14 +931,7 @@ static const char *exr_rgba_channelname(InputFile *file, const char *chan)
static int exr_has_zbuffer(InputFile *file)
{
- const ChannelList &channels = file->header().channels();
-
- for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i)
- {
- if(strcmp("Z", i.name())==0)
- return 1;
- }
- return 0;
+ return !(file->header().channels().findChannel("Z") == NULL);
}
static int exr_is_renderresult(InputFile *file)
@@ -984,16 +1028,22 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
file->setFrameBuffer (frameBuffer);
file->readPixels (dw.min.y, dw.max.y);
-
- IMB_rect_from_float(ibuf);
+
+ // XXX, ImBuf has no nice way to deal with this.
+ // ideally IM_rect would be used when the caller wants a rect BUT
+ // at the moment all functions use IM_rect.
+ // Disabling this is ok because all functions should check if a rect exists and create one on demand.
+ //
+ // Disabling this because the sequencer frees immediate.
+ //
+ // if(flag & IM_rect)
+ // IMB_rect_from_float(ibuf);
}
}
}
delete file;
-
return(ibuf);
-
}
catch (const std::exception &exc)
{
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h
index a6892dcbaed..c23b47d1480 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.h
+++ b/source/blender/imbuf/intern/openexr/openexr_api.h
@@ -46,7 +46,7 @@ extern "C" {
int imb_is_a_openexr (unsigned char *mem);
-short imb_save_openexr (struct ImBuf *ibuf, char *name, int flags);
+int imb_save_openexr (struct ImBuf *ibuf, char *name, int flags);
struct ImBuf *imb_load_openexr (unsigned char *mem, int size, int flags);
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index 2dafa043da6..6344b227174 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -31,17 +31,16 @@
#include "png.h"
#include "BLI_blenlib.h"
+#include "MEM_guardedalloc.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_cmap.h"
-#include "IMB_imginfo.h"
-#include "IMB_png.h"
+#include "IMB_metadata.h"
+#include "IMB_filetype.h"
typedef struct PNGReadStruct {
unsigned char *data;
@@ -53,7 +52,7 @@ static void ReadData( png_structp png_ptr, png_bytep data, png_size_t length);
static void WriteData( png_structp png_ptr, png_bytep data, png_size_t length);
static void Flush( png_structp png_ptr);
-int imb_is_a_png(void *mem)
+int imb_is_a_png(unsigned char *mem)
{
int ret_val = 0;
@@ -94,7 +93,7 @@ static void ReadData( png_structp png_ptr, png_bytep data, png_size_t length)
longjmp(png_jmpbuf(png_ptr), 1);
}
-short imb_savepng(struct ImBuf *ibuf, char *name, int flags)
+int imb_savepng(struct ImBuf *ibuf, char *name, int flags)
{
png_structp png_ptr;
png_infop info_ptr;
@@ -105,6 +104,11 @@ short imb_savepng(struct ImBuf *ibuf, char *name, int flags)
int i, bytesperpixel, color_type = PNG_COLOR_TYPE_GRAY;
FILE *fp = 0;
+ /* use the jpeg quality setting for compression */
+ int compression;
+ compression= (int)(((float)(ibuf->ftype & 0xff) / 11.1111f));
+ compression= compression < 0 ? 0 : (compression > 9 ? 9 : compression);
+
bytesperpixel = (ibuf->depth + 7) >> 3;
if ((bytesperpixel > 4) || (bytesperpixel == 2)) {
printf("imb_savepng: unsupported bytes per pixel: %d\n", bytesperpixel);
@@ -203,10 +207,10 @@ short imb_savepng(struct ImBuf *ibuf, char *name, int flags)
PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
PNG_ALL_FILTERS);
-
- png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
*/
+ png_set_compression_level(png_ptr, compression);
+
// png image settings
png_set_IHDR(png_ptr,
info_ptr,
@@ -219,30 +223,30 @@ short imb_savepng(struct ImBuf *ibuf, char *name, int flags)
PNG_FILTER_TYPE_DEFAULT);
/* image text info */
- if (ibuf->img_info) {
- png_text* imginfo;
- ImgInfo* iptr;
+ if (ibuf->metadata) {
+ png_text* metadata;
+ ImMetaData* iptr;
int num_text = 0;
- iptr = ibuf->img_info;
+ iptr = ibuf->metadata;
while (iptr) {
num_text++;
iptr = iptr->next;
}
- imginfo = MEM_callocN(num_text*sizeof(png_text), "png_imginfo");
- iptr = ibuf->img_info;
+ metadata = MEM_callocN(num_text*sizeof(png_text), "png_metadata");
+ iptr = ibuf->metadata;
num_text = 0;
while (iptr) {
- imginfo[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
- imginfo[num_text].key = iptr->key;
- imginfo[num_text].text = iptr->value;
+ metadata[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
+ metadata[num_text].key = iptr->key;
+ metadata[num_text].text = iptr->value;
num_text++;
iptr = iptr->next;
}
- png_set_text(png_ptr, info_ptr, imginfo, num_text);
- MEM_freeN(imginfo);
+ png_set_text(png_ptr, info_ptr, metadata, num_text);
+ MEM_freeN(metadata);
}
@@ -437,12 +441,12 @@ struct ImBuf *imb_loadpng(unsigned char *mem, int size, int flags)
break;
}
- if (flags & IB_imginfo) {
+ if (flags & IB_metadata) {
png_text* text_chunks;
int count = png_get_text(png_ptr, info_ptr, &text_chunks, NULL);
for(i = 0; i < count; i++) {
- IMB_imginfo_add_field(ibuf, text_chunks[i].key, text_chunks[i].text);
- ibuf->flags |= IB_imginfo;
+ IMB_metadata_add_field(ibuf, text_chunks[i].key, text_chunks[i].text);
+ ibuf->flags |= IB_metadata;
}
}
diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c
index 9ad28abeae4..c5122ebe46c 100644
--- a/source/blender/imbuf/intern/radiance_hdr.c
+++ b/source/blender/imbuf/intern/radiance_hdr.c
@@ -29,6 +29,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#ifdef WITH_HDR
+
/* ----------------------------------------------------------------------
Radiance High Dynamic Range image file IO
For description and code for reading/writing of radiance hdr files
@@ -40,17 +42,18 @@
#ifdef WIN32
#include <io.h>
#endif
+
+#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_allocimbuf.h"
-#include "IMB_cmap.h"
-#include "IMB_radiance_hdr.h"
+#include "IMB_filetype.h"
/* needed constants */
#define MINELEN 8
@@ -160,7 +163,7 @@ static void FLOAT2RGBE(fCOLOR fcol, RGBE rgbe)
/* ImBuf read */
-int imb_is_a_hdr(void *buf)
+int imb_is_a_hdr(unsigned char *buf)
{
// For recognition, Blender only loads first 32 bytes, so use #?RADIANCE id instead
// update: actually, the 'RADIANCE' part is just an optional program name, the magic word is really only the '#?' part
@@ -205,7 +208,6 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, int size, int flags)
if (ibuf==NULL) return NULL;
ibuf->ftype = RADHDR;
ibuf->profile = IB_PROFILE_LINEAR_RGB;
- ibuf->xorig = ibuf->yorig = 0;
if (flags & IB_test) return ibuf;
@@ -331,7 +333,7 @@ static void writeHeader(FILE *file, int width, int height)
fputc(10, file);
}
-short imb_savehdr(struct ImBuf *ibuf, char *name, int flags)
+int imb_savehdr(struct ImBuf *ibuf, char *name, int flags)
{
FILE* file = fopen(name, "wb");
float *fp= NULL;
@@ -361,3 +363,4 @@ short imb_savehdr(struct ImBuf *ibuf, char *name, int flags)
return 1;
}
+#endif /* WITH_HDR */
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c
index c23daacb919..3f4e177c78b 100644
--- a/source/blender/imbuf/intern/readimage.c
+++ b/source/blender/imbuf/intern/readimage.c
@@ -42,275 +42,159 @@
#include "BLI_blenlib.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
+#include "IMB_filetype.h"
-#include "IMB_amiga.h"
-#include "IMB_iris.h"
-#include "IMB_targa.h"
-#include "IMB_png.h"
-#include "IMB_hamx.h"
-#include "IMB_jpeg.h"
-#include "IMB_bmp.h"
-#include "IMB_radiance_hdr.h"
-#include "IMB_dpxcineon.h"
-#include "BKE_global.h"
-
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
-#include "IMB_cocoa.h"
-#else
-#include "IMB_tiff.h"
-#endif
-
-#ifdef WITH_OPENJPEG
-#include "IMB_jp2.h"
-#endif
-
-#ifdef WITH_OPENEXR
-#include "openexr/openexr_api.h"
-#endif
-
-#ifdef WITH_DDS
-#include "dds/dds_api.h"
-#endif
+ImBuf *IMB_ibImageFromMemory(unsigned char *mem, int size, int flags)
+{
+ ImBuf *ibuf;
+ ImFileType *type;
-#ifdef WITH_QUICKTIME
-#if defined(_WIN32) || defined (__APPLE__)
-#include "quicktime_import.h"
-#endif
-#endif
-
-/* actually hard coded endianness */
-#define GET_BIG_LONG(x) (((uchar *) (x))[0] << 24 | ((uchar *) (x))[1] << 16 | ((uchar *) (x))[2] << 8 | ((uchar *) (x))[3])
-#define GET_LITTLE_LONG(x) (((uchar *) (x))[3] << 24 | ((uchar *) (x))[2] << 16 | ((uchar *) (x))[1] << 8 | ((uchar *) (x))[0])
-#define SWAP_L(x) (((x << 24) & 0xff000000) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff))
-#define SWAP_S(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff))
-
-/* more endianness... should move to a separate file... */
-#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined(__hppa__) || defined (__BIG_ENDIAN__)
-#define GET_ID GET_BIG_LONG
-#define LITTLE_LONG SWAP_LONG
-#else
-#define GET_ID GET_LITTLE_LONG
-#define LITTLE_LONG ENDIAN_NOP
-#endif
-
-/* from misc_util: flip the bytes from x */
-#define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1])
-
-/* this one is only def-ed once, strangely... */
-#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
-
-int IB_verbose = TRUE;
+ if(mem == NULL) {
+ printf("Error in ibImageFromMemory: NULL pointer\n");
+ return NULL;
+ }
-ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) {
- int len;
- struct ImBuf *ibuf;
+ for(type=IMB_FILE_TYPES; type->is_a; type++) {
+ if(type->load) {
+ ibuf= type->load(mem, size, flags);
+ if(ibuf) {
+ if(flags & IB_premul) {
+ IMB_premultiply_alpha(ibuf);
+ ibuf->flags |= IB_premul;
+ }
- if (mem == NULL) {
- printf("Error in ibImageFromMemory: NULL pointer\n");
- } else {
- if ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)){
- return (imb_loadiris((uchar *) mem, flags));
- } else if (imb_is_a_jpeg((uchar *)mem)) {
- return (imb_ibJpegImageFromMemory((uchar *)mem, size, flags));
- }
-
- if (GET_ID(mem) == CAT){
- mem += 3;
- size -= 4;
- while (size > 0){
- if (GET_ID(mem) == FORM){
- len = ((GET_BIG_LONG(mem+1) + 1) & ~1) + 8;
- if ((GET_ID(mem+2) == ILBM) || (GET_ID(mem+2) == ANIM)) break;
- mem = (int *)((uchar *)mem +len);
- size -= len;
- } else return(0);
+ return ibuf;
}
}
+ }
+
+ fprintf(stderr, "Unknown fileformat\n");
- if (size > 0){
- if (GET_ID(mem) == FORM){
- if (GET_ID(mem+2) == ILBM){
- return (imb_loadamiga(mem, flags));
- } else if (GET_ID(mem+5) == ILBM){ /* animaties */
- return (imb_loadamiga(mem+3, flags));
- } else if (GET_ID(mem+2) == ANIM){
- return (imb_loadanim(mem, flags));
- }
- }
- }
+ return NULL;
+}
- ibuf = imb_loadpng((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ImBuf *IMB_loadifffile(int file, int flags)
+{
+ ImBuf *ibuf;
+ unsigned char *mem;
+ int size;
- ibuf = imb_bmp_decode((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ if(file == -1) return 0;
- ibuf = imb_loadtarga((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ size= BLI_filesize(file);
- ibuf = imb_loaddpx((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
+ mem= mmap(0, size, PROT_READ, MAP_SHARED, file, 0);
+ if(mem==(unsigned char*)-1) {
+ fprintf(stderr, "Couldn't get mapping\n");
+ return 0;
+ }
- ibuf = imb_loadcineon((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
-
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
- ibuf = imb_cocoaLoadImage((uchar *)mem, size, flags);
- if(ibuf) {
- ibuf->ftype = TIF;
- ibuf->profile = IB_PROFILE_SRGB;
- return ibuf;
- }
-#else
- if (G.have_libtiff) {
- ibuf = imb_loadtiff((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
- }
-#endif
-
- ibuf = imb_loadhdr((uchar*)mem, size, flags);
- if (ibuf) return (ibuf);
+ ibuf= IMB_ibImageFromMemory(mem, size, flags);
-#ifdef WITH_OPENEXR
- ibuf = imb_load_openexr((uchar *)mem, size, flags);
- if (ibuf) return (ibuf);
-#endif
+ if(munmap(mem, size))
+ fprintf(stderr, "Couldn't unmap file.\n");
-#ifdef WITH_OPENJPEG
- ibuf = imb_jp2_decode((uchar *)mem, size, flags);
- if (ibuf) return (ibuf);
-#endif
+ return ibuf;
+}
-#ifdef WITH_DDS
- ibuf = imb_load_dds((uchar *)mem, size, flags);
- if (ibuf) return (ibuf);
-#endif
-
-#ifdef WITH_QUICKTIME
-#if defined(_WIN32) || defined (__APPLE__)
- if(G.have_quicktime) {
- ibuf = imb_quicktime_decode((uchar *)mem, size, flags);
- if (ibuf) return(ibuf);
- }
-#endif
-#endif
+static void imb_cache_filename(char *filename, const char *name, int flags)
+{
+ /* read .tx instead if it exists and is not older */
+ if(flags & IB_tilecache) {
+ BLI_strncpy(filename, name, IB_FILENAME_SIZE);
+ if(!BLI_replace_extension(filename, IB_FILENAME_SIZE, ".tx"))
+ return;
- if (IB_verbose) fprintf(stderr, "Unknown fileformat\n");
+ if(BLI_file_older(name, filename))
+ return;
}
-
- return (0);
+
+ BLI_strncpy(filename, name, IB_FILENAME_SIZE);
}
+ImBuf *IMB_loadiffname(const char *name, int flags)
+{
+ ImBuf *ibuf;
+ int file, a;
+ char filename[IB_FILENAME_SIZE];
-struct ImBuf *IMB_loadiffmem(int *mem, int flags) {
- int len,maxlen;
- struct ImBuf *ibuf;
+ imb_cache_filename(filename, name, flags);
- // IMB_loadiffmem shouldn't be used anymore in new development
- // it's still here to be backwards compatible...
+ file = open(filename, O_BINARY|O_RDONLY);
+ if(file < 0) return 0;
- maxlen= (GET_BIG_LONG(mem+1) + 1) & ~1;
+ ibuf= IMB_loadifffile(file, flags);
- if (GET_ID(mem) == CAT){
- mem += 3;
- maxlen -= 4;
- while(maxlen > 0){
- if (GET_ID(mem) == FORM){
- len = ((GET_BIG_LONG(mem+1) + 1) & ~1) + 8;
- if ((GET_ID(mem+2) == ILBM) || (GET_ID(mem+2) == ANIM)) break;
- mem = (int *)((uchar *)mem +len);
- maxlen -= len;
- } else return(0);
- }
+ if(ibuf) {
+ BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
+ BLI_strncpy(ibuf->cachename, filename, sizeof(ibuf->cachename));
+ for(a=1; a<ibuf->miptot; a++)
+ BLI_strncpy(ibuf->mipmap[a-1]->cachename, filename, sizeof(ibuf->cachename));
+ if(flags & IB_fields) IMB_de_interlace(ibuf);
}
- if (maxlen > 0){
- if (GET_ID(mem) == FORM){
- if (GET_ID(mem+2) == ILBM){
- return (imb_loadamiga(mem, flags));
- } else if (GET_ID(mem+5) == ILBM){ /* animaties */
- return (imb_loadamiga(mem+3, flags));
- } else if (GET_ID(mem+2) == ANIM){
- return (imb_loadanim(mem, flags));
- }
- } else if ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)){
- return (imb_loadiris((uchar *) mem,flags));
- } else if ((BIG_LONG(mem[0]) & 0xfffffff0) == 0xffd8ffe0) {
- return (0);
- }
- }
-
- ibuf = imb_loadtarga((uchar *) mem,maxlen,flags);
- if (ibuf) return(ibuf);
+ close(file);
- if (IB_verbose) fprintf(stderr,"Unknown fileformat\n");
- return (0);
+ return ibuf;
}
-struct ImBuf *IMB_loadifffile(int file, int flags) {
- struct ImBuf *ibuf;
- int size, *mem;
+ImBuf *IMB_testiffname(char *name, int flags)
+{
+ ImBuf *ibuf;
+ int file;
+ char filename[IB_FILENAME_SIZE];
- if (file == -1) return (0);
+ imb_cache_filename(filename, name, flags);
- size = BLI_filesize(file);
+ file = open(filename,O_BINARY|O_RDONLY);
+ if(file < 0) return 0;
- mem= (int *)mmap(0,size,PROT_READ,MAP_SHARED,file,0);
- if (mem==(int *)-1){
- printf("Couldn't get mapping\n");
- return (0);
+ ibuf=IMB_loadifffile(file, flags|IB_test);
+ if(ibuf) {
+ BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
+ BLI_strncpy(ibuf->cachename, filename, sizeof(ibuf->cachename));
}
- ibuf = IMB_ibImageFromMemory(mem, size, flags);
+ close(file);
- if (munmap( (void *) mem, size)){
- printf("Couldn't unmap file.\n");
- }
- return(ibuf);
+ return ibuf;
}
+static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect)
+{
+ ImFileType *type;
+ unsigned char *mem;
+ int size;
-struct ImBuf *IMB_loadiffname(const char *naam, int flags) {
- int file;
- struct ImBuf *ibuf;
- int buf[1];
-
- file = open(naam, O_BINARY|O_RDONLY);
-
- if (file < 0) return (0);
+ if(file == -1) return;
- ibuf= IMB_loadifffile(file, flags);
+ size= BLI_filesize(file);
- if (ibuf == NULL) {
- if (read(file, buf, 4) != 4) buf[0] = 0;
- if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0)
- ibuf = imb_ibJpegImageFromFilename(naam, flags);
+ mem= mmap(0, 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;
}
- if (ibuf) {
- strncpy(ibuf->name, naam, sizeof(ibuf->name));
- if (flags & IB_fields) IMB_de_interlace(ibuf);
- }
- close(file);
- return(ibuf);
+ 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);
+
+ if(munmap(mem, size))
+ fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename);
}
-struct ImBuf *IMB_testiffname(char *naam,int flags) {
+void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
+{
int file;
- struct ImBuf *ibuf;
- flags |= IB_test;
- file = open(naam,O_BINARY|O_RDONLY);
+ file = open(ibuf->cachename, O_BINARY|O_RDONLY);
+ if(file < 0) return;
- if (file < 0) return (0);
+ imb_loadtilefile(ibuf, file, tx, ty, rect);
- ibuf=IMB_loadifffile(file,flags);
- if (ibuf) {
- strncpy(ibuf->name, naam, sizeof(ibuf->name));
- }
close(file);
- return(ibuf);
}
+
diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c
index 3202413a494..53385743bb8 100644
--- a/source/blender/imbuf/intern/rectop.c
+++ b/source/blender/imbuf/intern/rectop.c
@@ -32,7 +32,6 @@
#include "BLI_blenlib.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c
index 2369c83bbd3..4edb7ac7877 100644
--- a/source/blender/imbuf/intern/rotate.c
+++ b/source/blender/imbuf/intern/rotate.c
@@ -30,10 +30,10 @@
*/
#include "BLI_blenlib.h"
-#include "BKE_utildefines.h"
+#include "BKE_utildefines.h"
+#include "MEM_guardedalloc.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c
index b3e25b52140..f26eec51b03 100644
--- a/source/blender/imbuf/intern/scaling.c
+++ b/source/blender/imbuf/intern/scaling.c
@@ -30,9 +30,9 @@
*/
#include "BLI_blenlib.h"
+#include "MEM_guardedalloc.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -347,142 +347,6 @@ struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
}
-
-struct ImBuf *IMB_onethird(struct ImBuf *ibuf1)
-{
- struct ImBuf *ibuf2;
- uchar *p1,*p2,*p3,*dest;
- float *p1f, *p2f, *p3f, *destf;
- int do_rect, do_float;
- short a,r,g,b,x,y,i;
- float af,rf,gf,bf;
-
- p2= p3= NULL;
- p2f= p3f= NULL;
- if (ibuf1==NULL) return (0);
- if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (0);
-
- do_rect= (ibuf1->rect != NULL);
- do_float= (ibuf1->rect_float != NULL);
-
- ibuf2=IMB_allocImBuf((ibuf1->x)/3, (ibuf1->y)/3, ibuf1->depth, ibuf1->flags, 0);
- if (ibuf2==NULL) return (0);
-
- p1f = ibuf1->rect_float;
- destf = ibuf2->rect_float;
- p1 = (uchar *) ibuf1->rect;
- dest=(uchar *) ibuf2->rect;
-
- for(y=ibuf2->y;y>0;y--){
- if (do_rect) {
- p2 = p1 + (ibuf1->x << 2);
- p3 = p2 + (ibuf1->x << 2);
- }
- if (do_float) {
- p2f = p1f + (ibuf1->x <<2);
- p3f = p2f + (ibuf1->x <<2);
- }
- for(x=ibuf2->x;x>0;x--){
- a=r=g=b=0;
- af=rf=gf=bf=0;
- for (i=3;i>0;i--){
- if (do_rect) {
- a += *(p1++) + *(p2++) + *(p3++);
- b += *(p1++) + *(p2++) + *(p3++);
- g += *(p1++) + *(p2++) + *(p3++);
- r += *(p1++) + *(p2++) + *(p3++);
- }
- if (do_float) {
- af += *(p1f++) + *(p2f++) + *(p3f++);
- bf += *(p1f++) + *(p2f++) + *(p3f++);
- gf += *(p1f++) + *(p2f++) + *(p3f++);
- rf += *(p1f++) + *(p2f++) + *(p3f++);
- }
- }
- if (do_rect) {
- *(dest++) = a/9;
- *(dest++) = b/9;
- *(dest++) = g/9;
- *(dest++) = r/9;
- }
- if (do_float) {
- *(destf++) = af/9.0f;
- *(destf++) = bf/9.0f;
- *(destf++) = gf/9.0f;
- *(destf++) = rf/9.0f;
- }
- }
- if (do_rect) p1=p3;
- if (do_float) p1f = p3f;
- }
- return (ibuf2);
-}
-
-
-struct ImBuf *IMB_halflace(struct ImBuf *ibuf1)
-{
- struct ImBuf *ibuf2;
- uchar *p1,*p2,*dest;
- float *p1f,*p2f,*destf;
- short a,r,g,b,x,y,i;
- float af,rf,gf,bf;
- int do_rect, do_float;
-
- p2= NULL;
- p2f= NULL;
- if (ibuf1==NULL) return (0);
- if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (0);
-
- do_rect= (ibuf1->rect != NULL);
- do_float= (ibuf1->rect_float != NULL);
-
- ibuf2=IMB_allocImBuf((ibuf1->x)/4, (ibuf1->y)/2, ibuf1->depth, ibuf1->flags, 0);
- if (ibuf2==NULL) return (0);
-
- p1f = ibuf1->rect_float;
- destf= ibuf2->rect_float;
- p1 = (uchar *) ibuf1->rect;
- dest=(uchar *) ibuf2->rect;
-
- for(y= ibuf2->y / 2 ; y>0;y--){
- if (do_rect) p2 = p1 + (ibuf1->x << 3);
- if (do_float) p2f = p1f + (ibuf1->x << 3);
- for(x = 2 * ibuf2->x;x>0;x--){
- a=r=g=b=0;
- af=rf=gf=bf=0;
- for (i=4;i>0;i--){
- if (do_rect) {
- a += *(p1++) + *(p2++);
- b += *(p1++) + *(p2++);
- g += *(p1++) + *(p2++);
- r += *(p1++) + *(p2++);
- }
- if (do_float) {
- af += *(p1f++) + *(p2f++);
- bf += *(p1f++) + *(p2f++);
- gf += *(p1f++) + *(p2f++);
- rf += *(p1f++) + *(p2f++);
- }
- }
- if (do_rect) {
- *(dest++) = a >> 3;
- *(dest++) = b >> 3;
- *(dest++) = g >> 3;
- *(dest++) = r >> 3;
- }
- if (do_float) {
- *(destf++) = 0.125f*af;
- *(destf++) = 0.125f*bf;
- *(destf++) = 0.125f*gf;
- *(destf++) = 0.125f*rf;
- }
- }
- if (do_rect) p1 = p2;
- if (do_float) p1f = p2f;
- }
- return (ibuf2);
-}
-
/* q_scale_linear_interpolation helper functions */
static void enlarge_picture_byte(
@@ -1687,55 +1551,3 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, short newx, short newy)
return(ibuf);
}
-
-static struct ImBuf *generic_fieldscale(struct ImBuf *ibuf, short newx, short newy, struct ImBuf *(*scalefunc)(ImBuf *, short, short) )
-{
- struct ImBuf *sbuf1, *sbuf2;
-
- sbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, ibuf->flags, 0);
- sbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, ibuf->depth, ibuf->flags, 0);
-
- ibuf->x *= 2;
-
- /* more args needed, 0 assumed... (nzc) */
- IMB_rectcpy(sbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
- IMB_rectcpy(sbuf2, ibuf, 0, 0, sbuf2->x, 0, ibuf->x, ibuf->y);
-
- imb_freerectImBuf(ibuf);
- imb_freerectfloatImBuf(ibuf);
-
- ibuf->x = newx;
- ibuf->y = newy;
-
- imb_addrectImBuf(ibuf);
- if(ibuf->flags & IB_rectfloat)
- imb_addrectfloatImBuf(ibuf);
-
- scalefunc(sbuf1, newx, newy / 2);
- scalefunc(sbuf2, newx, newy / 2);
-
- ibuf->x *= 2;
-
- /* more args needed, 0 assumed... (nzc) */
- IMB_rectcpy(ibuf, sbuf1, 0, 0, 0, 0, sbuf1->x, sbuf1->y);
- IMB_rectcpy(ibuf, sbuf2, sbuf2->x, 0, 0, 0, sbuf2->x, sbuf2->y);
-
- ibuf->x /= 2;
-
- IMB_freeImBuf(sbuf1);
- IMB_freeImBuf(sbuf2);
-
- return(ibuf);
-}
-
-
-struct ImBuf *IMB_scalefastfieldImBuf(struct ImBuf *ibuf, short newx, short newy)
-{
- return(generic_fieldscale(ibuf, newx, newy, IMB_scalefastImBuf));
-}
-
-struct ImBuf *IMB_scalefieldImBuf(struct ImBuf *ibuf, short newx, short newy)
-{
- return(generic_fieldscale(ibuf, newx, newy, IMB_scaleImBuf));
-}
-
diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c
index 092c52d427b..b5434b85b5a 100644
--- a/source/blender/imbuf/intern/targa.c
+++ b/source/blender/imbuf/intern/targa.c
@@ -31,16 +31,15 @@
#include <io.h>
#endif
#include "BLI_blenlib.h"
+#include "MEM_guardedalloc.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_cmap.h"
-#include "IMB_targa.h"
+#include "IMB_filetype.h"
/* this one is only def-ed once, strangely... related to GS? */
@@ -234,11 +233,10 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file)
}
-short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
+int imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
{
char buf[20];
FILE *fildes;
- int i;
short ok = 0;
if (ibuf == 0) return (0);
@@ -249,19 +247,7 @@ short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
/* buf[0] = 0; length string */
buf[16] = (ibuf->depth + 0x7 ) & ~0x7;
- if (ibuf->cmap) {
- buf[1] = 1;
- buf[2] = 9;
- buf[3] = ibuf->mincol & 0xff;
- buf[4] = ibuf->mincol >> 8;
- buf[5] = ibuf->maxcol & 0xff;
- buf[6] = ibuf->maxcol >> 8;
- buf[7] = 24;
- if ((flags & IB_ttob) == 0) {
- IMB_flipy(ibuf);
- buf[17] = 0x20;
- }
- } else if (ibuf->depth > 8 ){
+ if (ibuf->depth > 8 ){
buf[2] = 10;
} else{
buf[2] = 11;
@@ -269,18 +255,16 @@ short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
if (ibuf->ftype == RAWTGA) buf[2] &= ~8;
- buf[8] = ibuf->xorig & 0xff;
- buf[9] = ibuf->xorig >> 8;
- buf[10] = ibuf->yorig & 0xff;
- buf[11] = ibuf->yorig >> 8;
+ buf[8] = 0;
+ buf[9] = 0;
+ buf[10] = 0;
+ buf[11] = 0;
buf[12] = ibuf->x & 0xff;
buf[13] = ibuf->x >> 8;
buf[14] = ibuf->y & 0xff;
buf[15] = ibuf->y >> 8;
- if (flags & IB_ttob) buf[17] ^= 0x20;
-
/* Don't forget to indicate that your 32 bit
* targa uses 8 bits for the alpha channel! */
if (ibuf->depth==32) {
@@ -294,17 +278,6 @@ short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
return (0);
}
- if (ibuf->cmap){
- for (i = 0 ; i<ibuf->maxcol ; i++){
- if (fwrite(((uchar *)(ibuf->cmap + i)) + 1,1,3,fildes) != 3) {
- fclose(fildes);
- return (0);
- }
- }
- }
-
- if (ibuf->cmap && (flags & IB_cmap) == 0) IMB_converttocmap(ibuf);
-
if (ibuf->ftype == RAWTGA) {
ok = dumptarga(ibuf, fildes);
} else {
@@ -365,7 +338,7 @@ static int checktarga(TARGA *tga, unsigned char *mem)
return(1);
}
-int imb_is_a_targa(void *buf) {
+int imb_is_a_targa(unsigned char *buf) {
TARGA tga;
return checktarga(&tga, buf);
@@ -559,7 +532,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags)
TARGA tga;
struct ImBuf * ibuf;
int col, count, size;
- unsigned int * rect;
+ unsigned int *rect, *cmap= NULL, mincol= 0, maxcol= 0;
uchar * cp = (uchar *) &col;
if (checktarga(&tga,mem) == 0) return(0);
@@ -570,19 +543,18 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags)
if (ibuf == 0) return(0);
ibuf->ftype = TGA;
ibuf->profile = IB_PROFILE_SRGB;
- ibuf->xorig = tga.xorig;
- ibuf->yorig = tga.yorig;
mem = mem + 18 + tga.numid;
cp[0] = 0xff;
cp[1] = cp[2] = 0;
if (tga.mapsize){
- ibuf->mincol = tga.maporig;
- ibuf->maxcol = tga.mapsize;
- imb_addcmapImBuf(ibuf);
- ibuf->cbits = 8;
- for (count = 0 ; count < ibuf->maxcol ; count ++) {
+ /* load color map */
+ mincol = tga.maporig;
+ maxcol = tga.mapsize;
+ cmap = MEM_callocN(sizeof(unsigned int)*maxcol, "targa cmap");
+
+ for (count = 0 ; count < maxcol ; count ++) {
switch (tga.mapbits >> 3) {
case 4:
cp[0] = mem[3];
@@ -606,21 +578,26 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags)
col = *mem++;
break;
}
- ibuf->cmap[count] = col;
+ cmap[count] = col;
}
size = 0;
- for (col = ibuf->maxcol - 1; col > 0; col >>= 1) size++;
+ for (col = maxcol - 1; col > 0; col >>= 1) size++;
ibuf->depth = size;
if (tga.mapbits != 32) { /* set alpha bits */
- ibuf->cmap[0] &= BIG_LONG(0x00ffffff);
+ cmap[0] &= BIG_LONG(0x00ffffff);
}
}
if (flags & IB_test) return (ibuf);
- if (tga.imgtyp != 1 && tga.imgtyp != 9) IMB_freecmapImBuf(ibuf); /* happens sometimes (beuh) */
+ if (tga.imgtyp != 1 && tga.imgtyp != 9) { /* happens sometimes (beuh) */
+ if(cmap) {
+ MEM_freeN(cmap);
+ cmap= NULL;
+ }
+ }
switch(tga.imgtyp){
case 1:
@@ -641,11 +618,18 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags)
break;
}
- if (ibuf->cmap){
- if ((flags & IB_cmap) == 0) IMB_applycmap(ibuf);
+ if(cmap) {
+ /* apply color map */
+ rect = ibuf->rect;
+ for(size = ibuf->x * ibuf->y; size>0; --size, ++rect) {
+ col = *rect;
+ if (col >= 0 && col < maxcol) *rect = cmap[col];
+ }
+
+ MEM_freeN(cmap);
}
- if (tga.pixsize == 16 && ibuf->cmap == 0){
+ if (tga.pixsize == 16) {
rect = ibuf->rect;
for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect){
col = *rect;
@@ -679,13 +663,10 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int mem_size, int flags)
}
}
- if (flags & IB_ttob) tga.imgdes ^= 0x20;
if (tga.imgdes & 0x20) IMB_flipy(ibuf);
- if (ibuf) {
- if (ibuf->rect && (flags & IB_cmap)==0)
- IMB_convert_rgba_to_abgr(ibuf);
- }
+ if (ibuf && ibuf->rect)
+ IMB_convert_rgba_to_abgr(ibuf);
return(ibuf);
}
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index 5e0504155dc..f3415d44ecb 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -29,7 +29,6 @@
#include <stdio.h>
-#include "BKE_global.h"
#include "BKE_utildefines.h"
#include "BLI_blenlib.h"
#include "MEM_guardedalloc.h"
@@ -37,7 +36,7 @@
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_thumbs.h"
-#include "IMB_imginfo.h"
+#include "IMB_metadata.h"
#include "md5.h"
@@ -241,17 +240,16 @@ void IMB_thumb_makedirs()
}
/* create thumbnail for file and returns new imbuf for thumbnail */
-ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source)
+ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, ImBuf *img)
{
- ImBuf *img = 0;
- char uri[URI_MAX];
+ char uri[URI_MAX]= "";
char desc[URI_MAX+22];
char tpath[FILE_MAX];
char tdir[FILE_MAX];
char temp[FILE_MAX];
- char mtime[40];
- char cwidth[40];
- char cheight[40];
+ char mtime[40]= "0"; /* incase we can't stat the file */
+ char cwidth[40]= "0"; /* incase images have no data */
+ char cheight[40]= "0";
char thumb[40];
short tsize = 128;
short ex, ey;
@@ -266,7 +264,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source)
tsize = 256;
break;
case THB_FAIL:
- tsize = 0;
+ tsize = 1;
break;
default:
return 0; /* unknown size */
@@ -282,11 +280,21 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source)
return NULL;
}
if (size == THB_FAIL) {
- img = IMB_allocImBuf(0,0,32, IB_rect | IB_imginfo, 0);
+ img = IMB_allocImBuf(1,1,32, IB_rect | IB_metadata, 0);
if (!img) return 0;
} else {
- if (THB_SOURCE_IMAGE == source) {
- img = IMB_loadiffname(path, IB_rect | IB_imginfo);
+ if (THB_SOURCE_IMAGE == source || THB_SOURCE_BLEND == source) {
+
+ /* only load if we didnt give an image */
+ if(img==NULL) {
+ if(THB_SOURCE_BLEND == source) {
+ img = IMB_loadblend_thumb(path);
+ }
+ else {
+ img = IMB_loadiffname(path, IB_rect | IB_metadata);
+ }
+ }
+
if (img != NULL) {
stat(path, &info);
sprintf(mtime, "%ld", info.st_mtime);
@@ -295,7 +303,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source)
}
} else if (THB_SOURCE_MOVIE == source) {
struct anim * anim = NULL;
- anim = IMB_open_anim(path, IB_rect | IB_imginfo);
+ anim = IMB_open_anim(path, IB_rect | IB_metadata);
if (anim != NULL) {
img = IMB_anim_absolute(anim, 0);
if (img == NULL) {
@@ -325,20 +333,20 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source)
IMB_scaleImBuf(img, ex, ey);
}
sprintf(desc, "Thumbnail for %s", uri);
- IMB_imginfo_change_field(img, "Description", desc);
- IMB_imginfo_change_field(img, "Software", "Blender");
- IMB_imginfo_change_field(img, "Thumb::URI", uri);
- IMB_imginfo_change_field(img, "Thumb::MTime", mtime);
+ IMB_metadata_change_field(img, "Description", desc);
+ IMB_metadata_change_field(img, "Software", "Blender");
+ IMB_metadata_change_field(img, "Thumb::URI", uri);
+ IMB_metadata_change_field(img, "Thumb::MTime", mtime);
if (THB_SOURCE_IMAGE == source) {
- IMB_imginfo_change_field(img, "Thumb::Image::Width", cwidth);
- IMB_imginfo_change_field(img, "Thumb::Image::Height", cheight);
+ IMB_metadata_change_field(img, "Thumb::Image::Width", cwidth);
+ IMB_metadata_change_field(img, "Thumb::Image::Height", cheight);
}
img->ftype = PNG;
img->depth = 32;
- if (IMB_saveiff(img, temp, IB_rect | IB_imginfo)) {
+ if (IMB_saveiff(img, temp, IB_rect | IB_metadata)) {
#ifndef WIN32
chmod(temp, S_IRUSR | S_IWUSR);
-#endif
+#endif
BLI_rename(temp, tpath);
}
@@ -358,7 +366,7 @@ ImBuf* IMB_thumb_read(const char* path, ThumbSize size)
return NULL;
}
if (thumbpath_from_uri(uri, thumb, size)) {
- img = IMB_loadiffname(thumb, IB_rect | IB_imginfo);
+ img = IMB_loadiffname(thumb, IB_rect | IB_metadata);
}
return img;
@@ -409,10 +417,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source)
if (strncmp(path, thumb, strlen(thumb)) == 0) {
img = IMB_loadiffname(path, IB_rect);
} else {
- img = IMB_loadiffname(thumb, IB_rect | IB_imginfo);
+ img = IMB_loadiffname(thumb, IB_rect | IB_metadata);
if (img) {
char mtime[40];
- if (!IMB_imginfo_get_field(img, "Thumb::MTime", mtime, 40)) {
+ if (!IMB_metadata_get_field(img, "Thumb::MTime", mtime, 40)) {
/* illegal thumb, forget it! */
IMB_freeImBuf(img);
img = 0;
@@ -425,10 +433,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source)
IMB_thumb_delete(path, THB_NORMAL);
IMB_thumb_delete(path, THB_LARGE);
IMB_thumb_delete(path, THB_FAIL);
- img = IMB_thumb_create(path, size, source);
+ img = IMB_thumb_create(path, size, source, NULL);
if(!img){
/* thumb creation failed, write fail thumb */
- img = IMB_thumb_create(path, THB_FAIL, source);
+ img = IMB_thumb_create(path, THB_FAIL, source, NULL);
if (img) {
/* we don't need failed thumb anymore */
IMB_freeImBuf(img);
@@ -438,10 +446,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source)
}
}
} else {
- img = IMB_thumb_create(path, size, source);
+ img = IMB_thumb_create(path, size, source, NULL);
if(!img){
/* thumb creation failed, write fail thumb */
- img = IMB_thumb_create(path, THB_FAIL, source);
+ img = IMB_thumb_create(path, THB_FAIL, source, NULL);
if (img) {
/* we don't need failed thumb anymore */
IMB_freeImBuf(img);
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
new file mode 100644
index 00000000000..cb27b1a647f
--- /dev/null
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -0,0 +1,192 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+
+#include "zlib.h"
+
+#include "BKE_utildefines.h"
+#include "BKE_global.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+#include "IMB_thumbs.h"
+
+#include "MEM_guardedalloc.h"
+
+/* extracts the thumbnail from between the 'REND' and the 'GLOB'
+ * chunks of the header, dont use typical blend loader because its too slow */
+
+static ImBuf *loadblend_thumb(gzFile gzfile)
+{
+ char buf[12];
+ int bhead[24/sizeof(int)]; /* max size on 64bit */
+ char endian, pointer_size;
+ char endian_switch;
+ int sizeof_bhead ;
+
+ /* read the blend file header */
+ if(gzread(gzfile, buf, 12) != 12)
+ return NULL;
+ if(strncmp(buf, "BLENDER", 7))
+ return NULL;
+
+ if(buf[7]=='-')
+ pointer_size= 8;
+ else if(buf[7]=='_')
+ pointer_size= 4;
+ else
+ return NULL;
+
+ sizeof_bhead = 16 + pointer_size;
+
+ if(buf[8]=='V')
+ endian= B_ENDIAN; /* big: PPC */
+ else if(buf[8]=='v')
+ endian= L_ENDIAN; /* little: x86 */
+ else
+ return NULL;
+
+ endian_switch = ((ENDIAN_ORDER != endian)) ? 1 : 0;
+
+ while(gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) {
+ if(endian_switch)
+ SWITCH_INT(bhead[1]); /* length */
+
+ if (bhead[0]==REND) {
+ gzseek(gzfile, bhead[1], SEEK_CUR); /* skip to the next */
+ }
+ else {
+ break;
+ }
+ }
+
+ /* using 'TEST' since new names segfault when loading in old blenders */
+ if(bhead[0] == TEST) {
+ ImBuf *img= NULL;
+ int size[2];
+
+ if(gzread(gzfile, size, sizeof(size)) != sizeof(size))
+ return NULL;
+
+ if(endian_switch) {
+ SWITCH_INT(size[0]);
+ SWITCH_INT(size[1]);
+ }
+ /* length */
+ bhead[1] -= sizeof(int) * 2;
+
+ /* inconsistant image size, quit early */
+ if(bhead[1] != size[0] * size[1] * sizeof(int))
+ return NULL;
+
+ /* finally malloc and read the data */
+ img= IMB_allocImBuf(size[0], size[1], 32, IB_rect | IB_metadata, 0);
+
+ if(gzread(gzfile, img->rect, bhead[1]) != bhead[1]) {
+ IMB_freeImBuf(img);
+ img= NULL;
+ }
+
+ return img;
+ }
+
+ return NULL;
+}
+
+ImBuf *IMB_loadblend_thumb(const char *path)
+{
+ gzFile gzfile;
+
+ /* not necessarily a gzip */
+ gzfile = gzopen(path, "rb");
+
+ if (NULL == gzfile ) {
+ return NULL;
+ }
+ else {
+ ImBuf *img= loadblend_thumb(gzfile);
+
+ /* read ok! */
+ gzclose(gzfile);
+
+ return img;
+ }
+}
+
+/* add a fake passepartout overlay to a byte buffer, use for blend file thumbnails */
+#define MARGIN 2
+
+void IMB_overlayblend_thumb(unsigned int *thumb, int width, int height, float aspect)
+{
+ unsigned char *px= (unsigned char *)thumb;
+ int margin_l = MARGIN;
+ int margin_b = MARGIN;
+ int margin_r = width - MARGIN;
+ int margin_t = height - MARGIN;
+
+ if(aspect < 1.0f) {
+ margin_l= (int)((width - ((float)width * aspect)) / 2.0f);
+ margin_l += MARGIN;
+ CLAMP(margin_l, MARGIN, (width/2));
+ margin_r = width - margin_l;
+ }
+ else if (aspect > 1.0f) {
+ margin_b= (int)((height - ((float)height / aspect)) / 2.0f);
+ margin_b += MARGIN;
+ CLAMP(margin_b, MARGIN, (height/2));
+ margin_t = height - margin_b;
+ }
+
+ {
+ int x, y;
+ int hline, vline;
+ int stride_x= (margin_r - margin_l) - 2;
+
+ for(y=0; y < height; y++) {
+ for(x=0; x < width; x++, px+=4) {
+ if((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) {
+ /* interior. skip */
+ x += stride_x;
+ px += stride_x * 4;
+ } else if( (hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) ||
+ (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r))
+ ) {
+ /* dashed line */
+ if((hline && y % 2) || (vline && x % 2)) {
+ px[0]= px[1]= px[2]= 0;
+ px[3] = 255;
+ }
+ }
+ else {
+ /* outside, fill in alpha, like passepartout */
+ px[0] *= 0.5f;
+ px[1] *= 0.5f;
+ px[2] *= 0.5f;
+ px[3] = (px[3] * 0.5f) + 96;
+ }
+ }
+ }
+ }
+}
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index dd18c77c5c6..6b94583f17d 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -40,21 +40,26 @@
* used to compress images.
*/
+#ifdef WITH_TIFF
+
#include <string.h>
#include "imbuf.h"
-#include "imbuf_patch.h"
-
+
#include "BKE_global.h"
+#include "BKE_utildefines.h"
+
+#include "BLI_math.h"
+#include "BLI_string.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_allocimbuf.h"
-#include "IMB_cmap.h"
-#include "IMB_tiff.h"
+#include "IMB_filetype.h"
+#include "IMB_filter.h"
-#include "dynlibtiff.h"
+#include "tiffio.h"
@@ -72,12 +77,12 @@ static void imb_tiff_DummyUnmapProc(thandle_t fd, tdata_t base, toff_t size);
/* Structure for in-memory TIFF file. */
-struct ImbTIFFMemFile {
+typedef struct ImbTIFFMemFile {
unsigned char *mem; /* Location of first byte of TIFF file. */
toff_t offset; /* Current offset within the file. */
tsize_t size; /* Size of the TIFF file. */
-};
-#define IMB_TIFF_GET_MEMFILE(x) ((struct ImbTIFFMemFile*)(x));
+} ImbTIFFMemFile;
+#define IMB_TIFF_GET_MEMFILE(x) ((ImbTIFFMemFile*)(x));
@@ -108,28 +113,28 @@ static int imb_tiff_DummyMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
static tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n)
{
tsize_t nRemaining, nCopy;
- struct ImbTIFFMemFile* mfile;
+ ImbTIFFMemFile* mfile;
void *srcAddr;
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- if (!mfile || !mfile->mem) {
+ if(!mfile || !mfile->mem) {
fprintf(stderr, "imb_tiff_ReadProc: !mfile || !mfile->mem!\n");
return 0;
}
/* find the actual number of bytes to read (copy) */
nCopy = n;
- if ((tsize_t)mfile->offset >= mfile->size)
+ if((tsize_t)mfile->offset >= mfile->size)
nRemaining = 0;
else
nRemaining = mfile->size - mfile->offset;
- if (nCopy > nRemaining)
+ if(nCopy > nRemaining)
nCopy = nRemaining;
/* on EOF, return immediately and read (copy) nothing */
- if (nCopy <= 0)
+ if(nCopy <= 0)
return (0);
/* all set -> do the read (copy) */
@@ -171,12 +176,12 @@ static tsize_t imb_tiff_WriteProc(thandle_t handle, tdata_t data, tsize_t n)
*/
static toff_t imb_tiff_SeekProc(thandle_t handle, toff_t ofs, int whence)
{
- struct ImbTIFFMemFile *mfile;
+ ImbTIFFMemFile *mfile;
toff_t new_offset;
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- if (!mfile || !mfile->mem) {
+ if(!mfile || !mfile->mem) {
fprintf(stderr, "imb_tiff_SeekProc: !mfile || !mfile->mem!\n");
return (-1);
}
@@ -218,11 +223,11 @@ static toff_t imb_tiff_SeekProc(thandle_t handle, toff_t ofs, int whence)
*/
static int imb_tiff_CloseProc(thandle_t handle)
{
- struct ImbTIFFMemFile *mfile;
+ ImbTIFFMemFile *mfile;
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- if (!mfile || !mfile->mem) {
+ if(!mfile || !mfile->mem) {
fprintf(stderr,"imb_tiff_CloseProc: !mfile || !mfile->mem!\n");
return (0);
}
@@ -244,11 +249,11 @@ static int imb_tiff_CloseProc(thandle_t handle)
*/
static toff_t imb_tiff_SizeProc(thandle_t handle)
{
- struct ImbTIFFMemFile* mfile;
+ ImbTIFFMemFile* mfile;
/* get the pointer to the in-memory file */
mfile = IMB_TIFF_GET_MEMFILE(handle);
- if (!mfile || !mfile->mem) {
+ if(!mfile || !mfile->mem) {
fprintf(stderr,"imb_tiff_SizeProc: !mfile || !mfile->mem!\n");
return (0);
}
@@ -257,14 +262,23 @@ static toff_t imb_tiff_SizeProc(thandle_t handle)
return (toff_t)(mfile->size);
}
+static TIFF *imb_tiff_client_open(ImbTIFFMemFile *memFile, unsigned char *mem, int size)
+{
+ /* open the TIFF client layer interface to the in-memory file */
+ memFile->mem = mem;
+ memFile->offset = 0;
+ memFile->size = size;
+ return TIFFClientOpen("(Blender TIFF Interface Layer)",
+ "r", (thandle_t)(memFile),
+ imb_tiff_ReadProc, imb_tiff_WriteProc,
+ imb_tiff_SeekProc, imb_tiff_CloseProc,
+ imb_tiff_SizeProc, imb_tiff_DummyMapProc, imb_tiff_DummyUnmapProc);
+}
/**
* Checks whether a given memory buffer contains a TIFF file.
*
- * FIXME: Possible memory leak if mem is less than IMB_TIFF_NCB bytes long.
- * However, changing this will require up-stream modifications.
- *
* This method uses the format identifiers from:
* http://www.faqs.org/faqs/graphics/fileformats-faq/part4/section-9.html
* The first four bytes of big-endian and little-endian TIFF files
@@ -278,7 +292,7 @@ static toff_t imb_tiff_SizeProc(thandle_t handle)
* hence my manual comparison. - Jonathan Merritt (lancelet) 4th Sept 2005.
*/
#define IMB_TIFF_NCB 4 /* number of comparison bytes used */
-int imb_is_a_tiff(void *mem)
+int imb_is_a_tiff(unsigned char *mem)
{
char big_endian[IMB_TIFF_NCB] = { 0x4d, 0x4d, 0x00, 0x2a };
char lil_endian[IMB_TIFF_NCB] = { 0x49, 0x49, 0x2a, 0x00 };
@@ -287,14 +301,161 @@ int imb_is_a_tiff(void *mem)
(memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0) );
}
+static void scanline_contig_16bit(float *rectf, unsigned short *sbuf, int scanline_w, int spp)
+{
+ int i;
+ for (i=0; i < scanline_w; i++) {
+ rectf[i*4 + 0] = sbuf[i*spp + 0] / 65535.0;
+ rectf[i*4 + 1] = sbuf[i*spp + 1] / 65535.0;
+ rectf[i*4 + 2] = sbuf[i*spp + 2] / 65535.0;
+ rectf[i*4 + 3] = (spp==4)?(sbuf[i*spp + 3] / 65535.0):1.0;
+ }
+}
+
+static void scanline_contig_32bit(float *rectf, float *fbuf, int scanline_w, int spp)
+{
+ int i;
+ for (i=0; i < scanline_w; i++) {
+ rectf[i*4 + 0] = fbuf[i*spp + 0];
+ rectf[i*4 + 1] = fbuf[i*spp + 1];
+ rectf[i*4 + 2] = fbuf[i*spp + 2];
+ rectf[i*4 + 3] = (spp==4)?fbuf[i*spp + 3]:1.0;
+ }
+}
+
+static void scanline_separate_16bit(float *rectf, unsigned short *sbuf, int scanline_w, int chan)
+{
+ int i;
+ for (i=0; i < scanline_w; i++)
+ rectf[i*4 + chan] = sbuf[i] / 65535.0;
+}
+
+static void scanline_separate_32bit(float *rectf, float *fbuf, int scanline_w, int chan)
+{
+ int i;
+ for (i=0; i < scanline_w; i++)
+ rectf[i*4 + chan] = fbuf[i];
+}
+
+/*
+ * Use the libTIFF scanline API to read a TIFF image.
+ * This method is most flexible and can handle multiple different bit depths
+ * and RGB channel orderings.
+ */
+static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
+{
+ ImBuf *tmpibuf;
+ int success= 0;
+ short bitspersample, spp, config;
+ size_t scanline;
+ int ib_flag=0, row, chan;
+ float *fbuf=NULL;
+ unsigned short *sbuf=NULL;
+
+ TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bitspersample);
+ TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp); /* number of 'channels' */
+ TIFFGetField(image, TIFFTAG_PLANARCONFIG, &config);
+ scanline = TIFFScanlineSize(image);
+
+ if (bitspersample == 32) {
+ ib_flag = IB_rectfloat;
+ fbuf = (float *)_TIFFmalloc(scanline);
+ } else if (bitspersample == 16) {
+ ib_flag = IB_rectfloat;
+ sbuf = (unsigned short *)_TIFFmalloc(scanline);
+ } else {
+ ib_flag = IB_rect;
+ }
+
+ tmpibuf= IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->depth, ib_flag, 0);
+
+ /* simple RGBA image */
+ if (!(bitspersample == 32 || bitspersample == 16)) {
+ success |= TIFFReadRGBAImage(image, ibuf->x, ibuf->y, tmpibuf->rect, 0);
+ }
+ /* contiguous channels: RGBRGBRGB */
+ else if (config == PLANARCONFIG_CONTIG) {
+ for (row = 0; row < ibuf->y; row++) {
+ int ib_offset = ibuf->x*ibuf->y*4 - ibuf->x*4 * (row+1);
+
+ if (bitspersample == 32) {
+ success |= TIFFReadScanline(image, fbuf, row, 0);
+ scanline_contig_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, spp);
+
+ } else if (bitspersample == 16) {
+ success |= TIFFReadScanline(image, sbuf, row, 0);
+ scanline_contig_16bit(tmpibuf->rect_float+ib_offset, sbuf, ibuf->x, spp);
+ }
+ }
+ /* separate channels: RRRGGGBBB */
+ } else if (config == PLANARCONFIG_SEPARATE) {
+
+ /* imbufs always have 4 channels of data, so we iterate over all of them
+ * but only fill in from the TIFF scanline where necessary. */
+ for (chan = 0; chan < 4; chan++) {
+ for (row = 0; row < ibuf->y; row++) {
+ int ib_offset = ibuf->x*ibuf->y*4 - ibuf->x*4 * (row+1);
+
+ if (bitspersample == 32) {
+ if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+ memset(fbuf, 1.0, sizeof(fbuf));
+ else
+ success |= TIFFReadScanline(image, fbuf, row, chan);
+ scanline_separate_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, chan);
+
+ } else if (bitspersample == 16) {
+ if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+ memset(sbuf, 65535, sizeof(sbuf));
+ else
+ success |= TIFFReadScanline(image, sbuf, row, chan);
+ scanline_separate_16bit(tmpibuf->rect_float+ib_offset, sbuf, ibuf->x, chan);
+
+ }
+ }
+ }
+ }
+
+ if (bitspersample == 32)
+ _TIFFfree(fbuf);
+ else if (bitspersample == 16)
+ _TIFFfree(sbuf);
+
+ if(success) {
+ ibuf->profile = (bitspersample==32)?IB_PROFILE_LINEAR_RGB:IB_PROFILE_SRGB;
+
+ if(ENDIAN_ORDER == B_ENDIAN)
+ IMB_convert_rgba_to_abgr(tmpibuf);
+ if(premul) {
+ IMB_premultiply_alpha(tmpibuf);
+ ibuf->flags |= IB_premul;
+ }
+
+ /* assign rect last */
+ if (tmpibuf->rect_float)
+ ibuf->rect_float= tmpibuf->rect_float;
+ else
+ ibuf->rect= tmpibuf->rect;
+ ibuf->mall |= ib_flag;
+ ibuf->flags |= ib_flag;
+
+ tmpibuf->mall &= ~ib_flag;
+ }
+
+ IMB_freeImBuf(tmpibuf);
+
+ return success;
+}
+
+void imb_inittiff(void)
+{
+ if (!(G.f & G_DEBUG))
+ TIFFSetErrorHandler(NULL);
+}
/**
* Loads a TIFF file.
*
- * This function uses the "RGBA Image" support from libtiff, which enables
- * it to load most commonly-encountered TIFF formats. libtiff handles format
- * conversion, color depth conversion, etc.
*
* @param mem: Memory containing the TIFF file.
* @param size: Size of the mem buffer.
@@ -303,118 +464,155 @@ int imb_is_a_tiff(void *mem)
*
* @return: A newly allocated ImBuf structure if successful, otherwise NULL.
*/
-struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
+ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
{
TIFF *image = NULL;
- struct ImBuf *ibuf = NULL;
- struct ImbTIFFMemFile memFile;
+ ImBuf *ibuf = NULL, *hbuf;
+ ImbTIFFMemFile memFile;
uint32 width, height;
- int bytesperpixel, bitspersample;
- int success;
- unsigned int pixel_i, byte_i;
- uint32 *raster = NULL;
- uint32 pixel;
- unsigned char *to = NULL;
-
- memFile.mem = mem;
- memFile.offset = 0;
- memFile.size = size;
+ char *format = NULL;
+ int level;
+ short spp;
+ int ib_depth;
/* check whether or not we have a TIFF file */
- if (size < IMB_TIFF_NCB) {
+ if(size < IMB_TIFF_NCB) {
fprintf(stderr, "imb_loadtiff: size < IMB_TIFF_NCB\n");
return NULL;
}
- if (imb_is_a_tiff(mem) == 0)
+ if(imb_is_a_tiff(mem) == 0)
return NULL;
- /* open the TIFF client layer interface to the in-memory file */
- image = libtiff_TIFFClientOpen("(Blender TIFF Interface Layer)",
- "r", (thandle_t)(&memFile),
- imb_tiff_ReadProc, imb_tiff_WriteProc,
- imb_tiff_SeekProc, imb_tiff_CloseProc,
- imb_tiff_SizeProc, imb_tiff_DummyMapProc, imb_tiff_DummyUnmapProc);
- if (image == NULL) {
+ image = imb_tiff_client_open(&memFile, mem, size);
+
+ if(image == NULL) {
printf("imb_loadtiff: could not open TIFF IO layer.\n");
return NULL;
}
/* allocate the image buffer */
- bytesperpixel = 4; /* 1 byte per channel, 4 channels */
- libtiff_TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);
- libtiff_TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
- libtiff_TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bitspersample);
- ibuf = IMB_allocImBuf(width, height, 8*bytesperpixel, 0, 0);
- if (ibuf) {
+ TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);
+ TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
+ TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);
+
+ ib_depth = (spp==3)?24:32;
+
+ ibuf = IMB_allocImBuf(width, height, ib_depth, 0, 0);
+ if(ibuf) {
ibuf->ftype = TIF;
- ibuf->profile = IB_PROFILE_SRGB;
- } else {
+ }
+ else {
fprintf(stderr,
"imb_loadtiff: could not allocate memory for TIFF " \
"image.\n");
- libtiff_TIFFClose(image);
+ TIFFClose(image);
return NULL;
}
- /* read in the image data */
- if (!(flags & IB_test)) {
+ /* if testing, we're done */
+ if(flags & IB_test) {
+ TIFFClose(image);
+ return ibuf;
+ }
- /* allocate memory for the ibuf->rect */
- imb_addrectImBuf(ibuf);
+ /* detect if we are reading a tiled/mipmapped texture, in that case
+ we don't read pixels but leave it to the cache to load tiles */
+ if(flags & IB_tilecache) {
+ format= NULL;
+ TIFFGetField(image, TIFFTAG_PIXAR_TEXTUREFORMAT, &format);
- /* perform actual read */
- raster = (uint32*)libtiff__TIFFmalloc(
- width*height * sizeof(uint32));
- if (raster == NULL) {
- libtiff_TIFFClose(image);
- return NULL;
- }
- success = libtiff_TIFFReadRGBAImage(
- image, width, height, raster, 0);
- if (!success) {
- fprintf(stderr,
- "imb_loadtiff: This TIFF format is not "
- "currently supported by Blender.\n");
- libtiff__TIFFfree(raster);
- libtiff_TIFFClose(image);
- return NULL;
- }
+ if(format && strcmp(format, "Plain Texture")==0 && TIFFIsTiled(image)) {
+ int numlevel = TIFFNumberOfDirectories(image);
- /* copy raster to ibuf->rect; we do a fast copy if possible,
- * otherwise revert to a slower component-wise copy */
- if (sizeof(unsigned int) == sizeof(uint32)) {
- memcpy(ibuf->rect, raster,
- width*height*sizeof(uint32));
- } else {
- /* this may not be entirely necessary, but is put here
- * in case sizeof(unsigned int) is not a 32-bit
- * quantity */
- fprintf(stderr,
- "imb_loadtiff: using (slower) component-wise "
- "buffer copy.\n");
- to = (unsigned char*)ibuf->rect;
- for (pixel_i=0; pixel_i < width*height; pixel_i++)
- {
- byte_i = sizeof(unsigned int)*pixel_i;
- pixel = raster[pixel_i];
-
- to[byte_i++] = (unsigned char)TIFFGetR(pixel);
- to[byte_i++] = (unsigned char)TIFFGetG(pixel);
- to[byte_i++] = (unsigned char)TIFFGetB(pixel);
- to[byte_i++] = (unsigned char)TIFFGetA(pixel);
+ /* create empty mipmap levels in advance */
+ for(level=0; level<numlevel; level++) {
+ if(!TIFFSetDirectory(image, level))
+ break;
+
+ if(level > 0) {
+ width= (width > 1)? width/2: 1;
+ height= (height > 1)? height/2: 1;
+
+ hbuf= IMB_allocImBuf(width, height, 32, 0, 0);
+ hbuf->miplevel= level;
+ hbuf->ftype= ibuf->ftype;
+ ibuf->mipmap[level-1] = hbuf;
+
+ if(flags & IB_premul)
+ hbuf->flags |= IB_premul;
+ }
+ else
+ hbuf= ibuf;
+
+ hbuf->flags |= IB_tilecache;
+
+ TIFFGetField(image, TIFFTAG_TILEWIDTH, &hbuf->tilex);
+ TIFFGetField(image, TIFFTAG_TILELENGTH, &hbuf->tiley);
+
+ hbuf->xtiles= ceil(hbuf->x/(float)hbuf->tilex);
+ hbuf->ytiles= ceil(hbuf->y/(float)hbuf->tiley);
+
+ imb_addtilesImBuf(hbuf);
+
+ ibuf->miptot++;
}
}
+ }
- libtiff__TIFFfree(raster);
+ /* read pixels */
+ if(!(ibuf->flags & IB_tilecache) && !imb_read_tiff_pixels(ibuf, image, 0)) {
+ fprintf(stderr, "imb_loadtiff: Failed to read tiff image.\n");
+ TIFFClose(image);
+ return NULL;
}
/* close the client layer interface to the in-memory file */
- libtiff_TIFFClose(image);
-
- if (ENDIAN_ORDER == B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
+ TIFFClose(image);
/* return successfully */
- return (ibuf);
+ return ibuf;
+}
+
+void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, int size, int tx, int ty, unsigned int *rect)
+{
+ TIFF *image = NULL;
+ uint32 width, height;
+ ImbTIFFMemFile memFile;
+
+ image = imb_tiff_client_open(&memFile, mem, size);
+
+ if(image == NULL) {
+ printf("imb_loadtiff: could not open TIFF IO layer for loading mipmap level.\n");
+ return;
+ }
+
+ if(TIFFSetDirectory(image, ibuf->miplevel)) {
+ /* allocate the image buffer */
+ TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);
+ TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height);
+
+ if(width == ibuf->x && height == ibuf->y) {
+ if(rect) {
+ /* tiff pixels are bottom to top, tiles are top to bottom */
+ if(TIFFReadRGBATile(image, tx*ibuf->tilex, (ibuf->ytiles - 1 - ty)*ibuf->tiley, rect) == 1) {
+ if(ibuf->tiley > ibuf->y)
+ memmove(rect, rect+ibuf->tilex*(ibuf->tiley - ibuf->y), sizeof(int)*ibuf->tilex*ibuf->y);
+
+ if(ibuf->flags & IB_premul)
+ IMB_premultiply_rect(rect, 32, ibuf->tilex, ibuf->tiley);
+ }
+ else
+ printf("imb_loadtiff: failed to read tiff tile at mipmap level %d\n", ibuf->miplevel);
+ }
+ }
+ else
+ printf("imb_loadtiff: mipmap level %d has unexpected size %dx%d instead of %dx%d\n", ibuf->miplevel, width, height, ibuf->x, ibuf->y);
+ }
+ else
+ printf("imb_loadtiff: could not find mipmap level %d\n", ibuf->miplevel);
+
+ /* close the client layer interface to the in-memory file */
+ TIFFClose(image);
}
/**
@@ -433,9 +631,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
* @return: 1 if the function is successful, 0 on failure.
*/
-#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f))
-
-short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
+int imb_savetiff(ImBuf *ibuf, char *name, int flags)
{
TIFF *image = NULL;
uint16 samplesperpixel, bitspersample;
@@ -446,12 +642,13 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
float *fromf = NULL;
int x, y, from_i, to_i, i;
int extraSampleTypes[1] = { EXTRASAMPLE_ASSOCALPHA };
+
/* check for a valid number of bytes per pixel. Like the PNG writer,
* the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding
* to gray, RGB, RGBA respectively. */
samplesperpixel = (uint16)((ibuf->depth + 7) >> 3);
- if ((samplesperpixel > 4) || (samplesperpixel == 2)) {
+ if((samplesperpixel > 4) || (samplesperpixel == 2)) {
fprintf(stderr,
"imb_savetiff: unsupported number of bytes per "
"pixel: %d\n", samplesperpixel);
@@ -464,17 +661,18 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
bitspersample = 8;
/* open TIFF file for writing */
- if (flags & IB_mem) {
+ if(flags & IB_mem) {
/* bork at the creation of a TIFF in memory */
fprintf(stderr,
"imb_savetiff: creation of in-memory TIFF files is "
"not yet supported.\n");
return (0);
- } else {
+ }
+ else {
/* create image as a file */
- image = libtiff_TIFFOpen(name, "w");
+ image = TIFFOpen(name, "w");
}
- if (image == NULL) {
+ if(image == NULL) {
fprintf(stderr,
"imb_savetiff: could not open TIFF for writing.\n");
return (0);
@@ -483,16 +681,16 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
/* allocate array for pixel data */
npixels = ibuf->x * ibuf->y;
if(bitspersample == 16)
- pixels16 = (unsigned short*)libtiff__TIFFmalloc(npixels *
+ pixels16 = (unsigned short*)_TIFFmalloc(npixels *
samplesperpixel * sizeof(unsigned short));
else
- pixels = (unsigned char*)libtiff__TIFFmalloc(npixels *
+ pixels = (unsigned char*)_TIFFmalloc(npixels *
samplesperpixel * sizeof(unsigned char));
- if (pixels == NULL && pixels16 == NULL) {
+ if(pixels == NULL && pixels16 == NULL) {
fprintf(stderr,
"imb_savetiff: could not allocate pixels array.\n");
- libtiff_TIFFClose(image);
+ TIFFClose(image);
return (0);
}
@@ -507,69 +705,85 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
}
/* setup samples per pixel */
- libtiff_TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bitspersample);
- libtiff_TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
+ TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bitspersample);
+ TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
if(samplesperpixel == 4) {
/* RGBA images */
- libtiff_TIFFSetField(image, TIFFTAG_EXTRASAMPLES, 1,
+ TIFFSetField(image, TIFFTAG_EXTRASAMPLES, 1,
extraSampleTypes);
- libtiff_TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
+ TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
PHOTOMETRIC_RGB);
}
else if(samplesperpixel == 3) {
/* RGB images */
- libtiff_TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
+ TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
PHOTOMETRIC_RGB);
}
else if(samplesperpixel == 1) {
/* greyscale images, 1 channel */
- libtiff_TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
+ TIFFSetField(image, TIFFTAG_PHOTOMETRIC,
PHOTOMETRIC_MINISBLACK);
}
/* copy pixel data. While copying, we flip the image vertically. */
- for (x = 0; x < ibuf->x; x++) {
- for (y = 0; y < ibuf->y; y++) {
+ for(x = 0; x < ibuf->x; x++) {
+ for(y = 0; y < ibuf->y; y++) {
from_i = 4*(y*ibuf->x+x);
to_i = samplesperpixel*((ibuf->y-y-1)*ibuf->x+x);
if(pixels16) {
- for (i = 0; i < samplesperpixel; i++, to_i++, from_i++)
- to16[to_i] = FTOUSHORT(fromf[from_i]);
+ /* convert from float source */
+ float rgb[3];
+
+ if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]);
+ else
+ copy_v3_v3(rgb, &fromf[from_i]);
+
+ to16[to_i+0] = FTOUSHORT(rgb[0]);
+ to16[to_i+1] = FTOUSHORT(rgb[1]);
+ to16[to_i+2] = FTOUSHORT(rgb[2]);
+ to_i += 3; from_i+=3;
+
+ if (samplesperpixel == 4) {
+ to16[to_i+3] = FTOUSHORT(fromf[from_i+3]);
+ to_i++; from_i++;
+ }
}
else {
- for (i = 0; i < samplesperpixel; i++, to_i++, from_i++)
+ for(i = 0; i < samplesperpixel; i++, to_i++, from_i++)
to[to_i] = from[from_i];
}
}
}
/* write the actual TIFF file */
- libtiff_TIFFSetField(image, TIFFTAG_IMAGEWIDTH, ibuf->x);
- libtiff_TIFFSetField(image, TIFFTAG_IMAGELENGTH, ibuf->y);
- libtiff_TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, ibuf->y);
- libtiff_TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
- libtiff_TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
- libtiff_TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
- libtiff_TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
- libtiff_TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
- libtiff_TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
- if (libtiff_TIFFWriteEncodedStrip(image, 0,
+ TIFFSetField(image, TIFFTAG_IMAGEWIDTH, ibuf->x);
+ TIFFSetField(image, TIFFTAG_IMAGELENGTH, ibuf->y);
+ TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, ibuf->y);
+ TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
+ TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
+ TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
+ TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
+ TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
+ if(TIFFWriteEncodedStrip(image, 0,
(bitspersample == 16)? (unsigned char*)pixels16: pixels,
ibuf->x*ibuf->y*samplesperpixel*bitspersample/8) == -1) {
fprintf(stderr,
"imb_savetiff: Could not write encoded TIFF.\n");
- libtiff_TIFFClose(image);
- if(pixels) libtiff__TIFFfree(pixels);
- if(pixels16) libtiff__TIFFfree(pixels16);
+ TIFFClose(image);
+ if(pixels) _TIFFfree(pixels);
+ if(pixels16) _TIFFfree(pixels16);
return (1);
}
/* close the TIFF file */
- libtiff_TIFFClose(image);
- if(pixels) libtiff__TIFFfree(pixels);
- if(pixels16) libtiff__TIFFfree(pixels16);
+ TIFFClose(image);
+ if(pixels) _TIFFfree(pixels);
+ if(pixels16) _TIFFfree(pixels16);
return (1);
}
+#endif /* WITH_TIFF */
diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c
index b1ca414434f..cd447e5e43a 100644
--- a/source/blender/imbuf/intern/util.c
+++ b/source/blender/imbuf/intern/util.c
@@ -42,36 +42,16 @@
#include "BKE_global.h"
#include "imbuf.h"
-#include "imbuf_patch.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
-
-#include "IMB_targa.h"
-#include "IMB_png.h"
-
-#ifdef WITH_DDS
-#include "dds/dds_api.h"
-#endif
-
-#include "IMB_bmp.h"
-#include "IMB_tiff.h"
-#include "IMB_radiance_hdr.h"
-#include "IMB_dpxcineon.h"
+#include "IMB_filetype.h"
#include "IMB_anim.h"
-#ifdef WITH_OPENEXR
-#include "openexr/openexr_api.h"
-#endif
-
#ifdef WITH_QUICKTIME
#include "quicktime_import.h"
#endif
-#ifdef WITH_OPENJPEG
-#include "IMB_jp2.h"
-#endif
-
#ifdef WITH_FFMPEG
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
@@ -88,153 +68,127 @@
#define UTIL_DEBUG 0
-/* from misc_util: flip the bytes from x */
-#define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1])
-
-/* this one is only def-ed once, strangely... */
-#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
+const char *imb_ext_image[] = {
+ ".png",
+ ".tga",
+ ".bmp",
+ ".jpg", ".jpeg",
+ ".sgi", ".rgb", ".rgba",
+#ifdef WITH_TIFF
+ ".tif", ".tiff", ".tx",
+#endif
+#ifdef WITH_OPENJPEG
+ ".jp2",
+#endif
+#ifdef WITH_HDR
+ ".hdr",
+#endif
+#ifdef WITH_DDS
+ ".dds",
+#endif
+#ifdef WITH_CINEON
+ ".dpx",
+ ".cin",
+#endif
+#ifdef WITH_OPENEXR
+ ".exr",
+#endif
+ NULL};
+
+const char *imb_ext_image_qt[] = {
+ ".gif",
+ ".psd",
+ ".pct", ".pict",
+ ".pntg",
+ ".qtif",
+ NULL};
+
+const char *imb_ext_movie[] = {
+ ".avi",
+ ".flc",
+ ".mov",
+ ".movie",
+ ".mp4",
+ ".m4v",
+ ".m2v",
+ ".m2t",
+ ".mts",
+ ".mv",
+ ".avs",
+ ".wmv",
+ ".ogv",
+ ".dv",
+ ".mpeg",
+ ".mpg",
+ ".mpg2",
+ ".vob",
+ ".mkv",
+ ".flv",
+ ".divx",
+ ".xvid",
+ NULL};
+
+/* sort of wrong being here... */
+const char *imb_ext_audio[] = {
+ ".wav",
+ ".ogg",
+ ".oga",
+ ".mp3",
+ ".mp2",
+ ".ac3",
+ ".aac",
+ ".flac",
+ ".wma",
+ ".eac3",
+ NULL};
static int IMB_ispic_name(char *name)
{
+ ImFileType *type;
struct stat st;
int fp, buf[10];
- int ofs = 0;
if(UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name);
- if (ib_stat(name,&st) == -1) return(0);
- if (((st.st_mode) & S_IFMT) == S_IFREG){
- if ((fp = open(name,O_BINARY|O_RDONLY)) >= 0){
- if (read(fp,buf,32)==32){
- close(fp);
- if (buf[ofs] == CAT) ofs += 3;
- if (buf[ofs] == FORM){
- if (buf[ofs + 2] == ILBM) return(AMI);
- if (buf[ofs + 2] == ANIM){
- if (buf[ofs + 3] == FORM){
- return(ANIM);
- }else{
- return(Anim);
- }
- }
- } else {
- if (GS(buf) == IMAGIC) return(IMAGIC);
- if (GSS(buf) == IMAGIC) return(IMAGIC);
- if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0) return(JPG);
-
- /* at windows there are ".ffl" files with the same magic numnber...
- besides that, tim images are not really important anymore! */
- /* if ((BIG_LONG(buf[0]) == 0x10000000) && ((BIG_LONG(buf[1]) & 0xf0ffffff) == 0)) return(TIM); */
-
- }
- if (imb_is_a_png(buf)) return(PNG);
-#ifdef WITH_DDS
- if (imb_is_a_dds((uchar *)buf)) return(DDS);
-#endif
- if (imb_is_a_targa(buf)) return(TGA);
-#ifdef WITH_OPENEXR
- if (imb_is_a_openexr((uchar *)buf)) return(OPENEXR);
-#endif
- if (imb_is_a_tiff(buf)) return(TIF);
- if (imb_is_dpx(buf)) return (DPX);
- if (imb_is_cineon(buf)) return(CINEON);
- /* radhdr: check if hdr format */
- if (imb_is_a_hdr(buf)) return(RADHDR);
-
-/*
- if (imb_is_a_bmp(buf)) return(BMP);
-*/
-
-#ifdef WITH_OPENJPEG
- if (imb_is_a_jp2(buf)) return(JP2);
-#endif
-
-#ifdef WITH_QUICKTIME
-#if defined(_WIN32) || defined(__APPLE__)
- if(G.have_quicktime) {
- if (imb_is_a_quicktime(name)) return(QUICKTIME);
- }
-#endif
-#endif
+ if(stat(name,&st) == -1)
+ return FALSE;
+ if(((st.st_mode) & S_IFMT) != S_IFREG)
+ return FALSE;
- return(FALSE);
- }
- close(fp);
- }
+ if((fp = open(name,O_BINARY|O_RDONLY)) < 0)
+ return FALSE;
+
+ if(read(fp, buf, 32) != 32) {
+ close(fp);
+ return FALSE;
}
- return(FALSE);
-}
+ close(fp);
+ /* XXX move this exception */
+ if((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0)
+ return JPG;
+
+ for(type=IMB_FILE_TYPES; type->is_a; type++)
+ if(type->is_a((uchar*)buf))
+ return type->filetype;
+
+ return FALSE;
+}
int IMB_ispic(char *filename)
{
if(U.uiflag & USER_FILTERFILEEXTS) {
- if (G.have_libtiff && (BLI_testextensie(filename, ".tif")
- || BLI_testextensie(filename, ".tiff"))) {
- return IMB_ispic_name(filename);
+ if( (BLI_testextensie_array(filename, imb_ext_image)) ||
+ (G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt))
+ ) {
+ return IMB_ispic_name(filename);
}
- if (G.have_quicktime){
- if( BLI_testextensie(filename, ".jpg")
- || BLI_testextensie(filename, ".jpeg")
- || BLI_testextensie(filename, ".tif")
- || BLI_testextensie(filename, ".tiff")
- || BLI_testextensie(filename, ".hdr")
- || BLI_testextensie(filename, ".tga")
- || BLI_testextensie(filename, ".rgb")
- || BLI_testextensie(filename, ".bmp")
- || BLI_testextensie(filename, ".png")
-#ifdef WITH_DDS
- || BLI_testextensie(filename, ".dds")
-#endif
- || BLI_testextensie(filename, ".iff")
- || BLI_testextensie(filename, ".lbm")
- || BLI_testextensie(filename, ".gif")
- || BLI_testextensie(filename, ".psd")
- || BLI_testextensie(filename, ".pct")
- || BLI_testextensie(filename, ".pict")
- || BLI_testextensie(filename, ".pntg") //macpaint
- || BLI_testextensie(filename, ".qtif")
- || BLI_testextensie(filename, ".cin")
-#ifdef WITH_BF_OPENEXR
- || BLI_testextensie(filename, ".exr")
-#endif
-#ifdef WITH_BF_OPENJPEG
- || BLI_testextensie(filename, ".jp2")
-#endif
- || BLI_testextensie(filename, ".sgi")) {
- return IMB_ispic_name(filename);
- } else {
- return(FALSE);
- }
- } else { /* no quicktime or libtiff */
- if( BLI_testextensie(filename, ".jpg")
- || BLI_testextensie(filename, ".jpeg")
- || BLI_testextensie(filename, ".hdr")
- || BLI_testextensie(filename, ".tga")
- || BLI_testextensie(filename, ".rgb")
- || BLI_testextensie(filename, ".bmp")
- || BLI_testextensie(filename, ".png")
- || BLI_testextensie(filename, ".cin")
-#ifdef WITH_DDS
- || BLI_testextensie(filename, ".dds")
-#endif
-#ifdef WITH_BF_OPENEXR
- || BLI_testextensie(filename, ".exr")
-#endif
-#ifdef WITH_BF_OPENJPEG
- || BLI_testextensie(filename, ".jp2")
-#endif
- || BLI_testextensie(filename, ".iff")
- || BLI_testextensie(filename, ".lbm")
- || BLI_testextensie(filename, ".sgi")) {
- return IMB_ispic_name(filename);
- }
- else {
- return(FALSE);
- }
+ else {
+ return FALSE;
}
- } else { /* no FILTERFILEEXTS */
+ }
+ else { /* no FILTERFILEEXTS */
return IMB_ispic_name(filename);
}
}
@@ -391,14 +345,14 @@ int imb_get_anim_type(char * name) {
/* stat test below fails on large files > 4GB */
if (isffmpeg(name)) return (ANIM_FFMPEG);
# endif
- if (ib_stat(name,&st) == -1) return(0);
+ if (stat(name,&st) == -1) return(0);
if (((st.st_mode) & S_IFMT) != S_IFREG) return(0);
if (isavi(name)) return (ANIM_AVI);
if (ismovie(name)) return (ANIM_MOVIE);
#else
- if (ib_stat(name,&st) == -1) return(0);
+ if (stat(name,&st) == -1) return(0);
if (((st.st_mode) & S_IFMT) != S_IFREG) return(0);
if (ismovie(name)) return (ANIM_MOVIE);
@@ -414,7 +368,6 @@ int imb_get_anim_type(char * name) {
if (isredcode(name)) return (ANIM_REDCODE);
#endif
type = IMB_ispic(name);
- if (type == ANIM) return (ANIM_ANIM5);
if (type) return(ANIM_SEQUENCE);
return(0);
}
diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c
index 808fbc25c24..b55ce4b1df4 100644
--- a/source/blender/imbuf/intern/writeimage.c
+++ b/source/blender/imbuf/intern/writeimage.c
@@ -31,180 +31,32 @@
#include <stdio.h>
-#include "BKE_global.h"
-#include "BLI_blenlib.h"
-
-#include "imbuf.h"
-#include "imbuf_patch.h"
-
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
+#include "IMB_filetype.h"
-#include "IMB_allocimbuf.h"
-
-#include "IMB_dpxcineon.h"
-#include "IMB_targa.h"
-#include "IMB_jpeg.h"
-#include "IMB_iris.h"
-#include "IMB_ham.h"
-#include "IMB_hamx.h"
-#include "IMB_amiga.h"
-#include "IMB_png.h"
-#include "IMB_bmp.h"
-#include "IMB_radiance_hdr.h"
-
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
-#include "IMB_cocoa.h"
-#else
-#include "IMB_tiff.h"
-#endif
-
-#ifdef WITH_OPENJPEG
-#include "IMB_jp2.h"
-#endif
-
-#ifdef WITH_OPENEXR
-#include "openexr/openexr_api.h"
-#endif
-
-#ifdef WITH_DDS
-#include "dds/dds_api.h"
-#endif
-
-#include "IMB_iff.h"
-#include "IMB_bitplanes.h"
-#include "IMB_divers.h"
-
-#ifdef WIN32
-#include <io.h>
-#include "BLI_winstuff.h"
-#endif
-/* added facility to copy with saving non-float rects */
+#include "imbuf.h"
short IMB_saveiff(struct ImBuf *ibuf, char *name, int flags)
{
- short ok=TRUE,delpl=FALSE;
- int file = -1;
+ ImFileType *type;
- if (ibuf==0) return (FALSE);
+ if(ibuf == NULL) return (FALSE);
ibuf->flags = flags;
- /* Put formats that take a filename here */
- if (IS_jpg(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_savejpeg(ibuf, name, flags);
- }
- if (IS_radhdr(ibuf)) {
- return imb_savehdr(ibuf, name, flags);
- }
- if (IS_png(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_savepng(ibuf, name, flags);
- }
- if (IS_bmp(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_savebmp(ibuf, name, flags);
- }
- if (IS_tga(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_savetarga(ibuf, name, flags);
- }
- if (IS_iris(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_saveiris(ibuf, name, flags);
- }
-
-#if defined(__APPLE__) && defined(IMBUF_COCOA)
- if (IS_tiff(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_cocoaSaveImage(ibuf, name, flags);
- }
-#else
- if (G.have_libtiff && IS_tiff(ibuf)) {
- if(ibuf->rect==NULL && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
- return imb_savetiff(ibuf, name, flags);
- }
-#endif
-
-#ifdef WITH_OPENEXR
- if (IS_openexr(ibuf)) {
- return imb_save_openexr(ibuf, name, flags);
- }
-#endif
-/* not supported yet
-#ifdef WITH_DDS
- if (IS_dds(ibuf)) {
- return imb_save_dds(ibuf, name, flags);
- }
-#endif
-*/
- if (IS_cineon(ibuf)) {
- return imb_savecineon(ibuf, name, flags);
-
- }
- if (IS_dpx(ibuf)) {
- return imb_save_dpx(ibuf, name, flags);
- }
-#ifdef WITH_OPENJPEG
- if (IS_jp2(ibuf)) {
- return imb_savejp2(ibuf, name, flags);
- }
-#endif
- file = open(name, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
- if (file < 0) return (FALSE);
-
- if (flags & IB_rect){
- if (ibuf->cmap){
- imb_checkncols(ibuf);
- }
- }
-
- /* Put formats that take a filehandle here */
- ok = imb_start_iff(ibuf,file);
- if (IS_amiga(ibuf)){
- IMB_flipy(ibuf);
- if (flags & IB_rect){
- if ((flags & IB_cmap) == 0) {
- if (IS_ham(ibuf)){
- if (ok) ok = imb_converttoham(ibuf);
- }else if (ibuf->cmap){
- if (ok) ok = IMB_converttocmap(ibuf);
- }
+ for(type=IMB_FILE_TYPES; type->is_a; type++) {
+ if(type->save && type->ftype(type, ibuf)) {
+ if(!(type->flag & IM_FTYPE_FLOAT)) {
+ if(ibuf->rect==NULL && ibuf->rect_float)
+ IMB_rect_from_float(ibuf);
}
- if (ok){
- if (ibuf->planes==0){
- delpl=TRUE;
- ok=imb_addplanesImBuf(ibuf);
- }
- imb_longtobp(ibuf);
- }
- }
- if (flags & IB_vert){
- if (ok) ok = imb_encodebodyv(ibuf,file);
- }
- else{
- if (ok) ok = imb_encodebodyh(ibuf,file);
+ return type->save(ibuf, name, flags);
}
- if (ok) ok = imb_update_iff(file,BODY);
- }else if (IS_anim(ibuf)) {
- if (ok) ok = imb_enc_anim(ibuf, file);
- if (ok) ok = imb_update_iff(file, BODY);
}
- close(file);
- if (ok==FALSE) {
- fprintf(stderr,"Couldn't save picture.\n");
- }
- if (delpl) imb_freeplanesImBuf(ibuf);
+ fprintf(stderr, "Couldn't save picture.\n");
- return (ok);
+ return FALSE;
}