1 /* 2 * Copyright 2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "BitmapExporter.h" 10 11 #include <Bitmap.h> 12 #include <BitmapStream.h> 13 #include <TranslatorFormats.h> 14 #include <TranslatorRoster.h> 15 16 #include "Icon.h" 17 #include "IconRenderer.h" 18 19 // constructor 20 BitmapExporter::BitmapExporter(uint32 size) 21 : Exporter(), 22 fFormat(B_PNG_FORMAT), 23 fSize(size) 24 { 25 } 26 27 // destructor 28 BitmapExporter::~BitmapExporter() 29 { 30 } 31 32 // Export 33 status_t 34 BitmapExporter::Export(const Icon* icon, BPositionIO* stream) 35 { 36 if (fSize == 0) 37 return B_NO_INIT; 38 39 // render icon into bitmap with given size and transparent background 40 uint32 bitmapFlags = 0; 41 42 #if __HAIKU__ 43 bitmapFlags |= B_BITMAP_NO_SERVER_LINK; 44 #endif 45 46 BBitmap bitmap(BRect(0, 0, fSize - 1, fSize - 1), 47 bitmapFlags, B_RGBA32); 48 49 status_t ret = bitmap.InitCheck(); 50 if (ret < B_OK) 51 return ret; 52 53 IconRenderer renderer(&bitmap); 54 renderer.SetIcon(icon); 55 renderer.SetScale(fSize / 64.0); 56 renderer.Render(); 57 // renderer.Demultiply(&bitmap); 58 59 // save bitmap to translator 60 BTranslatorRoster* roster = BTranslatorRoster::Default(); 61 if (!roster) 62 return B_ERROR; 63 64 BBitmapStream bitmapStream(&bitmap); 65 ret = roster->Translate(&bitmapStream, NULL, NULL, stream, fFormat, 0); 66 67 BBitmap* dummy; 68 bitmapStream.DetachBitmap(&dummy); 69 70 return ret; 71 } 72 73 // MIMEType 74 const char* 75 BitmapExporter::MIMEType() 76 { 77 // TODO: ... 78 return "image/png"; 79 } 80 81