changed to use shared translator code

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6842 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber 2004-03-01 04:38:21 +00:00
parent c36e6575c8
commit a1fd38b277
10 changed files with 105 additions and 1183 deletions

View File

@ -2,6 +2,9 @@ SubDir OBOS_TOP src add-ons translators libtifftranslator ;
UseLibraryHeaders zlib ;
# Include BaseTranslator code from shared directory
SEARCH_SOURCE += [ FDirName $(OBOS_TOP) src add-ons translators shared ] ;
Translator TIFFTranslator :
# libtiff
tif_aux.c
@ -38,12 +41,15 @@ Translator TIFFTranslator :
tif_write.c
tif_zip.c
# TIFFTranslator
TIFFTranslatorSettings.cpp
# shared classes
BaseTranslator.cpp
TranslatorSettings.cpp
TranslatorWindow.cpp
# TIFFTranslator classes
TIFFMain.cpp
TIFFTranslator.cpp
TIFFView.cpp
TIFFWindow.cpp ;
TIFFView.cpp ;
LinkSharedOSLibs TIFFTranslator : be translation libz.a ;

View File

@ -33,11 +33,8 @@
/*****************************************************************************/
#include <Application.h>
#include <Screen.h>
#include <Alert.h>
#include "TIFFTranslator.h"
#include "TIFFWindow.h"
#include "TIFFView.h"
#include "TranslatorWindow.h"
// ---------------------------------------------------------------
// main
@ -56,48 +53,12 @@ int
main()
{
BApplication app("application/x-vnd.obos-tiff-translator");
TIFFTranslator *ptranslator = new TIFFTranslator;
BView *view = NULL;
BRect rect(0, 0, 225, 175);
if (ptranslator->MakeConfigurationView(NULL, &view, &rect)) {
BAlert *err = new BAlert("Error",
"Unable to create the TIFFTranslator view.", "OK");
err->Go();
status_t result;
result = LaunchTranslatorWindow(new TIFFTranslator,
"TIFFTranslator", 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;
TIFFWindow *wnd = new TIFFWindow(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;
}

View File

@ -43,7 +43,6 @@
#include <string.h>
#include "tiffio.h"
#include "TIFFTranslator.h"
#include "TIFFTranslatorSettings.h"
#include "TIFFView.h"
// The input formats that this translator supports.
@ -86,6 +85,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},
{TIFF_SETTING_COMPRESSION, TRAN_SETTING_INT32, COMPRESSION_LZW}
// Compression is LZW by default
};
// ---------------------------------------------------------------
// make_nth_translator
//
@ -196,17 +203,14 @@ tiff_unmap_file_proc(thandle_t stream, tdata_t base, toff_t size)
// Returns:
// ---------------------------------------------------------------
TIFFTranslator::TIFFTranslator()
: BTranslator(),
fSettings(new TIFFTranslatorSettings())
: BaseTranslator("TIFF Images", "TIFF image translator",
TIFF_TRANSLATOR_VERSION,
gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
"TIFFTranslator_Settings",
gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting),
B_TRANSLATOR_BITMAP, B_TIFF_FORMAT)
{
fSettings->LoadSettings();
// load settings from the TIFF Translator settings file
strcpy(fName, "TIFF Images");
sprintf(fInfo, "TIFF image translator v%d.%d.%d %s",
static_cast<int>(TIFF_TRANSLATOR_VERSION >> 8),
static_cast<int>((TIFF_TRANSLATOR_VERSION >> 4) & 0xf),
static_cast<int>(TIFF_TRANSLATOR_VERSION & 0xf), __DATE__);
}
// ---------------------------------------------------------------
@ -224,230 +228,12 @@ TIFFTranslator::TIFFTranslator()
// ---------------------------------------------------------------
TIFFTranslator::~TIFFTranslator()
{
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 *
TIFFTranslator::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 *
TIFFTranslator::TranslatorInfo() const
{
return fInfo;
}
// ---------------------------------------------------------------
// TranslatorVersion
//
// Returns the integer representation of the current version of
// this translator.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
int32
TIFFTranslator::TranslatorVersion() const
{
return TIFF_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 *
TIFFTranslator::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 *
TIFFTranslator::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;
// 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 (TIFFTranslator)");
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_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
translator_info *outInfo, uint32 outType, TIFF **poutTIFF = NULL)
{
// Can only output to bits for now
if (outType != B_TRANSLATOR_BITMAP)
return B_NO_TRANSLATOR;
// reset pos to start
inSource->Seek(0, SEEK_SET);
// get TIFF handle
TIFF* tif = TIFFClientOpen("TIFFTranslator", "r", inSource,
tiff_read_proc, tiff_write_proc, tiff_seek_proc, tiff_close_proc,
@ -504,7 +290,7 @@ identify_tiff_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.
@ -543,52 +329,11 @@ identify_tiff_header(BPositionIO *inSource, BMessage *ioExtension,
// Other errors if BPositionIO::Read() returned an error value
// ---------------------------------------------------------------
status_t
TIFFTranslator::Identify(BPositionIO *inSource,
TIFFTranslator::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 != B_TIFF_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 TIFF image
else {
// TIFF Byte Order / Magic
const uint8 kleSig[] = { 0x49, 0x49, 0x2a, 0x00 };
const uint8 kbeSig[] = { 0x4d, 0x4d, 0x00, 0x2a };
if (memcmp(ch, kleSig, 4) != 0 && memcmp(ch, kbeSig, 4) != 0)
// If not a TIFF or a Be Bitmap image
// (invalid byte order value)
return B_NO_TRANSLATOR;
return identify_tiff_header(inSource, ioExtension, outInfo, outType);
}
return identify_tiff_header(inSource, ioExtension, outInfo, outType);
}
// How this works:
@ -943,61 +688,20 @@ write_tif_stream(TIFF* tif, BPositionIO* inSource, color_space format,
// translate_from_bits
status_t
translate_from_bits(BPositionIO *inSource, ssize_t amtread, uint8 *read,
BMessage *ioExtension, uint32 outType, BPositionIO *outDestination,
TIFFTranslatorSettings &settings)
TIFFTranslator::translate_from_bits(BPositionIO *inSource, uint32 outType,
BPositionIO *outDestination)
{
TranslatorBitmap bitsHeader;
bool bheaderonly = false, bdataonly = false;
// Always write out the entire image. Some programs
// fail when given "headerOnly", even though they requested it.
// These settings are not applicable when outputting TIFFs
uint32 compression = settings.SetGetCompression();
uint32 compression = fSettings->SetGetInt32(TIFF_SETTING_COMPRESSION);
status_t result;
result = identify_bits_header(inSource, NULL, amtread, read, &bitsHeader);
result = identify_bits_header(inSource, NULL, &bitsHeader);
if (result != B_OK)
return result;
// 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 B_TIFF_FORMAT
} else if (outType == B_TIFF_FORMAT) {
if (outType == B_TIFF_FORMAT) {
// Set up TIFF header
// get TIFF handle
@ -1142,11 +846,9 @@ printf("using unkown compression (%ld).\n", compression);
return B_NO_TRANSLATOR;
}
// translate_from_tiff
status_t
translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination,
TIFFTranslatorSettings &settings)
TIFFTranslator::translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination)
{
status_t result = B_NO_TRANSLATOR;
@ -1161,6 +863,15 @@ translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
status_t ret;
ret = identify_tiff_header(inSource, ioExtension, NULL, outType, &ptif);
if (outType == B_TIFF_FORMAT && ret == B_OK && ptif) {
// if translating from TIFF to TIFF,
// just write out the entire TIFF
TIFFClose(ptif);
translate_direct_copy(inSource, outDestination);
return B_OK;
}
while (ret == B_OK && ptif) {
// use while / break not for looping, but for
// cleaner goto like capability
@ -1249,7 +960,7 @@ translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
}
// ---------------------------------------------------------------
// Translate
// DerivedTranslate
//
// Translates the data in inSource to the type outType and stores
// the translated data in outDestination.
@ -1268,6 +979,10 @@ translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
// 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
@ -1280,101 +995,25 @@ translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
// B_OK, if all went well
// ---------------------------------------------------------------
status_t
TIFFTranslator::Translate(BPositionIO *inSource,
TIFFTranslator::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 != B_TIFF_FORMAT)
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_tiff(inSource, ioExtension, outType, outDestination);
else
// if BaseTranslator did not properly identify the data as
// bits or not bits
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 TIFF image
return translate_from_tiff(inSource, ioExtension, outType,
outDestination, *fSettings);
}
// returns the current translator settings into ioExtension
status_t
TIFFTranslator::GetConfigurationMessage(BMessage *ioExtension)
BView *
TIFFTranslator::NewConfigView(TranslatorSettings *settings)
{
return fSettings->GetConfigurationMessage(ioExtension);
return new TIFFView(BRect(0, 0, 225, 175), "TIFFTranslator 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
TIFFTranslator::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;
TIFFView *view = new TIFFView(BRect(0, 0, 225, 175),
"TIFFTranslator Settings", B_FOLLOW_ALL, B_WILL_DRAW,
AcquireSettings());
if (!view)
return B_NO_MEMORY;
*outView = view;
*outExtent = view->Bounds();
return B_OK;
}
// AcquireSettings
TIFFTranslatorSettings *
TIFFTranslator::AcquireSettings()
{
return fSettings->Acquire();
}

View File

@ -41,12 +41,16 @@
#include <File.h>
#include <ByteOrder.h>
#include <fs_attr.h>
#include "BaseTranslator.h"
// IO Extension Names:
#define DOCUMENT_COUNT "/documentCount"
#define DOCUMENT_INDEX "/documentIndex"
#define TIFF_TRANSLATOR_VERSION 0x100
// TIFF Translator Settings
#define TIFF_SETTING_COMPRESSION "tiff /compression"
#define TIFF_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VER(1,0,0)
#define TIFF_IN_QUALITY 0.7
#define TIFF_IN_CAPABILITY 0.6
@ -58,55 +62,19 @@
#define BBT_OUT_QUALITY 0.7
#define BBT_OUT_CAPABILITY 0.6
class TIFFTranslatorSettings;
class TIFFTranslator : public BTranslator {
class TIFFTranslator : public BaseTranslator {
public:
TIFFTranslator();
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
TIFFTranslatorSettings *AcquireSettings();
virtual BView *NewConfigView(TranslatorSettings *settings);
protected:
virtual ~TIFFTranslator();
@ -115,10 +83,11 @@ protected:
// the user
private:
TIFFTranslatorSettings *fSettings;
char fName[30];
char fInfo[100];
status_t translate_from_bits(BPositionIO *inSource, uint32 outType,
BPositionIO *outDestination);
status_t translate_from_tiff(BPositionIO *inSource, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination);
};
#endif // #ifndef TIFF_TRANSLATOR_H

View File

@ -1,446 +0,0 @@
/*****************************************************************************/
// TIFFTranslatorSettings
// Adopted by Stephan Aßmus, <stippi@yellowbites.com>
// from TGATranslatorSettings written by
// Michael Wilber, OBOS Translation Kit Team
//
// TIFFTranslatorSettings.cpp
//
// This class manages (saves/loads/locks/unlocks) the settings
// for the TIFFTranslator.
//
//
// 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 "tiff.h"
#include <File.h>
#include <FindDirectory.h>
#include <TranslatorFormats.h>
// for B_TRANSLATOR_EXT_*
#include "TIFFTranslatorSettings.h"
// ---------------------------------------------------------------
// Constructor
//
// Sets the default settings, location for the settings file
// and sets the reference count to 1
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
TIFFTranslatorSettings::TIFFTranslatorSettings()
: fLock("TIFF Settings Lock")
{
if (find_directory(B_USER_SETTINGS_DIRECTORY, &fSettingsPath) < B_OK)
fSettingsPath.SetTo("/tmp");
fSettingsPath.Append(TIFF_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(TIFF_SETTING_COMPRESSION, COMPRESSION_LZW);
// compression is set to LZW by default
}
// ---------------------------------------------------------------
// Acquire
//
// Returns a pointer to the TIFFTranslatorSettings and increments
// the reference count.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: pointer to this TIFFTranslatorSettings object
// ---------------------------------------------------------------
TIFFTranslatorSettings *
TIFFTranslatorSettings::Acquire()
{
TIFFTranslatorSettings *psettings = NULL;
if (fLock.Lock()) {
fRefCount++;
psettings = this;
fLock.Unlock();
}
return psettings;
}
// ---------------------------------------------------------------
// Release
//
// Decrements the reference count and deletes the
// TIFFTranslatorSettings if the reference count is zero.
//
// Preconditions:
//
// Parameters:
//
// Postconditions:
//
// Returns: pointer to this TIFFTranslatorSettings object if
// the reference count is greater than zero, returns NULL
// if the reference count is zero and the TIFFTranslatorSettings
// object has been deleted
// ---------------------------------------------------------------
TIFFTranslatorSettings *
TIFFTranslatorSettings::Release()
{
TIFFTranslatorSettings *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:
// ---------------------------------------------------------------
TIFFTranslatorSettings::~TIFFTranslatorSettings()
{
}
// ---------------------------------------------------------------
// 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
TIFFTranslatorSettings::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
TIFFTranslatorSettings::LoadSettings(BMessage *pmsg)
{
status_t result = B_BAD_VALUE;
if (pmsg) {
// Make certain that no TIFF 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(TIFF_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(TIFF_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
TIFFTranslatorSettings::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
TIFFTranslatorSettings::GetConfigurationMessage(BMessage *pmsg)
{
status_t result = B_BAD_VALUE;
if (pmsg) {
const char *kNames[] = {
B_TRANSLATOR_EXT_HEADER_ONLY,
B_TRANSLATOR_EXT_DATA_ONLY,
TIFF_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(TIFF_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
TIFFTranslatorSettings::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
TIFFTranslatorSettings::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, TIFF images created by the
// TIFFTranslator 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
TIFFTranslatorSettings::SetGetCompression(uint32 *pCompression)
{
uint32 prevValue;
if (fLock.Lock()) {
fSettingsMSG.FindInt32(TIFF_SETTING_COMPRESSION, (int32*)&prevValue);
if (pCompression)
fSettingsMSG.ReplaceInt32(TIFF_SETTING_COMPRESSION, *pCompression);
fLock.Unlock();
}
return prevValue;
}

View File

@ -1,91 +0,0 @@
/*****************************************************************************/
// TIFFTranslatorSettings
// Adopted by Stephan Aßmus, <stippi@yellowbites.com>
// from TGATranslatorSettings written by
// Michael Wilber, OBOS Translation Kit Team
//
// TIFFTranslatorSettings.h
//
// This class manages (saves/loads/locks/unlocks) the settings
// for the TIFFTranslator.
//
//
// 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 TIFF_TRANSLATOR_SETTINGS_H
#define TIFF_TRANSLATOR_SETTINGS_H
#include <Locker.h>
#include <Path.h>
#include <Message.h>
#define TIFF_SETTINGS_FILENAME "TIFFTranslator_Settings"
// TIFF Translator Settings
#define TIFF_SETTING_COMPRESSION "tiff /compression"
class TIFFTranslatorSettings {
public:
TIFFTranslatorSettings();
TIFFTranslatorSettings *Acquire();
// increments the reference count, returns this
TIFFTranslatorSettings *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 TIFFTranslator creates TIFF images
private:
~TIFFTranslatorSettings();
// 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 TIFF_TRANSLATOR_SETTTINGS_H

View File

@ -41,7 +41,7 @@
#include "tiffvers.h"
#include "TIFFTranslator.h"
#include "TIFFTranslatorSettings.h"
#include "TranslatorSettings.h"
#include "TIFFView.h"
@ -74,15 +74,16 @@ add_menu_item(BMenu* menu,
// Returns:
// ---------------------------------------------------------------
TIFFView::TIFFView(const BRect &frame, const char *name,
uint32 resize, uint32 flags, TIFFTranslatorSettings* settings)
: BView(frame, name, resize, flags),
fSettings(settings)
uint32 resize, uint32 flags, TranslatorSettings *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();
uint32 currentCompression = fSettings->SetGetInt32(TIFF_SETTING_COMPRESSION);
// create the menu items with the various compression methods
add_menu_item(menu, COMPRESSION_NONE, "None", currentCompression);
menu->AddSeparatorItem();
@ -137,9 +138,9 @@ TIFFView::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(TIFF_SETTING_COMPRESSION, &value);
fSettings->SaveSettings();
}
break;
@ -203,9 +204,10 @@ TIFFView::Draw(BRect area)
char detail[100];
sprintf(detail, "Version %d.%d.%d %s",
static_cast<int>(TIFF_TRANSLATOR_VERSION >> 8),
static_cast<int>((TIFF_TRANSLATOR_VERSION >> 4) & 0xf),
static_cast<int>(TIFF_TRANSLATOR_VERSION & 0xf), __DATE__);
static_cast<int>(B_TRANSLATION_MAJOR_VER(TIFF_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_MINOR_VER(TIFF_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_REVSN_VER(TIFF_TRANSLATOR_VERSION)),
__DATE__);
DrawString(detail, BPoint(xbold, yplain + ybold));
int32 lineno = 6;

View File

@ -33,14 +33,13 @@
#define TIFFVIEW_H
#include <View.h>
class BMenuField;
class TIFFTranslatorSettings;
#include <MenuField.h>
#include "TranslatorSettings.h"
class TIFFView : public BView {
public:
TIFFView(const BRect &frame, const char *name, uint32 resize,
uint32 flags, TIFFTranslatorSettings* psettings);
uint32 flags, TranslatorSettings *settings);
// sets up the view
~TIFFView();
@ -59,7 +58,7 @@ public:
private:
BMenuField* fCompressionMF;
TIFFTranslatorSettings* fSettings;
TranslatorSettings *fSettings;
// the actual settings for the translator,
// shared with the translator
};

View File

@ -1,69 +0,0 @@
/*****************************************************************************/
// TIFFWindow
// Written by Michael Wilber, OBOS Translation Kit Team
//
// TIFFWindow.cpp
//
// This BWindow based object is used to hold the TIFFView object when the
// user runs the TIFFTranslator 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 "TIFFWindow.h"
// ---------------------------------------------------------------
// Constructor
//
// Sets up the BWindow for holding a TIFFView
//
// Preconditions:
//
// Parameters: area, The bounds of the window
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
TIFFWindow::TIFFWindow(BRect area)
: BWindow(area, "TIFFTranslator", 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:
// ---------------------------------------------------------------
TIFFWindow::~TIFFWindow()
{
be_app->PostMessage(B_QUIT_REQUESTED);
}

View File

@ -1,48 +0,0 @@
/*****************************************************************************/
// TIFFWindow
// Written by Michael Wilber, OBOS Translation Kit Team
//
// TIFFWindow.h
//
// This BWindow based object is used to hold the TIFFView object when the
// user runs the TIFFTranslator 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 TIFFWINDOW_H
#define TIFFWINDOW_H
#include <Application.h>
#include <Window.h>
#include <View.h>
class TIFFWindow : public BWindow {
public:
TIFFWindow(BRect area);
// Sets up a BWindow with bounds area
~TIFFWindow();
// Posts a quit message so that the application closes properly
};
#endif // #define TIFFWINDOW_H