3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
34 #include "BKE_global.h"
35 #include "BLI_blenlib.h"
38 #include "imbuf_patch.h"
40 #include "IMB_imbuf_types.h"
41 #include "IMB_imbuf.h"
43 #include "IMB_allocimbuf.h"
45 #include "IMB_dpxcineon.h"
46 #include "IMB_targa.h"
51 #include "IMB_amiga.h"
54 #include "IMB_radiance_hdr.h"
56 #if defined(__APPLE__) && defined(GHOST_COCOA)
57 #include "IMB_cocoa.h"
67 #include "openexr/openexr_api.h"
71 #include "dds/dds_api.h"
75 #include "IMB_bitplanes.h"
76 #include "IMB_divers.h"
80 #include "BLI_winstuff.h"
82 /* added facility to copy with saving non-float rects */
84 short IMB_saveiff(struct ImBuf *ibuf, char *name, int flags)
86 short ok=TRUE,delpl=FALSE;
89 if (ibuf==0) return (FALSE);
92 /* Put formats that take a filename here */
94 if(ibuf->rect==NULL && ibuf->rect_float)
95 IMB_rect_from_float(ibuf);
96 return imb_savejpeg(ibuf, name, flags);
98 if (IS_radhdr(ibuf)) {
99 return imb_savehdr(ibuf, name, flags);
102 if(ibuf->rect==NULL && ibuf->rect_float)
103 IMB_rect_from_float(ibuf);
104 return imb_savepng(ibuf, name, flags);
107 if(ibuf->rect==NULL && ibuf->rect_float)
108 IMB_rect_from_float(ibuf);
109 return imb_savebmp(ibuf, name, flags);
112 if(ibuf->rect==NULL && ibuf->rect_float)
113 IMB_rect_from_float(ibuf);
114 return imb_savetarga(ibuf, name, flags);
117 if(ibuf->rect==NULL && ibuf->rect_float)
118 IMB_rect_from_float(ibuf);
119 return imb_saveiris(ibuf, name, flags);
122 #if defined(__APPLE__) && defined(GHOST_COCOA)
124 if(ibuf->rect==NULL && ibuf->rect_float)
125 IMB_rect_from_float(ibuf);
126 return imb_cocoaSaveImage(ibuf, name, flags);
129 if (G.have_libtiff && IS_tiff(ibuf)) {
130 if(ibuf->rect==NULL && ibuf->rect_float)
131 IMB_rect_from_float(ibuf);
132 return imb_savetiff(ibuf, name, flags);
137 if (IS_openexr(ibuf)) {
138 return imb_save_openexr(ibuf, name, flags);
144 return imb_save_dds(ibuf, name, flags);
148 if (IS_cineon(ibuf)) {
149 return imb_savecineon(ibuf, name, flags);
153 return imb_save_dpx(ibuf, name, flags);
157 return imb_savejp2(ibuf, name, flags);
160 file = open(name, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
161 if (file < 0) return (FALSE);
163 if (flags & IB_rect){
165 imb_checkncols(ibuf);
169 /* Put formats that take a filehandle here */
170 ok = imb_start_iff(ibuf,file);
173 if (flags & IB_rect){
174 if ((flags & IB_cmap) == 0) {
176 if (ok) ok = imb_converttoham(ibuf);
177 }else if (ibuf->cmap){
178 if (ok) ok = IMB_converttocmap(ibuf);
182 if (ibuf->planes==0){
184 ok=imb_addplanesImBuf(ibuf);
190 if (flags & IB_vert){
191 if (ok) ok = imb_encodebodyv(ibuf,file);
194 if (ok) ok = imb_encodebodyh(ibuf,file);
196 if (ok) ok = imb_update_iff(file,BODY);
197 }else if (IS_anim(ibuf)) {
198 if (ok) ok = imb_enc_anim(ibuf, file);
199 if (ok) ok = imb_update_iff(file, BODY);
204 fprintf(stderr,"Couldn't save picture.\n");
206 if (delpl) imb_freeplanesImBuf(ibuf);