mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
more general rgb fix
This commit is contained in:
parent
68fd96555c
commit
e214d8c9ef
@ -188,7 +188,8 @@ read_image(const string &image_filename, bool image_filename_temp,
|
|||||||
|
|
||||||
row_stride = width * num_channels;
|
row_stride = width * num_channels;
|
||||||
|
|
||||||
// We'll pad row_stride out to word alignment. Windows requires this.
|
// We'll pad row_stride out to word alignment, in case someone
|
||||||
|
// requires this.
|
||||||
row_stride = 4 * ((row_stride + 3) / 4);
|
row_stride = 4 * ((row_stride + 3) / 4);
|
||||||
|
|
||||||
size_t buffer_size = height * row_stride;
|
size_t buffer_size = height * row_stride;
|
||||||
|
@ -467,19 +467,38 @@ update_image_filename(const string &image_filename, bool image_filename_temp) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t data_length = data.length();
|
// Massage the data into Windows' conventions.
|
||||||
char *new_data = new char[data_length];
|
int new_row_stride = (_bitmap_width * 3);
|
||||||
memcpy(new_data, data.data(), data_length);
|
// DWORD-pad the row.
|
||||||
|
new_row_stride = 4 * ((new_row_stride + 3) / 4);
|
||||||
|
|
||||||
|
int new_data_length = new_row_stride * _bitmap_height;
|
||||||
|
char *new_data = new char[new_data_length];
|
||||||
|
|
||||||
if (num_channels == 3) {
|
if (num_channels == 3) {
|
||||||
// We have to reverse the order of the RGB channels: libjpeg and
|
// We have to reverse the order of the RGB channels: libjpeg and
|
||||||
// Windows follow an opposite convention.
|
// Windows follow an opposite convention.
|
||||||
for (int yi = 0; yi < _bitmap_height; ++yi) {
|
for (int yi = 0; yi < _bitmap_height; ++yi) {
|
||||||
char *dp = new_data + yi * row_stride;
|
const char *sp = data.data() + yi * row_stride;
|
||||||
|
char *dp = new_data + yi * new_row_stride;
|
||||||
for (int xi = 0; xi < _bitmap_width; ++xi) {
|
for (int xi = 0; xi < _bitmap_width; ++xi) {
|
||||||
char b = dp[0];
|
dp[0] = sp[2];
|
||||||
dp[0] = dp[2];
|
dp[1] = sp[1];
|
||||||
dp[2] = b;
|
dp[2] = sp[0];
|
||||||
|
sp += num_channels;
|
||||||
|
dp += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (num_channels == 1) {
|
||||||
|
// A grayscale image. Replicate out the channels.
|
||||||
|
for (int yi = 0; yi < _bitmap_height; ++yi) {
|
||||||
|
const char *sp = data.data() + yi * row_stride;
|
||||||
|
char *dp = new_data + yi * new_row_stride;
|
||||||
|
for (int xi = 0; xi < _bitmap_width; ++xi) {
|
||||||
|
dp[0] = sp[0];
|
||||||
|
dp[1] = sp[0];
|
||||||
|
dp[2] = sp[0];
|
||||||
|
sp += num_channels;
|
||||||
dp += 3;
|
dp += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,7 +510,7 @@ update_image_filename(const string &image_filename, bool image_filename_temp) {
|
|||||||
bmih.biWidth = _bitmap_width;
|
bmih.biWidth = _bitmap_width;
|
||||||
bmih.biHeight = -_bitmap_height;
|
bmih.biHeight = -_bitmap_height;
|
||||||
bmih.biPlanes = 1;
|
bmih.biPlanes = 1;
|
||||||
bmih.biBitCount = 8 * num_channels;
|
bmih.biBitCount = 24;
|
||||||
bmih.biCompression = BI_RGB;
|
bmih.biCompression = BI_RGB;
|
||||||
bmih.biSizeImage = 0;
|
bmih.biSizeImage = 0;
|
||||||
bmih.biXPelsPerMeter = 0;
|
bmih.biXPelsPerMeter = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user