Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine. Imbuf module: some small refactoring and removing a lot of unused or old code (about 6.5k lines). * Added a ImFileType struct with callbacks to make adding an file format type, or making changes to the API easier. * Move imbuf init/exit code into IMB_init()/IMB_exit() functions. * Increased mipmap levels from 10 to 20, you run into this limit already with a 2k image. * Removed hamx, amiga, anim5 format support. * Removed colormap saving, only simple colormap code now for reading tga. * Removed gen_dynlibtiff.py, editing this is almost as much work as just editing the code directly. * Functions removed that were only used for sequencer plugin API: IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp, IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace, IMB_dit0, IMB_dit2, IMB_cspace * Write metadata info into OpenEXR images. Can be viewed with the command line utility 'exrheader' For the image tile cache code, see this page: http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
This commit is contained in:
@@ -55,7 +55,6 @@ int BKE_imtype_is_movie(int imtype);
|
||||
|
||||
struct anim *openanim(char * name, int flags);
|
||||
|
||||
void converttopremul(struct ImBuf *ibuf);
|
||||
void image_de_interlace(struct Image *ima, int odd);
|
||||
|
||||
void tag_image_time(struct Image *ima);
|
||||
|
||||
@@ -100,7 +100,7 @@ void free_blender(void)
|
||||
|
||||
BKE_spacetypes_free(); /* after free main, it uses space callbacks */
|
||||
|
||||
IMB_freeImBufdata(); /* imbuf lib */
|
||||
IMB_exit();
|
||||
|
||||
free_nodesystem();
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ void detectBitmapFont(ImBuf *ibuf)
|
||||
unsigned short version;
|
||||
int i;
|
||||
|
||||
if (ibuf != NULL) {
|
||||
if (ibuf != NULL && ibuf->rect != NULL) {
|
||||
// bitmap must have an x size that is a power of two
|
||||
if (is_power_of_two(ibuf->x)) {
|
||||
rect = (unsigned char *) (ibuf->rect + (ibuf->x * (ibuf->y - 1)));
|
||||
|
||||
@@ -92,58 +92,6 @@
|
||||
|
||||
/* ******** IMAGE PROCESSING ************* */
|
||||
|
||||
/* used by sequencer and image premul option - IMA_DO_PREMUL */
|
||||
void converttopremul(struct ImBuf *ibuf)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if(ibuf==0) return;
|
||||
if (ibuf->rect) {
|
||||
int val;
|
||||
char *cp;
|
||||
if(ibuf->depth==24) { /* put alpha at 255 */
|
||||
cp= (char *)(ibuf->rect);
|
||||
for(y=0; y<ibuf->y; y++) {
|
||||
for(x=0; x<ibuf->x; x++, cp+=4) {
|
||||
cp[3]= 255;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cp= (char *)(ibuf->rect);
|
||||
for(y=0; y<ibuf->y; y++) {
|
||||
for(x=0; x<ibuf->x; x++, cp+=4) {
|
||||
val= cp[3];
|
||||
cp[0]= (cp[0]*val)>>8;
|
||||
cp[1]= (cp[1]*val)>>8;
|
||||
cp[2]= (cp[2]*val)>>8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ibuf->rect_float) {
|
||||
float val;
|
||||
float *cp;
|
||||
if(ibuf->depth==24) { /* put alpha at 1.0 */
|
||||
cp= ibuf->rect_float;;
|
||||
for(y=0; y<ibuf->y; y++) {
|
||||
for(x=0; x<ibuf->x; x++, cp+=4) {
|
||||
cp[3]= 1.0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cp= ibuf->rect_float;
|
||||
for(y=0; y<ibuf->y; y++) {
|
||||
for(x=0; x<ibuf->x; x++, cp+=4) {
|
||||
val= cp[3];
|
||||
cp[0]= cp[0]*val;
|
||||
cp[1]= cp[1]*val;
|
||||
cp[2]= cp[2]*val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void de_interlace_ng(struct ImBuf *ibuf) /* neogeo fields */
|
||||
{
|
||||
struct ImBuf * tbuf1, * tbuf2;
|
||||
@@ -735,8 +683,6 @@ int BKE_imtype_to_ftype(int imtype)
|
||||
return TGA;
|
||||
else if(imtype==R_RAWTGA)
|
||||
return RAWTGA;
|
||||
else if(imtype==R_HAMX)
|
||||
return AN_hamx;
|
||||
#ifdef WITH_OPENJPEG
|
||||
else if(imtype==R_JP2)
|
||||
return JP2;
|
||||
@@ -773,8 +719,6 @@ int BKE_ftype_to_imtype(int ftype)
|
||||
return R_TARGA;
|
||||
else if(ftype & RAWTGA)
|
||||
return R_RAWTGA;
|
||||
else if(ftype == AN_hamx)
|
||||
return R_HAMX;
|
||||
#ifdef WITH_OPENJPEG
|
||||
else if(ftype & JP2)
|
||||
return R_JP2;
|
||||
@@ -787,7 +731,6 @@ int BKE_ftype_to_imtype(int ftype)
|
||||
int BKE_imtype_is_movie(int imtype)
|
||||
{
|
||||
switch(imtype) {
|
||||
case R_MOVIE:
|
||||
case R_AVIRAW:
|
||||
case R_AVIJPEG:
|
||||
case R_AVICODEC:
|
||||
@@ -864,7 +807,7 @@ void BKE_add_image_extension(char *string, int imtype)
|
||||
extension= ".jp2";
|
||||
}
|
||||
#endif
|
||||
else { // R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90, R_QUICKTIME etc
|
||||
else { // R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90, R_QUICKTIME etc
|
||||
if(!( BLI_testextensie(string, ".jpg") || BLI_testextensie(string, ".jpeg")))
|
||||
extension= ".jpg";
|
||||
}
|
||||
@@ -1211,15 +1154,15 @@ void BKE_stamp_info(Scene *scene, struct ImBuf *ibuf)
|
||||
/* fill all the data values, no prefix */
|
||||
stampdata(scene, &stamp_data, 0);
|
||||
|
||||
if (stamp_data.file[0]) IMB_imginfo_change_field (ibuf, "File", stamp_data.file);
|
||||
if (stamp_data.note[0]) IMB_imginfo_change_field (ibuf, "Note", stamp_data.note);
|
||||
if (stamp_data.date[0]) IMB_imginfo_change_field (ibuf, "Date", stamp_data.date);
|
||||
if (stamp_data.marker[0]) IMB_imginfo_change_field (ibuf, "Marker", stamp_data.marker);
|
||||
if (stamp_data.time[0]) IMB_imginfo_change_field (ibuf, "Time", stamp_data.time);
|
||||
if (stamp_data.frame[0]) IMB_imginfo_change_field (ibuf, "Frame", stamp_data.frame);
|
||||
if (stamp_data.camera[0]) IMB_imginfo_change_field (ibuf, "Camera", stamp_data.camera);
|
||||
if (stamp_data.scene[0]) IMB_imginfo_change_field (ibuf, "Scene", stamp_data.scene);
|
||||
if (stamp_data.strip[0]) IMB_imginfo_change_field (ibuf, "Strip", stamp_data.strip);
|
||||
if (stamp_data.file[0]) IMB_metadata_change_field (ibuf, "File", stamp_data.file);
|
||||
if (stamp_data.note[0]) IMB_metadata_change_field (ibuf, "Note", stamp_data.note);
|
||||
if (stamp_data.date[0]) IMB_metadata_change_field (ibuf, "Date", stamp_data.date);
|
||||
if (stamp_data.marker[0]) IMB_metadata_change_field (ibuf, "Marker", stamp_data.marker);
|
||||
if (stamp_data.time[0]) IMB_metadata_change_field (ibuf, "Time", stamp_data.time);
|
||||
if (stamp_data.frame[0]) IMB_metadata_change_field (ibuf, "Frame", stamp_data.frame);
|
||||
if (stamp_data.camera[0]) IMB_metadata_change_field (ibuf, "Camera", stamp_data.camera);
|
||||
if (stamp_data.scene[0]) IMB_metadata_change_field (ibuf, "Scene", stamp_data.scene);
|
||||
if (stamp_data.strip[0]) IMB_metadata_change_field (ibuf, "Strip", stamp_data.strip);
|
||||
}
|
||||
|
||||
int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, char *name, int imtype, int subimtype, int quality)
|
||||
@@ -1273,9 +1216,6 @@ int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, char *name, int imtype, int subimt
|
||||
else if(imtype==R_RAWTGA) {
|
||||
ibuf->ftype= RAWTGA;
|
||||
}
|
||||
else if(imtype==R_HAMX) {
|
||||
ibuf->ftype= AN_hamx;
|
||||
}
|
||||
#ifdef WITH_OPENJPEG
|
||||
else if(imtype==R_JP2) {
|
||||
if(quality < 10) quality= 90;
|
||||
@@ -1299,7 +1239,7 @@ int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, char *name, int imtype, int subimt
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
/* R_JPEG90, R_MOVIE, etc. default we save jpegs */
|
||||
/* R_JPEG90, etc. default we save jpegs */
|
||||
if(quality < 10) quality= 90;
|
||||
ibuf->ftype= JPG|quality;
|
||||
if(ibuf->depth==32) ibuf->depth= 24; /* unsupported feature only confuses other s/w */
|
||||
@@ -1595,6 +1535,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
|
||||
struct ImBuf *ibuf;
|
||||
unsigned short numlen;
|
||||
char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];
|
||||
int flag;
|
||||
|
||||
/* XXX temp stuff? */
|
||||
if(ima->lastframe != frame)
|
||||
@@ -1611,8 +1552,12 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
|
||||
else
|
||||
BLI_path_abs(name, G.sce);
|
||||
|
||||
flag= IB_rect|IB_multilayer;
|
||||
if(ima->flag & IMA_DO_PREMUL)
|
||||
flag |= IB_premul;
|
||||
|
||||
/* read ibuf */
|
||||
ibuf = IMB_loadiffname(name, IB_rect|IB_multilayer);
|
||||
ibuf = IMB_loadiffname(name, flag);
|
||||
if(G.f & G_DEBUG) printf("loaded %s\n", name);
|
||||
|
||||
if (ibuf) {
|
||||
@@ -1632,10 +1577,6 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
|
||||
image_initialize_after_load(ima, ibuf);
|
||||
image_assign_ibuf(ima, ibuf, 0, frame);
|
||||
#endif
|
||||
|
||||
if(ima->flag & IMA_DO_PREMUL)
|
||||
converttopremul(ibuf);
|
||||
|
||||
}
|
||||
else
|
||||
ima->ok= 0;
|
||||
@@ -1718,7 +1659,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame)
|
||||
else
|
||||
BLI_path_abs(str, G.sce);
|
||||
|
||||
ima->anim = openanim(str, IB_cmap | IB_rect);
|
||||
ima->anim = openanim(str, IB_rect);
|
||||
|
||||
/* let's initialize this user */
|
||||
if(ima->anim && iuser && iuser->frames==0)
|
||||
@@ -1749,21 +1690,25 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame)
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
/* cfra used for # code, Image can only have this # for all its users */
|
||||
/* cfra used for # code, Image can only have this # for all its users
|
||||
* warning, 'iuser' can be NULL */
|
||||
static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
|
||||
{
|
||||
struct ImBuf *ibuf;
|
||||
char str[FILE_MAX];
|
||||
int assign = 0;
|
||||
int assign = 0, flag;
|
||||
|
||||
/* always ensure clean ima */
|
||||
image_free_buffers(ima);
|
||||
|
||||
/* is there a PackedFile with this image ? */
|
||||
if (ima->packedfile) {
|
||||
ibuf = IMB_ibImageFromMemory((int *) ima->packedfile->data, ima->packedfile->size, IB_rect|IB_multilayer);
|
||||
ibuf = IMB_ibImageFromMemory((unsigned char*)ima->packedfile->data, ima->packedfile->size, IB_rect|IB_multilayer);
|
||||
}
|
||||
else {
|
||||
flag= IB_rect|IB_multilayer|IB_metadata;
|
||||
if(ima->flag & IMA_DO_PREMUL)
|
||||
flag |= IB_premul;
|
||||
|
||||
/* get the right string */
|
||||
BLI_strncpy(str, ima->name, sizeof(str));
|
||||
@@ -1775,7 +1720,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
|
||||
BLI_path_frame(str, cfra, 0);
|
||||
|
||||
/* read ibuf */
|
||||
ibuf = IMB_loadiffname(str, IB_rect|IB_multilayer|IB_imginfo);
|
||||
ibuf = IMB_loadiffname(str, flag);
|
||||
}
|
||||
|
||||
if (ibuf) {
|
||||
@@ -1797,9 +1742,6 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
|
||||
if ((ima->packedfile == NULL) && (G.fileflags & G_AUTOPACK))
|
||||
ima->packedfile = newPackedFile(NULL, str);
|
||||
}
|
||||
|
||||
if(ima->flag & IMA_DO_PREMUL)
|
||||
converttopremul(ibuf);
|
||||
}
|
||||
else
|
||||
ima->ok= 0;
|
||||
|
||||
@@ -264,38 +264,6 @@ int multiresModifier_reshapeFromDeformMod(MultiresModifierData *mmd, Object *ob,
|
||||
return result;
|
||||
}
|
||||
|
||||
static void multires_set_tot_mdisps(Mesh *me, int lvl)
|
||||
{
|
||||
MDisps *mdisps= CustomData_get_layer(&me->fdata, CD_MDISPS);
|
||||
int i;
|
||||
|
||||
if(mdisps) {
|
||||
for(i = 0; i < me->totface; i++) {
|
||||
if(mdisps[i].totdisp == 0) {
|
||||
int nvert = (me->mface[i].v4)? 4: 3;
|
||||
mdisps[i].totdisp = multires_grid_tot[lvl]*nvert;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void multires_reallocate_mdisps(Mesh *me, MDisps *mdisps, int lvl)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* reallocate displacements to be filled in */
|
||||
for(i = 0; i < me->totface; ++i) {
|
||||
int nvert = (me->mface[i].v4)? 4: 3;
|
||||
int totdisp = multires_grid_tot[lvl]*nvert;
|
||||
float (*disps)[3] = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps");
|
||||
|
||||
if(mdisps[i].disps)
|
||||
MEM_freeN(mdisps[i].disps);
|
||||
|
||||
mdisps[i].disps = disps;
|
||||
mdisps[i].totdisp = totdisp;
|
||||
}
|
||||
}
|
||||
|
||||
static void column_vectors_to_mat3(float mat[][3], float v1[3], float v2[3], float v3[3])
|
||||
{
|
||||
@@ -352,7 +320,6 @@ void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int dire
|
||||
int levels = mmd->totlvl - lvl;
|
||||
MDisps *mdisps;
|
||||
|
||||
multires_set_tot_mdisps(me, mmd->totlvl);
|
||||
CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
|
||||
mdisps= CustomData_get_layer(&me->fdata, CD_MDISPS);
|
||||
|
||||
@@ -426,6 +393,24 @@ static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl
|
||||
return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0);
|
||||
}
|
||||
|
||||
static void multires_reallocate_mdisps(Mesh *me, MDisps *mdisps, int lvl)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* reallocate displacements to be filled in */
|
||||
for(i = 0; i < me->totface; ++i) {
|
||||
int nvert = (me->mface[i].v4)? 4: 3;
|
||||
int totdisp = multires_grid_tot[lvl]*nvert;
|
||||
float (*disps)[3] = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps");
|
||||
|
||||
if(mdisps[i].disps)
|
||||
MEM_freeN(mdisps[i].disps);
|
||||
|
||||
mdisps[i].disps = disps;
|
||||
mdisps[i].totdisp = totdisp;
|
||||
}
|
||||
}
|
||||
|
||||
void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int updateblock, int simple)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
@@ -630,7 +615,6 @@ static void multiresModifier_update(DerivedMesh *dm)
|
||||
ob = ccgdm->multires.ob;
|
||||
me = ccgdm->multires.ob->data;
|
||||
mmd = ccgdm->multires.mmd;
|
||||
multires_set_tot_mdisps(me, mmd->totlvl);
|
||||
CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
|
||||
mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
|
||||
|
||||
@@ -766,7 +750,6 @@ DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int loca
|
||||
memcpy(subGridData[i], gridData[i], sizeof(DMGridData)*gridSize*gridSize);
|
||||
}
|
||||
|
||||
multires_set_tot_mdisps(me, mmd->totlvl);
|
||||
CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
|
||||
multiresModifier_disp_run(result, ob->data, 0, 0, subGridData, mmd->totlvl);
|
||||
|
||||
|
||||
@@ -1777,7 +1777,7 @@ static void input_preprocess(Scene *scene, Sequence *seq, TStripElem *se, int cf
|
||||
|
||||
if(seq->flag & SEQ_MAKE_PREMUL) {
|
||||
if(se->ibuf->depth == 32 && se->ibuf->zbuf == 0) {
|
||||
converttopremul(se->ibuf);
|
||||
IMB_premultiply_alpha(se->ibuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,11 +75,6 @@ bMovieHandle *BKE_get_movie_handle(int imtype)
|
||||
mh.get_movie_path = filepath_avi;
|
||||
|
||||
/* do the platform specific handles */
|
||||
#ifdef __sgi
|
||||
if (imtype == R_MOVIE) {
|
||||
|
||||
}
|
||||
#endif
|
||||
#if defined(_WIN32) && !defined(FREE_WINDOWS)
|
||||
if (imtype == R_AVICODEC) {
|
||||
//XXX mh.start_movie= start_avi_codec;
|
||||
|
||||
@@ -71,6 +71,7 @@ MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f);
|
||||
MINLINE void mul_v2_v2(float r[2], const float a[2]);
|
||||
MINLINE void mul_v3_v3(float r[3], const float a[3]);
|
||||
MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]);
|
||||
MINLINE void mul_v4_fl(float r[4], float f);
|
||||
|
||||
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
|
||||
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
|
||||
|
||||
@@ -33,11 +33,6 @@
|
||||
#ifndef BLI_UTIL_H
|
||||
#define BLI_UTIL_H
|
||||
|
||||
/* XXX doesn't seem to be used, marded for removal
|
||||
#define mallocstructN(x,y,name) (x*)MEM_mallocN((y)* sizeof(x),name)
|
||||
#define callocstructN(x,y,name) (x*)MEM_callocN((y)* sizeof(x),name)
|
||||
*/
|
||||
|
||||
struct ListBase;
|
||||
struct direntry;
|
||||
|
||||
@@ -61,6 +56,7 @@ void BLI_join_dirfile(char *string, const char *dir, const char *file);
|
||||
int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir);
|
||||
void BLI_getlastdir(const char* dir, char *last, int maxlen);
|
||||
int BLI_testextensie(const char *str, const char *ext);
|
||||
int BLI_replace_extension(char *path, int maxlen, const char *ext);
|
||||
void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);
|
||||
void BLI_newname(char * name, int add);
|
||||
int BLI_stringdec(const char *string, char *head, char *start, unsigned short *numlen);
|
||||
|
||||
@@ -76,5 +76,8 @@ struct LinkNode *BLI_read_file_as_lines(char *name);
|
||||
*/
|
||||
void BLI_free_file_lines(struct LinkNode *lines);
|
||||
|
||||
/* Compare if one was last modified before the other */
|
||||
int BLI_file_older(const char *file1, const char *file2);
|
||||
|
||||
#endif /* BLI_STORAGE_H */
|
||||
|
||||
|
||||
@@ -188,6 +188,14 @@ MINLINE void mul_v3_v3(float r[3], const float a[3])
|
||||
r[2] *= a[2];
|
||||
}
|
||||
|
||||
MINLINE void mul_v4_fl(float r[4], float f)
|
||||
{
|
||||
r[0]*= f;
|
||||
r[1]*= f;
|
||||
r[2]*= f;
|
||||
r[3]*= f;
|
||||
}
|
||||
|
||||
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
|
||||
{
|
||||
r[0] += a[0]*f;
|
||||
|
||||
@@ -1109,6 +1109,24 @@ int BLI_testextensie(const char *str, const char *ext)
|
||||
return (retval);
|
||||
}
|
||||
|
||||
int BLI_replace_extension(char *path, int maxlen, const char *ext)
|
||||
{
|
||||
int a;
|
||||
|
||||
for(a=strlen(path)-1; a>=0; a--)
|
||||
if(path[a] == '.' || path[a] == '/' || path[a] == '\\')
|
||||
break;
|
||||
|
||||
if(path[a] != '.')
|
||||
a= strlen(path);
|
||||
|
||||
if(a + strlen(ext) >= maxlen)
|
||||
return 0;
|
||||
|
||||
strcpy(path+a, ext);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Converts "/foo/bar.txt" to "/foo/" and "bar.txt"
|
||||
* - wont change 'string'
|
||||
* - wont create any directories
|
||||
|
||||
@@ -500,3 +500,14 @@ void BLI_free_file_lines(LinkNode *lines)
|
||||
{
|
||||
BLI_linklist_free(lines, (void(*)(void*)) MEM_freeN);
|
||||
}
|
||||
|
||||
int BLI_file_older(const char *file1, const char *file2)
|
||||
{
|
||||
struct stat st1, st2;
|
||||
|
||||
if(stat(file1, &st1)) return 0;
|
||||
if(stat(file2, &st2)) return 0;
|
||||
|
||||
return (st1.st_mtime < st2.st_mtime);
|
||||
}
|
||||
|
||||
|
||||
@@ -8453,8 +8453,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
ima->flag |= IMA_FIELDS;
|
||||
if(tex->imaflag & TEX_STD_FIELD_)
|
||||
ima->flag |= IMA_STD_FIELD;
|
||||
if(tex->imaflag & TEX_ANTIALI_)
|
||||
ima->flag |= IMA_ANTIALI;
|
||||
}
|
||||
tex->iuser.frames= tex->frames;
|
||||
tex->iuser.fie_ima= tex->fie_ima;
|
||||
|
||||
@@ -35,123 +35,19 @@
|
||||
#include "util.h"
|
||||
#include "externdef.h"
|
||||
|
||||
#define IB_rect (1 << 0)
|
||||
#define IB_planes (1 << 1)
|
||||
#define IB_cmap (1 << 2)
|
||||
#define IB_test (1 << 7)
|
||||
struct ImMetaData;
|
||||
|
||||
#define IB_fields (1 << 11)
|
||||
#define IB_yuv (1 << 12)
|
||||
#define IB_zbuf (1 << 13)
|
||||
#define IB_rgba (1 << 14)
|
||||
|
||||
#define JP2 (1 << 18)
|
||||
|
||||
#define AMI (1 << 31)
|
||||
#define PNG (1 << 30)
|
||||
#define Anim (1 << 29)
|
||||
#define TGA (1 << 28)
|
||||
#define JPG (1 << 27)
|
||||
#define BMP (1 << 26)
|
||||
#ifdef WITH_QUICKTIME
|
||||
#define QUICKTIME (1 << 25)
|
||||
#endif
|
||||
#define RADHDR (1<<24)
|
||||
|
||||
#define RAWTGA (TGA | 1)
|
||||
|
||||
#define JPG_STD (JPG | (0 << 8))
|
||||
#define JPG_VID (JPG | (1 << 8))
|
||||
#define JPG_JST (JPG | (2 << 8))
|
||||
#define JPG_MAX (JPG | (3 << 8))
|
||||
#define JPG_MSK (0xffffff00)
|
||||
|
||||
#define AM_ham (0x0800 | AMI)
|
||||
#define AM_hbrite (0x0080 | AMI)
|
||||
#define AM_lace (0x0004 | AMI)
|
||||
#define AM_hires (0x8000 | AMI)
|
||||
#define AM_hblace (AM_hbrite | AM_lace)
|
||||
#define AM_hilace (AM_hires | AM_lace)
|
||||
#define AM_hamlace (AM_ham | AM_lace)
|
||||
|
||||
#define RGB888 1
|
||||
#define RGB555 2
|
||||
#define DYUV 3
|
||||
#define CLUT8 4
|
||||
#define CLUT7 5
|
||||
#define CLUT4 6
|
||||
#define CLUT3 7
|
||||
#define RL7 8
|
||||
#define RL3 9
|
||||
#define MPLTE 10
|
||||
|
||||
#define DYUV1 0
|
||||
#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 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_lace(x) ((x->ftype & AM_lace) == AM_lace)
|
||||
#define IS_hires(x) ((x->ftype & AM_hires) == AM_hires)
|
||||
#define IS_hblace(x) ((x->ftype & AM_hblace) == AM_hblace)
|
||||
#define IS_hilace(x) ((x->ftype & AM_hilace) == AM_hilace)
|
||||
#define IS_hamlace(x) ((x->ftype & AM_hamlace) == AM_hamlace)
|
||||
|
||||
#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_bmp(x) (x->ftype & BMP)
|
||||
#define IS_radhdr(x) (x->ftype & RADHDR)
|
||||
#define IS_tim(x) (x->ftype & TIM)
|
||||
#define IS_tiff(x) (x->ftype & TIFF)
|
||||
#define IS_openexr(x) (x->ftype & OPENEXR)
|
||||
#define IS_jp2(x) (x->ftype & JP2)
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
#define AN_INIT an_stringdec = stringdec; an_stringenc = stringenc;
|
||||
|
||||
#define IB_MIPMAP_LEVELS 10
|
||||
|
||||
struct MEM_CacheLimiterHandle_s;
|
||||
#define IB_MIPMAP_LEVELS 20
|
||||
#define IB_FILENAME_SIZE 1023
|
||||
|
||||
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 **planes; /**< bitplanes */
|
||||
unsigned int *crect; /**< color corrected pixel values stored here */
|
||||
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 */
|
||||
@@ -159,34 +55,43 @@ typedef struct ImBuf {
|
||||
unsigned int encodedsize; /**< Size of data written to encodedbuffer */
|
||||
unsigned int encodedbuffersize; /**< Size of encodedbuffer */
|
||||
|
||||
float *rect_float; /**< floating point Rect equivilant */
|
||||
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 */
|
||||
|
||||
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 */
|
||||
|
||||
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 miplevels;
|
||||
|
||||
/* externally used flags */
|
||||
int index; /* reference index for ImBuf lists */
|
||||
int userflags; /* used to set imbuf to dirty and other stuff */
|
||||
struct ImMetaData *metadata;
|
||||
|
||||
/* file information */
|
||||
int ftype; /* file type we are going to save as */
|
||||
char name[IB_FILENAME_SIZE]; /* filename associated with this image */
|
||||
|
||||
/* memory cache limiter */
|
||||
struct MEM_CacheLimiterHandle_s *c_handle; /* handle for cache limiter */
|
||||
int refcounter; /* reference counter for multiple users */
|
||||
} ImBuf;
|
||||
|
||||
LIBIMPORT struct ImBuf *allocImBuf(short,short,uchar,uint,uchar);
|
||||
LIBIMPORT struct ImBuf *dupImBuf(struct ImBuf *);
|
||||
LIBIMPORT void freeImBuf(struct ImBuf*);
|
||||
|
||||
LIBIMPORT short converttocmap(struct ImBuf* ibuf);
|
||||
|
||||
LIBIMPORT short saveiff(struct ImBuf *,char *,int);
|
||||
|
||||
LIBIMPORT struct ImBuf *loadiffmem(int *,int);
|
||||
LIBIMPORT struct ImBuf *loadifffile(int,int);
|
||||
LIBIMPORT struct ImBuf *loadiffname(char *,int);
|
||||
LIBIMPORT struct ImBuf *testiffname(char *,int);
|
||||
|
||||
LIBIMPORT struct ImBuf *onehalf(struct ImBuf *);
|
||||
LIBIMPORT struct ImBuf *onethird(struct ImBuf *);
|
||||
LIBIMPORT struct ImBuf *halflace(struct ImBuf *);
|
||||
LIBIMPORT struct ImBuf *half_x(struct ImBuf *);
|
||||
LIBIMPORT struct ImBuf *half_y(struct ImBuf *);
|
||||
LIBIMPORT struct ImBuf *double_x(struct ImBuf *);
|
||||
@@ -196,17 +101,11 @@ LIBIMPORT struct ImBuf *double_fast_y(struct ImBuf *);
|
||||
|
||||
LIBIMPORT int ispic(char *);
|
||||
|
||||
LIBIMPORT void dit2(struct ImBuf *, short, short);
|
||||
LIBIMPORT void dit0(struct ImBuf *, short, short);
|
||||
|
||||
LIBIMPORT struct ImBuf *scaleImBuf(struct ImBuf *, short, short);
|
||||
LIBIMPORT struct ImBuf *scalefastImBuf(struct ImBuf *, short, short);
|
||||
LIBIMPORT struct ImBuf *scalefieldImBuf(struct ImBuf *, short, short);
|
||||
LIBIMPORT struct ImBuf *scalefastfieldImBuf(struct ImBuf *, short, short);
|
||||
|
||||
LIBIMPORT void de_interlace(struct ImBuf *ib);
|
||||
LIBIMPORT void interlace(struct ImBuf *ib);
|
||||
LIBIMPORT void gamwarp(struct ImBuf *ibuf, double gamma);
|
||||
|
||||
LIBIMPORT void IMB_rectcpy(struct ImBuf *dbuf, struct ImBuf *sbuf,
|
||||
int destx, int desty, int srcx, int srcy, int width, int height);
|
||||
|
||||
@@ -118,11 +118,6 @@ LIBEXPORT void freeImBuf(struct ImBuf* ib)
|
||||
IMB_freeImBuf(ib);
|
||||
}
|
||||
|
||||
LIBEXPORT short converttocmap(struct ImBuf* ibuf)
|
||||
{
|
||||
return IMB_converttocmap(ibuf);
|
||||
}
|
||||
|
||||
LIBEXPORT short saveiff(struct ImBuf *ib,
|
||||
char *c,
|
||||
int i)
|
||||
@@ -130,11 +125,6 @@ LIBEXPORT short saveiff(struct ImBuf *ib,
|
||||
return IMB_saveiff(ib, c, i);
|
||||
}
|
||||
|
||||
LIBEXPORT struct ImBuf *loadiffmem(int *mem,int flags)
|
||||
{
|
||||
return IMB_loadiffmem(mem, flags);
|
||||
}
|
||||
|
||||
LIBEXPORT struct ImBuf *loadifffile(int a,
|
||||
int b)
|
||||
{
|
||||
@@ -158,16 +148,6 @@ LIBEXPORT struct ImBuf *onehalf(struct ImBuf *ib)
|
||||
return IMB_onehalf(ib);
|
||||
}
|
||||
|
||||
LIBEXPORT struct ImBuf *onethird(struct ImBuf *ib)
|
||||
{
|
||||
return IMB_onethird(ib);
|
||||
}
|
||||
|
||||
LIBEXPORT struct ImBuf *halflace(struct ImBuf *ib)
|
||||
{
|
||||
return IMB_halflace(ib);
|
||||
}
|
||||
|
||||
LIBEXPORT struct ImBuf *half_x(struct ImBuf *ib)
|
||||
{
|
||||
return IMB_half_x(ib);
|
||||
@@ -203,20 +183,6 @@ LIBEXPORT int ispic(char * name)
|
||||
return IMB_ispic(name);
|
||||
}
|
||||
|
||||
LIBEXPORT void dit2(struct ImBuf *ib,
|
||||
short a,
|
||||
short b)
|
||||
{
|
||||
IMB_dit2(ib, a, b);
|
||||
}
|
||||
|
||||
LIBEXPORT void dit0(struct ImBuf *ib,
|
||||
short a,
|
||||
short b)
|
||||
{
|
||||
IMB_dit0(ib, a, b);
|
||||
}
|
||||
|
||||
/* still the same name */
|
||||
/* void (*ditherfunc)(struct ImBuf *, short, short){} */
|
||||
|
||||
@@ -234,21 +200,6 @@ LIBEXPORT struct ImBuf *scalefastImBuf(struct ImBuf *ib,
|
||||
return IMB_scalefastImBuf(ib, x, y);
|
||||
}
|
||||
|
||||
|
||||
LIBEXPORT struct ImBuf *scalefieldImBuf(struct ImBuf *ib,
|
||||
short x,
|
||||
short y)
|
||||
{
|
||||
return IMB_scalefieldImBuf(ib, x, y);
|
||||
}
|
||||
|
||||
LIBEXPORT struct ImBuf *scalefastfieldImBuf(struct ImBuf *ib,
|
||||
short x,
|
||||
short y)
|
||||
{
|
||||
return IMB_scalefastfieldImBuf(ib, x, y);
|
||||
}
|
||||
|
||||
/* Extra ones that some NaN (read Ton) plugins use,
|
||||
* even though they aren't in the header
|
||||
*/
|
||||
@@ -258,11 +209,6 @@ LIBEXPORT void interlace(struct ImBuf *ibuf)
|
||||
IMB_interlace(ibuf);
|
||||
}
|
||||
|
||||
LIBEXPORT void gamwarp(struct ImBuf *ibuf, double gamma)
|
||||
{
|
||||
IMB_gamwarp(ibuf,gamma);
|
||||
}
|
||||
|
||||
LIBEXPORT void de_interlace(struct ImBuf *ib)
|
||||
{
|
||||
IMB_de_interlace(ib);
|
||||
@@ -334,15 +280,11 @@ int pluginapi_force_ref(void)
|
||||
GET_INT_FROM_POINTER( allocImBuf ) +
|
||||
GET_INT_FROM_POINTER( dupImBuf ) +
|
||||
GET_INT_FROM_POINTER( freeImBuf ) +
|
||||
GET_INT_FROM_POINTER( converttocmap ) +
|
||||
GET_INT_FROM_POINTER( saveiff ) +
|
||||
GET_INT_FROM_POINTER( loadiffmem ) +
|
||||
GET_INT_FROM_POINTER( loadifffile ) +
|
||||
GET_INT_FROM_POINTER( loadiffname ) +
|
||||
GET_INT_FROM_POINTER( testiffname ) +
|
||||
GET_INT_FROM_POINTER( onehalf ) +
|
||||
GET_INT_FROM_POINTER( onethird ) +
|
||||
GET_INT_FROM_POINTER( halflace ) +
|
||||
GET_INT_FROM_POINTER( half_x ) +
|
||||
GET_INT_FROM_POINTER( half_y ) +
|
||||
GET_INT_FROM_POINTER( double_x ) +
|
||||
@@ -350,17 +292,12 @@ int pluginapi_force_ref(void)
|
||||
GET_INT_FROM_POINTER( double_fast_x ) +
|
||||
GET_INT_FROM_POINTER( double_fast_y ) +
|
||||
GET_INT_FROM_POINTER( ispic ) +
|
||||
GET_INT_FROM_POINTER( dit2 ) +
|
||||
GET_INT_FROM_POINTER( dit0 ) +
|
||||
GET_INT_FROM_POINTER( scaleImBuf ) +
|
||||
GET_INT_FROM_POINTER( scalefastImBuf ) +
|
||||
GET_INT_FROM_POINTER( scalefieldImBuf ) +
|
||||
GET_INT_FROM_POINTER( scalefastfieldImBuf ) +
|
||||
GET_INT_FROM_POINTER( hnoise ) +
|
||||
GET_INT_FROM_POINTER( hnoisep ) +
|
||||
GET_INT_FROM_POINTER( turbulence ) +
|
||||
GET_INT_FROM_POINTER( turbulence1 ) +
|
||||
GET_INT_FROM_POINTER( de_interlace ) +
|
||||
GET_INT_FROM_POINTER( interlace ) +
|
||||
GET_INT_FROM_POINTER( gamwarp );
|
||||
GET_INT_FROM_POINTER( interlace );
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ void ui_draw_but_IMAGE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
|
||||
//int w, h;
|
||||
|
||||
/* hardcoded to splash, loading and freeing every draw, eek! */
|
||||
ibuf= IMB_ibImageFromMemory((int *)datatoc_splash_png, datatoc_splash_png_size, IB_rect);
|
||||
ibuf= IMB_ibImageFromMemory((unsigned char*)datatoc_splash_png, datatoc_splash_png_size, IB_rect);
|
||||
|
||||
if (!ibuf) return;
|
||||
|
||||
|
||||
@@ -480,7 +480,7 @@ static void init_internal_icons()
|
||||
}
|
||||
}
|
||||
if(bbuf==NULL)
|
||||
bbuf = IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
|
||||
bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
|
||||
|
||||
if(bbuf) {
|
||||
/* free existing texture if any */
|
||||
|
||||
@@ -88,8 +88,6 @@ static int screenshot_exec(bContext *C, wmOperator *op)
|
||||
ibuf= IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0, 0);
|
||||
ibuf->rect= scd->dumprect;
|
||||
|
||||
if(scene->r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
|
||||
|
||||
BKE_write_ibuf(scene, ibuf, path, scene->r.imtype, scene->r.subimtype, scene->r.quality);
|
||||
|
||||
IMB_freeImBuf(ibuf);
|
||||
|
||||
@@ -375,7 +375,7 @@ void filelist_init_icons()
|
||||
short x, y, k;
|
||||
ImBuf *bbuf;
|
||||
ImBuf *ibuf;
|
||||
bbuf = IMB_ibImageFromMemory((int *)datatoc_prvicons, datatoc_prvicons_size, IB_rect);
|
||||
bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_prvicons, datatoc_prvicons_size, IB_rect);
|
||||
if (bbuf) {
|
||||
for (y=0; y<SPECIAL_IMG_ROWS; y++) {
|
||||
for (x=0; x<SPECIAL_IMG_COLS; x++) {
|
||||
@@ -850,6 +850,7 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime)
|
||||
|| BLI_testextensie(file->relname, ".psd")
|
||||
|| BLI_testextensie(file->relname, ".tif")
|
||||
|| BLI_testextensie(file->relname, ".tiff")
|
||||
|| BLI_testextensie(file->relname, ".tx")
|
||||
|| BLI_testextensie(file->relname, ".pct")
|
||||
|| BLI_testextensie(file->relname, ".pict")
|
||||
|| BLI_testextensie(file->relname, ".pntg") //macpaint
|
||||
@@ -913,6 +914,7 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime)
|
||||
|| BLI_testextensie(file->relname, ".iff")
|
||||
|| BLI_testextensie(file->relname, ".tif")
|
||||
|| BLI_testextensie(file->relname, ".tiff")
|
||||
|| BLI_testextensie(file->relname, ".tx")
|
||||
|| BLI_testextensie(file->relname, ".hdr")
|
||||
#ifdef WITH_DDS
|
||||
|| BLI_testextensie(file->relname, ".dds")
|
||||
|
||||
@@ -183,7 +183,6 @@ void save_image_filesel_str(Scene *scene, char *str)
|
||||
#endif
|
||||
/* default we save jpeg, also for all movie formats */
|
||||
case R_JPEG90:
|
||||
case R_MOVIE:
|
||||
case R_AVICODEC:
|
||||
case R_AVIRAW:
|
||||
case R_AVIJPEG:
|
||||
|
||||
@@ -882,7 +882,6 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn
|
||||
uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "fields"));
|
||||
|
||||
col= uiLayoutColumn(split, 0);
|
||||
uiItemR(col, &imaptr, "antialias", 0, NULL, 0);
|
||||
uiItemR(col, &imaptr, "premultiply", 0, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* @attention Defined in allocimbuf.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
|
||||
*/
|
||||
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,18 +130,20 @@ 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);
|
||||
|
||||
void IMB_free_cache_limiter(void);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -203,14 +155,8 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1);
|
||||
*
|
||||
* @attention Defined in allocimbuf.c
|
||||
*/
|
||||
short addzbufImBuf(struct ImBuf * ibuf);
|
||||
short addzbuffloatImBuf(struct ImBuf * ibuf);
|
||||
|
||||
/**
|
||||
*
|
||||
* @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,6 +245,16 @@ 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 cache.c
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -335,13 +272,7 @@ struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1);
|
||||
*
|
||||
* @attention Defined in scaling.c
|
||||
*/
|
||||
struct ImBuf *IMB_scaleImBuf(struct ImBuf * ibuf, short newx, short newy);
|
||||
|
||||
/**
|
||||
*
|
||||
* @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,7 +317,6 @@ 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);
|
||||
|
||||
@@ -397,6 +327,15 @@ void IMB_float_from_rect(struct ImBuf *ibuf);
|
||||
* @attention Defined in imageprocess.c
|
||||
*/
|
||||
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf);
|
||||
|
||||
/**
|
||||
* Change the ordering of the color bytes pointed to by rect from
|
||||
* rgba to abgr. size * 4 color bytes are reordered.
|
||||
*
|
||||
* @attention Defined in imageprocess.c
|
||||
*/
|
||||
void IMB_convert_bgra_to_rgba(int size, unsigned int *rect);
|
||||
|
||||
/**
|
||||
*
|
||||
* @attention defined in imageprocess.c
|
||||
@@ -410,22 +349,6 @@ void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *c
|
||||
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
|
||||
* rgba to abgr. size * 4 color bytes are reordered.
|
||||
*
|
||||
* @attention Defined in imageprocess.c
|
||||
*/
|
||||
void IMB_convert_bgra_to_rgba(int size, unsigned int *rect);
|
||||
|
||||
/**
|
||||
*
|
||||
* @attention defined in scaling.c
|
||||
*/
|
||||
struct ImBuf *IMB_scalefastfieldImBuf(struct ImBuf *ibuf,
|
||||
short newx,
|
||||
short newy);
|
||||
|
||||
/**
|
||||
*
|
||||
* @attention defined in readimage.c
|
||||
@@ -478,68 +401,23 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1);
|
||||
*/
|
||||
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 +429,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
|
||||
|
||||
|
||||
@@ -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 */
|
||||
/* 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 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 */
|
||||
|
||||
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)
|
||||
@@ -188,11 +190,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 +205,16 @@ 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
|
||||
/**@}*/
|
||||
|
||||
|
||||
/** \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
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef enum ThumbSource {
|
||||
THB_SOURCE_MOVIE
|
||||
} 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);
|
||||
|
||||
@@ -14,6 +14,9 @@ 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')
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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*/
|
||||
120
source/blender/imbuf/intern/IMB_filetype.h
Normal file
120
source/blender/imbuf/intern/IMB_filetype.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* $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 */
|
||||
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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id$
|
||||
* $Id: IMB_metadata.h 28607 2010-05-06 07:10:56Z campbellbarton $
|
||||
*
|
||||
* ***** 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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -32,54 +32,38 @@
|
||||
/* It's become a bit messy... Basically, only the IMB_ prefixed files
|
||||
* should remain. */
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
#include "IMB_divers.h"
|
||||
#include "IMB_allocimbuf.h"
|
||||
#include "IMB_imginfo.h"
|
||||
#include "IMB_filetype.h"
|
||||
#include "IMB_metadata.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
|
||||
#include "MEM_CacheLimiterC-Api.h"
|
||||
|
||||
static unsigned int dfltcmap[16] = {
|
||||
0x00000000, 0xffffffff, 0x777777ff, 0xccccccff,
|
||||
0xcc3344ff, 0xdd8844ff, 0xccdd44ff, 0x888833ff,
|
||||
0x338844ff, 0x44dd44ff, 0x44ddccff, 0x3388ccff,
|
||||
0x8888ddff, 0x4433ccff, 0xcc33ccff, 0xcc88ddff
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 +73,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 && ibuf->crect != ibuf->rect)
|
||||
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 +90,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)
|
||||
void IMB_freeImBuf(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)
|
||||
{
|
||||
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 +265,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);
|
||||
if(ibuf->depth > 32) return (addzbufImBuf(ibuf));
|
||||
else return TRUE;
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
short imb_addcmapImBuf(struct ImBuf *ibuf)
|
||||
short imb_addtilesImBuf(ImBuf *ibuf)
|
||||
{
|
||||
int min;
|
||||
|
||||
if (ibuf==NULL) return(FALSE);
|
||||
IMB_freecmapImBuf(ibuf);
|
||||
if(ibuf==NULL) return FALSE;
|
||||
|
||||
imb_checkncols(ibuf);
|
||||
if (ibuf->maxcol == 0) return (TRUE);
|
||||
if(!ibuf->tiles)
|
||||
if((ibuf->tiles = MEM_callocN(sizeof(unsigned int*)*ibuf->xtiles*ibuf->ytiles, "imb_tiles")))
|
||||
ibuf->mall |= IB_tiles;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
return (ibuf->tiles != NULL);
|
||||
}
|
||||
|
||||
|
||||
short imb_addplanesImBuf(struct ImBuf *ibuf)
|
||||
ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, uchar bitmap) /* XXX bitmap argument is deprecated */
|
||||
{
|
||||
int size;
|
||||
short skipx,d,y;
|
||||
unsigned int **planes;
|
||||
unsigned int *point2;
|
||||
ImBuf *ibuf;
|
||||
|
||||
if (ibuf==NULL) return(FALSE);
|
||||
imb_freeplanesImBuf(ibuf);
|
||||
ibuf = MEM_callocN(sizeof(ImBuf), "ImBuf_struct");
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, uchar bitmap)
|
||||
{
|
||||
struct ImBuf *ibuf;
|
||||
|
||||
ibuf = MEM_callocN(sizeof(struct ImBuf), "ImBuf_struct");
|
||||
if (bitmap) flags |= IB_planes;
|
||||
|
||||
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 +366,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 +406,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 +417,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 +456,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 +468,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -64,7 +64,6 @@
|
||||
#include "BKE_global.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
|
||||
#include "AVI_avi.h"
|
||||
|
||||
@@ -78,9 +77,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>
|
||||
@@ -327,7 +324,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);
|
||||
|
||||
@@ -341,7 +337,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) {
|
||||
@@ -476,7 +472,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...
|
||||
}
|
||||
}
|
||||
@@ -995,7 +991,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
|
||||
@@ -1013,10 +1008,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) {
|
||||
@@ -1094,26 +1085,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:
|
||||
@@ -1153,7 +1131,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);
|
||||
|
||||
@@ -1161,16 +1138,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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
442
source/blender/imbuf/intern/cache.c
Normal file
442
source/blender/imbuf/intern/cache.c
Normal file
@@ -0,0 +1,442 @@
|
||||
/*
|
||||
* $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 "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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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]; */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
@@ -172,6 +171,12 @@ void libtiff_init(void)
|
||||
}
|
||||
libtiff_loadlibtiff();
|
||||
G.have_libtiff = ((libtiff != NULL) && (libtiff_load_symbols()));
|
||||
|
||||
if (!G.have_libtiff && (G.f & G_DEBUG)) {
|
||||
printf("Unable to load: libtiff.\n");
|
||||
printf("Try setting the BF_TIFF_LIB environment variable if you want this support.\n");
|
||||
printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n");
|
||||
}
|
||||
}
|
||||
|
||||
void libtiff_exit(void)
|
||||
@@ -230,6 +235,26 @@ int libtiff_load_symbols(void)
|
||||
if (libtiff__TIFFmalloc == NULL) {
|
||||
return (0);
|
||||
}
|
||||
/* Attempt to load TIFFSetDirectory */
|
||||
libtiff_TIFFSetDirectory = libtiff_findsymbol("TIFFSetDirectory");
|
||||
if (libtiff_TIFFSetDirectory == NULL) {
|
||||
return (0);
|
||||
}
|
||||
/* Attempt to load TIFFNumberOfDirectories */
|
||||
libtiff_TIFFNumberOfDirectories = libtiff_findsymbol("TIFFNumberOfDirectories");
|
||||
if (libtiff_TIFFNumberOfDirectories == NULL) {
|
||||
return (0);
|
||||
}
|
||||
/* Attempt to load TIFFIsTiled */
|
||||
libtiff_TIFFIsTiled = libtiff_findsymbol("TIFFIsTiled");
|
||||
if (libtiff_TIFFIsTiled == NULL) {
|
||||
return (0);
|
||||
}
|
||||
/* Attempt to load TIFFReadRGBATile */
|
||||
libtiff_TIFFReadRGBATile = libtiff_findsymbol("TIFFReadRGBATile");
|
||||
if (libtiff_TIFFReadRGBATile == NULL) {
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -247,3 +272,9 @@ 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;
|
||||
int (*libtiff_TIFFSetDirectory)(TIFF*, tdir_t) = NULL;
|
||||
tdir_t (*libtiff_TIFFNumberOfDirectories)(TIFF*) = NULL;
|
||||
int (*libtiff_TIFFIsTiled)(TIFF*) = NULL;
|
||||
int (*libtiff_TIFFReadRGBATile)(TIFF*, uint32, uint32, uint32 * ) = NULL;
|
||||
|
||||
|
||||
|
||||
@@ -51,5 +51,9 @@ 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);
|
||||
extern int (*libtiff_TIFFSetDirectory)(TIFF*, tdir_t);
|
||||
extern tdir_t (*libtiff_TIFFNumberOfDirectories)(TIFF*);
|
||||
extern int (*libtiff_TIFFIsTiled)(TIFF*);
|
||||
extern int (*libtiff_TIFFReadRGBATile)(TIFF*, uint32, uint32, uint32 * );
|
||||
#endif /* DYN_LIBTIFF_H */
|
||||
|
||||
|
||||
105
source/blender/imbuf/intern/filetype.c
Normal file
105
source/blender/imbuf/intern/filetype.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* $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
|
||||
|
||||
void libtiff_init(void);
|
||||
void libtiff_exit(void);
|
||||
|
||||
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},
|
||||
{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},
|
||||
#if defined(__APPLE__) && defined(IMBUF_COCOA)
|
||||
{NULL, NULL, imb_is_a_cocoa, imb_ftype_cocoa, imb_imb_cocoaLoadImage, imb_savecocoa, NULL, 0, TIF},
|
||||
#else
|
||||
{libtiff_init, libtiff_exit, imb_is_a_tiff, imb_ftype_default, imb_loadtiff, imb_savetiff, imb_loadtiletiff, 0, TIF},
|
||||
#endif
|
||||
{NULL, NULL, imb_is_a_hdr, imb_ftype_default, imb_loadhdr, imb_savehdr, NULL, IM_FTYPE_FLOAT, RADHDR},
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -29,14 +29,13 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BKE_utildefines.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 +374,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -37,6 +37,8 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
#include "math.h"
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#if !defined(WIN32)
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
@@ -72,97 +74,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 */
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -32,11 +32,10 @@
|
||||
#include <string.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_iris.h"
|
||||
#include "IMB_filetype.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned short imagic; /* stuff saved on disk . . */
|
||||
@@ -224,6 +223,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 +241,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 +254,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 +288,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 +390,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 +506,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 +671,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 +725,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 +809,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;
|
||||
|
||||
@@ -26,12 +26,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_jp2.h"
|
||||
#include "IMB_filetype.h"
|
||||
|
||||
#include "openjpeg.h"
|
||||
|
||||
@@ -58,7 +57,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);
|
||||
}
|
||||
@@ -642,7 +641,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;
|
||||
|
||||
|
||||
@@ -34,17 +34,24 @@
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imginfo.h"
|
||||
#include "IMB_jpeg.h"
|
||||
#include "IMB_metadata.h"
|
||||
#include "IMB_filetype.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
#define IS_jpg(x) (x->ftype & JPG)
|
||||
#define IS_stdjpg(x) ((x->ftype & JPG_MSK) == JPG_STD)
|
||||
#define IS_vidjpg(x) ((x->ftype & JPG_MSK) == JPG_VID)
|
||||
#define IS_jstjpg(x) ((x->ftype & JPG_MSK) == JPG_JST)
|
||||
#define IS_maxjpg(x) ((x->ftype & JPG_MSK) == JPG_MAX)
|
||||
|
||||
/* the types are from the jpeg lib */
|
||||
static void jpeg_error (j_common_ptr cinfo);
|
||||
static void init_source(j_decompress_ptr cinfo);
|
||||
@@ -297,11 +304,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
|
||||
|
||||
for (y = ibuf->y - 1; y >= 0; y--) {
|
||||
jpeg_read_scanlines(cinfo, row_pointer, 1);
|
||||
if (flags & IB_ttob) {
|
||||
rect = (uchar *) (ibuf->rect + (ibuf->y - 1 - y) * ibuf->x);
|
||||
} else {
|
||||
rect = (uchar *) (ibuf->rect + y * ibuf->x);
|
||||
}
|
||||
rect = (uchar *) (ibuf->rect + y * ibuf->x);
|
||||
buffer = row_pointer[0];
|
||||
|
||||
switch(depth) {
|
||||
@@ -378,8 +381,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
|
||||
* the information when we write
|
||||
* it back to disk.
|
||||
*/
|
||||
IMB_imginfo_add_field(ibuf, "None", (char *) marker->data);
|
||||
ibuf->flags |= IB_imginfo;
|
||||
IMB_metadata_add_field(ibuf, "None", (char *) marker->data);
|
||||
ibuf->flags |= IB_metadata;
|
||||
goto next_stamp_marker;
|
||||
}
|
||||
|
||||
@@ -404,8 +407,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f
|
||||
|
||||
*value = '\0'; /* need finish the key string */
|
||||
value++;
|
||||
IMB_imginfo_add_field(ibuf, key, value);
|
||||
ibuf->flags |= IB_imginfo;
|
||||
IMB_metadata_add_field(ibuf, key, value);
|
||||
ibuf->flags |= IB_metadata;
|
||||
MEM_freeN(str);
|
||||
next_stamp_marker:
|
||||
marker= marker->next;
|
||||
@@ -453,11 +456,13 @@ ImBuf * imb_ibJpegImageFromFilename (const char * filename, int flags)
|
||||
return(ibuf);
|
||||
}
|
||||
|
||||
ImBuf * imb_ibJpegImageFromMemory (unsigned char * buffer, int size, int flags)
|
||||
ImBuf * imb_load_jpeg (unsigned char * buffer, int size, int flags)
|
||||
{
|
||||
struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
|
||||
struct my_error_mgr jerr;
|
||||
ImBuf * ibuf;
|
||||
|
||||
if(!imb_is_a_jpeg(buffer)) return NULL;
|
||||
|
||||
cinfo->err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = jpeg_error;
|
||||
@@ -487,7 +492,7 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf)
|
||||
uchar * rect;
|
||||
int x, y;
|
||||
char neogeo[128];
|
||||
ImgInfo *iptr;
|
||||
ImMetaData *iptr;
|
||||
char *text;
|
||||
|
||||
jpeg_start_compress(cinfo, TRUE);
|
||||
@@ -498,10 +503,10 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf)
|
||||
memcpy(neogeo + 6, &ibuf_ftype, 4);
|
||||
jpeg_write_marker(cinfo, 0xe1, (JOCTET*) neogeo, 10);
|
||||
|
||||
if(ibuf->img_info) {
|
||||
if(ibuf->metadata) {
|
||||
/* key + max value + "Blender" */
|
||||
text= MEM_mallocN(530, "stamp info read");
|
||||
iptr= ibuf->img_info;
|
||||
iptr= ibuf->metadata;
|
||||
while(iptr) {
|
||||
if (!strcmp (iptr->key, "None")) {
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen (iptr->value) + 1);
|
||||
@@ -526,9 +531,9 @@ next_stamp_info:
|
||||
}
|
||||
|
||||
row_pointer[0] =
|
||||
mallocstruct(JSAMPLE,
|
||||
MEM_mallocN(sizeof(JSAMPLE) *
|
||||
cinfo->input_components *
|
||||
cinfo->image_width);
|
||||
cinfo->image_width, "jpeg row_pointer");
|
||||
|
||||
for(y = ibuf->y - 1; y >= 0; y--){
|
||||
rect = (uchar *) (ibuf->rect + y * ibuf->x);
|
||||
@@ -561,7 +566,7 @@ next_stamp_info:
|
||||
}
|
||||
|
||||
jpeg_finish_compress(cinfo);
|
||||
free(row_pointer[0]);
|
||||
MEM_freeN(row_pointer[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -580,7 +585,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct
|
||||
cinfo->image_height = ibuf->y;
|
||||
|
||||
cinfo->in_color_space = JCS_RGB;
|
||||
if (ibuf->depth == 8 && ibuf->cmap == 0) cinfo->in_color_space = JCS_GRAYSCALE;
|
||||
if (ibuf->depth == 8) cinfo->in_color_space = JCS_GRAYSCALE;
|
||||
if (ibuf->depth == 32) cinfo->in_color_space = JCS_UNKNOWN;
|
||||
|
||||
switch(cinfo->in_color_space){
|
||||
|
||||
@@ -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}};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id$
|
||||
* $Id: metadata.c 28209 2010-04-15 15:49:48Z blendix $
|
||||
*
|
||||
* ***** 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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_filetype.h"
|
||||
|
||||
struct ImBuf;
|
||||
void IMB_init(void)
|
||||
{
|
||||
imb_filetypes_init();
|
||||
imb_tile_cache_init();
|
||||
}
|
||||
|
||||
short imb_converttoham(struct ImBuf *ibuf);
|
||||
|
||||
#endif
|
||||
void IMB_exit(void)
|
||||
{
|
||||
IMB_free_cache_limiter();
|
||||
imb_tile_cache_exit();
|
||||
imb_filetypes_exit();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ _CRTIMP void __cdecl _invalid_parameter_noinfo(void)
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_allocimbuf.h"
|
||||
#include "IMB_metadata.h"
|
||||
|
||||
#include "openexr_multi.h"
|
||||
}
|
||||
@@ -177,7 +178,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 +198,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));
|
||||
@@ -269,7 +279,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 +291,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));
|
||||
@@ -326,7 +337,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 +446,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 +460,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"));
|
||||
@@ -575,7 +588,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 +616,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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -33,15 +33,13 @@
|
||||
#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_imginfo.h"
|
||||
#include "IMB_png.h"
|
||||
#include "IMB_metadata.h"
|
||||
#include "IMB_filetype.h"
|
||||
|
||||
typedef struct PNGReadStruct {
|
||||
unsigned char *data;
|
||||
@@ -53,7 +51,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 +92,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;
|
||||
@@ -219,30 +217,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 +435,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,14 +43,12 @@
|
||||
#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 +158,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 +203,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 +328,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;
|
||||
|
||||
@@ -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"
|
||||
ImBuf *IMB_ibImageFromMemory(unsigned char *mem, int size, int flags)
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
ImFileType *type;
|
||||
|
||||
#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
|
||||
|
||||
#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;
|
||||
|
||||
ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) {
|
||||
int len;
|
||||
struct ImBuf *ibuf;
|
||||
|
||||
if (mem == NULL) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
}
|
||||
|
||||
ibuf = imb_loadpng((uchar *)mem, size, flags);
|
||||
if (ibuf) return(ibuf);
|
||||
|
||||
ibuf = imb_bmp_decode((uchar *)mem, size, flags);
|
||||
if (ibuf) return(ibuf);
|
||||
|
||||
ibuf = imb_loadtarga((uchar *)mem, size, flags);
|
||||
if (ibuf) return(ibuf);
|
||||
|
||||
ibuf = imb_loaddpx((uchar *)mem, size, flags);
|
||||
if (ibuf) return(ibuf);
|
||||
|
||||
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);
|
||||
|
||||
#ifdef WITH_OPENEXR
|
||||
ibuf = imb_load_openexr((uchar *)mem, size, flags);
|
||||
if (ibuf) return (ibuf);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_OPENJPEG
|
||||
ibuf = imb_jp2_decode((uchar *)mem, size, flags);
|
||||
if (ibuf) return (ibuf);
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
if (IB_verbose) fprintf(stderr, "Unknown fileformat\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, "Unknown fileformat\n");
|
||||
|
||||
return (0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ImBuf *IMB_loadifffile(int file, int flags)
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
unsigned char *mem;
|
||||
int size;
|
||||
|
||||
struct ImBuf *IMB_loadiffmem(int *mem, int flags) {
|
||||
int len,maxlen;
|
||||
struct ImBuf *ibuf;
|
||||
if(file == -1) return 0;
|
||||
|
||||
// IMB_loadiffmem shouldn't be used anymore in new development
|
||||
// it's still here to be backwards compatible...
|
||||
size= BLI_filesize(file);
|
||||
|
||||
maxlen= (GET_BIG_LONG(mem+1) + 1) & ~1;
|
||||
|
||||
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);
|
||||
}
|
||||
mem= mmap(0, size, PROT_READ, MAP_SHARED, file, 0);
|
||||
if(mem==(unsigned char*)-1) {
|
||||
fprintf(stderr, "Couldn't get mapping\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_ibImageFromMemory(mem, size, flags);
|
||||
|
||||
ibuf = imb_loadtarga((uchar *) mem,maxlen,flags);
|
||||
if (ibuf) return(ibuf);
|
||||
if(munmap(mem, size))
|
||||
fprintf(stderr, "Couldn't unmap file.\n");
|
||||
|
||||
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;
|
||||
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 (file == -1) return (0);
|
||||
|
||||
size = BLI_filesize(file);
|
||||
|
||||
mem= (int *)mmap(0,size,PROT_READ,MAP_SHARED,file,0);
|
||||
if (mem==(int *)-1){
|
||||
printf("Couldn't get mapping\n");
|
||||
return (0);
|
||||
if(BLI_file_older(name, filename))
|
||||
return;
|
||||
}
|
||||
|
||||
ibuf = IMB_ibImageFromMemory(mem, size, flags);
|
||||
|
||||
if (munmap( (void *) mem, size)){
|
||||
printf("Couldn't unmap file.\n");
|
||||
}
|
||||
return(ibuf);
|
||||
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_loadiffname(const char *naam, int flags) {
|
||||
int file;
|
||||
struct ImBuf *ibuf;
|
||||
int buf[1];
|
||||
imb_cache_filename(filename, name, flags);
|
||||
|
||||
file = open(naam, O_BINARY|O_RDONLY);
|
||||
|
||||
if (file < 0) return (0);
|
||||
file = open(filename, O_BINARY|O_RDONLY);
|
||||
if(file < 0) return 0;
|
||||
|
||||
ibuf= IMB_loadifffile(file, flags);
|
||||
|
||||
if (ibuf == NULL) {
|
||||
if (read(file, buf, 4) != 4) buf[0] = 0;
|
||||
if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0)
|
||||
ibuf = imb_ibJpegImageFromFilename(naam, flags);
|
||||
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 (ibuf) {
|
||||
strncpy(ibuf->name, naam, sizeof(ibuf->name));
|
||||
if (flags & IB_fields) IMB_de_interlace(ibuf);
|
||||
}
|
||||
close(file);
|
||||
return(ibuf);
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
struct ImBuf *IMB_testiffname(char *naam,int flags) {
|
||||
ImBuf *IMB_testiffname(char *name, int flags)
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
int file;
|
||||
struct ImBuf *ibuf;
|
||||
char filename[IB_FILENAME_SIZE];
|
||||
|
||||
flags |= IB_test;
|
||||
file = open(naam,O_BINARY|O_RDONLY);
|
||||
imb_cache_filename(filename, name, flags);
|
||||
|
||||
if (file < 0) return (0);
|
||||
file = open(filename,O_BINARY|O_RDONLY);
|
||||
if(file < 0) return 0;
|
||||
|
||||
ibuf=IMB_loadifffile(file,flags);
|
||||
if (ibuf) {
|
||||
strncpy(ibuf->name, naam, sizeof(ibuf->name));
|
||||
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));
|
||||
}
|
||||
|
||||
close(file);
|
||||
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;
|
||||
|
||||
if(file == -1) return;
|
||||
|
||||
size= BLI_filesize(file);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
|
||||
{
|
||||
int file;
|
||||
|
||||
file = open(ibuf->cachename, O_BINARY|O_RDONLY);
|
||||
if(file < 0) return;
|
||||
|
||||
imb_loadtilefile(ibuf, file, tx, ty, rect);
|
||||
|
||||
close(file);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
@@ -347,142 +346,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 +1550,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));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,14 +33,12 @@
|
||||
#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_targa.h"
|
||||
#include "IMB_filetype.h"
|
||||
|
||||
|
||||
/* this one is only def-ed once, strangely... related to GS? */
|
||||
@@ -234,11 +232,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 +246,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 +254,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 +277,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 +337,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 +531,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 +542,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 +577,24 @@ 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) */
|
||||
MEM_freeN(cmap);
|
||||
cmap= NULL;
|
||||
}
|
||||
|
||||
switch(tga.imgtyp){
|
||||
case 1:
|
||||
@@ -641,11 +615,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 +660,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);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,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"
|
||||
|
||||
@@ -282,11 +282,11 @@ 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(0,0,32, IB_rect | IB_metadata, 0);
|
||||
if (!img) return 0;
|
||||
} else {
|
||||
if (THB_SOURCE_IMAGE == source) {
|
||||
img = IMB_loadiffname(path, IB_rect | IB_imginfo);
|
||||
img = IMB_loadiffname(path, IB_rect | IB_metadata);
|
||||
if (img != NULL) {
|
||||
stat(path, &info);
|
||||
sprintf(mtime, "%ld", info.st_mtime);
|
||||
@@ -295,7 +295,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,17 +325,17 @@ 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
|
||||
@@ -358,7 +358,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 +409,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;
|
||||
|
||||
@@ -43,16 +43,17 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "imbuf_patch.h"
|
||||
|
||||
#include "BKE_global.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"
|
||||
|
||||
@@ -72,12 +73,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 +109,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 +172,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 +219,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 +245,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 +258,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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 +288,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,7 +297,31 @@ int imb_is_a_tiff(void *mem)
|
||||
(memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0) );
|
||||
}
|
||||
|
||||
static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul)
|
||||
{
|
||||
ImBuf *tmpibuf;
|
||||
int success;
|
||||
|
||||
tmpibuf= IMB_allocImBuf(ibuf->x, ibuf->y, 32, IB_rect, 0);
|
||||
success= libtiff_TIFFReadRGBAImage(image, ibuf->x, ibuf->y, tmpibuf->rect, 0);
|
||||
|
||||
if(ENDIAN_ORDER == B_ENDIAN)
|
||||
IMB_convert_rgba_to_abgr(tmpibuf);
|
||||
if(premul) {
|
||||
IMB_premultiply_alpha(tmpibuf);
|
||||
ibuf->flags |= IB_premul;
|
||||
}
|
||||
|
||||
/* assign rect last */
|
||||
ibuf->rect= tmpibuf->rect;
|
||||
ibuf->mall |= IB_rect;
|
||||
ibuf->flags |= IB_rect;
|
||||
|
||||
tmpibuf->mall &= ~IB_rect;
|
||||
IMB_freeImBuf(tmpibuf);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a TIFF file.
|
||||
@@ -303,52 +337,42 @@ 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;
|
||||
char *format = NULL;
|
||||
int level;
|
||||
|
||||
memFile.mem = mem;
|
||||
memFile.offset = 0;
|
||||
memFile.size = size;
|
||||
if(!G.have_libtiff)
|
||||
return NULL;
|
||||
|
||||
/* 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) {
|
||||
ibuf = IMB_allocImBuf(width, height, 32, 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");
|
||||
@@ -356,65 +380,109 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read in the image data */
|
||||
if (!(flags & IB_test)) {
|
||||
/* if testing, we're done */
|
||||
if(flags & IB_test) {
|
||||
libtiff_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;
|
||||
libtiff_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 && libtiff_TIFFIsTiled(image)) {
|
||||
int numlevel = libtiff_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(!libtiff_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->flags |= IB_tilecache;
|
||||
hbuf->ftype= ibuf->ftype;
|
||||
ibuf->mipmap[level-1] = hbuf;
|
||||
|
||||
if(flags & IB_premul)
|
||||
hbuf->flags |= IB_premul;
|
||||
}
|
||||
else
|
||||
hbuf= ibuf;
|
||||
|
||||
libtiff_TIFFGetField(image, TIFFTAG_TILEWIDTH, &hbuf->tilex);
|
||||
libtiff_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");
|
||||
libtiff_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);
|
||||
|
||||
/* 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(libtiff_TIFFSetDirectory(image, ibuf->miplevel)) {
|
||||
/* allocate the image buffer */
|
||||
libtiff_TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);
|
||||
libtiff_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(libtiff_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 */
|
||||
libtiff_TIFFClose(image);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +503,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags)
|
||||
|
||||
#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 +514,17 @@ 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 };
|
||||
|
||||
if(!G.have_libtiff) {
|
||||
fprintf(stderr, "imb_savetiff: no tiff library available.\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* 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 +537,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");
|
||||
}
|
||||
if (image == NULL) {
|
||||
if(image == NULL) {
|
||||
fprintf(stderr,
|
||||
"imb_savetiff: could not open TIFF for writing.\n");
|
||||
return (0);
|
||||
@@ -489,7 +563,7 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
|
||||
pixels = (unsigned char*)libtiff__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);
|
||||
@@ -529,17 +603,17 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
|
||||
}
|
||||
|
||||
/* 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++)
|
||||
for(i = 0; i < samplesperpixel; i++, to_i++, from_i++)
|
||||
to16[to_i] = FTOUSHORT(fromf[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];
|
||||
}
|
||||
}
|
||||
@@ -555,7 +629,7 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags)
|
||||
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,
|
||||
if(libtiff_TIFFWriteEncodedStrip(image, 0,
|
||||
(bitspersample == 16)? (unsigned char*)pixels16: pixels,
|
||||
ibuf->x*ibuf->y*samplesperpixel*bitspersample/8) == -1) {
|
||||
fprintf(stderr,
|
||||
|
||||
@@ -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,90 +68,46 @@
|
||||
|
||||
#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])
|
||||
|
||||
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);
|
||||
if(stat(name,&st) == -1)
|
||||
return FALSE;
|
||||
if(((st.st_mode) & S_IFMT) != S_IFREG)
|
||||
return FALSE;
|
||||
|
||||
/* 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((fp = open(name,O_BINARY|O_RDONLY)) < 0)
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
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
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
close(fp);
|
||||
}
|
||||
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"))) {
|
||||
|| BLI_testextensie(filename, ".tiff")
|
||||
|| BLI_testextensie(filename, ".tx"))) {
|
||||
return IMB_ispic_name(filename);
|
||||
}
|
||||
if (G.have_quicktime){
|
||||
@@ -179,6 +115,7 @@ int IMB_ispic(char *filename)
|
||||
|| BLI_testextensie(filename, ".jpeg")
|
||||
|| BLI_testextensie(filename, ".tif")
|
||||
|| BLI_testextensie(filename, ".tiff")
|
||||
|| BLI_testextensie(filename, ".tx")
|
||||
|| BLI_testextensie(filename, ".hdr")
|
||||
|| BLI_testextensie(filename, ".tga")
|
||||
|| BLI_testextensie(filename, ".rgb")
|
||||
@@ -391,14 +328,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 +351,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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
return type->save(ibuf, name, flags);
|
||||
}
|
||||
else{
|
||||
if (ok) ok = imb_encodebodyh(ibuf,file);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ typedef struct Image {
|
||||
|
||||
#define IMA_REFLECT 16
|
||||
#define IMA_NOCOLLECT 32
|
||||
#define IMA_ANTIALI 64
|
||||
#define IMA_DEPRECATED 64
|
||||
#define IMA_OLD_PREMUL 128
|
||||
|
||||
/* tpageflag */
|
||||
|
||||
@@ -339,11 +339,6 @@ static void rna_def_image(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Fields", "Use fields of the image");
|
||||
RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_fields_update");
|
||||
|
||||
prop= RNA_def_property(srna, "antialias", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANTIALI);
|
||||
RNA_def_property_ui_text(prop, "Anti-alias", "Toggles image anti-aliasing, only works with solid colors");
|
||||
RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "premultiply", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_DO_PREMUL);
|
||||
RNA_def_property_ui_text(prop, "Premultiply", "Convert RGB from key alpha to premultiplied alpha");
|
||||
|
||||
@@ -376,7 +376,11 @@ int imb_is_a_quicktime (char *name)
|
||||
{
|
||||
NSImage *image;
|
||||
int result;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
if(!G.have_quicktime) return 0;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// dont let quicktime image import handle these
|
||||
if( BLI_testextensie(name, ".swf") ||
|
||||
@@ -412,6 +416,9 @@ ImBuf *imb_quicktime_decode(unsigned char *mem, int size, int flags)
|
||||
NSBitmapImageRep *bitmapImage;
|
||||
NSBitmapImageRep *blBitmapFormatImageRGB,*blBitmapFormatImageRGBA;
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
if(!G.have_quicktime)
|
||||
return NULL;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
@@ -559,6 +559,8 @@ int imb_is_a_quicktime (char *name)
|
||||
#endif
|
||||
OSErr err = noErr;
|
||||
|
||||
if(!G.have_quicktime) return 0;
|
||||
|
||||
if(QTIME_DEBUG) printf("qt: checking as image %s\n", name);
|
||||
|
||||
// dont let quicktime image import handle these
|
||||
|
||||
@@ -301,12 +301,6 @@ void WM_exit(bContext *C)
|
||||
BPY_end_python();
|
||||
#endif
|
||||
|
||||
libtiff_exit();
|
||||
|
||||
#ifdef WITH_QUICKTIME
|
||||
quicktime_exit();
|
||||
#endif
|
||||
|
||||
if (!G.background) {
|
||||
// XXX UI_filelist_free_icons();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_sound.h"
|
||||
|
||||
#include "IMB_imbuf.h" // for quicktime_init
|
||||
#include "IMB_imbuf.h" // for IMB_init
|
||||
|
||||
#ifndef DISABLE_PYTHON
|
||||
#include "BPY_extern.h"
|
||||
@@ -217,7 +217,7 @@ static int print_help(int argc, char **argv, void *data)
|
||||
printf (" use -E help to list available engines.\n");
|
||||
printf ("\nFormat options:\n");
|
||||
printf (" -F <format>\tSet the render format, Valid options are...\n");
|
||||
printf (" \tTGA IRIS HAMX JPEG MOVIE IRIZ RAWTGA\n");
|
||||
printf (" \tTGA IRIS JPEG MOVIE IRIZ RAWTGA\n");
|
||||
printf (" \tAVIRAW AVIJPEG PNG BMP FRAMESERVER\n");
|
||||
printf (" (formats that can be compiled into blender, not available on all systems)\n");
|
||||
printf (" \tHDR TIFF EXR MULTILAYER MPEG AVICODEC QUICKTIME CINEON DPX DDS\n");
|
||||
@@ -367,8 +367,6 @@ static int playback_mode(int argc, char **argv, void *data)
|
||||
{
|
||||
/* not if -b was given first */
|
||||
if (G.background == 0) {
|
||||
/* exception here, see below, it probably needs happens after qt init? */
|
||||
libtiff_init();
|
||||
|
||||
// XXX playanim(argc, argv); /* not the same argc and argv as before */
|
||||
exit(0);
|
||||
@@ -532,12 +530,10 @@ static int set_image_type(int argc, char **argv, void *data)
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
if (!strcmp(imtype,"TGA")) scene->r.imtype = R_TARGA;
|
||||
else if (!strcmp(imtype,"IRIS")) scene->r.imtype = R_IRIS;
|
||||
else if (!strcmp(imtype,"HAMX")) scene->r.imtype = R_HAMX;
|
||||
#ifdef WITH_DDS
|
||||
else if (!strcmp(imtype,"DDS")) scene->r.imtype = R_DDS;
|
||||
#endif
|
||||
else if (!strcmp(imtype,"JPEG")) scene->r.imtype = R_JPEG90;
|
||||
else if (!strcmp(imtype,"MOVIE")) scene->r.imtype = R_MOVIE;
|
||||
else if (!strcmp(imtype,"IRIZ")) scene->r.imtype = R_IRIZ;
|
||||
else if (!strcmp(imtype,"RAWTGA")) scene->r.imtype = R_RAWTGA;
|
||||
else if (!strcmp(imtype,"AVIRAW")) scene->r.imtype = R_AVIRAW;
|
||||
@@ -972,6 +968,8 @@ int main(int argc, char **argv)
|
||||
|
||||
initglobals(); /* blender.c */
|
||||
|
||||
IMB_init();
|
||||
|
||||
syshandle = SYS_GetSystem();
|
||||
GEN_init_messaging_system();
|
||||
|
||||
@@ -1042,20 +1040,6 @@ int main(int argc, char **argv)
|
||||
CTX_py_init_set(C, 1);
|
||||
WM_keymap_init(C);
|
||||
|
||||
#ifdef WITH_QUICKTIME
|
||||
|
||||
quicktime_init();
|
||||
|
||||
#endif /* WITH_QUICKTIME */
|
||||
|
||||
/* dynamically load libtiff, if available */
|
||||
libtiff_init();
|
||||
if (!G.have_libtiff && (G.f & G_DEBUG)) {
|
||||
printf("Unable to load: libtiff.\n");
|
||||
printf("Try setting the BF_TIFF_LIB environment variable if you want this support.\n");
|
||||
printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n");
|
||||
}
|
||||
|
||||
/* OK we are ready for it */
|
||||
BLI_argsParse(ba, 4, load_file, C);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user