Fixed issue that caused some 32-bit TGA files to be converted to B_RGB32 (no alpha) instead of B_RGBA32 (alpha)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5284 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
735e7442a8
commit
1cb6ca0473
@ -33,8 +33,8 @@
|
|||||||
#include "TGATranslator.h"
|
#include "TGATranslator.h"
|
||||||
#include "TGAView.h"
|
#include "TGAView.h"
|
||||||
#include "StreamBuffer.h"
|
#include "StreamBuffer.h"
|
||||||
#include <SupportDefs.h>
|
|
||||||
// for min()/max()
|
#define min(a,b) ((a < b) ? (a) : (b))
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
translation_format gInputFormats[] = {
|
||||||
@ -365,6 +365,23 @@ identify_bits_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8
|
||||||
|
tga_alphabits(TGAImageSpec &imagespec)
|
||||||
|
{
|
||||||
|
uint8 nalpha;
|
||||||
|
if (imagespec.depth == 32)
|
||||||
|
// Some programs that generate 32-bit TGA files
|
||||||
|
// have an alpha channel, but have an incorrect
|
||||||
|
// descriptor which says there are no alpha bits.
|
||||||
|
// This logic is so that the alpha data can be
|
||||||
|
// obtained from TGA files that lie.
|
||||||
|
nalpha = 8;
|
||||||
|
else
|
||||||
|
nalpha = imagespec.descriptor & TGA_DESC_ALPHABITS;
|
||||||
|
|
||||||
|
return nalpha;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// identify_tga_header
|
// identify_tga_header
|
||||||
//
|
//
|
||||||
@ -1789,8 +1806,7 @@ translate_from_tganm_to_bits(BPositionIO *inSource,
|
|||||||
bvflip = false;
|
bvflip = false;
|
||||||
else
|
else
|
||||||
bvflip = true;
|
bvflip = true;
|
||||||
uint8 nalpha = imagespec.descriptor & TGA_DESC_ALPHABITS;
|
uint8 nalpha = tga_alphabits(imagespec);
|
||||||
|
|
||||||
int32 bitsRowBytes = imagespec.width * 4;
|
int32 bitsRowBytes = imagespec.width * 4;
|
||||||
uint8 tgaBytesPerPixel = (imagespec.depth / 8) +
|
uint8 tgaBytesPerPixel = (imagespec.depth / 8) +
|
||||||
((imagespec.depth % 8) ? 1 : 0);
|
((imagespec.depth % 8) ? 1 : 0);
|
||||||
@ -1882,8 +1898,7 @@ translate_from_tganmrle_to_bits(BPositionIO *inSource,
|
|||||||
bvflip = false;
|
bvflip = false;
|
||||||
else
|
else
|
||||||
bvflip = true;
|
bvflip = true;
|
||||||
uint8 nalpha = imagespec.descriptor & TGA_DESC_ALPHABITS;
|
uint8 nalpha = tga_alphabits(imagespec);
|
||||||
|
|
||||||
int32 bitsRowBytes = imagespec.width * 4;
|
int32 bitsRowBytes = imagespec.width * 4;
|
||||||
uint8 tgaBytesPerPixel = (imagespec.depth / 8) +
|
uint8 tgaBytesPerPixel = (imagespec.depth / 8) +
|
||||||
((imagespec.depth % 8) ? 1 : 0);
|
((imagespec.depth % 8) ? 1 : 0);
|
||||||
@ -2398,7 +2413,7 @@ translate_from_tga(BPositionIO *inSource, ssize_t amtread, uint8 *read,
|
|||||||
bitsHeader.rowBytes = imagespec.width * 4;
|
bitsHeader.rowBytes = imagespec.width * 4;
|
||||||
if (fileheader.imagetype != TGA_NOCOMP_BW &&
|
if (fileheader.imagetype != TGA_NOCOMP_BW &&
|
||||||
fileheader.imagetype != TGA_RLE_BW &&
|
fileheader.imagetype != TGA_RLE_BW &&
|
||||||
imagespec.descriptor & TGA_DESC_ALPHABITS)
|
tga_alphabits(imagespec))
|
||||||
bitsHeader.colors = B_RGBA32;
|
bitsHeader.colors = B_RGBA32;
|
||||||
else
|
else
|
||||||
bitsHeader.colors = B_RGB32;
|
bitsHeader.colors = B_RGB32;
|
||||||
|
Loading…
Reference in New Issue
Block a user