diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2011-05-08 00:53:49 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2011-05-08 00:53:49 +0400 |
commit | 3fe841597bd9e42dfcdfc9be4eefa661e7512265 (patch) | |
tree | 278fb691c4f1cfc23f1a0fe2059610dc74ef8fd2 /source/blender/imbuf/intern/dds/dds_api.cpp | |
parent | 471c28f91c489d40ae80561ce4d9629d2f152292 (diff) |
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.
Diffstat (limited to 'source/blender/imbuf/intern/dds/dds_api.cpp')
-rw-r--r-- | source/blender/imbuf/intern/dds/dds_api.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
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++) { |