3 * ***** BEGIN GPL/BL DUAL 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. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL/BL DUAL LICENSE BLOCK *****
39 #include "BKE_global.h"
40 #include "BLI_blenlib.h"
43 #include "imbuf_patch.h"
45 #include "IMB_imbuf_types.h"
46 #include "IMB_imbuf.h"
48 #include "IMB_allocimbuf.h"
50 #include "IMB_dpxcineon.h"
51 #include "IMB_targa.h"
56 #include "IMB_amiga.h"
60 #include "IMB_radiance_hdr.h"
62 #include "openexr/openexr_api.h"
65 #include "dds/dds_api.h"
69 #include "IMB_bitplanes.h"
70 #include "IMB_divers.h"
72 /* added facility to copy with saving non-float rects */
74 short IMB_saveiff(struct ImBuf *ibuf, char *name, int flags)
76 short ok=TRUE,delpl=FALSE;
79 if (ibuf==0) return (FALSE);
82 /* Put formats that take a filename here */
84 if(ibuf->rect==NULL && ibuf->rect_float)
85 IMB_rect_from_float(ibuf);
86 return imb_savejpeg(ibuf, name, flags);
88 if (IS_radhdr(ibuf)) {
89 return imb_savehdr(ibuf, name, flags);
92 if(ibuf->rect==NULL && ibuf->rect_float)
93 IMB_rect_from_float(ibuf);
94 return imb_savepng(ibuf, name, flags);
97 if(ibuf->rect==NULL && ibuf->rect_float)
98 IMB_rect_from_float(ibuf);
99 return imb_savebmp(ibuf, name, flags);
102 if(ibuf->rect==NULL && ibuf->rect_float)
103 IMB_rect_from_float(ibuf);
104 return imb_savetarga(ibuf, name, flags);
107 if(ibuf->rect==NULL && ibuf->rect_float)
108 IMB_rect_from_float(ibuf);
109 return imb_saveiris(ibuf, name, flags);
111 if (G.have_libtiff && IS_tiff(ibuf)) {
112 if(ibuf->rect==NULL && ibuf->rect_float)
113 IMB_rect_from_float(ibuf);
114 return imb_savetiff(ibuf, name, flags);
117 if (IS_openexr(ibuf)) {
118 return imb_save_openexr(ibuf, name, flags);
124 return imb_save_dds(ibuf, name, flags);
128 if (IS_cineon(ibuf)) {
129 return imb_savecineon(ibuf, name, flags);
133 return imb_save_dpx(ibuf, name, flags);
135 file = open(name, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
136 if (file < 0) return (FALSE);
138 if (flags & IB_rect){
140 imb_checkncols(ibuf);
144 /* Put formats that take a filehandle here */
145 ok = imb_start_iff(ibuf,file);
148 if (flags & IB_rect){
149 if ((flags & IB_cmap) == 0) {
151 if (ok) ok = imb_converttoham(ibuf);
152 }else if (ibuf->cmap){
153 if (ok) ok = IMB_converttocmap(ibuf);
157 if (ibuf->planes==0){
159 ok=imb_addplanesImBuf(ibuf);
165 if (flags & IB_vert){
166 if (ok) ok = imb_encodebodyv(ibuf,file);
169 if (ok) ok = imb_encodebodyh(ibuf,file);
171 if (ok) ok = imb_update_iff(file,BODY);
172 }else if (IS_anim(ibuf)) {
173 if (ok) ok = imb_enc_anim(ibuf, file);
174 if (ok) ok = imb_update_iff(file, BODY);
179 fprintf(stderr,"Couldn't save picture.\n");
181 if (delpl) imb_freeplanesImBuf(ibuf);