Changed to use shared translator code
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6873 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
57ffd61845
commit
edd8878638
@ -1,12 +1,19 @@
|
||||
SubDir OBOS_TOP src add-ons translators sgitranslator ;
|
||||
|
||||
# Include BaseTranslator code from shared directory
|
||||
SEARCH_SOURCE += [ FDirName $(OBOS_TOP) src add-ons translators shared ] ;
|
||||
|
||||
Translator SGITranslator :
|
||||
# shared classes
|
||||
BaseTranslator.cpp
|
||||
TranslatorSettings.cpp
|
||||
TranslatorWindow.cpp
|
||||
|
||||
# SGITranslator classes
|
||||
SGIImage.cpp
|
||||
SGIMain.cpp
|
||||
SGITranslator.cpp
|
||||
SGITranslatorSettings.cpp
|
||||
SGIView.cpp
|
||||
SGIWindow.cpp ;
|
||||
SGIView.cpp ;
|
||||
|
||||
LinkSharedOSLibs SGITranslator : be translation ;
|
||||
|
||||
|
@ -35,11 +35,8 @@
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <Application.h>
|
||||
#include <Screen.h>
|
||||
#include <Alert.h>
|
||||
#include "SGITranslator.h"
|
||||
#include "SGIWindow.h"
|
||||
#include "SGIView.h"
|
||||
#include "TranslatorWindow.h"
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// main
|
||||
@ -58,47 +55,12 @@ int
|
||||
main()
|
||||
{
|
||||
BApplication app("application/x-vnd.obos-sgi-translator");
|
||||
SGITranslator *ptranslator = new SGITranslator;
|
||||
BView *view = NULL;
|
||||
BRect rect(0, 0, 225, 175);
|
||||
if (ptranslator->MakeConfigurationView(NULL, &view, &rect)) {
|
||||
BAlert *err = new BAlert("Error",
|
||||
"Unable to create the SGITranslator view.", "OK");
|
||||
err->Go();
|
||||
status_t result;
|
||||
result = LaunchTranslatorWindow(new SGITranslator,
|
||||
"SGI Settings", BRect(0, 0, 225, 175));
|
||||
if (result == B_OK) {
|
||||
app.Run();
|
||||
return 0;
|
||||
} else
|
||||
return 1;
|
||||
}
|
||||
// release the translator even though I never really used it anyway
|
||||
ptranslator->Release();
|
||||
ptranslator = NULL;
|
||||
|
||||
SGIWindow *wnd = new SGIWindow(rect);
|
||||
view->ResizeTo(rect.Width(), rect.Height());
|
||||
wnd->AddChild(view);
|
||||
BPoint wndpt = B_ORIGIN;
|
||||
{
|
||||
BScreen scrn;
|
||||
BRect frame = scrn.Frame();
|
||||
frame.InsetBy(10, 23);
|
||||
// if the point is outside of the screen frame,
|
||||
// use the mouse location to find a better point
|
||||
if (!frame.Contains(wndpt)) {
|
||||
uint32 dummy;
|
||||
view->GetMouse(&wndpt, &dummy, false);
|
||||
wndpt.x -= rect.Width() / 2;
|
||||
wndpt.y -= rect.Height() / 2;
|
||||
// clamp location to screen
|
||||
if (wndpt.x < frame.left)
|
||||
wndpt.x = frame.left;
|
||||
if (wndpt.y < frame.top)
|
||||
wndpt.y = frame.top;
|
||||
if (wndpt.x > frame.right)
|
||||
wndpt.x = frame.right;
|
||||
if (wndpt.y > frame.bottom)
|
||||
wndpt.y = frame.bottom;
|
||||
}
|
||||
}
|
||||
wnd->MoveTo(wndpt);
|
||||
wnd->Show();
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
@ -48,7 +48,6 @@
|
||||
|
||||
#include "SGIImage.h"
|
||||
#include "SGITranslator.h"
|
||||
#include "SGITranslatorSettings.h"
|
||||
#include "SGIView.h"
|
||||
|
||||
// The input formats that this translator supports.
|
||||
@ -91,6 +90,14 @@ translation_format gOutputFormats[] = {
|
||||
}
|
||||
};
|
||||
|
||||
// Default settings for the Translator
|
||||
TranSetting gDefaultSettings[] = {
|
||||
{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
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// make_nth_translator
|
||||
//
|
||||
@ -137,23 +144,20 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
SGITranslator::SGITranslator()
|
||||
: BTranslator(),
|
||||
fSettings(new SGITranslatorSettings())
|
||||
: BaseTranslator("SGI Images", "SGI image translator",
|
||||
SGI_TRANSLATOR_VERSION,
|
||||
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
|
||||
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
|
||||
"SGITranslator_Settings",
|
||||
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
|
||||
B_TRANSLATOR_BITMAP, SGI_FORMAT)
|
||||
{
|
||||
fSettings->LoadSettings();
|
||||
// load settings from the SGI Translator settings file
|
||||
|
||||
strcpy(fName, "SGI Images");
|
||||
sprintf(fInfo, "SGI image translator v%d.%d.%d %s",
|
||||
static_cast<int>(SGI_TRANSLATOR_VERSION >> 8),
|
||||
static_cast<int>((SGI_TRANSLATOR_VERSION >> 4) & 0xf),
|
||||
static_cast<int>(SGI_TRANSLATOR_VERSION & 0xf), __DATE__);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Destructor
|
||||
//
|
||||
// releases the settings object
|
||||
// Does nothing
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
@ -165,229 +169,12 @@ SGITranslator::SGITranslator()
|
||||
// ---------------------------------------------------------------
|
||||
SGITranslator::~SGITranslator()
|
||||
{
|
||||
fSettings->Release();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// TranslatorName
|
||||
//
|
||||
// Returns the short name of the translator.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: a const char * to the short name of the translator
|
||||
// ---------------------------------------------------------------
|
||||
const char *
|
||||
SGITranslator::TranslatorName() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// TranslatorInfo
|
||||
//
|
||||
// Returns a more verbose name for the translator than the one
|
||||
// TranslatorName() returns. This usually includes version info.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: a const char * to the verbose name of the translator
|
||||
// ---------------------------------------------------------------
|
||||
const char *
|
||||
SGITranslator::TranslatorInfo() const
|
||||
{
|
||||
return fInfo;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// TranslatorVersion
|
||||
//
|
||||
// Returns the integer representation of the current version of
|
||||
// this translator.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
int32
|
||||
SGITranslator::TranslatorVersion() const
|
||||
{
|
||||
return SGI_TRANSLATOR_VERSION;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// InputFormats
|
||||
//
|
||||
// Returns a list of input formats supported by this translator.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: out_count, The number of input formats
|
||||
// support is returned here.
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: the list of input formats and the number of input
|
||||
// formats through the out_count parameter, if out_count is NULL,
|
||||
// NULL is returned
|
||||
// ---------------------------------------------------------------
|
||||
const translation_format *
|
||||
SGITranslator::InputFormats(int32 *out_count) const
|
||||
{
|
||||
if (out_count) {
|
||||
*out_count = sizeof(gInputFormats) /
|
||||
sizeof(translation_format);
|
||||
return gInputFormats;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// OutputFormats
|
||||
//
|
||||
// Returns a list of output formats supported by this translator.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: out_count, The number of output formats
|
||||
// support is returned here.
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: the list of output formats and the number of output
|
||||
// formats through the out_count parameter, if out_count is NULL,
|
||||
// NULL is returned
|
||||
// ---------------------------------------------------------------
|
||||
const translation_format *
|
||||
SGITranslator::OutputFormats(int32 *out_count) const
|
||||
{
|
||||
if (out_count) {
|
||||
*out_count = sizeof(gOutputFormats) /
|
||||
sizeof(translation_format);
|
||||
return gOutputFormats;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// identify_bits_header
|
||||
//
|
||||
// Determines if the data in inSource is in the
|
||||
// B_TRANSLATOR_BITMAP ('bits') format. If it is, it returns
|
||||
// info about the data in inSource to outInfo and pheader.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: inSource, The source of the image data
|
||||
//
|
||||
// outInfo, Information about the translator
|
||||
// is copied here
|
||||
//
|
||||
// amtread, Amount of data read from inSource
|
||||
// before this function was called
|
||||
//
|
||||
// read, Pointer to the data that was read
|
||||
// in before this function was called
|
||||
//
|
||||
// pheader, The bits header is copied here after
|
||||
// it is read in from inSource
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_NO_TRANSLATOR, if the data does not look like
|
||||
// bits format data
|
||||
//
|
||||
// B_ERROR, if the header data could not be converted to host
|
||||
// format
|
||||
//
|
||||
// B_OK, if the data looks like bits data and no errors were
|
||||
// encountered
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
identify_bits_header(BPositionIO *inSource, translator_info *outInfo,
|
||||
ssize_t amtread, uint8 *read, TranslatorBitmap *pheader = NULL)
|
||||
{
|
||||
TranslatorBitmap header;
|
||||
|
||||
memcpy(&header, read, amtread);
|
||||
// copy portion of header already read in
|
||||
// read in the rest of the header
|
||||
ssize_t size = sizeof(TranslatorBitmap) - amtread;
|
||||
if (inSource->Read(
|
||||
(reinterpret_cast<uint8 *> (&header)) + amtread, 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;
|
||||
|
||||
// TODO: supress unwanted colorspaces here already?
|
||||
// check if header values are reasonable
|
||||
if (header.colors != B_RGB32 &&
|
||||
header.colors != B_RGB32_BIG &&
|
||||
header.colors != B_RGBA32 &&
|
||||
header.colors != B_RGBA32_BIG &&
|
||||
header.colors != B_RGB24 &&
|
||||
header.colors != B_RGB24_BIG &&
|
||||
header.colors != B_RGB16 &&
|
||||
header.colors != B_RGB16_BIG &&
|
||||
header.colors != B_RGB15 &&
|
||||
header.colors != B_RGB15_BIG &&
|
||||
header.colors != B_RGBA15 &&
|
||||
header.colors != B_RGBA15_BIG &&
|
||||
header.colors != B_CMAP8 &&
|
||||
header.colors != B_GRAY8 &&
|
||||
header.colors != B_GRAY1 &&
|
||||
header.colors != B_CMYK32 &&
|
||||
header.colors != B_CMY32 &&
|
||||
header.colors != B_CMYA32 &&
|
||||
header.colors != B_CMY24)
|
||||
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;
|
||||
outInfo->quality = BBT_IN_QUALITY;
|
||||
outInfo->capability = BBT_IN_CAPABILITY;
|
||||
strcpy(outInfo->name, "Be Bitmap Format (SGITranslator)");
|
||||
strcpy(outInfo->MIME, "image/x-be-bitmap");
|
||||
}
|
||||
|
||||
if (pheader) {
|
||||
pheader->magic = header.magic;
|
||||
pheader->bounds = header.bounds;
|
||||
pheader->rowBytes = header.rowBytes;
|
||||
pheader->colors = header.colors;
|
||||
pheader->dataSize = header.dataSize;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t
|
||||
identify_sgi_header(BPositionIO *inSource, BMessage *ioExtension,
|
||||
translator_info *outInfo, uint32 outType,
|
||||
identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outType,
|
||||
SGIImage **poutSGIImage = NULL)
|
||||
{
|
||||
// Can only output to bits for now
|
||||
if (outType != B_TRANSLATOR_BITMAP)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
status_t status = B_NO_MEMORY;
|
||||
// construct new SGIImage object and set it to the provided BPositionIO
|
||||
SGIImage* sgiImage = new(nothrow) SGIImage();
|
||||
@ -418,7 +205,7 @@ identify_sgi_header(BPositionIO *inSource, BMessage *ioExtension,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Identify
|
||||
// DerivedIdentify
|
||||
//
|
||||
// Examines the data from inSource and determines if it is in a
|
||||
// format that this translator knows how to work with.
|
||||
@ -457,96 +244,28 @@ identify_sgi_header(BPositionIO *inSource, BMessage *ioExtension,
|
||||
// Other errors if BPositionIO::Read() returned an error value
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslator::Identify(BPositionIO *inSource,
|
||||
SGITranslator::DerivedIdentify(BPositionIO *inSource,
|
||||
const translation_format *inFormat, BMessage *ioExtension,
|
||||
translator_info *outInfo, uint32 outType)
|
||||
{
|
||||
if (!outType)
|
||||
outType = B_TRANSLATOR_BITMAP;
|
||||
if (outType != B_TRANSLATOR_BITMAP && outType != SGI_FORMAT)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
// Convert the magic numbers to the various byte orders so that
|
||||
// I won't have to convert the data read in to see whether or not
|
||||
// it is a supported type
|
||||
uint32 nbits = B_TRANSLATOR_BITMAP;
|
||||
if (swap_data(B_UINT32_TYPE, &nbits, sizeof(uint32),
|
||||
B_SWAP_HOST_TO_BENDIAN) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
// Read in the magic number and determine if it
|
||||
// is a supported type
|
||||
uint8 ch[4];
|
||||
if (inSource->Read(ch, 4) != 4)
|
||||
return B_NO_TRANSLATOR;
|
||||
// Read settings from ioExtension
|
||||
if (ioExtension && fSettings->LoadSettings(ioExtension) < B_OK)
|
||||
return B_BAD_VALUE; // reason could be invalid settings,
|
||||
// like header only and data only set at the same time
|
||||
|
||||
uint32 n32ch;
|
||||
memcpy(&n32ch, ch, sizeof(uint32));
|
||||
// if B_TRANSLATOR_BITMAP type
|
||||
if (n32ch == nbits)
|
||||
return identify_bits_header(inSource, outInfo, 4, ch);
|
||||
// Might be SGI image
|
||||
else
|
||||
return identify_sgi_header(inSource, ioExtension, outInfo, outType);
|
||||
return identify_sgi_header(inSource, outInfo, outType);
|
||||
}
|
||||
|
||||
// translate_from_bits
|
||||
status_t
|
||||
translate_from_bits(BPositionIO *inSource, ssize_t amtread, uint8 *read,
|
||||
BMessage *ioExtension, uint32 outType, BPositionIO *outDestination,
|
||||
SGITranslatorSettings &settings)
|
||||
SGITranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
|
||||
BPositionIO *outDestination)
|
||||
{
|
||||
TranslatorBitmap bitsHeader;
|
||||
|
||||
bool bheaderonly = false, bdataonly = false;
|
||||
uint32 compression = settings.SetGetCompression();
|
||||
uint32 compression = fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
|
||||
|
||||
status_t ret = identify_bits_header(inSource, NULL, amtread, read, &bitsHeader);
|
||||
status_t ret = identify_bits_header(inSource, NULL, &bitsHeader);
|
||||
if (ret < B_OK)
|
||||
return ret;
|
||||
|
||||
// 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)) {
|
||||
if (swap_data(B_UINT32_TYPE, &bitsHeader,
|
||||
sizeof(TranslatorBitmap), B_SWAP_HOST_TO_BENDIAN) != B_OK)
|
||||
return B_ERROR;
|
||||
if (outDestination->Write(&bitsHeader,
|
||||
sizeof(TranslatorBitmap)) != sizeof(TranslatorBitmap))
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
// write out the data (only if configured to)
|
||||
if (bdataonly || (!bheaderonly && !bdataonly)) {
|
||||
uint32 size = 4096;
|
||||
uint8* buf = new uint8[size];
|
||||
uint32 remaining = B_BENDIAN_TO_HOST_INT32(bitsHeader.dataSize);
|
||||
ssize_t rd, writ = B_ERROR;
|
||||
rd = inSource->Read(buf, size);
|
||||
while (rd > 0) {
|
||||
writ = outDestination->Write(buf, rd);
|
||||
if (writ < 0)
|
||||
break;
|
||||
remaining -= static_cast<uint32>(writ);
|
||||
rd = inSource->Read(buf, min_c(size, remaining));
|
||||
}
|
||||
delete[] buf;
|
||||
|
||||
if (remaining > 0)
|
||||
// writ may contain a more specific error
|
||||
return writ < 0 ? writ : B_ERROR;
|
||||
else
|
||||
return B_OK;
|
||||
} else
|
||||
return B_OK;
|
||||
|
||||
// Translate B_TRANSLATOR_BITMAP to SGI_FORMAT
|
||||
} else if (outType == SGI_FORMAT) {
|
||||
if (outType == SGI_FORMAT) {
|
||||
|
||||
// common fields which are independent of the bitmap format
|
||||
uint32 width = bitsHeader.bounds.IntegerWidth() + 1;
|
||||
@ -555,7 +274,7 @@ translate_from_bits(BPositionIO *inSource, ssize_t amtread, uint8 *read,
|
||||
uint32 bytesPerChannel = 1;
|
||||
color_space format = bitsHeader.colors;
|
||||
|
||||
uint32 channelCount;
|
||||
uint32 channelCount;
|
||||
switch (format) {
|
||||
case B_GRAY8:
|
||||
channelCount = 1;
|
||||
@ -711,16 +430,21 @@ printf("WriteRow() returned %s!\n", strerror(ret));
|
||||
|
||||
// translate_from_sgi
|
||||
status_t
|
||||
translate_from_sgi(BPositionIO *inSource, BMessage *ioExtension,
|
||||
uint32 outType, BPositionIO *outDestination,
|
||||
SGITranslatorSettings &settings)
|
||||
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);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// variables needing cleanup
|
||||
SGIImage* sgiImage = NULL;
|
||||
|
||||
ret = identify_sgi_header(inSource, ioExtension, NULL, outType, &sgiImage);
|
||||
ret = identify_sgi_header(inSource, NULL, outType, &sgiImage);
|
||||
|
||||
if (ret >= B_OK) {
|
||||
|
||||
@ -952,7 +676,7 @@ printf("error writing bits header: %s\n", strerror(ret));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Translate
|
||||
// DerivedTranslate
|
||||
//
|
||||
// Translates the data in inSource to the type outType and stores
|
||||
// the translated data in outDestination.
|
||||
@ -971,6 +695,10 @@ printf("error writing bits header: %s\n", strerror(ret));
|
||||
// outDestination, where the translated data is
|
||||
// put
|
||||
//
|
||||
// baseType, indicates whether inSource is in the
|
||||
// bits format, not in the bits format or
|
||||
// is unknown
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_BAD_VALUE, if the options in ioExtension are bad
|
||||
@ -983,101 +711,25 @@ printf("error writing bits header: %s\n", strerror(ret));
|
||||
// B_OK, if all went well
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslator::Translate(BPositionIO *inSource,
|
||||
SGITranslator::DerivedTranslate(BPositionIO *inSource,
|
||||
const translator_info *inInfo, BMessage *ioExtension,
|
||||
uint32 outType, BPositionIO *outDestination)
|
||||
uint32 outType, BPositionIO *outDestination, int32 baseType)
|
||||
{
|
||||
if (!outType)
|
||||
outType = B_TRANSLATOR_BITMAP;
|
||||
if (outType != B_TRANSLATOR_BITMAP && outType != SGI_FORMAT)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
// Convert the magic numbers to the various byte orders so that
|
||||
// I won't have to convert the data read in to see whether or not
|
||||
// it is a supported type
|
||||
uint32 nbits = B_TRANSLATOR_BITMAP;
|
||||
if (swap_data(B_UINT32_TYPE, &nbits, sizeof(uint32),
|
||||
B_SWAP_HOST_TO_BENDIAN) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
// Read in the magic number and determine if it
|
||||
// is a supported type
|
||||
uint8 ch[4];
|
||||
inSource->Seek(0, SEEK_SET);
|
||||
if (inSource->Read(ch, 4) != 4)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
// Read settings from ioExtension
|
||||
if (ioExtension && fSettings->LoadSettings(ioExtension) < B_OK)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
uint32 n32ch;
|
||||
memcpy(&n32ch, ch, sizeof(uint32));
|
||||
if (n32ch == nbits) {
|
||||
// B_TRANSLATOR_BITMAP type
|
||||
return translate_from_bits(inSource, 4, ch, ioExtension, outType,
|
||||
outDestination, *fSettings);
|
||||
} else
|
||||
// Might be SGI image
|
||||
return translate_from_sgi(inSource, ioExtension, outType,
|
||||
outDestination, *fSettings);
|
||||
if (baseType == 1)
|
||||
// if inSource is in bits format
|
||||
return translate_from_bits(inSource, outType, outDestination);
|
||||
else if (baseType == 0)
|
||||
// if inSource is NOT in bits format
|
||||
return translate_from_sgi(inSource, outType, outDestination);
|
||||
else
|
||||
// if BaseTranslator did not properly identify the data as
|
||||
// bits or not bits
|
||||
return B_NO_TRANSLATOR;
|
||||
}
|
||||
|
||||
// returns the current translator settings into ioExtension
|
||||
status_t
|
||||
SGITranslator::GetConfigurationMessage(BMessage *ioExtension)
|
||||
BView *
|
||||
SGITranslator::NewConfigView(TranslatorSettings *settings)
|
||||
{
|
||||
return fSettings->GetConfigurationMessage(ioExtension);
|
||||
return new SGIView(BRect(0, 0, 225, 175), "SGITranslator Settings",
|
||||
B_FOLLOW_ALL, B_WILL_DRAW, settings);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// MakeConfigurationView
|
||||
//
|
||||
// Makes a BView object for configuring / displaying info about
|
||||
// this translator.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: ioExtension, configuration options for the
|
||||
// translator
|
||||
//
|
||||
// outView, the view to configure the
|
||||
// translator is stored here
|
||||
//
|
||||
// outExtent, the bounds of the view are
|
||||
// stored here
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_BAD_VALUE if outView or outExtent is NULL,
|
||||
// B_NO_MEMORY if the view couldn't be allocated,
|
||||
// B_OK if no errors
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslator::MakeConfigurationView(BMessage *ioExtension, BView **outView,
|
||||
BRect *outExtent)
|
||||
{
|
||||
if (!outView || !outExtent)
|
||||
return B_BAD_VALUE;
|
||||
if (ioExtension && fSettings->LoadSettings(ioExtension) < B_OK)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
SGIView *view = new SGIView(BRect(0, 0, 225, 175),
|
||||
"SGITranslator Settings", B_FOLLOW_ALL, B_WILL_DRAW,
|
||||
AcquireSettings());
|
||||
if (!view)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
*outView = view;
|
||||
*outExtent = view->Bounds();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// AcquireSettings
|
||||
SGITranslatorSettings *
|
||||
SGITranslator::AcquireSettings()
|
||||
{
|
||||
return fSettings->Acquire();
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,9 @@
|
||||
#include <File.h>
|
||||
#include <ByteOrder.h>
|
||||
#include <fs_attr.h>
|
||||
#include "BaseTranslator.h"
|
||||
|
||||
#define SGI_TRANSLATOR_VERSION 0x100
|
||||
#define SGI_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VER(1,0,0)
|
||||
|
||||
#define SGI_IN_QUALITY 0.5
|
||||
#define SGI_IN_CAPABILITY 0.6
|
||||
@ -58,59 +59,26 @@
|
||||
#define BBT_OUT_QUALITY 0.4
|
||||
#define BBT_OUT_CAPABILITY 0.6
|
||||
|
||||
// SGI Translator Settings
|
||||
#define SGI_SETTING_COMPRESSION "sgi /compression"
|
||||
|
||||
enum {
|
||||
SGI_FORMAT = 'SGI ',
|
||||
};
|
||||
|
||||
class SGITranslatorSettings;
|
||||
|
||||
class SGITranslator : public BTranslator {
|
||||
class SGITranslator : public BaseTranslator {
|
||||
public:
|
||||
SGITranslator();
|
||||
|
||||
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
|
||||
|
||||
virtual const translation_format *InputFormats(int32 *out_count)
|
||||
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
|
||||
// that this translator supports
|
||||
|
||||
virtual status_t Identify(BPositionIO *inSource,
|
||||
virtual status_t DerivedIdentify(BPositionIO *inSource,
|
||||
const translation_format *inFormat, BMessage *ioExtension,
|
||||
translator_info *outInfo, uint32 outType);
|
||||
// determines whether or not this translator can convert the
|
||||
// data in inSource to the type outType
|
||||
|
||||
virtual status_t Translate(BPositionIO *inSource,
|
||||
|
||||
virtual status_t DerivedTranslate(BPositionIO *inSource,
|
||||
const translator_info *inInfo, BMessage *ioExtension,
|
||||
uint32 outType, BPositionIO *outDestination);
|
||||
// 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
|
||||
uint32 outType, BPositionIO *outDestination, int32 baseType);
|
||||
|
||||
|
||||
virtual status_t MakeConfigurationView(BMessage *ioExtension,
|
||||
BView **outView, BRect *outExtent);
|
||||
// creates and returns the view for displaying information
|
||||
// about this translator
|
||||
|
||||
SGITranslatorSettings *AcquireSettings();
|
||||
virtual BView *NewConfigView(TranslatorSettings *settings);
|
||||
|
||||
protected:
|
||||
virtual ~SGITranslator();
|
||||
@ -118,11 +86,13 @@ protected:
|
||||
// Release() function instead of being deleted directly by
|
||||
// the user
|
||||
|
||||
private:
|
||||
SGITranslatorSettings *fSettings;
|
||||
private:
|
||||
|
||||
char fName[30];
|
||||
char fInfo[100];
|
||||
status_t translate_from_bits(BPositionIO *inSource, uint32 outType,
|
||||
BPositionIO *outDestination);
|
||||
|
||||
status_t translate_from_sgi(BPositionIO *inSource, uint32 outType,
|
||||
BPositionIO *outDestination);
|
||||
};
|
||||
|
||||
#endif // #ifndef SGI_TRANSLATOR_H
|
||||
|
@ -1,447 +0,0 @@
|
||||
/*****************************************************************************/
|
||||
// SGITranslatorSettings
|
||||
// Adopted by Stephan Aßmus, <stippi@yellowbites.com>
|
||||
// from TGATranslatorSettings written by
|
||||
// Written by Michael Wilber, OBOS Translation Kit Team
|
||||
//
|
||||
// SGITranslatorSettings.cpp
|
||||
//
|
||||
// This class manages (saves/loads/locks/unlocks) the settings
|
||||
// for the SGITranslator.
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2002 OpenBeOS Project
|
||||
//
|
||||
// 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
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// 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
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// 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.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <TranslatorFormats.h>
|
||||
// for B_TRANSLATOR_EXT_*
|
||||
|
||||
#include "SGIImage.h"
|
||||
|
||||
#include "SGITranslatorSettings.h"
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor
|
||||
//
|
||||
// Sets the default settings, location for the settings file
|
||||
// and sets the reference count to 1
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
SGITranslatorSettings::SGITranslatorSettings()
|
||||
: fLock("SGI Settings Lock")
|
||||
{
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &fSettingsPath) < B_OK)
|
||||
fSettingsPath.SetTo("/tmp");
|
||||
fSettingsPath.Append(SGI_SETTINGS_FILENAME);
|
||||
|
||||
fRefCount = 1;
|
||||
|
||||
// Default Settings
|
||||
// (Used when loading from the settings file or from
|
||||
// a BMessage fails)
|
||||
fSettingsMSG.AddBool(B_TRANSLATOR_EXT_HEADER_ONLY, false);
|
||||
fSettingsMSG.AddBool(B_TRANSLATOR_EXT_DATA_ONLY, false);
|
||||
fSettingsMSG.AddInt32(SGI_SETTING_COMPRESSION, SGI_COMP_RLE);
|
||||
// compression is set to RLE by default
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Acquire
|
||||
//
|
||||
// Returns a pointer to the SGITranslatorSettings and increments
|
||||
// the reference count.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: pointer to this SGITranslatorSettings object
|
||||
// ---------------------------------------------------------------
|
||||
SGITranslatorSettings *
|
||||
SGITranslatorSettings::Acquire()
|
||||
{
|
||||
SGITranslatorSettings *psettings = NULL;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
fRefCount++;
|
||||
psettings = this;
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
return psettings;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Release
|
||||
//
|
||||
// Decrements the reference count and deletes the
|
||||
// SGITranslatorSettings if the reference count is zero.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: pointer to this SGITranslatorSettings object if
|
||||
// the reference count is greater than zero, returns NULL
|
||||
// if the reference count is zero and the SGITranslatorSettings
|
||||
// object has been deleted
|
||||
// ---------------------------------------------------------------
|
||||
SGITranslatorSettings *
|
||||
SGITranslatorSettings::Release()
|
||||
{
|
||||
SGITranslatorSettings *psettings = NULL;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
fRefCount--;
|
||||
if (fRefCount > 0) {
|
||||
psettings = this;
|
||||
fLock.Unlock();
|
||||
} else
|
||||
delete this;
|
||||
// delete this object and
|
||||
// release locks
|
||||
}
|
||||
|
||||
return psettings;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Destructor
|
||||
//
|
||||
// Does nothing!
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
SGITranslatorSettings::~SGITranslatorSettings()
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// LoadSettings
|
||||
//
|
||||
// Loads the settings by reading them from the default
|
||||
// settings file.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_OK if there were no errors or an error code from
|
||||
// BFile::SetTo() or BMessage::Unflatten() if there were errors
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslatorSettings::LoadSettings()
|
||||
{
|
||||
status_t result = B_ERROR;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
|
||||
BFile settingsFile;
|
||||
result = settingsFile.SetTo(fSettingsPath.Path(), B_READ_ONLY);
|
||||
if (result >= B_OK) {
|
||||
BMessage msg;
|
||||
result = msg.Unflatten(&settingsFile);
|
||||
if (result >= B_OK)
|
||||
result = LoadSettings(&msg);
|
||||
}
|
||||
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// LoadSettings
|
||||
//
|
||||
// Loads the settings from a BMessage passed to the function.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: pmsg pointer to BMessage that contains the
|
||||
// settings
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_BAD_VALUE if pmsg is NULL or invalid options
|
||||
// have been found, B_OK if there were no
|
||||
// errors or an error code from BMessage::FindBool() or
|
||||
// BMessage::ReplaceBool() if there were other errors
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslatorSettings::LoadSettings(BMessage *pmsg)
|
||||
{
|
||||
status_t result = B_BAD_VALUE;
|
||||
|
||||
if (pmsg) {
|
||||
// Make certain that no SGI settings
|
||||
// are missing from the file
|
||||
bool bheaderOnly, bdataOnly;
|
||||
uint32 compression;
|
||||
|
||||
result = B_ERROR;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
|
||||
result = pmsg->FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bheaderOnly);
|
||||
if (result < B_OK)
|
||||
bheaderOnly = SetGetHeaderOnly();
|
||||
result = pmsg->FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bdataOnly);
|
||||
if (result < B_OK)
|
||||
bdataOnly = SetGetDataOnly();
|
||||
result = pmsg->FindInt32(SGI_SETTING_COMPRESSION, (int32*)&compression);
|
||||
if (result < B_OK)
|
||||
compression = SetGetCompression();
|
||||
|
||||
if (bheaderOnly && bdataOnly)
|
||||
// "write header only" and "write data only"
|
||||
// are mutually exclusive
|
||||
result = B_BAD_VALUE;
|
||||
else {
|
||||
result = B_OK;
|
||||
|
||||
result = fSettingsMSG.ReplaceBool(
|
||||
B_TRANSLATOR_EXT_HEADER_ONLY, bheaderOnly);
|
||||
if (result >= B_OK)
|
||||
result = fSettingsMSG.ReplaceBool(
|
||||
B_TRANSLATOR_EXT_DATA_ONLY, bdataOnly);
|
||||
if (result >= B_OK)
|
||||
result = fSettingsMSG.ReplaceInt32(SGI_SETTING_COMPRESSION,
|
||||
compression);
|
||||
}
|
||||
fLock.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// SaveSettings
|
||||
//
|
||||
// Saves the settings as a flattened BMessage to the default
|
||||
// settings file
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_OK if no errors or an error code from BFile::SetTo()
|
||||
// or BMessage::Flatten() if there were errors
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslatorSettings::SaveSettings()
|
||||
{
|
||||
status_t result = B_ERROR;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
|
||||
BFile settingsFile;
|
||||
result = settingsFile.SetTo(fSettingsPath.Path(),
|
||||
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||
if (result >= B_OK)
|
||||
result = fSettingsMSG.Flatten(&settingsFile);
|
||||
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// GetConfigurationMessage
|
||||
//
|
||||
// Saves the current settings to the BMessage passed to the
|
||||
// function
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: pmsg pointer to BMessage where the settings
|
||||
// will be stored
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: B_OK if there were no errors or an error code from
|
||||
// BMessage::RemoveName() or BMessage::AddBool() if there were
|
||||
// errors
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
SGITranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
|
||||
{
|
||||
status_t result = B_BAD_VALUE;
|
||||
|
||||
if (pmsg) {
|
||||
const char *kNames[] = {
|
||||
B_TRANSLATOR_EXT_HEADER_ONLY,
|
||||
B_TRANSLATOR_EXT_DATA_ONLY,
|
||||
SGI_SETTING_COMPRESSION
|
||||
};
|
||||
const int32 klen = sizeof(kNames) / sizeof(const char *);
|
||||
int32 i;
|
||||
for (i = 0; i < klen; i++) {
|
||||
result = pmsg->RemoveName(kNames[i]);
|
||||
if (result < B_OK && result != B_NAME_NOT_FOUND)
|
||||
break;
|
||||
}
|
||||
if (i == klen && fLock.Lock()) {
|
||||
result = B_OK;
|
||||
|
||||
result = pmsg->AddBool(B_TRANSLATOR_EXT_HEADER_ONLY,
|
||||
SetGetHeaderOnly());
|
||||
if (result >= B_OK)
|
||||
result = pmsg->AddBool(B_TRANSLATOR_EXT_DATA_ONLY,
|
||||
SetGetDataOnly());
|
||||
if (result >= B_OK)
|
||||
result = pmsg->AddInt32(SGI_SETTING_COMPRESSION, SetGetCompression());
|
||||
|
||||
fLock.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// SetGetHeaderOnly
|
||||
//
|
||||
// Sets the state of the HeaderOnly setting (if pbHeaderOnly
|
||||
// is not NULL) and returns the previous value of the
|
||||
// HeaderOnly setting.
|
||||
//
|
||||
// If the HeaderOnly setting is true, only the header of
|
||||
// the image will be output; the data will not be output.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: pbHeaderOnly pointer to a bool specifying
|
||||
// the new value of the
|
||||
// HeaderOnly setting
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: the prior value of the HeaderOnly setting
|
||||
// ---------------------------------------------------------------
|
||||
bool
|
||||
SGITranslatorSettings::SetGetHeaderOnly(bool *pbHeaderOnly)
|
||||
{
|
||||
bool bprevValue;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
fSettingsMSG.FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bprevValue);
|
||||
if (pbHeaderOnly)
|
||||
fSettingsMSG.ReplaceBool(B_TRANSLATOR_EXT_HEADER_ONLY, *pbHeaderOnly);
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
return bprevValue;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// SetGetDataOnly
|
||||
//
|
||||
// Sets the state of the DataOnly setting (if pbDataOnly
|
||||
// is not NULL) and returns the previous value of the
|
||||
// DataOnly setting.
|
||||
//
|
||||
// If the DataOnly setting is true, only the data of
|
||||
// the image will be output; the header will not be output.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: pbDataOnly pointer to a bool specifying
|
||||
// the new value of the
|
||||
// DataOnly setting
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: the prior value of the DataOnly setting
|
||||
// ---------------------------------------------------------------
|
||||
bool
|
||||
SGITranslatorSettings::SetGetDataOnly(bool *pbDataOnly)
|
||||
{
|
||||
bool bprevValue;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
fSettingsMSG.FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bprevValue);
|
||||
if (pbDataOnly)
|
||||
fSettingsMSG.ReplaceBool(B_TRANSLATOR_EXT_DATA_ONLY, *pbDataOnly);
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
return bprevValue;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// SetGetRLE
|
||||
//
|
||||
// Sets the state of the RLE setting (if pbRLE is not NULL)
|
||||
// and returns the previous value of the RLE setting.
|
||||
//
|
||||
// If the RLE setting is true, SGI images created by the
|
||||
// SGITranslator will be RLE compressed.
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: pbRLE pointer to bool which specifies
|
||||
// the new value for the RLE setting
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns: the prior value of the RLE setting
|
||||
// ---------------------------------------------------------------
|
||||
uint32
|
||||
SGITranslatorSettings::SetGetCompression(uint32 *pCompression)
|
||||
{
|
||||
uint32 prevValue;
|
||||
|
||||
if (fLock.Lock()) {
|
||||
fSettingsMSG.FindInt32(SGI_SETTING_COMPRESSION, (int32*)&prevValue);
|
||||
if (pCompression)
|
||||
fSettingsMSG.ReplaceInt32(SGI_SETTING_COMPRESSION, *pCompression);
|
||||
fLock.Unlock();
|
||||
}
|
||||
|
||||
return prevValue;
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*****************************************************************************/
|
||||
// SGITranslatorSettings
|
||||
// Adopted by Stephan Aßmus, <stippi@yellowbites.com>
|
||||
// from TGATranslatorSettings written by
|
||||
// Michael Wilber, OBOS Translation Kit Team
|
||||
//
|
||||
// SGITranslatorSettings.h
|
||||
//
|
||||
// This class manages (saves/loads/locks/unlocks) the settings
|
||||
// for the SGITranslator.
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2002 OpenBeOS Project
|
||||
//
|
||||
// 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
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// 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
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// 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.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef SGI_TRANSLATOR_SETTINGS_H
|
||||
#define SGI_TRANSLATOR_SETTINGS_H
|
||||
|
||||
#include <Locker.h>
|
||||
#include <Path.h>
|
||||
#include <Message.h>
|
||||
|
||||
#define SGI_SETTINGS_FILENAME "SGITranslator_Settings"
|
||||
|
||||
// SGI Translator Settings
|
||||
#define SGI_SETTING_COMPRESSION "sgi /compression"
|
||||
|
||||
class SGITranslatorSettings {
|
||||
public:
|
||||
SGITranslatorSettings();
|
||||
|
||||
SGITranslatorSettings *Acquire();
|
||||
// increments the reference count, returns this
|
||||
SGITranslatorSettings *Release();
|
||||
// decrements the reference count, deletes this
|
||||
// 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 SetGetHeaderOnly(bool *pbHeaderOnly = NULL);
|
||||
// sets / gets HeaderOnly setting
|
||||
// specifies if only the image header should be
|
||||
// outputted
|
||||
bool SetGetDataOnly(bool *pbDataOnly = NULL);
|
||||
// sets / gets DataOnly setting
|
||||
// specifiees if only the image data should be
|
||||
// outputted
|
||||
uint32 SetGetCompression(uint32 *pCompression = NULL);
|
||||
// sets / gets Compression setting
|
||||
// specifies what compression will be used
|
||||
// when the SGITranslator creates SGI images
|
||||
|
||||
private:
|
||||
~SGITranslatorSettings();
|
||||
// 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
|
||||
};
|
||||
|
||||
#endif // #ifndef SGI_TRANSLATOR_SETTTINGS_H
|
@ -41,8 +41,6 @@
|
||||
|
||||
#include "SGIImage.h"
|
||||
#include "SGITranslator.h"
|
||||
#include "SGITranslatorSettings.h"
|
||||
|
||||
#include "SGIView.h"
|
||||
|
||||
const char* author = "Stephan Aßmus, <stippi@yellowbites.com>";
|
||||
@ -75,7 +73,7 @@ add_menu_item(BMenu* menu,
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
SGIView::SGIView(const BRect &frame, const char *name,
|
||||
uint32 resize, uint32 flags, SGITranslatorSettings* settings)
|
||||
uint32 resize, uint32 flags, TranslatorSettings *settings)
|
||||
: BView(frame, name, resize, flags),
|
||||
fSettings(settings)
|
||||
{
|
||||
@ -83,7 +81,7 @@ SGIView::SGIView(const BRect &frame, const char *name,
|
||||
|
||||
BPopUpMenu* menu = new BPopUpMenu("pick compression");
|
||||
|
||||
uint32 currentCompression = fSettings->SetGetCompression();
|
||||
uint32 currentCompression = fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
|
||||
// create the menu items with the various compression methods
|
||||
add_menu_item(menu, SGI_COMP_NONE, "None", currentCompression);
|
||||
// menu->AddSeparatorItem();
|
||||
@ -163,9 +161,9 @@ SGIView::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_COMPRESSION_CHANGED: {
|
||||
uint32 value;
|
||||
if (message->FindInt32("value", (int32*)&value) >= B_OK) {
|
||||
fSettings->SetGetCompression(&value);
|
||||
int32 value;
|
||||
if (message->FindInt32("value", &value) >= B_OK) {
|
||||
fSettings->SetGetInt32(SGI_SETTING_COMPRESSION, &value);
|
||||
fSettings->SaveSettings();
|
||||
}
|
||||
break;
|
||||
@ -280,8 +278,10 @@ SGIView::Draw(BRect area)
|
||||
|
||||
char detail[100];
|
||||
sprintf(detail, "Version %d.%d.%d %s",
|
||||
SGI_TRANSLATOR_VERSION / 100, (SGI_TRANSLATOR_VERSION / 10) % 10,
|
||||
SGI_TRANSLATOR_VERSION % 10, __DATE__);
|
||||
static_cast<int>(B_TRANSLATION_MAJOR_VER(SGI_TRANSLATOR_VERSION)),
|
||||
static_cast<int>(B_TRANSLATION_MINOR_VER(SGI_TRANSLATOR_VERSION)),
|
||||
static_cast<int>(B_TRANSLATION_REVSN_VER(SGI_TRANSLATOR_VERSION)),
|
||||
__DATE__);
|
||||
DrawString(detail, BPoint(xbold, yplain + ybold));
|
||||
|
||||
BPoint offset = fCompressionMF->Frame().LeftBottom();
|
||||
|
@ -34,14 +34,14 @@
|
||||
#define SGIVIEW_H
|
||||
|
||||
#include <View.h>
|
||||
#include "TranslatorSettings.h"
|
||||
|
||||
class BMenuField;
|
||||
class SGITranslatorSettings;
|
||||
|
||||
class SGIView : public BView {
|
||||
public:
|
||||
SGIView(const BRect &frame, const char *name, uint32 resize,
|
||||
uint32 flags, SGITranslatorSettings* psettings);
|
||||
uint32 flags, TranslatorSettings *settings);
|
||||
// sets up the view
|
||||
|
||||
~SGIView();
|
||||
@ -62,7 +62,7 @@ public:
|
||||
private:
|
||||
BMenuField* fCompressionMF;
|
||||
|
||||
SGITranslatorSettings* fSettings;
|
||||
TranslatorSettings *fSettings;
|
||||
// the actual settings for the translator,
|
||||
// shared with the translator
|
||||
};
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*****************************************************************************/
|
||||
// SGIWindow
|
||||
// Adopted by Stephan Aßmus, <stippi@yellowbites.com>
|
||||
// from TIFFWindow written by
|
||||
// Michael Wilber, OBOS Translation Kit Team
|
||||
//
|
||||
// SGIWindow.cpp
|
||||
//
|
||||
// This BWindow based object is used to hold the SGIView object when the
|
||||
// user runs the SGITranslator as an application.
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// 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
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// 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
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// 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.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "SGIWindow.h"
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor
|
||||
//
|
||||
// Sets up the BWindow for holding a SGIView
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters: area, The bounds of the window
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
SGIWindow::SGIWindow(BRect area)
|
||||
: BWindow(area, "SGITranslator", B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Destructor
|
||||
//
|
||||
// Posts a quit message so that the application is close properly
|
||||
//
|
||||
// Preconditions:
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// Postconditions:
|
||||
//
|
||||
// Returns:
|
||||
// ---------------------------------------------------------------
|
||||
SGIWindow::~SGIWindow()
|
||||
{
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*****************************************************************************/
|
||||
// SGIWindow
|
||||
// Adopted by Stephan Aßmus, <stippi@yellowbites.com>
|
||||
// from TIFFWindow written by
|
||||
// Michael Wilber, OBOS Translation Kit Team
|
||||
//
|
||||
// SGIWindow.h
|
||||
//
|
||||
// This BWindow based object is used to hold the SGIView object when the
|
||||
// user runs the SGITranslator as an application.
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2003 OpenBeOS Project
|
||||
//
|
||||
// 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
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// 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
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// 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.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef SGIWINDOW_H
|
||||
#define SGIWINDOW_H
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
|
||||
class SGIWindow : public BWindow {
|
||||
public:
|
||||
SGIWindow(BRect area);
|
||||
// Sets up a BWindow with bounds area
|
||||
|
||||
~SGIWindow();
|
||||
// Posts a quit message so that the application closes properly
|
||||
};
|
||||
|
||||
#endif // #define SGIWINDOW_H
|
Loading…
Reference in New Issue
Block a user