* Switch to B_RGB24 output format

* Renamed everything after WebP, as it turns out the official name is
  case-sensitive.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39505 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2010-11-19 13:10:16 +00:00
parent 399227b7b5
commit e4f8681e79
6 changed files with 32 additions and 47 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
#include "ConfigView.h" #include "ConfigView.h"
#include "WEBPTranslator.h" #include "WebPTranslator.h"
#include <StringView.h> #include <StringView.h>
#include <CheckBox.h> #include <CheckBox.h>
+2 -2
View File
@@ -6,11 +6,11 @@ SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) shared ] ;
SubDirHdrs [ FDirName $(SUBDIR) webp ] ; SubDirHdrs [ FDirName $(SUBDIR) webp ] ;
Translator WEBPTranslator : Translator WebPTranslator :
main.cpp main.cpp
WEBPTranslator.cpp WebPTranslator.cpp
ConfigView.cpp ConfigView.cpp
bits.c bits.c
@@ -7,7 +7,7 @@
*/ */
#include "WEBPTranslator.h" #include "WebPTranslator.h"
#include "ConfigView.h" #include "ConfigView.h"
#include "decode.h" #include "decode.h"
@@ -48,7 +48,7 @@ translation_format sInputFormats[] = {
WEBP_IN_QUALITY, WEBP_IN_QUALITY,
WEBP_IN_CAPABILITY, WEBP_IN_CAPABILITY,
"image/webp", "image/webp",
"WEBP image" "WebP image"
}, },
}; };
@@ -60,7 +60,7 @@ translation_format sOutputFormats[] = {
BITS_OUT_QUALITY, BITS_OUT_QUALITY,
BITS_OUT_CAPABILITY, BITS_OUT_CAPABILITY,
"image/x-be-bitmap", "image/x-be-bitmap",
"Be Bitmap Format (WEBPTranslator)" "Be Bitmap Format (WebPTranslator)"
}, },
}; };
@@ -78,25 +78,25 @@ const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting
// #pragma mark - // #pragma mark -
WEBPTranslator::WEBPTranslator() WebPTranslator::WebPTranslator()
: BaseTranslator("WEBP images", "WEBP image translator", : BaseTranslator("WebP images", "WebP image translator",
WEBP_TRANSLATOR_VERSION, WEBP_TRANSLATOR_VERSION,
sInputFormats, kNumInputFormats, sInputFormats, kNumInputFormats,
sOutputFormats, kNumOutputFormats, sOutputFormats, kNumOutputFormats,
"WEBPTranslator_Settings", "WebPTranslator_Settings",
sDefaultSettings, kNumDefaultSettings, sDefaultSettings, kNumDefaultSettings,
B_TRANSLATOR_BITMAP, WEBP_IMAGE_FORMAT) B_TRANSLATOR_BITMAP, WEBP_IMAGE_FORMAT)
{ {
} }
WEBPTranslator::~WEBPTranslator() WebPTranslator::~WebPTranslator()
{ {
} }
status_t status_t
WEBPTranslator::DerivedIdentify(BPositionIO *stream, WebPTranslator::DerivedIdentify(BPositionIO *stream,
const translation_format *format, BMessage *settings, const translation_format *format, BMessage *settings,
translator_info *info, uint32 outType) translator_info *info, uint32 outType)
{ {
@@ -121,7 +121,7 @@ WEBPTranslator::DerivedIdentify(BPositionIO *stream,
info->group = B_TRANSLATOR_BITMAP; info->group = B_TRANSLATOR_BITMAP;
info->quality = WEBP_IN_QUALITY; info->quality = WEBP_IN_QUALITY;
info->capability = WEBP_IN_CAPABILITY; info->capability = WEBP_IN_CAPABILITY;
snprintf(info->name, sizeof(info->name), "WEBP image"); snprintf(info->name, sizeof(info->name), "WebP image");
strcpy(info->MIME, "image/webp"); strcpy(info->MIME, "image/webp");
return B_OK; return B_OK;
@@ -129,7 +129,7 @@ WEBPTranslator::DerivedIdentify(BPositionIO *stream,
status_t status_t
WEBPTranslator::DerivedTranslate(BPositionIO *stream, WebPTranslator::DerivedTranslate(BPositionIO *stream,
const translator_info *info, BMessage *settings, const translator_info *info, BMessage *settings,
uint32 outType, BPositionIO *target, int32 baseType) uint32 outType, BPositionIO *target, int32 baseType)
{ {
@@ -162,7 +162,7 @@ WEBPTranslator::DerivedTranslate(BPositionIO *stream,
printf("WebPDecodeRGB(%p, %lld) failed.\n", streamData, streamSize); printf("WebPDecodeRGB(%p, %lld) failed.\n", streamData, streamSize);
return B_ILLEGAL_DATA; return B_ILLEGAL_DATA;
} }
printf("WebPDecodeRGB(%p, %lld) succeed: %d x %d WEBP image decoded.\n", printf("WebPDecodeRGB(%p, %lld) succeed: %d x %d WebP image decoded.\n",
streamData, streamSize, width, height); streamData, streamSize, width, height);
FreeAllocation _(out); FreeAllocation _(out);
@@ -172,9 +172,9 @@ WEBPTranslator::DerivedTranslate(BPositionIO *stream,
TranslatorBitmap bitmapHeader; TranslatorBitmap bitmapHeader;
bitmapHeader.magic = B_TRANSLATOR_BITMAP; bitmapHeader.magic = B_TRANSLATOR_BITMAP;
bitmapHeader.bounds.Set(0, 0, width - 1, height - 1); bitmapHeader.bounds.Set(0, 0, width - 1, height - 1);
bitmapHeader.rowBytes = width * 4; bitmapHeader.rowBytes = width * 3;
bitmapHeader.colors = B_RGB32; bitmapHeader.colors = B_RGB24;
bitmapHeader.dataSize = width * 4 * height; bitmapHeader.dataSize = width * 3 * height;
// write out Be's Bitmap header // write out Be's Bitmap header
swap_data(B_UINT32_TYPE, &bitmapHeader, sizeof(TranslatorBitmap), swap_data(B_UINT32_TYPE, &bitmapHeader, sizeof(TranslatorBitmap),
@@ -192,28 +192,19 @@ WEBPTranslator::DerivedTranslate(BPositionIO *stream,
if (headerOnly) if (headerOnly)
return B_OK; return B_OK;
/*
bytesWritten = target->Write(out, dataSize);
if (bytesWritten < B_OK)
return bytesWritten;
if (bytesWritten != (ssize_t)dataSize)
return B_IO_ERROR;
*/
uint32 dataLeft = dataSize; uint32 dataLeft = dataSize;
uint8* p = out; uint8* p = out;
uint8 rgb[4] = { 0, 0, 0, 255}; uint8 rgb[3];
while (dataLeft) { while (dataLeft) {
rgb[0] = *(p+2); rgb[0] = *(p+2);
rgb[1] = *(p+1); rgb[1] = *(p+1);
rgb[2] = *(p); rgb[2] = *(p);
bytesWritten = target->Write(rgb, 4); bytesWritten = target->Write(rgb, 3);
if (bytesWritten < B_OK) if (bytesWritten < B_OK)
return bytesWritten; return bytesWritten;
if (bytesWritten != 4) if (bytesWritten != 3)
return B_IO_ERROR; return B_IO_ERROR;
p += 3; p += 3;
@@ -226,7 +217,7 @@ WEBPTranslator::DerivedTranslate(BPositionIO *stream,
BView * BView *
WEBPTranslator::NewConfigView(TranslatorSettings *settings) WebPTranslator::NewConfigView(TranslatorSettings *settings)
{ {
return new ConfigView(); return new ConfigView();
} }
@@ -241,5 +232,5 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
if (n != 0) if (n != 0)
return NULL; return NULL;
return new WEBPTranslator(); return new WebPTranslator();
} }
@@ -21,7 +21,7 @@
#include "BaseTranslator.h" #include "BaseTranslator.h"
#define WEBP_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0,1,0) #define WEBP_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0,1,0)
#define WEBP_IMAGE_FORMAT 'WEBP' #define WEBP_IMAGE_FORMAT 'WebP'
#define WEBP_IN_QUALITY 0.90 #define WEBP_IN_QUALITY 0.90
#define WEBP_IN_CAPABILITY 0.90 #define WEBP_IN_CAPABILITY 0.90
@@ -29,9 +29,9 @@
#define BITS_OUT_QUALITY 1 #define BITS_OUT_QUALITY 1
#define BITS_OUT_CAPABILITY 0.9 #define BITS_OUT_CAPABILITY 0.9
class WEBPTranslator : public BaseTranslator { class WebPTranslator : public BaseTranslator {
public: public:
WEBPTranslator(); WebPTranslator();
virtual status_t DerivedIdentify(BPositionIO *inSource, virtual status_t DerivedIdentify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension, const translation_format *inFormat, BMessage *ioExtension,
@@ -44,17 +44,10 @@ public:
virtual BView *NewConfigView(TranslatorSettings *settings); virtual BView *NewConfigView(TranslatorSettings *settings);
protected: protected:
virtual ~WEBPTranslator(); virtual ~WebPTranslator();
// this is protected because the object is deleted by the // this is protected because the object is deleted by the
// Release() function instead of being deleted directly by // Release() function instead of being deleted directly by
// the user // the user
private:
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 WEBP_TRANSLATOR_H #endif // #ifndef WEBP_TRANSLATOR_H
+5 -4
View File
@@ -8,15 +8,16 @@
#include <Application.h> #include <Application.h>
#include "WEBPTranslator.h"
#include "WebPTranslator.h"
#include "TranslatorWindow.h" #include "TranslatorWindow.h"
int int
main() main()
{ {
BApplication app("application/x-vnd.Haiku-WEBPTranslator"); BApplication app("application/x-vnd.Haiku-WebPTranslator");
if (LaunchTranslatorWindow(new WEBPTranslator, if (LaunchTranslatorWindow(new WebPTranslator,
"WEBP Settings") != B_OK) "WebP Settings") != B_OK)
return 1; return 1;
app.Run(); app.Run();
+1 -1
View File
@@ -5,7 +5,7 @@ resource(1, "META:TYPE") "image/webp";
resource(2, "META:SNIFF_RULE") "0.50 (\"RIFF????WEBP\" & 0xffffffff00000000ffffffff)"; resource(2, "META:SNIFF_RULE") "0.50 (\"RIFF????WEBP\" & 0xffffffff00000000ffffffff)";
resource(3, "META:S:DESC") #'MSDC' "WEBP image"; resource(3, "META:S:DESC") #'MSDC' "WebP image";
resource(4, "META:EXTENS") message(234) { resource(4, "META:EXTENS") message(234) {
"extensions" = "webp", "extensions" = "webp",