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/editors/space_image/image_ops.c | 3 +++ 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 +- source/blender/makesrna/intern/rna_nodetree.c | 3 +++ source/blender/makesrna/intern/rna_scene.c | 4 +++- 18 files changed, 39 insertions(+), 23 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 7d4aaf0c70e..13e855f60b1 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -645,6 +645,9 @@ static const EnumPropertyItem image_file_type_items[] = { {R_TARGA, "TARGA", 0, "Targa", ""}, {R_RAWTGA, "TARGA RAW", 0, "Targa Raw", ""}, {R_PNG, "PNG", 0, "PNG", ""}, +#ifdef WITH_DDS + {R_DDS, "DDS", 0, "DirectDraw Surface", ""}, +#endif {R_BMP, "BMP", 0, "BMP", ""}, {R_JPEG90, "JPEG", 0, "Jpeg", ""}, #ifdef WITH_OPENJPEG 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 ***** */ diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 3c26c18f17f..d55534bb1b5 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1323,6 +1323,9 @@ static void def_cmp_output_file(StructRNA *srna) {R_TARGA, "TARGA", 0, "Targa", ""}, {R_RAWTGA, "RAW_TARGA", 0, "Targa Raw", ""}, {R_PNG, "PNG", 0, "PNG", ""}, +#ifdef WITH_DDS + {R_DDS, "DDS", 0, "DirectDraw Surface", ""}, +#endif {R_BMP, "BMP", 0, "BMP", ""}, {R_JPEG90, "JPEG", 0, "JPEG", ""}, {R_IRIS, "IRIS", 0, "IRIS", ""}, diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index e06e71d6a0e..1497f5a4405 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -101,7 +101,9 @@ EnumPropertyItem snap_element_items[] = { EnumPropertyItem image_type_items[] = { {0, "", 0, "Image", NULL}, {R_BMP, "BMP", ICON_FILE_IMAGE, "BMP", ""}, - //{R_DDS, "DDS", ICON_FILE_IMAGE, "DDS", ""}, // XXX not yet implemented +#ifdef WITH_DDS + {R_DDS, "DDS", ICON_FILE_IMAGE, "DDS", ""}, +#endif {R_IRIS, "IRIS", ICON_FILE_IMAGE, "Iris", ""}, {R_PNG, "PNG", ICON_FILE_IMAGE, "PNG", ""}, {R_JPEG90, "JPEG", ICON_FILE_IMAGE, "JPEG", ""}, -- cgit v1.2.3