replace ImBuf.depth with ImBuf.planes to match ImageFormatData.planes & to avoid...
[blender.git] / source / blender / blenkernel / intern / image.c
index 9aeacb9d7fa36f830841d1a5599fda2eb429319f..c99396e6939fd54146e6d0561955e78c67759a7d 100644 (file)
@@ -385,13 +385,12 @@ void make_local_image(struct Image *ima)
                extern_local_image(ima);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, ima->id.lib->filepath};
                Image *iman= copy_image(ima);
 
                iman->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &iman->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &iman->id);
 
                tex= bmain->tex.first;
                while(tex) {
@@ -602,7 +601,7 @@ void BKE_image_memorypack(Image *ima)
        }
        
        ibuf->ftype= PNG;
-       ibuf->depth= 32;
+       ibuf->planes= R_IMF_PLANES_RGBA;
        
        IMB_saveiff(ibuf, ibuf->name, IB_rect | IB_mem);
        if(ibuf->encodedbuffer==NULL) {
@@ -901,6 +900,76 @@ int BKE_imtype_is_movie(int imtype)
        return 0;
 }
 
+int BKE_imtype_is_alpha_ok(int imtype)
+{
+       switch(imtype) {
+       case R_TARGA:
+       case R_IRIS:
+       case R_PNG:
+       case R_BMP:
+       case R_RADHDR:
+       case R_TIFF:
+       case R_OPENEXR:
+       case R_MULTILAYER:
+       case R_DDS:
+       case R_JP2:
+                       return 1;
+       }
+       return 0;
+}
+
+int BKE_imtype_is_zbuf_ok(int imtype)
+{
+       switch(imtype) {
+       case R_IRIZ:
+       case R_OPENEXR: /* but not R_MULTILAYER */
+                       return 1;
+       }
+       return 0;
+}
+
+int BKE_imtype_is_compression_ok(int imtype)
+{
+       switch(imtype) {
+       case R_PNG:
+                       return 1;
+       }
+       return 0;
+}
+
+int BKE_imtype_is_quality_ok(int imtype)
+{
+       switch(imtype) {
+       case R_JPEG90:
+       case R_JP2:
+                       return 1;
+       }
+       return 0;
+}
+
+int BKE_imtype_is_depth_ok(int imtype)
+{
+       switch (imtype) {
+       case R_RADHDR:
+               return R_IMF_CHAN_DEPTH_32;
+       case R_TIFF:
+               return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16;
+       case R_OPENEXR:
+               return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32;
+       case R_MULTILAYER:
+               return R_IMF_CHAN_DEPTH_32;
+       /* eeh, cineone does some strange 10bits per channel */
+       case R_DPX:
+       case R_CINEON:
+               return R_IMF_CHAN_DEPTH_12;
+       case R_JP2:
+               return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16;
+       /* most formats are 8bit only */
+       default:
+               return R_IMF_CHAN_DEPTH_8;
+       }
+}
+
 int BKE_add_image_extension(char *string, int imtype)
 {
        const char *extension= NULL;
@@ -1372,10 +1441,13 @@ int BKE_alphatest_ibuf(ImBuf *ibuf)
        return FALSE;
 }
 
-int BKE_write_ibuf(ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality)
+int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf)
 {
+       char imtype= imf->imtype;
+       char compress= imf->compress;
+       char quality= imf->quality;
+
        int ok;
-       (void)subimtype; /* quies unused warnings */
 
        if(imtype == -1) {
                /* use whatever existing image type is set by 'ibuf' */
@@ -1392,7 +1464,7 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, int imtype, int subimtype, int
                ibuf->ftype= PNG;
 
                if(imtype==R_PNG)
-                       ibuf->ftype |= quality;  /* quality is actually compression 0-100 --> 0-9 */
+                       ibuf->ftype |= compress;
 
        }
 #ifdef WITH_DDS
@@ -1407,18 +1479,18 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, int imtype, int subimtype, int
        else if (imtype==R_TIFF) {
                ibuf->ftype= TIF;
 
-               if(subimtype & R_TIFF_16BIT)
+               if(imf->depth == R_IMF_CHAN_DEPTH_16)
                        ibuf->ftype |= TIF_16BIT;
        }
 #endif
 #ifdef WITH_OPENEXR
        else if (imtype==R_OPENEXR || imtype==R_MULTILAYER) {
                ibuf->ftype= OPENEXR;
-               if(subimtype & R_OPENEXR_HALF)
+               if(imf->depth == R_IMF_CHAN_DEPTH_16)
                        ibuf->ftype |= OPENEXR_HALF;
                ibuf->ftype |= (quality & OPENEXR_COMPRESS);
                
-               if(!(subimtype & R_OPENEXR_ZBUF))
+               if(!(imf->flag & R_IMF_FLAG_ZBUF))
                        ibuf->zbuf_float = NULL;        /* signal for exr saving */
                
        }
@@ -1442,19 +1514,19 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, int imtype, int subimtype, int
                if(quality < 10) quality= 90;
                ibuf->ftype= JP2|quality;
                
-               if (subimtype & R_JPEG2K_16BIT) {
+               if (imf->depth == R_IMF_CHAN_DEPTH_16) {
                        ibuf->ftype |= JP2_16BIT;
-               } else if (subimtype & R_JPEG2K_12BIT) {
+               } else if (imf->depth == R_IMF_CHAN_DEPTH_12) {
                        ibuf->ftype |= JP2_12BIT;
                }
                
-               if (subimtype & R_JPEG2K_YCC) {
+               if (imf->jp2_flag & R_IMF_JP2_FLAG_YCC) {
                        ibuf->ftype |= JP2_YCC;
                }
-               
-               if (subimtype & R_JPEG2K_CINE_PRESET) {
+
+               if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_PRESET) {
                        ibuf->ftype |= JP2_CINE;
-                       if (subimtype & R_JPEG2K_CINE_48FPS)
+                       if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_48)
                                ibuf->ftype |= JP2_CINE_48FPS;
                }
        }
@@ -1463,7 +1535,7 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, int imtype, int subimtype, int
                /* 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 */
+               if(ibuf->planes==32) ibuf->planes= 24;  /* unsupported feature only confuses other s/w */
        }
        
        BLI_make_existing_file(name);
@@ -1476,20 +1548,20 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, int imtype, int subimtype, int
        return(ok);
 }
 
-int BKE_write_ibuf_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality)
+int BKE_write_ibuf_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const char *name, struct ImageFormatData *imf)
 {
        if(scene && scene->r.stamp & R_STAMP_ALL)
                BKE_stamp_info(scene, camera, ibuf);
 
-       return BKE_write_ibuf(ibuf, name, imtype, subimtype, quality);
+       return BKE_write_ibuf(ibuf, name, imf);
 }
 
 
-void BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames)
+void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, int imtype, const short use_ext, const short use_frames)
 {
        if (string==NULL) return;
        BLI_strncpy(string, base, FILE_MAX - 10);       /* weak assumption */
-       BLI_path_abs(string, G.main->name);
+       BLI_path_abs(string, relbase);
 
        if(use_frames)
                BLI_path_frame(string, frame, 4);
@@ -2415,13 +2487,13 @@ int BKE_image_has_alpha(struct Image *image)
 {
        ImBuf *ibuf;
        void *lock;
-       int depth;
+       int planes;
        
        ibuf= BKE_image_acquire_ibuf(image, NULL, &lock);
-       depth = (ibuf?ibuf->depth:0);
+       planes = (ibuf?ibuf->planes:0);
        BKE_image_release_ibuf(image, lock);
 
-       if (depth == 32)
+       if (planes == 32)
                return 1;
        else
                return 0;