~diresu/blender/blender-command-port-002

« back to all changes in this revision

Viewing changes to source/blender/imbuf/intern/writeimage.c

  • Committer: Dietrich Bollmann
  • Date: 2010-07-23 08:21:44 UTC
  • mfrom: (15474.1.5025)
  • Revision ID: dietrich@formgames.org-20100723082144-24nrn8oku0115pwh
Update to state of blender repository from 2010-07-23 revision 30644.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
#include <stdio.h>
33
33
 
34
 
#include "BKE_global.h"
35
 
#include "BLI_blenlib.h"
36
 
 
37
 
#include "imbuf.h"
38
 
#include "imbuf_patch.h"
39
 
 
40
34
#include "IMB_imbuf_types.h"
41
35
#include "IMB_imbuf.h"
42
 
 
43
 
#include "IMB_allocimbuf.h"
44
 
 
45
 
#include "IMB_dpxcineon.h"
46
 
#include "IMB_targa.h"
47
 
#include "IMB_jpeg.h"
48
 
#include "IMB_iris.h"
49
 
#include "IMB_ham.h"
50
 
#include "IMB_hamx.h"
51
 
#include "IMB_amiga.h"
52
 
#include "IMB_png.h"
53
 
#include "IMB_bmp.h"
54
 
#include "IMB_radiance_hdr.h"
55
 
 
56
 
#if defined(__APPLE__) && defined(IMBUF_COCOA)
57
 
#include "IMB_cocoa.h"
58
 
#else
59
 
#include "IMB_tiff.h"
60
 
#endif
61
 
 
62
 
#ifdef WITH_OPENJPEG
63
 
#include "IMB_jp2.h"
64
 
#endif
65
 
 
66
 
#ifdef WITH_OPENEXR
67
 
#include "openexr/openexr_api.h"
68
 
#endif
69
 
 
70
 
#ifdef WITH_DDS
71
 
#include "dds/dds_api.h"
72
 
#endif
73
 
 
74
 
#include "IMB_iff.h"
75
 
#include "IMB_bitplanes.h"
76
 
#include "IMB_divers.h"
77
 
 
78
 
#ifdef WIN32
79
 
#include <io.h>
80
 
#include "BLI_winstuff.h"
81
 
#endif
82
 
/* added facility to copy with saving non-float rects */
 
36
#include "IMB_filetype.h"
 
37
 
 
38
#include "imbuf.h"
83
39
 
84
40
short IMB_saveiff(struct ImBuf *ibuf, char *name, int flags)
85
41
{
86
 
        short ok=TRUE,delpl=FALSE;
87
 
        int file = -1;
 
42
        ImFileType *type;
88
43
 
89
 
        if (ibuf==0) return (FALSE);
 
44
        if(ibuf == NULL) return (FALSE);
90
45
        ibuf->flags = flags;
91
46
 
92
 
        /* Put formats that take a filename here */
93
 
        if (IS_jpg(ibuf)) {
94
 
                if(ibuf->rect==NULL && ibuf->rect_float)
95
 
                        IMB_rect_from_float(ibuf);
96
 
                return imb_savejpeg(ibuf, name, flags);
97
 
        }
98
 
        if (IS_radhdr(ibuf)) {
99
 
                return imb_savehdr(ibuf, name, flags);
100
 
        }
101
 
        if (IS_png(ibuf)) {
102
 
                if(ibuf->rect==NULL && ibuf->rect_float)
103
 
                        IMB_rect_from_float(ibuf);
104
 
                return imb_savepng(ibuf, name, flags);
105
 
        }
106
 
        if (IS_bmp(ibuf)) {
107
 
                if(ibuf->rect==NULL && ibuf->rect_float)
108
 
                        IMB_rect_from_float(ibuf);
109
 
                return imb_savebmp(ibuf, name, flags);
110
 
        }
111
 
        if (IS_tga(ibuf)) {
112
 
                if(ibuf->rect==NULL && ibuf->rect_float)
113
 
                        IMB_rect_from_float(ibuf);
114
 
                return imb_savetarga(ibuf, name, flags);
115
 
        }
116
 
        if (IS_iris(ibuf)) {
117
 
                if(ibuf->rect==NULL && ibuf->rect_float)
118
 
                        IMB_rect_from_float(ibuf);
119
 
                return imb_saveiris(ibuf, name, flags);
120
 
        }
121
 
        
122
 
#if defined(__APPLE__) && defined(IMBUF_COCOA)
123
 
        if (IS_tiff(ibuf)) {
124
 
                if(ibuf->rect==NULL && ibuf->rect_float)
125
 
                        IMB_rect_from_float(ibuf);
126
 
                return imb_cocoaSaveImage(ibuf, name, flags);
127
 
        }
128
 
#else
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);
133
 
        }
134
 
#endif
135
 
        
136
 
#ifdef WITH_OPENEXR
137
 
        if (IS_openexr(ibuf)) {
138
 
                return imb_save_openexr(ibuf, name, flags);
139
 
        }
140
 
#endif
141
 
/* not supported yet
142
 
#ifdef WITH_DDS
143
 
        if (IS_dds(ibuf)) {
144
 
                return imb_save_dds(ibuf, name, flags);
145
 
        }
146
 
#endif
147
 
*/
148
 
        if (IS_cineon(ibuf)) {
149
 
                return imb_savecineon(ibuf, name, flags);
150
 
                
151
 
        }
152
 
        if (IS_dpx(ibuf)) {
153
 
                return imb_save_dpx(ibuf, name, flags);
154
 
        }
155
 
#ifdef WITH_OPENJPEG
156
 
        if (IS_jp2(ibuf)) {
157
 
                return imb_savejp2(ibuf, name, flags);
158
 
        }
159
 
#endif  
160
 
        file = open(name, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
161
 
        if (file < 0) return (FALSE);
162
 
 
163
 
        if (flags & IB_rect){
164
 
                if (ibuf->cmap){
165
 
                        imb_checkncols(ibuf);
166
 
                }
167
 
        }
168
 
 
169
 
        /* Put formats that take a filehandle here */
170
 
        ok = imb_start_iff(ibuf,file);
171
 
        if (IS_amiga(ibuf)){
172
 
                IMB_flipy(ibuf);
173
 
                if (flags & IB_rect){
174
 
                        if ((flags & IB_cmap) == 0) {
175
 
                                if (IS_ham(ibuf)){
176
 
                                        if (ok) ok = imb_converttoham(ibuf);
177
 
                                }else if (ibuf->cmap){
178
 
                                        if (ok) ok = IMB_converttocmap(ibuf);
179
 
                                }
180
 
                        }
181
 
                        if (ok){
182
 
                                if (ibuf->planes==0){
183
 
                                        delpl=TRUE;
184
 
                                        ok=imb_addplanesImBuf(ibuf);
185
 
                                }
186
 
                                imb_longtobp(ibuf);
187
 
                        }
188
 
                }
189
 
 
190
 
                if (flags & IB_vert){
191
 
                        if (ok) ok = imb_encodebodyv(ibuf,file);
192
 
                }
193
 
                else{
194
 
                        if (ok) ok = imb_encodebodyh(ibuf,file);
195
 
                }
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);
200
 
        }
201
 
        close(file);
202
 
 
203
 
        if (ok==FALSE) {
204
 
                fprintf(stderr,"Couldn't save picture.\n");
205
 
        }       
206
 
        if (delpl) imb_freeplanesImBuf(ibuf);
207
 
 
208
 
        return (ok);
 
47
        for(type=IMB_FILE_TYPES; type->is_a; type++) {
 
48
                if(type->save && type->ftype(type, ibuf)) {
 
49
                        if(!(type->flag & IM_FTYPE_FLOAT)) {
 
50
                                if(ibuf->rect==NULL && ibuf->rect_float)
 
51
                                        IMB_rect_from_float(ibuf);
 
52
                        }
 
53
 
 
54
                        return type->save(ibuf, name, flags);
 
55
                }
 
56
        }
 
57
 
 
58
        fprintf(stderr, "Couldn't save picture.\n");
 
59
 
 
60
        return FALSE;
209
61
}
210
62