2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-27 20:23:21 +00:00
|
|
|
/** \file blender/imbuf/intern/targa.c
|
|
|
|
* \ingroup imbuf
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef WIN32
|
2012-08-12 23:28:33 +00:00
|
|
|
# include <io.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
#endif
|
2012-08-12 23:28:33 +00:00
|
|
|
|
2013-03-05 03:17:46 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2012-08-12 23:28:33 +00:00
|
|
|
#include "BLI_fileops.h"
|
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "imbuf.h"
|
|
|
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "IMB_imbuf.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"
|
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"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* this one is only def-ed once, strangely... related to GS? */
|
|
|
|
#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
typedef struct TARGA {
|
2012-10-21 05:46:41 +00:00
|
|
|
unsigned char numid;
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned char maptyp;
|
2012-10-21 05:46:41 +00:00
|
|
|
unsigned char imgtyp;
|
2002-10-12 11:37:38 +00:00
|
|
|
short maporig;
|
|
|
|
short mapsize;
|
|
|
|
unsigned char mapbits;
|
|
|
|
short xorig;
|
|
|
|
short yorig;
|
|
|
|
short xsize;
|
|
|
|
short ysize;
|
|
|
|
unsigned char pixsize;
|
|
|
|
unsigned char imgdes;
|
|
|
|
} TARGA;
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
static int tga_out1(unsigned int data, FILE *file)
|
|
|
|
{
|
|
|
|
uchar *p;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
p = (uchar *) &data;
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(p[0], file) == EOF) return EOF;
|
|
|
|
return ~EOF;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static int tga_out2(unsigned int data, FILE *file)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
uchar *p;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
p = (uchar *) &data;
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(p[0], file) == EOF) return EOF;
|
|
|
|
if (putc(p[1], file) == EOF) return EOF;
|
|
|
|
return ~EOF;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static int tga_out3(unsigned int data, FILE *file)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
uchar *p;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
p = (uchar *) &data;
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(p[2], file) == EOF) return EOF;
|
|
|
|
if (putc(p[1], file) == EOF) return EOF;
|
|
|
|
if (putc(p[0], file) == EOF) return EOF;
|
|
|
|
return ~EOF;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static int tga_out4(unsigned int data, FILE *file)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
uchar *p;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
p = (uchar *) &data;
|
2003-04-27 09:59:36 +00:00
|
|
|
/* order = bgra */
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(p[2], file) == EOF) return EOF;
|
|
|
|
if (putc(p[1], file) == EOF) return EOF;
|
|
|
|
if (putc(p[0], file) == EOF) return EOF;
|
|
|
|
if (putc(p[3], file) == EOF) return EOF;
|
|
|
|
return ~EOF;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 11:25:41 +10:00
|
|
|
static bool makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE *))
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-04-29 15:47:02 +00:00
|
|
|
register int last, this;
|
2002-10-12 11:37:38 +00:00
|
|
|
register int copy, bytes;
|
|
|
|
register unsigned int *rect, *rectstart, *temp;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
for (y = 0; y < ibuf->y; y++) {
|
|
|
|
bytes = ibuf->x - 1;
|
|
|
|
rectstart = rect = ibuf->rect + (y * ibuf->x);
|
|
|
|
last = *rect++;
|
|
|
|
this = *rect++;
|
2012-05-16 07:38:23 +00:00
|
|
|
copy = last ^ this;
|
2012-03-24 06:38:07 +00:00
|
|
|
while (bytes > 0) {
|
|
|
|
if (copy) {
|
2012-03-12 23:56:11 +00:00
|
|
|
do {
|
2002-10-12 11:37:38 +00:00
|
|
|
last = this;
|
|
|
|
this = *rect++;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (last == this) {
|
2012-05-16 07:38:23 +00:00
|
|
|
if (this == rect[-3]) { /* three the same? */
|
|
|
|
bytes--; /* set bytes */
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 23:56:11 +00:00
|
|
|
} while (--bytes != 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
copy = rect - rectstart;
|
|
|
|
copy--;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (bytes) copy -= 2;
|
|
|
|
|
|
|
|
temp = rect;
|
|
|
|
rect = rectstart;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
while (copy) {
|
2002-10-12 11:37:38 +00:00
|
|
|
last = copy;
|
2012-05-16 07:38:23 +00:00
|
|
|
if (copy >= 128) last = 128;
|
2002-10-12 11:37:38 +00:00
|
|
|
copy -= last;
|
2013-03-09 03:46:30 +00:00
|
|
|
if (fputc(last - 1, file) == EOF) return 0;
|
2012-03-12 23:56:11 +00:00
|
|
|
do {
|
2013-03-09 03:46:30 +00:00
|
|
|
if (out(*rect++, file) == EOF) return 0;
|
2012-03-24 07:52:14 +00:00
|
|
|
} while (--last != 0);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
rectstart = rect;
|
|
|
|
rect = temp;
|
|
|
|
last = this;
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
copy = 0;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-16 07:38:23 +00:00
|
|
|
while (*rect++ == this) { /* seek for first different byte */
|
|
|
|
if (--bytes == 0) break; /* oor end of line */
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-16 07:38:23 +00:00
|
|
|
rect--;
|
|
|
|
copy = rect - rectstart;
|
2002-10-12 11:37:38 +00:00
|
|
|
rectstart = rect;
|
2012-05-16 07:38:23 +00:00
|
|
|
bytes--;
|
2002-10-12 11:37:38 +00:00
|
|
|
this = *rect++;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
while (copy) {
|
2012-05-16 07:38:23 +00:00
|
|
|
if (copy > 128) {
|
2013-03-09 03:46:30 +00:00
|
|
|
if (fputc(255, file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
copy -= 128;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (copy == 1) {
|
2013-03-09 03:46:30 +00:00
|
|
|
if (fputc(0, file) == EOF) return 0;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else if (fputc(127 + copy, file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
copy = 0;
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
if (out(last, file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2014-04-01 11:34:00 +11:00
|
|
|
copy = 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 11:25:41 +10:00
|
|
|
static bool dumptarga(struct ImBuf *ibuf, FILE *file)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
uchar *rect;
|
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
if (ibuf == NULL) return 0;
|
|
|
|
if (ibuf->rect == NULL) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
size = ibuf->x * ibuf->y;
|
|
|
|
rect = (uchar *) ibuf->rect;
|
|
|
|
|
2011-11-21 20:47:19 +00:00
|
|
|
if (ibuf->planes <= 8) {
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size > 0) {
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(*rect, file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
size--;
|
|
|
|
rect += 4;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (ibuf->planes <= 16) {
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size > 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
putc(rect[0], file);
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(rect[1], file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
size--;
|
|
|
|
rect += 4;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (ibuf->planes <= 24) {
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size > 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
putc(rect[2], file);
|
|
|
|
putc(rect[1], file);
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(rect[0], file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
size--;
|
|
|
|
rect += 4;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (ibuf->planes <= 32) {
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size > 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
putc(rect[2], file);
|
|
|
|
putc(rect[1], file);
|
|
|
|
putc(rect[0], file);
|
2013-03-09 03:46:30 +00:00
|
|
|
if (putc(rect[3], file) == EOF) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
size--;
|
|
|
|
rect += 4;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
int imb_savetarga(struct ImBuf *ibuf, const char *name, int flags)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-16 07:38:23 +00:00
|
|
|
char buf[20] = {0};
|
2002-10-12 11:37:38 +00:00
|
|
|
FILE *fildes;
|
2014-04-11 11:25:41 +10:00
|
|
|
bool ok = false;
|
2010-10-17 06:38:56 +00:00
|
|
|
|
|
|
|
(void)flags; /* unused */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
buf[16] = (ibuf->planes + 0x7) & ~0x7;
|
|
|
|
if (ibuf->planes > 8) {
|
2002-10-12 11:37:38 +00:00
|
|
|
buf[2] = 10;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
buf[2] = 11;
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:58:17 +02:00
|
|
|
if (ibuf->foptions.flag & RAWTGA) buf[2] &= ~8;
|
2002-10-12 11:37:38 +00: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
|
|
|
buf[8] = 0;
|
|
|
|
buf[9] = 0;
|
|
|
|
buf[10] = 0;
|
|
|
|
buf[11] = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
buf[12] = ibuf->x & 0xff;
|
|
|
|
buf[13] = ibuf->x >> 8;
|
|
|
|
buf[14] = ibuf->y & 0xff;
|
|
|
|
buf[15] = ibuf->y >> 8;
|
|
|
|
|
2005-01-03 19:53:04 +00:00
|
|
|
/* Don't forget to indicate that your 32 bit
|
|
|
|
* targa uses 8 bits for the alpha channel! */
|
2012-05-16 07:38:23 +00:00
|
|
|
if (ibuf->planes == 32) {
|
2005-01-03 19:53:04 +00:00
|
|
|
buf[17] |= 0x08;
|
|
|
|
}
|
2012-04-29 15:47:02 +00:00
|
|
|
fildes = BLI_fopen(name, "wb");
|
2012-05-16 07:38:23 +00:00
|
|
|
if (!fildes) return 0;
|
2004-12-09 13:09:11 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
if (fwrite(buf, 1, 18, fildes) != 18) {
|
2009-08-01 06:27:40 +00:00
|
|
|
fclose(fildes);
|
2013-03-09 03:46:30 +00:00
|
|
|
return 0;
|
2009-08-01 06:27:40 +00:00
|
|
|
}
|
2002-12-21 09:52:03 +00:00
|
|
|
|
2015-07-13 13:58:17 +02:00
|
|
|
if (ibuf->foptions.flag & RAWTGA) {
|
2002-10-12 11:37:38 +00:00
|
|
|
ok = dumptarga(ibuf, fildes);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-04-28 06:31:57 +00:00
|
|
|
switch ((ibuf->planes + 7) >> 3) {
|
2012-05-16 07:38:23 +00:00
|
|
|
case 1:
|
|
|
|
ok = makebody_tga(ibuf, fildes, tga_out1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ok = makebody_tga(ibuf, fildes, tga_out2);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ok = makebody_tga(ibuf, fildes, tga_out3);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ok = makebody_tga(ibuf, fildes, tga_out4);
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fildes);
|
2013-03-09 03:46:30 +00:00
|
|
|
return ok;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
static int checktarga(TARGA *tga, const unsigned char *mem)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
tga->numid = mem[0];
|
|
|
|
tga->maptyp = mem[1];
|
|
|
|
tga->imgtyp = mem[2];
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
tga->maporig = GSS(mem + 3);
|
|
|
|
tga->mapsize = GSS(mem + 5);
|
2002-10-12 11:37:38 +00:00
|
|
|
tga->mapbits = mem[7];
|
2012-05-16 07:38:23 +00:00
|
|
|
tga->xorig = GSS(mem + 8);
|
|
|
|
tga->yorig = GSS(mem + 10);
|
|
|
|
tga->xsize = GSS(mem + 12);
|
|
|
|
tga->ysize = GSS(mem + 14);
|
2002-10-12 11:37:38 +00:00
|
|
|
tga->pixsize = mem[16];
|
|
|
|
tga->imgdes = mem[17];
|
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
if (tga->maptyp > 1) return 0;
|
2012-03-24 06:38:07 +00:00
|
|
|
switch (tga->imgtyp) {
|
2012-05-16 07:38:23 +00:00
|
|
|
case 1: /* raw cmap */
|
|
|
|
case 2: /* raw rgb */
|
|
|
|
case 3: /* raw b&w */
|
|
|
|
case 9: /* cmap */
|
|
|
|
case 10: /* rgb */
|
|
|
|
case 11: /* b&w */
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-09 03:46:30 +00:00
|
|
|
return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
if (tga->mapsize && tga->mapbits > 32) return 0;
|
2013-03-24 20:59:53 +00:00
|
|
|
if (tga->xsize <= 0) return 0;
|
|
|
|
if (tga->ysize <= 0) return 0;
|
2013-03-09 03:46:30 +00:00
|
|
|
if (tga->pixsize > 32) return 0;
|
|
|
|
if (tga->pixsize == 0) return 0;
|
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
int imb_is_a_targa(const unsigned char *buf)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
TARGA tga;
|
|
|
|
|
|
|
|
return checktarga(&tga, buf);
|
|
|
|
}
|
|
|
|
|
2009-07-27 22:41:35 +00:00
|
|
|
static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-07-27 22:41:35 +00:00
|
|
|
int size = (ibuf->x * ibuf->y) - (rect - ibuf->rect);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (size) {
|
2012-05-16 07:38:23 +00:00
|
|
|
printf("decodetarga: incomplete file, %.1f%% missing\n", 100 * ((float)size / (ibuf->x * ibuf->y)));
|
2009-07-27 22:41:35 +00:00
|
|
|
|
|
|
|
/* not essential but makes displaying partially rendered TGA's less ugly */
|
|
|
|
memset(rect, 0, size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* shouldnt happen */
|
|
|
|
printf("decodetarga: incomplete file, all pixels written\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
|
2009-07-27 22:41:35 +00:00
|
|
|
{
|
2015-07-11 23:52:18 +10:00
|
|
|
const unsigned char *mem_end = mem + mem_size;
|
2002-10-12 11:37:38 +00:00
|
|
|
int count, col, size;
|
|
|
|
unsigned int *rect;
|
2012-05-16 07:38:23 +00:00
|
|
|
uchar *cp = (uchar *) &col;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-03-05 10:29:10 +00:00
|
|
|
if (ibuf == NULL) return;
|
|
|
|
if (ibuf->rect == NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
size = ibuf->x * ibuf->y;
|
|
|
|
rect = ibuf->rect;
|
|
|
|
|
2003-04-27 09:59:36 +00:00
|
|
|
/* set alpha */
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[0] = 0xff;
|
|
|
|
cp[1] = cp[2] = 0;
|
2009-07-27 22:41:35 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size > 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
count = *mem++;
|
2009-07-27 22:41:35 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
if (mem > mem_end)
|
2009-07-27 22:41:35 +00:00
|
|
|
goto partial_load;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (count >= 128) {
|
|
|
|
/*if (count == 128) printf("TARGA: 128 in file !\n");*/
|
|
|
|
count -= 127;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (psize & 2) {
|
|
|
|
if (psize & 1) {
|
2003-04-27 09:59:36 +00:00
|
|
|
/* order = bgra */
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[0] = mem[3];
|
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
/*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
|
|
|
|
mem += 4;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
/*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
|
|
|
|
mem += 3;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (psize & 1) {
|
2006-11-07 17:32:29 +00:00
|
|
|
cp[0] = mem[0];
|
|
|
|
cp[1] = mem[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
mem += 2;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
col = *mem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size -= count;
|
|
|
|
if (size >= 0) {
|
|
|
|
while (count > 0) {
|
|
|
|
*rect++ = col;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-16 07:38:23 +00:00
|
|
|
count++;
|
2002-10-12 11:37:38 +00:00
|
|
|
size -= count;
|
|
|
|
if (size >= 0) {
|
2012-03-24 06:38:07 +00:00
|
|
|
while (count > 0) {
|
|
|
|
if (psize & 2) {
|
|
|
|
if (psize & 1) {
|
2003-04-27 09:59:36 +00:00
|
|
|
/* order = bgra */
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[0] = mem[3];
|
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
/*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
|
|
|
|
mem += 4;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
/*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
|
|
|
|
mem += 3;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (psize & 1) {
|
2006-11-07 17:32:29 +00:00
|
|
|
cp[0] = mem[0];
|
|
|
|
cp[1] = mem[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
mem += 2;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
col = *mem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*rect++ = col;
|
2012-05-16 07:38:23 +00:00
|
|
|
count--;
|
2009-07-27 22:41:35 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
if (mem > mem_end)
|
2009-07-27 22:41:35 +00:00
|
|
|
goto partial_load;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-07-27 22:41:35 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
if (mem > mem_end)
|
2009-07-27 22:41:35 +00:00
|
|
|
goto partial_load;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-27 22:41:35 +00:00
|
|
|
if (size) {
|
|
|
|
printf("decodetarga: count would overwrite %d pixels\n", -size);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
partial_load:
|
|
|
|
complete_partial_load(ibuf, rect);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2015-07-11 23:52:18 +10:00
|
|
|
const unsigned char *mem_end = mem + mem_size;
|
2012-04-29 15:47:02 +00:00
|
|
|
int col, size;
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned int *rect;
|
2012-05-16 07:38:23 +00:00
|
|
|
uchar *cp = (uchar *) &col;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-03-05 10:29:10 +00:00
|
|
|
if (ibuf == NULL) return;
|
|
|
|
if (ibuf->rect == NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
size = ibuf->x * ibuf->y;
|
|
|
|
rect = ibuf->rect;
|
|
|
|
|
2003-04-27 09:59:36 +00:00
|
|
|
/* set alpha */
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[0] = 0xff;
|
|
|
|
cp[1] = cp[2] = 0;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size > 0) {
|
2012-05-16 07:38:23 +00:00
|
|
|
if (mem > mem_end)
|
2009-07-27 22:41:35 +00:00
|
|
|
goto partial_load;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (psize & 2) {
|
|
|
|
if (psize & 1) {
|
2003-04-27 09:59:36 +00:00
|
|
|
/* order = bgra */
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[0] = mem[3];
|
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
/*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
|
|
|
|
mem += 4;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-04-27 09:59:36 +00:00
|
|
|
/* set alpha for 24 bits colors */
|
2002-10-12 11:37:38 +00:00
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
/*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
|
|
|
|
mem += 3;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (psize & 1) {
|
2006-11-07 17:32:29 +00:00
|
|
|
cp[0] = mem[0];
|
|
|
|
cp[1] = mem[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
mem += 2;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
col = *mem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*rect++ = col;
|
|
|
|
size--;
|
|
|
|
}
|
2009-07-27 22:41:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
partial_load:
|
|
|
|
complete_partial_load(ibuf, rect);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
ImBuf *imb_loadtarga(const unsigned char *mem, size_t mem_size, int flags, char colorspace[IM_MAX_SPACE])
|
2012-05-17 23:21:11 +00:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
TARGA tga;
|
2012-05-16 07:38:23 +00:00
|
|
|
struct ImBuf *ibuf;
|
2015-11-23 11:45:54 +11:00
|
|
|
int count, size;
|
|
|
|
unsigned int *rect, *cmap = NULL /*, mincol = 0*/, cmap_max = 0;
|
|
|
|
int32_t cp_data;
|
|
|
|
uchar *cp = (uchar *) &cp_data;
|
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
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
if (checktarga(&tga, mem) == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
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
|
|
|
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
if (flags & IB_test) ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, tga.pixsize, 0);
|
|
|
|
else ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, (tga.pixsize + 0x7) & ~0x7, IB_rect);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
if (ibuf == NULL) return NULL;
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf->ftype = IMB_FTYPE_TGA;
|
|
|
|
if (tga.imgtyp < 4)
|
|
|
|
ibuf->foptions.flag |= RAWTGA;
|
2002-10-12 11:37:38 +00:00
|
|
|
mem = mem + 18 + tga.numid;
|
|
|
|
|
|
|
|
cp[0] = 0xff;
|
|
|
|
cp[1] = cp[2] = 0;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tga.mapsize) {
|
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
|
|
|
/* load color map */
|
2011-05-23 15:23:31 +00:00
|
|
|
/*mincol = tga.maporig;*/ /*UNUSED*/
|
2015-11-23 11:45:54 +11:00
|
|
|
cmap_max = tga.mapsize;
|
|
|
|
cmap = MEM_callocN(sizeof(unsigned int) * cmap_max, "targa cmap");
|
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
|
|
|
|
2015-11-23 11:45:54 +11:00
|
|
|
for (count = 0; count < cmap_max; count++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
switch (tga.mapbits >> 3) {
|
|
|
|
case 4:
|
|
|
|
cp[0] = mem[3];
|
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
mem += 4;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
cp[1] = mem[0];
|
|
|
|
cp[2] = mem[1];
|
|
|
|
cp[3] = mem[2];
|
|
|
|
mem += 3;
|
|
|
|
break;
|
|
|
|
case 2:
|
2006-11-07 21:24:47 +00:00
|
|
|
cp[1] = mem[1];
|
|
|
|
cp[0] = mem[0];
|
2002-10-12 11:37:38 +00:00
|
|
|
mem += 2;
|
|
|
|
break;
|
|
|
|
case 1:
|
2015-11-23 11:45:54 +11:00
|
|
|
cp_data = *mem++;
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-23 11:45:54 +11:00
|
|
|
cmap[count] = cp_data;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size = 0;
|
2015-11-23 11:45:54 +11:00
|
|
|
for (int cmap_index = cmap_max - 1; cmap_index > 0; cmap_index >>= 1) {
|
|
|
|
size++;
|
|
|
|
}
|
2011-11-21 20:47:19 +00:00
|
|
|
ibuf->planes = size;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
if (tga.mapbits != 32) { /* set alpha bits */
|
2011-06-04 03:07:56 +00:00
|
|
|
cmap[0] &= BIG_LONG(0x00ffffffl);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
if (flags & IB_test) {
|
2014-03-01 20:14:20 +11:00
|
|
|
if (cmap) {
|
|
|
|
MEM_freeN(cmap);
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
return ibuf;
|
|
|
|
}
|
2002-10-12 11:37:38 +00: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
|
|
|
if (tga.imgtyp != 1 && tga.imgtyp != 9) { /* happens sometimes (beuh) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cmap) {
|
2010-06-23 10:24:35 +00:00
|
|
|
MEM_freeN(cmap);
|
2012-05-16 07:38:23 +00:00
|
|
|
cmap = NULL;
|
2010-06-23 10:24:35 +00: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
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (tga.imgtyp) {
|
2012-05-16 07:38:23 +00:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0);
|
|
|
|
else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1);
|
|
|
|
else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2);
|
|
|
|
else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0);
|
|
|
|
else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1);
|
|
|
|
else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2);
|
|
|
|
else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3);
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cmap) {
|
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
|
|
|
/* apply color map */
|
|
|
|
rect = ibuf->rect;
|
2012-05-16 07:38:23 +00:00
|
|
|
for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) {
|
2015-11-23 11:45:54 +11:00
|
|
|
int cmap_index = *rect;
|
|
|
|
if (cmap_index >= 0 && cmap_index < cmap_max) {
|
|
|
|
*rect = cmap[cmap_index];
|
|
|
|
}
|
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(cmap);
|
2002-10-12 11:37:38 +00: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
|
|
|
if (tga.pixsize == 16) {
|
2015-11-23 11:45:54 +11:00
|
|
|
unsigned int col;
|
2002-10-12 11:37:38 +00:00
|
|
|
rect = ibuf->rect;
|
2012-03-24 06:38:07 +00:00
|
|
|
for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) {
|
2002-10-12 11:37:38 +00:00
|
|
|
col = *rect;
|
2012-05-16 07:38:23 +00:00
|
|
|
cp = (uchar *)rect;
|
|
|
|
mem = (uchar *)&col;
|
2006-11-07 18:32:25 +00:00
|
|
|
|
2006-11-07 17:32:29 +00:00
|
|
|
cp[3] = ((mem[1] << 1) & 0xf8);
|
|
|
|
cp[2] = ((mem[0] & 0xe0) >> 2) + ((mem[1] & 0x03) << 6);
|
|
|
|
cp[1] = ((mem[0] << 3) & 0xf8);
|
|
|
|
cp[1] += cp[1] >> 5;
|
|
|
|
cp[2] += cp[2] >> 5;
|
|
|
|
cp[3] += cp[3] >> 5;
|
|
|
|
cp[0] = 0xff;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-11-21 20:47:19 +00:00
|
|
|
ibuf->planes = 24;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tga.imgtyp == 3 || tga.imgtyp == 11) {
|
2002-10-12 11:37:38 +00:00
|
|
|
uchar *crect;
|
|
|
|
unsigned int *lrect, col;
|
|
|
|
|
|
|
|
crect = (uchar *) ibuf->rect;
|
|
|
|
lrect = (unsigned int *) ibuf->rect;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
for (size = ibuf->x * ibuf->y; size > 0; size--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
col = *lrect++;
|
|
|
|
|
|
|
|
crect[0] = 255;
|
|
|
|
crect[1] = crect[2] = crect[3] = col;
|
|
|
|
crect += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-15 06:29:32 +00:00
|
|
|
if (tga.imgdes & 0x20) {
|
|
|
|
IMB_flipy(ibuf);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-09-15 06:29:32 +00:00
|
|
|
if (ibuf->rect)
|
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
|
|
|
IMB_convert_rgba_to_abgr(ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
return ibuf;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|