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:
authorKent Mein <mein@cs.umn.edu>2007-10-12 20:09:59 +0400
committerKent Mein <mein@cs.umn.edu>2007-10-12 20:09:59 +0400
commit6fe98f19a95117633684b85073b4d90654e159fd (patch)
tree50d54508e6e4395442fb486d96cb7202a871ee5e /source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
parent3697e0852467a29223a59d2ad6a31a00cfbde529 (diff)
This is patch [#7483] imbuf support for uncompressed DDS images
provided by Amorilia NVIDIA updated the dds stuff so we get a nice new patch. Kent
Diffstat (limited to 'source/blender/imbuf/intern/dds/DirectDrawSurface.cpp')
-rw-r--r--source/blender/imbuf/intern/dds/DirectDrawSurface.cpp112
1 files changed, 104 insertions, 8 deletions
diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
index 6937840334d..c28f8b5b72d 100644
--- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
+++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
@@ -434,16 +434,15 @@ bool DirectDrawSurface::isSupported() const
return false;
}
}
- /*
else if (header.pf.flags & DDPF_RGB)
{
if (header.pf.bitcount == 24)
{
- return false;
+ return true;
}
else if (header.pf.bitcount == 32)
{
- return false;
+ return true;
}
else
{
@@ -451,7 +450,6 @@ bool DirectDrawSurface::isSupported() const
return false;
}
}
- */
else
{
return false;
@@ -500,8 +498,18 @@ unsigned int DirectDrawSurface::depth() const
bool DirectDrawSurface::hasAlpha() const
{
- if (header.pf.fourcc == FOURCC_DXT1) return false;
- else return true;
+ if ((header.pf.flags & DDPF_RGB) && (header.pf.amask == 0))
+ {
+ return false;
+ }
+ else if (header.pf.fourcc == FOURCC_DXT1)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
}
bool DirectDrawSurface::isTexture2D() const
@@ -545,10 +553,98 @@ void DirectDrawSurface::mipmap(Image * img, unsigned int face, unsigned int mipm
}
}
+/* helper function for readLinearImage */
+void maskShiftAndSize(unsigned int mask, unsigned int * shift, unsigned int * size)
+{
+ if (!mask)
+ {
+ *shift = 0;
+ *size = 0;
+ return;
+ }
+
+ *shift = 0;
+ while((mask & 1) == 0) {
+ ++(*shift);
+ mask >>= 1;
+ }
+
+ *size = 0;
+ while((mask & 1) == 1) {
+ ++(*size);
+ mask >>= 1;
+ }
+}
+
+/* helper function for readLinearImage */
+unsigned int convert(unsigned int c, unsigned int inbits, unsigned int outbits)
+{
+ if (inbits == 0) {
+ return 0;
+ }
+ else if (inbits == outbits)
+ {
+ return c;
+ }
+ else if (inbits > outbits)
+ {
+ // truncate
+ return c >> (inbits - outbits);
+ }
+ else
+ {
+ // bitexpand
+ return (c << (outbits - inbits)) | convert(c, inbits, outbits - inbits);
+ }
+}
+
void DirectDrawSurface::readLinearImage(Image * img)
{
- // @@ Read linear RGB images.
- printf("DDS: linear RGB images not supported\n");
+ const unsigned int w = img->width();
+ const unsigned int h = img->height();
+
+ unsigned int rshift, rsize;
+ maskShiftAndSize(header.pf.rmask, &rshift, &rsize);
+
+ unsigned int gshift, gsize;
+ maskShiftAndSize(header.pf.gmask, &gshift, &gsize);
+
+ unsigned int bshift, bsize;
+ maskShiftAndSize(header.pf.bmask, &bshift, &bsize);
+
+ unsigned int ashift, asize;
+ maskShiftAndSize(header.pf.amask, &ashift, &asize);
+
+ unsigned int byteCount = (header.pf.bitcount + 7) / 8;
+ if (byteCount > 4)
+ {
+ /* just in case... we could have segfaults later on if byteCount > 4 */
+ printf("DDS: bitcount too large (file corrupt?)");
+ return;
+ }
+
+ if (header.pf.amask != 0)
+ {
+ img->setFormat(Image::Format_ARGB);
+ }
+
+ // Read linear RGB images.
+ for (unsigned int y = 0; y < h; y++)
+ {
+ for (unsigned int x = 0; x < w; x++)
+ {
+ unsigned int c = 0;
+ mem_read(stream, (unsigned char *)(&c), byteCount);
+
+ Color32 pixel(0, 0, 0, 0xFF);
+ pixel.r = convert(c >> rshift, rsize, 8);
+ pixel.g = convert(c >> gshift, gsize, 8);
+ pixel.b = convert(c >> bshift, bsize, 8);
+ pixel.a = convert(c >> ashift, asize, 8);
+
+ img->pixel(x, y) = pixel;
+ }
+ }
}
void DirectDrawSurface::readBlockImage(Image * img)