Blender  V2.93
writeimage.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  * writeimage.c
19  */
20 
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 
29 #include "BLI_path_util.h"
30 #include "BLI_utildefines.h"
31 
32 #include "IMB_filetype.h"
33 #include "IMB_imbuf.h"
34 #include "IMB_imbuf_types.h"
35 
36 #include "IMB_colormanagement.h"
38 
39 static bool prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf)
40 {
41  return IMB_prepare_write_ImBuf((type->flag & IM_FTYPE_FLOAT), ibuf);
42 }
43 
44 bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
45 {
46  errno = 0;
47 
48  BLI_assert(!BLI_path_is_rel(filepath));
49 
50  if (ibuf == NULL) {
51  return false;
52  }
53  ibuf->flags = flags;
54 
56  if (type != NULL) {
57  if (type->save != NULL) {
59  return type->save(ibuf, filepath, flags);
60  }
61  }
62 
63  fprintf(stderr, "Couldn't save picture.\n");
64 
65  return false;
66 }
67 
68 bool IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf)
69 {
70  bool changed = false;
71 
72  if (isfloat) {
73  /* pass */
74  }
75  else {
76  if (ibuf->rect == NULL && ibuf->rect_float) {
78  IMB_rect_from_float(ibuf);
79  if (ibuf->rect != NULL) {
80  changed = true;
81  }
82  }
83  }
84 
85  return changed;
86 }
#define BLI_assert(a)
Definition: BLI_assert.h:58
bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:411
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
@ COLOR_ROLE_DEFAULT_BYTE
#define IM_FTYPE_FLOAT
Definition: IMB_filetype.h:29
void IMB_rect_from_float(struct ImBuf *ibuf)
Definition: divers.c:720
Contains defines and structs used throughout the imbuf module.
ColorSpace * colormanage_colorspace_get_roled(int role)
const ImFileType * IMB_file_type_from_ibuf(const ImBuf *ibuf)
Definition: filetype.c:229
struct ColorSpace * rect_colorspace
unsigned int * rect
float * rect_float
bool IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf)
Definition: writeimage.c:68
static bool prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf)
Definition: writeimage.c:39
bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: writeimage.c:44