2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbuf
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstring>
|
2010-08-16 05:46:10 +00:00
|
|
|
|
2012-08-12 23:28:33 +00:00
|
|
|
#include "BLI_fileops.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2012-08-12 23:28:33 +00:00
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include "IMB_filetype.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "imbuf.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
#include "IMB_colormanagement_intern.h"
|
|
|
|
|
|
2015-07-13 13:58:17 +02:00
|
|
|
#define IMAGIC 0732
|
|
|
|
|
|
2023-07-24 10:10:47 +10:00
|
|
|
struct IMAGE {
|
2021-07-23 16:56:00 +10:00
|
|
|
ushort imagic; /* Stuff saved on disk. */
|
2017-09-17 16:14:59 +10:00
|
|
|
ushort type;
|
|
|
|
|
ushort dim;
|
|
|
|
|
ushort xsize;
|
|
|
|
|
ushort ysize;
|
|
|
|
|
ushort zsize;
|
|
|
|
|
uint min;
|
|
|
|
|
uint max;
|
2017-09-17 17:55:04 +10:00
|
|
|
uchar _pad1[4];
|
2017-09-17 16:14:59 +10:00
|
|
|
char name[80];
|
|
|
|
|
uint colormap;
|
2017-09-17 17:55:04 +10:00
|
|
|
uchar _pad2[404];
|
2023-07-24 10:10:47 +10:00
|
|
|
};
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
#define HEADER_SIZE 512
|
|
|
|
|
|
2017-09-17 17:55:04 +10:00
|
|
|
BLI_STATIC_ASSERT(sizeof(IMAGE) == HEADER_SIZE, "Invalid header size");
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#define RINTLUM (79)
|
|
|
|
|
#define GINTLUM (156)
|
|
|
|
|
#define BINTLUM (21)
|
|
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
#define ILUM(r, g, b) (int(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8)
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
#define OFFSET_R 0 /* this is byte order dependent */
|
|
|
|
|
#define OFFSET_G 1
|
|
|
|
|
#define OFFSET_B 2
|
2012-09-20 01:02:39 +00:00
|
|
|
// #define OFFSET_A 3
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
#define CHANOFFSET(z) (3 - (z)) /* this is byte order dependent */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-09-20 01:02:39 +00:00
|
|
|
// #define TYPEMASK 0xff00
|
2012-05-16 09:26:37 +00:00
|
|
|
#define BPPMASK 0x00ff
|
2021-08-26 12:27:17 +10:00
|
|
|
// #define ITYPE_VERBATIM 0x0000 /* UNUSED */
|
2012-05-16 09:26:37 +00:00
|
|
|
#define ITYPE_RLE 0x0100
|
|
|
|
|
#define ISRLE(type) (((type)&0xff00) == ITYPE_RLE)
|
2012-09-20 01:02:39 +00:00
|
|
|
// #define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM)
|
2012-05-16 09:26:37 +00:00
|
|
|
#define BPP(type) ((type)&BPPMASK)
|
|
|
|
|
#define RLE(bpp) (ITYPE_RLE | (bpp))
|
2021-08-26 12:27:17 +10:00
|
|
|
// #define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) /* UNUSED */
|
|
|
|
|
// #define IBUFSIZE(pixels) ((pixels + (pixels >> 6)) << 2) /* UNUSED */
|
2012-09-20 01:02:39 +00:00
|
|
|
// #define RLE_NOP 0x00
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
/* local struct for mem access */
|
2023-07-02 19:37:19 +10:00
|
|
|
struct MFileOffset {
|
2015-07-12 01:06:32 +10:00
|
|
|
const uchar *_file_data;
|
2017-09-17 16:14:59 +10:00
|
|
|
uint _file_offset;
|
2023-07-02 19:37:19 +10:00
|
|
|
};
|
2015-07-12 01:06:32 +10:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
#define MFILE_DATA(inf) ((void)0, ((inf)->_file_data + (inf)->_file_offset))
|
2015-07-12 01:06:32 +10:00
|
|
|
#define MFILE_STEP(inf, step) \
|
|
|
|
|
{ \
|
|
|
|
|
(inf)->_file_offset += step; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
|
|
|
|
#define MFILE_SEEK(inf, pos) \
|
|
|
|
|
{ \
|
|
|
|
|
(inf)->_file_offset = pos; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
|
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
/* error flags */
|
|
|
|
|
#define DIRTY_FLAG_EOF (1 << 0)
|
|
|
|
|
#define DIRTY_FLAG_ENCODING (1 << 1)
|
|
|
|
|
|
2022-09-19 14:47:27 +10:00
|
|
|
/* Functions. */
|
2015-07-12 01:06:32 +10:00
|
|
|
static void readheader(MFileOffset *inf, IMAGE *image);
|
2002-10-12 11:37:38 +00:00
|
|
|
static int writeheader(FILE *outf, IMAGE *image);
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static ushort getshort(MFileOffset *inf);
|
2020-09-04 20:59:13 +02:00
|
|
|
static uint getlong(MFileOffset *mofs);
|
2017-09-17 16:14:59 +10:00
|
|
|
static void putshort(FILE *outf, ushort val);
|
|
|
|
|
static int putlong(FILE *outf, uint val);
|
|
|
|
|
static int writetab(FILE *outf, uint *tab, int len);
|
|
|
|
|
static void readtab(MFileOffset *inf, uint *tab, int len);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
static int expandrow(
|
|
|
|
|
uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z);
|
|
|
|
|
static int expandrow2(
|
|
|
|
|
float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z);
|
2017-09-17 16:14:59 +10:00
|
|
|
static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n);
|
|
|
|
|
static void interleaverow2(float *lptr, const uchar *cptr, int z, int n);
|
2022-05-17 10:24:26 +10:00
|
|
|
static int compressrow(const uchar *lbuf, uchar *rlebuf, int z, int row_len);
|
2020-07-13 11:27:09 +02:00
|
|
|
static void lumrow(const uchar *rgbptr, uchar *lumptr, int n);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* byte order independent read/write of shorts and ints.
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static ushort getshort(MFileOffset *inf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2017-09-17 16:14:59 +10:00
|
|
|
const uchar *buf;
|
2010-10-17 06:38:56 +00:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
buf = MFILE_DATA(inf);
|
|
|
|
|
MFILE_STEP(inf, 2);
|
2017-09-17 16:19:07 +10:00
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
return (ushort(buf[0]) << 8) + (ushort(buf[1]) << 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static uint getlong(MFileOffset *mofs)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2017-09-17 16:14:59 +10:00
|
|
|
const uchar *buf;
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
buf = MFILE_DATA(mofs);
|
|
|
|
|
MFILE_STEP(mofs, 4);
|
2017-09-17 16:19:07 +10:00
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
return (uint(buf[0]) << 24) + (uint(buf[1]) << 16) + (uint(buf[2]) << 8) + (uint(buf[3]) << 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static void putshort(FILE *outf, ushort val)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2017-09-17 16:14:59 +10:00
|
|
|
uchar buf[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
buf[0] = (val >> 8);
|
|
|
|
|
buf[1] = (val >> 0);
|
2012-04-29 15:47:02 +00:00
|
|
|
fwrite(buf, 2, 1, outf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static int putlong(FILE *outf, uint val)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2017-09-17 16:14:59 +10:00
|
|
|
uchar buf[4];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
buf[0] = (val >> 24);
|
|
|
|
|
buf[1] = (val >> 16);
|
|
|
|
|
buf[2] = (val >> 8);
|
|
|
|
|
buf[3] = (val >> 0);
|
2012-04-29 15:47:02 +00:00
|
|
|
return fwrite(buf, 4, 1, outf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
static void readheader(MFileOffset *inf, IMAGE *image)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
memset(image, 0, sizeof(IMAGE));
|
|
|
|
|
image->imagic = getshort(inf);
|
|
|
|
|
image->type = getshort(inf);
|
|
|
|
|
image->dim = getshort(inf);
|
|
|
|
|
image->xsize = getshort(inf);
|
|
|
|
|
image->ysize = getshort(inf);
|
|
|
|
|
image->zsize = getshort(inf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int writeheader(FILE *outf, IMAGE *image)
|
|
|
|
|
{
|
2012-05-16 09:26:37 +00:00
|
|
|
IMAGE t = {0};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
fwrite(&t, sizeof(IMAGE), 1, outf);
|
|
|
|
|
fseek(outf, 0, SEEK_SET);
|
|
|
|
|
putshort(outf, image->imagic);
|
|
|
|
|
putshort(outf, image->type);
|
|
|
|
|
putshort(outf, image->dim);
|
|
|
|
|
putshort(outf, image->xsize);
|
|
|
|
|
putshort(outf, image->ysize);
|
|
|
|
|
putshort(outf, image->zsize);
|
|
|
|
|
putlong(outf, image->min);
|
|
|
|
|
putlong(outf, image->max);
|
|
|
|
|
putlong(outf, 0);
|
|
|
|
|
return fwrite("no name", 8, 1, outf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static int writetab(FILE *outf, uint *tab, int len)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
Fixed two uninitalized vars:
Kent
/cvs01/blender/source/blender/imbuf/intern/iris.c,v
retrieving revision 1.3
diff -u -r1.3 iris.c
--- iris.c 2002/11/25 12:02:00 1.3
+++ iris.c 2002/12/19 22:12:53
@@ -212,7 +212,7 @@
/* unsigned int *tab; */
/* int len; */
{
- int r;
+ int r = 0;
while(len) {
r = putlong(outf,*tab++);
@@ -548,7 +548,7 @@
{
FILE *outf;
IMAGE *image;
- int tablen, y, z, pos, len;
+ int tablen, y, z, pos, len = 0;
int *starttab, *lengthtab;
unsigned char *rlebuf;
2002-12-19 22:13:37 +00:00
|
|
|
int r = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (len) {
|
2012-04-29 15:47:02 +00:00
|
|
|
r = putlong(outf, *tab++);
|
2002-10-12 11:37:38 +00:00
|
|
|
len -= 4;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static void readtab(MFileOffset *inf, uint *tab, int len)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
while (len) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*tab++ = getlong(inf);
|
|
|
|
|
len -= 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* From misc_util: flip the bytes from x. */
|
2017-09-17 16:14:59 +10:00
|
|
|
#define GS(x) (((uchar *)(x))[0] << 8 | ((uchar *)(x))[1])
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* This one is only def-ed once, strangely... */
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
|
|
|
|
|
|
2020-11-11 16:14:09 +11:00
|
|
|
bool imb_is_a_iris(const uchar *mem, size_t size)
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
{
|
2020-11-11 16:14:09 +11:00
|
|
|
if (size < 2) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
return ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC));
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
uint *base, *lptr = nullptr;
|
|
|
|
|
float *fbase, *fptr = nullptr;
|
2017-09-17 16:14:59 +10:00
|
|
|
const uchar *rledat;
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *mem_end = mem + size;
|
2015-07-12 01:06:32 +10:00
|
|
|
MFileOffset _inf_data = {mem, 0}, *inf = &_inf_data;
|
2002-10-12 11:37:38 +00:00
|
|
|
IMAGE image;
|
|
|
|
|
int bpp, rle, cur, badorder;
|
2023-05-02 11:32:27 +02:00
|
|
|
ImBuf *ibuf = nullptr;
|
2017-09-17 16:22:56 +10:00
|
|
|
uchar dirty_flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-31 17:05:57 +11:00
|
|
|
if (!imb_is_a_iris(mem, size)) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2017-09-17 16:22:56 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-12 17:52:35 +11:00
|
|
|
/* Could be part of the magic check above,
|
2021-03-31 17:05:57 +11:00
|
|
|
* by convention this check only requests the size needed to read it's magic though. */
|
|
|
|
|
if (size < HEADER_SIZE) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2017-09-17 16:22:56 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
/* OCIO_TODO: only tested with 1 byte per pixel, not sure how to test with other settings */
|
|
|
|
|
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
readheader(inf, &image);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (image.imagic != IMAGIC) {
|
2012-04-29 15:47:02 +00:00
|
|
|
fprintf(stderr, "longimagedata: bad magic number in image file\n");
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
rle = ISRLE(image.type);
|
|
|
|
|
bpp = BPP(image.type);
|
2020-11-06 12:30:59 +11:00
|
|
|
if (!ELEM(bpp, 1, 2)) {
|
2012-04-29 15:47:02 +00:00
|
|
|
fprintf(stderr, "longimagedata: image must have 1 or 2 byte per pix chan\n");
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2023-05-02 20:09:09 +10:00
|
|
|
if (uint(image.zsize) > 8) {
|
2017-09-17 16:22:56 +10:00
|
|
|
fprintf(stderr, "longimagedata: channels over 8 not supported\n");
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2017-09-17 16:22:56 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
const int xsize = image.xsize;
|
|
|
|
|
const int ysize = image.ysize;
|
2023-07-04 17:03:02 +02:00
|
|
|
|
|
|
|
|
const int zsize_file = image.zsize;
|
|
|
|
|
const int zsize_read = min_ii(image.zsize, 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (flags & IB_test) {
|
2010-10-16 14:32:17 +00:00
|
|
|
ibuf = IMB_allocImBuf(image.xsize, image.ysize, 8 * image.zsize, 0);
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ibuf) {
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf->ftype = IMB_FTYPE_IMAGIC;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2020-08-08 11:02:11 +10:00
|
|
|
return ibuf;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (rle) {
|
2023-07-04 17:03:02 +02:00
|
|
|
size_t tablen = size_t(ysize) * size_t(zsize_file) * sizeof(int);
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, HEADER_SIZE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
uint *starttab = static_cast<uint *>(MEM_mallocN(tablen, "iris starttab"));
|
|
|
|
|
uint *lengthtab = static_cast<uint *>(MEM_mallocN(tablen, "iris endtab"));
|
2017-09-17 16:22:56 +10:00
|
|
|
|
|
|
|
|
#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
|
|
|
|
|
if (UNLIKELY((p) > mem_end)) { \
|
|
|
|
|
dirty_flag |= DIRTY_FLAG_EOF; \
|
|
|
|
|
goto fail_rle; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(MFILE_DATA(inf) + ((4 * 2) * tablen));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
readtab(inf, starttab, tablen);
|
|
|
|
|
readtab(inf, lengthtab, tablen);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* check data order */
|
|
|
|
|
cur = 0;
|
|
|
|
|
badorder = 0;
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_file; z++) {
|
2012-05-16 09:26:37 +00:00
|
|
|
if (starttab[y + z * ysize] < cur) {
|
2002-10-12 11:37:38 +00:00
|
|
|
badorder = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-16 09:26:37 +00:00
|
|
|
cur = starttab[y + z * ysize];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-23 11:01:30 +10:00
|
|
|
if (badorder) {
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
if (bpp == 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-04 17:03:02 +02:00
|
|
|
ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize_read, IB_rect);
|
2018-01-14 14:19:57 +01:00
|
|
|
if (!ibuf) {
|
|
|
|
|
goto fail_rle;
|
|
|
|
|
}
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ibuf->planes > 32) {
|
2011-11-21 20:47:19 +00:00
|
|
|
ibuf->planes = 32;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2023-05-18 10:19:01 +02:00
|
|
|
base = (uint *)ibuf->byte_buffer.data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
if (badorder) {
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_read; z++) {
|
2009-07-24 17:17:04 +00:00
|
|
|
lptr = base;
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, starttab[y + z * ysize]);
|
|
|
|
|
rledat = MFILE_DATA(inf);
|
|
|
|
|
MFILE_STEP(inf, lengthtab[y + z * ysize]);
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *rledat_next = MFILE_DATA(inf);
|
|
|
|
|
uint *lptr_next = lptr + xsize;
|
|
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next);
|
|
|
|
|
dirty_flag |= expandrow((uchar *)lptr, (uchar *)lptr_next, rledat, rledat_next, 3 - z);
|
|
|
|
|
lptr = lptr_next;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
lptr = base;
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
uint *lptr_next = lptr + xsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_read; z++) {
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, starttab[y + z * ysize]);
|
|
|
|
|
rledat = MFILE_DATA(inf);
|
|
|
|
|
MFILE_STEP(inf, lengthtab[y + z * ysize]);
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *rledat_next = MFILE_DATA(inf);
|
|
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next);
|
|
|
|
|
if (z < 4) {
|
|
|
|
|
dirty_flag |= expandrow(
|
|
|
|
|
(uchar *)lptr, (uchar *)lptr_next, rledat, rledat_next, 3 - z);
|
|
|
|
|
}
|
2023-07-04 17:03:02 +02:00
|
|
|
else {
|
|
|
|
|
break;
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
lptr = lptr_next;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-16 09:26:37 +00:00
|
|
|
else { /* bpp == 2 */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat);
|
2018-01-14 14:19:57 +01:00
|
|
|
if (!ibuf) {
|
|
|
|
|
goto fail_rle;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
fbase = ibuf->float_buffer.data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
if (badorder) {
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_read; z++) {
|
2009-07-24 17:17:04 +00:00
|
|
|
fptr = fbase;
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, starttab[y + z * ysize]);
|
|
|
|
|
rledat = MFILE_DATA(inf);
|
|
|
|
|
MFILE_STEP(inf, lengthtab[y + z * ysize]);
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *rledat_next = MFILE_DATA(inf);
|
|
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next);
|
|
|
|
|
float *fptr_next = fptr + (xsize * 4);
|
|
|
|
|
dirty_flag |= expandrow2(fptr, fptr_next, rledat, rledat_next, 3 - z);
|
|
|
|
|
fptr = fptr_next;
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else {
|
2009-07-24 17:17:04 +00:00
|
|
|
fptr = fbase;
|
2017-09-17 16:22:56 +10:00
|
|
|
float *fptr_next = fptr + (xsize * 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_read; z++) {
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, starttab[y + z * ysize]);
|
|
|
|
|
rledat = MFILE_DATA(inf);
|
|
|
|
|
MFILE_STEP(inf, lengthtab[y + z * ysize]);
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *rledat_next = MFILE_DATA(inf);
|
|
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next);
|
|
|
|
|
dirty_flag |= expandrow2(fptr, fptr_next, rledat, rledat_next, 3 - z);
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
fptr = fptr_next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
|
|
|
|
|
fail_rle:
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
MEM_freeN(starttab);
|
2012-10-21 05:46:41 +00:00
|
|
|
MEM_freeN(lengthtab);
|
2018-01-14 14:19:57 +01:00
|
|
|
|
|
|
|
|
if (!ibuf) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2018-01-14 14:19:57 +01:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2017-09-17 16:22:56 +10:00
|
|
|
|
|
|
|
|
#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
|
|
|
|
|
if (UNLIKELY((p) > mem_end)) { \
|
|
|
|
|
dirty_flag |= DIRTY_FLAG_EOF; \
|
|
|
|
|
goto fail_uncompressed; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
if (bpp == 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-04 17:03:02 +02:00
|
|
|
ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize_read, IB_rect);
|
2018-01-14 14:19:57 +01:00
|
|
|
if (!ibuf) {
|
|
|
|
|
goto fail_uncompressed;
|
|
|
|
|
}
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ibuf->planes > 32) {
|
2011-11-21 20:47:19 +00:00
|
|
|
ibuf->planes = 32;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
base = (uint *)ibuf->byte_buffer.data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, HEADER_SIZE);
|
|
|
|
|
rledat = MFILE_DATA(inf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_read; z++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (z < 4) {
|
2012-05-16 09:26:37 +00:00
|
|
|
lptr = base;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2023-07-04 17:03:02 +02:00
|
|
|
else {
|
|
|
|
|
break;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *rledat_next = rledat + xsize;
|
|
|
|
|
const int z_ofs = 3 - z;
|
|
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next + z_ofs);
|
|
|
|
|
interleaverow((uchar *)lptr, rledat, z_ofs, xsize);
|
|
|
|
|
rledat = rledat_next;
|
2009-07-24 17:17:04 +00:00
|
|
|
lptr += xsize;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-16 09:26:37 +00:00
|
|
|
else { /* bpp == 2 */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat);
|
2018-01-14 14:19:57 +01:00
|
|
|
if (!ibuf) {
|
|
|
|
|
goto fail_uncompressed;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
fbase = ibuf->float_buffer.data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
MFILE_SEEK(inf, HEADER_SIZE);
|
|
|
|
|
rledat = MFILE_DATA(inf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-04 17:03:02 +02:00
|
|
|
for (size_t z = 0; z < zsize_read; z++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
fptr = fbase;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < ysize; y++) {
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *rledat_next = rledat + xsize * 2;
|
|
|
|
|
const int z_ofs = 3 - z;
|
|
|
|
|
MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next + z_ofs);
|
|
|
|
|
interleaverow2(fptr, rledat, z_ofs, xsize);
|
|
|
|
|
rledat = rledat_next;
|
2009-07-24 17:17:04 +00:00
|
|
|
fptr += xsize * 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
|
|
|
|
|
fail_uncompressed:
|
2018-01-14 14:19:57 +01:00
|
|
|
if (!ibuf) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2018-01-14 14:19:57 +01:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
if (bpp == 1) {
|
2012-05-16 09:26:37 +00:00
|
|
|
uchar *rect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (image.zsize == 1) {
|
2023-05-18 10:19:01 +02:00
|
|
|
rect = ibuf->byte_buffer.data;
|
2023-05-02 20:09:09 +10:00
|
|
|
for (size_t x = size_t(ibuf->x) * size_t(ibuf->y); x > 0; x--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
rect[0] = 255;
|
|
|
|
|
rect[1] = rect[2] = rect[3];
|
|
|
|
|
rect += 4;
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else if (image.zsize == 2) {
|
2022-01-06 13:54:52 +11:00
|
|
|
/* Gray-scale with alpha. */
|
2023-05-18 10:19:01 +02:00
|
|
|
rect = ibuf->byte_buffer.data;
|
2023-05-02 20:09:09 +10:00
|
|
|
for (size_t x = size_t(ibuf->x) * size_t(ibuf->y); x > 0; x--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
rect[0] = rect[2];
|
|
|
|
|
rect[1] = rect[2] = rect[3];
|
|
|
|
|
rect += 4;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (image.zsize == 3) {
|
2009-07-24 17:17:04 +00:00
|
|
|
/* add alpha */
|
2023-05-18 10:19:01 +02:00
|
|
|
rect = ibuf->byte_buffer.data;
|
2023-05-02 20:09:09 +10:00
|
|
|
for (size_t x = size_t(ibuf->x) * size_t(ibuf->y); x > 0; x--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
rect[0] = 255;
|
|
|
|
|
rect += 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2012-05-16 09:26:37 +00:00
|
|
|
else { /* bpp == 2 */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (image.zsize == 1) {
|
2023-05-18 10:19:01 +02:00
|
|
|
fbase = ibuf->float_buffer.data;
|
2023-05-02 20:09:09 +10:00
|
|
|
for (size_t x = size_t(ibuf->x) * size_t(ibuf->y); x > 0; x--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
fbase[0] = 1;
|
2009-07-25 19:34:38 +00:00
|
|
|
fbase[1] = fbase[2] = fbase[3];
|
2009-07-24 17:17:04 +00:00
|
|
|
fbase += 4;
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else if (image.zsize == 2) {
|
2022-01-06 13:54:52 +11:00
|
|
|
/* Gray-scale with alpha. */
|
2023-05-18 10:19:01 +02:00
|
|
|
fbase = ibuf->float_buffer.data;
|
2023-05-02 20:09:09 +10:00
|
|
|
for (size_t x = size_t(ibuf->x) * size_t(ibuf->y); x > 0; x--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
fbase[0] = fbase[2];
|
|
|
|
|
fbase[1] = fbase[2] = fbase[3];
|
|
|
|
|
fbase += 4;
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else if (image.zsize == 3) {
|
2009-07-24 17:17:04 +00:00
|
|
|
/* add alpha */
|
2023-05-18 10:19:01 +02:00
|
|
|
fbase = ibuf->float_buffer.data;
|
2023-05-02 20:09:09 +10:00
|
|
|
for (size_t x = size_t(ibuf->x) * size_t(ibuf->y); x > 0; x--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
fbase[0] = 1;
|
|
|
|
|
fbase += 4;
|
2005-01-03 19:53:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
if (flags & IB_rect) {
|
|
|
|
|
IMB_rect_from_float(ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
if (dirty_flag) {
|
|
|
|
|
fprintf(stderr, "longimagedata: corrupt file content (%d)\n", dirty_flag);
|
|
|
|
|
}
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf->ftype = IMB_FTYPE_IMAGIC;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->byte_buffer.data) {
|
2012-09-14 06:17:14 +00:00
|
|
|
IMB_convert_rgba_to_abgr(ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-08 11:02:11 +10:00
|
|
|
return ibuf;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static utility functions for longimagedata */
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
lptr += z;
|
2012-03-24 07:52:14 +00:00
|
|
|
while (n--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*lptr = *cptr++;
|
|
|
|
|
lptr += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:14:59 +10:00
|
|
|
static void interleaverow2(float *lptr, const uchar *cptr, int z, int n)
|
2009-07-24 17:17:04 +00:00
|
|
|
{
|
|
|
|
|
lptr += z;
|
2012-03-24 07:52:14 +00:00
|
|
|
while (n--) {
|
2023-05-02 20:09:09 +10:00
|
|
|
*lptr = ((cptr[0] << 8) | (cptr[1] << 0)) / float(0xFFFF);
|
2009-07-24 17:17:04 +00:00
|
|
|
cptr += 2;
|
|
|
|
|
lptr += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
static int expandrow2(
|
|
|
|
|
float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
|
2009-07-24 17:17:04 +00:00
|
|
|
{
|
2017-09-17 16:14:59 +10:00
|
|
|
ushort pixel, count;
|
2009-07-24 17:17:04 +00:00
|
|
|
float pixel_f;
|
|
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \
|
2019-04-02 17:54:04 +11:00
|
|
|
if (UNLIKELY(iptr_next > iptr_end)) { \
|
|
|
|
|
goto fail; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
2017-09-17 16:22:56 +10:00
|
|
|
|
|
|
|
|
#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \
|
2019-04-02 17:54:04 +11:00
|
|
|
if (UNLIKELY(optr_next > optr_end)) { \
|
|
|
|
|
goto fail; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-24 17:17:04 +00:00
|
|
|
optr += z;
|
2017-09-17 16:22:56 +10:00
|
|
|
optr_end += z;
|
2023-07-22 11:36:59 +10:00
|
|
|
while (true) {
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *iptr_next = iptr + 2;
|
|
|
|
|
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
|
2012-05-16 09:26:37 +00:00
|
|
|
pixel = (iptr[0] << 8) | (iptr[1] << 0);
|
2017-09-17 16:22:56 +10:00
|
|
|
iptr = iptr_next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (!(count = (pixel & 0x7f))) {
|
2017-09-17 16:22:56 +10:00
|
|
|
return false;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
const float *optr_next = optr + count;
|
|
|
|
|
EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pixel & 0x80) {
|
2017-09-17 16:22:56 +10:00
|
|
|
iptr_next = iptr + (count * 2);
|
|
|
|
|
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
|
2012-05-16 09:26:37 +00:00
|
|
|
while (count >= 8) {
|
2023-05-02 20:09:09 +10:00
|
|
|
optr[0 * 4] = ((iptr[0] << 8) | (iptr[1] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[1 * 4] = ((iptr[2] << 8) | (iptr[3] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[2 * 4] = ((iptr[4] << 8) | (iptr[5] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[3 * 4] = ((iptr[6] << 8) | (iptr[7] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[4 * 4] = ((iptr[8] << 8) | (iptr[9] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[5 * 4] = ((iptr[10] << 8) | (iptr[11] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[6 * 4] = ((iptr[12] << 8) | (iptr[13] << 0)) / float(0xFFFF);
|
|
|
|
|
optr[7 * 4] = ((iptr[14] << 8) | (iptr[15] << 0)) / float(0xFFFF);
|
2012-05-16 09:26:37 +00:00
|
|
|
optr += 8 * 4;
|
|
|
|
|
iptr += 8 * 2;
|
2009-07-24 17:17:04 +00:00
|
|
|
count -= 8;
|
|
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
while (count--) {
|
2023-05-02 20:09:09 +10:00
|
|
|
*optr = ((iptr[0] << 8) | (iptr[1] << 0)) / float(0xFFFF);
|
2012-05-16 09:26:37 +00:00
|
|
|
iptr += 2;
|
|
|
|
|
optr += 4;
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
BLI_assert(iptr == iptr_next);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2017-09-17 16:22:56 +10:00
|
|
|
iptr_next = iptr + 2;
|
|
|
|
|
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
|
2023-05-02 20:09:09 +10:00
|
|
|
pixel_f = ((iptr[0] << 8) | (iptr[1] << 0)) / float(0xFFFF);
|
2017-09-17 16:22:56 +10:00
|
|
|
iptr = iptr_next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
while (count >= 8) {
|
|
|
|
|
optr[0 * 4] = pixel_f;
|
|
|
|
|
optr[1 * 4] = pixel_f;
|
|
|
|
|
optr[2 * 4] = pixel_f;
|
|
|
|
|
optr[3 * 4] = pixel_f;
|
|
|
|
|
optr[4 * 4] = pixel_f;
|
|
|
|
|
optr[5 * 4] = pixel_f;
|
|
|
|
|
optr[6 * 4] = pixel_f;
|
|
|
|
|
optr[7 * 4] = pixel_f;
|
|
|
|
|
optr += 8 * 4;
|
2009-07-24 17:17:04 +00:00
|
|
|
count -= 8;
|
|
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
while (count--) {
|
2009-07-24 17:17:04 +00:00
|
|
|
*optr = pixel_f;
|
2012-05-16 09:26:37 +00:00
|
|
|
optr += 4;
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
BLI_assert(iptr == iptr_next);
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
BLI_assert(optr == optr_next);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
#undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL
|
|
|
|
|
#undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL
|
|
|
|
|
fail:
|
|
|
|
|
return DIRTY_FLAG_ENCODING;
|
2009-07-24 17:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
static int expandrow(
|
|
|
|
|
uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2017-09-17 16:14:59 +10:00
|
|
|
uchar pixel, count;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \
|
2019-04-02 17:54:04 +11:00
|
|
|
if (UNLIKELY(iptr_next > iptr_end)) { \
|
|
|
|
|
goto fail; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
2017-09-17 16:22:56 +10:00
|
|
|
|
|
|
|
|
#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \
|
2019-04-02 17:54:04 +11:00
|
|
|
if (UNLIKELY(optr_next > optr_end)) { \
|
|
|
|
|
goto fail; \
|
|
|
|
|
} \
|
|
|
|
|
((void)0)
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
optr += z;
|
2017-09-17 16:22:56 +10:00
|
|
|
optr_end += z;
|
2023-07-22 11:36:59 +10:00
|
|
|
while (true) {
|
2017-09-17 16:22:56 +10:00
|
|
|
const uchar *iptr_next = iptr + 1;
|
|
|
|
|
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
|
|
|
|
|
pixel = *iptr;
|
|
|
|
|
iptr = iptr_next;
|
2019-04-23 11:01:30 +10:00
|
|
|
if (!(count = (pixel & 0x7f))) {
|
2017-09-17 16:22:56 +10:00
|
|
|
return false;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2023-05-02 20:09:09 +10:00
|
|
|
const uchar *optr_next = optr + (int(count) * 4);
|
2017-09-17 16:22:56 +10:00
|
|
|
EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pixel & 0x80) {
|
2017-09-17 16:22:56 +10:00
|
|
|
iptr_next = iptr + count;
|
|
|
|
|
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
|
2012-05-16 09:26:37 +00:00
|
|
|
while (count >= 8) {
|
|
|
|
|
optr[0 * 4] = iptr[0];
|
|
|
|
|
optr[1 * 4] = iptr[1];
|
|
|
|
|
optr[2 * 4] = iptr[2];
|
|
|
|
|
optr[3 * 4] = iptr[3];
|
|
|
|
|
optr[4 * 4] = iptr[4];
|
|
|
|
|
optr[5 * 4] = iptr[5];
|
|
|
|
|
optr[6 * 4] = iptr[6];
|
|
|
|
|
optr[7 * 4] = iptr[7];
|
|
|
|
|
optr += 8 * 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
iptr += 8;
|
|
|
|
|
count -= 8;
|
|
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
while (count--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*optr = *iptr++;
|
2012-05-16 09:26:37 +00:00
|
|
|
optr += 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
BLI_assert(iptr == iptr_next);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2017-09-17 16:22:56 +10:00
|
|
|
iptr_next = iptr + 1;
|
|
|
|
|
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
|
2002-10-12 11:37:38 +00:00
|
|
|
pixel = *iptr++;
|
2012-05-16 09:26:37 +00:00
|
|
|
while (count >= 8) {
|
|
|
|
|
optr[0 * 4] = pixel;
|
|
|
|
|
optr[1 * 4] = pixel;
|
|
|
|
|
optr[2 * 4] = pixel;
|
|
|
|
|
optr[3 * 4] = pixel;
|
|
|
|
|
optr[4 * 4] = pixel;
|
|
|
|
|
optr[5 * 4] = pixel;
|
|
|
|
|
optr[6 * 4] = pixel;
|
|
|
|
|
optr[7 * 4] = pixel;
|
|
|
|
|
optr += 8 * 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
count -= 8;
|
|
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
while (count--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*optr = pixel;
|
2012-05-16 09:26:37 +00:00
|
|
|
optr += 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
BLI_assert(iptr == iptr_next);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2017-09-17 16:22:56 +10:00
|
|
|
BLI_assert(optr == optr_next);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-17 16:22:56 +10:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
#undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL
|
|
|
|
|
#undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL
|
|
|
|
|
fail:
|
|
|
|
|
return DIRTY_FLAG_ENCODING;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-02 18:51:31 +10:00
|
|
|
/**
|
2022-05-17 10:24:26 +10:00
|
|
|
* \param filepath: The file path to write to.
|
|
|
|
|
* \param lptr: an array of integers to an iris image file (each int represents one pixel).
|
2023-05-02 11:32:27 +02:00
|
|
|
* \param zptr: depth-buffer (optional, may be nullptr).
|
2022-05-17 10:24:26 +10:00
|
|
|
* \param xsize: with width of the pixel-array.
|
|
|
|
|
* \param ysize: height of the pixel-array.
|
|
|
|
|
* \param zsize: specifies what kind of image file to write out.
|
|
|
|
|
* - 1: the luminance of the pixels are calculated,
|
|
|
|
|
* and a single channel black and white image is saved.
|
|
|
|
|
* - 3: an RGB image file is saved.
|
|
|
|
|
* - 4: an RGBA image file is saved.
|
|
|
|
|
* - 8: an RGBA image and a Z-buffer (non-null `zptr`).
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2022-05-17 10:24:26 +10:00
|
|
|
static bool output_iris(const char *filepath,
|
|
|
|
|
const uint *lptr,
|
|
|
|
|
const int *zptr,
|
|
|
|
|
const int xsize,
|
|
|
|
|
const int ysize,
|
|
|
|
|
const int zsize)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
FILE *outf;
|
|
|
|
|
IMAGE *image;
|
Fixed two uninitalized vars:
Kent
/cvs01/blender/source/blender/imbuf/intern/iris.c,v
retrieving revision 1.3
diff -u -r1.3 iris.c
--- iris.c 2002/11/25 12:02:00 1.3
+++ iris.c 2002/12/19 22:12:53
@@ -212,7 +212,7 @@
/* unsigned int *tab; */
/* int len; */
{
- int r;
+ int r = 0;
while(len) {
r = putlong(outf,*tab++);
@@ -548,7 +548,7 @@
{
FILE *outf;
IMAGE *image;
- int tablen, y, z, pos, len;
+ int tablen, y, z, pos, len = 0;
int *starttab, *lengthtab;
unsigned char *rlebuf;
2002-12-19 22:13:37 +00:00
|
|
|
int tablen, y, z, pos, len = 0;
|
2017-09-17 16:14:59 +10:00
|
|
|
uint *starttab, *lengthtab;
|
|
|
|
|
uchar *rlebuf;
|
|
|
|
|
uint *lumbuf;
|
2002-10-12 11:37:38 +00:00
|
|
|
int rlebuflen, goodwrite;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
goodwrite = 1;
|
2022-05-17 10:24:26 +10:00
|
|
|
outf = BLI_fopen(filepath, "wb");
|
2019-04-23 11:01:30 +10:00
|
|
|
if (!outf) {
|
2023-07-22 11:36:59 +10:00
|
|
|
return false;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
tablen = ysize * zsize * sizeof(int);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image");
|
2017-09-17 16:14:59 +10:00
|
|
|
starttab = (uint *)MEM_mallocN(tablen, "iris starttab");
|
|
|
|
|
lengthtab = (uint *)MEM_mallocN(tablen, "iris lengthtab");
|
2012-05-16 09:26:37 +00:00
|
|
|
rlebuflen = 1.05 * xsize + 10;
|
2017-09-17 16:14:59 +10:00
|
|
|
rlebuf = (uchar *)MEM_mallocN(rlebuflen, "iris rlebuf");
|
|
|
|
|
lumbuf = (uint *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
memset(image, 0, sizeof(IMAGE));
|
2017-09-16 16:07:27 +10:00
|
|
|
image->imagic = IMAGIC;
|
2002-10-12 11:37:38 +00:00
|
|
|
image->type = RLE(1);
|
2019-04-23 11:01:30 +10:00
|
|
|
if (zsize > 1) {
|
2002-10-12 11:37:38 +00:00
|
|
|
image->dim = 3;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
image->dim = 2;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
image->xsize = xsize;
|
|
|
|
|
image->ysize = ysize;
|
|
|
|
|
image->zsize = zsize;
|
|
|
|
|
image->min = 0;
|
|
|
|
|
image->max = 255;
|
2012-04-29 15:47:02 +00:00
|
|
|
goodwrite *= writeheader(outf, image);
|
2015-07-12 01:06:32 +10:00
|
|
|
fseek(outf, HEADER_SIZE + (2 * tablen), SEEK_SET);
|
|
|
|
|
pos = HEADER_SIZE + (2 * tablen);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
for (y = 0; y < ysize; y++) {
|
|
|
|
|
for (z = 0; z < zsize; z++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (zsize == 1) {
|
2022-05-17 10:24:26 +10:00
|
|
|
lumrow((const uchar *)lptr, (uchar *)lumbuf, xsize);
|
|
|
|
|
len = compressrow((const uchar *)lumbuf, rlebuf, CHANOFFSET(z), xsize);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-16 09:26:37 +00:00
|
|
|
if (z < 4) {
|
2022-05-17 10:24:26 +10:00
|
|
|
len = compressrow((const uchar *)lptr, rlebuf, CHANOFFSET(z), xsize);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-16 09:26:37 +00:00
|
|
|
else if (z < 8 && zptr) {
|
2022-05-17 10:24:26 +10:00
|
|
|
len = compressrow((const uchar *)zptr, rlebuf, CHANOFFSET(z - 4), xsize);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 10:50:21 +10:00
|
|
|
|
|
|
|
|
BLI_assert_msg(len <= rlebuflen, "The length calculated for 'rlebuflen' was too small!");
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
goodwrite *= fwrite(rlebuf, len, 1, outf);
|
2012-05-16 09:26:37 +00:00
|
|
|
starttab[y + z * ysize] = pos;
|
|
|
|
|
lengthtab[y + z * ysize] = len;
|
2002-10-12 11:37:38 +00:00
|
|
|
pos += len;
|
|
|
|
|
}
|
|
|
|
|
lptr += xsize;
|
2019-04-23 11:01:30 +10:00
|
|
|
if (zptr) {
|
2012-03-24 06:38:07 +00:00
|
|
|
zptr += xsize;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-12 01:06:32 +10:00
|
|
|
fseek(outf, HEADER_SIZE, SEEK_SET);
|
2012-04-29 15:47:02 +00:00
|
|
|
goodwrite *= writetab(outf, starttab, tablen);
|
|
|
|
|
goodwrite *= writetab(outf, lengthtab, tablen);
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
MEM_freeN(image);
|
|
|
|
|
MEM_freeN(starttab);
|
|
|
|
|
MEM_freeN(lengthtab);
|
|
|
|
|
MEM_freeN(rlebuf);
|
|
|
|
|
MEM_freeN(lumbuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
fclose(outf);
|
2019-04-23 11:01:30 +10:00
|
|
|
if (goodwrite) {
|
2023-07-22 11:36:59 +10:00
|
|
|
return true;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2020-08-07 12:39:50 +02:00
|
|
|
|
|
|
|
|
fprintf(stderr, "output_iris: not enough space for image!!\n");
|
2023-07-22 11:36:59 +10:00
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static utility functions for output_iris */
|
|
|
|
|
|
2020-07-13 11:27:09 +02:00
|
|
|
static void lumrow(const uchar *rgbptr, uchar *lumptr, int n)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
lumptr += CHANOFFSET(0);
|
2012-03-24 07:52:14 +00:00
|
|
|
while (n--) {
|
2012-04-29 15:47:02 +00:00
|
|
|
*lumptr = ILUM(rgbptr[OFFSET_R], rgbptr[OFFSET_G], rgbptr[OFFSET_B]);
|
2002-10-12 11:37:38 +00:00
|
|
|
lumptr += 4;
|
|
|
|
|
rgbptr += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 10:24:26 +10:00
|
|
|
static int compressrow(const uchar *lbuf, uchar *rlebuf, const int z, const int row_len)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2022-05-17 10:24:26 +10:00
|
|
|
const uchar *iptr, *ibufend, *sptr;
|
|
|
|
|
uchar *optr;
|
2002-10-12 11:37:38 +00:00
|
|
|
short todo, cc;
|
|
|
|
|
int count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
lbuf += z;
|
|
|
|
|
iptr = lbuf;
|
2022-03-16 11:58:22 +11:00
|
|
|
ibufend = iptr + row_len * 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
optr = rlebuf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 09:26:37 +00:00
|
|
|
while (iptr < ibufend) {
|
2002-10-12 11:37:38 +00:00
|
|
|
sptr = iptr;
|
|
|
|
|
iptr += 8;
|
2019-04-23 11:01:30 +10:00
|
|
|
while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0]))) {
|
2012-05-16 09:26:37 +00:00
|
|
|
iptr += 4;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
iptr -= 8;
|
2012-05-16 09:26:37 +00:00
|
|
|
count = (iptr - sptr) / 4;
|
2012-03-24 07:52:14 +00:00
|
|
|
while (count) {
|
2012-05-16 09:26:37 +00:00
|
|
|
todo = count > 126 ? 126 : count;
|
2002-10-12 11:37:38 +00:00
|
|
|
count -= todo;
|
2012-05-16 09:26:37 +00:00
|
|
|
*optr++ = 0x80 | todo;
|
|
|
|
|
while (todo > 8) {
|
|
|
|
|
optr[0] = sptr[0 * 4];
|
|
|
|
|
optr[1] = sptr[1 * 4];
|
|
|
|
|
optr[2] = sptr[2 * 4];
|
|
|
|
|
optr[3] = sptr[3 * 4];
|
|
|
|
|
optr[4] = sptr[4 * 4];
|
|
|
|
|
optr[5] = sptr[5 * 4];
|
|
|
|
|
optr[6] = sptr[6 * 4];
|
|
|
|
|
optr[7] = sptr[7 * 4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
optr += 8;
|
2012-05-16 09:26:37 +00:00
|
|
|
sptr += 8 * 4;
|
2002-10-12 11:37:38 +00:00
|
|
|
todo -= 8;
|
|
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
while (todo--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*optr++ = *sptr;
|
|
|
|
|
sptr += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sptr = iptr;
|
|
|
|
|
cc = *iptr;
|
|
|
|
|
iptr += 4;
|
2019-04-23 11:01:30 +10:00
|
|
|
while ((iptr < ibufend) && (*iptr == cc)) {
|
2002-10-12 11:37:38 +00:00
|
|
|
iptr += 4;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2012-05-16 09:26:37 +00:00
|
|
|
count = (iptr - sptr) / 4;
|
2012-03-24 07:52:14 +00:00
|
|
|
while (count) {
|
2012-05-16 09:26:37 +00:00
|
|
|
todo = count > 126 ? 126 : count;
|
2002-10-12 11:37:38 +00:00
|
|
|
count -= todo;
|
|
|
|
|
*optr++ = todo;
|
|
|
|
|
*optr++ = cc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*optr++ = 0;
|
2017-09-17 16:14:59 +10:00
|
|
|
return optr - (uchar *)rlebuf;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-05 13:02:16 +10:00
|
|
|
bool imb_saveiris(ImBuf *ibuf, const char *filepath, int /*flags*/)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-07-04 17:03:02 +02:00
|
|
|
const short zsize = (ibuf->planes + 7) >> 3;
|
2018-06-17 17:04:54 +02:00
|
|
|
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
IMB_convert_rgba_to_abgr(ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
const bool ok = output_iris(
|
2023-07-04 17:03:02 +02:00
|
|
|
filepath, (uint *)ibuf->byte_buffer.data, nullptr, ibuf->x, ibuf->y, zsize);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
/* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
IMB_convert_rgba_to_abgr(ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-11-11 16:14:05 +11:00
|
|
|
return ok;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|