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:
Philippe Houdoin 2011-01-18 19:39:13 +00:00
parent 63652401db
commit bf243977ff
22 changed files with 809 additions and 769 deletions

View File

@ -25,7 +25,7 @@ using std::min;
#define ERROR(x)
// The input formats that this translator supports.
translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -45,7 +45,7 @@ translation_format gInputFormats[] = {
};
// The output formats that this translator supports.
translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -65,11 +65,16 @@ translation_format gOutputFormats[] = {
};
// Default settings for the Translator
TranSetting gDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_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
//
@ -118,10 +123,10 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
BMPTranslator::BMPTranslator()
: BaseTranslator("BMP images", "BMP image translator",
BMP_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"BMPTranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, B_BMP_FORMAT)
{
}
@ -148,7 +153,7 @@ BMPTranslator::~BMPTranslator()
//
// Returns number of bytes of padding required at the end of
// the row by the BMP format
//
//
//
// Preconditions: If bitsperpixel is zero, a division by zero
// will occur, which is bad
@ -159,13 +164,13 @@ BMPTranslator::~BMPTranslator()
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
// Returns:
// ---------------------------------------------------------------
int32
get_padding(uint32 width, uint16 bitsperpixel)
{
int32 padding = 0;
if (bitsperpixel > 8) {
uint8 bytesPerPixel = bitsperpixel / 8;
padding = (width * bytesPerPixel) % 4;
@ -178,10 +183,10 @@ get_padding(uint32 width, uint16 bitsperpixel)
(width % pixelsPerByte)) /
pixelsPerByte) % 4;
}
if (padding)
padding = 4 - 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
// with a width of width and a bit depth of bitsperpixel.
//
//
//
// Preconditions: If bitsperpixel is zero, a division by zero
// will occur, which is bad
@ -201,14 +206,14 @@ get_padding(uint32 width, uint16 bitsperpixel)
//
// Postconditions:
//
// Returns:
// Returns:
// ---------------------------------------------------------------
int32
get_rowbytes(uint32 width, uint16 bitsperpixel)
{
int32 rowbytes = 0;
int32 padding = get_padding(width, bitsperpixel);
if (bitsperpixel > 8) {
uint8 bytesPerPixel = bitsperpixel / 8;
rowbytes = (width * bytesPerPixel) + padding;
@ -217,7 +222,7 @@ get_rowbytes(uint32 width, uint16 bitsperpixel)
rowbytes = (width / pixelsPerByte) +
((width % pixelsPerByte) ? 1 : 0) + padding;
}
return rowbytes;
}
@ -278,14 +283,14 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
ssize_t size = 14;
if (inSource->Read(buf, size) != size)
return B_NO_TRANSLATOR;
// check BMP magic number
const uint16 kBmpMagic = B_HOST_TO_LENDIAN_INT16('MB');
uint16 sourceMagic;
memcpy(&sourceMagic, buf, sizeof(uint16));
if (sourceMagic != kBmpMagic)
return B_NO_TRANSLATOR;
// convert fileHeader to host byte order
memcpy(&fileHeader.magic, buf, 2);
memcpy(&fileHeader.fileSize, buf + 2, 4);
@ -301,32 +306,32 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
if (fileHeader.reserved != 0)
return B_NO_TRANSLATOR;
uint32 headersize = 0;
if (inSource->Read(&headersize, 4) != 4)
return B_NO_TRANSLATOR;
if (swap_data(B_UINT32_TYPE, &headersize, 4,
B_SWAP_LENDIAN_TO_HOST) != B_OK)
return B_ERROR;
if (headersize == sizeof(MSInfoHeader)) {
// MS format
if (fileHeader.dataOffset < 54)
return B_NO_TRANSLATOR;
MSInfoHeader msheader;
msheader.size = headersize;
if (inSource->Read(
reinterpret_cast<uint8 *> (&msheader) + 4, 36) != 36)
return B_NO_TRANSLATOR;
// convert msheader to host byte order
if (swap_data(B_UINT32_TYPE,
reinterpret_cast<uint8 *> (&msheader) + 4, 36,
B_SWAP_LENDIAN_TO_HOST) != B_OK)
return B_ERROR;
// check if msheader is valid
if (msheader.width == 0 || msheader.height == 0)
return B_NO_TRANSLATOR;
@ -350,8 +355,8 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
if (!msheader.imagesize && msheader.compression)
return B_NO_TRANSLATOR;
if (msheader.colorsimportant > msheader.colorsused)
return B_NO_TRANSLATOR;
return B_NO_TRANSLATOR;
if (outInfo) {
outInfo->type = B_BMP_FORMAT;
outInfo->group = B_TRANSLATOR_BITMAP;
@ -365,7 +370,7 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
strcat(outInfo->name, ")");
strcpy(outInfo->MIME, "image/x-bmp");
}
if (pfileheader) {
pfileheader->magic = fileHeader.magic;
pfileheader->fileSize = fileHeader.fileSize;
@ -389,7 +394,7 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
}
if (pfrommsformat)
(*pfrommsformat) = true;
return B_OK;
} else if (headersize == sizeof(OS2InfoHeader)) {
@ -397,19 +402,19 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
if (fileHeader.dataOffset < 26)
return B_NO_TRANSLATOR;
OS2InfoHeader os2header;
os2header.size = headersize;
if (inSource->Read(
reinterpret_cast<uint8 *> (&os2header) + 4, 8) != 8)
return B_NO_TRANSLATOR;
// convert msheader to host byte order
if (swap_data(B_UINT32_TYPE,
reinterpret_cast<uint8 *> (&os2header) + 4, 8,
B_SWAP_LENDIAN_TO_HOST) != B_OK)
return B_ERROR;
// check if msheader is valid
if (os2header.width == 0 || os2header.height == 0)
return B_NO_TRANSLATOR;
@ -420,7 +425,7 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
os2header.bitsperpixel != 8 &&
os2header.bitsperpixel != 24)
return B_NO_TRANSLATOR;
if (outInfo) {
outInfo->type = B_BMP_FORMAT;
outInfo->group = B_TRANSLATOR_BITMAP;
@ -447,21 +452,21 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
pmsheader->ypixperm = 2835; // 72 dpi vertical
pmsheader->colorsused = 0;
pmsheader->colorsimportant = 0;
// determine fileSize / imagesize
switch (pmsheader->bitsperpixel) {
case 24:
if (pos2skip && fileHeader.dataOffset > 26)
(*pos2skip) = fileHeader.dataOffset - 26;
pfileheader->dataOffset = 54;
pmsheader->imagesize = get_rowbytes(pmsheader->width,
pmsheader->bitsperpixel) * pmsheader->height;
pfileheader->fileSize = pfileheader->dataOffset +
pmsheader->imagesize;
break;
case 8:
case 4:
case 1:
@ -479,17 +484,17 @@ identify_bmp_header(BPositionIO *inSource, translator_info *outInfo,
pmsheader->bitsperpixel) * pmsheader->height;
pfileheader->fileSize = pfileheader->dataOffset +
pmsheader->imagesize;
break;
}
default:
break;
}
}
if (pfrommsformat)
(*pfrommsformat) = false;
return B_OK;
} else
@ -583,13 +588,13 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
case B_CMYK32:
bitsBytesPerPixel = 4;
break;
case B_RGB24:
case B_RGB24_BIG:
case B_CMY24:
bitsBytesPerPixel = 3;
break;
case B_RGB16:
case B_RGB16_BIG:
case B_RGBA15:
@ -598,12 +603,12 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
case B_RGB15_BIG:
bitsBytesPerPixel = 2;
break;
case B_CMAP8:
case B_GRAY8:
bitsBytesPerPixel = 1;
break;
default:
return B_ERROR;
}
@ -634,7 +639,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
}
}
while (rd == static_cast<ssize_t>(bitsRowBytes)) {
for (uint32 i = 0; i < msheader.width; i++) {
uint8 *bitspixel, *bmppixel;
uint16 val;
@ -645,7 +650,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
memcpy(bmpRowData + (i * 3),
bitsRowData + (i * bitsBytesPerPixel), 3);
break;
case B_RGB16:
case B_RGB16_BIG:
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
@ -673,14 +678,14 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
val = bitspixel[0] + (bitspixel[1] << 8);
else
val = bitspixel[1] + (bitspixel[0] << 8);
bmppixel[0] =
bmppixel[0] =
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
bmppixel[1] =
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
bmppixel[2] =
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
break;
case B_RGB32_BIG:
case B_RGBA32_BIG:
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
@ -689,7 +694,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
bmppixel[1] = bitspixel[2];
bmppixel[2] = bitspixel[1];
break;
case B_RGB24_BIG:
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
bmppixel = bmpRowData + (i * 3);
@ -697,7 +702,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
bmppixel[1] = bitspixel[1];
bmppixel[2] = bitspixel[0];
break;
case B_CMAP8:
{
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
@ -708,7 +713,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
bmppixel[2] = c.red;
break;
}
case B_GRAY8:
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
bmppixel = bmpRowData + (i * 3);
@ -716,23 +721,23 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
bmppixel[1] = bitspixel[0];
bmppixel[2] = bitspixel[0];
break;
case B_CMYK32:
{
bitspixel = bitsRowData + (i * bitsBytesPerPixel);
bmppixel = bmpRowData + (i * 3);
int32 comp = 255 - bitspixel[2] - bitspixel[3];
bmppixel[0] = (comp < 0) ? 0 : comp;
comp = 255 - bitspixel[1] - bitspixel[3];
bmppixel[1] = (comp < 0) ? 0 : comp;
comp = 255 - bitspixel[0] - bitspixel[3];
bmppixel[2] = (comp < 0) ? 0 : comp;
break;
}
case B_CMY32:
case B_CMYA32:
case B_CMY24:
@ -742,16 +747,16 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
bmppixel[1] = 255 - bitspixel[1];
bmppixel[2] = 255 - bitspixel[0];
break;
default:
break;
} // switch (fromspace)
} // for for (uint32 i = 0; i < msheader.width; i++)
outDestination->Write(bmpRowData, bmpRowBytes);
bmppixrow++;
// 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
if (bmppixrow == msheader.height)
break;
@ -759,7 +764,7 @@ BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader)
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
rd = inSource->Read(bitsRowData, bitsRowBytes);
} // while (rd == bitsRowBytes)
delete[] bmpRowData;
delete[] bitsRowData;
@ -815,7 +820,7 @@ translate_from_bits8_to_bmp8(BPositionIO *inSource,
outDestination->Write(bmpRowData, bmpRowBytes);
bmppixrow++;
// 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
if (bmppixrow == msheader.height)
break;
@ -823,7 +828,7 @@ translate_from_bits8_to_bmp8(BPositionIO *inSource,
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
rd = inSource->Read(bitsRowData, bitsRowBytes);
} // while (rd == bitsRowBytes)
delete[] bmpRowData;
delete[] bitsRowData;
@ -876,7 +881,7 @@ translate_from_bits1_to_bmp1(BPositionIO *inSource,
while (rd == bitsRowBytes) {
uint32 bmppixcol = 0;
memset(bmpRowData, 0, bmpRowBytes);
for (int32 i = 0; (bmppixcol < msheader.width) &&
for (int32 i = 0; (bmppixcol < msheader.width) &&
(i < bitsRowBytes); i++) {
// process each byte in the row
uint8 pixels = bitsRowData[i];
@ -891,16 +896,16 @@ translate_from_bits1_to_bmp1(BPositionIO *inSource,
else
// 0 == white
index = 0;
bmpRowData[bmppixcol / pixelsPerByte] |=
bmpRowData[bmppixcol / pixelsPerByte] |=
index << (7 - (bmppixcol % pixelsPerByte));
bmppixcol++;
}
}
outDestination->Write(bmpRowData, bmpRowBytes);
bmppixrow++;
// 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
if (bmppixrow == msheader.height)
break;
@ -908,7 +913,7 @@ translate_from_bits1_to_bmp1(BPositionIO *inSource,
inSource->Seek(bitsRowBytes * -2, SEEK_CUR);
rd = inSource->Read(bitsRowData, bitsRowBytes);
} // while (rd == bitsRowBytes)
delete[] bmpRowData;
delete[] bitsRowData;
@ -956,7 +961,7 @@ write_bmp_headers(BPositionIO *outDestination, BMPFileHeader &fileHeader,
return B_ERROR;
if (outDestination->Write(bmpheaders, 54) != 54)
return B_ERROR;
return B_OK;
}
@ -996,26 +1001,26 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
result = identify_bits_header(inSource, NULL, &bitsHeader);
if (result != B_OK)
return result;
// Translate B_TRANSLATOR_BITMAP to B_BMP_FORMAT
if (outType == B_BMP_FORMAT) {
// Set up BMP header
BMPFileHeader fileHeader;
fileHeader.magic = 'MB';
fileHeader.reserved = 0;
MSInfoHeader msheader;
msheader.size = 40;
msheader.width =
msheader.width =
static_cast<uint32> (bitsHeader.bounds.Width() + 1);
msheader.height =
msheader.height =
static_cast<uint32> (bitsHeader.bounds.Height() + 1);
msheader.planes = 1;
msheader.xpixperm = 2835; // 72 dpi horizontal
msheader.ypixperm = 2835; // 72 dpi vertical
msheader.colorsused = 0;
msheader.colorsimportant = 0;
// determine fileSize / imagesize
switch (bitsHeader.colors) {
case B_RGB32:
@ -1034,7 +1039,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
case B_CMY32:
case B_CMYA32:
case B_CMY24:
fileHeader.dataOffset = 54;
msheader.bitsperpixel = 24;
msheader.compression = BMP_NO_COMPRESS;
@ -1042,12 +1047,12 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
msheader.height;
fileHeader.fileSize = fileHeader.dataOffset +
msheader.imagesize;
break;
case B_CMAP8:
case B_GRAY8:
msheader.colorsused = 256;
msheader.colorsimportant = 256;
fileHeader.dataOffset = 54 + (4 * 256);
@ -1057,11 +1062,11 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
msheader.bitsperpixel) * msheader.height;
fileHeader.fileSize = fileHeader.dataOffset +
msheader.imagesize;
break;
case B_GRAY1:
msheader.colorsused = 2;
msheader.colorsimportant = 2;
fileHeader.dataOffset = 62;
@ -1071,13 +1076,13 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
msheader.bitsperpixel) * msheader.height;
fileHeader.fileSize = fileHeader.dataOffset +
msheader.imagesize;
break;
default:
return B_NO_TRANSLATOR;
}
// write out the BMP headers
if (bheaderonly || (!bheaderonly && !bdataonly)) {
result = write_bmp_headers(outDestination, fileHeader, msheader);
@ -1109,7 +1114,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
case B_CMY24:
return translate_from_bits_to_bmp24(inSource, outDestination,
bitsHeader.colors, msheader);
case B_CMAP8:
case B_GRAY8:
{
@ -1138,7 +1143,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
palHandle[3] = 255;
palHandle += 4;
}
}
}
ssize_t written = outDestination->Write(pal, 1024);
if (written < 0)
return written;
@ -1148,7 +1153,7 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
return translate_from_bits8_to_bmp8(inSource, outDestination,
bitsHeader.rowBytes, msheader);
}
case B_GRAY1:
{
// write monochrome palette to the BMP file
@ -1158,11 +1163,11 @@ BMPTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
return written;
if (written != 8)
return B_ERROR;
return translate_from_bits1_to_bmp1(inSource, outDestination,
bitsHeader.rowBytes, msheader);
}
default:
return B_NO_TRANSLATOR;
}
@ -1202,7 +1207,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
// Setup outDestination so that it can be written to
// from the end of the file to the beginning instead of
// the other way around
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
sizeof(TranslatorBitmap);
if (outDestination->SetSize(bitsFileSize) != B_OK) {
// 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;
outDestination->Seek(bitsoffset, SEEK_CUR);
// allocate row buffers
uint8 *bmpRowData = new (nothrow) uint8[bmpRowBytes];
if (!bmpRowData)
@ -1269,7 +1274,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
break;
}
}
delete[] bmpRowData;
delete[] bitsRowData;
@ -1279,7 +1284,7 @@ translate_from_bmpnpal_to_bits(BPositionIO *inSource,
// ---------------------------------------------------------------
// 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.
//
// Preconditions:
@ -1313,19 +1318,19 @@ translate_from_bmppal_to_bits(BPositionIO *inSource,
palBytesPerPixel = 4;
else
palBytesPerPixel = 3;
uint8 mask = 1;
mask = (mask << bitsPerPixel) - 1;
int32 bmpRowBytes =
get_rowbytes(msheader.width, msheader.bitsperpixel);
uint32 bmppixrow = 0;
// Setup outDestination so that it can be written to
// from the end of the file to the beginning instead of
// the other way around
int32 bitsRowBytes = msheader.width * 4;
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
sizeof(TranslatorBitmap);
if (outDestination->SetSize(bitsFileSize) != B_OK)
// 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 index;
index = (indices >>
(bitsPerPixel * ((pixelsPerByte - 1) -
(bitsPerPixel * ((pixelsPerByte - 1) -
(i % pixelsPerByte)))) & mask;
memcpy(bitsRowData + (i * 4),
palette + (index * palBytesPerPixel), 3);
}
outDestination->Write(bitsRowData, bitsRowBytes);
bmppixrow++;
// 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
if (bmppixrow == msheader.height)
break;
@ -1367,7 +1372,7 @@ translate_from_bmppal_to_bits(BPositionIO *inSource,
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
rd = inSource->Read(bmpRowData, bmpRowBytes);
}
delete[] bmpRowData;
delete[] bitsRowData;
@ -1406,10 +1411,10 @@ pixelcpy(uint8 *dest, uint32 pixel, uint32 count)
// ---------------------------------------------------------------
// 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
// memory effcient as it could be. It assumes that the BMP
// from inSource is relatively small.
// from inSource is relatively small.
//
// Preconditions:
//
@ -1443,7 +1448,7 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
// from the end of the file to the beginning instead of
// the other way around
int32 bitsRowBytes = msheader.width * 4;
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
off_t bitsFileSize = (bitsRowBytes * msheader.height) +
sizeof(TranslatorBitmap);
if (outDestination->SetSize(bitsFileSize) != B_OK)
// This call should work for BFile and BMallocIO objects,
@ -1470,19 +1475,19 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
break;
}
// 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
// remaining in the row
if (count + bmppixcol > msheader.width)
count = msheader.width - bmppixcol;
rd = inSource->Read(&indices, 1);
if (rd != 1) {
rd = -1;
break;
}
for (uint8 i = 0; i < count; i++) {
index = (indices >> (bitsPerPixel * ((pixelsPerByte - 1) -
index = (indices >> (bitsPerPixel * ((pixelsPerByte - 1) -
(i % pixelsPerByte)))) & mask;
memcpy(bitsRowData + (bmppixcol*4), palette + (index*4), 3);
bmppixcol++;
@ -1509,8 +1514,8 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
if (bmppixrow < msheader.height)
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
break;
// end of bitmap
// end of bitmap
case 1:
// if at the end of a row
if (bmppixcol == msheader.width) {
@ -1520,7 +1525,7 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
if (bmppixrow < msheader.height)
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
}
while (bmppixrow < msheader.height) {
pixelcpy(bitsRowData + (bmppixcol * 4), defaultcolor,
msheader.width - bmppixcol);
@ -1533,9 +1538,9 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
rd = 0;
// break out of while loop
break;
// 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:
{
uint8 da[2], lastcol, dx, dy;
@ -1546,16 +1551,16 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
}
dx = da[0];
dy = da[1];
// abort if dx or dy is too large
if ((dx + bmppixcol >= msheader.width) ||
(dy + bmppixrow >= msheader.height)) {
rd = -1;
break;
}
}
lastcol = bmppixcol;
// set all pixels to the first entry in
// the palette, for the number of rows skipped
while (dy > 0) {
@ -1567,13 +1572,13 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
dy--;
outDestination->Seek(bitsRowBytes * -2, SEEK_CUR);
}
if (bmppixcol < static_cast<uint32>(lastcol + dx)) {
pixelcpy(bitsRowData + (bmppixcol * 4), defaultcolor,
dx + lastcol - bmppixcol);
bmppixcol = dx + lastcol;
}
break;
}
@ -1587,20 +1592,20 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
break;
}
// 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
// remaining in the row
if (code + bmppixcol > msheader.width)
code = msheader.width - bmppixcol;
uint8 uncomp[256];
int32 padding;
if (!(code % pixelsPerByte))
padding = (code / pixelsPerByte) % 2;
else
padding = ((code + pixelsPerByte -
padding = ((code + pixelsPerByte -
(code % pixelsPerByte)) / pixelsPerByte) % 2;
int32 uncompBytes = (code / pixelsPerByte) +
int32 uncompBytes = (code / pixelsPerByte) +
((code % pixelsPerByte) ? 1 : 0) + padding;
rd = inSource->Read(uncomp, uncompBytes);
if (rd != uncompBytes) {
@ -1610,7 +1615,7 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
for (uint8 i = 0; i < code; i++) {
indices = (uncomp + (i / pixelsPerByte))[0];
index = (indices >>
(bitsPerPixel * ((pixelsPerByte - 1) -
(bitsPerPixel * ((pixelsPerByte - 1) -
(i % pixelsPerByte)))) & mask;
memcpy(bitsRowData + (bmppixcol * 4),
palette + (index * 4), 3);
@ -1623,9 +1628,9 @@ translate_from_bmppalr_to_bits(BPositionIO *inSource,
if (rd > 0)
rd = inSource->Read(&count, 1);
}
delete[] bitsRowData;
if (!rd)
return B_OK;
else
@ -1675,8 +1680,8 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
INFO("BMPTranslator::translate_from_bmp() - identify_bmp_header failed\n");
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) {
// write out the BMP headers
if (bheaderonly || (!bheaderonly && !bdataonly)) {
@ -1685,14 +1690,14 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
return result;
}
if (bheaderonly)
// if the user only wants the header,
// if the user only wants the header,
// bail before it is written
return result;
uint8 buf[1024];
ssize_t rd;
uint32 rdtotal = 54;
if (!frommsformat && (msheader.bitsperpixel == 1 ||
if (!frommsformat && (msheader.bitsperpixel == 1 ||
msheader.bitsperpixel == 4 || msheader.bitsperpixel == 8)) {
// if OS/2 paletted format, convert palette to MS format
uint16 ncolors = 1 << msheader.bitsperpixel;
@ -1723,7 +1728,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
return B_OK;
else
return B_ERROR;
// if translating a BMP to a Be Bitmap
} else if (outType == B_TRANSLATOR_BITMAP) {
TranslatorBitmap bitsHeader;
@ -1732,31 +1737,31 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
bitsHeader.bounds.top = 0;
bitsHeader.bounds.right = msheader.width - 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];
off_t nskip = 0;
if (msheader.bitsperpixel == 1 ||
msheader.bitsperpixel == 4 ||
msheader.bitsperpixel == 8) {
uint8 palBytesPerPixel;
if (frommsformat)
palBytesPerPixel = 4;
else
palBytesPerPixel = 3;
if (!msheader.colorsused)
msheader.colorsused = 1 << msheader.bitsperpixel;
if (inSource->Read(bmppalette, msheader.colorsused *
palBytesPerPixel) !=
(off_t) msheader.colorsused * palBytesPerPixel)
return B_NO_TRANSLATOR;
// skip over non-BMP data
if (frommsformat) {
if (fileHeader.dataOffset > (msheader.colorsused *
if (fileHeader.dataOffset > (msheader.colorsused *
palBytesPerPixel) + 54)
nskip = fileHeader.dataOffset -
((msheader.colorsused * palBytesPerPixel) + 54);
@ -1765,7 +1770,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
} else if (fileHeader.dataOffset > 54)
// skip over non-BMP data
nskip = fileHeader.dataOffset - 54;
if (nskip > 0 && inSource->Seek(nskip, SEEK_CUR) < 0)
return B_NO_TRANSLATOR;
@ -1773,7 +1778,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
bitsHeader.colors = B_RGB32;
int32 datasize = bitsHeader.rowBytes * msheader.height;
bitsHeader.dataSize = datasize;
// write out Be's Bitmap header
if (bheaderonly || (!bheaderonly && !bdataonly)) {
if (swap_data(B_UINT32_TYPE, &bitsHeader,
@ -1782,17 +1787,17 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
}
if (bheaderonly)
// if the user only wants the header,
// if the user only wants the header,
// bail before the data is written
return B_OK;
// write out the actual image data
switch (msheader.bitsperpixel) {
case 32:
case 24:
return translate_from_bmpnpal_to_bits(inSource,
outDestination, msheader);
case 8:
// 8 bit BMP with NO compression
if (msheader.compression == BMP_NO_COMPRESS)
@ -1805,10 +1810,10 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
outDestination, datasize, msheader, bmppalette);
else
return B_NO_TRANSLATOR;
case 4:
// 4 bit BMP with NO compression
if (!msheader.compression)
if (!msheader.compression)
return translate_from_bmppal_to_bits(inSource,
outDestination, msheader, bmppalette, frommsformat);
@ -1818,15 +1823,15 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
outDestination, datasize, msheader, bmppalette);
else
return B_NO_TRANSLATOR;
case 1:
return translate_from_bmppal_to_bits(inSource,
outDestination, msheader, bmppalette, frommsformat);
default:
return B_NO_TRANSLATOR;
}
} else
return B_NO_TRANSLATOR;
}
@ -1840,7 +1845,7 @@ BMPTranslator::translate_from_bmp(BPositionIO *inSource, uint32 outType,
// Preconditions:
//
// Parameters: inSource, the data to be translated
//
//
// inInfo, hint about the data in inSource (not used)
//
// ioExtension, configuration options for the

View File

@ -21,7 +21,7 @@
// The input formats that this translator supports.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
EXR_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -33,7 +33,7 @@ translation_format sInputFormats[] = {
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -45,7 +45,7 @@ translation_format sOutputFormats[] = {
};
// Default settings for the Translator
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
};
@ -91,7 +91,7 @@ EXRTranslator::DerivedIdentify(BPositionIO *stream,
try {
IStreamWrapper istream("filename", stream);
RgbaInputFile inputFile(istream);
if (outInfo) {
outInfo->type = EXR_IMAGE_FORMAT;
outInfo->group = B_TRANSLATOR_BITMAP;
@ -131,7 +131,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
int dataHeight = dataWindow.max.y - dataWindow.min.y + 1;
int displayWidth = displayWindow.max.x - displayWindow.min.x + 1;
int displayHeight = displayWindow.max.y - displayWindow.min.y + 1;
// Write out the data to outDestination
// Construct and write Be bitmap header
TranslatorBitmap bitsHeader;
@ -148,11 +148,11 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
return B_ERROR;
}
target->Write(&bitsHeader, sizeof(TranslatorBitmap));
Array2D <Rgba> pixels(dataHeight, dataWidth);
in.setFrameBuffer (&pixels[0][0] - dataWindow.min.y * dataWidth - dataWindow.min.x, 1, dataWidth);
in.readPixels (dataWindow.min.y, dataWindow.max.y);
float _gamma = 0.4545f;
float _exposure = 0.0f;
float _defog = 0.0f;
@ -162,7 +162,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
float _fogR = 0.0f;
float _fogG = 0.0f;
float _fogB = 0.0f;
halfFunction<float>
rGamma (Gamma (_gamma,
_exposure,
@ -171,7 +171,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
_kneeHigh),
-HALF_MAX, HALF_MAX,
0.f, 255.f, 0.f, 0.f);
halfFunction<float>
gGamma (Gamma (_gamma,
_exposure,
@ -180,7 +180,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
_kneeHigh),
-HALF_MAX, HALF_MAX,
0.f, 255.f, 0.f, 0.f);
halfFunction<float>
bGamma (Gamma (_gamma,
_exposure,
@ -189,7 +189,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
_kneeHigh),
-HALF_MAX, HALF_MAX,
0.f, 255.f, 0.f, 0.f);
for (int y = displayWindow.min.y; y <= displayWindow.max.y; ++y) {
if (y < dataWindow.min.y
|| y > dataWindow.max.y) {
@ -203,7 +203,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
}
continue;
}
for (int x = displayWindow.min.x; x <= displayWindow.max.x; ++x) {
unsigned char sp[4];
if (x < dataWindow.min.x
@ -214,7 +214,7 @@ EXRTranslator::DerivedTranslate(BPositionIO* source,
sp[3] = 255;
} else {
const Imf::Rgba &rp = pixels[y][x];
sp[0] = (unsigned char)bGamma(rp.b);
sp[1] = (unsigned char)gGamma(rp.g);
sp[2] = (unsigned char)rGamma(rp.r);

View File

@ -23,7 +23,7 @@ typedef struct my_hpgs_png_image_st {
} my_hpgs_png_image;
int
int
my_pim_write(hpgs_image *_this, const char *filename)
{
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.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
HPGS_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -54,7 +54,7 @@ translation_format sInputFormats[] = {
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -66,7 +66,7 @@ translation_format sOutputFormats[] = {
};
// Default settings for the Translator
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_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;
hpgs_istream *istream = hpgs_new_wrapper_istream(stream);
status_t err = B_OK;
int verbosity = 1;
hpgs_bool multipage = HPGS_FALSE;
@ -126,7 +126,7 @@ HPGSTranslator::DerivedIdentify(BPositionIO *stream,
strcpy(info->MIME, "vector/x-hpgl2");
} else
err = B_NO_TRANSLATOR;
free(reader);
free(size_dev);
hpgs_free_wrapper_istream(istream);
@ -147,11 +147,11 @@ HPGSTranslator::DerivedTranslate(BPositionIO* source,
status_t err = B_OK;
hpgs_istream *istream = hpgs_new_wrapper_istream(source);
TranslatorBitmap header;
ssize_t bytesWritten;
uint32 dataSize;
double paper_angle = 180.0;
double paper_border = 0.0;
double paper_width = 0.0;
@ -201,7 +201,7 @@ HPGSTranslator::DerivedTranslate(BPositionIO* source,
image->vtable->write = &my_pim_write;
image = (hpgs_image *)realloc(image, sizeof(my_hpgs_png_image));
((my_hpgs_png_image *)image)->target = target;
pdv = hpgs_new_paint_device(image, NULL, &bbox, antialias);
hpgs_paint_device_set_image_interpolation(pdv, image_interpolation);
hpgs_paint_device_set_thin_alpha(pdv, thin_alpha);

View File

@ -21,7 +21,7 @@
#define HVIF_TRANSLATION_QUALITY 1.0
#define HVIF_TRANSLATION_CAPABILITY 1.0
static translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
HVIF_FORMAT_CODE,
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,
@ -45,10 +45,15 @@ static translation_format sOutputFormats[] = {
};
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{ 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 *
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()
: BaseTranslator("HVIF icons", "Native Haiku vector icon translator",
HVIF_TRANSLATOR_VERSION, sInputFormats,
sizeof(sInputFormats) / sizeof(sInputFormats[0]), sOutputFormats,
sizeof(sOutputFormats) / sizeof(sOutputFormats[0]),
"HVIFTranslator_Settings", sDefaultSettings,
sizeof(sDefaultSettings) / sizeof(sDefaultSettings[0]),
B_TRANSLATOR_BITMAP, HVIF_FORMAT_CODE)
: BaseTranslator("HVIF icons", "Native Haiku vector icon translator",
HVIF_TRANSLATOR_VERSION,
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"HVIFTranslator_Settings",
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, HVIF_FORMAT_CODE)
{
}

View File

@ -21,7 +21,7 @@ const char *kDocumentIndex = "/documentIndex";
// The input formats that this translator supports.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
ICO_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -41,7 +41,7 @@ translation_format sInputFormats[] = {
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
ICO_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -61,7 +61,7 @@ translation_format sOutputFormats[] = {
};
// Default settings for the Translator
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
};

View File

@ -55,8 +55,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Translation Kit required globals
char gTranslatorName[] = "JPEG images";
char gTranslatorInfo[] =
static char sTranslatorName[] = "JPEG images";
static char sTranslatorInfo[] =
"©2002-2003, Marcin Konicki\n"
"©2005-2007, Haiku\n"
"\n"
@ -69,28 +69,26 @@ char gTranslatorInfo[] =
"With some colorspace conversion routines by Magnus Hellman\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
const translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
{ JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
JPEG_MIME_STRING, JPEG_DESCRIPTION },
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
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
const translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{ JPEG_FORMAT, B_TRANSLATOR_BITMAP, 0.5, 0.5,
JPEG_MIME_STRING, JPEG_DESCRIPTION },
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
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_QUALITY, TRAN_SETTING_INT32, 95},
{JPEG_SET_PROGRESSIVE, TRAN_SETTING_BOOL, true},
@ -101,7 +99,10 @@ TranSetting gSettings[] = {
{JPEG_SET_PHOTOSHOP_CMYK, 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 {
@ -658,19 +659,19 @@ TranslatorAboutView::TranslatorAboutView(const char* name)
BView(name, 0, new BGroupLayout(B_VERTICAL))
{
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->SetExplicitAlignment(labelAlignment);
char versionString[16];
sprintf(versionString, "v%d.%d.%d", (int)(gTranslatorVersion >> 8),
(int)((gTranslatorVersion >> 4) & 0xf), (int)(gTranslatorVersion & 0xf));
sprintf(versionString, "v%d.%d.%d", (int)(sTranslatorVersion >> 8),
(int)((sTranslatorVersion >> 4) & 0xf), (int)(sTranslatorVersion & 0xf));
BStringView* version = new BStringView("Version", versionString);
version->SetExplicitAlignment(labelAlignment);
BTextView* infoView = new BTextView("info");
infoView->SetText(gTranslatorInfo);
infoView->SetText(sTranslatorInfo);
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
infoView->MakeEditable(false);
@ -1293,11 +1294,12 @@ JPEGTranslator::Error(j_common_ptr cinfo, status_t error)
JPEGTranslator::JPEGTranslator()
:
BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion,
gInputFormats, gInputFormatCount, gOutputFormats, gOutputFormatCount,
SETTINGS_FILE, gSettings, gSettingsCount,
B_TRANSLATOR_BITMAP, JPEG_FORMAT)
: BaseTranslator(sTranslatorName, sTranslatorInfo, sTranslatorVersion,
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
SETTINGS_FILE,
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, JPEG_FORMAT)
{}
@ -1316,7 +1318,7 @@ main(int, char**)
{
BApplication app("application/x-vnd.Haiku-JPEGTranslator");
JPEGTranslator* translator = new JPEGTranslator();
if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK)
if (LaunchTranslatorWindow(translator, sTranslatorName) == B_OK)
app.Run();
return 0;

View File

@ -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_DESCRIPTION "Be Bitmap Format (JPEG2000Translator)"
const char gTranslatorName[] = "JPEG2000 images";
const char gTranslatorInfo[] = "©2002-2003, Shard\n"
static const char sTranslatorName[] = "JPEG2000 images";
static const char sTranslatorInfo[] = "©2002-2003, Shard\n"
"©2005-2006, Haiku\n"
"\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"
" 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_MIME_STRING, JP2_DESCRIPTION },
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
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_MIME_STRING, JP2_DESCRIPTION },
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.5, 0.5,
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_JPC, TRAN_SETTING_BOOL, false},
{JP2_SET_GRAY1_AS_B_RGB24, TRAN_SETTING_BOOL, false},
{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{
@ -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_t* stream;
@ -628,7 +627,7 @@ TranslatorWriteView::TranslatorWriteView(const char* name,
new BMessage(VIEW_MSG_SET_JPC));
if (fSettings->SetGetBool(JP2_SET_JPC))
fCodeStreamOnly->SetValue(B_CONTROL_ON);
float padding = 10.0f;
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(fQualitySlider)
@ -703,22 +702,22 @@ TranslatorAboutView::TranslatorAboutView(const char* name)
BView(name, 0, new BGroupLayout(B_VERTICAL))
{
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->SetExplicitAlignment(labelAlignment);
char versionString[16];
sprintf(versionString, "v%d.%d.%d", (int)(gTranslatorVersion >> 8),
(int)((gTranslatorVersion >> 4) & 0xf), (int)(gTranslatorVersion & 0xf));
sprintf(versionString, "v%d.%d.%d", (int)(sTranslatorVersion >> 8),
(int)((sTranslatorVersion >> 4) & 0xf), (int)(sTranslatorVersion & 0xf));
BStringView* version = new BStringView("Version", versionString);
version->SetExplicitAlignment(labelAlignment);
BTextView* infoView = new BTextView("info");
infoView->SetText(gTranslatorInfo);
BTextView* infoView = new BTextView("info");
infoView->SetText(sTranslatorInfo);
infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
infoView->MakeEditable(false);
float padding = 10.0f;
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
@ -763,11 +762,12 @@ JP2Translator::NewConfigView(TranslatorSettings* settings)
JP2Translator::JP2Translator()
:
BaseTranslator(gTranslatorName, gTranslatorInfo, gTranslatorVersion,
gInputFormats, gInputFormatCount,
gOutputFormats, gOutputFormatCount, JP2_SETTINGS_FILE,
gSettings, gSettingsCount, B_TRANSLATOR_BITMAP, JP2_FORMAT)
: BaseTranslator(sTranslatorName, sTranslatorInfo, sTranslatorVersion,
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
JP2_SETTINGS_FILE,
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);
if (jas_image_encode(image, outs, jas_image_strtofmt(
fSettings->SetGetBool(JP2_SET_JPC) ?
fSettings->SetGetBool(JP2_SET_JPC) ?
(char*)"jpc" : (char*)"jp2"), opts)) {
return Error(outs, image, pixels,
out_color_components, in_scanline, err);
@ -1287,7 +1287,7 @@ main()
{
BApplication app("application/x-vnd.Haiku-JPEG2000Translator");
JP2Translator* translator = new JP2Translator();
if (LaunchTranslatorWindow(translator, gTranslatorName) == B_OK)
if (LaunchTranslatorWindow(translator, sTranslatorName) == B_OK)
app.Run();
return 0;

View File

@ -18,7 +18,7 @@
// The input formats that this translator supports.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
PCX_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -38,7 +38,7 @@ translation_format sInputFormats[] = {
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
/*{
PCX_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -58,7 +58,7 @@ translation_format sOutputFormats[] = {
};
// Default settings for the Translator
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
};

View File

@ -4,7 +4,7 @@
//
// PNGTranslator.cpp
//
// This BTranslator based object is for opening and writing
// This BTranslator based object is for opening and writing
// PNG images.
//
//
@ -14,18 +14,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// 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
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
@ -39,7 +39,7 @@
#include "PNGView.h"
// The input formats that this translator supports.
translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
{
B_PNG_FORMAT,
B_TRANSLATOR_BITMAP,
@ -67,7 +67,7 @@ translation_format gInputFormats[] = {
};
// The output formats that this translator supports.
translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_PNG_FORMAT,
B_TRANSLATOR_BITMAP,
@ -87,13 +87,18 @@ translation_format gOutputFormats[] = {
};
// Default settings for the Translator
TranSetting gDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
{PNG_SETTING_INTERLACE, TRAN_SETTING_INT32, PNG_INTERLACE_NONE}
// 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
//
@ -141,7 +146,7 @@ BPositionIO *
get_pio(png_structp ppng)
{
BPositionIO *pio = NULL;
pio = static_cast<BPositionIO *>(png_get_io_ptr(ppng));
pio = static_cast<BPositionIO *>(png_get_io_ptr(ppng));
return pio;
}
@ -182,10 +187,10 @@ pngcb_flush_data(png_structp ppng)
PNGTranslator::PNGTranslator()
: BaseTranslator("PNG images", "PNG image translator",
PNG_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"PNGTranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, B_PNG_FORMAT)
{
}
@ -213,7 +218,7 @@ identify_png_header(BPositionIO *inSource, translator_info *outInfo)
const int32 kSigSize = 8;
uint8 buf[kSigSize];
if (inSource->Read(buf, kSigSize) != kSigSize)
return B_NO_TRANSLATOR;
return B_NO_TRANSLATOR;
if (png_sig_cmp(buf, 0, kSigSize))
// if first 8 bytes of stream don't match PNG signature bail
return B_NO_TRANSLATOR;
@ -226,10 +231,10 @@ identify_png_header(BPositionIO *inSource, translator_info *outInfo)
strcpy(outInfo->MIME, "image/png");
strcpy(outInfo->name, "PNG image");
}
return B_OK;
}
// ---------------------------------------------------------------
// DerivedIdentify
//
@ -288,13 +293,13 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
// if a libpng errors before this is set
// to a different value, the above is what
// will be returned from this function
bool bheaderonly = false, bdataonly = false;
// for storing decoded PNG row data
uint8 **prows = NULL, *prow = NULL;
png_uint_32 nalloc = 0;
png_structp ppng = NULL;
png_infop pinfo = NULL;
while (ppng == NULL) {
@ -312,67 +317,67 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
// the longjmp function to continue execution
// from this point
break;
// set read callback function
png_set_read_fn(ppng, static_cast<void *>(inSource), pngcb_read_data);
// Read in PNG image info
png_set_sig_bytes(ppng, 8);
png_read_info(ppng, pinfo);
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
png_get_IHDR(ppng, pinfo, &width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
// Setup image transformations to make converting it easier
bool balpha = false;
if (bit_depth == 16)
png_set_strip_16(ppng);
else if (bit_depth < 8)
png_set_packing(ppng);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(ppng);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
// In order to convert from low-depth gray images to RGB,
// I first need to convert them to grayscale, 8 bpp
png_set_expand_gray_1_2_4_to_8(ppng);
if (png_get_valid(ppng, pinfo, PNG_INFO_tRNS)) {
// if there is transparency data in the
// PNG, but not in the form of an alpha channel
balpha = true;
png_set_tRNS_to_alpha(ppng);
}
// change RGB to BGR as it is in 'bits'
if (color_type & PNG_COLOR_MASK_COLOR)
png_set_bgr(ppng);
// have libpng convert gray to RGB for me
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(ppng);
if (color_type & PNG_COLOR_MASK_ALPHA)
// if image contains an alpha channel
balpha = true;
if (!balpha)
// add filler byte for images without alpha
// so that the pixels are 4 bytes each
png_set_filler(ppng, 0xff, PNG_FILLER_AFTER);
// Check that transformed PNG rowbytes matches
// what is expected
const int32 kbytes = 4;
png_uint_32 rowbytes = png_get_rowbytes(ppng, pinfo);
if (rowbytes < kbytes * width)
rowbytes = kbytes * width;
if (!bdataonly) {
// Write out the data to outDestination
// Construct and write Be bitmap header
@ -394,13 +399,13 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
break;
}
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
if (bheaderonly) {
result = B_OK;
break;
}
}
if (interlace_type == PNG_INTERLACE_NONE) {
// allocate buffer for storing PNG row
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
// an error, png_read_end() will longjmp to error
// handler above and not execute lines below it
// finish reading, pass NULL for info because I
// don't need the extra data
png_read_end(ppng, NULL);
break;
} else {
// interlaced PNG image
prows = new uint8 *[height];
@ -436,30 +441,30 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
if (!prows[nalloc])
break;
}
if (nalloc < height)
result = B_NO_MEMORY;
else {
png_read_image(ppng, prows);
for (png_uint_32 i = 0; i < height; i++)
outDestination->Write(prows[i], width * kbytes);
result = B_OK;
// Set OK status here, because, in the event of
// an error, png_read_end() will longjmp to error
// handler above and not execute lines below it
png_read_end(ppng, NULL);
}
break;
}
}
if (ppng) {
delete[] prow;
prow = NULL;
// delete row pointers and array of pointers to rows
while (nalloc) {
nalloc--;
@ -467,7 +472,7 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
}
delete[] prows;
prows = NULL;
// free PNG handle / info structures
if (!pinfo)
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;
uint16 val;
switch (fromspace) {
case B_RGBA32:
bytescopied = width * bitsBytesPerPixel;
memcpy(ppng, pbits, bytescopied);
break;
case B_RGB32:
case B_RGB24:
bytescopied = width * bitsBytesPerPixel;
@ -515,7 +520,7 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
pbits += bitsBytesPerPixel;
}
break;
case B_RGBA32_BIG:
bytescopied = width * 4;
while (width--) {
@ -523,12 +528,12 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
ppng[1] = pbits[2];
ppng[2] = pbits[1];
ppng[3] = pbits[0];
ppng += 4;
pbits += 4;
}
break;
case B_CMYA32:
bytescopied = width * 4;
while (width--) {
@ -536,32 +541,32 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
ppng[1] = 255 - pbits[1];
ppng[2] = 255 - pbits[0];
ppng[3] = pbits[3];
ppng += 4;
pbits += 4;
}
break;
case B_CMYK32:
{
int32 comp;
bytescopied = width * 3;
while (width--) {
while (width--) {
comp = 255 - pbits[2] - pbits[3];
ppng[0] = (comp < 0) ? 0 : comp;
comp = 255 - pbits[1] - pbits[3];
ppng[1] = (comp < 0) ? 0 : comp;
comp = 255 - pbits[0] - pbits[3];
ppng[2] = (comp < 0) ? 0 : comp;
ppng += 3;
pbits += 4;
}
break;
}
case B_CMY32:
case B_CMY24:
bytescopied = width * 3;
@ -569,12 +574,12 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
ppng[0] = 255 - pbits[2];
ppng[1] = 255 - pbits[1];
ppng[2] = 255 - pbits[0];
ppng += 3;
pbits += bitsBytesPerPixel;
}
break;
case B_RGB16:
case B_RGB16_BIG:
bytescopied = width * 3;
@ -590,7 +595,7 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);
ppng[2] =
((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);
ppng += 3;
pbits += 2;
}
@ -604,18 +609,18 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
val = pbits[0] + (pbits[1] << 8);
else
val = pbits[1] + (pbits[0] << 8);
ppng[0] =
ppng[0] =
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
ppng[1] =
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
ppng[2] =
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
ppng += 3;
pbits += 2;
}
break;
case B_RGBA15:
case B_RGBA15_BIG:
bytescopied = width * 4;
@ -624,43 +629,43 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
val = pbits[0] + (pbits[1] << 8);
else
val = pbits[1] + (pbits[0] << 8);
ppng[0] =
ppng[0] =
((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
ppng[1] =
((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
ppng[2] =
((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
ppng[3] = (val & 0x8000) ? 255 : 0;
ppng += 4;
pbits += 2;
}
break;
case B_RGB32_BIG:
bytescopied = width * 3;
while (width--) {
ppng[0] = pbits[3];
ppng[1] = pbits[2];
ppng[2] = pbits[1];
ppng += 3;
pbits += 4;
}
break;
case B_RGB24_BIG:
bytescopied = width * 3;
while (width--) {
ppng[0] = pbits[2];
ppng[1] = pbits[1];
ppng[2] = pbits[0];
ppng += 3;
pbits += 3;
}
break;
case B_CMAP8:
{
rgb_color c;
@ -670,23 +675,23 @@ pix_bits_to_png(uint8 *pbits, uint8 *ppng, color_space fromspace,
ppng[0] = c.blue;
ppng[1] = c.green;
ppng[2] = c.red;
ppng += 3;
pbits++;
}
break;
}
case B_GRAY8:
bytescopied = width;
memcpy(ppng, pbits, bytescopied);
break;
default:
bytescopied = B_ERROR;
break;
} // switch (fromspace)
return bytescopied;
}
@ -695,24 +700,24 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
BPositionIO *outDestination)
{
TranslatorBitmap bitsHeader;
status_t result;
result = identify_bits_header(inSource, NULL, &bitsHeader);
if (result != B_OK)
return result;
const color_map *pmap = NULL;
if (bitsHeader.colors == B_CMAP8) {
pmap = system_colors();
if (!pmap)
return B_ERROR;
}
png_uint_32 width, height;
width = static_cast<png_uint_32>(bitsHeader.bounds.Width() + 1);
height = static_cast<png_uint_32>(bitsHeader.bounds.Height() + 1);
int32 pngBytesPerPixel = 0;
int bit_depth, color_type, interlace_type;
bit_depth = 8;
@ -725,7 +730,7 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
pngBytesPerPixel = 4;
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
break;
case B_RGB32:
case B_RGB32_BIG:
case B_RGB24:
@ -740,19 +745,19 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
pngBytesPerPixel = 3;
color_type = PNG_COLOR_TYPE_RGB;
break;
// ADD SUPPORT FOR B_CMAP8 HERE (later)
case B_GRAY8:
pngBytesPerPixel = 1;
color_type = PNG_COLOR_TYPE_GRAY;
break;
default:
return B_NO_TRANSLATOR;
}
interlace_type = fSettings->SetGetInt32(PNG_SETTING_INTERLACE);
int32 bitsBytesPerPixel = 0;
switch (bitsHeader.colors) {
case B_RGBA32:
@ -764,13 +769,13 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
case B_CMY32:
bitsBytesPerPixel = 4;
break;
case B_RGB24:
case B_RGB24_BIG:
case B_CMY24:
bitsBytesPerPixel = 3;
break;
case B_RGB16:
case B_RGB16_BIG:
case B_RGBA15:
@ -784,20 +789,20 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
case B_CMAP8:
bitsBytesPerPixel = 1;
break;
default:
return B_NO_TRANSLATOR;
};
uint8 *pbitsrow = NULL, *prow = NULL;
// row buffers
// image buffer for writing whole png image at once
uint8 **prows = NULL;
png_uint_32 nalloc = 0;
png_structp ppng = NULL;
png_infop pinfo = NULL;
result = B_NO_TRANSLATOR;
while (ppng == NULL) {
// create PNG read pointer with default error handling routines
@ -822,9 +827,9 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
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);
// Allocate memory needed to buffer image data
pbitsrow = new uint8[bitsHeader.rowBytes];
if (!pbitsrow) {
@ -858,46 +863,46 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
break;
}
}
// Specify image info
png_set_IHDR(ppng, pinfo, width, height, bit_depth, color_type,
interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(ppng, pinfo);
png_set_bgr(ppng);
// write out image data
if (interlace_type == PNG_INTERLACE_NONE) {
for (png_uint_32 i = 0; i < height; i++) {
inSource->Read(pbitsrow, bitsHeader.rowBytes);
pix_bits_to_png(pbitsrow, prow, bitsHeader.colors, width,
pmap, bitsBytesPerPixel);
png_write_row(ppng, prow);
}
} else {
for (png_uint_32 i = 0; i < height; i++) {
inSource->Read(pbitsrow, bitsHeader.rowBytes);
pix_bits_to_png(pbitsrow, prows[i], bitsHeader.colors, width,
pmap, bitsBytesPerPixel);
}
png_write_image(ppng, prows);
}
png_write_end(ppng, NULL);
result = B_OK;
break;
}
if (ppng) {
delete[] pbitsrow;
pbitsrow = NULL;
delete[] prow;
prow = NULL;
// delete row pointers and array of pointers to rows
while (nalloc) {
nalloc--;
@ -905,7 +910,7 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
}
delete[] prows;
prows = NULL;
// free PNG handle / info structures
if (!pinfo)
png_destroy_write_struct(&ppng, NULL);
@ -925,7 +930,7 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
// Preconditions:
//
// Parameters: inSource, the data to be translated
//
//
// inInfo, hint about the data in inSource (not used)
//
// ioExtension, configuration options for the
@ -958,7 +963,7 @@ PNGTranslator::DerivedTranslate(BPositionIO *inSource,
{
if (baseType == 1)
// 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)
// if inSource is NOT in bits format
return translate_from_png(inSource, outType, outDestination);

View File

@ -90,8 +90,8 @@ struct ppm_settings {
bool write_ascii;
bool settings_touched;
};
BLocker g_settings_lock("PPM settings lock");
ppm_settings g_settings;
static BLocker g_settings_lock("PPM settings lock");
static ppm_settings g_settings;
BPoint get_window_origin();
void set_window_origin(BPoint pos);
@ -485,10 +485,10 @@ public:
if (g_settings.write_ascii)
mAscii->SetValue(1);
mAscii->SetViewColor(ViewColor());
// Build the layout
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, 7)
.Add(mTitle)
.Add(mDetail)
@ -504,7 +504,7 @@ public:
.AddGlue()
.SetInsets(5, 5, 5, 5)
);
BFont font;
GetFont(&font);
SetExplicitPreferredSize(BSize((font.Size() * 350)/12, (font.Size() * 200)/12));

View File

@ -46,7 +46,7 @@ const char* kProgressMonitor = "/progressMonitor";
const char* kProgressMessage = "/progressMessage";
// The input formats that this translator supports.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
RAW_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -62,11 +62,11 @@ translation_format sInputFormats[] = {
RAW_IN_CAPABILITY,
"image/x-vnd.photo-raw",
"Digital Photo RAW image"
},
}
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -74,11 +74,11 @@ translation_format sOutputFormats[] = {
BITS_OUT_CAPABILITY,
"image/x-be-bitmap",
"Be Bitmap Format (RAWTranslator)"
},
}
};
// Default settings for the Translator
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
};

View File

@ -19,7 +19,7 @@
// The input formats that this translator supports.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
RTF_TEXT_FORMAT,
B_TRANSLATOR_TEXT,
@ -27,11 +27,11 @@ translation_format sInputFormats[] = {
RTF_IN_CAPABILITY,
"text/rtf",
"RichTextFormat file"
},
}
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_TEXT,
B_TRANSLATOR_TEXT,

View File

@ -6,7 +6,7 @@
//
// SGITranslator.cpp
//
// This BTranslator based object is for opening and writing
// This BTranslator based object is for opening and writing
// SGI images.
//
//
@ -15,18 +15,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// 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
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
@ -53,7 +53,7 @@
using std::nothrow;
// The input formats that this translator supports.
translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -73,7 +73,7 @@ translation_format gInputFormats[] = {
};
// The output formats that this translator supports.
translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -93,13 +93,18 @@ translation_format gOutputFormats[] = {
};
// Default settings for the Translator
TranSetting gDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
{SGI_SETTING_COMPRESSION, TRAN_SETTING_INT32, SGI_COMP_RLE}
// 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
//
@ -149,10 +154,10 @@ SGITranslator::SGITranslator()
:
BaseTranslator("SGI images", "SGI image translator",
SGI_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"SGITranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, SGI_FORMAT)
{
}
@ -183,7 +188,7 @@ identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outT
SGIImage* sgiImage = new(nothrow) SGIImage();
if (sgiImage)
status = sgiImage->SetTo(inSource);
if (status >= B_OK) {
if (outInfo) {
outInfo->type = SGI_FORMAT;
@ -206,7 +211,7 @@ identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outT
return status;
}
// ---------------------------------------------------------------
// DerivedIdentify
//
@ -304,7 +309,7 @@ SGITranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
// read one row at a time,
// convert to the correct format
// and write out the results
// SGI Images store each channel separately
// a buffer is allocated big enough to hold all channels
// 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
break;
} // switch (format)
// for each channel, write a row buffer
for (uint32 z = 0; z < channelCount; z++) {
ret = sgiImage->WriteRow(rows[z], y, z);
@ -411,13 +416,13 @@ printf("WriteRow() returned %s!\n", strerror(ret));
break;
}
}
} // for (uint32 y = 0; y < height && ret >= B_OK; y++)
if (ret >= B_OK)
ret = B_OK;
} else // if (rows && rows[0] && rowBuffer)
ret = B_NO_MEMORY;
delete[] rows[0];
delete[] rows;
delete[] rowBuffer;
@ -437,7 +442,7 @@ SGITranslator::translate_from_sgi(BPositionIO *inSource, uint32 outType,
BPositionIO *outDestination)
{
status_t ret = B_NO_TRANSLATOR;
// if copying SGI_FORMAT to SGI_FORMAT
if (outType == SGI_FORMAT) {
translate_direct_copy(inSource, outDestination);
@ -446,13 +451,13 @@ SGITranslator::translate_from_sgi(BPositionIO *inSource, uint32 outType,
// variables needing cleanup
SGIImage* sgiImage = NULL;
ret = identify_sgi_header(inSource, NULL, outType, &sgiImage);
if (ret >= B_OK) {
bool bheaderonly = false, bdataonly = false;
uint32 width = sgiImage->Width();
uint32 height = sgiImage->Height();
uint32 channelCount = sgiImage->CountChannels();
@ -687,7 +692,7 @@ printf("error writing bits header: %s\n", strerror(ret));
// Preconditions:
//
// Parameters: inSource, the data to be translated
//
//
// inInfo, hint about the data in inSource (not used)
//
// ioExtension, configuration options for the
@ -727,7 +732,7 @@ SGITranslator::DerivedTranslate(BPositionIO *inSource,
else
// if BaseTranslator did not properly identify the data as
// bits or not bits
return B_NO_TRANSLATOR;
return B_NO_TRANSLATOR;
}
BView *

View File

@ -14,18 +14,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// 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
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
@ -59,7 +59,7 @@
BaseTranslator::BaseTranslator(const char *name, const char *info,
const int32 version, const translation_format *inFormats,
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)
:
BTranslator()
@ -123,7 +123,7 @@ BaseTranslator::~BaseTranslator()
// Postconditions:
//
// Returns: a const char * to the short name of the translator
// ---------------------------------------------------------------
// ---------------------------------------------------------------
const char *
BaseTranslator::TranslatorName() const
{
@ -166,7 +166,7 @@ BaseTranslator::TranslatorInfo() const
//
// Returns:
// ---------------------------------------------------------------
int32
int32
BaseTranslator::TranslatorVersion() const
{
return fVersion;
@ -213,7 +213,7 @@ BaseTranslator::InputFormats(int32 *out_count) const
//
// Returns: the array of output formats and the number of output
// formats through the out_count parameter
// ---------------------------------------------------------------
// ---------------------------------------------------------------
const translation_format *
BaseTranslator::OutputFormats(int32 *out_count) const
{
@ -229,7 +229,7 @@ BaseTranslator::OutputFormats(int32 *out_count) const
// identify_bits_header
//
// 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.
//
// Preconditions:
@ -259,7 +259,7 @@ BaseTranslator::OutputFormats(int32 *out_count) const
// B_OK, if the data looks like bits data and no errors were
// encountered
// ---------------------------------------------------------------
status_t
status_t
BaseTranslator::identify_bits_header(BPositionIO *inSource,
translator_info *outInfo, TranslatorBitmap *pheader)
{
@ -270,12 +270,12 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
if (inSource->Read(
(reinterpret_cast<uint8 *> (&header)), size) != size)
return B_NO_TRANSLATOR;
// convert to host byte order
if (swap_data(B_UINT32_TYPE, &header, sizeof(TranslatorBitmap),
B_SWAP_BENDIAN_TO_HOST) != B_OK)
return B_ERROR;
// check if header values are reasonable
if (header.colors != B_RGB32 &&
header.colors != B_RGB32_BIG &&
@ -299,7 +299,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
return B_NO_TRANSLATOR;
if (header.rowBytes * (header.bounds.Height() + 1) != header.dataSize)
return B_NO_TRANSLATOR;
if (outInfo) {
outInfo->type = B_TRANSLATOR_BITMAP;
outInfo->group = B_TRANSLATOR_BITMAP;
@ -307,7 +307,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
outInfo->capability = 0.2;
strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format"));
strcpy(outInfo->MIME, "image/x-be-bitmap");
// Look for quality / capability info in fInputFormats
for (int32 i = 0; i < fInputCount; i++) {
if (fInputFormats[i].type == B_TRANSLATOR_BITMAP &&
@ -319,7 +319,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
}
}
}
if (pheader) {
pheader->magic = header.magic;
pheader->bounds = header.bounds;
@ -327,7 +327,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
pheader->colors = header.colors;
pheader->dataSize = header.dataSize;
}
return B_OK;
}
@ -335,7 +335,7 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource,
// ---------------------------------------------------------------
// 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
// the translation entirely, if it must pass the task of
// 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
// it is a supported type
const uint32 kBitsMagic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
// Read in the magic number and determine if it
// is a supported type
uint8 ch[4];
@ -391,11 +391,11 @@ BaseTranslator::BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
inSource->Seek(-4, SEEK_CUR);
// seek backward becuase functions used after this one
// expect the stream to be at the beginning
// Read settings from ioExtension
if (ioExtension && fSettings->LoadSettings(ioExtension) < B_OK)
return B_BAD_VALUE;
uint32 sourceMagic;
memcpy(&sourceMagic, ch, sizeof(uint32));
if (sourceMagic == kBitsMagic)
@ -516,13 +516,13 @@ BaseTranslator::translate_from_bits_to_bits(BPositionIO *inSource,
{
TranslatorBitmap bitsHeader;
bool bheaderonly = false, bdataonly = false;
status_t result;
result = identify_bits_header(inSource, NULL, &bitsHeader);
if (result != B_OK)
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) {
// write out bitsHeader (only if configured to)
if (bheaderonly || (!bheaderonly && !bdataonly)) {
@ -533,9 +533,9 @@ BaseTranslator::translate_from_bits_to_bits(BPositionIO *inSource,
sizeof(TranslatorBitmap)) != sizeof(TranslatorBitmap))
return B_ERROR;
}
// write out the data (only if configured to)
if (bdataonly || (!bheaderonly && !bdataonly)) {
if (bdataonly || (!bheaderonly && !bdataonly)) {
uint8 buf[1024];
uint32 remaining = B_BENDIAN_TO_HOST_INT32(bitsHeader.dataSize);
ssize_t rd, writ;
@ -547,7 +547,7 @@ BaseTranslator::translate_from_bits_to_bits(BPositionIO *inSource,
remaining -= static_cast<uint32>(writ);
rd = inSource->Read(buf, min(1024, remaining));
}
if (remaining > 0)
return B_ERROR;
else
@ -587,7 +587,7 @@ BaseTranslator::BitsTranslate(BPositionIO *inSource,
// Preconditions:
//
// Parameters: inSource, the data to be translated
//
//
// inInfo, hint about the data in inSource (not used)
//
// ioExtension, configuration options for the
@ -638,7 +638,7 @@ BaseTranslator::GetConfigurationMessage(BMessage *ioExtension)
// MakeConfigurationView
//
// Makes a BView object for configuring / displaying info about
// this translator.
// this translator.
//
// Preconditions:
//

View File

@ -14,18 +14,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// 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
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
@ -55,15 +55,15 @@ public:
BaseTranslator(const char *name, const char *info,
const int32 version, const translation_format *inFormats,
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);
virtual const char *TranslatorName() const;
// returns the short name of the translator
virtual const char *TranslatorInfo() const;
// returns a verbose name/description for the translator
virtual int32 TranslatorVersion() const;
// returns the version of the translator
@ -71,7 +71,7 @@ public:
const;
// returns the input formats and the count of input formats
// that this translator supports
virtual const translation_format *OutputFormats(int32 *out_count)
const;
// 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,
// it translates the data in inSource to outDestination
// using the format outType
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
// write the current state of the translator into
// the supplied BMessage object
virtual status_t MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent);
// creates and returns the view for displaying information
// about this translator
TranslatorSettings *AcquireSettings();
// Functions to be implmemented by derived class
virtual status_t DerivedIdentify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType);
virtual status_t DerivedTranslate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination, int32 baseType);
virtual status_t DerivedCanHandleImageSize(float width, float height) const;
virtual BView *NewConfigView(TranslatorSettings *settings);
protected:
status_t BitsCheck(BPositionIO *inSource, BMessage *ioExtension,
@ -122,14 +122,14 @@ protected:
status_t BitsIdentify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType);
status_t identify_bits_header(BPositionIO *inSource,
translator_info *outInfo, TranslatorBitmap *pheader = NULL);
status_t BitsTranslate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
BPositionIO *outDestination);
status_t translate_from_bits_to_bits(BPositionIO *inSource,
uint32 outType, BPositionIO *outDestination);
@ -137,9 +137,9 @@ protected:
// this is protected because the object is deleted by the
// Release() function instead of being deleted directly by
// the user
TranslatorSettings *fSettings;
private:
int32 fVersion;
char *fName;

View File

@ -13,18 +13,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// 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
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
@ -51,15 +51,15 @@
// Returns:
// ---------------------------------------------------------------
TranslatorSettings::TranslatorSettings(const char *settingsFile,
TranSetting *defaults, int32 defCount)
const TranSetting *defaults, int32 defCount)
: fLock("TranslatorSettings Lock")
{
if (find_directory(B_USER_SETTINGS_DIRECTORY, &fSettingsPath))
fSettingsPath.SetTo("/tmp");
fSettingsPath.Append(settingsFile);
fRefCount = 1;
if (defCount > 0) {
fDefaults = defaults;
fDefCount = defCount;
@ -67,7 +67,7 @@ TranslatorSettings::TranslatorSettings(const char *settingsFile,
fDefaults = NULL;
fDefCount = 0;
}
// Add Default Settings
// (Used when loading from the settings file or from
// a BMessage fails)
@ -78,11 +78,11 @@ TranslatorSettings::TranslatorSettings(const char *settingsFile,
fSettingsMsg.AddBool(defs[i].name,
static_cast<bool>(defs[i].defaultVal));
break;
case TRAN_SETTING_INT32:
fSettingsMsg.AddInt32(defs[i].name, defs[i].defaultVal);
break;
default:
// ASSERT here? Erase the bogus setting entry instead?
break;
@ -94,7 +94,7 @@ TranslatorSettings::TranslatorSettings(const char *settingsFile,
// Acquire
//
// Returns a pointer to the TranslatorSettings and increments
// the reference count.
// the reference count.
//
// Preconditions:
//
@ -108,12 +108,12 @@ TranslatorSettings *
TranslatorSettings::Acquire()
{
TranslatorSettings *psettings = NULL;
fLock.Lock();
fRefCount++;
psettings = this;
fLock.Unlock();
return psettings;
}
@ -138,7 +138,7 @@ TranslatorSettings *
TranslatorSettings::Release()
{
TranslatorSettings *psettings = NULL;
fLock.Lock();
fRefCount--;
if (fRefCount > 0) {
@ -148,8 +148,8 @@ TranslatorSettings::Release()
delete this;
// delete this object and
// release locks
return psettings;
return psettings;
}
// ---------------------------------------------------------------
@ -188,9 +188,9 @@ status_t
TranslatorSettings::LoadSettings()
{
status_t result;
fLock.Lock();
// Don't try to open the settings file if there are
// no settings that need to be loaded
if (fDefCount > 0) {
@ -204,9 +204,9 @@ TranslatorSettings::LoadSettings()
}
} else
result = B_OK;
fLock.Unlock();
return result;
}
@ -294,9 +294,9 @@ status_t
TranslatorSettings::SaveSettings()
{
status_t result;
fLock.Lock();
// Only write out settings file if there are
// actual settings stored by this object
if (fDefCount > 0) {
@ -307,9 +307,9 @@ TranslatorSettings::SaveSettings()
result = fSettingsMsg.Flatten(&settingsFile);
} else
result = B_OK;
fLock.Unlock();
return result;
}
@ -334,7 +334,7 @@ status_t
TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
{
status_t result = B_BAD_VALUE;
if (pmsg) {
int32 i;
for (i = 0; i < fDefCount; i++) {
@ -345,7 +345,7 @@ TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
if (i == fDefCount) {
fLock.Lock();
result = B_OK;
const TranSetting *defs = fDefaults;
for (i = 0; i < fDefCount && result >= B_OK; i++) {
switch (defs[i].dataType) {
@ -353,22 +353,22 @@ TranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
result = pmsg->AddBool(defs[i].name,
SetGetBool(defs[i].name));
break;
case TRAN_SETTING_INT32:
result = pmsg->AddInt32(defs[i].name,
SetGetInt32(defs[i].name));
break;
default:
// ASSERT here? Erase the bogus setting entry instead?
break;
}
}
}
fLock.Unlock();
}
}
return result;
}
@ -420,9 +420,9 @@ bool
TranslatorSettings::SetGetBool(const char *name, bool *pbool)
{
bool bprevValue;
fLock.Lock();
const TranSetting *def = FindTranSetting(name);
if (def) {
fSettingsMsg.FindBool(def->name, &bprevValue);
@ -430,9 +430,9 @@ TranslatorSettings::SetGetBool(const char *name, bool *pbool)
fSettingsMsg.ReplaceBool(def->name, *pbool);
} else
bprevValue = false;
fLock.Unlock();
return bprevValue;
}
@ -458,9 +458,9 @@ int32
TranslatorSettings::SetGetInt32(const char *name, int32 *pint32)
{
int32 prevValue;
fLock.Lock();
const TranSetting *def = FindTranSetting(name);
if (def) {
fSettingsMsg.FindInt32(def->name, &prevValue);
@ -468,9 +468,9 @@ TranslatorSettings::SetGetInt32(const char *name, int32 *pint32)
fSettingsMsg.ReplaceInt32(def->name, *pint32);
} else
prevValue = 0;
fLock.Unlock();
return prevValue;
}

View File

@ -13,18 +13,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// 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
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
@ -49,40 +49,40 @@ struct TranSetting {
class TranslatorSettings {
public:
TranslatorSettings(const char *settingsFile, TranSetting *defaults,
TranslatorSettings(const char *settingsFile, const TranSetting *defaults,
int32 defCount);
TranslatorSettings *Acquire();
// increments the reference count, returns this
TranslatorSettings *Release();
// 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 zero
status_t LoadSettings();
status_t LoadSettings(BMessage *pmsg);
status_t SaveSettings();
status_t GetConfigurationMessage(BMessage *pmsg);
bool SetGetBool(const char *name, bool *pbool = NULL);
int32 SetGetInt32(const char *name, int32 *pint32 = NULL);
private:
const TranSetting *FindTranSetting(const char *name);
~TranslatorSettings();
// private so that Release() must be used
// to delete the object
BLocker fLock;
int32 fRefCount;
BPath fSettingsPath;
// where the settings file will be loaded from /
// saved to
BMessage fSettingsMsg;
// the actual settings
const TranSetting *fDefaults;
int32 fDefCount;
};

View File

@ -32,7 +32,7 @@ using namespace std;
#define DATA_BUFFER_SIZE 256
// The input formats that this translator supports.
translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
{
B_TRANSLATOR_TEXT,
B_TRANSLATOR_TEXT,
@ -52,7 +52,7 @@ translation_format gInputFormats[] = {
};
// The output formats that this translator supports.
translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_TEXT,
B_TRANSLATOR_TEXT,
@ -72,11 +72,15 @@ translation_format gOutputFormats[] = {
};
// Default settings for the Translator
TranSetting gDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_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
//
@ -119,7 +123,7 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* 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) {
mimeType->SetTo(subtypeMimeSpecific);
if (mimeType->IsInstalled())
found = true;
found = true;
}
if (!found && subtypeMimeGeneric != NULL) {
mimeType->SetTo(subtypeMimeGeneric);
if (mimeType->IsInstalled())
found = true;
found = true;
}
if (!found)
mimeType->SetTo("text/plain");
@ -195,7 +199,7 @@ file_ascmagic(const unsigned char *buf, size_t nbytes, BMimeType* mimeType,
{
size_t i;
unsigned char *nbuf = NULL;
my_unichar *ubuf = NULL;
my_unichar *ubuf = NULL;
size_t ulen;
struct names *p;
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)) {
code = "ISO-8859";
type = "text";
encoding = "iso-8859-1";
encoding = "iso-8859-1";
} else if (looks_extended(buf, nbytes, ubuf, &ulen)) {
code = "Non-ISO extended-ASCII";
type = "text";
@ -407,12 +411,12 @@ done:
if (subtypeMimeSpecific != NULL) {
mimeType->SetTo(subtypeMimeSpecific);
if (mimeType->IsInstalled())
found = true;
found = true;
}
if (!found && subtypeMimeGeneric != NULL) {
mimeType->SetTo(subtypeMimeGeneric);
if (mimeType->IsInstalled())
found = true;
found = true;
}
if (!found)
mimeType->SetTo("text/plain");
@ -789,19 +793,19 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
{
const ssize_t ktxtsize = sizeof(TranslatorStyledTextTextHeader);
const ssize_t kstylsize = sizeof(TranslatorStyledTextStyleHeader);
uint8 buffer[max(ktxtsize, kstylsize)];
// Check the TEXT header
TranslatorStyledTextTextHeader txtheader;
if (inSource->Read(buffer, ktxtsize) != ktxtsize)
return B_NO_TRANSLATOR;
memcpy(&txtheader, buffer, ktxtsize);
if (swap_data(B_UINT32_TYPE, &txtheader, ktxtsize,
B_SWAP_BENDIAN_TO_HOST) != B_OK)
return B_ERROR;
if (txtheader.header.magic != 'TEXT'
|| txtheader.header.header_size != sizeof(TranslatorStyledTextTextHeader)
|| txtheader.charset != B_UNICODE_UTF8)
@ -835,7 +839,7 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header,
return B_ERROR;
if (stylheader.header.magic != 'STYL'
|| stylheader.header.header_size !=
|| stylheader.header.header_size !=
sizeof(TranslatorStyledTextStyleHeader))
return B_NO_TRANSLATOR;
}
@ -943,10 +947,10 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
{
if (inSource->Seek(0, SEEK_SET) != 0)
return B_ERROR;
const ssize_t kstxtsize = sizeof(TranslatorStyledTextStreamHeader);
const ssize_t ktxtsize = sizeof(TranslatorStyledTextTextHeader);
bool btoplain;
if (outType == B_TRANSLATOR_TEXT)
btoplain = true;
@ -954,19 +958,19 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
btoplain = false;
else
return B_BAD_VALUE;
uint8 buffer[READ_BUFFER_SIZE];
ssize_t nread = 0, nwritten = 0, nreed = 0, ntotalread = 0;
// skip to the actual text data when outputting a
// plain text file
if (btoplain) {
if (inSource->Seek(kstxtsize + ktxtsize, SEEK_CUR) !=
if (inSource->Seek(kstxtsize + ktxtsize, SEEK_CUR) !=
kstxtsize + ktxtsize)
return B_ERROR;
}
// Read data from inSource
// Read data from inSource
// When outputing B_TRANSLATOR_TEXT, the loop stops when all of
// the text data has been read and written.
// 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;
nread = inSource->Read(buffer, nreed);
}
if (btoplain && static_cast<ssize_t>(txtheader.header.data_size) !=
ntotalread)
// If not all of the text data was able to be read...
@ -1017,10 +1021,10 @@ translate_from_stxt(BPositionIO *inSource, BPositionIO *outDestination,
//
// Postconditions:
//
// Returns:
// Returns:
//
// 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
// ---------------------------------------------------------------
@ -1032,22 +1036,22 @@ output_headers(BPositionIO *outDestination, uint32 text_data_size)
status_t result;
TranslatorStyledTextStreamHeader stxtheader;
TranslatorStyledTextTextHeader txtheader;
uint8 buffer[kHeadersSize];
stxtheader.header.magic = 'STXT';
stxtheader.header.header_size = sizeof(TranslatorStyledTextStreamHeader);
stxtheader.header.data_size = 0;
stxtheader.version = 100;
memcpy(buffer, &stxtheader, stxtheader.header.header_size);
txtheader.header.magic = 'TEXT';
txtheader.header.header_size = sizeof(TranslatorStyledTextTextHeader);
txtheader.header.data_size = text_data_size;
txtheader.charset = B_UNICODE_UTF8;
memcpy(buffer + stxtheader.header.header_size, &txtheader,
txtheader.header.header_size);
// write out headers in Big Endian byte order
result = swap_data(B_UINT32_TYPE, buffer, kHeadersSize,
B_SWAP_HOST_TO_BENDIAN);
@ -1059,7 +1063,7 @@ output_headers(BPositionIO *outDestination, uint32 text_data_size)
else
return B_OK;
}
return result;
}
@ -1084,7 +1088,7 @@ output_headers(BPositionIO *outDestination, uint32 text_data_size)
// Returns:
//
// 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
// ---------------------------------------------------------------
@ -1093,9 +1097,9 @@ output_styles(BPositionIO *outDestination, uint32 text_size,
uint8 *pflatRunArray, ssize_t data_size)
{
const ssize_t kstylsize = sizeof(TranslatorStyledTextStyleHeader);
uint8 buffer[kstylsize];
// output STYL header
TranslatorStyledTextStyleHeader stylheader;
stylheader.header.magic = 'STYL';
@ -1104,19 +1108,19 @@ output_styles(BPositionIO *outDestination, uint32 text_size,
stylheader.header.data_size = data_size;
stylheader.apply_offset = 0;
stylheader.apply_length = text_size;
memcpy(buffer, &stylheader, kstylsize);
if (swap_data(B_UINT32_TYPE, buffer, kstylsize,
B_SWAP_HOST_TO_BENDIAN) != B_OK)
return B_ERROR;
if (outDestination->Write(buffer, kstylsize) != kstylsize)
return B_ERROR;
// output actual style information
if (outDestination->Write(pflatRunArray,
data_size) != data_size)
return B_ERROR;
return B_OK;
}
@ -1290,7 +1294,7 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
return status;
}
// Read file attributes if outputting styled data
// Read file attributes if outputting styled data
// and source is a BNode object
if (node == NULL)
@ -1331,10 +1335,10 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
STXTTranslator::STXTTranslator()
: BaseTranslator("StyledEdit files", "StyledEdit files translator",
STXT_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"STXTTranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_TEXT, B_STYLED_TEXT_FORMAT)
{
}
@ -1354,9 +1358,9 @@ STXTTranslator::Identify(BPositionIO *inSource,
outType = B_TRANSLATOR_TEXT;
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
return B_NO_TRANSLATOR;
const ssize_t kstxtsize = sizeof(TranslatorStyledTextStreamHeader);
uint8 buffer[DATA_BUFFER_SIZE];
status_t nread = 0;
// Read in the header to determine

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@
/*!
How this works:
libtiff has a special version of TIFFOpen() that gets passed custom
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
@ -30,7 +30,7 @@
// The input formats that this translator supports.
translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -50,7 +50,7 @@ translation_format gInputFormats[] = {
};
// The output formats that this translator supports.
translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -70,13 +70,18 @@ translation_format gOutputFormats[] = {
};
// Default settings for the Translator
TranSetting gDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
{TIFF_SETTING_COMPRESSION, TRAN_SETTING_INT32, COMPRESSION_LZW}
// 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
//
@ -118,7 +123,7 @@ tiff_get_pio(thandle_t stream)
pio = static_cast<BPositionIO *>(stream);
if (!pio)
debugger("pio is NULL");
return pio;
}
@ -155,7 +160,7 @@ tiff_size_proc(thandle_t stream)
cur = pio->Position();
end = pio->Seek(0, SEEK_END);
pio->Seek(cur, SEEK_SET);
return end;
}
@ -177,10 +182,10 @@ status_t
identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
translator_info *outInfo, uint32 outType, TIFF **poutTIFF = NULL)
{
// get TIFF handle
// get TIFF handle
TIFF* tif = TIFFClientOpen("TIFFTranslator", "r", inSource,
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)
return B_NO_TRANSLATOR;
@ -234,7 +239,7 @@ identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
return B_OK;
}
// How this works:
// Following are a couple of functions,
@ -593,10 +598,10 @@ write_tif_stream(TIFF* tif, BPositionIO* inSource, color_space format,
TIFFTranslator::TIFFTranslator()
: BaseTranslator("TIFF images", "TIFF image translator",
TIFF_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"TIFFTranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, B_TIFF_FORMAT)
{
// TODO: for now!
@ -630,15 +635,15 @@ TIFFTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
result = identify_bits_header(inSource, NULL, &bitsHeader);
if (result != B_OK)
return result;
// Translate B_TRANSLATOR_BITMAP to B_TIFF_FORMAT
if (outType == B_TIFF_FORMAT) {
// Set up TIFF header
// get TIFF handle
// get TIFF handle
TIFF* tif = TIFFClientOpen("TIFFTranslator", "w", outDestination,
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)
return B_NO_TRANSLATOR;
@ -769,7 +774,7 @@ printf("using unkown compression (%ld).\n", compression);
default:
ret = B_NO_TRANSLATOR;
}
// Close the handle
// Close the handle
TIFFClose(tif);
return ret;
@ -787,16 +792,16 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
// Always write out the entire image. Some programs
// fail when given "headerOnly", even though they requested it.
// These settings are not applicable when outputting TIFFs
// variables needing cleanup
TIFF *ptif = NULL;
uint32 *praster = NULL;
status_t ret;
ret = identify_tiff_header(inSource, ioExtension, NULL, outType, &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
TIFFClose(ptif);
translate_direct_copy(inSource, outDestination);
@ -804,12 +809,12 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
}
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
ret = B_ERROR;
// make certain there is no looping
uint32 width = 0, height = 0;
if (!TIFFGetField(ptif, TIFFTAG_IMAGEWIDTH, &width)) {
result = B_NO_TRANSLATOR;
@ -841,7 +846,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
}
outDestination->Write(&bitsHeader, sizeof(TranslatorBitmap));
}
if (!bheaderonly) {
// Convert raw RGBA data to B_RGBA32 colorspace
// and write out the results
@ -855,7 +860,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
uint8 *pbits, *prgba;
pbits = pbitsrow;
prgba = pras8 + ((height - (i + 1)) * width * 4);
for (uint32 k = 0; k < width; k++) {
pbits[0] = prgba[2];
pbits[1] = prgba[1];
@ -875,7 +880,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
break;
} // if (praster && TIFFReadRGBAImage(ptif, width, height, praster, 0))
} // while (ret == B_OK && ptif)
if (praster) {
@ -899,7 +904,7 @@ TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension
// Preconditions:
//
// Parameters: inSource, the data to be translated
//
//
// inInfo, hint about the data in inSource (not used)
//
// ioExtension, configuration options for the

View File

@ -41,7 +41,7 @@ class FreeAllocation {
// The input formats that this translator supports.
translation_format sInputFormats[] = {
static const translation_format sInputFormats[] = {
{
WEBP_IMAGE_FORMAT,
B_TRANSLATOR_BITMAP,
@ -53,7 +53,7 @@ translation_format sInputFormats[] = {
};
// The output formats that this translator supports.
translation_format sOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -65,7 +65,7 @@ translation_format sOutputFormats[] = {
};
// Default settings for the Translator
static TranSetting sDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
};

View File

@ -23,7 +23,7 @@
using std::nothrow;
// The input formats that this translator supports.
translation_format gInputFormats[] = {
static const translation_format sInputFormats[] = {
/*{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -43,7 +43,7 @@ translation_format gInputFormats[] = {
};
// The output formats that this translator supports.
translation_format gOutputFormats[] = {
static const translation_format sOutputFormats[] = {
{
B_TRANSLATOR_BITMAP,
B_TRANSLATOR_BITMAP,
@ -64,11 +64,15 @@ translation_format gOutputFormats[] = {
// Default settings for the Translator
TranSetting gDefaultSettings[] = {
static const TranSetting sDefaultSettings[] = {
{ B_TRANSLATOR_EXT_HEADER_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*
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()
: BaseTranslator("WonderBrush images", "WonderBrush image translator",
WBI_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats,
"WBITranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, WBI_FORMAT)
{
#if GAMMA_BLEND
@ -112,7 +116,7 @@ identify_wbi_header(BPositionIO* inSource, translator_info* outInfo,
WonderBrushImage* wbImage = new(nothrow) WonderBrushImage();
if (wbImage)
status = wbImage->SetTo(inSource);
if (status >= B_OK) {
if (outInfo) {
outInfo->type = WBI_FORMAT;
@ -137,7 +141,7 @@ identify_wbi_header(BPositionIO* inSource, translator_info* outInfo,
return status;
}
status_t
WonderBrushTranslator::DerivedIdentify(BPositionIO* inSource,
@ -159,7 +163,7 @@ WonderBrushTranslator::DerivedTranslate(BPositionIO* inSource,
else
// if BaseTranslator did not properly identify the data as
// bits or not bits
return B_NO_TRANSLATOR;
return B_NO_TRANSLATOR;
}