2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2007-06-25 19:50:25 +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.
|
2007-06-25 19:50:25 +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.
|
2007-06-25 19:50:25 +00:00
|
|
|
*
|
2011-05-07 20:53:49 +00:00
|
|
|
* Contributors: Amorilia (amorilia@users.sourceforge.net)
|
2007-06-25 19:50:25 +00:00
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2007-06-25 19:50:25 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-27 20:23:21 +00:00
|
|
|
/** \file blender/imbuf/intern/dds/dds_api.cpp
|
|
|
|
* \ingroup imbdds
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-09-15 08:00:19 +00:00
|
|
|
#include <stddef.h>
|
2007-06-25 19:50:25 +00:00
|
|
|
#include <dds_api.h>
|
|
|
|
#include <Stream.h>
|
|
|
|
#include <DirectDrawSurface.h>
|
2012-10-25 12:54:16 +00:00
|
|
|
#include <FlipDXT.h>
|
2007-06-25 19:50:25 +00:00
|
|
|
#include <stdio.h> // printf
|
2007-10-12 16:09:59 +00:00
|
|
|
#include <fstream>
|
2007-06-25 19:50:25 +00:00
|
|
|
|
2012-08-22 19:01:09 +00:00
|
|
|
#if defined (WIN32) && !defined(FREE_WINDOWS)
|
2012-08-22 13:10:37 +00:00
|
|
|
#include "utfconv.h"
|
|
|
|
#endif
|
|
|
|
|
2007-06-25 19:50:25 +00:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
#include "imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
#include "IMB_allocimbuf.h"
|
|
|
|
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
#include "IMB_colormanagement_intern.h"
|
|
|
|
|
2015-03-27 15:51:21 +05:00
|
|
|
int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/)
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
2007-10-12 16:09:59 +00:00
|
|
|
return(0); /* todo: finish this function */
|
|
|
|
|
|
|
|
/* check image buffer */
|
|
|
|
if (ibuf == 0) return (0);
|
|
|
|
if (ibuf->rect == 0) return (0);
|
|
|
|
|
|
|
|
/* open file for writing */
|
2012-08-22 13:10:37 +00:00
|
|
|
std::ofstream fildes;
|
|
|
|
|
2012-08-22 19:01:09 +00:00
|
|
|
#if defined (WIN32) && !defined(FREE_WINDOWS)
|
2012-08-22 13:10:37 +00:00
|
|
|
wchar_t *wname = alloc_utf16_from_8(name, 0);
|
|
|
|
fildes.open(wname);
|
|
|
|
free(wname);
|
|
|
|
#else
|
|
|
|
fildes.open(name);
|
|
|
|
#endif
|
2007-10-12 16:09:59 +00:00
|
|
|
|
|
|
|
/* write header */
|
|
|
|
fildes << "DDS ";
|
|
|
|
fildes.close();
|
|
|
|
|
|
|
|
return(1);
|
2007-06-25 19:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int imb_is_a_dds(unsigned char *mem) // note: use at most first 32 bytes
|
|
|
|
{
|
|
|
|
/* heuristic check to see if mem contains a DDS file */
|
|
|
|
/* header.fourcc == FOURCC_DDS */
|
|
|
|
if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' ')) return(0);
|
|
|
|
/* header.size == 124 */
|
|
|
|
if ((mem[4] != 124) || mem[5] || mem[6] || mem[7]) return(0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
2013-03-26 07:29:01 +00:00
|
|
|
struct ImBuf *ibuf = NULL;
|
2007-06-25 19:50:25 +00:00
|
|
|
DirectDrawSurface dds(mem, size); /* reads header */
|
2007-10-12 16:09:59 +00:00
|
|
|
unsigned char bits_per_pixel;
|
2007-06-25 19:50:25 +00:00
|
|
|
unsigned int *rect;
|
|
|
|
Image img;
|
|
|
|
unsigned int numpixels = 0;
|
|
|
|
int col;
|
|
|
|
unsigned char *cp = (unsigned char *) &col;
|
|
|
|
Color32 pixel;
|
|
|
|
Color32 *pixels = 0;
|
|
|
|
|
2013-02-19 02:30:02 +00:00
|
|
|
/* OCIO_TODO: never was able to save DDS, so can't test loading
|
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
|
|
|
* but profile used to be set to sRGB and can't see rect_float here, so
|
|
|
|
* default byte space should work fine
|
|
|
|
*/
|
|
|
|
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!imb_is_a_dds(mem))
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
return (0);
|
|
|
|
|
2007-06-25 19:50:25 +00:00
|
|
|
/* check if DDS is valid and supported */
|
|
|
|
if (!dds.isValid()) {
|
2010-01-30 09:14:12 +00:00
|
|
|
/* no need to print error here, just testing if it is a DDS */
|
2012-03-24 07:52:14 +00:00
|
|
|
if (flags & IB_test)
|
2010-01-30 09:14:12 +00:00
|
|
|
return (0);
|
|
|
|
|
2007-06-25 19:50:25 +00:00
|
|
|
printf("DDS: not valid; header follows\n");
|
|
|
|
dds.printInfo();
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if (!dds.isSupported()) {
|
|
|
|
printf("DDS: format not supported\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if ((dds.width() > 65535) || (dds.height() > 65535)) {
|
|
|
|
printf("DDS: dimensions too large\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert DDS into ImBuf */
|
2011-05-07 20:53:49 +00:00
|
|
|
dds.mipmap(&img, 0, 0); /* load first face, first mipmap */
|
|
|
|
pixels = img.pixels();
|
|
|
|
numpixels = dds.width() * dds.height();
|
|
|
|
bits_per_pixel = 24;
|
|
|
|
if (img.format() == Image::Format_ARGB) {
|
|
|
|
/* check that there is effectively an alpha channel */
|
|
|
|
for (unsigned int i = 0; i < numpixels; i++) {
|
|
|
|
pixel = pixels[i];
|
|
|
|
if (pixel.a != 255) {
|
|
|
|
bits_per_pixel = 32;
|
|
|
|
break;
|
2013-01-19 06:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-07 20:53:49 +00:00
|
|
|
ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0);
|
2007-06-25 19:50:25 +00:00
|
|
|
if (ibuf == 0) return(0); /* memory allocation failed */
|
|
|
|
|
|
|
|
ibuf->ftype = DDS;
|
2012-06-30 04:34:34 +00:00
|
|
|
ibuf->dds_data.fourcc = dds.fourCC();
|
|
|
|
ibuf->dds_data.nummipmaps = dds.mipmapCount();
|
2007-06-25 19:50:25 +00:00
|
|
|
|
|
|
|
if ((flags & IB_test) == 0) {
|
|
|
|
if (!imb_addrectImBuf(ibuf)) return(ibuf);
|
|
|
|
if (ibuf->rect == 0) return(ibuf);
|
|
|
|
|
|
|
|
rect = ibuf->rect;
|
|
|
|
cp[3] = 0xff; /* default alpha if alpha channel is not present */
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < numpixels; i++) {
|
|
|
|
pixel = pixels[i];
|
|
|
|
cp[0] = pixel.r; /* set R component of col */
|
|
|
|
cp[1] = pixel.g; /* set G component of col */
|
|
|
|
cp[2] = pixel.b; /* set B component of col */
|
2012-06-30 04:34:34 +00:00
|
|
|
if (dds.hasAlpha())
|
2007-06-25 19:50:25 +00:00
|
|
|
cp[3] = pixel.a; /* set A component of col */
|
|
|
|
rect[i] = col;
|
|
|
|
}
|
2012-06-30 04:34:34 +00:00
|
|
|
|
2012-10-25 12:54:16 +00:00
|
|
|
if (ibuf->dds_data.fourcc != FOURCC_DDS) {
|
2012-12-28 14:19:05 +00:00
|
|
|
ibuf->dds_data.data = (unsigned char *)dds.readData(ibuf->dds_data.size);
|
2012-10-25 12:54:16 +00:00
|
|
|
|
|
|
|
/* flip compressed texture */
|
|
|
|
FlipDXTCImage(dds.width(), dds.height(), dds.mipmapCount(), dds.fourCC(), ibuf->dds_data.data);
|
|
|
|
}
|
2012-06-30 04:34:34 +00:00
|
|
|
else {
|
|
|
|
ibuf->dds_data.data = NULL;
|
|
|
|
ibuf->dds_data.size = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-25 12:54:16 +00:00
|
|
|
/* flip uncompressed texture */
|
|
|
|
IMB_flipy(ibuf);
|
2007-06-25 19:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(ibuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|