From 3fe841597bd9e42dfcdfc9be4eefa661e7512265 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sat, 7 May 2011 20:53:49 +0000 Subject: Apply part of [#21590] .dds textures: fix for DXT1n format Submitted by Amorilia. DXT1 .dds textures with 1-bit alpha channel have their alpha channel imported in Blender. The patch also makes change to contact info for the patch submitter. I left the sync with upstream nvtt for another commit. --- source/blender/imbuf/intern/dds/BlockDXT.cpp | 2 +- source/blender/imbuf/intern/dds/BlockDXT.h | 2 +- source/blender/imbuf/intern/dds/Color.h | 2 +- source/blender/imbuf/intern/dds/ColorBlock.cpp | 2 +- source/blender/imbuf/intern/dds/ColorBlock.h | 2 +- source/blender/imbuf/intern/dds/Common.h | 2 +- .../blender/imbuf/intern/dds/DirectDrawSurface.cpp | 2 +- .../blender/imbuf/intern/dds/DirectDrawSurface.h | 2 +- source/blender/imbuf/intern/dds/Image.cpp | 2 +- source/blender/imbuf/intern/dds/Image.h | 2 +- source/blender/imbuf/intern/dds/PixelFormat.h | 2 +- source/blender/imbuf/intern/dds/Stream.cpp | 2 +- source/blender/imbuf/intern/dds/Stream.h | 2 +- source/blender/imbuf/intern/dds/dds_api.cpp | 24 ++++++++++++++-------- source/blender/imbuf/intern/dds/dds_api.h | 2 +- 15 files changed, 30 insertions(+), 22 deletions(-) (limited to 'source/blender/imbuf/intern') diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp index 2989361efe6..b634a4d938e 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.cpp +++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/BlockDXT.h b/source/blender/imbuf/intern/dds/BlockDXT.h index 7c5b9acffd2..6e9e555d963 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.h +++ b/source/blender/imbuf/intern/dds/BlockDXT.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/Color.h b/source/blender/imbuf/intern/dds/Color.h index 5efc259b795..42ed34daf76 100644 --- a/source/blender/imbuf/intern/dds/Color.h +++ b/source/blender/imbuf/intern/dds/Color.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp index 711d1b54cfa..3dcfa0cef43 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.cpp +++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/ColorBlock.h b/source/blender/imbuf/intern/dds/ColorBlock.h index dd40d21e8b3..47b08303a05 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.h +++ b/source/blender/imbuf/intern/dds/ColorBlock.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/Common.h b/source/blender/imbuf/intern/dds/Common.h index 25b743311d2..9cf1de3644a 100644 --- a/source/blender/imbuf/intern/dds/Common.h +++ b/source/blender/imbuf/intern/dds/Common.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp index ede82896554..b179432da4a 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.h b/source/blender/imbuf/intern/dds/DirectDrawSurface.h index cc04c50e795..4db621be3da 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.h +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/Image.cpp b/source/blender/imbuf/intern/dds/Image.cpp index a775a9125d2..9c34c4e7199 100644 --- a/source/blender/imbuf/intern/dds/Image.cpp +++ b/source/blender/imbuf/intern/dds/Image.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/Image.h b/source/blender/imbuf/intern/dds/Image.h index 88051410056..96e455fc75b 100644 --- a/source/blender/imbuf/intern/dds/Image.h +++ b/source/blender/imbuf/intern/dds/Image.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/PixelFormat.h b/source/blender/imbuf/intern/dds/PixelFormat.h index c483c525570..2602681d979 100644 --- a/source/blender/imbuf/intern/dds/PixelFormat.h +++ b/source/blender/imbuf/intern/dds/PixelFormat.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/Stream.cpp b/source/blender/imbuf/intern/dds/Stream.cpp index 88c5277e097..497109efd25 100644 --- a/source/blender/imbuf/intern/dds/Stream.cpp +++ b/source/blender/imbuf/intern/dds/Stream.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/Stream.h b/source/blender/imbuf/intern/dds/Stream.h index acc2c8bb176..ca081d331fe 100644 --- a/source/blender/imbuf/intern/dds/Stream.h +++ b/source/blender/imbuf/intern/dds/Stream.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp index a7b2934cafa..73ee3a2cb9c 100644 --- a/source/blender/imbuf/intern/dds/dds_api.cpp +++ b/source/blender/imbuf/intern/dds/dds_api.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ @@ -106,10 +106,21 @@ struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags) } /* convert DDS into ImBuf */ - // TODO use the image RGB or RGBA tag to determine the bits per pixel - if (dds.hasAlpha()) bits_per_pixel = 32; - else bits_per_pixel = 24; - ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0); + 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; + }; + }; + }; + ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0); if (ibuf == 0) return(0); /* memory allocation failed */ ibuf->ftype = DDS; @@ -120,9 +131,6 @@ struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags) if (ibuf->rect == 0) return(ibuf); rect = ibuf->rect; - dds.mipmap(&img, 0, 0); /* load first face, first mipmap */ - pixels = img.pixels(); - numpixels = dds.width() * dds.height(); cp[3] = 0xff; /* default alpha if alpha channel is not present */ for (unsigned int i = 0; i < numpixels; i++) { diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index cfc6910e71d..d78e4f31474 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Contributors: Amorilia (amorilia@gamebox.net) + * Contributors: Amorilia (amorilia@users.sourceforge.net) * * ***** END GPL LICENSE BLOCK ***** */ -- cgit v1.2.3