2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +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-04-16 22:40:48 +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-04-16 22:40:48 +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/jpeg.c
|
|
|
|
* \ingroup imbuf
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* This little block needed for linking to Blender... */
|
|
|
|
#include <stdio.h>
|
2009-12-01 20:37:26 +00:00
|
|
|
#include <setjmp.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 "MEM_guardedalloc.h"
|
|
|
|
|
2015-01-26 16:03:11 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2012-08-12 23:28:33 +00:00
|
|
|
#include "BLI_string.h"
|
|
|
|
#include "BLI_fileops.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-01-31 17:15:43 +01:00
|
|
|
#include "BKE_idprop.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_metadata.h"
|
|
|
|
#include "IMB_filetype.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "jpeglib.h"
|
2009-12-01 20:37:26 +00:00
|
|
|
#include "jerror.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"
|
|
|
|
|
2012-09-20 01:02:39 +00:00
|
|
|
// #define IS_jpg(x) (x->ftype & JPG) // UNUSED
|
2015-07-13 13:58:17 +02:00
|
|
|
#define IS_stdjpg(x) ((x->foptions.flag & JPG_MSK) == JPG_STD)
|
|
|
|
// #define IS_vidjpg(x) ((x->foptions & JPG_MSK) == JPG_VID) // UNUSED
|
|
|
|
#define IS_jstjpg(x) ((x->foptions.flag & JPG_MSK) == JPG_JST)
|
|
|
|
#define IS_maxjpg(x) ((x->foptions.flag & JPG_MSK) == JPG_MAX)
|
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
|
|
|
/* the types are from the jpeg lib */
|
2013-09-01 15:01:15 +00:00
|
|
|
static void jpeg_error(j_common_ptr cinfo) ATTR_NORETURN;
|
2002-10-12 11:37:38 +00:00
|
|
|
static void init_source(j_decompress_ptr cinfo);
|
|
|
|
static boolean fill_input_buffer(j_decompress_ptr cinfo);
|
|
|
|
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes);
|
|
|
|
static void term_source(j_decompress_ptr cinfo);
|
2015-07-11 23:52:18 +10:00
|
|
|
static void memory_source(j_decompress_ptr cinfo, const unsigned char *buffer, size_t size);
|
2012-05-16 07:38:23 +00:00
|
|
|
static boolean handle_app1(j_decompress_ptr cinfo);
|
|
|
|
static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2003-04-27 09:59:36 +00:00
|
|
|
* In principle there are 4 jpeg formats.
|
2012-02-27 10:35:39 +00:00
|
|
|
*
|
2012-07-16 23:23:33 +00:00
|
|
|
* 1. jpeg - standard printing, u & v at quarter of resolution
|
|
|
|
* 2. jvid - standard video, u & v half resolution, frame not interlaced
|
2012-03-09 18:28:30 +00:00
|
|
|
*
|
|
|
|
* type 3 is unsupported as of jul 05 2000 Frank.
|
|
|
|
*
|
2010-01-14 10:59:42 +00:00
|
|
|
* 3. jstr - as 2, but written in 2 separate fields
|
2012-03-09 18:28:30 +00:00
|
|
|
*
|
2003-04-27 09:59:36 +00:00
|
|
|
* 4. jmax - no scaling in the components
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int jpeg_default_quality;
|
2015-07-13 13:58:17 +02:00
|
|
|
static int ibuf_foptions;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
int imb_is_a_jpeg(const unsigned char *mem)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2012-05-16 07:38:23 +00:00
|
|
|
if ((mem[0] == 0xFF) && (mem[1] == 0xD8)) return 1;
|
2006-02-28 18:30:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/*----------------------------------------------------------
|
|
|
|
* JPG ERROR HANDLING
|
|
|
|
*---------------------------------------------------------- */
|
2009-12-01 20:37:26 +00:00
|
|
|
|
|
|
|
typedef struct my_error_mgr {
|
2012-05-16 07:38:23 +00:00
|
|
|
struct jpeg_error_mgr pub; /* "public" fields */
|
2009-12-01 20:37:26 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
jmp_buf setjmp_buffer; /* for return to caller */
|
2009-12-01 20:37:26 +00:00
|
|
|
} my_error_mgr;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
typedef my_error_mgr *my_error_ptr;
|
2009-12-01 20:37:26 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static void jpeg_error(j_common_ptr cinfo)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-12-01 20:37:26 +00:00
|
|
|
my_error_ptr err = (my_error_ptr)cinfo->err;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* Always display the message */
|
2012-05-16 07:38:23 +00:00
|
|
|
(*cinfo->err->output_message)(cinfo);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Let the memory manager delete any temp files before we die */
|
|
|
|
jpeg_destroy(cinfo);
|
|
|
|
|
2009-12-01 20:37:26 +00:00
|
|
|
/* return control to the setjmp point */
|
|
|
|
longjmp(err->setjmp_buffer, 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/*----------------------------------------------------------
|
|
|
|
* INPUT HANDLER FROM MEMORY
|
|
|
|
*---------------------------------------------------------- */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-03-17 10:26:23 +00:00
|
|
|
#if 0
|
2002-10-12 11:37:38 +00:00
|
|
|
typedef struct {
|
2012-05-16 07:38:23 +00:00
|
|
|
unsigned char *buffer;
|
|
|
|
int filled;
|
2002-10-12 11:37:38 +00:00
|
|
|
} buffer_struct;
|
2013-03-17 10:26:23 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2012-05-16 07:38:23 +00:00
|
|
|
struct jpeg_source_mgr pub; /* public fields */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
const unsigned char *buffer;
|
2012-05-16 07:38:23 +00:00
|
|
|
int size;
|
|
|
|
JOCTET terminal[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
} my_source_mgr;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
typedef my_source_mgr *my_src_ptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
static void init_source(j_decompress_ptr cinfo)
|
|
|
|
{
|
2010-10-17 06:38:56 +00:00
|
|
|
(void)cinfo; /* unused */
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static boolean fill_input_buffer(j_decompress_ptr cinfo)
|
|
|
|
{
|
|
|
|
my_src_ptr src = (my_src_ptr) cinfo->src;
|
|
|
|
|
|
|
|
/* Since we have given all we have got already
|
2012-03-09 18:28:30 +00:00
|
|
|
* we simply fake an end of file
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
src->pub.next_input_byte = src->terminal;
|
|
|
|
src->pub.bytes_in_buffer = 2;
|
|
|
|
src->terminal[0] = (JOCTET) 0xFF;
|
|
|
|
src->terminal[1] = (JOCTET) JPEG_EOI;
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
|
|
|
|
{
|
|
|
|
my_src_ptr src = (my_src_ptr) cinfo->src;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (num_bytes > 0) {
|
2012-07-07 22:51:57 +00:00
|
|
|
/* prevent skipping over file end */
|
2011-04-10 11:36:29 +00:00
|
|
|
size_t skip_size = (size_t)num_bytes <= src->pub.bytes_in_buffer ? num_bytes : src->pub.bytes_in_buffer;
|
|
|
|
|
|
|
|
src->pub.next_input_byte = src->pub.next_input_byte + skip_size;
|
|
|
|
src->pub.bytes_in_buffer = src->pub.bytes_in_buffer - skip_size;
|
2010-07-27 14:40:48 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void term_source(j_decompress_ptr cinfo)
|
|
|
|
{
|
2010-10-17 06:38:56 +00:00
|
|
|
(void)cinfo; /* unused */
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
static void memory_source(j_decompress_ptr cinfo, const unsigned char *buffer, size_t size)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
my_src_ptr src;
|
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
2002-10-12 11:37:38 +00:00
|
|
|
cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)
|
2012-05-16 07:38:23 +00:00
|
|
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_source_mgr));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
src = (my_src_ptr) cinfo->src;
|
2012-05-16 07:38:23 +00:00
|
|
|
src->pub.init_source = init_source;
|
|
|
|
src->pub.fill_input_buffer = fill_input_buffer;
|
|
|
|
src->pub.skip_input_data = skip_input_data;
|
|
|
|
src->pub.resync_to_restart = jpeg_resync_to_restart;
|
|
|
|
src->pub.term_source = term_source;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
src->pub.bytes_in_buffer = size;
|
|
|
|
src->pub.next_input_byte = buffer;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
src->buffer = buffer;
|
|
|
|
src->size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
#define MAKESTMT(stuff) do { stuff } while (0)
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#define INPUT_VARS(cinfo) \
|
2012-08-04 19:34:38 +00:00
|
|
|
struct jpeg_source_mgr *datasrc = (cinfo)->src; \
|
2002-10-12 11:37:38 +00:00
|
|
|
const JOCTET * next_input_byte = datasrc->next_input_byte; \
|
|
|
|
size_t bytes_in_buffer = datasrc->bytes_in_buffer
|
|
|
|
|
|
|
|
/* Unload the local copies --- do this only at a restart boundary */
|
|
|
|
#define INPUT_SYNC(cinfo) \
|
|
|
|
( datasrc->next_input_byte = next_input_byte, \
|
|
|
|
datasrc->bytes_in_buffer = bytes_in_buffer )
|
|
|
|
|
|
|
|
/* Reload the local copies --- seldom used except in MAKE_BYTE_AVAIL */
|
|
|
|
#define INPUT_RELOAD(cinfo) \
|
|
|
|
( next_input_byte = datasrc->next_input_byte, \
|
|
|
|
bytes_in_buffer = datasrc->bytes_in_buffer )
|
|
|
|
|
|
|
|
/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
|
|
|
|
* Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
|
|
|
|
* but we must reload the local copies after a successful fill.
|
|
|
|
*/
|
2011-11-11 13:09:14 +00:00
|
|
|
#define MAKE_BYTE_AVAIL(cinfo, action) \
|
|
|
|
if (bytes_in_buffer == 0) { \
|
|
|
|
if (! (*datasrc->fill_input_buffer) (cinfo)) \
|
|
|
|
{ action; } \
|
|
|
|
INPUT_RELOAD(cinfo); \
|
2012-05-27 20:13:59 +00:00
|
|
|
} (void)0
|
2011-04-10 11:36:29 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Read a byte into variable V.
|
2014-04-01 11:34:00 +11:00
|
|
|
* If must suspend, take the specified action (typically "return false").
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2012-05-16 07:38:23 +00:00
|
|
|
#define INPUT_BYTE(cinfo, V, action) \
|
2012-12-29 01:54:58 +00:00
|
|
|
MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); \
|
2012-11-09 09:33:28 +00:00
|
|
|
bytes_in_buffer--; \
|
|
|
|
V = GETJOCTET(*next_input_byte++); )
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* As above, but read two bytes interpreted as an unsigned 16-bit integer.
|
|
|
|
* V should be declared unsigned int or perhaps INT32.
|
|
|
|
*/
|
2012-05-16 07:38:23 +00:00
|
|
|
#define INPUT_2BYTES(cinfo, V, action) \
|
2012-12-29 01:54:58 +00:00
|
|
|
MAKESTMT(MAKE_BYTE_AVAIL(cinfo, action); \
|
2012-11-09 09:33:28 +00:00
|
|
|
bytes_in_buffer--; \
|
|
|
|
V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
|
|
|
|
MAKE_BYTE_AVAIL(cinfo, action); \
|
|
|
|
bytes_in_buffer--; \
|
|
|
|
V += GETJOCTET(*next_input_byte++); )
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2015-07-12 01:43:32 +10:00
|
|
|
static boolean handle_app1(j_decompress_ptr cinfo)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-09-22 03:14:50 +00:00
|
|
|
INT32 length; /* initialized by the macro */
|
|
|
|
INT32 i;
|
2002-10-12 11:37:38 +00:00
|
|
|
char neogeo[128];
|
|
|
|
|
|
|
|
INPUT_VARS(cinfo);
|
2011-09-22 03:14:50 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
INPUT_2BYTES(cinfo, length, return false);
|
2002-10-12 11:37:38 +00:00
|
|
|
length -= 2;
|
|
|
|
|
|
|
|
if (length < 16) {
|
2014-04-01 11:34:00 +11:00
|
|
|
for (i = 0; i < length; i++) INPUT_BYTE(cinfo, neogeo[i], return false);
|
2002-10-12 11:37:38 +00:00
|
|
|
length = 0;
|
2015-07-13 13:58:17 +02:00
|
|
|
if (STREQLEN(neogeo, "NeoGeo", 6)) memcpy(&ibuf_foptions, neogeo + 6, 4);
|
|
|
|
ibuf_foptions = BIG_LONG(ibuf_foptions);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-16 07:38:23 +00:00
|
|
|
INPUT_SYNC(cinfo); /* do before skip_input_data */
|
|
|
|
if (length > 0) (*cinfo->src->skip_input_data)(cinfo, length);
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
JSAMPARRAY row_pointer;
|
2012-05-16 07:38:23 +00:00
|
|
|
JSAMPLE *buffer = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
int row_stride;
|
|
|
|
int x, y, depth, r, g, b, k;
|
2012-05-16 07:38:23 +00:00
|
|
|
struct ImBuf *ibuf = NULL;
|
|
|
|
uchar *rect;
|
2007-12-19 05:37:57 +00:00
|
|
|
jpeg_saved_marker_ptr marker;
|
|
|
|
char *str, *key, *value;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-27 09:59:36 +00:00
|
|
|
/* install own app1 handler */
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf_foptions = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
jpeg_set_marker_processor(cinfo, 0xe1, handle_app1);
|
|
|
|
cinfo->dct_method = JDCT_FLOAT;
|
2007-12-19 05:37:57 +00:00
|
|
|
jpeg_save_markers(cinfo, JPEG_COM, 0xffff);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
if (jpeg_read_header(cinfo, false) == JPEG_HEADER_OK) {
|
2002-10-12 11:37:38 +00:00
|
|
|
x = cinfo->image_width;
|
|
|
|
y = cinfo->image_height;
|
|
|
|
depth = cinfo->num_components;
|
2009-12-01 20:37:26 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if (cinfo->jpeg_color_space == JCS_YCCK) cinfo->out_color_space = JCS_CMYK;
|
|
|
|
|
|
|
|
jpeg_start_decompress(cinfo);
|
|
|
|
|
2015-07-13 13:58:17 +02:00
|
|
|
if (ibuf_foptions == 0) {
|
|
|
|
ibuf_foptions = JPG_STD;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (cinfo->max_v_samp_factor == 1) {
|
2015-07-13 13:58:17 +02:00
|
|
|
if (cinfo->max_h_samp_factor == 1) ibuf_foptions = JPG_MAX;
|
|
|
|
else ibuf_foptions = JPG_VID;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & IB_test) {
|
|
|
|
jpeg_abort_decompress(cinfo);
|
2010-10-16 14:32:17 +00:00
|
|
|
ibuf = IMB_allocImBuf(x, y, 8 * depth, 0);
|
2010-09-28 10:03:56 +00:00
|
|
|
}
|
2010-10-16 14:32:17 +00:00
|
|
|
else if ((ibuf = IMB_allocImBuf(x, y, 8 * depth, IB_rect)) == NULL) {
|
2010-09-28 10:03:56 +00:00
|
|
|
jpeg_abort_decompress(cinfo);
|
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
row_stride = cinfo->output_width * depth;
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
row_pointer = (*cinfo->mem->alloc_sarray)((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
for (y = ibuf->y - 1; y >= 0; y--) {
|
|
|
|
jpeg_read_scanlines(cinfo, row_pointer, 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
|
|
|
rect = (uchar *) (ibuf->rect + y * ibuf->x);
|
2002-10-12 11:37:38 +00:00
|
|
|
buffer = row_pointer[0];
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (depth) {
|
2006-02-28 23:58:17 +00:00
|
|
|
case 1:
|
2012-05-16 07:38:23 +00:00
|
|
|
for (x = ibuf->x; x > 0; x--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
rect[3] = 255;
|
|
|
|
rect[0] = rect[1] = rect[2] = *buffer++;
|
|
|
|
rect += 4;
|
2006-02-28 23:58:17 +00:00
|
|
|
}
|
2012-02-27 10:35:39 +00:00
|
|
|
break;
|
2006-02-28 23:58:17 +00:00
|
|
|
case 3:
|
2012-05-16 07:38:23 +00:00
|
|
|
for (x = ibuf->x; x > 0; x--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
rect[3] = 255;
|
|
|
|
rect[0] = *buffer++;
|
|
|
|
rect[1] = *buffer++;
|
|
|
|
rect[2] = *buffer++;
|
|
|
|
rect += 4;
|
2006-02-28 23:58:17 +00:00
|
|
|
}
|
2012-02-27 10:35:39 +00:00
|
|
|
break;
|
2006-02-28 23:58:17 +00:00
|
|
|
case 4:
|
2012-05-16 07:38:23 +00:00
|
|
|
for (x = ibuf->x; x > 0; x--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
r = *buffer++;
|
|
|
|
g = *buffer++;
|
|
|
|
b = *buffer++;
|
|
|
|
k = *buffer++;
|
2012-11-13 14:28:45 +00:00
|
|
|
|
|
|
|
r = (r * k) / 255;
|
|
|
|
g = (g * k) / 255;
|
|
|
|
b = (b * k) / 255;
|
|
|
|
|
|
|
|
rect[3] = 255;
|
2002-10-12 11:37:38 +00:00
|
|
|
rect[2] = b;
|
|
|
|
rect[1] = g;
|
|
|
|
rect[0] = r;
|
|
|
|
rect += 4;
|
2006-02-28 23:58:17 +00:00
|
|
|
}
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-19 05:37:57 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
marker = cinfo->marker_list;
|
2012-03-24 06:38:07 +00:00
|
|
|
while (marker) {
|
|
|
|
if (marker->marker != JPEG_COM)
|
2007-12-19 05:37:57 +00:00
|
|
|
goto next_stamp_marker;
|
|
|
|
|
2013-05-04 21:12:23 +00:00
|
|
|
/*
|
|
|
|
* JPEG marker strings are not null-terminated,
|
|
|
|
* create a null-terminated copy before going further
|
|
|
|
*/
|
|
|
|
str = BLI_strdupn((char *)marker->data, marker->data_length);
|
|
|
|
|
2007-12-19 05:37:57 +00:00
|
|
|
/*
|
|
|
|
* Because JPEG format don't support the
|
|
|
|
* pair "key/value" like PNG, we store the
|
|
|
|
* stampinfo in a single "encode" string:
|
|
|
|
* "Blender:key:value"
|
|
|
|
*
|
|
|
|
* That is why we need split it to the
|
|
|
|
* common key/value here.
|
|
|
|
*/
|
2015-01-26 16:03:11 +01:00
|
|
|
if (!STREQLEN(str, "Blender", 7)) {
|
2007-12-19 05:37:57 +00:00
|
|
|
/*
|
|
|
|
* Maybe the file have text that
|
|
|
|
* we don't know "what it's", in that
|
|
|
|
* case we keep the text (with a
|
|
|
|
* key "None").
|
|
|
|
* This is only for don't "lose"
|
|
|
|
* the information when we write
|
|
|
|
* it back to disk.
|
|
|
|
*/
|
2013-05-04 21:12:23 +00:00
|
|
|
IMB_metadata_add_field(ibuf, "None", str);
|
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
|
|
|
ibuf->flags |= IB_metadata;
|
2013-05-04 21:12:23 +00:00
|
|
|
MEM_freeN(str);
|
2007-12-19 05:37:57 +00:00
|
|
|
goto next_stamp_marker;
|
|
|
|
}
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
key = strchr(str, ':');
|
2007-12-19 05:37:57 +00:00
|
|
|
/*
|
|
|
|
* A little paranoid, but the file maybe
|
|
|
|
* is broken... and a "extra" check is better
|
2012-03-09 00:41:09 +00:00
|
|
|
* then segfault ;)
|
2007-12-19 05:37:57 +00:00
|
|
|
*/
|
|
|
|
if (!key) {
|
|
|
|
MEM_freeN(str);
|
|
|
|
goto next_stamp_marker;
|
|
|
|
}
|
|
|
|
|
|
|
|
key++;
|
2012-05-16 07:38:23 +00:00
|
|
|
value = strchr(key, ':');
|
2007-12-19 05:37:57 +00:00
|
|
|
if (!value) {
|
|
|
|
MEM_freeN(str);
|
|
|
|
goto next_stamp_marker;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = '\0'; /* need finish the key string */
|
|
|
|
value++;
|
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_metadata_add_field(ibuf, key, value);
|
|
|
|
ibuf->flags |= IB_metadata;
|
2007-12-19 05:37:57 +00:00
|
|
|
MEM_freeN(str);
|
|
|
|
next_stamp_marker:
|
2012-05-16 07:38:23 +00:00
|
|
|
marker = marker->next;
|
2007-12-19 05:37:57 +00:00
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
jpeg_finish_decompress(cinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
jpeg_destroy((j_common_ptr) cinfo);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf) {
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf->ftype = IMB_FTYPE_JPG;
|
|
|
|
ibuf->foptions.flag = ibuf_foptions;
|
2010-09-28 10:03:56 +00:00
|
|
|
}
|
2005-01-03 19:53:04 +00:00
|
|
|
}
|
2010-09-28 10:03:56 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return(ibuf);
|
2005-01-21 17:50:11 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-07-11 23:52:18 +10:00
|
|
|
ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, int flags, char colorspace[IM_MAX_SPACE])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
|
2009-12-01 20:37:26 +00:00
|
|
|
struct my_error_mgr jerr;
|
2012-05-16 07:38:23 +00:00
|
|
|
ImBuf *ibuf;
|
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
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!imb_is_a_jpeg(buffer)) return NULL;
|
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);
|
|
|
|
|
2009-12-01 20:37:26 +00:00
|
|
|
cinfo->err = jpeg_std_error(&jerr.pub);
|
|
|
|
jerr.pub.error_exit = jpeg_error;
|
|
|
|
|
|
|
|
/* Establish the setjmp return context for my_error_exit to use. */
|
|
|
|
if (setjmp(jerr.setjmp_buffer)) {
|
|
|
|
/* If we get here, the JPEG code has signaled an error.
|
|
|
|
* We need to clean up the JPEG object, close the input file, and return.
|
|
|
|
*/
|
|
|
|
jpeg_destroy_decompress(cinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
jpeg_create_decompress(cinfo);
|
|
|
|
memory_source(cinfo, buffer, size);
|
|
|
|
|
|
|
|
ibuf = ibJpegImageFromCinfo(cinfo, flags);
|
|
|
|
|
|
|
|
return(ibuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-16 07:38:23 +00:00
|
|
|
JSAMPLE *buffer = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
JSAMPROW row_pointer[1];
|
2012-05-16 07:38:23 +00:00
|
|
|
uchar *rect;
|
2002-10-12 11:37:38 +00:00
|
|
|
int x, y;
|
|
|
|
char neogeo[128];
|
2007-12-19 05:37:57 +00:00
|
|
|
char *text;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
jpeg_start_compress(cinfo, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
strcpy(neogeo, "NeoGeo");
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf_foptions = BIG_LONG((((int)ibuf->foptions.flag) << 8) | (int)ibuf->foptions.quality);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-07-13 13:58:17 +02:00
|
|
|
memcpy(neogeo + 6, &ibuf_foptions, 4);
|
2012-05-16 07:38:23 +00:00
|
|
|
jpeg_write_marker(cinfo, 0xe1, (JOCTET *) neogeo, 10);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf->metadata) {
|
2015-01-31 17:15:43 +01:00
|
|
|
IDProperty *prop;
|
2007-12-19 05:37:57 +00:00
|
|
|
/* key + max value + "Blender" */
|
2012-05-16 07:38:23 +00:00
|
|
|
text = MEM_mallocN(530, "stamp info read");
|
2015-01-31 17:15:43 +01:00
|
|
|
for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) {
|
|
|
|
if (prop->type == IDP_STRING) {
|
|
|
|
int text_len;
|
|
|
|
if (!strcmp(prop->name, "None")) {
|
|
|
|
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) IDP_String(prop), prop->len + 1);
|
|
|
|
}
|
2007-12-19 05:37:57 +00:00
|
|
|
|
2015-01-31 17:15:43 +01:00
|
|
|
/*
|
|
|
|
* The JPEG format don't support a pair "key/value"
|
|
|
|
* like PNG, so we "encode" the stamp in a
|
|
|
|
* single string:
|
|
|
|
* "Blender:key:value"
|
|
|
|
*
|
|
|
|
* The first "Blender" is a simple identify to help
|
|
|
|
* in the read process.
|
|
|
|
*/
|
|
|
|
text_len = sprintf(text, "Blender:%s:%s", prop->name, IDP_String(prop));
|
|
|
|
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, text_len + 1);
|
|
|
|
}
|
2007-12-19 05:37:57 +00:00
|
|
|
}
|
|
|
|
MEM_freeN(text);
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
row_pointer[0] =
|
2012-05-16 07:38:23 +00:00
|
|
|
MEM_mallocN(sizeof(JSAMPLE) *
|
|
|
|
cinfo->input_components *
|
|
|
|
cinfo->image_width, "jpeg row_pointer");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = ibuf->y - 1; y >= 0; y--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
rect = (uchar *) (ibuf->rect + y * ibuf->x);
|
|
|
|
buffer = row_pointer[0];
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (cinfo->in_color_space) {
|
2012-02-27 10:35:39 +00:00
|
|
|
case JCS_RGB:
|
|
|
|
for (x = 0; x < ibuf->x; x++) {
|
|
|
|
*buffer++ = rect[0];
|
|
|
|
*buffer++ = rect[1];
|
|
|
|
*buffer++ = rect[2];
|
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case JCS_GRAYSCALE:
|
|
|
|
for (x = 0; x < ibuf->x; x++) {
|
|
|
|
*buffer++ = rect[0];
|
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case JCS_UNKNOWN:
|
|
|
|
memcpy(buffer, rect, 4 * ibuf->x);
|
|
|
|
break;
|
2012-05-16 07:38:23 +00:00
|
|
|
/* default was missing... intentional ? */
|
2012-02-27 10:35:39 +00:00
|
|
|
default:
|
2013-07-21 08:16:37 +00:00
|
|
|
/* do nothing */
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jpeg_write_scanlines(cinfo, row_pointer, 1);
|
|
|
|
}
|
|
|
|
|
2009-12-01 20:37:26 +00:00
|
|
|
jpeg_finish_compress(cinfo);
|
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(row_pointer[0]);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
int quality;
|
|
|
|
|
2015-07-13 13:58:17 +02:00
|
|
|
quality = ibuf->foptions.quality;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (quality <= 0) quality = jpeg_default_quality;
|
|
|
|
if (quality > 100) quality = 100;
|
|
|
|
|
|
|
|
jpeg_create_compress(cinfo);
|
|
|
|
jpeg_stdio_dest(cinfo, outfile);
|
|
|
|
|
|
|
|
cinfo->image_width = ibuf->x;
|
|
|
|
cinfo->image_height = ibuf->y;
|
|
|
|
|
|
|
|
cinfo->in_color_space = JCS_RGB;
|
2011-11-21 20:47:19 +00:00
|
|
|
if (ibuf->planes == 8) cinfo->in_color_space = JCS_GRAYSCALE;
|
2011-11-24 06:30:37 +00:00
|
|
|
#if 0
|
|
|
|
/* just write RGBA as RGB,
|
|
|
|
* unsupported feature only confuses other s/w */
|
|
|
|
|
2011-11-21 20:47:19 +00:00
|
|
|
if (ibuf->planes == 32) cinfo->in_color_space = JCS_UNKNOWN;
|
2011-11-24 06:30:37 +00:00
|
|
|
#endif
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (cinfo->in_color_space) {
|
2012-02-27 10:35:39 +00:00
|
|
|
case JCS_RGB:
|
|
|
|
cinfo->input_components = 3;
|
|
|
|
break;
|
|
|
|
case JCS_GRAYSCALE:
|
|
|
|
cinfo->input_components = 1;
|
|
|
|
break;
|
|
|
|
case JCS_UNKNOWN:
|
|
|
|
cinfo->input_components = 4;
|
|
|
|
break;
|
2012-05-16 07:38:23 +00:00
|
|
|
/* default was missing... intentional ? */
|
2012-02-27 10:35:39 +00:00
|
|
|
default:
|
2013-07-21 08:16:37 +00:00
|
|
|
/* do nothing */
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
jpeg_set_defaults(cinfo);
|
|
|
|
|
2003-04-27 09:59:36 +00:00
|
|
|
/* own settings */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
cinfo->dct_method = JDCT_FLOAT;
|
2014-04-01 11:34:00 +11:00
|
|
|
jpeg_set_quality(cinfo, quality, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-16 07:38:23 +00:00
|
|
|
FILE *outfile;
|
2002-10-12 11:37:38 +00:00
|
|
|
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
|
2009-12-01 20:37:26 +00:00
|
|
|
struct my_error_mgr jerr;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-20 02:17:37 +00:00
|
|
|
if ((outfile = BLI_fopen(name, "wb")) == NULL) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
jpeg_default_quality = 75;
|
|
|
|
|
2009-12-01 20:37:26 +00:00
|
|
|
cinfo->err = jpeg_std_error(&jerr.pub);
|
|
|
|
jerr.pub.error_exit = jpeg_error;
|
|
|
|
|
|
|
|
/* Establish the setjmp return context for jpeg_error to use. */
|
|
|
|
if (setjmp(jerr.setjmp_buffer)) {
|
|
|
|
/* If we get here, the JPEG code has signaled an error.
|
|
|
|
* We need to clean up the JPEG object, close the input file, and return.
|
|
|
|
*/
|
|
|
|
jpeg_destroy_compress(cinfo);
|
|
|
|
fclose(outfile);
|
|
|
|
remove(name);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
init_jpeg(outfile, cinfo, ibuf);
|
|
|
|
|
|
|
|
write_jpeg(cinfo, ibuf);
|
|
|
|
|
|
|
|
fclose(outfile);
|
|
|
|
jpeg_destroy_compress(cinfo);
|
|
|
|
|
2005-01-21 17:50:11 +00:00
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
static int save_vidjpeg(const char *name, struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-16 07:38:23 +00:00
|
|
|
FILE *outfile;
|
2002-10-12 11:37:38 +00:00
|
|
|
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
|
2009-12-01 20:37:26 +00:00
|
|
|
struct my_error_mgr jerr;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-20 02:17:37 +00:00
|
|
|
if ((outfile = BLI_fopen(name, "wb")) == NULL) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
jpeg_default_quality = 90;
|
|
|
|
|
2009-12-01 20:37:26 +00:00
|
|
|
cinfo->err = jpeg_std_error(&jerr.pub);
|
|
|
|
jerr.pub.error_exit = jpeg_error;
|
|
|
|
|
|
|
|
/* Establish the setjmp return context for jpeg_error to use. */
|
|
|
|
if (setjmp(jerr.setjmp_buffer)) {
|
|
|
|
/* If we get here, the JPEG code has signaled an error.
|
|
|
|
* We need to clean up the JPEG object, close the input file, and return.
|
|
|
|
*/
|
|
|
|
jpeg_destroy_compress(cinfo);
|
|
|
|
fclose(outfile);
|
|
|
|
remove(name);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
init_jpeg(outfile, cinfo, ibuf);
|
|
|
|
|
2003-04-27 09:59:36 +00:00
|
|
|
/* adjust scaling factors */
|
2002-10-12 11:37:38 +00:00
|
|
|
if (cinfo->in_color_space == JCS_RGB) {
|
|
|
|
cinfo->comp_info[0].h_samp_factor = 2;
|
|
|
|
cinfo->comp_info[0].v_samp_factor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
write_jpeg(cinfo, ibuf);
|
|
|
|
|
|
|
|
fclose(outfile);
|
|
|
|
jpeg_destroy_compress(cinfo);
|
|
|
|
|
2005-01-21 17:50:11 +00:00
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
static int save_jstjpeg(const char *name, struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
char fieldname[1024];
|
2012-05-16 07:38:23 +00:00
|
|
|
struct ImBuf *tbuf;
|
2005-01-21 17:50:11 +00:00
|
|
|
int oldy, returnval;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-10-16 14:32:17 +00:00
|
|
|
tbuf = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 24, IB_rect);
|
2002-10-12 11:37:38 +00:00
|
|
|
tbuf->ftype = ibuf->ftype;
|
2015-07-13 13:58:17 +02:00
|
|
|
tbuf->foptions = ibuf->foptions;
|
2002-10-12 11:37:38 +00:00
|
|
|
tbuf->flags = ibuf->flags;
|
|
|
|
|
|
|
|
oldy = ibuf->y;
|
|
|
|
ibuf->x *= 2;
|
|
|
|
ibuf->y /= 2;
|
|
|
|
|
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_rectcpy(tbuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
|
2002-10-12 11:37:38 +00:00
|
|
|
sprintf(fieldname, "%s.jf0", name);
|
|
|
|
|
2012-02-27 10:35:39 +00:00
|
|
|
returnval = save_vidjpeg(fieldname, tbuf);
|
|
|
|
if (returnval == 1) {
|
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_rectcpy(tbuf, ibuf, 0, 0, tbuf->x, 0, ibuf->x, ibuf->y);
|
2002-10-12 11:37:38 +00:00
|
|
|
sprintf(fieldname, "%s.jf1", name);
|
2005-01-21 17:50:11 +00:00
|
|
|
returnval = save_vidjpeg(fieldname, tbuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ibuf->y = oldy;
|
|
|
|
ibuf->x /= 2;
|
|
|
|
IMB_freeImBuf(tbuf);
|
|
|
|
|
2005-01-21 17:50:11 +00:00
|
|
|
return returnval;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
static int save_maxjpeg(const char *name, struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-16 07:38:23 +00:00
|
|
|
FILE *outfile;
|
2002-10-12 11:37:38 +00:00
|
|
|
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
|
2009-12-01 20:37:26 +00:00
|
|
|
struct my_error_mgr jerr;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-20 02:17:37 +00:00
|
|
|
if ((outfile = BLI_fopen(name, "wb")) == NULL) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
jpeg_default_quality = 100;
|
|
|
|
|
2009-12-01 20:37:26 +00:00
|
|
|
cinfo->err = jpeg_std_error(&jerr.pub);
|
|
|
|
jerr.pub.error_exit = jpeg_error;
|
|
|
|
|
|
|
|
/* Establish the setjmp return context for jpeg_error to use. */
|
|
|
|
if (setjmp(jerr.setjmp_buffer)) {
|
|
|
|
/* If we get here, the JPEG code has signaled an error.
|
|
|
|
* We need to clean up the JPEG object, close the input file, and return.
|
|
|
|
*/
|
|
|
|
jpeg_destroy_compress(cinfo);
|
|
|
|
fclose(outfile);
|
|
|
|
remove(name);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
init_jpeg(outfile, cinfo, ibuf);
|
|
|
|
|
2003-04-27 09:59:36 +00:00
|
|
|
/* adjust scaling factors */
|
2002-10-12 11:37:38 +00:00
|
|
|
if (cinfo->in_color_space == JCS_RGB) {
|
|
|
|
cinfo->comp_info[0].h_samp_factor = 1;
|
|
|
|
cinfo->comp_info[0].v_samp_factor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
write_jpeg(cinfo, ibuf);
|
|
|
|
|
|
|
|
fclose(outfile);
|
|
|
|
jpeg_destroy_compress(cinfo);
|
|
|
|
|
2005-01-21 17:50:11 +00:00
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
int imb_savejpeg(struct ImBuf *ibuf, const char *name, int flags)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ibuf->flags = flags;
|
2003-12-04 18:18:05 +00:00
|
|
|
if (IS_stdjpg(ibuf)) return save_stdjpeg(name, ibuf);
|
|
|
|
if (IS_jstjpg(ibuf)) return save_jstjpeg(name, ibuf);
|
|
|
|
if (IS_maxjpg(ibuf)) return save_maxjpeg(name, ibuf);
|
|
|
|
return save_vidjpeg(name, ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|