libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / icon-o-matic / import_export / bitmap / BitmapExporter.cpp
blobfc0f9a2aaf76db735ea5e00e8897e3f5fc67e1e2
1 /*
2 * Copyright 2006, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "BitmapExporter.h"
11 #include <Bitmap.h>
12 #include <BitmapStream.h>
13 #include <TranslatorFormats.h>
14 #include <TranslatorRoster.h>
16 #include "Icon.h"
17 #include "IconRenderer.h"
19 // constructor
20 BitmapExporter::BitmapExporter(uint32 size)
21 : Exporter(),
22 fFormat(B_PNG_FORMAT),
23 fSize(size)
27 // destructor
28 BitmapExporter::~BitmapExporter()
32 // Export
33 status_t
34 BitmapExporter::Export(const Icon* icon, BPositionIO* stream)
36 if (fSize == 0)
37 return B_NO_INIT;
39 // render icon into bitmap with given size and transparent background
40 uint32 bitmapFlags = 0;
42 #if __HAIKU__
43 bitmapFlags |= B_BITMAP_NO_SERVER_LINK;
44 #endif
46 BBitmap bitmap(BRect(0, 0, fSize - 1, fSize - 1),
47 bitmapFlags, B_RGBA32);
49 status_t ret = bitmap.InitCheck();
50 if (ret < B_OK)
51 return ret;
53 IconRenderer renderer(&bitmap);
54 renderer.SetIcon(icon);
55 renderer.SetScale(fSize / 64.0);
56 renderer.Render();
57 // renderer.Demultiply(&bitmap);
59 // save bitmap to translator
60 BTranslatorRoster* roster = BTranslatorRoster::Default();
61 if (!roster)
62 return B_ERROR;
64 BBitmapStream bitmapStream(&bitmap);
65 ret = roster->Translate(&bitmapStream, NULL, NULL, stream, fFormat, 0);
67 BBitmap* dummy;
68 bitmapStream.DetachBitmap(&dummy);
70 return ret;
73 // MIMEType
74 const char*
75 BitmapExporter::MIMEType()
77 // TODO: ...
78 return "image/png";