Initial check in for Stephan Assmus' SGITranslator

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6472 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2004-02-02 23:55:38 +00:00
parent fbf9f5c51e
commit f29673f8ae
12 changed files with 3584 additions and 0 deletions
@@ -0,0 +1,16 @@
SubDir OBOS_TOP src add-ons translators sgitranslator ;
Translator SGITranslator :
SGIImage.cpp
SGIMain.cpp
SGITranslator.cpp
SGITranslatorSettings.cpp
SGIView.cpp
SGIWindow.cpp ;
LinkSharedOSLibs SGITranslator : be translation ;
Package openbeos-translationkit-cvs :
SGITranslator :
boot home config add-ons Translators ;
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,138 @@
/*
* "$Id: SGIImage.h,v 1.1 2004/02/02 23:55:38 mwilber Exp $"
*
* SGI image file format library definitions.
*
* Copyright 1997-1998 Michael Sweet ([email protected])
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Revision History:
*
* $Log: SGIImage.h,v $
* Revision 1.1 2004/02/02 23:55:38 mwilber
* Initial check in for Stephan Assmus' SGITranslator
*
* Revision 1.5 1998/05/17 16:01:33 mike
* Added <unistd.h> header file.
*
* Revision 1.4 1998/04/23 17:40:49 mike
* Updated to support 16-bit <unsigned> image data.
*
* Revision 1.3 1998/02/05 17:10:58 mike
* Added sgiOpenFile() function for opening an existing file pointer.
*
* Revision 1.2 1997/06/18 00:55:28 mike
* Updated to hold length table when writing.
* Updated to hold current length when doing ARLE.
*
* Revision 1.1 1997/06/15 03:37:19 mike
* Initial revision
*/
#ifndef SGI_IMAGE_H
#define SGI_IMAGE_H
#include <DataIO.h>
#include <InterfaceDefs.h>
#define SGI_MAGIC 474 // magic number in image file
#define SGI_READ 0 // read from an SGI image file
#define SGI_WRITE 1 // write to an SGI image file
#define SGI_COMP_NONE 0 // no compression
#define SGI_COMP_RLE 1 // run-length encoding
#define SGI_COMP_ARLE 2 // agressive run-length encoding
extern const char kSGICopyright[];
class SGIImage {
public:
SGIImage();
virtual ~SGIImage();
// not really necessary, SetTo() will return an error anyways
status_t InitCheck() const;
// first version -> read from an existing sgi image in stream
status_t SetTo(BPositionIO* stream);
// second version -> set up a stream for writing an sgi image;
// when SetTo() returns, the image header will have been written
// already
status_t SetTo(BPositionIO* stream,
uint16 width, uint16 height,
uint16 channels, uint32 bytesPerChannel,
uint32 compression);
// has to be called if writing, writes final information to the stream
status_t Unset();
// access to each row of image data
status_t ReadRow(void* row, int32 lineNum, int32 channel);
// write one row of image data
// right now, could be used to modify an image in place, but only
// if dealing with uncompressed data, compressed data is currently
// not supported
status_t WriteRow(void* row, int32 lineNum, int32 channel);
// access to the attributes of the sgi image
uint16 Width() const
{ return fWidth; }
uint16 Height() const
{ return fHeight; }
uint32 BytesPerChannel() const
{ return fBytesPerChannel; }
uint32 CountChannels() const
{ return fChannelCount; }
private:
int32 _ReadLong() const;
int16 _ReadShort() const;
int8 _ReadChar() const;
status_t _WriteLong(int32 n) const;
status_t _WriteShort(uint16 n) const;
status_t _WriteChar(int8 n) const;
ssize_t _ReadRLE8(uint8* row, int32 numPixels) const;
ssize_t _ReadRLE8(uint8* row, uint8* rleBuffer, int32 numPixels) const;
ssize_t _ReadRLE16(uint16* row, int32 numPixels) const;
ssize_t _ReadRLE16(uint16* row, uint16* rleBuffer, int32 numPixels) const;
ssize_t _WriteRLE8(uint8* row, int32 numPixels) const;
ssize_t _WriteRLE16(uint16* row, int32 numPixels) const;
BPositionIO* fStream;
uint32 fMode; // reading or writing
uint32 fBytesPerChannel;
uint32 fCompression;
uint16 fWidth; // in number of pixels
uint16 fHeight; // in number of pixels
uint16 fChannelCount;
off_t fFirstRowOffset; // offset into stream
off_t fNextRowOffset; // offset into stream
int32** fOffsetTable; // offset table for compression
int32** fLengthTable; // length table for compression
uint16* fARLERow; // advanced RLE compression buffer
int32 fARLEOffset; // advanced RLE buffer offset
int32 fARLELength; // advanced RLE buffer length
};
#endif // SGI_IMAGE_H
@@ -0,0 +1,104 @@
/*****************************************************************************/
// SGITranslator
// Adopted by Stephan Aßmus, <[email protected]>
// from TIFFMain written by
// Michael Wilber, OBOS Translation Kit Team
//
// Version:
//
// This translator opens and writes SGI images.
//
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// 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 <Application.h>
#include <Screen.h>
#include <Alert.h>
#include "SGITranslator.h"
#include "SGIWindow.h"
#include "SGIView.h"
// ---------------------------------------------------------------
// main
//
// Creates a BWindow for displaying info about the SGITranslator
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
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();
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;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,128 @@
/*****************************************************************************/
// SGITranslator
// Written by Stephan Aßmus
// based on TIFFTranslator written mostly by
// Michael Wilber, OBOS Translation Kit Team
//
// SGITranslator.h
//
// This BTranslator based object is for opening and writing
// SGI images.
//
//
// 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 SGI_TRANSLATOR_H
#define SGI_TRANSLATOR_H
#include <Translator.h>
#include <TranslatorFormats.h>
#include <TranslationDefs.h>
#include <GraphicsDefs.h>
#include <InterfaceDefs.h>
#include <DataIO.h>
#include <File.h>
#include <ByteOrder.h>
#include <fs_attr.h>
#define SGI_TRANSLATOR_VERSION 100
#define SGI_IN_QUALITY 0.5
#define SGI_IN_CAPABILITY 0.6
#define SGI_OUT_QUALITY 1.0
// high out quality because this code outputs fully standard SGIs
#define SGI_OUT_CAPABILITY 0.4
// medium out capability because not many SGI features are supported (?)
#define BBT_IN_QUALITY 0.4
#define BBT_IN_CAPABILITY 0.6
#define BBT_OUT_QUALITY 0.4
#define BBT_OUT_CAPABILITY 0.6
enum {
SGI_FORMAT = 'SGI ',
};
class SGITranslatorSettings;
class SGITranslator : public BTranslator {
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,
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,
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
virtual status_t MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent);
// creates and returns the view for displaying information
// about this translator
SGITranslatorSettings *AcquireSettings();
protected:
virtual ~SGITranslator();
// this is protected because the object is deleted by the
// Release() function instead of being deleted directly by
// the user
private:
SGITranslatorSettings *fSettings;
char fName[30];
char fInfo[100];
};
#endif // #ifndef SGI_TRANSLATOR_H
@@ -0,0 +1,447 @@
/*****************************************************************************/
// SGITranslatorSettings
// Adopted by Stephan Aßmus, <[email protected]>
// 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;
}
@@ -0,0 +1,91 @@
/*****************************************************************************/
// SGITranslatorSettings
// Adopted by Stephan Aßmus, <[email protected]>
// 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
@@ -0,0 +1,335 @@
/*****************************************************************************/
// SGIView
// Adopted by Stephan Aßmus, <[email protected]>
// from TIFFView written by
// Picking the compression method added by Stephan Aßmus, <[email protected]>
//
// SGIView.cpp
//
// This BView based object displays information about the SGITranslator.
//
//
// 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 <stdio.h>
#include <string.h>
#include <MenuBar.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <Window.h>
#include "SGIImage.h"
#include "SGITranslator.h"
#include "SGITranslatorSettings.h"
#include "SGIView.h"
const char* author = "Stephan Aßmus, <[email protected]>";
// add_menu_item
void
add_menu_item(BMenu* menu,
uint32 compression,
const char* label,
uint32 currentCompression)
{
BMessage* message = new BMessage(SGIView::MSG_COMPRESSION_CHANGED);
message->AddInt32("value", compression);
BMenuItem* item = new BMenuItem(label, message);
item->SetMarked(currentCompression == compression);
menu->AddItem(item);
}
// ---------------------------------------------------------------
// Constructor
//
// Sets up the view settings
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
SGIView::SGIView(const BRect &frame, const char *name,
uint32 resize, uint32 flags, SGITranslatorSettings* settings)
: BView(frame, name, resize, flags),
fSettings(settings)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BPopUpMenu* menu = new BPopUpMenu("pick compression");
uint32 currentCompression = fSettings->SetGetCompression();
// create the menu items with the various compression methods
add_menu_item(menu, SGI_COMP_NONE, "None", currentCompression);
// menu->AddSeparatorItem();
add_menu_item(menu, SGI_COMP_RLE, "RLE", currentCompression);
// DON'T turn this on, it's so slow that I didn't wait long enough
// the one time I tested this. So I don't know if the code even works.
// Supposedly, this would look for an already written scanline, and
// modify the scanline tables so that the current row is not written
// at all...
// add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression);
BRect menuFrame = Bounds();
menuFrame.bottom = menuFrame.top + menu->Bounds().Height();
fCompressionMF = new BMenuField(menuFrame, "compression",
"Use Compression:", menu, true/*,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP*/);
if (fCompressionMF->MenuBar())
fCompressionMF->MenuBar()->ResizeToPreferred();
fCompressionMF->ResizeToPreferred();
// figure out where the text ends
font_height fh;
be_bold_font->GetHeight(&fh);
float xbold, ybold;
xbold = fh.descent + 1;
ybold = fh.ascent + fh.descent * 2 + fh.leading;
font_height plainh;
be_plain_font->GetHeight(&plainh);
float yplain;
yplain = plainh.ascent + plainh.descent * 2 + plainh.leading;
// position the menu field below all the text we draw in Draw()
BPoint textOffset(0.0, yplain * 2 + ybold);
fCompressionMF->MoveTo(textOffset);
AddChild(fCompressionMF);
ResizeToPreferred();
}
// ---------------------------------------------------------------
// Destructor
//
// Does nothing
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
SGIView::~SGIView()
{
fSettings->Release();
}
// ---------------------------------------------------------------
// MessageReceived
//
// Handles state changes of the Compression menu field
//
// Preconditions:
//
// Parameters: area, not used
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
void
SGIView::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_COMPRESSION_CHANGED: {
uint32 value;
if (message->FindInt32("value", (int32*)&value) >= B_OK) {
fSettings->SetGetCompression(&value);
fSettings->SaveSettings();
}
break;
}
default:
BView::MessageReceived(message);
}
}
// ---------------------------------------------------------------
// AllAttached
//
// sets the target for the controls controlling the configuration
//
// Preconditions:
//
// Parameters: area, not used
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
void
SGIView::AllAttached()
{
fCompressionMF->Menu()->SetTargetForItems(this);
}
// ---------------------------------------------------------------
// AttachedToWindow
//
// hack to make the window recognize our size
//
// Preconditions:
//
// Parameters: area, not used
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
void
SGIView::AttachedToWindow()
{
// Hack for DataTranslations which doesn't resize visible area to requested by view
// which makes some parts of bigger than usual translationviews out of visible area
// so if it was loaded to DataTranslations resize window if needed
BWindow *window = Window();
if (!strcmp(window->Name(), "DataTranslations")) {
BView *view = Parent();
if (view) {
BRect frame = view->Frame();
float x, y;
GetPreferredSize(&x, &y);
if (frame.Width() < x || (frame.Height() - 48) < y) {
x -= frame.Width();
y -= frame.Height() - 48;
if (x < 0) x = 0;
if (y < 0) y = 0;
// DataTranslations has main view called "Background"
// change it's resizing mode so it will always resize with window
// also make sure view will be redrawed after resize
view = window->FindView("Background");
if (view) {
view->SetResizingMode(B_FOLLOW_ALL);
view->SetFlags(B_FULL_UPDATE_ON_RESIZE);
}
// The same with "Info..." button, except redrawing, which isn't needed
view = window->FindView("Info…");
if (view)
view->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
window->ResizeBy( x, y);
}
}
}
}
// ---------------------------------------------------------------
// Draw
//
// Draws information about the SGITranslator to this view.
//
// Preconditions:
//
// Parameters: area, not used
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
void
SGIView::Draw(BRect area)
{
SetFont(be_bold_font);
font_height fh;
GetFontHeight(&fh);
float xbold, ybold;
xbold = fh.descent + 1;
ybold = fh.ascent + fh.descent * 2 + fh.leading;
const char* text = "OpenBeOS SGI Image Translator";
DrawString(text, BPoint(xbold, ybold));
SetFont(be_plain_font);
font_height plainh;
GetFontHeight(&plainh);
float yplain;
yplain = plainh.ascent + plainh.descent * 2 + plainh.leading;
char detail[100];
sprintf(detail, "Version %d.%d.%d %s",
SGI_TRANSLATOR_VERSION / 100, (SGI_TRANSLATOR_VERSION / 10) % 10,
SGI_TRANSLATOR_VERSION % 10, __DATE__);
DrawString(detail, BPoint(xbold, yplain + ybold));
BPoint offset = fCompressionMF->Frame().LeftBottom();
offset.x += xbold;
offset.y += 2 * ybold;
text = "written by:";
DrawString(text, offset);
offset.y += ybold;
DrawString(author, offset);
offset.y += 2 * ybold;
text = "based on GIMP SGI plugin v1.5:";
DrawString(text, offset);
offset.y += ybold;
DrawString(kSGICopyright, offset);
}
// ---------------------------------------------------------------
// Draw
//
// calculated the preferred size of this view
//
// Preconditions:
//
// Parameters: width and height
//
// Postconditions:
//
// Returns: in width and height, the preferred size...
// ---------------------------------------------------------------
void
SGIView::GetPreferredSize(float* width, float* height)
{
*width = fCompressionMF->Bounds().Width();
// look at the two biggest strings
float width1 = StringWidth(kSGICopyright) + 15.0;
if (*width < width1)
*width = width1;
float width2 = be_plain_font->StringWidth(author) + 15.0;
if (*width < width2)
*width = width2;
font_height fh;
be_bold_font->GetHeight(&fh);
float ybold = fh.ascent + fh.descent * 2 + fh.leading;
*height = fCompressionMF->Bounds().bottom + 7 * ybold;
}
@@ -0,0 +1,70 @@
/*****************************************************************************/
// SGIView
// Adopted by Stephan Aßmus, <[email protected]>
// from TIFFView written by
// Picking the compression method added by Stephan Aßmus, <[email protected]>
//
// SGIView.h
//
// This BView based object displays information about the SGITranslator.
//
//
// 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 SGIVIEW_H
#define SGIVIEW_H
#include <View.h>
class BMenuField;
class SGITranslatorSettings;
class SGIView : public BView {
public:
SGIView(const BRect &frame, const char *name, uint32 resize,
uint32 flags, SGITranslatorSettings* psettings);
// sets up the view
~SGIView();
// releases the SGITranslator settings
virtual void AllAttached();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void Draw(BRect area);
// draws information about the SGITranslator
virtual void GetPreferredSize(float* width, float* height);
enum {
MSG_COMPRESSION_CHANGED = 'cmch',
};
private:
BMenuField* fCompressionMF;
SGITranslatorSettings* fSettings;
// the actual settings for the translator,
// shared with the translator
};
#endif // #ifndef SGIVIEW_H
@@ -0,0 +1,71 @@
/*****************************************************************************/
// SGIWindow
// Adopted by Stephan Aßmus, <[email protected]>
// 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);
}
@@ -0,0 +1,50 @@
/*****************************************************************************/
// SGIWindow
// Adopted by Stephan Aßmus, <[email protected]>
// 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