Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2013-10-09 01:17:24 +0400
committerDalai Felinto <dfelinto@gmail.com>2013-10-09 01:17:24 +0400
commit4abb8fde95260e692b3cd5b5b2f8bcd1d1f3be3b (patch)
tree9c3d68aa7abd18ddfef5b3af643b8a7556903e18 /source/blender/imbuf/intern/oiio
parent590f58d45583f36522ffbcebd68b4a6c921bebeb (diff)
Photoshop PSD support
We now support the combined layer of Photoshop files (stored as layer 0 in the file). This way users can keep their files as multilayer PSD and Blender always handle them as flat images. For perfect alpha this requires an OpenImageIO update: https://github.com/OpenImageIO/oiio/commit/342cc2633ff590a3bb278481c61ae798c7148361 Photoshop sample files: https://github.com/OpenImageIO/oiio-images Brecht has some pending fixes to push for OIIO as well, so we may as well wait to update our libraries. What works: =========== * 8bit images (with or without alpha) * 16bits images (alpha discarded) * Photoshop files saved with 'Maximum Compatibility' * Cycles, Blender internal, BGE (and player) Known limitations (due to OIIO dependency): ========================= * Images with less than 4 channels show a wrong thumbnail (bug may be in OIIO) * Packed images are not supported * We do not write PSD files. Note: old Blenders have support for PSD via Quicktime library. But due to license issues this was discontinued. Many thanks for Brecht van Lommel for reviewing the patch, suggesting multiple improvements and to help solving the alpha issue.
Diffstat (limited to 'source/blender/imbuf/intern/oiio')
-rw-r--r--source/blender/imbuf/intern/oiio/CMakeLists.txt54
-rw-r--r--source/blender/imbuf/intern/oiio/SConscript47
-rw-r--r--source/blender/imbuf/intern/oiio/openimageio_api.cpp257
-rw-r--r--source/blender/imbuf/intern/oiio/openimageio_api.h53
-rw-r--r--source/blender/imbuf/intern/oiio/openimageio_stub.cpp35
5 files changed, 446 insertions, 0 deletions
diff --git a/source/blender/imbuf/intern/oiio/CMakeLists.txt b/source/blender/imbuf/intern/oiio/CMakeLists.txt
new file mode 100644
index 00000000000..f5ee5eb6589
--- /dev/null
+++ b/source/blender/imbuf/intern/oiio/CMakeLists.txt
@@ -0,0 +1,54 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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
+# of the License, or (at your option) any later version.
+#
+# 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,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2013, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s):
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ ..
+ ../..
+ ../../../blenkernel
+ ../../../blenlib
+ ../../../makesdna
+ ../../../../../intern/guardedalloc
+ ../../../../../intern/utfconv
+)
+
+set(INC_SYS
+
+)
+
+set(SRC
+ openimageio_api.h
+
+ openimageio_api.cpp
+)
+
+if(WITH_IMAGE_PSD)
+ list(APPEND INC_SYS
+ ${OPENIMAGEIO_INCLUDE_DIRS}
+ )
+ add_definitions(-DWITH_PSD)
+endif()
+
+blender_add_lib(bf_imbuf_openimageio "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/imbuf/intern/oiio/SConscript b/source/blender/imbuf/intern/oiio/SConscript
new file mode 100644
index 00000000000..124f8fbdfce
--- /dev/null
+++ b/source/blender/imbuf/intern/oiio/SConscript
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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
+# of the License, or (at your option) any later version.
+#
+# 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,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2013, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s):
+#
+# ***** END GPL LICENSE BLOCK *****
+
+Import ('env')
+
+source_files = ['openimageio_api.cpp']
+
+incs = ['.',
+ '../../../blenkernel',
+ '../../',
+ '..',
+ '../../../blenlib',
+ 'intern/include',
+ '#/intern/guardedalloc',
+ '../../../makesdna',
+ '#/intern/utfconv']
+
+defs = ['WITH_PSD']
+
+if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
+ incs.append(env['BF_PTHREADS_INC'])
+
+env.BlenderLib ('bf_imbuf_openimageio', source_files, incs, defs, libtype=['core','player'], priority = [225,180])
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
new file mode 100644
index 00000000000..3253cf9da08
--- /dev/null
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -0,0 +1,257 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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
+ * of the License, or (at your option) any later version.
+ *
+ * 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Dalai Felinto and Brecht van Lommel
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/imbuf/intern/oiio/openimageio_api.h
+ * \ingroup openimageio
+ */
+
+#include <set>
+
+#include <openimageio_api.h>
+#include <OpenImageIO/imageio.h>
+
+OIIO_NAMESPACE_USING
+
+#if defined (WIN32) && !defined(FREE_WINDOWS)
+#include "utfconv.h"
+#endif
+
+extern "C"
+{
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+#include "IMB_allocimbuf.h"
+#include "IMB_colormanagement.h"
+#include "IMB_colormanagement_intern.h"
+}
+
+using namespace std;
+
+typedef unsigned char uchar;
+
+template <class T, class Q>
+static void
+fill_all_channels(T * pixels, int width, int height, int components, Q alpha)
+{
+ if(components == 2) {
+ for(int i = width*height-1; i >= 0; i--) {
+ pixels[i*4+3] = pixels[i*2+1];
+ pixels[i*4+2] = pixels[i*2+0];
+ pixels[i*4+1] = pixels[i*2+0];
+ pixels[i*4+0] = pixels[i*2+0];
+ }
+ }
+ else if(components == 3) {
+ for(int i = width*height-1; i >= 0; i--) {
+ pixels[i*4+3] = alpha;
+ pixels[i*4+2] = pixels[i*3+2];
+ pixels[i*4+1] = pixels[i*3+1];
+ pixels[i*4+0] = pixels[i*3+0];
+
+ }
+ }
+ else if(components == 1) {
+ for(int i = width*height-1; i >= 0; i--) {
+ pixels[i*4+3] = alpha;
+ pixels[i*4+2] = pixels[i];
+ pixels[i*4+1] = pixels[i];
+ pixels[i*4+0] = pixels[i];
+ }
+ }
+
+}
+
+static ImBuf *imb_oiio_load_image(ImageInput *in, int width, int height, int components, int flags, bool is_alpha)
+{
+ ImBuf *ibuf;
+ int scanlinesize = width*components*sizeof(uchar);
+
+ /* allocate the memory for the image */
+ ibuf = IMB_allocImBuf(width, height, is_alpha ? 32 : 24, flags|IB_rect);
+
+ try
+ {
+ in->read_image(TypeDesc::UINT8,
+ (uchar *)ibuf->rect + (height-1) * scanlinesize,
+ AutoStride,
+ -scanlinesize,
+ AutoStride);
+ }
+ catch (const std::exception &exc)
+ {
+ std::cerr << exc.what() << std::endl;
+ if (ibuf) IMB_freeImBuf(ibuf);
+
+ return NULL;
+ }
+
+ /* ImBuf always needs 4 channels */
+ fill_all_channels((uchar *)ibuf->rect, width, height, components, 0xFF);
+
+ return ibuf;
+}
+
+static ImBuf *imb_oiio_load_image_float(ImageInput *in, int width, int height, int components, int flags, bool is_alpha)
+{
+ ImBuf *ibuf;
+ int scanlinesize = width*components*sizeof(float);
+
+ /* allocate the memory for the image */
+ ibuf = IMB_allocImBuf(width, height, is_alpha ? 32 : 24, flags|IB_rectfloat);
+
+ try
+ {
+ in->read_image(TypeDesc::FLOAT,
+ (uchar *)ibuf->rect_float + (height-1) * scanlinesize,
+ AutoStride,
+ -scanlinesize,
+ AutoStride);
+ }
+ catch (const std::exception &exc)
+ {
+ std::cerr << exc.what() << std::endl;
+ if (ibuf) IMB_freeImBuf(ibuf);
+
+ return NULL;
+ }
+
+ /* ImBuf always needs 4 channels */
+ fill_all_channels((float *)ibuf->rect_float, width, height, components, 1.0f);
+
+ /* note: Photoshop 16 bit files never has alpha with it, so no need to handle associated/unassociated alpha */
+ return ibuf;
+}
+
+extern "C"
+{
+
+int imb_is_a_photoshop(const char *filename)
+{
+ const char *photoshop_extension[] = {
+ ".psd",
+ ".pdd",
+ ".psb",
+ NULL
+ };
+
+ return BLI_testextensie_array(filename, photoshop_extension);
+}
+
+int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags)
+{
+ if (flags & IB_mem) {
+ printf("Photoshop PSD-save: Create PSD in memory CURRENTLY NOT SUPPORTED !\n");
+ imb_addencodedbufferImBuf(ibuf);
+ ibuf->encodedsize = 0;
+ return(0);
+ }
+
+ return(0);
+}
+
+struct ImBuf *imb_load_photoshop (const char *filename, int flags, char colorspace[IM_MAX_SPACE])
+{
+ ImageInput *in = NULL;
+ struct ImBuf *ibuf = NULL;
+ int width, height, components;
+ bool is_float, is_alpha;
+ TypeDesc typedesc;
+ int basesize;
+
+ /* load image from file through OIIO */
+ if (imb_is_a_photoshop(filename) == 0) return (NULL);
+
+ colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
+
+ in = ImageInput::create(filename);
+ if (!in) return NULL;
+
+ ImageSpec spec, config;
+ config.attribute ("oiio:UnassociatedAlpha", (int) 1);
+
+ if(!in->open(filename, spec, config)) {
+ delete in;
+ return NULL;
+ }
+
+ string ics = spec.get_string_attribute("oiio:ColorSpace");
+ BLI_strncpy(colorspace, ics.c_str(), IM_MAX_SPACE);
+
+ width = spec.width;
+ height = spec.height;
+ components = spec.nchannels;
+ is_alpha = spec.alpha_channel != -1;
+ basesize = spec.format.basesize();
+ is_float = basesize > 1;
+
+ /* we only handle certain number of components */
+ if(!(components >= 1 && components <= 4)) {
+ if(in) {
+ in->close();
+ delete in;
+ }
+ return NULL;
+ }
+
+ if (is_float)
+ ibuf = imb_oiio_load_image_float(in, width, height, components, flags, is_alpha);
+ else
+ ibuf = imb_oiio_load_image(in, width, height, components, flags, is_alpha);
+
+ if (in) {
+ in->close();
+ delete in;
+ }
+
+ if (!ibuf)
+ return NULL;
+
+ /* ImBuf always needs 4 channels */
+ ibuf->ftype = PSD;
+ ibuf->channels = 4;
+ ibuf->planes = (3 + (is_alpha ? 1 : 0)) * 4 << basesize;
+
+ try
+ {
+ return(ibuf);
+ }
+ catch (const std::exception &exc)
+ {
+ std::cerr << exc.what() << std::endl;
+ if (ibuf) IMB_freeImBuf(ibuf);
+
+ return (0);
+ }
+}
+
+} // export "C"
+
+
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h
new file mode 100644
index 00000000000..ce96e277f7f
--- /dev/null
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.h
@@ -0,0 +1,53 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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
+ * of the License, or (at your option) any later version.
+ *
+ * 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/imbuf/intern/oiio/openimageio_api.h
+ * \ingroup openimageio
+ */
+
+
+#ifndef __OIIO_API_H__
+#define __OIIO_API_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+int imb_is_a_photoshop (const char *name);
+
+int imb_save_photoshop (struct ImBuf *ibuf, const char *name, int flags);
+
+struct ImBuf *imb_load_photoshop (const char *name, int flags, char *colorspace);
+
+#ifdef __cplusplus
+}
+
+#endif
+
+#endif /* __OIIO_API_H */
diff --git a/source/blender/imbuf/intern/oiio/openimageio_stub.cpp b/source/blender/imbuf/intern/oiio/openimageio_stub.cpp
new file mode 100644
index 00000000000..b57de0b24a7
--- /dev/null
+++ b/source/blender/imbuf/intern/oiio/openimageio_stub.cpp
@@ -0,0 +1,35 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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
+ * of the License, or (at your option) any later version.
+ *
+ * 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+
+/** \file blender/imbuf/intern/oiio/openimageio_api.h
+ * \ingroup openimageio
+ */
+
+#include "openimageio_api.h"
+
+#endif