minor update
This commit is contained in:
@@ -81,7 +81,7 @@ int LoadTGA(const char *filename,
|
||||
default:
|
||||
std::abort();
|
||||
}
|
||||
*dst_bytes++ = color.toRGBA();
|
||||
*dst_bytes++ = color;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -108,6 +108,11 @@ int SaveTGA(const char *filename,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bpp < 2 || bpp > 4) {
|
||||
std::cerr << "unsupported pixel stride: " << bpp << "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tga_header_t header;
|
||||
header.idlength = 0;
|
||||
header.colormaptype = 0; // no palette
|
||||
@@ -131,20 +136,7 @@ int SaveTGA(const char *filename,
|
||||
for (uint32_t y = 0; y < height; ++y) {
|
||||
const uint8_t* pixel_row = pixel_bytes;
|
||||
for (uint32_t x = 0; x < width; ++x) {
|
||||
// swap R/B color channels
|
||||
if (bpp == 4) {
|
||||
ofs.write((const char*)pixel_row + 2, 1);
|
||||
ofs.write((const char*)pixel_row + 1, 1);
|
||||
ofs.write((const char*)pixel_row + 0, 1);
|
||||
ofs.write((const char*)pixel_row + 3, 1);
|
||||
} else if (bpp == 3) {
|
||||
ofs.write((const char*)pixel_row + 2, 1);
|
||||
ofs.write((const char*)pixel_row + 1, 1);
|
||||
ofs.write((const char*)pixel_row + 0, 1);
|
||||
} else{
|
||||
std::cerr << "unsupported TGA bitsperpixel!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
ofs.write((const char*)pixel_row, bpp);
|
||||
pixel_row += bpp;
|
||||
}
|
||||
pixel_bytes -= pitch;
|
||||
|
||||
Reference in New Issue
Block a user