Made local variables actually local.
Both JPEGTranslator and JPEG200Translator were "exporting" gSettings symbol, which when loaded within a app (like Paladin) exporting the same global symbol was leading to a symbol resolution error. See #7114 for details. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40245 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -25,7 +25,7 @@ using std::min;
|
|||||||
#define ERROR(x)
|
#define ERROR(x)
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -45,7 +45,7 @@ translation_format gInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -65,11 +65,16 @@ translation_format gOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
TranSetting gDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// make_nth_translator
|
// make_nth_translator
|
||||||
//
|
//
|
||||||
@@ -118,10 +123,10 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
BMPTranslator::BMPTranslator()
|
BMPTranslator::BMPTranslator()
|
||||||
: BaseTranslator("BMP images", "BMP image translator",
|
: BaseTranslator("BMP images", "BMP image translator",
|
||||||
BMP_TRANSLATOR_VERSION,
|
BMP_TRANSLATOR_VERSION,
|
||||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
sInputFormats, kNumInputFormats,
|
||||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"BMPTranslator_Settings",
|
"BMPTranslator_Settings",
|
||||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_BITMAP, B_BMP_FORMAT)
|
B_TRANSLATOR_BITMAP, B_BMP_FORMAT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -148,7 +153,7 @@ BMPTranslator::~BMPTranslator()
|
|||||||
//
|
//
|
||||||
// Returns number of bytes of padding required at the end of
|
// Returns number of bytes of padding required at the end of
|
||||||
// the row by the BMP format
|
// the row by the BMP format
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Preconditions: If bitsperpixel is zero, a division by zero
|
// Preconditions: If bitsperpixel is zero, a division by zero
|
||||||
// will occur, which is bad
|
// will occur, which is bad
|
||||||
@@ -159,13 +164,13 @@ BMPTranslator::~BMPTranslator()
|
|||||||
//
|
//
|
||||||
// Postconditions:
|
// Postconditions:
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
int32
|
int32
|
||||||
get_padding(uint32 width, uint16 bitsperpixel)
|
get_padding(uint32 width, uint16 bitsperpixel)
|
||||||
{
|
{
|
||||||
int32 padding = 0;
|
int32 padding = 0;
|
||||||
|
|
||||||
if (bitsperpixel > 8) {
|
if (bitsperpixel > 8) {
|
||||||
uint8 bytesPerPixel = bitsperpixel / 8;
|
uint8 bytesPerPixel = bitsperpixel / 8;
|
||||||
padding = (width * bytesPerPixel) % 4;
|
padding = (width * bytesPerPixel) % 4;
|
||||||
@@ -178,10 +183,10 @@ get_padding(uint32 width, uint16 bitsperpixel)
|
|||||||
(width % pixelsPerByte)) /
|
(width % pixelsPerByte)) /
|
||||||
pixelsPerByte) % 4;
|
pixelsPerByte) % 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (padding)
|
if (padding)
|
||||||
padding = 4 - padding;
|
padding = 4 - padding;
|
||||||
|
|
||||||
return padding;
|
return padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +195,7 @@ get_padding(uint32 width, uint16 bitsperpixel)
|
|||||||
//
|
//
|
||||||
// Returns number of bytes required to store a row of BMP pixels
|
// Returns number of bytes required to store a row of BMP pixels
|
||||||
// with a width of width and a bit depth of bitsperpixel.
|
// with a width of width and a bit depth of bitsperpixel.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Preconditions: If bitsperpixel is zero, a division by zero
|
// Preconditions: If bitsperpixel is zero, a division by zero
|
||||||
// will occur, which is bad
|
// will occur, which is bad
|
||||||
@@ -201,14 +206,14 @@ get_padding(uint32 width, uint16 bitsperpixel)
|
|||||||
//
|
//
|
||||||
// Postconditions:
|
// Postconditions:
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
int32
|
int32
|
||||||
get_rowbytes(uint32 width, uint16 bitsperpixel)
|
get_rowbytes(uint32 width, uint16 bitsperpixel)
|
||||||
{
|
{
|
||||||
int32 rowbytes = 0;
|
int32 rowbytes = 0;
|
||||||
int32 padding = get_padding(width, bitsperpixel);
|
int32 padding = get_padding(width, bitsperpixel);
|
||||||
|
|
||||||
if (bitsperpixel > 8) {
|
if (bitsperpixel > 8) {
|
||||||
uint8 bytesPerPixel = bitsperpixel / 8;
|
uint8 bytesPerPixel = bitsperpixel / 8;
|
||||||
rowbytes = (width * bytesPerPixel) + padding;
|
rowbytes = (width * bytesPerPixel) + padding;
|
||||||
@@ -217,7 +222,7 @@ get_rowbytes(uint32 width, uint16 bitsperpixel)
|
|||||||
rowbytes = (width / pixelsPerByte) +
|
rowbytes = (width / pixelsPerByte) +
|
||||||
((width % pixelsPerByte) ? 1 : 0) + padding;
|
((width % pixelsPerByte) ? 1 : 0) + padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowbytes;
|
return rowbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,14 +283,14 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
ssize_t size = 14;
|
ssize_t size = 14;
|
||||||
if (inSource->Read(buf, size) != size)
|
if (inSource->Read(buf, size) != size)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// check BMP magic number
|
// check BMP magic number
|
||||||
const uint16 kBmpMagic = B_HOST_TO_LENDIAN_INT16('MB');
|
const uint16 kBmpMagic = B_HOST_TO_LENDIAN_INT16('MB');
|
||||||
uint16 sourceMagic;
|
uint16 sourceMagic;
|
||||||
memcpy(&sourceMagic, buf, sizeof(uint16));
|
memcpy(&sourceMagic, buf, sizeof(uint16));
|
||||||
if (sourceMagic != kBmpMagic)
|
if (sourceMagic != kBmpMagic)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// convert fileHeader to host byte order
|
// convert fileHeader to host byte order
|
||||||
memcpy(&fileHeader.magic, buf, 2);
|
memcpy(&fileHeader.magic, buf, 2);
|
||||||
memcpy(&fileHeader.fileSize, buf + 2, 4);
|
memcpy(&fileHeader.fileSize, buf + 2, 4);
|
||||||
@@ -301,32 +306,32 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
|
|
||||||
if (fileHeader.reserved != 0)
|
if (fileHeader.reserved != 0)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
uint32 headersize = 0;
|
uint32 headersize = 0;
|
||||||
if (inSource->Read(&headersize, 4) != 4)
|
if (inSource->Read(&headersize, 4) != 4)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
if (swap_data(B_UINT32_TYPE, &headersize, 4,
|
if (swap_data(B_UINT32_TYPE, &headersize, 4,
|
||||||
B_SWAP_LENDIAN_TO_HOST) != B_OK)
|
B_SWAP_LENDIAN_TO_HOST) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (headersize == sizeof(MSInfoHeader)) {
|
if (headersize == sizeof(MSInfoHeader)) {
|
||||||
// MS format
|
// MS format
|
||||||
|
|
||||||
if (fileHeader.dataOffset < 54)
|
if (fileHeader.dataOffset < 54)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
MSInfoHeader msheader;
|
MSInfoHeader msheader;
|
||||||
msheader.size = headersize;
|
msheader.size = headersize;
|
||||||
if (inSource->Read(
|
if (inSource->Read(
|
||||||
reinterpret_cast<uint8 *> (&msheader) + 4, 36) != 36)
|
reinterpret_cast<uint8 *> (&msheader) + 4, 36) != 36)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// convert msheader to host byte order
|
// convert msheader to host byte order
|
||||||
if (swap_data(B_UINT32_TYPE,
|
if (swap_data(B_UINT32_TYPE,
|
||||||
reinterpret_cast<uint8 *> (&msheader) + 4, 36,
|
reinterpret_cast<uint8 *> (&msheader) + 4, 36,
|
||||||
B_SWAP_LENDIAN_TO_HOST) != B_OK)
|
B_SWAP_LENDIAN_TO_HOST) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// check if msheader is valid
|
// check if msheader is valid
|
||||||
if (msheader.width == 0 || msheader.height == 0)
|
if (msheader.width == 0 || msheader.height == 0)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
@@ -350,8 +355,8 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
if (!msheader.imagesize && msheader.compression)
|
if (!msheader.imagesize && msheader.compression)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
if (msheader.colorsimportant > msheader.colorsused)
|
if (msheader.colorsimportant > msheader.colorsused)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
if (outInfo) {
|
if (outInfo) {
|
||||||
outInfo->type = B_BMP_FORMAT;
|
outInfo->type = B_BMP_FORMAT;
|
||||||
outInfo->group = B_TRANSLATOR_BITMAP;
|
outInfo->group = B_TRANSLATOR_BITMAP;
|
||||||
@@ -365,7 +370,7 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
strcat(outInfo->name, ")");
|
strcat(outInfo->name, ")");
|
||||||
strcpy(outInfo->MIME, "image/x-bmp");
|
strcpy(outInfo->MIME, "image/x-bmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pfileheader) {
|
if (pfileheader) {
|
||||||
pfileheader->magic = fileHeader.magic;
|
pfileheader->magic = fileHeader.magic;
|
||||||
pfileheader->fileSize = fileHeader.fileSize;
|
pfileheader->fileSize = fileHeader.fileSize;
|
||||||
@@ -389,7 +394,7 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
}
|
}
|
||||||
if (pfrommsformat)
|
if (pfrommsformat)
|
||||||
(*pfrommsformat) = true;
|
(*pfrommsformat) = true;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
} else if (headersize == sizeof(OS2InfoHeader)) {
|
} else if (headersize == sizeof(OS2InfoHeader)) {
|
||||||
@@ -397,19 +402,19 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
|
|
||||||
if (fileHeader.dataOffset < 26)
|
if (fileHeader.dataOffset < 26)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
OS2InfoHeader os2header;
|
OS2InfoHeader os2header;
|
||||||
os2header.size = headersize;
|
os2header.size = headersize;
|
||||||
if (inSource->Read(
|
if (inSource->Read(
|
||||||
reinterpret_cast<uint8 *> (&os2header) + 4, 8) != 8)
|
reinterpret_cast<uint8 *> (&os2header) + 4, 8) != 8)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// convert msheader to host byte order
|
// convert msheader to host byte order
|
||||||
if (swap_data(B_UINT32_TYPE,
|
if (swap_data(B_UINT32_TYPE,
|
||||||
reinterpret_cast<uint8 *> (&os2header) + 4, 8,
|
reinterpret_cast<uint8 *> (&os2header) + 4, 8,
|
||||||
B_SWAP_LENDIAN_TO_HOST) != B_OK)
|
B_SWAP_LENDIAN_TO_HOST) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// check if msheader is valid
|
// check if msheader is valid
|
||||||
if (os2header.width == 0 || os2header.height == 0)
|
if (os2header.width == 0 || os2header.height == 0)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
@@ -420,7 +425,7 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
os2header.bitsperpixel != 8 &&
|
os2header.bitsperpixel != 8 &&
|
||||||
os2header.bitsperpixel != 24)
|
os2header.bitsperpixel != 24)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
if (outInfo) {
|
if (outInfo) {
|
||||||
outInfo->type = B_BMP_FORMAT;
|
outInfo->type = B_BMP_FORMAT;
|
||||||
outInfo->group = B_TRANSLATOR_BITMAP;
|
outInfo->group = B_TRANSLATOR_BITMAP;
|
||||||
@@ -447,21 +452,21 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
pmsheader->ypixperm = 2835; // 72 dpi vertical
|
pmsheader->ypixperm = 2835; // 72 dpi vertical
|
||||||
pmsheader->colorsused = 0;
|
pmsheader->colorsused = 0;
|
||||||
pmsheader->colorsimportant = 0;
|
pmsheader->colorsimportant = 0;
|
||||||
|
|
||||||
// determine fileSize / imagesize
|
// determine fileSize / imagesize
|
||||||
switch (pmsheader->bitsperpixel) {
|
switch (pmsheader->bitsperpixel) {
|
||||||
case 24:
|
case 24:
|
||||||
if (pos2skip && fileHeader.dataOffset > 26)
|
if (pos2skip && fileHeader.dataOffset > 26)
|
||||||
(*pos2skip) = fileHeader.dataOffset - 26;
|
(*pos2skip) = fileHeader.dataOffset - 26;
|
||||||
|
|
||||||
pfileheader->dataOffset = 54;
|
pfileheader->dataOffset = 54;
|
||||||
pmsheader->imagesize = get_rowbytes(pmsheader->width,
|
pmsheader->imagesize = get_rowbytes(pmsheader->width,
|
||||||
pmsheader->bitsperpixel) * pmsheader->height;
|
pmsheader->bitsperpixel) * pmsheader->height;
|
||||||
pfileheader->fileSize = pfileheader->dataOffset +
|
pfileheader->fileSize = pfileheader->dataOffset +
|
||||||
pmsheader->imagesize;
|
pmsheader->imagesize;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
case 4:
|
case 4:
|
||||||
case 1:
|
case 1:
|
||||||
@@ -479,17 +484,17 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
pmsheader->bitsperpixel) * pmsheader->height;
|
pmsheader->bitsperpixel) * pmsheader->height;
|
||||||
pfileheader->fileSize = pfileheader->dataOffset +
|
pfileheader->fileSize = pfileheader->dataOffset +
|
||||||
pmsheader->imagesize;
|
pmsheader->imagesize;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pfrommsformat)
|
if (pfrommsformat)
|
||||||
(*pfrommsformat) = false;
|
(*pfrommsformat) = false;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
@@ -583,13 +588,13 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
case B_CMYK32:
|
case B_CMYK32:
|
||||||
bitsBytesPerPixel = 4;
|
bitsBytesPerPixel = 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB24:
|
case B_RGB24:
|
||||||
case B_RGB24_BIG:
|
case B_RGB24_BIG:
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
bitsBytesPerPixel = 3;
|
bitsBytesPerPixel = 3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
case B_RGBA15:
|
case B_RGBA15:
|
||||||
@@ -598,12 +603,12 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
case B_RGB15_BIG:
|
case B_RGB15_BIG:
|
||||||
bitsBytesPerPixel = 2;
|
bitsBytesPerPixel = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
bitsBytesPerPixel = 1;
|
bitsBytesPerPixel = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -634,7 +639,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (rd == static_cast<ssize_t>(bitsRowBytes)) {
|
while (rd == static_cast<ssize_t>(bitsRowBytes)) {
|
||||||
|
|
||||||
for (uint32 i = 0; i < msheader.width; i++) {
|
for (uint32 i = 0; i < msheader.width; i++) {
|
||||||
uint8 *bitspixel, *bmppixel;
|
uint8 *bitspixel, *bmppixel;
|
||||||
uint16 val;
|
uint16 val;
|
||||||
@@ -645,7 +650,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
memcpy(bmpRowData + (i * 3),
|
memcpy(bmpRowData + (i * 3),
|
||||||
bitsRowData + (i * bitsBytesPerPixel), 3);
|
bitsRowData + (i * bitsBytesPerPixel), 3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
||||||
@@ -673,14 +678,14 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
val = bitspixel[0] + (bitspixel[1] << 8);
|
val = bitspixel[0] + (bitspixel[1] << 8);
|
||||||
else
|
else
|
||||||
val = bitspixel[1] + (bitspixel[0] << 8);
|
val = bitspixel[1] + (bitspixel[0] << 8);
|
||||||
bmppixel[0] =
|
bmppixel[0] =
|
||||||
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
bmppixel[1] =
|
bmppixel[1] =
|
||||||
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
bmppixel[2] =
|
bmppixel[2] =
|
||||||
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB32_BIG:
|
case B_RGB32_BIG:
|
||||||
case B_RGBA32_BIG:
|
case B_RGBA32_BIG:
|
||||||
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
||||||
@@ -689,7 +694,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
bmppixel[1] = bitspixel[2];
|
bmppixel[1] = bitspixel[2];
|
||||||
bmppixel[2] = bitspixel[1];
|
bmppixel[2] = bitspixel[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB24_BIG:
|
case B_RGB24_BIG:
|
||||||
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
||||||
bmppixel = bmpRowData + (i * 3);
|
bmppixel = bmpRowData + (i * 3);
|
||||||
@@ -697,7 +702,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
bmppixel[1] = bitspixel[1];
|
bmppixel[1] = bitspixel[1];
|
||||||
bmppixel[2] = bitspixel[0];
|
bmppixel[2] = bitspixel[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
{
|
{
|
||||||
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
||||||
@@ -708,7 +713,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
bmppixel[2] = c.red;
|
bmppixel[2] = c.red;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
||||||
bmppixel = bmpRowData + (i * 3);
|
bmppixel = bmpRowData + (i * 3);
|
||||||
@@ -716,23 +721,23 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
bmppixel[1] = bitspixel[0];
|
bmppixel[1] = bitspixel[0];
|
||||||
bmppixel[2] = bitspixel[0];
|
bmppixel[2] = bitspixel[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMYK32:
|
case B_CMYK32:
|
||||||
{
|
{
|
||||||
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
|
||||||
bmppixel = bmpRowData + (i * 3);
|
bmppixel = bmpRowData + (i * 3);
|
||||||
|
|
||||||
int32 comp = 255 - bitspixel[2] - bitspixel[3];
|
int32 comp = 255 - bitspixel[2] - bitspixel[3];
|
||||||
bmppixel[0] = (comp < 0) ? 0 : comp;
|
bmppixel[0] = (comp < 0) ? 0 : comp;
|
||||||
|
|
||||||
comp = 255 - bitspixel[1] - bitspixel[3];
|
comp = 255 - bitspixel[1] - bitspixel[3];
|
||||||
bmppixel[1] = (comp < 0) ? 0 : comp;
|
bmppixel[1] = (comp < 0) ? 0 : comp;
|
||||||
|
|
||||||
comp = 255 - bitspixel[0] - bitspixel[3];
|
comp = 255 - bitspixel[0] - bitspixel[3];
|
||||||
bmppixel[2] = (comp < 0) ? 0 : comp;
|
bmppixel[2] = (comp < 0) ? 0 : comp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_CMY32:
|
case B_CMY32:
|
||||||
case B_CMYA32:
|
case B_CMYA32:
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
@@ -742,16 +747,16 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
bmppixel[1] = 255 - bitspixel[1];
|
bmppixel[1] = 255 - bitspixel[1];
|
||||||
bmppixel[2] = 255 - bitspixel[0];
|
bmppixel[2] = 255 - bitspixel[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
} // switch (fromspace)
|
} // switch (fromspace)
|
||||||
} // for for (uint32 i = 0; i < msheader.width; i++)
|
} // for for (uint32 i = 0; i < msheader.width; i++)
|
||||||
|
|
||||||
outDestination->Write(bmpRowData, bmpRowBytes);
|
outDestination->Write(bmpRowData, bmpRowBytes);
|
||||||
bmppixrow++;
|
bmppixrow++;
|
||||||
// if I've read all of the pixel data, break
|
// if I've read all of the pixel data, break
|
||||||
// out of the loop so I don't try to read
|
// out of the loop so I don't try to read
|
||||||
// non-pixel data
|
// non-pixel data
|
||||||
if (bmppixrow == msheader.height)
|
if (bmppixrow == msheader.height)
|
||||||
break;
|
break;
|
||||||
@@ -759,7 +764,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
|
|||||||
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
|
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
rd = inSource->Read(bitsRowData, bitsRowBytes);
|
rd = inSource->Read(bitsRowData, bitsRowBytes);
|
||||||
} // while (rd == bitsRowBytes)
|
} // while (rd == bitsRowBytes)
|
||||||
|
|
||||||
delete[] bmpRowData;
|
delete[] bmpRowData;
|
||||||
delete[] bitsRowData;
|
delete[] bitsRowData;
|
||||||
|
|
||||||
@@ -815,7 +820,7 @@ translate_from_bits8_to_bmp8(BPositionIO *inSource,
|
|||||||
outDestination->Write(bmpRowData, bmpRowBytes);
|
outDestination->Write(bmpRowData, bmpRowBytes);
|
||||||
bmppixrow++;
|
bmppixrow++;
|
||||||
// if I've read all of the pixel data, break
|
// if I've read all of the pixel data, break
|
||||||
// out of the loop so I don't try to read
|
// out of the loop so I don't try to read
|
||||||
// non-pixel data
|
// non-pixel data
|
||||||
if (bmppixrow == msheader.height)
|
if (bmppixrow == msheader.height)
|
||||||
break;
|
break;
|
||||||
@@ -823,7 +828,7 @@ translate_from_bits8_to_bmp8(BPositionIO *inSource,
|
|||||||
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
|
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
rd = inSource->Read(bitsRowData, bitsRowBytes);
|
rd = inSource->Read(bitsRowData, bitsRowBytes);
|
||||||
} // while (rd == bitsRowBytes)
|
} // while (rd == bitsRowBytes)
|
||||||
|
|
||||||
delete[] bmpRowData;
|
delete[] bmpRowData;
|
||||||
delete[] bitsRowData;
|
delete[] bitsRowData;
|
||||||
|
|
||||||
@@ -876,7 +881,7 @@ translate_from_bits1_to_bmp1(BPositionIO *inSource,
|
|||||||
while (rd == bitsRowBytes) {
|
while (rd == bitsRowBytes) {
|
||||||
uint32 bmppixcol = 0;
|
uint32 bmppixcol = 0;
|
||||||
memset(bmpRowData, 0, bmpRowBytes);
|
memset(bmpRowData, 0, bmpRowBytes);
|
||||||
for (int32 i = 0; (bmppixcol < msheader.width) &&
|
for (int32 i = 0; (bmppixcol < msheader.width) &&
|
||||||
(i < bitsRowBytes); i++) {
|
(i < bitsRowBytes); i++) {
|
||||||
// process each byte in the row
|
// process each byte in the row
|
||||||
uint8 pixels = bitsRowData[i];
|
uint8 pixels = bitsRowData[i];
|
||||||
@@ -891,16 +896,16 @@ translate_from_bits1_to_bmp1(BPositionIO *inSource,
|
|||||||
else
|
else
|
||||||
// 0 == white
|
// 0 == white
|
||||||
index = 0;
|
index = 0;
|
||||||
bmpRowData[bmppixcol / pixelsPerByte] |=
|
bmpRowData[bmppixcol / pixelsPerByte] |=
|
||||||
index << (7 - (bmppixcol % pixelsPerByte));
|
index << (7 - (bmppixcol % pixelsPerByte));
|
||||||
bmppixcol++;
|
bmppixcol++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outDestination->Write(bmpRowData, bmpRowBytes);
|
outDestination->Write(bmpRowData, bmpRowBytes);
|
||||||
bmppixrow++;
|
bmppixrow++;
|
||||||
// if I've read all of the pixel data, break
|
// if I've read all of the pixel data, break
|
||||||
// out of the loop so I don't try to read
|
// out of the loop so I don't try to read
|
||||||
// non-pixel data
|
// non-pixel data
|
||||||
if (bmppixrow == msheader.height)
|
if (bmppixrow == msheader.height)
|
||||||
break;
|
break;
|
||||||
@@ -908,7 +913,7 @@ translate_from_bits1_to_bmp1(BPositionIO *inSource,
|
|||||||
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
|
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
rd = inSource->Read(bitsRowData, bitsRowBytes);
|
rd = inSource->Read(bitsRowData, bitsRowBytes);
|
||||||
} // while (rd == bitsRowBytes)
|
} // while (rd == bitsRowBytes)
|
||||||
|
|
||||||
delete[] bmpRowData;
|
delete[] bmpRowData;
|
||||||
delete[] bitsRowData;
|
delete[] bitsRowData;
|
||||||
|
|
||||||
@@ -956,7 +961,7 @@ write_bmp_headers(BPositionIO *outDestination, BMPFileHeader &fileHeader,
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
if (outDestination->Write(bmpheaders, 54) != 54)
|
if (outDestination->Write(bmpheaders, 54) != 54)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,26 +1001,26 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Translate B_TRANSLATOR_BITMAP to B_BMP_FORMAT
|
// Translate B_TRANSLATOR_BITMAP to B_BMP_FORMAT
|
||||||
if (outType == B_BMP_FORMAT) {
|
if (outType == B_BMP_FORMAT) {
|
||||||
// Set up BMP header
|
// Set up BMP header
|
||||||
BMPFileHeader fileHeader;
|
BMPFileHeader fileHeader;
|
||||||
fileHeader.magic = 'MB';
|
fileHeader.magic = 'MB';
|
||||||
fileHeader.reserved = 0;
|
fileHeader.reserved = 0;
|
||||||
|
|
||||||
MSInfoHeader msheader;
|
MSInfoHeader msheader;
|
||||||
msheader.size = 40;
|
msheader.size = 40;
|
||||||
msheader.width =
|
msheader.width =
|
||||||
static_cast<uint32> (bitsHeader.bounds.Width() + 1);
|
static_cast<uint32> (bitsHeader.bounds.Width() + 1);
|
||||||
msheader.height =
|
msheader.height =
|
||||||
static_cast<uint32> (bitsHeader.bounds.Height() + 1);
|
static_cast<uint32> (bitsHeader.bounds.Height() + 1);
|
||||||
msheader.planes = 1;
|
msheader.planes = 1;
|
||||||
msheader.xpixperm = 2835; // 72 dpi horizontal
|
msheader.xpixperm = 2835; // 72 dpi horizontal
|
||||||
msheader.ypixperm = 2835; // 72 dpi vertical
|
msheader.ypixperm = 2835; // 72 dpi vertical
|
||||||
msheader.colorsused = 0;
|
msheader.colorsused = 0;
|
||||||
msheader.colorsimportant = 0;
|
msheader.colorsimportant = 0;
|
||||||
|
|
||||||
// determine fileSize / imagesize
|
// determine fileSize / imagesize
|
||||||
switch (bitsHeader.colors) {
|
switch (bitsHeader.colors) {
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
@@ -1034,7 +1039,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
case B_CMY32:
|
case B_CMY32:
|
||||||
case B_CMYA32:
|
case B_CMYA32:
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
|
|
||||||
fileHeader.dataOffset = 54;
|
fileHeader.dataOffset = 54;
|
||||||
msheader.bitsperpixel = 24;
|
msheader.bitsperpixel = 24;
|
||||||
msheader.compression = BMP_NO_COMPRESS;
|
msheader.compression = BMP_NO_COMPRESS;
|
||||||
@@ -1042,12 +1047,12 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
msheader.height;
|
msheader.height;
|
||||||
fileHeader.fileSize = fileHeader.dataOffset +
|
fileHeader.fileSize = fileHeader.dataOffset +
|
||||||
msheader.imagesize;
|
msheader.imagesize;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
|
|
||||||
msheader.colorsused = 256;
|
msheader.colorsused = 256;
|
||||||
msheader.colorsimportant = 256;
|
msheader.colorsimportant = 256;
|
||||||
fileHeader.dataOffset = 54 + (4 * 256);
|
fileHeader.dataOffset = 54 + (4 * 256);
|
||||||
@@ -1057,11 +1062,11 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
msheader.bitsperpixel) * msheader.height;
|
msheader.bitsperpixel) * msheader.height;
|
||||||
fileHeader.fileSize = fileHeader.dataOffset +
|
fileHeader.fileSize = fileHeader.dataOffset +
|
||||||
msheader.imagesize;
|
msheader.imagesize;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_GRAY1:
|
case B_GRAY1:
|
||||||
|
|
||||||
msheader.colorsused = 2;
|
msheader.colorsused = 2;
|
||||||
msheader.colorsimportant = 2;
|
msheader.colorsimportant = 2;
|
||||||
fileHeader.dataOffset = 62;
|
fileHeader.dataOffset = 62;
|
||||||
@@ -1071,13 +1076,13 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
msheader.bitsperpixel) * msheader.height;
|
msheader.bitsperpixel) * msheader.height;
|
||||||
fileHeader.fileSize = fileHeader.dataOffset +
|
fileHeader.fileSize = fileHeader.dataOffset +
|
||||||
msheader.imagesize;
|
msheader.imagesize;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write out the BMP headers
|
// write out the BMP headers
|
||||||
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
||||||
result = write_bmp_headers(outDestination, fileHeader, msheader);
|
result = write_bmp_headers(outDestination, fileHeader, msheader);
|
||||||
@@ -1109,7 +1114,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
return translate_from_bits_to_bmp24(inSource, outDestination,
|
return translate_from_bits_to_bmp24(inSource, outDestination,
|
||||||
bitsHeader.colors, msheader);
|
bitsHeader.colors, msheader);
|
||||||
|
|
||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
{
|
{
|
||||||
@@ -1138,7 +1143,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
palHandle[3] = 255;
|
palHandle[3] = 255;
|
||||||
palHandle += 4;
|
palHandle += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ssize_t written = outDestination->Write(pal, 1024);
|
ssize_t written = outDestination->Write(pal, 1024);
|
||||||
if (written < 0)
|
if (written < 0)
|
||||||
return written;
|
return written;
|
||||||
@@ -1148,7 +1153,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
return translate_from_bits8_to_bmp8(inSource, outDestination,
|
return translate_from_bits8_to_bmp8(inSource, outDestination,
|
||||||
bitsHeader.rowBytes, msheader);
|
bitsHeader.rowBytes, msheader);
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_GRAY1:
|
case B_GRAY1:
|
||||||
{
|
{
|
||||||
// write monochrome palette to the BMP file
|
// write monochrome palette to the BMP file
|
||||||
@@ -1158,11 +1163,11 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
return written;
|
return written;
|
||||||
if (written != 8)
|
if (written != 8)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
return translate_from_bits1_to_bmp1(inSource, outDestination,
|
return translate_from_bits1_to_bmp1(inSource, outDestination,
|
||||||
bitsHeader.rowBytes, msheader);
|
bitsHeader.rowBytes, msheader);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
@@ -1202,7 +1207,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
|
|||||||
// Setup outDestination so that it can be written to
|
// Setup outDestination so that it can be written to
|
||||||
// from the end of the file to the beginning instead of
|
// from the end of the file to the beginning instead of
|
||||||
// the other way around
|
// the other way around
|
||||||
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
|
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
|
||||||
sizeof(TranslatorBitmap);
|
sizeof(TranslatorBitmap);
|
||||||
if (outDestination->SetSize(bitsFileSize) != B_OK) {
|
if (outDestination->SetSize(bitsFileSize) != B_OK) {
|
||||||
// This call should work for BFile and BMallocIO objects,
|
// This call should work for BFile and BMallocIO objects,
|
||||||
@@ -1212,7 +1217,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
|
|||||||
}
|
}
|
||||||
off_t bitsoffset = (msheader.height - 1) * bitsRowBytes;
|
off_t bitsoffset = (msheader.height - 1) * bitsRowBytes;
|
||||||
outDestination->Seek(bitsoffset, SEEK_CUR);
|
outDestination->Seek(bitsoffset, SEEK_CUR);
|
||||||
|
|
||||||
// allocate row buffers
|
// allocate row buffers
|
||||||
uint8 *bmpRowData = new (nothrow) uint8[bmpRowBytes];
|
uint8 *bmpRowData = new (nothrow) uint8[bmpRowBytes];
|
||||||
if (!bmpRowData)
|
if (!bmpRowData)
|
||||||
@@ -1269,7 +1274,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] bmpRowData;
|
delete[] bmpRowData;
|
||||||
delete[] bitsRowData;
|
delete[] bitsRowData;
|
||||||
|
|
||||||
@@ -1279,7 +1284,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
|
|||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// translate_from_bmppal_to_bits
|
// translate_from_bmppal_to_bits
|
||||||
//
|
//
|
||||||
// Translates an uncompressed, palette BMP from inSource to
|
// Translates an uncompressed, palette BMP from inSource to
|
||||||
// the B_RGB32 bits format.
|
// the B_RGB32 bits format.
|
||||||
//
|
//
|
||||||
// Preconditions:
|
// Preconditions:
|
||||||
@@ -1313,19 +1318,19 @@ translate_from_bmppal_to_bits(BPositionIO *inSource,
|
|||||||
palBytesPerPixel = 4;
|
palBytesPerPixel = 4;
|
||||||
else
|
else
|
||||||
palBytesPerPixel = 3;
|
palBytesPerPixel = 3;
|
||||||
|
|
||||||
uint8 mask = 1;
|
uint8 mask = 1;
|
||||||
mask = (mask << bitsPerPixel) - 1;
|
mask = (mask << bitsPerPixel) - 1;
|
||||||
|
|
||||||
int32 bmpRowBytes =
|
int32 bmpRowBytes =
|
||||||
get_rowbytes(msheader.width, msheader.bitsperpixel);
|
get_rowbytes(msheader.width, msheader.bitsperpixel);
|
||||||
uint32 bmppixrow = 0;
|
uint32 bmppixrow = 0;
|
||||||
|
|
||||||
// Setup outDestination so that it can be written to
|
// Setup outDestination so that it can be written to
|
||||||
// from the end of the file to the beginning instead of
|
// from the end of the file to the beginning instead of
|
||||||
// the other way around
|
// the other way around
|
||||||
int32 bitsRowBytes = msheader.width * 4;
|
int32 bitsRowBytes = msheader.width * 4;
|
||||||
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
|
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
|
||||||
sizeof(TranslatorBitmap);
|
sizeof(TranslatorBitmap);
|
||||||
if (outDestination->SetSize(bitsFileSize) != B_OK)
|
if (outDestination->SetSize(bitsFileSize) != B_OK)
|
||||||
// This call should work for BFile and BMallocIO objects,
|
// This call should work for BFile and BMallocIO objects,
|
||||||
@@ -1350,16 +1355,16 @@ translate_from_bmppal_to_bits(BPositionIO *inSource,
|
|||||||
uint8 indices = (bmpRowData + (i / pixelsPerByte))[0];
|
uint8 indices = (bmpRowData + (i / pixelsPerByte))[0];
|
||||||
uint8 index;
|
uint8 index;
|
||||||
index = (indices >>
|
index = (indices >>
|
||||||
(bitsPerPixel * ((pixelsPerByte - 1) -
|
(bitsPerPixel * ((pixelsPerByte - 1) -
|
||||||
(i % pixelsPerByte)))) & mask;
|
(i % pixelsPerByte)))) & mask;
|
||||||
memcpy(bitsRowData + (i * 4),
|
memcpy(bitsRowData + (i * 4),
|
||||||
palette + (index * palBytesPerPixel), 3);
|
palette + (index * palBytesPerPixel), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
outDestination->Write(bitsRowData, bitsRowBytes);
|
outDestination->Write(bitsRowData, bitsRowBytes);
|
||||||
bmppixrow++;
|
bmppixrow++;
|
||||||
// if I've read all of the pixel data, break
|
// if I've read all of the pixel data, break
|
||||||
// out of the loop so I don't try to read
|
// out of the loop so I don't try to read
|
||||||
// non-pixel data
|
// non-pixel data
|
||||||
if (bmppixrow == msheader.height)
|
if (bmppixrow == msheader.height)
|
||||||
break;
|
break;
|
||||||
@@ -1367,7 +1372,7 @@ translate_from_bmppal_to_bits(BPositionIO *inSource,
|
|||||||
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
rd = inSource->Read(bmpRowData, bmpRowBytes);
|
rd = inSource->Read(bmpRowData, bmpRowBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] bmpRowData;
|
delete[] bmpRowData;
|
||||||
delete[] bitsRowData;
|
delete[] bitsRowData;
|
||||||
|
|
||||||
@@ -1406,10 +1411,10 @@ pixelcpy(uint8 *dest, uint32 pixel, uint32 count)
|
|||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// translate_from_bmppalr_to_bits
|
// translate_from_bmppalr_to_bits
|
||||||
//
|
//
|
||||||
// Translates an RLE compressed, palette BMP from inSource to
|
// Translates an RLE compressed, palette BMP from inSource to
|
||||||
// the B_RGB32 bits format. Currently, this code is not as
|
// the B_RGB32 bits format. Currently, this code is not as
|
||||||
// memory effcient as it could be. It assumes that the BMP
|
// memory effcient as it could be. It assumes that the BMP
|
||||||
// from inSource is relatively small.
|
// from inSource is relatively small.
|
||||||
//
|
//
|
||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
@@ -1443,7 +1448,7 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
// from the end of the file to the beginning instead of
|
// from the end of the file to the beginning instead of
|
||||||
// the other way around
|
// the other way around
|
||||||
int32 bitsRowBytes = msheader.width * 4;
|
int32 bitsRowBytes = msheader.width * 4;
|
||||||
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
|
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
|
||||||
sizeof(TranslatorBitmap);
|
sizeof(TranslatorBitmap);
|
||||||
if (outDestination->SetSize(bitsFileSize) != B_OK)
|
if (outDestination->SetSize(bitsFileSize) != B_OK)
|
||||||
// This call should work for BFile and BMallocIO objects,
|
// This call should work for BFile and BMallocIO objects,
|
||||||
@@ -1470,19 +1475,19 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// if count is greater than the number of
|
// if count is greater than the number of
|
||||||
// pixels remaining in the current row,
|
// pixels remaining in the current row,
|
||||||
// only process the correct number of pixels
|
// only process the correct number of pixels
|
||||||
// remaining in the row
|
// remaining in the row
|
||||||
if (count + bmppixcol > msheader.width)
|
if (count + bmppixcol > msheader.width)
|
||||||
count = msheader.width - bmppixcol;
|
count = msheader.width - bmppixcol;
|
||||||
|
|
||||||
rd = inSource->Read(&indices, 1);
|
rd = inSource->Read(&indices, 1);
|
||||||
if (rd != 1) {
|
if (rd != 1) {
|
||||||
rd = -1;
|
rd = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (uint8 i = 0; i < count; i++) {
|
for (uint8 i = 0; i < count; i++) {
|
||||||
index = (indices >> (bitsPerPixel * ((pixelsPerByte - 1) -
|
index = (indices >> (bitsPerPixel * ((pixelsPerByte - 1) -
|
||||||
(i % pixelsPerByte)))) & mask;
|
(i % pixelsPerByte)))) & mask;
|
||||||
memcpy(bitsRowData + (bmppixcol*4), palette + (index*4), 3);
|
memcpy(bitsRowData + (bmppixcol*4), palette + (index*4), 3);
|
||||||
bmppixcol++;
|
bmppixcol++;
|
||||||
@@ -1509,8 +1514,8 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
if (bmppixrow < msheader.height)
|
if (bmppixrow < msheader.height)
|
||||||
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// end of bitmap
|
// end of bitmap
|
||||||
case 1:
|
case 1:
|
||||||
// if at the end of a row
|
// if at the end of a row
|
||||||
if (bmppixcol == msheader.width) {
|
if (bmppixcol == msheader.width) {
|
||||||
@@ -1520,7 +1525,7 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
if (bmppixrow < msheader.height)
|
if (bmppixrow < msheader.height)
|
||||||
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (bmppixrow < msheader.height) {
|
while (bmppixrow < msheader.height) {
|
||||||
pixelcpy(bitsRowData + (bmppixcol * 4), defaultcolor,
|
pixelcpy(bitsRowData + (bmppixcol * 4), defaultcolor,
|
||||||
msheader.width - bmppixcol);
|
msheader.width - bmppixcol);
|
||||||
@@ -1533,9 +1538,9 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
rd = 0;
|
rd = 0;
|
||||||
// break out of while loop
|
// break out of while loop
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// delta, skip several rows and/or columns and
|
// delta, skip several rows and/or columns and
|
||||||
// fill the skipped pixels with the default color
|
// fill the skipped pixels with the default color
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
uint8 da[2], lastcol, dx, dy;
|
uint8 da[2], lastcol, dx, dy;
|
||||||
@@ -1546,16 +1551,16 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
}
|
}
|
||||||
dx = da[0];
|
dx = da[0];
|
||||||
dy = da[1];
|
dy = da[1];
|
||||||
|
|
||||||
// abort if dx or dy is too large
|
// abort if dx or dy is too large
|
||||||
if ((dx + bmppixcol >= msheader.width) ||
|
if ((dx + bmppixcol >= msheader.width) ||
|
||||||
(dy + bmppixrow >= msheader.height)) {
|
(dy + bmppixrow >= msheader.height)) {
|
||||||
rd = -1;
|
rd = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastcol = bmppixcol;
|
lastcol = bmppixcol;
|
||||||
|
|
||||||
// set all pixels to the first entry in
|
// set all pixels to the first entry in
|
||||||
// the palette, for the number of rows skipped
|
// the palette, for the number of rows skipped
|
||||||
while (dy > 0) {
|
while (dy > 0) {
|
||||||
@@ -1567,13 +1572,13 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
dy--;
|
dy--;
|
||||||
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmppixcol < static_cast<uint32>(lastcol + dx)) {
|
if (bmppixcol < static_cast<uint32>(lastcol + dx)) {
|
||||||
pixelcpy(bitsRowData + (bmppixcol * 4), defaultcolor,
|
pixelcpy(bitsRowData + (bmppixcol * 4), defaultcolor,
|
||||||
dx + lastcol - bmppixcol);
|
dx + lastcol - bmppixcol);
|
||||||
bmppixcol = dx + lastcol;
|
bmppixcol = dx + lastcol;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1587,20 +1592,20 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// if code is greater than the number of
|
// if code is greater than the number of
|
||||||
// pixels remaining in the current row,
|
// pixels remaining in the current row,
|
||||||
// only process the correct number of pixels
|
// only process the correct number of pixels
|
||||||
// remaining in the row
|
// remaining in the row
|
||||||
if (code + bmppixcol > msheader.width)
|
if (code + bmppixcol > msheader.width)
|
||||||
code = msheader.width - bmppixcol;
|
code = msheader.width - bmppixcol;
|
||||||
|
|
||||||
uint8 uncomp[256];
|
uint8 uncomp[256];
|
||||||
int32 padding;
|
int32 padding;
|
||||||
if (!(code % pixelsPerByte))
|
if (!(code % pixelsPerByte))
|
||||||
padding = (code / pixelsPerByte) % 2;
|
padding = (code / pixelsPerByte) % 2;
|
||||||
else
|
else
|
||||||
padding = ((code + pixelsPerByte -
|
padding = ((code + pixelsPerByte -
|
||||||
(code % pixelsPerByte)) / pixelsPerByte) % 2;
|
(code % pixelsPerByte)) / pixelsPerByte) % 2;
|
||||||
int32 uncompBytes = (code / pixelsPerByte) +
|
int32 uncompBytes = (code / pixelsPerByte) +
|
||||||
((code % pixelsPerByte) ? 1 : 0) + padding;
|
((code % pixelsPerByte) ? 1 : 0) + padding;
|
||||||
rd = inSource->Read(uncomp, uncompBytes);
|
rd = inSource->Read(uncomp, uncompBytes);
|
||||||
if (rd != uncompBytes) {
|
if (rd != uncompBytes) {
|
||||||
@@ -1610,7 +1615,7 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
for (uint8 i = 0; i < code; i++) {
|
for (uint8 i = 0; i < code; i++) {
|
||||||
indices = (uncomp + (i / pixelsPerByte))[0];
|
indices = (uncomp + (i / pixelsPerByte))[0];
|
||||||
index = (indices >>
|
index = (indices >>
|
||||||
(bitsPerPixel * ((pixelsPerByte - 1) -
|
(bitsPerPixel * ((pixelsPerByte - 1) -
|
||||||
(i % pixelsPerByte)))) & mask;
|
(i % pixelsPerByte)))) & mask;
|
||||||
memcpy(bitsRowData + (bmppixcol * 4),
|
memcpy(bitsRowData + (bmppixcol * 4),
|
||||||
palette + (index * 4), 3);
|
palette + (index * 4), 3);
|
||||||
@@ -1623,9 +1628,9 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
|
|||||||
if (rd > 0)
|
if (rd > 0)
|
||||||
rd = inSource->Read(&count, 1);
|
rd = inSource->Read(&count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] bitsRowData;
|
delete[] bitsRowData;
|
||||||
|
|
||||||
if (!rd)
|
if (!rd)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
else
|
else
|
||||||
@@ -1675,8 +1680,8 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
INFO("BMPTranslator::translate_from_bmp() - identify_bmp_header failed\n");
|
INFO("BMPTranslator::translate_from_bmp() - identify_bmp_header failed\n");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the user wants to translate a BMP to a BMP, easy enough :)
|
// if the user wants to translate a BMP to a BMP, easy enough :)
|
||||||
if (outType == B_BMP_FORMAT) {
|
if (outType == B_BMP_FORMAT) {
|
||||||
// write out the BMP headers
|
// write out the BMP headers
|
||||||
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
||||||
@@ -1685,14 +1690,14 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (bheaderonly)
|
if (bheaderonly)
|
||||||
// if the user only wants the header,
|
// if the user only wants the header,
|
||||||
// bail before it is written
|
// bail before it is written
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
uint8 buf[1024];
|
uint8 buf[1024];
|
||||||
ssize_t rd;
|
ssize_t rd;
|
||||||
uint32 rdtotal = 54;
|
uint32 rdtotal = 54;
|
||||||
if (!frommsformat && (msheader.bitsperpixel == 1 ||
|
if (!frommsformat && (msheader.bitsperpixel == 1 ||
|
||||||
msheader.bitsperpixel == 4 || msheader.bitsperpixel == 8)) {
|
msheader.bitsperpixel == 4 || msheader.bitsperpixel == 8)) {
|
||||||
// if OS/2 paletted format, convert palette to MS format
|
// if OS/2 paletted format, convert palette to MS format
|
||||||
uint16 ncolors = 1 << msheader.bitsperpixel;
|
uint16 ncolors = 1 << msheader.bitsperpixel;
|
||||||
@@ -1723,7 +1728,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
else
|
else
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// if translating a BMP to a Be Bitmap
|
// if translating a BMP to a Be Bitmap
|
||||||
} else if (outType == B_TRANSLATOR_BITMAP) {
|
} else if (outType == B_TRANSLATOR_BITMAP) {
|
||||||
TranslatorBitmap bitsHeader;
|
TranslatorBitmap bitsHeader;
|
||||||
@@ -1732,31 +1737,31 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
bitsHeader.bounds.top = 0;
|
bitsHeader.bounds.top = 0;
|
||||||
bitsHeader.bounds.right = msheader.width - 1;
|
bitsHeader.bounds.right = msheader.width - 1;
|
||||||
bitsHeader.bounds.bottom = msheader.height - 1;
|
bitsHeader.bounds.bottom = msheader.height - 1;
|
||||||
|
|
||||||
// read in palette and/or skip non-BMP data
|
// read in palette and/or skip non-BMP data
|
||||||
uint8 bmppalette[1024];
|
uint8 bmppalette[1024];
|
||||||
off_t nskip = 0;
|
off_t nskip = 0;
|
||||||
if (msheader.bitsperpixel == 1 ||
|
if (msheader.bitsperpixel == 1 ||
|
||||||
msheader.bitsperpixel == 4 ||
|
msheader.bitsperpixel == 4 ||
|
||||||
msheader.bitsperpixel == 8) {
|
msheader.bitsperpixel == 8) {
|
||||||
|
|
||||||
uint8 palBytesPerPixel;
|
uint8 palBytesPerPixel;
|
||||||
if (frommsformat)
|
if (frommsformat)
|
||||||
palBytesPerPixel = 4;
|
palBytesPerPixel = 4;
|
||||||
else
|
else
|
||||||
palBytesPerPixel = 3;
|
palBytesPerPixel = 3;
|
||||||
|
|
||||||
if (!msheader.colorsused)
|
if (!msheader.colorsused)
|
||||||
msheader.colorsused = 1 << msheader.bitsperpixel;
|
msheader.colorsused = 1 << msheader.bitsperpixel;
|
||||||
|
|
||||||
if (inSource->Read(bmppalette, msheader.colorsused *
|
if (inSource->Read(bmppalette, msheader.colorsused *
|
||||||
palBytesPerPixel) !=
|
palBytesPerPixel) !=
|
||||||
(off_t) msheader.colorsused * palBytesPerPixel)
|
(off_t) msheader.colorsused * palBytesPerPixel)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// skip over non-BMP data
|
// skip over non-BMP data
|
||||||
if (frommsformat) {
|
if (frommsformat) {
|
||||||
if (fileHeader.dataOffset > (msheader.colorsused *
|
if (fileHeader.dataOffset > (msheader.colorsused *
|
||||||
palBytesPerPixel) + 54)
|
palBytesPerPixel) + 54)
|
||||||
nskip = fileHeader.dataOffset -
|
nskip = fileHeader.dataOffset -
|
||||||
((msheader.colorsused * palBytesPerPixel) + 54);
|
((msheader.colorsused * palBytesPerPixel) + 54);
|
||||||
@@ -1765,7 +1770,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
} else if (fileHeader.dataOffset > 54)
|
} else if (fileHeader.dataOffset > 54)
|
||||||
// skip over non-BMP data
|
// skip over non-BMP data
|
||||||
nskip = fileHeader.dataOffset - 54;
|
nskip = fileHeader.dataOffset - 54;
|
||||||
|
|
||||||
if (nskip > 0 && inSource->Seek(nskip, SEEK_CUR) < 0)
|
if (nskip > 0 && inSource->Seek(nskip, SEEK_CUR) < 0)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
@@ -1773,7 +1778,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
bitsHeader.colors = B_RGB32;
|
bitsHeader.colors = B_RGB32;
|
||||||
int32 datasize = bitsHeader.rowBytes * msheader.height;
|
int32 datasize = bitsHeader.rowBytes * msheader.height;
|
||||||
bitsHeader.dataSize = datasize;
|
bitsHeader.dataSize = datasize;
|
||||||
|
|
||||||
// write out Be's Bitmap header
|
// write out Be's Bitmap header
|
||||||
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
||||||
if (swap_data(B_UINT32_TYPE, &bitsHeader,
|
if (swap_data(B_UINT32_TYPE, &bitsHeader,
|
||||||
@@ -1782,17 +1787,17 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
||||||
}
|
}
|
||||||
if (bheaderonly)
|
if (bheaderonly)
|
||||||
// if the user only wants the header,
|
// if the user only wants the header,
|
||||||
// bail before the data is written
|
// bail before the data is written
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
// write out the actual image data
|
// write out the actual image data
|
||||||
switch (msheader.bitsperpixel) {
|
switch (msheader.bitsperpixel) {
|
||||||
case 32:
|
case 32:
|
||||||
case 24:
|
case 24:
|
||||||
return translate_from_bmpnpal_to_bits(inSource,
|
return translate_from_bmpnpal_to_bits(inSource,
|
||||||
outDestination, msheader);
|
outDestination, msheader);
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
// 8 bit BMP with NO compression
|
// 8 bit BMP with NO compression
|
||||||
if (msheader.compression == BMP_NO_COMPRESS)
|
if (msheader.compression == BMP_NO_COMPRESS)
|
||||||
@@ -1805,10 +1810,10 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
outDestination, datasize, msheader, bmppalette);
|
outDestination, datasize, msheader, bmppalette);
|
||||||
else
|
else
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
// 4 bit BMP with NO compression
|
// 4 bit BMP with NO compression
|
||||||
if (!msheader.compression)
|
if (!msheader.compression)
|
||||||
return translate_from_bmppal_to_bits(inSource,
|
return translate_from_bmppal_to_bits(inSource,
|
||||||
outDestination, msheader, bmppalette, frommsformat);
|
outDestination, msheader, bmppalette, frommsformat);
|
||||||
|
|
||||||
@@ -1818,15 +1823,15 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
outDestination, datasize, msheader, bmppalette);
|
outDestination, datasize, msheader, bmppalette);
|
||||||
else
|
else
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
return translate_from_bmppal_to_bits(inSource,
|
return translate_from_bmppal_to_bits(inSource,
|
||||||
outDestination, msheader, bmppalette, frommsformat);
|
outDestination, msheader, bmppalette, frommsformat);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
@@ -1840,7 +1845,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
|
|||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
// Parameters: inSource, the data to be translated
|
// Parameters: inSource, the data to be translated
|
||||||
//
|
//
|
||||||
// inInfo, hint about the data in inSource (not used)
|
// inInfo, hint about the data in inSource (not used)
|
||||||
//
|
//
|
||||||
// ioExtension, configuration options for the
|
// ioExtension, configuration options for the
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
EXR_IMAGE_FORMAT,
|
EXR_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -33,7 +33,7 @@ translation_format sInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -45,7 +45,7 @@ translation_format sOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
@@ -91,7 +91,7 @@ EXRTranslator::DerivedIdentify(BPositionIO *stream,
|
|||||||
try {
|
try {
|
||||||
IStreamWrapper istream("filename", stream);
|
IStreamWrapper istream("filename", stream);
|
||||||
RgbaInputFile inputFile(istream);
|
RgbaInputFile inputFile(istream);
|
||||||
|
|
||||||
if (outInfo) {
|
if (outInfo) {
|
||||||
outInfo->type = EXR_IMAGE_FORMAT;
|
outInfo->type = EXR_IMAGE_FORMAT;
|
||||||
outInfo->group = B_TRANSLATOR_BITMAP;
|
outInfo->group = B_TRANSLATOR_BITMAP;
|
||||||
@@ -131,7 +131,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
int dataHeight = dataWindow.max.y - dataWindow.min.y + 1;
|
int dataHeight = dataWindow.max.y - dataWindow.min.y + 1;
|
||||||
int displayWidth = displayWindow.max.x - displayWindow.min.x + 1;
|
int displayWidth = displayWindow.max.x - displayWindow.min.x + 1;
|
||||||
int displayHeight = displayWindow.max.y - displayWindow.min.y + 1;
|
int displayHeight = displayWindow.max.y - displayWindow.min.y + 1;
|
||||||
|
|
||||||
// Write out the data to outDestination
|
// Write out the data to outDestination
|
||||||
// Construct and write Be bitmap header
|
// Construct and write Be bitmap header
|
||||||
TranslatorBitmap bitsHeader;
|
TranslatorBitmap bitsHeader;
|
||||||
@@ -148,11 +148,11 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
target->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
target->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
||||||
|
|
||||||
Array2D <Rgba> pixels(dataHeight, dataWidth);
|
Array2D <Rgba> pixels(dataHeight, dataWidth);
|
||||||
in.setFrameBuffer (&pixels[0][0] - dataWindow.min.y * dataWidth - dataWindow.min.x, 1, dataWidth);
|
in.setFrameBuffer (&pixels[0][0] - dataWindow.min.y * dataWidth - dataWindow.min.x, 1, dataWidth);
|
||||||
in.readPixels (dataWindow.min.y, dataWindow.max.y);
|
in.readPixels (dataWindow.min.y, dataWindow.max.y);
|
||||||
|
|
||||||
float _gamma = 0.4545f;
|
float _gamma = 0.4545f;
|
||||||
float _exposure = 0.0f;
|
float _exposure = 0.0f;
|
||||||
float _defog = 0.0f;
|
float _defog = 0.0f;
|
||||||
@@ -162,7 +162,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
float _fogR = 0.0f;
|
float _fogR = 0.0f;
|
||||||
float _fogG = 0.0f;
|
float _fogG = 0.0f;
|
||||||
float _fogB = 0.0f;
|
float _fogB = 0.0f;
|
||||||
|
|
||||||
halfFunction<float>
|
halfFunction<float>
|
||||||
rGamma (Gamma (_gamma,
|
rGamma (Gamma (_gamma,
|
||||||
_exposure,
|
_exposure,
|
||||||
@@ -171,7 +171,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
_kneeHigh),
|
_kneeHigh),
|
||||||
-HALF_MAX, HALF_MAX,
|
-HALF_MAX, HALF_MAX,
|
||||||
0.f, 255.f, 0.f, 0.f);
|
0.f, 255.f, 0.f, 0.f);
|
||||||
|
|
||||||
halfFunction<float>
|
halfFunction<float>
|
||||||
gGamma (Gamma (_gamma,
|
gGamma (Gamma (_gamma,
|
||||||
_exposure,
|
_exposure,
|
||||||
@@ -180,7 +180,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
_kneeHigh),
|
_kneeHigh),
|
||||||
-HALF_MAX, HALF_MAX,
|
-HALF_MAX, HALF_MAX,
|
||||||
0.f, 255.f, 0.f, 0.f);
|
0.f, 255.f, 0.f, 0.f);
|
||||||
|
|
||||||
halfFunction<float>
|
halfFunction<float>
|
||||||
bGamma (Gamma (_gamma,
|
bGamma (Gamma (_gamma,
|
||||||
_exposure,
|
_exposure,
|
||||||
@@ -189,7 +189,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
_kneeHigh),
|
_kneeHigh),
|
||||||
-HALF_MAX, HALF_MAX,
|
-HALF_MAX, HALF_MAX,
|
||||||
0.f, 255.f, 0.f, 0.f);
|
0.f, 255.f, 0.f, 0.f);
|
||||||
|
|
||||||
for (int y = displayWindow.min.y; y <= displayWindow.max.y; ++y) {
|
for (int y = displayWindow.min.y; y <= displayWindow.max.y; ++y) {
|
||||||
if (y < dataWindow.min.y
|
if (y < dataWindow.min.y
|
||||||
|| y > dataWindow.max.y) {
|
|| y > dataWindow.max.y) {
|
||||||
@@ -203,7 +203,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = displayWindow.min.x; x <= displayWindow.max.x; ++x) {
|
for (int x = displayWindow.min.x; x <= displayWindow.max.x; ++x) {
|
||||||
unsigned char sp[4];
|
unsigned char sp[4];
|
||||||
if (x < dataWindow.min.x
|
if (x < dataWindow.min.x
|
||||||
@@ -214,7 +214,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
sp[3] = 255;
|
sp[3] = 255;
|
||||||
} else {
|
} else {
|
||||||
const Imf::Rgba &rp = pixels[y][x];
|
const Imf::Rgba &rp = pixels[y][x];
|
||||||
|
|
||||||
sp[0] = (unsigned char)bGamma(rp.b);
|
sp[0] = (unsigned char)bGamma(rp.b);
|
||||||
sp[1] = (unsigned char)gGamma(rp.g);
|
sp[1] = (unsigned char)gGamma(rp.g);
|
||||||
sp[2] = (unsigned char)rGamma(rp.r);
|
sp[2] = (unsigned char)rGamma(rp.r);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ typedef struct my_hpgs_png_image_st {
|
|||||||
} my_hpgs_png_image;
|
} my_hpgs_png_image;
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
my_pim_write(hpgs_image *_this, const char *filename)
|
my_pim_write(hpgs_image *_this, const char *filename)
|
||||||
{
|
{
|
||||||
BPositionIO* target = ((my_hpgs_png_image *)_this)->target;
|
BPositionIO* target = ((my_hpgs_png_image *)_this)->target;
|
||||||
@@ -42,7 +42,7 @@ my_pim_write(hpgs_image *_this, const char *filename)
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
HPGS_IMAGE_FORMAT,
|
HPGS_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -54,7 +54,7 @@ translation_format sInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -66,7 +66,7 @@ translation_format sOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
@@ -109,7 +109,7 @@ HPGSTranslator::DerivedIdentify(BPositionIO *stream,
|
|||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
hpgs_istream *istream = hpgs_new_wrapper_istream(stream);
|
hpgs_istream *istream = hpgs_new_wrapper_istream(stream);
|
||||||
|
|
||||||
status_t err = B_OK;
|
status_t err = B_OK;
|
||||||
int verbosity = 1;
|
int verbosity = 1;
|
||||||
hpgs_bool multipage = HPGS_FALSE;
|
hpgs_bool multipage = HPGS_FALSE;
|
||||||
@@ -126,7 +126,7 @@ HPGSTranslator::DerivedIdentify(BPositionIO *stream,
|
|||||||
strcpy(info->MIME, "vector/x-hpgl2");
|
strcpy(info->MIME, "vector/x-hpgl2");
|
||||||
} else
|
} else
|
||||||
err = B_NO_TRANSLATOR;
|
err = B_NO_TRANSLATOR;
|
||||||
|
|
||||||
free(reader);
|
free(reader);
|
||||||
free(size_dev);
|
free(size_dev);
|
||||||
hpgs_free_wrapper_istream(istream);
|
hpgs_free_wrapper_istream(istream);
|
||||||
@@ -147,11 +147,11 @@ HPGSTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
|
|
||||||
status_t err = B_OK;
|
status_t err = B_OK;
|
||||||
hpgs_istream *istream = hpgs_new_wrapper_istream(source);
|
hpgs_istream *istream = hpgs_new_wrapper_istream(source);
|
||||||
|
|
||||||
TranslatorBitmap header;
|
TranslatorBitmap header;
|
||||||
ssize_t bytesWritten;
|
ssize_t bytesWritten;
|
||||||
uint32 dataSize;
|
uint32 dataSize;
|
||||||
|
|
||||||
double paper_angle = 180.0;
|
double paper_angle = 180.0;
|
||||||
double paper_border = 0.0;
|
double paper_border = 0.0;
|
||||||
double paper_width = 0.0;
|
double paper_width = 0.0;
|
||||||
@@ -201,7 +201,7 @@ HPGSTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
image->vtable->write = &my_pim_write;
|
image->vtable->write = &my_pim_write;
|
||||||
image = (hpgs_image *)realloc(image, sizeof(my_hpgs_png_image));
|
image = (hpgs_image *)realloc(image, sizeof(my_hpgs_png_image));
|
||||||
((my_hpgs_png_image *)image)->target = target;
|
((my_hpgs_png_image *)image)->target = target;
|
||||||
|
|
||||||
pdv = hpgs_new_paint_device(image, NULL, &bbox, antialias);
|
pdv = hpgs_new_paint_device(image, NULL, &bbox, antialias);
|
||||||
hpgs_paint_device_set_image_interpolation(pdv, image_interpolation);
|
hpgs_paint_device_set_image_interpolation(pdv, image_interpolation);
|
||||||
hpgs_paint_device_set_thin_alpha(pdv, thin_alpha);
|
hpgs_paint_device_set_thin_alpha(pdv, thin_alpha);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#define HVIF_TRANSLATION_QUALITY 1.0
|
#define HVIF_TRANSLATION_QUALITY 1.0
|
||||||
#define HVIF_TRANSLATION_CAPABILITY 1.0
|
#define HVIF_TRANSLATION_CAPABILITY 1.0
|
||||||
|
|
||||||
static translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
HVIF_FORMAT_CODE,
|
HVIF_FORMAT_CODE,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -33,7 +33,7 @@ static translation_format sInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -45,10 +45,15 @@ static translation_format sOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{ HVIF_SETTING_RENDER_SIZE, TRAN_SETTING_INT32, 64 }
|
{ HVIF_SETTING_RENDER_SIZE, TRAN_SETTING_INT32, 64 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BTranslator *
|
BTranslator *
|
||||||
make_nth_translator(int32 n, image_id image, uint32 flags, ...)
|
make_nth_translator(int32 n, image_id image, uint32 flags, ...)
|
||||||
@@ -60,13 +65,13 @@ make_nth_translator(int32 n, image_id image, uint32 flags, ...)
|
|||||||
|
|
||||||
|
|
||||||
HVIFTranslator::HVIFTranslator()
|
HVIFTranslator::HVIFTranslator()
|
||||||
: BaseTranslator("HVIF icons", "Native Haiku vector icon translator",
|
: BaseTranslator("HVIF icons", "Native Haiku vector icon translator",
|
||||||
HVIF_TRANSLATOR_VERSION, sInputFormats,
|
HVIF_TRANSLATOR_VERSION,
|
||||||
sizeof(sInputFormats) / sizeof(sInputFormats[0]), sOutputFormats,
|
sInputFormats, kNumInputFormats,
|
||||||
sizeof(sOutputFormats) / sizeof(sOutputFormats[0]),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"HVIFTranslator_Settings", sDefaultSettings,
|
"HVIFTranslator_Settings",
|
||||||
sizeof(sDefaultSettings) / sizeof(sDefaultSettings[0]),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_BITMAP, HVIF_FORMAT_CODE)
|
B_TRANSLATOR_BITMAP, HVIF_FORMAT_CODE)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const char *kDocumentIndex = "/documentIndex";
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
ICO_IMAGE_FORMAT,
|
ICO_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -41,7 +41,7 @@ translation_format sInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
ICO_IMAGE_FORMAT,
|
ICO_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -61,7 +61,7 @@ translation_format sOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
|
|
||||||
// Translation Kit required globals
|
// Translation Kit required globals
|
||||||
char gTranslatorName[] = "JPEG images";
|
static char sTranslatorName[] = "JPEG images";
|
||||||
char gTranslatorInfo[] =
|
static char sTranslatorInfo[] =
|
||||||
"©2002-2003, Marcin Konicki\n"
|
"©2002-2003, Marcin Konicki\n"
|
||||||
"©2005-2007, Haiku\n"
|
"©2005-2007, Haiku\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -69,28 +69,26 @@ char gTranslatorInfo[] =
|
|||||||
"With some colorspace conversion routines by Magnus Hellman\n"
|
"With some colorspace conversion routines by Magnus Hellman\n"
|
||||||
" http://www.bebits.com/app/802\n";
|
" http://www.bebits.com/app/802\n";
|
||||||
|
|
||||||
int32 gTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 2, 0);
|
static const int32 sTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 2, 0);
|
||||||
|
|
||||||
// Define the formats we know how to read
|
// Define the formats we know how to read
|
||||||
const translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{ JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
JPEG_MIME_STRING, JPEG_DESCRIPTION },
|
JPEG_MIME_STRING, JPEG_DESCRIPTION },
|
||||||
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }
|
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }
|
||||||
};
|
};
|
||||||
const int gInputFormatCount = sizeof(gInputFormats) / sizeof(translation_format);
|
|
||||||
|
|
||||||
// Define the formats we know how to write
|
// Define the formats we know how to write
|
||||||
const translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{ JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
JPEG_MIME_STRING, JPEG_DESCRIPTION },
|
JPEG_MIME_STRING, JPEG_DESCRIPTION },
|
||||||
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }
|
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION }
|
||||||
};
|
};
|
||||||
const int gOutputFormatCount = sizeof(gOutputFormats) / sizeof(translation_format);
|
|
||||||
|
|
||||||
|
|
||||||
TranSetting gSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{JPEG_SET_SMOOTHING, TRAN_SETTING_INT32, 0},
|
{JPEG_SET_SMOOTHING, TRAN_SETTING_INT32, 0},
|
||||||
{JPEG_SET_QUALITY, TRAN_SETTING_INT32, 95},
|
{JPEG_SET_QUALITY, TRAN_SETTING_INT32, 95},
|
||||||
{JPEG_SET_PROGRESSIVE, TRAN_SETTING_BOOL, true},
|
{JPEG_SET_PROGRESSIVE, TRAN_SETTING_BOOL, true},
|
||||||
@@ -101,7 +99,10 @@ TranSetting gSettings[] = {
|
|||||||
{JPEG_SET_PHOTOSHOP_CMYK, TRAN_SETTING_BOOL, true},
|
{JPEG_SET_PHOTOSHOP_CMYK, TRAN_SETTING_BOOL, true},
|
||||||
{JPEG_SET_SHOWREADWARNING, TRAN_SETTING_BOOL, true}
|
{JPEG_SET_SHOWREADWARNING, TRAN_SETTING_BOOL, true}
|
||||||
};
|
};
|
||||||
const int gSettingsCount = sizeof(gSettings) / sizeof(TranSetting);
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
namespace conversion {
|
namespace conversion {
|
||||||
@@ -658,19 +659,19 @@ TranslatorAboutView::TranslatorAboutView(const char* name)
|
|||||||
BView(name, 0, new BGroupLayout(B_VERTICAL))
|
BView(name, 0, new BGroupLayout(B_VERTICAL))
|
||||||
{
|
{
|
||||||
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
|
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
|
||||||
BStringView* title = new BStringView("Title", gTranslatorName);
|
BStringView* title = new BStringView("Title", sTranslatorName);
|
||||||
title->SetFont(be_bold_font);
|
title->SetFont(be_bold_font);
|
||||||
title->SetExplicitAlignment(labelAlignment);
|
title->SetExplicitAlignment(labelAlignment);
|
||||||
|
|
||||||
char versionString[16];
|
char versionString[16];
|
||||||
sprintf(versionString, "v%d.%d.%d", (int)(gTranslatorVersion >> 8),
|
sprintf(versionString, "v%d.%d.%d", (int)(sTranslatorVersion >> 8),
|
||||||
(int)((gTranslatorVersion >> 4) & 0xf), (int)(gTranslatorVersion & 0xf));
|
(int)((sTranslatorVersion >> 4) & 0xf), (int)(sTranslatorVersion & 0xf));
|
||||||
|
|
||||||
BStringView* version = new BStringView("Version", versionString);
|
BStringView* version = new BStringView("Version", versionString);
|
||||||
version->SetExplicitAlignment(labelAlignment);
|
version->SetExplicitAlignment(labelAlignment);
|
||||||
|
|
||||||
BTextView* infoView = new BTextView("info");
|
BTextView* infoView = new BTextView("info");
|
||||||
infoView->SetText(gTranslatorInfo);
|
infoView->SetText(sTranslatorInfo);
|
||||||
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
infoView->MakeEditable(false);
|
infoView->MakeEditable(false);
|
||||||
|
|
||||||
@@ -1293,11 +1294,12 @@ JPEGTranslator::Error(j_common_ptr cinfo, status_t error)
|
|||||||
|
|
||||||
|
|
||||||
JPEGTranslator::JPEGTranslator()
|
JPEGTranslator::JPEGTranslator()
|
||||||
:
|
: BaseTranslator(sTranslatorName, sTranslatorInfo, sTranslatorVersion,
|
||||||
BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion,
|
sInputFormats, kNumInputFormats,
|
||||||
gInputFormats, gInputFormatCount, gOutputFormats, gOutputFormatCount,
|
sOutputFormats, kNumOutputFormats,
|
||||||
SETTINGS_FILE, gSettings, gSettingsCount,
|
SETTINGS_FILE,
|
||||||
B_TRANSLATOR_BITMAP, JPEG_FORMAT)
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
|
B_TRANSLATOR_BITMAP, JPEG_FORMAT)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@@ -1316,7 +1318,7 @@ main(int, char**)
|
|||||||
{
|
{
|
||||||
BApplication app("application/x-vnd.Haiku-JPEGTranslator");
|
BApplication app("application/x-vnd.Haiku-JPEGTranslator");
|
||||||
JPEGTranslator* translator = new JPEGTranslator();
|
JPEGTranslator* translator = new JPEGTranslator();
|
||||||
if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK)
|
if (LaunchTranslatorWindow(translator, sTranslatorName) == B_OK)
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define B_TRANSLATOR_BITMAP_MIME_STRING "image/x-be-bitmap"
|
#define B_TRANSLATOR_BITMAP_MIME_STRING "image/x-be-bitmap"
|
||||||
#define B_TRANSLATOR_BITMAP_DESCRIPTION "Be Bitmap Format (JPEG2000Translator)"
|
#define B_TRANSLATOR_BITMAP_DESCRIPTION "Be Bitmap Format (JPEG2000Translator)"
|
||||||
|
|
||||||
const char gTranslatorName[] = "JPEG2000 images";
|
static const char sTranslatorName[] = "JPEG2000 images";
|
||||||
const char gTranslatorInfo[] = "©2002-2003, Shard\n"
|
static const char sTranslatorInfo[] = "©2002-2003, Shard\n"
|
||||||
"©2005-2006, Haiku\n"
|
"©2005-2006, Haiku\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Based on JasPer library:\n"
|
"Based on JasPer library:\n"
|
||||||
@@ -63,34 +63,33 @@ const char gTranslatorInfo[] = "©2002-2003, Shard\n"
|
|||||||
"ImageMagick's jp2 codec was used as \"tutorial\".\n"
|
"ImageMagick's jp2 codec was used as \"tutorial\".\n"
|
||||||
" http://www.imagemagick.org/\n";
|
" http://www.imagemagick.org/\n";
|
||||||
|
|
||||||
int32 gTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 0, 0);
|
static int32 sTranslatorVersion = B_TRANSLATION_MAKE_VERSION(1, 0, 0);
|
||||||
|
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{ JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
JP2_MIME_STRING, JP2_DESCRIPTION },
|
JP2_MIME_STRING, JP2_DESCRIPTION },
|
||||||
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
|
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
|
||||||
};
|
};
|
||||||
const int gInputFormatCount =
|
|
||||||
sizeof(gInputFormats) / sizeof(translation_format);
|
|
||||||
|
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{ JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ JP2_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
JP2_MIME_STRING, JP2_DESCRIPTION },
|
JP2_MIME_STRING, JP2_DESCRIPTION },
|
||||||
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
|
||||||
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
|
B_TRANSLATOR_BITMAP_MIME_STRING, B_TRANSLATOR_BITMAP_DESCRIPTION },
|
||||||
};
|
};
|
||||||
const int gOutputFormatCount =
|
|
||||||
sizeof(gOutputFormats) / sizeof(translation_format);
|
|
||||||
|
|
||||||
|
|
||||||
TranSetting gSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{JP2_SET_QUALITY, TRAN_SETTING_INT32, 25},
|
{JP2_SET_QUALITY, TRAN_SETTING_INT32, 25},
|
||||||
{JP2_SET_JPC, TRAN_SETTING_BOOL, false},
|
{JP2_SET_JPC, TRAN_SETTING_BOOL, false},
|
||||||
{JP2_SET_GRAY1_AS_B_RGB24, TRAN_SETTING_BOOL, false},
|
{JP2_SET_GRAY1_AS_B_RGB24, TRAN_SETTING_BOOL, false},
|
||||||
{JP2_SET_GRAY8_AS_B_RGB32, TRAN_SETTING_BOOL, true}
|
{JP2_SET_GRAY8_AS_B_RGB32, TRAN_SETTING_BOOL, true}
|
||||||
};
|
};
|
||||||
const int gSettingsCount = sizeof(gSettings) / sizeof(TranSetting) ;
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
namespace conversion{
|
namespace conversion{
|
||||||
@@ -492,7 +491,7 @@ static jas_stream_ops_t positionIOops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static jas_stream_t*
|
static jas_stream_t*
|
||||||
jas_stream_positionIOopen(BPositionIO *positionIO)
|
jas_stream_positionIOopen(BPositionIO *positionIO)
|
||||||
{
|
{
|
||||||
jas_stream_t* stream;
|
jas_stream_t* stream;
|
||||||
@@ -628,7 +627,7 @@ TranslatorWriteView::TranslatorWriteView(const char* name,
|
|||||||
new BMessage(VIEW_MSG_SET_JPC));
|
new BMessage(VIEW_MSG_SET_JPC));
|
||||||
if (fSettings->SetGetBool(JP2_SET_JPC))
|
if (fSettings->SetGetBool(JP2_SET_JPC))
|
||||||
fCodeStreamOnly->SetValue(B_CONTROL_ON);
|
fCodeStreamOnly->SetValue(B_CONTROL_ON);
|
||||||
|
|
||||||
float padding = 10.0f;
|
float padding = 10.0f;
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
|
||||||
.Add(fQualitySlider)
|
.Add(fQualitySlider)
|
||||||
@@ -703,22 +702,22 @@ TranslatorAboutView::TranslatorAboutView(const char* name)
|
|||||||
BView(name, 0, new BGroupLayout(B_VERTICAL))
|
BView(name, 0, new BGroupLayout(B_VERTICAL))
|
||||||
{
|
{
|
||||||
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
|
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
|
||||||
BStringView* title = new BStringView("Title", gTranslatorName);
|
BStringView* title = new BStringView("Title", sTranslatorName);
|
||||||
title->SetFont(be_bold_font);
|
title->SetFont(be_bold_font);
|
||||||
title->SetExplicitAlignment(labelAlignment);
|
title->SetExplicitAlignment(labelAlignment);
|
||||||
|
|
||||||
char versionString[16];
|
char versionString[16];
|
||||||
sprintf(versionString, "v%d.%d.%d", (int)(gTranslatorVersion >> 8),
|
sprintf(versionString, "v%d.%d.%d", (int)(sTranslatorVersion >> 8),
|
||||||
(int)((gTranslatorVersion >> 4) & 0xf), (int)(gTranslatorVersion & 0xf));
|
(int)((sTranslatorVersion >> 4) & 0xf), (int)(sTranslatorVersion & 0xf));
|
||||||
|
|
||||||
BStringView* version = new BStringView("Version", versionString);
|
BStringView* version = new BStringView("Version", versionString);
|
||||||
version->SetExplicitAlignment(labelAlignment);
|
version->SetExplicitAlignment(labelAlignment);
|
||||||
|
|
||||||
BTextView* infoView = new BTextView("info");
|
BTextView* infoView = new BTextView("info");
|
||||||
infoView->SetText(gTranslatorInfo);
|
infoView->SetText(sTranslatorInfo);
|
||||||
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
infoView->MakeEditable(false);
|
infoView->MakeEditable(false);
|
||||||
|
|
||||||
float padding = 10.0f;
|
float padding = 10.0f;
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
|
||||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
|
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
|
||||||
@@ -763,11 +762,12 @@ JP2Translator::NewConfigView(TranslatorSettings* settings)
|
|||||||
|
|
||||||
|
|
||||||
JP2Translator::JP2Translator()
|
JP2Translator::JP2Translator()
|
||||||
:
|
: BaseTranslator(sTranslatorName, sTranslatorInfo, sTranslatorVersion,
|
||||||
BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion,
|
sInputFormats, kNumInputFormats,
|
||||||
gInputFormats, gInputFormatCount,
|
sOutputFormats, kNumOutputFormats,
|
||||||
gOutputFormats, gOutputFormatCount, JP2_SETTINGS_FILE,
|
JP2_SETTINGS_FILE,
|
||||||
gSettings, gSettingsCount, B_TRANSLATOR_BITMAP, JP2_FORMAT)
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
|
B_TRANSLATOR_BITMAP, JP2_FORMAT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1048,7 +1048,7 @@ JP2Translator::Compress(BPositionIO* in, BPositionIO* out)
|
|||||||
(float)fSettings->SetGetInt32(JP2_SET_QUALITY) / 100.0);
|
(float)fSettings->SetGetInt32(JP2_SET_QUALITY) / 100.0);
|
||||||
|
|
||||||
if (jas_image_encode(image, outs, jas_image_strtofmt(
|
if (jas_image_encode(image, outs, jas_image_strtofmt(
|
||||||
fSettings->SetGetBool(JP2_SET_JPC) ?
|
fSettings->SetGetBool(JP2_SET_JPC) ?
|
||||||
(char*)"jpc" : (char*)"jp2"), opts)) {
|
(char*)"jpc" : (char*)"jp2"), opts)) {
|
||||||
return Error(outs, image, pixels,
|
return Error(outs, image, pixels,
|
||||||
out_color_components, in_scanline, err);
|
out_color_components, in_scanline, err);
|
||||||
@@ -1287,7 +1287,7 @@ main()
|
|||||||
{
|
{
|
||||||
BApplication app("application/x-vnd.Haiku-JPEG2000Translator");
|
BApplication app("application/x-vnd.Haiku-JPEG2000Translator");
|
||||||
JP2Translator* translator = new JP2Translator();
|
JP2Translator* translator = new JP2Translator();
|
||||||
if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK)
|
if (LaunchTranslatorWindow(translator, sTranslatorName) == B_OK)
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
PCX_IMAGE_FORMAT,
|
PCX_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -38,7 +38,7 @@ translation_format sInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
/*{
|
/*{
|
||||||
PCX_IMAGE_FORMAT,
|
PCX_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -58,7 +58,7 @@ translation_format sOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
// PNGTranslator.cpp
|
// PNGTranslator.cpp
|
||||||
//
|
//
|
||||||
// This BTranslator based object is for opening and writing
|
// This BTranslator based object is for opening and writing
|
||||||
// PNG images.
|
// PNG images.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -14,18 +14,18 @@
|
|||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
// to deal in the Software without restriction, including without limitation
|
// to deal in the Software without restriction, including without limitation
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// and/or sell copies of the Software, and to permit persons to whom the
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
// Software is furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included
|
// The above copyright notice and this permission notice shall be included
|
||||||
// in all copies or substantial portions of the Software.
|
// in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
#include "PNGView.h"
|
#include "PNGView.h"
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
B_PNG_FORMAT,
|
B_PNG_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -67,7 +67,7 @@ translation_format gInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_PNG_FORMAT,
|
B_PNG_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -87,13 +87,18 @@ translation_format gOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
TranSetting gDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{PNG_SETTING_INTERLACE, TRAN_SETTING_INT32, PNG_INTERLACE_NONE}
|
{PNG_SETTING_INTERLACE, TRAN_SETTING_INT32, PNG_INTERLACE_NONE}
|
||||||
// interlacing is off by default
|
// interlacing is off by default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// make_nth_translator
|
// make_nth_translator
|
||||||
//
|
//
|
||||||
@@ -141,7 +146,7 @@ BPositionIO *
|
|||||||
get_pio(png_structp ppng)
|
get_pio(png_structp ppng)
|
||||||
{
|
{
|
||||||
BPositionIO *pio = NULL;
|
BPositionIO *pio = NULL;
|
||||||
pio = static_cast<BPositionIO *>(png_get_io_ptr(ppng));
|
pio = static_cast<BPositionIO *>(png_get_io_ptr(ppng));
|
||||||
return pio;
|
return pio;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,10 +187,10 @@ pngcb_flush_data(png_structp ppng)
|
|||||||
PNGTranslator::PNGTranslator()
|
PNGTranslator::PNGTranslator()
|
||||||
: BaseTranslator("PNG images", "PNG image translator",
|
: BaseTranslator("PNG images", "PNG image translator",
|
||||||
PNG_TRANSLATOR_VERSION,
|
PNG_TRANSLATOR_VERSION,
|
||||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
sInputFormats, kNumInputFormats,
|
||||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"PNGTranslator_Settings",
|
"PNGTranslator_Settings",
|
||||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_BITMAP, B_PNG_FORMAT)
|
B_TRANSLATOR_BITMAP, B_PNG_FORMAT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -213,7 +218,7 @@ identify_png_header(BPositionIO *inSource, translator_info *outInfo)
|
|||||||
const int32 kSigSize = 8;
|
const int32 kSigSize = 8;
|
||||||
uint8 buf[kSigSize];
|
uint8 buf[kSigSize];
|
||||||
if (inSource->Read(buf, kSigSize) != kSigSize)
|
if (inSource->Read(buf, kSigSize) != kSigSize)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
if (png_sig_cmp(buf, 0, kSigSize))
|
if (png_sig_cmp(buf, 0, kSigSize))
|
||||||
// if first 8 bytes of stream don't match PNG signature bail
|
// if first 8 bytes of stream don't match PNG signature bail
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
@@ -226,10 +231,10 @@ identify_png_header(BPositionIO *inSource, translator_info *outInfo)
|
|||||||
strcpy(outInfo->MIME, "image/png");
|
strcpy(outInfo->MIME, "image/png");
|
||||||
strcpy(outInfo->name, "PNG image");
|
strcpy(outInfo->name, "PNG image");
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// DerivedIdentify
|
// DerivedIdentify
|
||||||
//
|
//
|
||||||
@@ -288,13 +293,13 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
|||||||
// if a libpng errors before this is set
|
// if a libpng errors before this is set
|
||||||
// to a different value, the above is what
|
// to a different value, the above is what
|
||||||
// will be returned from this function
|
// will be returned from this function
|
||||||
|
|
||||||
bool bheaderonly = false, bdataonly = false;
|
bool bheaderonly = false, bdataonly = false;
|
||||||
|
|
||||||
// for storing decoded PNG row data
|
// for storing decoded PNG row data
|
||||||
uint8 **prows = NULL, *prow = NULL;
|
uint8 **prows = NULL, *prow = NULL;
|
||||||
png_uint_32 nalloc = 0;
|
png_uint_32 nalloc = 0;
|
||||||
|
|
||||||
png_structp ppng = NULL;
|
png_structp ppng = NULL;
|
||||||
png_infop pinfo = NULL;
|
png_infop pinfo = NULL;
|
||||||
while (ppng == NULL) {
|
while (ppng == NULL) {
|
||||||
@@ -312,67 +317,67 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
|||||||
// the longjmp function to continue execution
|
// the longjmp function to continue execution
|
||||||
// from this point
|
// from this point
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// set read callback function
|
// set read callback function
|
||||||
png_set_read_fn(ppng, static_cast<void *>(inSource), pngcb_read_data);
|
png_set_read_fn(ppng, static_cast<void *>(inSource), pngcb_read_data);
|
||||||
|
|
||||||
// Read in PNG image info
|
// Read in PNG image info
|
||||||
png_set_sig_bytes(ppng, 8);
|
png_set_sig_bytes(ppng, 8);
|
||||||
png_read_info(ppng, pinfo);
|
png_read_info(ppng, pinfo);
|
||||||
|
|
||||||
png_uint_32 width, height;
|
png_uint_32 width, height;
|
||||||
int bit_depth, color_type, interlace_type;
|
int bit_depth, color_type, interlace_type;
|
||||||
png_get_IHDR(ppng, pinfo, &width, &height, &bit_depth, &color_type,
|
png_get_IHDR(ppng, pinfo, &width, &height, &bit_depth, &color_type,
|
||||||
&interlace_type, NULL, NULL);
|
&interlace_type, NULL, NULL);
|
||||||
|
|
||||||
// Setup image transformations to make converting it easier
|
// Setup image transformations to make converting it easier
|
||||||
bool balpha = false;
|
bool balpha = false;
|
||||||
|
|
||||||
if (bit_depth == 16)
|
if (bit_depth == 16)
|
||||||
png_set_strip_16(ppng);
|
png_set_strip_16(ppng);
|
||||||
else if (bit_depth < 8)
|
else if (bit_depth < 8)
|
||||||
png_set_packing(ppng);
|
png_set_packing(ppng);
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
png_set_palette_to_rgb(ppng);
|
png_set_palette_to_rgb(ppng);
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||||
// In order to convert from low-depth gray images to RGB,
|
// In order to convert from low-depth gray images to RGB,
|
||||||
// I first need to convert them to grayscale, 8 bpp
|
// I first need to convert them to grayscale, 8 bpp
|
||||||
png_set_expand_gray_1_2_4_to_8(ppng);
|
png_set_expand_gray_1_2_4_to_8(ppng);
|
||||||
|
|
||||||
if (png_get_valid(ppng, pinfo, PNG_INFO_tRNS)) {
|
if (png_get_valid(ppng, pinfo, PNG_INFO_tRNS)) {
|
||||||
// if there is transparency data in the
|
// if there is transparency data in the
|
||||||
// PNG, but not in the form of an alpha channel
|
// PNG, but not in the form of an alpha channel
|
||||||
balpha = true;
|
balpha = true;
|
||||||
png_set_tRNS_to_alpha(ppng);
|
png_set_tRNS_to_alpha(ppng);
|
||||||
}
|
}
|
||||||
|
|
||||||
// change RGB to BGR as it is in 'bits'
|
// change RGB to BGR as it is in 'bits'
|
||||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||||
png_set_bgr(ppng);
|
png_set_bgr(ppng);
|
||||||
|
|
||||||
// have libpng convert gray to RGB for me
|
// have libpng convert gray to RGB for me
|
||||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
png_set_gray_to_rgb(ppng);
|
png_set_gray_to_rgb(ppng);
|
||||||
|
|
||||||
if (color_type & PNG_COLOR_MASK_ALPHA)
|
if (color_type & PNG_COLOR_MASK_ALPHA)
|
||||||
// if image contains an alpha channel
|
// if image contains an alpha channel
|
||||||
balpha = true;
|
balpha = true;
|
||||||
|
|
||||||
if (!balpha)
|
if (!balpha)
|
||||||
// add filler byte for images without alpha
|
// add filler byte for images without alpha
|
||||||
// so that the pixels are 4 bytes each
|
// so that the pixels are 4 bytes each
|
||||||
png_set_filler(ppng, 0xff, PNG_FILLER_AFTER);
|
png_set_filler(ppng, 0xff, PNG_FILLER_AFTER);
|
||||||
|
|
||||||
// Check that transformed PNG rowbytes matches
|
// Check that transformed PNG rowbytes matches
|
||||||
// what is expected
|
// what is expected
|
||||||
const int32 kbytes = 4;
|
const int32 kbytes = 4;
|
||||||
png_uint_32 rowbytes = png_get_rowbytes(ppng, pinfo);
|
png_uint_32 rowbytes = png_get_rowbytes(ppng, pinfo);
|
||||||
if (rowbytes < kbytes * width)
|
if (rowbytes < kbytes * width)
|
||||||
rowbytes = kbytes * width;
|
rowbytes = kbytes * width;
|
||||||
|
|
||||||
if (!bdataonly) {
|
if (!bdataonly) {
|
||||||
// Write out the data to outDestination
|
// Write out the data to outDestination
|
||||||
// Construct and write Be bitmap header
|
// Construct and write Be bitmap header
|
||||||
@@ -394,13 +399,13 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
||||||
|
|
||||||
if (bheaderonly) {
|
if (bheaderonly) {
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interlace_type == PNG_INTERLACE_NONE) {
|
if (interlace_type == PNG_INTERLACE_NONE) {
|
||||||
// allocate buffer for storing PNG row
|
// allocate buffer for storing PNG row
|
||||||
prow = new uint8[rowbytes];
|
prow = new uint8[rowbytes];
|
||||||
@@ -416,13 +421,13 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
|||||||
// Set OK status here, because, in the event of
|
// Set OK status here, because, in the event of
|
||||||
// an error, png_read_end() will longjmp to error
|
// an error, png_read_end() will longjmp to error
|
||||||
// handler above and not execute lines below it
|
// handler above and not execute lines below it
|
||||||
|
|
||||||
// finish reading, pass NULL for info because I
|
// finish reading, pass NULL for info because I
|
||||||
// don't need the extra data
|
// don't need the extra data
|
||||||
png_read_end(ppng, NULL);
|
png_read_end(ppng, NULL);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// interlaced PNG image
|
// interlaced PNG image
|
||||||
prows = new uint8 *[height];
|
prows = new uint8 *[height];
|
||||||
@@ -436,30 +441,30 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
|||||||
if (!prows[nalloc])
|
if (!prows[nalloc])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nalloc < height)
|
if (nalloc < height)
|
||||||
result = B_NO_MEMORY;
|
result = B_NO_MEMORY;
|
||||||
else {
|
else {
|
||||||
png_read_image(ppng, prows);
|
png_read_image(ppng, prows);
|
||||||
|
|
||||||
for (png_uint_32 i = 0; i < height; i++)
|
for (png_uint_32 i = 0; i < height; i++)
|
||||||
outDestination->Write(prows[i], width * kbytes);
|
outDestination->Write(prows[i], width * kbytes);
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
// Set OK status here, because, in the event of
|
// Set OK status here, because, in the event of
|
||||||
// an error, png_read_end() will longjmp to error
|
// an error, png_read_end() will longjmp to error
|
||||||
// handler above and not execute lines below it
|
// handler above and not execute lines below it
|
||||||
|
|
||||||
png_read_end(ppng, NULL);
|
png_read_end(ppng, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ppng) {
|
if (ppng) {
|
||||||
delete[] prow;
|
delete[] prow;
|
||||||
prow = NULL;
|
prow = NULL;
|
||||||
|
|
||||||
// delete row pointers and array of pointers to rows
|
// delete row pointers and array of pointers to rows
|
||||||
while (nalloc) {
|
while (nalloc) {
|
||||||
nalloc--;
|
nalloc--;
|
||||||
@@ -467,7 +472,7 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
|||||||
}
|
}
|
||||||
delete[] prows;
|
delete[] prows;
|
||||||
prows = NULL;
|
prows = NULL;
|
||||||
|
|
||||||
// free PNG handle / info structures
|
// free PNG handle / info structures
|
||||||
if (!pinfo)
|
if (!pinfo)
|
||||||
png_destroy_read_struct(&ppng, NULL, NULL);
|
png_destroy_read_struct(&ppng, NULL, NULL);
|
||||||
@@ -499,13 +504,13 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
{
|
{
|
||||||
status_t bytescopied = 0;
|
status_t bytescopied = 0;
|
||||||
uint16 val;
|
uint16 val;
|
||||||
|
|
||||||
switch (fromspace) {
|
switch (fromspace) {
|
||||||
case B_RGBA32:
|
case B_RGBA32:
|
||||||
bytescopied = width * bitsBytesPerPixel;
|
bytescopied = width * bitsBytesPerPixel;
|
||||||
memcpy(ppng, pbits, bytescopied);
|
memcpy(ppng, pbits, bytescopied);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
case B_RGB24:
|
case B_RGB24:
|
||||||
bytescopied = width * bitsBytesPerPixel;
|
bytescopied = width * bitsBytesPerPixel;
|
||||||
@@ -515,7 +520,7 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
pbits += bitsBytesPerPixel;
|
pbits += bitsBytesPerPixel;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGBA32_BIG:
|
case B_RGBA32_BIG:
|
||||||
bytescopied = width * 4;
|
bytescopied = width * 4;
|
||||||
while (width--) {
|
while (width--) {
|
||||||
@@ -523,12 +528,12 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
ppng[1] = pbits[2];
|
ppng[1] = pbits[2];
|
||||||
ppng[2] = pbits[1];
|
ppng[2] = pbits[1];
|
||||||
ppng[3] = pbits[0];
|
ppng[3] = pbits[0];
|
||||||
|
|
||||||
ppng += 4;
|
ppng += 4;
|
||||||
pbits += 4;
|
pbits += 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMYA32:
|
case B_CMYA32:
|
||||||
bytescopied = width * 4;
|
bytescopied = width * 4;
|
||||||
while (width--) {
|
while (width--) {
|
||||||
@@ -536,32 +541,32 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
ppng[1] = 255 - pbits[1];
|
ppng[1] = 255 - pbits[1];
|
||||||
ppng[2] = 255 - pbits[0];
|
ppng[2] = 255 - pbits[0];
|
||||||
ppng[3] = pbits[3];
|
ppng[3] = pbits[3];
|
||||||
|
|
||||||
ppng += 4;
|
ppng += 4;
|
||||||
pbits += 4;
|
pbits += 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMYK32:
|
case B_CMYK32:
|
||||||
{
|
{
|
||||||
int32 comp;
|
int32 comp;
|
||||||
bytescopied = width * 3;
|
bytescopied = width * 3;
|
||||||
while (width--) {
|
while (width--) {
|
||||||
comp = 255 - pbits[2] - pbits[3];
|
comp = 255 - pbits[2] - pbits[3];
|
||||||
ppng[0] = (comp < 0) ? 0 : comp;
|
ppng[0] = (comp < 0) ? 0 : comp;
|
||||||
|
|
||||||
comp = 255 - pbits[1] - pbits[3];
|
comp = 255 - pbits[1] - pbits[3];
|
||||||
ppng[1] = (comp < 0) ? 0 : comp;
|
ppng[1] = (comp < 0) ? 0 : comp;
|
||||||
|
|
||||||
comp = 255 - pbits[0] - pbits[3];
|
comp = 255 - pbits[0] - pbits[3];
|
||||||
ppng[2] = (comp < 0) ? 0 : comp;
|
ppng[2] = (comp < 0) ? 0 : comp;
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits += 4;
|
pbits += 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_CMY32:
|
case B_CMY32:
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
bytescopied = width * 3;
|
bytescopied = width * 3;
|
||||||
@@ -569,12 +574,12 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
ppng[0] = 255 - pbits[2];
|
ppng[0] = 255 - pbits[2];
|
||||||
ppng[1] = 255 - pbits[1];
|
ppng[1] = 255 - pbits[1];
|
||||||
ppng[2] = 255 - pbits[0];
|
ppng[2] = 255 - pbits[0];
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits += bitsBytesPerPixel;
|
pbits += bitsBytesPerPixel;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
bytescopied = width * 3;
|
bytescopied = width * 3;
|
||||||
@@ -590,7 +595,7 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);
|
((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);
|
||||||
ppng[2] =
|
ppng[2] =
|
||||||
((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);
|
((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits += 2;
|
pbits += 2;
|
||||||
}
|
}
|
||||||
@@ -604,18 +609,18 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
val = pbits[0] + (pbits[1] << 8);
|
val = pbits[0] + (pbits[1] << 8);
|
||||||
else
|
else
|
||||||
val = pbits[1] + (pbits[0] << 8);
|
val = pbits[1] + (pbits[0] << 8);
|
||||||
ppng[0] =
|
ppng[0] =
|
||||||
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
ppng[1] =
|
ppng[1] =
|
||||||
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
ppng[2] =
|
ppng[2] =
|
||||||
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits += 2;
|
pbits += 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGBA15:
|
case B_RGBA15:
|
||||||
case B_RGBA15_BIG:
|
case B_RGBA15_BIG:
|
||||||
bytescopied = width * 4;
|
bytescopied = width * 4;
|
||||||
@@ -624,43 +629,43 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
val = pbits[0] + (pbits[1] << 8);
|
val = pbits[0] + (pbits[1] << 8);
|
||||||
else
|
else
|
||||||
val = pbits[1] + (pbits[0] << 8);
|
val = pbits[1] + (pbits[0] << 8);
|
||||||
ppng[0] =
|
ppng[0] =
|
||||||
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
ppng[1] =
|
ppng[1] =
|
||||||
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
ppng[2] =
|
ppng[2] =
|
||||||
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
ppng[3] = (val & 0x8000) ? 255 : 0;
|
ppng[3] = (val & 0x8000) ? 255 : 0;
|
||||||
|
|
||||||
ppng += 4;
|
ppng += 4;
|
||||||
pbits += 2;
|
pbits += 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB32_BIG:
|
case B_RGB32_BIG:
|
||||||
bytescopied = width * 3;
|
bytescopied = width * 3;
|
||||||
while (width--) {
|
while (width--) {
|
||||||
ppng[0] = pbits[3];
|
ppng[0] = pbits[3];
|
||||||
ppng[1] = pbits[2];
|
ppng[1] = pbits[2];
|
||||||
ppng[2] = pbits[1];
|
ppng[2] = pbits[1];
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits += 4;
|
pbits += 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB24_BIG:
|
case B_RGB24_BIG:
|
||||||
bytescopied = width * 3;
|
bytescopied = width * 3;
|
||||||
while (width--) {
|
while (width--) {
|
||||||
ppng[0] = pbits[2];
|
ppng[0] = pbits[2];
|
||||||
ppng[1] = pbits[1];
|
ppng[1] = pbits[1];
|
||||||
ppng[2] = pbits[0];
|
ppng[2] = pbits[0];
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits += 3;
|
pbits += 3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
{
|
{
|
||||||
rgb_color c;
|
rgb_color c;
|
||||||
@@ -670,23 +675,23 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
|
|||||||
ppng[0] = c.blue;
|
ppng[0] = c.blue;
|
||||||
ppng[1] = c.green;
|
ppng[1] = c.green;
|
||||||
ppng[2] = c.red;
|
ppng[2] = c.red;
|
||||||
|
|
||||||
ppng += 3;
|
ppng += 3;
|
||||||
pbits++;
|
pbits++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
bytescopied = width;
|
bytescopied = width;
|
||||||
memcpy(ppng, pbits, bytescopied);
|
memcpy(ppng, pbits, bytescopied);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
bytescopied = B_ERROR;
|
bytescopied = B_ERROR;
|
||||||
break;
|
break;
|
||||||
} // switch (fromspace)
|
} // switch (fromspace)
|
||||||
|
|
||||||
return bytescopied;
|
return bytescopied;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -695,24 +700,24 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
BPositionIO *outDestination)
|
BPositionIO *outDestination)
|
||||||
{
|
{
|
||||||
TranslatorBitmap bitsHeader;
|
TranslatorBitmap bitsHeader;
|
||||||
|
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
const color_map *pmap = NULL;
|
const color_map *pmap = NULL;
|
||||||
if (bitsHeader.colors == B_CMAP8) {
|
if (bitsHeader.colors == B_CMAP8) {
|
||||||
pmap = system_colors();
|
pmap = system_colors();
|
||||||
if (!pmap)
|
if (!pmap)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_uint_32 width, height;
|
png_uint_32 width, height;
|
||||||
width = static_cast<png_uint_32>(bitsHeader.bounds.Width() + 1);
|
width = static_cast<png_uint_32>(bitsHeader.bounds.Width() + 1);
|
||||||
height = static_cast<png_uint_32>(bitsHeader.bounds.Height() + 1);
|
height = static_cast<png_uint_32>(bitsHeader.bounds.Height() + 1);
|
||||||
|
|
||||||
int32 pngBytesPerPixel = 0;
|
int32 pngBytesPerPixel = 0;
|
||||||
int bit_depth, color_type, interlace_type;
|
int bit_depth, color_type, interlace_type;
|
||||||
bit_depth = 8;
|
bit_depth = 8;
|
||||||
@@ -725,7 +730,7 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
pngBytesPerPixel = 4;
|
pngBytesPerPixel = 4;
|
||||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
case B_RGB32_BIG:
|
case B_RGB32_BIG:
|
||||||
case B_RGB24:
|
case B_RGB24:
|
||||||
@@ -740,19 +745,19 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
pngBytesPerPixel = 3;
|
pngBytesPerPixel = 3;
|
||||||
color_type = PNG_COLOR_TYPE_RGB;
|
color_type = PNG_COLOR_TYPE_RGB;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ADD SUPPORT FOR B_CMAP8 HERE (later)
|
// ADD SUPPORT FOR B_CMAP8 HERE (later)
|
||||||
|
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
pngBytesPerPixel = 1;
|
pngBytesPerPixel = 1;
|
||||||
color_type = PNG_COLOR_TYPE_GRAY;
|
color_type = PNG_COLOR_TYPE_GRAY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
interlace_type = fSettings->SetGetInt32(PNG_SETTING_INTERLACE);
|
interlace_type = fSettings->SetGetInt32(PNG_SETTING_INTERLACE);
|
||||||
|
|
||||||
int32 bitsBytesPerPixel = 0;
|
int32 bitsBytesPerPixel = 0;
|
||||||
switch (bitsHeader.colors) {
|
switch (bitsHeader.colors) {
|
||||||
case B_RGBA32:
|
case B_RGBA32:
|
||||||
@@ -764,13 +769,13 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
case B_CMY32:
|
case B_CMY32:
|
||||||
bitsBytesPerPixel = 4;
|
bitsBytesPerPixel = 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB24:
|
case B_RGB24:
|
||||||
case B_RGB24_BIG:
|
case B_RGB24_BIG:
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
bitsBytesPerPixel = 3;
|
bitsBytesPerPixel = 3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
case B_RGBA15:
|
case B_RGBA15:
|
||||||
@@ -784,20 +789,20 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
bitsBytesPerPixel = 1;
|
bitsBytesPerPixel = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8 *pbitsrow = NULL, *prow = NULL;
|
uint8 *pbitsrow = NULL, *prow = NULL;
|
||||||
// row buffers
|
// row buffers
|
||||||
// image buffer for writing whole png image at once
|
// image buffer for writing whole png image at once
|
||||||
uint8 **prows = NULL;
|
uint8 **prows = NULL;
|
||||||
png_uint_32 nalloc = 0;
|
png_uint_32 nalloc = 0;
|
||||||
|
|
||||||
png_structp ppng = NULL;
|
png_structp ppng = NULL;
|
||||||
png_infop pinfo = NULL;
|
png_infop pinfo = NULL;
|
||||||
|
|
||||||
result = B_NO_TRANSLATOR;
|
result = B_NO_TRANSLATOR;
|
||||||
while (ppng == NULL) {
|
while (ppng == NULL) {
|
||||||
// create PNG read pointer with default error handling routines
|
// create PNG read pointer with default error handling routines
|
||||||
@@ -822,9 +827,9 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_set_write_fn(ppng, static_cast<void *>(outDestination),
|
png_set_write_fn(ppng, static_cast<void *>(outDestination),
|
||||||
pngcb_write_data, pngcb_flush_data);
|
pngcb_write_data, pngcb_flush_data);
|
||||||
|
|
||||||
// Allocate memory needed to buffer image data
|
// Allocate memory needed to buffer image data
|
||||||
pbitsrow = new uint8[bitsHeader.rowBytes];
|
pbitsrow = new uint8[bitsHeader.rowBytes];
|
||||||
if (!pbitsrow) {
|
if (!pbitsrow) {
|
||||||
@@ -858,46 +863,46 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specify image info
|
// Specify image info
|
||||||
png_set_IHDR(ppng, pinfo, width, height, bit_depth, color_type,
|
png_set_IHDR(ppng, pinfo, width, height, bit_depth, color_type,
|
||||||
interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||||
png_write_info(ppng, pinfo);
|
png_write_info(ppng, pinfo);
|
||||||
|
|
||||||
png_set_bgr(ppng);
|
png_set_bgr(ppng);
|
||||||
|
|
||||||
// write out image data
|
// write out image data
|
||||||
if (interlace_type == PNG_INTERLACE_NONE) {
|
if (interlace_type == PNG_INTERLACE_NONE) {
|
||||||
for (png_uint_32 i = 0; i < height; i++) {
|
for (png_uint_32 i = 0; i < height; i++) {
|
||||||
inSource->Read(pbitsrow, bitsHeader.rowBytes);
|
inSource->Read(pbitsrow, bitsHeader.rowBytes);
|
||||||
|
|
||||||
pix_bits_to_png(pbitsrow, prow, bitsHeader.colors, width,
|
pix_bits_to_png(pbitsrow, prow, bitsHeader.colors, width,
|
||||||
pmap, bitsBytesPerPixel);
|
pmap, bitsBytesPerPixel);
|
||||||
|
|
||||||
png_write_row(ppng, prow);
|
png_write_row(ppng, prow);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (png_uint_32 i = 0; i < height; i++) {
|
for (png_uint_32 i = 0; i < height; i++) {
|
||||||
inSource->Read(pbitsrow, bitsHeader.rowBytes);
|
inSource->Read(pbitsrow, bitsHeader.rowBytes);
|
||||||
|
|
||||||
pix_bits_to_png(pbitsrow, prows[i], bitsHeader.colors, width,
|
pix_bits_to_png(pbitsrow, prows[i], bitsHeader.colors, width,
|
||||||
pmap, bitsBytesPerPixel);
|
pmap, bitsBytesPerPixel);
|
||||||
}
|
}
|
||||||
png_write_image(ppng, prows);
|
png_write_image(ppng, prows);
|
||||||
}
|
}
|
||||||
png_write_end(ppng, NULL);
|
png_write_end(ppng, NULL);
|
||||||
|
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ppng) {
|
if (ppng) {
|
||||||
delete[] pbitsrow;
|
delete[] pbitsrow;
|
||||||
pbitsrow = NULL;
|
pbitsrow = NULL;
|
||||||
|
|
||||||
delete[] prow;
|
delete[] prow;
|
||||||
prow = NULL;
|
prow = NULL;
|
||||||
|
|
||||||
// delete row pointers and array of pointers to rows
|
// delete row pointers and array of pointers to rows
|
||||||
while (nalloc) {
|
while (nalloc) {
|
||||||
nalloc--;
|
nalloc--;
|
||||||
@@ -905,7 +910,7 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
}
|
}
|
||||||
delete[] prows;
|
delete[] prows;
|
||||||
prows = NULL;
|
prows = NULL;
|
||||||
|
|
||||||
// free PNG handle / info structures
|
// free PNG handle / info structures
|
||||||
if (!pinfo)
|
if (!pinfo)
|
||||||
png_destroy_write_struct(&ppng, NULL);
|
png_destroy_write_struct(&ppng, NULL);
|
||||||
@@ -925,7 +930,7 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
|||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
// Parameters: inSource, the data to be translated
|
// Parameters: inSource, the data to be translated
|
||||||
//
|
//
|
||||||
// inInfo, hint about the data in inSource (not used)
|
// inInfo, hint about the data in inSource (not used)
|
||||||
//
|
//
|
||||||
// ioExtension, configuration options for the
|
// ioExtension, configuration options for the
|
||||||
@@ -958,7 +963,7 @@ PNGTranslator::DerivedTranslate(BPositionIO *inSource,
|
|||||||
{
|
{
|
||||||
if (baseType == 1)
|
if (baseType == 1)
|
||||||
// if inSource is in bits format
|
// if inSource is in bits format
|
||||||
return translate_from_bits_to_png(inSource, outDestination);
|
return translate_from_bits_to_png(inSource, outDestination);
|
||||||
else if (baseType == 0)
|
else if (baseType == 0)
|
||||||
// if inSource is NOT in bits format
|
// if inSource is NOT in bits format
|
||||||
return translate_from_png(inSource, outType, outDestination);
|
return translate_from_png(inSource, outType, outDestination);
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ struct ppm_settings {
|
|||||||
bool write_ascii;
|
bool write_ascii;
|
||||||
bool settings_touched;
|
bool settings_touched;
|
||||||
};
|
};
|
||||||
BLocker g_settings_lock("PPM settings lock");
|
static BLocker g_settings_lock("PPM settings lock");
|
||||||
ppm_settings g_settings;
|
static ppm_settings g_settings;
|
||||||
|
|
||||||
BPoint get_window_origin();
|
BPoint get_window_origin();
|
||||||
void set_window_origin(BPoint pos);
|
void set_window_origin(BPoint pos);
|
||||||
@@ -485,10 +485,10 @@ public:
|
|||||||
if (g_settings.write_ascii)
|
if (g_settings.write_ascii)
|
||||||
mAscii->SetValue(1);
|
mAscii->SetValue(1);
|
||||||
mAscii->SetViewColor(ViewColor());
|
mAscii->SetViewColor(ViewColor());
|
||||||
|
|
||||||
// Build the layout
|
// Build the layout
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
|
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, 7)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 7)
|
||||||
.Add(mTitle)
|
.Add(mTitle)
|
||||||
.Add(mDetail)
|
.Add(mDetail)
|
||||||
@@ -504,7 +504,7 @@ public:
|
|||||||
.AddGlue()
|
.AddGlue()
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
);
|
);
|
||||||
|
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
SetExplicitPreferredSize(BSize((font.Size() * 350)/12, (font.Size() * 200)/12));
|
SetExplicitPreferredSize(BSize((font.Size() * 350)/12, (font.Size() * 200)/12));
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const char* kProgressMonitor = "/progressMonitor";
|
|||||||
const char* kProgressMessage = "/progressMessage";
|
const char* kProgressMessage = "/progressMessage";
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
RAW_IMAGE_FORMAT,
|
RAW_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -62,11 +62,11 @@ translation_format sInputFormats[] = {
|
|||||||
RAW_IN_CAPABILITY,
|
RAW_IN_CAPABILITY,
|
||||||
"image/x-vnd.photo-raw",
|
"image/x-vnd.photo-raw",
|
||||||
"Digital Photo RAW image"
|
"Digital Photo RAW image"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -74,11 +74,11 @@ translation_format sOutputFormats[] = {
|
|||||||
BITS_OUT_CAPABILITY,
|
BITS_OUT_CAPABILITY,
|
||||||
"image/x-be-bitmap",
|
"image/x-be-bitmap",
|
||||||
"Be Bitmap Format (RAWTranslator)"
|
"Be Bitmap Format (RAWTranslator)"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
RTF_TEXT_FORMAT,
|
RTF_TEXT_FORMAT,
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
@@ -27,11 +27,11 @@ translation_format sInputFormats[] = {
|
|||||||
RTF_IN_CAPABILITY,
|
RTF_IN_CAPABILITY,
|
||||||
"text/rtf",
|
"text/rtf",
|
||||||
"RichTextFormat file"
|
"RichTextFormat file"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
//
|
//
|
||||||
// SGITranslator.cpp
|
// SGITranslator.cpp
|
||||||
//
|
//
|
||||||
// This BTranslator based object is for opening and writing
|
// This BTranslator based object is for opening and writing
|
||||||
// SGI images.
|
// SGI images.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -15,18 +15,18 @@
|
|||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
// to deal in the Software without restriction, including without limitation
|
// to deal in the Software without restriction, including without limitation
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// and/or sell copies of the Software, and to permit persons to whom the
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
// Software is furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included
|
// The above copyright notice and this permission notice shall be included
|
||||||
// in all copies or substantial portions of the Software.
|
// in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -73,7 +73,7 @@ translation_format gInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -93,13 +93,18 @@ translation_format gOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
TranSetting gDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{SGI_SETTING_COMPRESSION, TRAN_SETTING_INT32, SGI_COMP_RLE}
|
{SGI_SETTING_COMPRESSION, TRAN_SETTING_INT32, SGI_COMP_RLE}
|
||||||
// compression is set to RLE by default
|
// compression is set to RLE by default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// make_nth_translator
|
// make_nth_translator
|
||||||
//
|
//
|
||||||
@@ -149,10 +154,10 @@ SGITranslator::SGITranslator()
|
|||||||
:
|
:
|
||||||
BaseTranslator("SGI images", "SGI image translator",
|
BaseTranslator("SGI images", "SGI image translator",
|
||||||
SGI_TRANSLATOR_VERSION,
|
SGI_TRANSLATOR_VERSION,
|
||||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
sInputFormats, kNumInputFormats,
|
||||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"SGITranslator_Settings",
|
"SGITranslator_Settings",
|
||||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_BITMAP, SGI_FORMAT)
|
B_TRANSLATOR_BITMAP, SGI_FORMAT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -183,7 +188,7 @@ identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outT
|
|||||||
SGIImage* sgiImage = new(nothrow) SGIImage();
|
SGIImage* sgiImage = new(nothrow) SGIImage();
|
||||||
if (sgiImage)
|
if (sgiImage)
|
||||||
status = sgiImage->SetTo(inSource);
|
status = sgiImage->SetTo(inSource);
|
||||||
|
|
||||||
if (status >= B_OK) {
|
if (status >= B_OK) {
|
||||||
if (outInfo) {
|
if (outInfo) {
|
||||||
outInfo->type = SGI_FORMAT;
|
outInfo->type = SGI_FORMAT;
|
||||||
@@ -206,7 +211,7 @@ identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outT
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// DerivedIdentify
|
// DerivedIdentify
|
||||||
//
|
//
|
||||||
@@ -304,7 +309,7 @@ SGITranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
// read one row at a time,
|
// read one row at a time,
|
||||||
// convert to the correct format
|
// convert to the correct format
|
||||||
// and write out the results
|
// and write out the results
|
||||||
|
|
||||||
// SGI Images store each channel separately
|
// SGI Images store each channel separately
|
||||||
// a buffer is allocated big enough to hold all channels
|
// a buffer is allocated big enough to hold all channels
|
||||||
// then the pointers are assigned with offsets into that buffer
|
// then the pointers are assigned with offsets into that buffer
|
||||||
@@ -402,7 +407,7 @@ SGITranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
// cannot be here
|
// cannot be here
|
||||||
break;
|
break;
|
||||||
} // switch (format)
|
} // switch (format)
|
||||||
|
|
||||||
// for each channel, write a row buffer
|
// for each channel, write a row buffer
|
||||||
for (uint32 z = 0; z < channelCount; z++) {
|
for (uint32 z = 0; z < channelCount; z++) {
|
||||||
ret = sgiImage->WriteRow(rows[z], y, z);
|
ret = sgiImage->WriteRow(rows[z], y, z);
|
||||||
@@ -411,13 +416,13 @@ printf("WriteRow() returned %s!\n", strerror(ret));
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // for (uint32 y = 0; y < height && ret >= B_OK; y++)
|
} // for (uint32 y = 0; y < height && ret >= B_OK; y++)
|
||||||
if (ret >= B_OK)
|
if (ret >= B_OK)
|
||||||
ret = B_OK;
|
ret = B_OK;
|
||||||
} else // if (rows && rows[0] && rowBuffer)
|
} else // if (rows && rows[0] && rowBuffer)
|
||||||
ret = B_NO_MEMORY;
|
ret = B_NO_MEMORY;
|
||||||
|
|
||||||
delete[] rows[0];
|
delete[] rows[0];
|
||||||
delete[] rows;
|
delete[] rows;
|
||||||
delete[] rowBuffer;
|
delete[] rowBuffer;
|
||||||
@@ -437,7 +442,7 @@ SGITranslator::translate_from_sgi(BPositionIO *inSource, uint32 outType,
|
|||||||
BPositionIO *outDestination)
|
BPositionIO *outDestination)
|
||||||
{
|
{
|
||||||
status_t ret = B_NO_TRANSLATOR;
|
status_t ret = B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// if copying SGI_FORMAT to SGI_FORMAT
|
// if copying SGI_FORMAT to SGI_FORMAT
|
||||||
if (outType == SGI_FORMAT) {
|
if (outType == SGI_FORMAT) {
|
||||||
translate_direct_copy(inSource, outDestination);
|
translate_direct_copy(inSource, outDestination);
|
||||||
@@ -446,13 +451,13 @@ SGITranslator::translate_from_sgi(BPositionIO *inSource, uint32 outType,
|
|||||||
|
|
||||||
// variables needing cleanup
|
// variables needing cleanup
|
||||||
SGIImage* sgiImage = NULL;
|
SGIImage* sgiImage = NULL;
|
||||||
|
|
||||||
ret = identify_sgi_header(inSource, NULL, outType, &sgiImage);
|
ret = identify_sgi_header(inSource, NULL, outType, &sgiImage);
|
||||||
|
|
||||||
if (ret >= B_OK) {
|
if (ret >= B_OK) {
|
||||||
|
|
||||||
bool bheaderonly = false, bdataonly = false;
|
bool bheaderonly = false, bdataonly = false;
|
||||||
|
|
||||||
uint32 width = sgiImage->Width();
|
uint32 width = sgiImage->Width();
|
||||||
uint32 height = sgiImage->Height();
|
uint32 height = sgiImage->Height();
|
||||||
uint32 channelCount = sgiImage->CountChannels();
|
uint32 channelCount = sgiImage->CountChannels();
|
||||||
@@ -687,7 +692,7 @@ printf("error writing bits header: %s\n", strerror(ret));
|
|||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
// Parameters: inSource, the data to be translated
|
// Parameters: inSource, the data to be translated
|
||||||
//
|
//
|
||||||
// inInfo, hint about the data in inSource (not used)
|
// inInfo, hint about the data in inSource (not used)
|
||||||
//
|
//
|
||||||
// ioExtension, configuration options for the
|
// ioExtension, configuration options for the
|
||||||
@@ -727,7 +732,7 @@ SGITranslator::DerivedTranslate(BPositionIO *inSource,
|
|||||||
else
|
else
|
||||||
// if BaseTranslator did not properly identify the data as
|
// if BaseTranslator did not properly identify the data as
|
||||||
// bits or not bits
|
// bits or not bits
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
BView *
|
BView *
|
||||||
|
|||||||
@@ -14,18 +14,18 @@
|
|||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
// to deal in the Software without restriction, including without limitation
|
// to deal in the Software without restriction, including without limitation
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// and/or sell copies of the Software, and to permit persons to whom the
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
// Software is furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included
|
// The above copyright notice and this permission notice shall be included
|
||||||
// in all copies or substantial portions of the Software.
|
// in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
BaseTranslator::BaseTranslator(const char *name, const char *info,
|
BaseTranslator::BaseTranslator(const char *name, const char *info,
|
||||||
const int32 version, const translation_format *inFormats,
|
const int32 version, const translation_format *inFormats,
|
||||||
int32 inCount, const translation_format *outFormats, int32 outCount,
|
int32 inCount, const translation_format *outFormats, int32 outCount,
|
||||||
const char *settingsFile, TranSetting *defaults, int32 defCount,
|
const char *settingsFile, const TranSetting *defaults, int32 defCount,
|
||||||
uint32 tranGroup, uint32 tranType)
|
uint32 tranGroup, uint32 tranType)
|
||||||
:
|
:
|
||||||
BTranslator()
|
BTranslator()
|
||||||
@@ -123,7 +123,7 @@ BaseTranslator::~BaseTranslator()
|
|||||||
// Postconditions:
|
// Postconditions:
|
||||||
//
|
//
|
||||||
// Returns: a const char * to the short name of the translator
|
// Returns: a const char * to the short name of the translator
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
const char *
|
const char *
|
||||||
BaseTranslator::TranslatorName() const
|
BaseTranslator::TranslatorName() const
|
||||||
{
|
{
|
||||||
@@ -166,7 +166,7 @@ BaseTranslator::TranslatorInfo() const
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
int32
|
int32
|
||||||
BaseTranslator::TranslatorVersion() const
|
BaseTranslator::TranslatorVersion() const
|
||||||
{
|
{
|
||||||
return fVersion;
|
return fVersion;
|
||||||
@@ -213,7 +213,7 @@ BaseTranslator::InputFormats(int32 *out_count) const
|
|||||||
//
|
//
|
||||||
// Returns: the array of output formats and the number of output
|
// Returns: the array of output formats and the number of output
|
||||||
// formats through the out_count parameter
|
// formats through the out_count parameter
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
const translation_format *
|
const translation_format *
|
||||||
BaseTranslator::OutputFormats(int32 *out_count) const
|
BaseTranslator::OutputFormats(int32 *out_count) const
|
||||||
{
|
{
|
||||||
@@ -229,7 +229,7 @@ BaseTranslator::OutputFormats(int32 *out_count) const
|
|||||||
// identify_bits_header
|
// identify_bits_header
|
||||||
//
|
//
|
||||||
// Determines if the data in inSource is in the
|
// Determines if the data in inSource is in the
|
||||||
// B_TRANSLATOR_BITMAP ('bits') format. If it is, it returns
|
// B_TRANSLATOR_BITMAP ('bits') format. If it is, it returns
|
||||||
// info about the data in inSource to outInfo and pheader.
|
// info about the data in inSource to outInfo and pheader.
|
||||||
//
|
//
|
||||||
// Preconditions:
|
// Preconditions:
|
||||||
@@ -259,7 +259,7 @@ BaseTranslator::OutputFormats(int32 *out_count) const
|
|||||||
// B_OK, if the data looks like bits data and no errors were
|
// B_OK, if the data looks like bits data and no errors were
|
||||||
// encountered
|
// encountered
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
status_t
|
status_t
|
||||||
BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
||||||
translator_info *outInfo, TranslatorBitmap *pheader)
|
translator_info *outInfo, TranslatorBitmap *pheader)
|
||||||
{
|
{
|
||||||
@@ -270,12 +270,12 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
|||||||
if (inSource->Read(
|
if (inSource->Read(
|
||||||
(reinterpret_cast<uint8 *> (&header)), size) != size)
|
(reinterpret_cast<uint8 *> (&header)), size) != size)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// convert to host byte order
|
// convert to host byte order
|
||||||
if (swap_data(B_UINT32_TYPE, &header, sizeof(TranslatorBitmap),
|
if (swap_data(B_UINT32_TYPE, &header, sizeof(TranslatorBitmap),
|
||||||
B_SWAP_BENDIAN_TO_HOST) != B_OK)
|
B_SWAP_BENDIAN_TO_HOST) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// check if header values are reasonable
|
// check if header values are reasonable
|
||||||
if (header.colors != B_RGB32 &&
|
if (header.colors != B_RGB32 &&
|
||||||
header.colors != B_RGB32_BIG &&
|
header.colors != B_RGB32_BIG &&
|
||||||
@@ -299,7 +299,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
|||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
if (header.rowBytes * (header.bounds.Height() + 1) != header.dataSize)
|
if (header.rowBytes * (header.bounds.Height() + 1) != header.dataSize)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
if (outInfo) {
|
if (outInfo) {
|
||||||
outInfo->type = B_TRANSLATOR_BITMAP;
|
outInfo->type = B_TRANSLATOR_BITMAP;
|
||||||
outInfo->group = B_TRANSLATOR_BITMAP;
|
outInfo->group = B_TRANSLATOR_BITMAP;
|
||||||
@@ -307,7 +307,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
|||||||
outInfo->capability = 0.2;
|
outInfo->capability = 0.2;
|
||||||
strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format"));
|
strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format"));
|
||||||
strcpy(outInfo->MIME, "image/x-be-bitmap");
|
strcpy(outInfo->MIME, "image/x-be-bitmap");
|
||||||
|
|
||||||
// Look for quality / capability info in fInputFormats
|
// Look for quality / capability info in fInputFormats
|
||||||
for (int32 i = 0; i < fInputCount; i++) {
|
for (int32 i = 0; i < fInputCount; i++) {
|
||||||
if (fInputFormats[i].type == B_TRANSLATOR_BITMAP &&
|
if (fInputFormats[i].type == B_TRANSLATOR_BITMAP &&
|
||||||
@@ -319,7 +319,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pheader) {
|
if (pheader) {
|
||||||
pheader->magic = header.magic;
|
pheader->magic = header.magic;
|
||||||
pheader->bounds = header.bounds;
|
pheader->bounds = header.bounds;
|
||||||
@@ -327,7 +327,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
|||||||
pheader->colors = header.colors;
|
pheader->colors = header.colors;
|
||||||
pheader->dataSize = header.dataSize;
|
pheader->dataSize = header.dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
|
|||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// BitsCheck
|
// BitsCheck
|
||||||
//
|
//
|
||||||
// Examines the input stream for B_TRANSLATOR_BITMAP format
|
// Examines the input stream for B_TRANSLATOR_BITMAP format
|
||||||
// information and determines if BaseTranslator can handle
|
// information and determines if BaseTranslator can handle
|
||||||
// the translation entirely, if it must pass the task of
|
// the translation entirely, if it must pass the task of
|
||||||
// translation to the derived translator or if the stream cannot
|
// translation to the derived translator or if the stream cannot
|
||||||
@@ -382,7 +382,7 @@ BaseTranslator::BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
|
|||||||
// I won't have to convert the data read in to see whether or not
|
// I won't have to convert the data read in to see whether or not
|
||||||
// it is a supported type
|
// it is a supported type
|
||||||
const uint32 kBitsMagic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
|
const uint32 kBitsMagic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
|
||||||
|
|
||||||
// Read in the magic number and determine if it
|
// Read in the magic number and determine if it
|
||||||
// is a supported type
|
// is a supported type
|
||||||
uint8 ch[4];
|
uint8 ch[4];
|
||||||
@@ -391,11 +391,11 @@ BaseTranslator::BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
|
|||||||
inSource->Seek(-4, SEEK_CUR);
|
inSource->Seek(-4, SEEK_CUR);
|
||||||
// seek backward becuase functions used after this one
|
// seek backward becuase functions used after this one
|
||||||
// expect the stream to be at the beginning
|
// expect the stream to be at the beginning
|
||||||
|
|
||||||
// Read settings from ioExtension
|
// Read settings from ioExtension
|
||||||
if (ioExtension && fSettings->LoadSettings(ioExtension) < B_OK)
|
if (ioExtension && fSettings->LoadSettings(ioExtension) < B_OK)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
uint32 sourceMagic;
|
uint32 sourceMagic;
|
||||||
memcpy(&sourceMagic, ch, sizeof(uint32));
|
memcpy(&sourceMagic, ch, sizeof(uint32));
|
||||||
if (sourceMagic == kBitsMagic)
|
if (sourceMagic == kBitsMagic)
|
||||||
@@ -516,13 +516,13 @@ BaseTranslator::translate_from_bits_to_bits(BPositionIO *inSource,
|
|||||||
{
|
{
|
||||||
TranslatorBitmap bitsHeader;
|
TranslatorBitmap bitsHeader;
|
||||||
bool bheaderonly = false, bdataonly = false;
|
bool bheaderonly = false, bdataonly = false;
|
||||||
|
|
||||||
status_t result;
|
status_t result;
|
||||||
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Translate B_TRANSLATOR_BITMAP to B_TRANSLATOR_BITMAP, easy enough :)
|
// Translate B_TRANSLATOR_BITMAP to B_TRANSLATOR_BITMAP, easy enough :)
|
||||||
if (outType == B_TRANSLATOR_BITMAP) {
|
if (outType == B_TRANSLATOR_BITMAP) {
|
||||||
// write out bitsHeader (only if configured to)
|
// write out bitsHeader (only if configured to)
|
||||||
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
if (bheaderonly || (!bheaderonly && !bdataonly)) {
|
||||||
@@ -533,9 +533,9 @@ BaseTranslator::translate_from_bits_to_bits(BPositionIO *inSource,
|
|||||||
sizeof(TranslatorBitmap)) != sizeof(TranslatorBitmap))
|
sizeof(TranslatorBitmap)) != sizeof(TranslatorBitmap))
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write out the data (only if configured to)
|
// write out the data (only if configured to)
|
||||||
if (bdataonly || (!bheaderonly && !bdataonly)) {
|
if (bdataonly || (!bheaderonly && !bdataonly)) {
|
||||||
uint8 buf[1024];
|
uint8 buf[1024];
|
||||||
uint32 remaining = B_BENDIAN_TO_HOST_INT32(bitsHeader.dataSize);
|
uint32 remaining = B_BENDIAN_TO_HOST_INT32(bitsHeader.dataSize);
|
||||||
ssize_t rd, writ;
|
ssize_t rd, writ;
|
||||||
@@ -547,7 +547,7 @@ BaseTranslator::translate_from_bits_to_bits(BPositionIO *inSource,
|
|||||||
remaining -= static_cast<uint32>(writ);
|
remaining -= static_cast<uint32>(writ);
|
||||||
rd = inSource->Read(buf, min(1024, remaining));
|
rd = inSource->Read(buf, min(1024, remaining));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remaining > 0)
|
if (remaining > 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
else
|
else
|
||||||
@@ -587,7 +587,7 @@ BaseTranslator::BitsTranslate(BPositionIO *inSource,
|
|||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
// Parameters: inSource, the data to be translated
|
// Parameters: inSource, the data to be translated
|
||||||
//
|
//
|
||||||
// inInfo, hint about the data in inSource (not used)
|
// inInfo, hint about the data in inSource (not used)
|
||||||
//
|
//
|
||||||
// ioExtension, configuration options for the
|
// ioExtension, configuration options for the
|
||||||
@@ -638,7 +638,7 @@ BaseTranslator::GetConfigurationMessage(BMessage *ioExtension)
|
|||||||
// MakeConfigurationView
|
// MakeConfigurationView
|
||||||
//
|
//
|
||||||
// Makes a BView object for configuring / displaying info about
|
// Makes a BView object for configuring / displaying info about
|
||||||
// this translator.
|
// this translator.
|
||||||
//
|
//
|
||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -14,18 +14,18 @@
|
|||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
// to deal in the Software without restriction, including without limitation
|
// to deal in the Software without restriction, including without limitation
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// and/or sell copies of the Software, and to permit persons to whom the
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
// Software is furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included
|
// The above copyright notice and this permission notice shall be included
|
||||||
// in all copies or substantial portions of the Software.
|
// in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -55,15 +55,15 @@ public:
|
|||||||
BaseTranslator(const char *name, const char *info,
|
BaseTranslator(const char *name, const char *info,
|
||||||
const int32 version, const translation_format *inFormats,
|
const int32 version, const translation_format *inFormats,
|
||||||
int32 inCount, const translation_format *outFormats, int32 outCount,
|
int32 inCount, const translation_format *outFormats, int32 outCount,
|
||||||
const char *settingsFile, TranSetting *defaults, int32 defCount,
|
const char *settingsFile, const TranSetting *defaults, int32 defCount,
|
||||||
uint32 tranGroup, uint32 tranType);
|
uint32 tranGroup, uint32 tranType);
|
||||||
|
|
||||||
virtual const char *TranslatorName() const;
|
virtual const char *TranslatorName() const;
|
||||||
// returns the short name of the translator
|
// returns the short name of the translator
|
||||||
|
|
||||||
virtual const char *TranslatorInfo() const;
|
virtual const char *TranslatorInfo() const;
|
||||||
// returns a verbose name/description for the translator
|
// returns a verbose name/description for the translator
|
||||||
|
|
||||||
virtual int32 TranslatorVersion() const;
|
virtual int32 TranslatorVersion() const;
|
||||||
// returns the version of the translator
|
// returns the version of the translator
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
const;
|
const;
|
||||||
// returns the input formats and the count of input formats
|
// returns the input formats and the count of input formats
|
||||||
// that this translator supports
|
// that this translator supports
|
||||||
|
|
||||||
virtual const translation_format *OutputFormats(int32 *out_count)
|
virtual const translation_format *OutputFormats(int32 *out_count)
|
||||||
const;
|
const;
|
||||||
// returns the output formats and the count of output formats
|
// returns the output formats and the count of output formats
|
||||||
@@ -89,31 +89,31 @@ public:
|
|||||||
// this function is the whole point of the Translation Kit,
|
// this function is the whole point of the Translation Kit,
|
||||||
// it translates the data in inSource to outDestination
|
// it translates the data in inSource to outDestination
|
||||||
// using the format outType
|
// using the format outType
|
||||||
|
|
||||||
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
|
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
|
||||||
// write the current state of the translator into
|
// write the current state of the translator into
|
||||||
// the supplied BMessage object
|
// the supplied BMessage object
|
||||||
|
|
||||||
virtual status_t MakeConfigurationView(BMessage *ioExtension,
|
virtual status_t MakeConfigurationView(BMessage *ioExtension,
|
||||||
BView **outView, BRect *outExtent);
|
BView **outView, BRect *outExtent);
|
||||||
// creates and returns the view for displaying information
|
// creates and returns the view for displaying information
|
||||||
// about this translator
|
// about this translator
|
||||||
|
|
||||||
TranslatorSettings *AcquireSettings();
|
TranslatorSettings *AcquireSettings();
|
||||||
|
|
||||||
// Functions to be implmemented by derived class
|
// Functions to be implmemented by derived class
|
||||||
virtual status_t DerivedIdentify(BPositionIO *inSource,
|
virtual status_t DerivedIdentify(BPositionIO *inSource,
|
||||||
const translation_format *inFormat, BMessage *ioExtension,
|
const translation_format *inFormat, BMessage *ioExtension,
|
||||||
translator_info *outInfo, uint32 outType);
|
translator_info *outInfo, uint32 outType);
|
||||||
|
|
||||||
virtual status_t DerivedTranslate(BPositionIO *inSource,
|
virtual status_t DerivedTranslate(BPositionIO *inSource,
|
||||||
const translator_info *inInfo, BMessage *ioExtension,
|
const translator_info *inInfo, BMessage *ioExtension,
|
||||||
uint32 outType, BPositionIO *outDestination, int32 baseType);
|
uint32 outType, BPositionIO *outDestination, int32 baseType);
|
||||||
|
|
||||||
virtual status_t DerivedCanHandleImageSize(float width, float height) const;
|
virtual status_t DerivedCanHandleImageSize(float width, float height) const;
|
||||||
|
|
||||||
virtual BView *NewConfigView(TranslatorSettings *settings);
|
virtual BView *NewConfigView(TranslatorSettings *settings);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
status_t BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
|
status_t BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
|
||||||
@@ -122,14 +122,14 @@ protected:
|
|||||||
status_t BitsIdentify(BPositionIO *inSource,
|
status_t BitsIdentify(BPositionIO *inSource,
|
||||||
const translation_format *inFormat, BMessage *ioExtension,
|
const translation_format *inFormat, BMessage *ioExtension,
|
||||||
translator_info *outInfo, uint32 outType);
|
translator_info *outInfo, uint32 outType);
|
||||||
|
|
||||||
status_t identify_bits_header(BPositionIO *inSource,
|
status_t identify_bits_header(BPositionIO *inSource,
|
||||||
translator_info *outInfo, TranslatorBitmap *pheader = NULL);
|
translator_info *outInfo, TranslatorBitmap *pheader = NULL);
|
||||||
|
|
||||||
status_t BitsTranslate(BPositionIO *inSource,
|
status_t BitsTranslate(BPositionIO *inSource,
|
||||||
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
|
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
|
||||||
BPositionIO *outDestination);
|
BPositionIO *outDestination);
|
||||||
|
|
||||||
status_t translate_from_bits_to_bits(BPositionIO *inSource,
|
status_t translate_from_bits_to_bits(BPositionIO *inSource,
|
||||||
uint32 outType, BPositionIO *outDestination);
|
uint32 outType, BPositionIO *outDestination);
|
||||||
|
|
||||||
@@ -137,9 +137,9 @@ protected:
|
|||||||
// this is protected because the object is deleted by the
|
// this is protected because the object is deleted by the
|
||||||
// Release() function instead of being deleted directly by
|
// Release() function instead of being deleted directly by
|
||||||
// the user
|
// the user
|
||||||
|
|
||||||
TranslatorSettings *fSettings;
|
TranslatorSettings *fSettings;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 fVersion;
|
int32 fVersion;
|
||||||
char *fName;
|
char *fName;
|
||||||
|
|||||||
@@ -13,18 +13,18 @@
|
|||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
// to deal in the Software without restriction, including without limitation
|
// to deal in the Software without restriction, including without limitation
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// and/or sell copies of the Software, and to permit persons to whom the
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
// Software is furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included
|
// The above copyright notice and this permission notice shall be included
|
||||||
// in all copies or substantial portions of the Software.
|
// in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -51,15 +51,15 @@
|
|||||||
// Returns:
|
// Returns:
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
TranslatorSettings::TranslatorSettings(const char *settingsFile,
|
TranslatorSettings::TranslatorSettings(const char *settingsFile,
|
||||||
TranSetting *defaults, int32 defCount)
|
const TranSetting *defaults, int32 defCount)
|
||||||
: fLock("TranslatorSettings Lock")
|
: fLock("TranslatorSettings Lock")
|
||||||
{
|
{
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &fSettingsPath))
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &fSettingsPath))
|
||||||
fSettingsPath.SetTo("/tmp");
|
fSettingsPath.SetTo("/tmp");
|
||||||
fSettingsPath.Append(settingsFile);
|
fSettingsPath.Append(settingsFile);
|
||||||
|
|
||||||
fRefCount = 1;
|
fRefCount = 1;
|
||||||
|
|
||||||
if (defCount > 0) {
|
if (defCount > 0) {
|
||||||
fDefaults = defaults;
|
fDefaults = defaults;
|
||||||
fDefCount = defCount;
|
fDefCount = defCount;
|
||||||
@@ -67,7 +67,7 @@ TranslatorSettings::TranslatorSettings(const char *settingsFile,
|
|||||||
fDefaults = NULL;
|
fDefaults = NULL;
|
||||||
fDefCount = 0;
|
fDefCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Default Settings
|
// Add Default Settings
|
||||||
// (Used when loading from the settings file or from
|
// (Used when loading from the settings file or from
|
||||||
// a BMessage fails)
|
// a BMessage fails)
|
||||||
@@ -78,11 +78,11 @@ TranslatorSettings::TranslatorSettings(const char *settingsFile,
|
|||||||
fSettingsMsg.AddBool(defs[i].name,
|
fSettingsMsg.AddBool(defs[i].name,
|
||||||
static_cast<bool>(defs[i].defaultVal));
|
static_cast<bool>(defs[i].defaultVal));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRAN_SETTING_INT32:
|
case TRAN_SETTING_INT32:
|
||||||
fSettingsMsg.AddInt32(defs[i].name, defs[i].defaultVal);
|
fSettingsMsg.AddInt32(defs[i].name, defs[i].defaultVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// ASSERT here? Erase the bogus setting entry instead?
|
// ASSERT here? Erase the bogus setting entry instead?
|
||||||
break;
|
break;
|
||||||
@@ -94,7 +94,7 @@ TranslatorSettings::TranslatorSettings(const char *settingsFile,
|
|||||||
// Acquire
|
// Acquire
|
||||||
//
|
//
|
||||||
// Returns a pointer to the TranslatorSettings and increments
|
// Returns a pointer to the TranslatorSettings and increments
|
||||||
// the reference count.
|
// the reference count.
|
||||||
//
|
//
|
||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
@@ -108,12 +108,12 @@ TranslatorSettings *
|
|||||||
TranslatorSettings::Acquire()
|
TranslatorSettings::Acquire()
|
||||||
{
|
{
|
||||||
TranslatorSettings *psettings = NULL;
|
TranslatorSettings *psettings = NULL;
|
||||||
|
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
fRefCount++;
|
fRefCount++;
|
||||||
psettings = this;
|
psettings = this;
|
||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
|
|
||||||
return psettings;
|
return psettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ TranslatorSettings *
|
|||||||
TranslatorSettings::Release()
|
TranslatorSettings::Release()
|
||||||
{
|
{
|
||||||
TranslatorSettings *psettings = NULL;
|
TranslatorSettings *psettings = NULL;
|
||||||
|
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
fRefCount--;
|
fRefCount--;
|
||||||
if (fRefCount > 0) {
|
if (fRefCount > 0) {
|
||||||
@@ -148,8 +148,8 @@ TranslatorSettings::Release()
|
|||||||
delete this;
|
delete this;
|
||||||
// delete this object and
|
// delete this object and
|
||||||
// release locks
|
// release locks
|
||||||
|
|
||||||
return psettings;
|
return psettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@@ -188,9 +188,9 @@ status_t
|
|||||||
TranslatorSettings::LoadSettings()
|
TranslatorSettings::LoadSettings()
|
||||||
{
|
{
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
|
|
||||||
// Don't try to open the settings file if there are
|
// Don't try to open the settings file if there are
|
||||||
// no settings that need to be loaded
|
// no settings that need to be loaded
|
||||||
if (fDefCount > 0) {
|
if (fDefCount > 0) {
|
||||||
@@ -204,9 +204,9 @@ TranslatorSettings::LoadSettings()
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
|
|
||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,9 +294,9 @@ status_t
|
|||||||
TranslatorSettings::SaveSettings()
|
TranslatorSettings::SaveSettings()
|
||||||
{
|
{
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
|
|
||||||
// Only write out settings file if there are
|
// Only write out settings file if there are
|
||||||
// actual settings stored by this object
|
// actual settings stored by this object
|
||||||
if (fDefCount > 0) {
|
if (fDefCount > 0) {
|
||||||
@@ -307,9 +307,9 @@ TranslatorSettings::SaveSettings()
|
|||||||
result = fSettingsMsg.Flatten(&settingsFile);
|
result = fSettingsMsg.Flatten(&settingsFile);
|
||||||
} else
|
} else
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
|
|
||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ status_t
|
|||||||
TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
|
TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
|
||||||
{
|
{
|
||||||
status_t result = B_BAD_VALUE;
|
status_t result = B_BAD_VALUE;
|
||||||
|
|
||||||
if (pmsg) {
|
if (pmsg) {
|
||||||
int32 i;
|
int32 i;
|
||||||
for (i = 0; i < fDefCount; i++) {
|
for (i = 0; i < fDefCount; i++) {
|
||||||
@@ -345,7 +345,7 @@ TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
|
|||||||
if (i == fDefCount) {
|
if (i == fDefCount) {
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
|
|
||||||
const TranSetting *defs = fDefaults;
|
const TranSetting *defs = fDefaults;
|
||||||
for (i = 0; i < fDefCount && result >= B_OK; i++) {
|
for (i = 0; i < fDefCount && result >= B_OK; i++) {
|
||||||
switch (defs[i].dataType) {
|
switch (defs[i].dataType) {
|
||||||
@@ -353,22 +353,22 @@ TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
|
|||||||
result = pmsg->AddBool(defs[i].name,
|
result = pmsg->AddBool(defs[i].name,
|
||||||
SetGetBool(defs[i].name));
|
SetGetBool(defs[i].name));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRAN_SETTING_INT32:
|
case TRAN_SETTING_INT32:
|
||||||
result = pmsg->AddInt32(defs[i].name,
|
result = pmsg->AddInt32(defs[i].name,
|
||||||
SetGetInt32(defs[i].name));
|
SetGetInt32(defs[i].name));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// ASSERT here? Erase the bogus setting entry instead?
|
// ASSERT here? Erase the bogus setting entry instead?
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,9 +420,9 @@ bool
|
|||||||
TranslatorSettings::SetGetBool(const char *name, bool *pbool)
|
TranslatorSettings::SetGetBool(const char *name, bool *pbool)
|
||||||
{
|
{
|
||||||
bool bprevValue;
|
bool bprevValue;
|
||||||
|
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
|
|
||||||
const TranSetting *def = FindTranSetting(name);
|
const TranSetting *def = FindTranSetting(name);
|
||||||
if (def) {
|
if (def) {
|
||||||
fSettingsMsg.FindBool(def->name, &bprevValue);
|
fSettingsMsg.FindBool(def->name, &bprevValue);
|
||||||
@@ -430,9 +430,9 @@ TranslatorSettings::SetGetBool(const char *name, bool *pbool)
|
|||||||
fSettingsMsg.ReplaceBool(def->name, *pbool);
|
fSettingsMsg.ReplaceBool(def->name, *pbool);
|
||||||
} else
|
} else
|
||||||
bprevValue = false;
|
bprevValue = false;
|
||||||
|
|
||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
|
|
||||||
return bprevValue;
|
return bprevValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,9 +458,9 @@ int32
|
|||||||
TranslatorSettings::SetGetInt32(const char *name, int32 *pint32)
|
TranslatorSettings::SetGetInt32(const char *name, int32 *pint32)
|
||||||
{
|
{
|
||||||
int32 prevValue;
|
int32 prevValue;
|
||||||
|
|
||||||
fLock.Lock();
|
fLock.Lock();
|
||||||
|
|
||||||
const TranSetting *def = FindTranSetting(name);
|
const TranSetting *def = FindTranSetting(name);
|
||||||
if (def) {
|
if (def) {
|
||||||
fSettingsMsg.FindInt32(def->name, &prevValue);
|
fSettingsMsg.FindInt32(def->name, &prevValue);
|
||||||
@@ -468,9 +468,9 @@ TranslatorSettings::SetGetInt32(const char *name, int32 *pint32)
|
|||||||
fSettingsMsg.ReplaceInt32(def->name, *pint32);
|
fSettingsMsg.ReplaceInt32(def->name, *pint32);
|
||||||
} else
|
} else
|
||||||
prevValue = 0;
|
prevValue = 0;
|
||||||
|
|
||||||
fLock.Unlock();
|
fLock.Unlock();
|
||||||
|
|
||||||
return prevValue;
|
return prevValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,18 @@
|
|||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
// to deal in the Software without restriction, including without limitation
|
// to deal in the Software without restriction, including without limitation
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
// and/or sell copies of the Software, and to permit persons to whom the
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
// Software is furnished to do so, subject to the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included
|
// The above copyright notice and this permission notice shall be included
|
||||||
// in all copies or substantial portions of the Software.
|
// in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -49,40 +49,40 @@ struct TranSetting {
|
|||||||
|
|
||||||
class TranslatorSettings {
|
class TranslatorSettings {
|
||||||
public:
|
public:
|
||||||
TranslatorSettings(const char *settingsFile, TranSetting *defaults,
|
TranslatorSettings(const char *settingsFile, const TranSetting *defaults,
|
||||||
int32 defCount);
|
int32 defCount);
|
||||||
|
|
||||||
TranslatorSettings *Acquire();
|
TranslatorSettings *Acquire();
|
||||||
// increments the reference count, returns this
|
// increments the reference count, returns this
|
||||||
TranslatorSettings *Release();
|
TranslatorSettings *Release();
|
||||||
// decrements the reference count, deletes this
|
// decrements the reference count, deletes this
|
||||||
// when count reaches zero, returns this when
|
// when count reaches zero, returns this when
|
||||||
// ref count is greater than zero, NULL when
|
// ref count is greater than zero, NULL when
|
||||||
// ref count is zero
|
// ref count is zero
|
||||||
|
|
||||||
status_t LoadSettings();
|
status_t LoadSettings();
|
||||||
status_t LoadSettings(BMessage *pmsg);
|
status_t LoadSettings(BMessage *pmsg);
|
||||||
status_t SaveSettings();
|
status_t SaveSettings();
|
||||||
status_t GetConfigurationMessage(BMessage *pmsg);
|
status_t GetConfigurationMessage(BMessage *pmsg);
|
||||||
|
|
||||||
bool SetGetBool(const char *name, bool *pbool = NULL);
|
bool SetGetBool(const char *name, bool *pbool = NULL);
|
||||||
int32 SetGetInt32(const char *name, int32 *pint32 = NULL);
|
int32 SetGetInt32(const char *name, int32 *pint32 = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const TranSetting *FindTranSetting(const char *name);
|
const TranSetting *FindTranSetting(const char *name);
|
||||||
~TranslatorSettings();
|
~TranslatorSettings();
|
||||||
// private so that Release() must be used
|
// private so that Release() must be used
|
||||||
// to delete the object
|
// to delete the object
|
||||||
|
|
||||||
BLocker fLock;
|
BLocker fLock;
|
||||||
int32 fRefCount;
|
int32 fRefCount;
|
||||||
BPath fSettingsPath;
|
BPath fSettingsPath;
|
||||||
// where the settings file will be loaded from /
|
// where the settings file will be loaded from /
|
||||||
// saved to
|
// saved to
|
||||||
|
|
||||||
BMessage fSettingsMsg;
|
BMessage fSettingsMsg;
|
||||||
// the actual settings
|
// the actual settings
|
||||||
|
|
||||||
const TranSetting *fDefaults;
|
const TranSetting *fDefaults;
|
||||||
int32 fDefCount;
|
int32 fDefCount;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ using namespace std;
|
|||||||
#define DATA_BUFFER_SIZE 256
|
#define DATA_BUFFER_SIZE 256
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
@@ -52,7 +52,7 @@ translation_format gInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
B_TRANSLATOR_TEXT,
|
B_TRANSLATOR_TEXT,
|
||||||
@@ -72,11 +72,15 @@ translation_format gOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
TranSetting gDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// make_nth_translator
|
// make_nth_translator
|
||||||
//
|
//
|
||||||
@@ -119,7 +123,7 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
* Copyright (c) Ian F. Darwin 1986-1995.
|
* Copyright (c) Ian F. Darwin 1986-1995.
|
||||||
* Software written by Ian F. Darwin and others;
|
* Software written by Ian F. Darwin and others;
|
||||||
* maintained 1995-present by Christos Zoulas and others.
|
* maintained 1995-present by Christos Zoulas and others.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -129,7 +133,7 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
@@ -149,12 +153,12 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
if (subtypeMimeSpecific != NULL) {
|
if (subtypeMimeSpecific != NULL) {
|
||||||
mimeType->SetTo(subtypeMimeSpecific);
|
mimeType->SetTo(subtypeMimeSpecific);
|
||||||
if (mimeType->IsInstalled())
|
if (mimeType->IsInstalled())
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found && subtypeMimeGeneric != NULL) {
|
if (!found && subtypeMimeGeneric != NULL) {
|
||||||
mimeType->SetTo(subtypeMimeGeneric);
|
mimeType->SetTo(subtypeMimeGeneric);
|
||||||
if (mimeType->IsInstalled())
|
if (mimeType->IsInstalled())
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
mimeType->SetTo("text/plain");
|
mimeType->SetTo("text/plain");
|
||||||
@@ -195,7 +199,7 @@ file_ascmagic(const unsigned char *buf, size_t nbytes, BMimeType* mimeType,
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned char *nbuf = NULL;
|
unsigned char *nbuf = NULL;
|
||||||
my_unichar *ubuf = NULL;
|
my_unichar *ubuf = NULL;
|
||||||
size_t ulen;
|
size_t ulen;
|
||||||
struct names *p;
|
struct names *p;
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
@@ -260,7 +264,7 @@ file_ascmagic(const unsigned char *buf, size_t nbytes, BMimeType* mimeType,
|
|||||||
} else if (looks_latin1(buf, nbytes, ubuf, &ulen)) {
|
} else if (looks_latin1(buf, nbytes, ubuf, &ulen)) {
|
||||||
code = "ISO-8859";
|
code = "ISO-8859";
|
||||||
type = "text";
|
type = "text";
|
||||||
encoding = "iso-8859-1";
|
encoding = "iso-8859-1";
|
||||||
} else if (looks_extended(buf, nbytes, ubuf, &ulen)) {
|
} else if (looks_extended(buf, nbytes, ubuf, &ulen)) {
|
||||||
code = "Non-ISO extended-ASCII";
|
code = "Non-ISO extended-ASCII";
|
||||||
type = "text";
|
type = "text";
|
||||||
@@ -407,12 +411,12 @@ done:
|
|||||||
if (subtypeMimeSpecific != NULL) {
|
if (subtypeMimeSpecific != NULL) {
|
||||||
mimeType->SetTo(subtypeMimeSpecific);
|
mimeType->SetTo(subtypeMimeSpecific);
|
||||||
if (mimeType->IsInstalled())
|
if (mimeType->IsInstalled())
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found && subtypeMimeGeneric != NULL) {
|
if (!found && subtypeMimeGeneric != NULL) {
|
||||||
mimeType->SetTo(subtypeMimeGeneric);
|
mimeType->SetTo(subtypeMimeGeneric);
|
||||||
if (mimeType->IsInstalled())
|
if (mimeType->IsInstalled())
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
mimeType->SetTo("text/plain");
|
mimeType->SetTo("text/plain");
|
||||||
@@ -789,19 +793,19 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
|
|||||||
{
|
{
|
||||||
const ssize_t ktxtsize = sizeof(TranslatorStyledTextTextHeader);
|
const ssize_t ktxtsize = sizeof(TranslatorStyledTextTextHeader);
|
||||||
const ssize_t kstylsize = sizeof(TranslatorStyledTextStyleHeader);
|
const ssize_t kstylsize = sizeof(TranslatorStyledTextStyleHeader);
|
||||||
|
|
||||||
uint8 buffer[max(ktxtsize, kstylsize)];
|
uint8 buffer[max(ktxtsize, kstylsize)];
|
||||||
|
|
||||||
// Check the TEXT header
|
// Check the TEXT header
|
||||||
TranslatorStyledTextTextHeader txtheader;
|
TranslatorStyledTextTextHeader txtheader;
|
||||||
if (inSource->Read(buffer, ktxtsize) != ktxtsize)
|
if (inSource->Read(buffer, ktxtsize) != ktxtsize)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
memcpy(&txtheader, buffer, ktxtsize);
|
memcpy(&txtheader, buffer, ktxtsize);
|
||||||
if (swap_data(B_UINT32_TYPE, &txtheader, ktxtsize,
|
if (swap_data(B_UINT32_TYPE, &txtheader, ktxtsize,
|
||||||
B_SWAP_BENDIAN_TO_HOST) != B_OK)
|
B_SWAP_BENDIAN_TO_HOST) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (txtheader.header.magic != 'TEXT'
|
if (txtheader.header.magic != 'TEXT'
|
||||||
|| txtheader.header.header_size != sizeof(TranslatorStyledTextTextHeader)
|
|| txtheader.header.header_size != sizeof(TranslatorStyledTextTextHeader)
|
||||||
|| txtheader.charset != B_UNICODE_UTF8)
|
|| txtheader.charset != B_UNICODE_UTF8)
|
||||||
@@ -835,7 +839,7 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (stylheader.header.magic != 'STYL'
|
if (stylheader.header.magic != 'STYL'
|
||||||
|| stylheader.header.header_size !=
|
|| stylheader.header.header_size !=
|
||||||
sizeof(TranslatorStyledTextStyleHeader))
|
sizeof(TranslatorStyledTextStyleHeader))
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
@@ -943,10 +947,10 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
|
|||||||
{
|
{
|
||||||
if (inSource->Seek(0, SEEK_SET) != 0)
|
if (inSource->Seek(0, SEEK_SET) != 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
const ssize_t kstxtsize = sizeof(TranslatorStyledTextStreamHeader);
|
const ssize_t kstxtsize = sizeof(TranslatorStyledTextStreamHeader);
|
||||||
const ssize_t ktxtsize = sizeof(TranslatorStyledTextTextHeader);
|
const ssize_t ktxtsize = sizeof(TranslatorStyledTextTextHeader);
|
||||||
|
|
||||||
bool btoplain;
|
bool btoplain;
|
||||||
if (outType == B_TRANSLATOR_TEXT)
|
if (outType == B_TRANSLATOR_TEXT)
|
||||||
btoplain = true;
|
btoplain = true;
|
||||||
@@ -954,19 +958,19 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
|
|||||||
btoplain = false;
|
btoplain = false;
|
||||||
else
|
else
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
uint8 buffer[READ_BUFFER_SIZE];
|
uint8 buffer[READ_BUFFER_SIZE];
|
||||||
ssize_t nread = 0, nwritten = 0, nreed = 0, ntotalread = 0;
|
ssize_t nread = 0, nwritten = 0, nreed = 0, ntotalread = 0;
|
||||||
|
|
||||||
// skip to the actual text data when outputting a
|
// skip to the actual text data when outputting a
|
||||||
// plain text file
|
// plain text file
|
||||||
if (btoplain) {
|
if (btoplain) {
|
||||||
if (inSource->Seek(kstxtsize + ktxtsize, SEEK_CUR) !=
|
if (inSource->Seek(kstxtsize + ktxtsize, SEEK_CUR) !=
|
||||||
kstxtsize + ktxtsize)
|
kstxtsize + ktxtsize)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read data from inSource
|
// Read data from inSource
|
||||||
// When outputing B_TRANSLATOR_TEXT, the loop stops when all of
|
// When outputing B_TRANSLATOR_TEXT, the loop stops when all of
|
||||||
// the text data has been read and written.
|
// the text data has been read and written.
|
||||||
// When outputting B_STYLED_TEXT_FORMAT, the loop stops when all
|
// When outputting B_STYLED_TEXT_FORMAT, the loop stops when all
|
||||||
@@ -990,7 +994,7 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
|
|||||||
nreed = READ_BUFFER_SIZE;
|
nreed = READ_BUFFER_SIZE;
|
||||||
nread = inSource->Read(buffer, nreed);
|
nread = inSource->Read(buffer, nreed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (btoplain && static_cast<ssize_t>(txtheader.header.data_size) !=
|
if (btoplain && static_cast<ssize_t>(txtheader.header.data_size) !=
|
||||||
ntotalread)
|
ntotalread)
|
||||||
// If not all of the text data was able to be read...
|
// If not all of the text data was able to be read...
|
||||||
@@ -1017,10 +1021,10 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
|
|||||||
//
|
//
|
||||||
// Postconditions:
|
// Postconditions:
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
//
|
//
|
||||||
// B_ERROR, if there was an error writing to outDestination or
|
// B_ERROR, if there was an error writing to outDestination or
|
||||||
// an error with converting the byte order
|
// an error with converting the byte order
|
||||||
//
|
//
|
||||||
// B_OK, if all went well
|
// B_OK, if all went well
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@@ -1032,22 +1036,22 @@ output_headers(BPositionIO *outDestination, uint32 text_data_size)
|
|||||||
status_t result;
|
status_t result;
|
||||||
TranslatorStyledTextStreamHeader stxtheader;
|
TranslatorStyledTextStreamHeader stxtheader;
|
||||||
TranslatorStyledTextTextHeader txtheader;
|
TranslatorStyledTextTextHeader txtheader;
|
||||||
|
|
||||||
uint8 buffer[kHeadersSize];
|
uint8 buffer[kHeadersSize];
|
||||||
|
|
||||||
stxtheader.header.magic = 'STXT';
|
stxtheader.header.magic = 'STXT';
|
||||||
stxtheader.header.header_size = sizeof(TranslatorStyledTextStreamHeader);
|
stxtheader.header.header_size = sizeof(TranslatorStyledTextStreamHeader);
|
||||||
stxtheader.header.data_size = 0;
|
stxtheader.header.data_size = 0;
|
||||||
stxtheader.version = 100;
|
stxtheader.version = 100;
|
||||||
memcpy(buffer, &stxtheader, stxtheader.header.header_size);
|
memcpy(buffer, &stxtheader, stxtheader.header.header_size);
|
||||||
|
|
||||||
txtheader.header.magic = 'TEXT';
|
txtheader.header.magic = 'TEXT';
|
||||||
txtheader.header.header_size = sizeof(TranslatorStyledTextTextHeader);
|
txtheader.header.header_size = sizeof(TranslatorStyledTextTextHeader);
|
||||||
txtheader.header.data_size = text_data_size;
|
txtheader.header.data_size = text_data_size;
|
||||||
txtheader.charset = B_UNICODE_UTF8;
|
txtheader.charset = B_UNICODE_UTF8;
|
||||||
memcpy(buffer + stxtheader.header.header_size, &txtheader,
|
memcpy(buffer + stxtheader.header.header_size, &txtheader,
|
||||||
txtheader.header.header_size);
|
txtheader.header.header_size);
|
||||||
|
|
||||||
// write out headers in Big Endian byte order
|
// write out headers in Big Endian byte order
|
||||||
result = swap_data(B_UINT32_TYPE, buffer, kHeadersSize,
|
result = swap_data(B_UINT32_TYPE, buffer, kHeadersSize,
|
||||||
B_SWAP_HOST_TO_BENDIAN);
|
B_SWAP_HOST_TO_BENDIAN);
|
||||||
@@ -1059,7 +1063,7 @@ output_headers(BPositionIO *outDestination, uint32 text_data_size)
|
|||||||
else
|
else
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1084,7 +1088,7 @@ output_headers(BPositionIO *outDestination, uint32 text_data_size)
|
|||||||
// Returns:
|
// Returns:
|
||||||
//
|
//
|
||||||
// B_ERROR, if there was an error writing to outDestination or
|
// B_ERROR, if there was an error writing to outDestination or
|
||||||
// an error with converting the byte order
|
// an error with converting the byte order
|
||||||
//
|
//
|
||||||
// B_OK, if all went well
|
// B_OK, if all went well
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@@ -1093,9 +1097,9 @@ output_styles(BPositionIO *outDestination, uint32 text_size,
|
|||||||
uint8 *pflatRunArray, ssize_t data_size)
|
uint8 *pflatRunArray, ssize_t data_size)
|
||||||
{
|
{
|
||||||
const ssize_t kstylsize = sizeof(TranslatorStyledTextStyleHeader);
|
const ssize_t kstylsize = sizeof(TranslatorStyledTextStyleHeader);
|
||||||
|
|
||||||
uint8 buffer[kstylsize];
|
uint8 buffer[kstylsize];
|
||||||
|
|
||||||
// output STYL header
|
// output STYL header
|
||||||
TranslatorStyledTextStyleHeader stylheader;
|
TranslatorStyledTextStyleHeader stylheader;
|
||||||
stylheader.header.magic = 'STYL';
|
stylheader.header.magic = 'STYL';
|
||||||
@@ -1104,19 +1108,19 @@ output_styles(BPositionIO *outDestination, uint32 text_size,
|
|||||||
stylheader.header.data_size = data_size;
|
stylheader.header.data_size = data_size;
|
||||||
stylheader.apply_offset = 0;
|
stylheader.apply_offset = 0;
|
||||||
stylheader.apply_length = text_size;
|
stylheader.apply_length = text_size;
|
||||||
|
|
||||||
memcpy(buffer, &stylheader, kstylsize);
|
memcpy(buffer, &stylheader, kstylsize);
|
||||||
if (swap_data(B_UINT32_TYPE, buffer, kstylsize,
|
if (swap_data(B_UINT32_TYPE, buffer, kstylsize,
|
||||||
B_SWAP_HOST_TO_BENDIAN) != B_OK)
|
B_SWAP_HOST_TO_BENDIAN) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
if (outDestination->Write(buffer, kstylsize) != kstylsize)
|
if (outDestination->Write(buffer, kstylsize) != kstylsize)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// output actual style information
|
// output actual style information
|
||||||
if (outDestination->Write(pflatRunArray,
|
if (outDestination->Write(pflatRunArray,
|
||||||
data_size) != data_size)
|
data_size) != data_size)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1290,7 +1294,7 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read file attributes if outputting styled data
|
// Read file attributes if outputting styled data
|
||||||
// and source is a BNode object
|
// and source is a BNode object
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
@@ -1331,10 +1335,10 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
|||||||
STXTTranslator::STXTTranslator()
|
STXTTranslator::STXTTranslator()
|
||||||
: BaseTranslator("StyledEdit files", "StyledEdit files translator",
|
: BaseTranslator("StyledEdit files", "StyledEdit files translator",
|
||||||
STXT_TRANSLATOR_VERSION,
|
STXT_TRANSLATOR_VERSION,
|
||||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
sInputFormats, kNumInputFormats,
|
||||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"STXTTranslator_Settings",
|
"STXTTranslator_Settings",
|
||||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_TEXT, B_STYLED_TEXT_FORMAT)
|
B_TRANSLATOR_TEXT, B_STYLED_TEXT_FORMAT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1354,9 +1358,9 @@ STXTTranslator::Identify(BPositionIO *inSource,
|
|||||||
outType = B_TRANSLATOR_TEXT;
|
outType = B_TRANSLATOR_TEXT;
|
||||||
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
|
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
const ssize_t kstxtsize = sizeof(TranslatorStyledTextStreamHeader);
|
const ssize_t kstxtsize = sizeof(TranslatorStyledTextStreamHeader);
|
||||||
|
|
||||||
uint8 buffer[DATA_BUFFER_SIZE];
|
uint8 buffer[DATA_BUFFER_SIZE];
|
||||||
status_t nread = 0;
|
status_t nread = 0;
|
||||||
// Read in the header to determine
|
// Read in the header to determine
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
How this works:
|
How this works:
|
||||||
|
|
||||||
libtiff has a special version of TIFFOpen() that gets passed custom
|
libtiff has a special version of TIFFOpen() that gets passed custom
|
||||||
functions for reading writing etc. and a handle. This handle in our case
|
functions for reading writing etc. and a handle. This handle in our case
|
||||||
is a BPositionIO object, which libtiff passes on to the functions for reading
|
is a BPositionIO object, which libtiff passes on to the functions for reading
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -50,7 +50,7 @@ translation_format gInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -70,13 +70,18 @@ translation_format gOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
TranSetting gDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{TIFF_SETTING_COMPRESSION, TRAN_SETTING_INT32, COMPRESSION_LZW}
|
{TIFF_SETTING_COMPRESSION, TRAN_SETTING_INT32, COMPRESSION_LZW}
|
||||||
// Compression is LZW by default
|
// Compression is LZW by default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// make_nth_translator
|
// make_nth_translator
|
||||||
//
|
//
|
||||||
@@ -118,7 +123,7 @@ tiff_get_pio(thandle_t stream)
|
|||||||
pio = static_cast<BPositionIO *>(stream);
|
pio = static_cast<BPositionIO *>(stream);
|
||||||
if (!pio)
|
if (!pio)
|
||||||
debugger("pio is NULL");
|
debugger("pio is NULL");
|
||||||
|
|
||||||
return pio;
|
return pio;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +160,7 @@ tiff_size_proc(thandle_t stream)
|
|||||||
cur = pio->Position();
|
cur = pio->Position();
|
||||||
end = pio->Seek(0, SEEK_END);
|
end = pio->Seek(0, SEEK_END);
|
||||||
pio->Seek(cur, SEEK_SET);
|
pio->Seek(cur, SEEK_SET);
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,10 +182,10 @@ status_t
|
|||||||
identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
|
identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
|
||||||
translator_info *outInfo, uint32 outType, TIFF **poutTIFF = NULL)
|
translator_info *outInfo, uint32 outType, TIFF **poutTIFF = NULL)
|
||||||
{
|
{
|
||||||
// get TIFF handle
|
// get TIFF handle
|
||||||
TIFF* tif = TIFFClientOpen("TIFFTranslator", "r", inSource,
|
TIFF* tif = TIFFClientOpen("TIFFTranslator", "r", inSource,
|
||||||
tiff_read_proc, tiff_write_proc, tiff_seek_proc, tiff_close_proc,
|
tiff_read_proc, tiff_write_proc, tiff_seek_proc, tiff_close_proc,
|
||||||
tiff_size_proc, tiff_map_file_proc, tiff_unmap_file_proc);
|
tiff_size_proc, tiff_map_file_proc, tiff_unmap_file_proc);
|
||||||
if (!tif)
|
if (!tif)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
@@ -234,7 +239,7 @@ identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
|
|||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// How this works:
|
// How this works:
|
||||||
// Following are a couple of functions,
|
// Following are a couple of functions,
|
||||||
@@ -593,10 +598,10 @@ write_tif_stream(TIFF* tif, BPositionIO* inSource, color_space format,
|
|||||||
TIFFTranslator::TIFFTranslator()
|
TIFFTranslator::TIFFTranslator()
|
||||||
: BaseTranslator("TIFF images", "TIFF image translator",
|
: BaseTranslator("TIFF images", "TIFF image translator",
|
||||||
TIFF_TRANSLATOR_VERSION,
|
TIFF_TRANSLATOR_VERSION,
|
||||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
sInputFormats, kNumInputFormats,
|
||||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"TIFFTranslator_Settings",
|
"TIFFTranslator_Settings",
|
||||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_BITMAP, B_TIFF_FORMAT)
|
B_TRANSLATOR_BITMAP, B_TIFF_FORMAT)
|
||||||
{
|
{
|
||||||
// TODO: for now!
|
// TODO: for now!
|
||||||
@@ -630,15 +635,15 @@ TIFFTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
|||||||
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
result = identify_bits_header(inSource, NULL, &bitsHeader);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Translate B_TRANSLATOR_BITMAP to B_TIFF_FORMAT
|
// Translate B_TRANSLATOR_BITMAP to B_TIFF_FORMAT
|
||||||
if (outType == B_TIFF_FORMAT) {
|
if (outType == B_TIFF_FORMAT) {
|
||||||
// Set up TIFF header
|
// Set up TIFF header
|
||||||
|
|
||||||
// get TIFF handle
|
// get TIFF handle
|
||||||
TIFF* tif = TIFFClientOpen("TIFFTranslator", "w", outDestination,
|
TIFF* tif = TIFFClientOpen("TIFFTranslator", "w", outDestination,
|
||||||
tiff_read_proc, tiff_write_proc, tiff_seek_proc, tiff_close_proc,
|
tiff_read_proc, tiff_write_proc, tiff_seek_proc, tiff_close_proc,
|
||||||
tiff_size_proc, tiff_map_file_proc, tiff_unmap_file_proc);
|
tiff_size_proc, tiff_map_file_proc, tiff_unmap_file_proc);
|
||||||
if (!tif)
|
if (!tif)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
@@ -769,7 +774,7 @@ printf("using unkown compression (%ld).\n", compression);
|
|||||||
default:
|
default:
|
||||||
ret = B_NO_TRANSLATOR;
|
ret = B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
// Close the handle
|
// Close the handle
|
||||||
TIFFClose(tif);
|
TIFFClose(tif);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@@ -787,16 +792,16 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
|
|||||||
// Always write out the entire image. Some programs
|
// Always write out the entire image. Some programs
|
||||||
// fail when given "headerOnly", even though they requested it.
|
// fail when given "headerOnly", even though they requested it.
|
||||||
// These settings are not applicable when outputting TIFFs
|
// These settings are not applicable when outputting TIFFs
|
||||||
|
|
||||||
// variables needing cleanup
|
// variables needing cleanup
|
||||||
TIFF *ptif = NULL;
|
TIFF *ptif = NULL;
|
||||||
uint32 *praster = NULL;
|
uint32 *praster = NULL;
|
||||||
|
|
||||||
status_t ret;
|
status_t ret;
|
||||||
ret = identify_tiff_header(inSource, ioExtension, NULL, outType, &ptif);
|
ret = identify_tiff_header(inSource, ioExtension, NULL, outType, &ptif);
|
||||||
|
|
||||||
if (outType == B_TIFF_FORMAT && ret == B_OK && ptif) {
|
if (outType == B_TIFF_FORMAT && ret == B_OK && ptif) {
|
||||||
// if translating from TIFF to TIFF,
|
// if translating from TIFF to TIFF,
|
||||||
// just write out the entire TIFF
|
// just write out the entire TIFF
|
||||||
TIFFClose(ptif);
|
TIFFClose(ptif);
|
||||||
translate_direct_copy(inSource, outDestination);
|
translate_direct_copy(inSource, outDestination);
|
||||||
@@ -804,12 +809,12 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (ret == B_OK && ptif) {
|
while (ret == B_OK && ptif) {
|
||||||
// use while / break not for looping, but for
|
// use while / break not for looping, but for
|
||||||
// cleaner goto like capability
|
// cleaner goto like capability
|
||||||
|
|
||||||
ret = B_ERROR;
|
ret = B_ERROR;
|
||||||
// make certain there is no looping
|
// make certain there is no looping
|
||||||
|
|
||||||
uint32 width = 0, height = 0;
|
uint32 width = 0, height = 0;
|
||||||
if (!TIFFGetField(ptif, TIFFTAG_IMAGEWIDTH, &width)) {
|
if (!TIFFGetField(ptif, TIFFTAG_IMAGEWIDTH, &width)) {
|
||||||
result = B_NO_TRANSLATOR;
|
result = B_NO_TRANSLATOR;
|
||||||
@@ -841,7 +846,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
|
|||||||
}
|
}
|
||||||
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bheaderonly) {
|
if (!bheaderonly) {
|
||||||
// Convert raw RGBA data to B_RGBA32 colorspace
|
// Convert raw RGBA data to B_RGBA32 colorspace
|
||||||
// and write out the results
|
// and write out the results
|
||||||
@@ -855,7 +860,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
|
|||||||
uint8 *pbits, *prgba;
|
uint8 *pbits, *prgba;
|
||||||
pbits = pbitsrow;
|
pbits = pbitsrow;
|
||||||
prgba = pras8 + ((height - (i + 1)) * width * 4);
|
prgba = pras8 + ((height - (i + 1)) * width * 4);
|
||||||
|
|
||||||
for (uint32 k = 0; k < width; k++) {
|
for (uint32 k = 0; k < width; k++) {
|
||||||
pbits[0] = prgba[2];
|
pbits[0] = prgba[2];
|
||||||
pbits[1] = prgba[1];
|
pbits[1] = prgba[1];
|
||||||
@@ -875,7 +880,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
} // if (praster && TIFFReadRGBAImage(ptif, width, height, praster, 0))
|
} // if (praster && TIFFReadRGBAImage(ptif, width, height, praster, 0))
|
||||||
|
|
||||||
} // while (ret == B_OK && ptif)
|
} // while (ret == B_OK && ptif)
|
||||||
|
|
||||||
if (praster) {
|
if (praster) {
|
||||||
@@ -899,7 +904,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
|
|||||||
// Preconditions:
|
// Preconditions:
|
||||||
//
|
//
|
||||||
// Parameters: inSource, the data to be translated
|
// Parameters: inSource, the data to be translated
|
||||||
//
|
//
|
||||||
// inInfo, hint about the data in inSource (not used)
|
// inInfo, hint about the data in inSource (not used)
|
||||||
//
|
//
|
||||||
// ioExtension, configuration options for the
|
// ioExtension, configuration options for the
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class FreeAllocation {
|
|||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
{
|
{
|
||||||
WEBP_IMAGE_FORMAT,
|
WEBP_IMAGE_FORMAT,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -53,7 +53,7 @@ translation_format sInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format sOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -65,7 +65,7 @@ translation_format sOutputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
static TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format gInputFormats[] = {
|
static const translation_format sInputFormats[] = {
|
||||||
/*{
|
/*{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -43,7 +43,7 @@ translation_format gInputFormats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The output formats that this translator supports.
|
// The output formats that this translator supports.
|
||||||
translation_format gOutputFormats[] = {
|
static const translation_format sOutputFormats[] = {
|
||||||
{
|
{
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
B_TRANSLATOR_BITMAP,
|
B_TRANSLATOR_BITMAP,
|
||||||
@@ -64,11 +64,15 @@ translation_format gOutputFormats[] = {
|
|||||||
|
|
||||||
|
|
||||||
// Default settings for the Translator
|
// Default settings for the Translator
|
||||||
TranSetting gDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{ B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false },
|
{ B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false },
|
||||||
{ B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false }
|
{ B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint32 kNumInputFormats = sizeof(sInputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_format);
|
||||||
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
BTranslator*
|
BTranslator*
|
||||||
make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
||||||
@@ -83,10 +87,10 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
WonderBrushTranslator::WonderBrushTranslator()
|
WonderBrushTranslator::WonderBrushTranslator()
|
||||||
: BaseTranslator("WonderBrush images", "WonderBrush image translator",
|
: BaseTranslator("WonderBrush images", "WonderBrush image translator",
|
||||||
WBI_TRANSLATOR_VERSION,
|
WBI_TRANSLATOR_VERSION,
|
||||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
sInputFormats, kNumInputFormats,
|
||||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
sOutputFormats, kNumOutputFormats,
|
||||||
"WBITranslator_Settings",
|
"WBITranslator_Settings",
|
||||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
sDefaultSettings, kNumDefaultSettings,
|
||||||
B_TRANSLATOR_BITMAP, WBI_FORMAT)
|
B_TRANSLATOR_BITMAP, WBI_FORMAT)
|
||||||
{
|
{
|
||||||
#if GAMMA_BLEND
|
#if GAMMA_BLEND
|
||||||
@@ -112,7 +116,7 @@ identify_wbi_header(BPositionIO* inSource, translator_info* outInfo,
|
|||||||
WonderBrushImage* wbImage = new(nothrow) WonderBrushImage();
|
WonderBrushImage* wbImage = new(nothrow) WonderBrushImage();
|
||||||
if (wbImage)
|
if (wbImage)
|
||||||
status = wbImage->SetTo(inSource);
|
status = wbImage->SetTo(inSource);
|
||||||
|
|
||||||
if (status >= B_OK) {
|
if (status >= B_OK) {
|
||||||
if (outInfo) {
|
if (outInfo) {
|
||||||
outInfo->type = WBI_FORMAT;
|
outInfo->type = WBI_FORMAT;
|
||||||
@@ -137,7 +141,7 @@ identify_wbi_header(BPositionIO* inSource, translator_info* outInfo,
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
WonderBrushTranslator::DerivedIdentify(BPositionIO* inSource,
|
WonderBrushTranslator::DerivedIdentify(BPositionIO* inSource,
|
||||||
@@ -159,7 +163,7 @@ WonderBrushTranslator::DerivedTranslate(BPositionIO* inSource,
|
|||||||
else
|
else
|
||||||
// if BaseTranslator did not properly identify the data as
|
// if BaseTranslator did not properly identify the data as
|
||||||
// bits or not bits
|
// bits or not bits
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user