mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
small dds optimization
This commit is contained in:
parent
cd69554707
commit
481e53fd77
@ -3652,16 +3652,8 @@ read_dds_level_bgr8(Texture *tex, const DDSHeader &header,
|
|||||||
PTA_uchar image = PTA_uchar::empty_array(size);
|
PTA_uchar image = PTA_uchar::empty_array(size);
|
||||||
for (int y = y_size - 1; y >= 0; --y) {
|
for (int y = y_size - 1; y >= 0; --y) {
|
||||||
unsigned char *p = image.p() + y * row_bytes;
|
unsigned char *p = image.p() + y * row_bytes;
|
||||||
for (int x = 0; x < x_size; ++x) {
|
nassertr(p + row_bytes <= image.p() + size, false);
|
||||||
unsigned int b = (unsigned char)in.get();
|
in.read((char *)p, row_bytes);
|
||||||
unsigned int g = (unsigned char)in.get();
|
|
||||||
unsigned int r = (unsigned char)in.get();
|
|
||||||
|
|
||||||
store_unscaled_byte(p, b);
|
|
||||||
store_unscaled_byte(p, g);
|
|
||||||
store_unscaled_byte(p, r);
|
|
||||||
}
|
|
||||||
nassertr(p <= image.p() + size, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tex->set_ram_mipmap_image(n, image);
|
tex->set_ram_mipmap_image(n, image);
|
||||||
@ -3686,14 +3678,15 @@ read_dds_level_rgb8(Texture *tex, const DDSHeader &header,
|
|||||||
PTA_uchar image = PTA_uchar::empty_array(size);
|
PTA_uchar image = PTA_uchar::empty_array(size);
|
||||||
for (int y = y_size - 1; y >= 0; --y) {
|
for (int y = y_size - 1; y >= 0; --y) {
|
||||||
unsigned char *p = image.p() + y * row_bytes;
|
unsigned char *p = image.p() + y * row_bytes;
|
||||||
for (int x = 0; x < x_size; ++x) {
|
nassertr(p + row_bytes <= image.p() + size, false);
|
||||||
unsigned int r = (unsigned char)in.get();
|
in.read((char *)p, row_bytes);
|
||||||
unsigned int g = (unsigned char)in.get();
|
|
||||||
unsigned int b = (unsigned char)in.get();
|
|
||||||
|
|
||||||
store_unscaled_byte(p, b);
|
// Now reverse the r, g, b triples.
|
||||||
store_unscaled_byte(p, g);
|
for (int x = 0; x < x_size; ++x) {
|
||||||
store_unscaled_byte(p, r);
|
unsigned char r = p[0];
|
||||||
|
p[0] = p[2];
|
||||||
|
p[2] = r;
|
||||||
|
p += 3;
|
||||||
}
|
}
|
||||||
nassertr(p <= image.p() + size, false);
|
nassertr(p <= image.p() + size, false);
|
||||||
}
|
}
|
||||||
@ -3720,18 +3713,22 @@ read_dds_level_abgr8(Texture *tex, const DDSHeader &header,
|
|||||||
PTA_uchar image = PTA_uchar::empty_array(size);
|
PTA_uchar image = PTA_uchar::empty_array(size);
|
||||||
for (int y = y_size - 1; y >= 0; --y) {
|
for (int y = y_size - 1; y >= 0; --y) {
|
||||||
unsigned char *p = image.p() + y * row_bytes;
|
unsigned char *p = image.p() + y * row_bytes;
|
||||||
for (int x = 0; x < x_size; ++x) {
|
in.read((char *)p, row_bytes);
|
||||||
unsigned int r = (unsigned char)in.get();
|
|
||||||
unsigned int g = (unsigned char)in.get();
|
|
||||||
unsigned int b = (unsigned char)in.get();
|
|
||||||
unsigned int a = (unsigned char)in.get();
|
|
||||||
|
|
||||||
store_unscaled_byte(p, b);
|
PN_uint32 *pw = (PN_uint32 *)p;
|
||||||
store_unscaled_byte(p, g);
|
for (int x = 0; x < x_size; ++x) {
|
||||||
store_unscaled_byte(p, r);
|
PN_uint32 w = *pw;
|
||||||
store_unscaled_byte(p, a);
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
// bigendian: convert R, G, B, A to B, G, R, A.
|
||||||
|
w = ((w & 0xff00) << 16) | ((w & 0xff000000U) >> 16) | (w & 0xff00ff);
|
||||||
|
#else
|
||||||
|
// littendian: convert A, B, G, R to to A, R, G, B.
|
||||||
|
w = ((w & 0xff) << 16) | ((w & 0xff0000) >> 16) | (w & 0xff00ff00U);
|
||||||
|
#endif
|
||||||
|
*pw = w;
|
||||||
|
++pw;
|
||||||
}
|
}
|
||||||
nassertr(p <= image.p() + size, false);
|
nassertr((unsigned char *)pw <= image.p() + size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
tex->set_ram_mipmap_image(n, image);
|
tex->set_ram_mipmap_image(n, image);
|
||||||
@ -3756,18 +3753,8 @@ read_dds_level_rgba8(Texture *tex, const DDSHeader &header,
|
|||||||
PTA_uchar image = PTA_uchar::empty_array(size);
|
PTA_uchar image = PTA_uchar::empty_array(size);
|
||||||
for (int y = y_size - 1; y >= 0; --y) {
|
for (int y = y_size - 1; y >= 0; --y) {
|
||||||
unsigned char *p = image.p() + y * row_bytes;
|
unsigned char *p = image.p() + y * row_bytes;
|
||||||
for (int x = 0; x < x_size; ++x) {
|
nassertr(p + row_bytes <= image.p() + size, false);
|
||||||
unsigned int b = (unsigned char)in.get();
|
in.read((char *)p, row_bytes);
|
||||||
unsigned int g = (unsigned char)in.get();
|
|
||||||
unsigned int r = (unsigned char)in.get();
|
|
||||||
unsigned int a = (unsigned char)in.get();
|
|
||||||
|
|
||||||
store_unscaled_byte(p, b);
|
|
||||||
store_unscaled_byte(p, g);
|
|
||||||
store_unscaled_byte(p, r);
|
|
||||||
store_unscaled_byte(p, a);
|
|
||||||
}
|
|
||||||
nassertr(p <= image.p() + size, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tex->set_ram_mipmap_image(n, image);
|
tex->set_ram_mipmap_image(n, image);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user