Adding a BIconUtils based HVIFTranslator. It's not very efficient as it does
the full work twice in the worst case. Also since it only supports actual HVIF format and not the Icon-O-Matic one directly it is not as useful as one might think. Still it's a start. You could translate from a HVIF file to a PNG using the command line translate tool with it (translate infile outfile 'PNG '). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30792 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,6 +4,7 @@ SubInclude HAIKU_TOP src add-ons translators bmp ;
|
||||
SubInclude HAIKU_TOP src add-ons translators exr ;
|
||||
SubInclude HAIKU_TOP src add-ons translators gif ;
|
||||
SubInclude HAIKU_TOP src add-ons translators hpgs ;
|
||||
SubInclude HAIKU_TOP src add-ons translators hvif ;
|
||||
SubInclude HAIKU_TOP src add-ons translators ico ;
|
||||
SubInclude HAIKU_TOP src add-ons translators jpeg ;
|
||||
SubInclude HAIKU_TOP src add-ons translators jpeg2000 ;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz, [email protected]
|
||||
*/
|
||||
|
||||
#include <Application.h>
|
||||
#include "HVIFTranslator.h"
|
||||
#include "TranslatorWindow.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
BApplication application("application/x-vnd.haiku.hvif-translator");
|
||||
if (LaunchTranslatorWindow(new HVIFTranslator, "HVIF Settings",
|
||||
BRect(0, 0, 250, 150)) != B_OK)
|
||||
return 1;
|
||||
|
||||
application.Run();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz, [email protected]
|
||||
*/
|
||||
|
||||
#include "HVIFTranslator.h"
|
||||
#include "HVIFView.h"
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <BitmapStream.h>
|
||||
#include <IconUtils.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define HVIF_FORMAT_CODE 'HVIF'
|
||||
#define HVIF_TRANSLATION_QUALITY 1.0
|
||||
#define HVIF_TRANSLATION_CAPABILITY 1.0
|
||||
|
||||
static translation_format sInputFormats[] = {
|
||||
{
|
||||
HVIF_FORMAT_CODE,
|
||||
B_TRANSLATOR_BITMAP,
|
||||
HVIF_TRANSLATION_QUALITY,
|
||||
HVIF_TRANSLATION_CAPABILITY,
|
||||
"application/x-vnd.Haiku-icon",
|
||||
"Native Haiku vector icon"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static translation_format sOutputFormats[] = {
|
||||
{
|
||||
B_TRANSLATOR_BITMAP,
|
||||
B_TRANSLATOR_BITMAP,
|
||||
0.4,
|
||||
0.4,
|
||||
"image/x-be-bitmap",
|
||||
"Be Bitmap Format (HVIFTranslator)"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
BTranslator *
|
||||
make_nth_translator(int32 n, image_id image, uint32 flags, ...)
|
||||
{
|
||||
if (n == 0)
|
||||
return new HVIFTranslator();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
HVIFTranslator::HVIFTranslator()
|
||||
: BaseTranslator("HVIF Icons", "Native Haiku vector icon translator",
|
||||
HVIF_TRANSLATOR_VERSION, sInputFormats,
|
||||
sizeof(sInputFormats) / sizeof(sInputFormats[0]), sOutputFormats,
|
||||
sizeof(sOutputFormats) / sizeof(sOutputFormats[0]),
|
||||
"HVIFTranslator_Settings", NULL, 0, B_TRANSLATOR_BITMAP,
|
||||
HVIF_FORMAT_CODE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HVIFTranslator::~HVIFTranslator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
HVIFTranslator::DerivedIdentify(BPositionIO *inSource,
|
||||
const translation_format *inFormat, BMessage *ioExtension,
|
||||
translator_info *outInfo, uint32 outType)
|
||||
{
|
||||
// TODO: we do the fully work twice!
|
||||
if (outType != B_TRANSLATOR_BITMAP)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
// filter out invalid sizes
|
||||
off_t size = inSource->Seek(0, SEEK_END);
|
||||
if (size <= 0 || size > 256 * 1024 || inSource->Seek(0, SEEK_SET) != 0)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
uint8 *buffer = (uint8 *)malloc(size);
|
||||
if (buffer == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
if (inSource->Read(buffer, size) != size) {
|
||||
free(buffer);
|
||||
return B_NO_TRANSLATOR;
|
||||
}
|
||||
|
||||
BBitmap dummy(BRect(0, 0, 1, 1), B_BITMAP_NO_SERVER_LINK, B_RGBA32);
|
||||
if (BIconUtils::GetVectorIcon(buffer, size, &dummy) != B_OK) {
|
||||
free(buffer);
|
||||
return B_NO_TRANSLATOR;
|
||||
}
|
||||
|
||||
if (outInfo) {
|
||||
outInfo->type = sInputFormats[0].type;
|
||||
outInfo->group = sInputFormats[0].group;
|
||||
outInfo->quality = sInputFormats[0].quality;
|
||||
outInfo->capability = sInputFormats[0].capability;
|
||||
strcpy(outInfo->MIME, sInputFormats[0].MIME);
|
||||
strcpy(outInfo->name, sInputFormats[0].name);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
HVIFTranslator::DerivedTranslate(BPositionIO *inSource,
|
||||
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
|
||||
BPositionIO *outDestination, int32 baseType)
|
||||
{
|
||||
if (outType != B_TRANSLATOR_BITMAP)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
// filter out invalid sizes
|
||||
off_t size = inSource->Seek(0, SEEK_END);
|
||||
if (size <= 0 || size > 256 * 1024 || inSource->Seek(0, SEEK_SET) != 0)
|
||||
return B_NO_TRANSLATOR;
|
||||
|
||||
uint8 *buffer = (uint8 *)malloc(size);
|
||||
if (buffer == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
if (inSource->Read(buffer, size) != size) {
|
||||
free(buffer);
|
||||
return B_NO_TRANSLATOR;
|
||||
}
|
||||
|
||||
BBitmap rendered(BRect(0, 0, 63, 63), B_BITMAP_NO_SERVER_LINK, B_RGBA32);
|
||||
if (BIconUtils::GetVectorIcon(buffer, size, &rendered) != B_OK) {
|
||||
free(buffer);
|
||||
return B_NO_TRANSLATOR;
|
||||
}
|
||||
|
||||
BBitmapStream stream(&rendered);
|
||||
stream.Seek(0, SEEK_SET);
|
||||
ssize_t read = 0;
|
||||
|
||||
while ((read = stream.Read(buffer, size)) > 0)
|
||||
outDestination->Write(buffer, read);
|
||||
|
||||
BBitmap *dummy = NULL;
|
||||
stream.DetachBitmap(&dummy);
|
||||
free(buffer);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
BView *
|
||||
HVIFTranslator::NewConfigView(TranslatorSettings *settings)
|
||||
{
|
||||
return new HVIFView(BRect(0, 0, 250, 150), "HVIFTranslator Settings",
|
||||
B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz, [email protected]
|
||||
*/
|
||||
#ifndef HVIF_TRANSLATOR_H
|
||||
#define HVIF_TRANSLATOR_H
|
||||
|
||||
#include "BaseTranslator.h"
|
||||
|
||||
#define HVIF_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1, 0, 0)
|
||||
|
||||
class HVIFTranslator : public BaseTranslator {
|
||||
public:
|
||||
HVIFTranslator();
|
||||
|
||||
virtual status_t DerivedIdentify(BPositionIO *inSource,
|
||||
const translation_format *inFormat,
|
||||
BMessage *ioExtension, translator_info *outInfo,
|
||||
uint32 outType);
|
||||
|
||||
virtual status_t DerivedTranslate(BPositionIO *inSource,
|
||||
const translator_info *inInfo,
|
||||
BMessage *ioExtension, uint32 outType,
|
||||
BPositionIO *outDestination, int32 baseType);
|
||||
|
||||
virtual BView * NewConfigView(TranslatorSettings *settings);
|
||||
|
||||
protected:
|
||||
virtual ~HVIFTranslator();
|
||||
// this is protected because the object is deleted by the
|
||||
// Release() function instead of being deleted directly by
|
||||
// the user
|
||||
};
|
||||
|
||||
#endif // HVIF_TRANSLATOR_H
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz, [email protected]
|
||||
*/
|
||||
|
||||
#include "HVIFView.h"
|
||||
#include "HVIFTranslator.h"
|
||||
|
||||
#include <StringView.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
HVIFView::HVIFView(const BRect &frame, const char *name, uint32 resizeMode,
|
||||
uint32 flags)
|
||||
: BView(frame, name, resizeMode, flags)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
font_height fontHeight;
|
||||
be_bold_font->GetHeight(&fontHeight);
|
||||
float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
|
||||
|
||||
BRect rect(10, 10, 200, 10 + height);
|
||||
BStringView *stringView = new BStringView(rect, "title",
|
||||
"Native Haiku Icon Format Translator");
|
||||
stringView->SetFont(be_bold_font);
|
||||
stringView->ResizeToPreferred();
|
||||
AddChild(stringView);
|
||||
|
||||
rect.OffsetBy(0, height + 10);
|
||||
char version[256];
|
||||
snprintf(version, sizeof(version), "Version %d.%d.%d, %s",
|
||||
int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)),
|
||||
int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)),
|
||||
int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)),
|
||||
__DATE__);
|
||||
stringView = new BStringView(rect, "version", version);
|
||||
stringView->ResizeToPreferred();
|
||||
AddChild(stringView);
|
||||
|
||||
GetFontHeight(&fontHeight);
|
||||
height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
|
||||
|
||||
rect.OffsetBy(0, height + 5);
|
||||
stringView = new BStringView(rect, "copyright",
|
||||
B_UTF8_COPYRIGHT"2009 Haiku Inc.");
|
||||
stringView->ResizeToPreferred();
|
||||
AddChild(stringView);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz, [email protected]
|
||||
*/
|
||||
#ifndef HVIF_VIEW_H
|
||||
#define HVIF_VIEW_H
|
||||
|
||||
#include <View.h>
|
||||
|
||||
class HVIFView : public BView {
|
||||
public:
|
||||
HVIFView(const BRect &frame, const char *name,
|
||||
uint32 resizeMode, uint32 flags);
|
||||
};
|
||||
|
||||
#endif // HVIF_VIEW_H
|
||||
@@ -0,0 +1,13 @@
|
||||
SubDir HAIKU_TOP src add-ons translators hvif ;
|
||||
|
||||
UseLibraryHeaders icon ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ;
|
||||
|
||||
Translator HVIFTranslator :
|
||||
HVIFMain.cpp
|
||||
HVIFTranslator.cpp
|
||||
HVIFView.cpp
|
||||
: be translation libtranslatorsutils.a
|
||||
: true
|
||||
;
|
||||
Reference in New Issue
Block a user