1 /**************************************************************************
3 * Copyright 2009 Artur Wyszynski <harakash@gmail.com>
4 * Copyright 2013 Alexander von Gluck IV <kallisti5@unixzen.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 **************************************************************************/
30 #include <interface/Bitmap.h>
31 #include <storage/File.h>
32 #include <support/String.h>
33 #include <translation/BitmapStream.h>
34 #include <translation/TranslatorRoster.h>
36 #include "bitmap_wrapper.h"
40 static int frameNo = 0;
44 create_bitmap(int32 width, int32 height, color_space colorSpace)
46 BBitmap *bb = new BBitmap(BRect(0, 0, width, height), colorSpace);
54 get_bitmap_size(const Bitmap* bitmap, int32* width, int32* height)
56 BBitmap *bb = (BBitmap*)bitmap;
57 if (bb && width && height) {
58 uint32 w = bb->Bounds().IntegerWidth() + 1;
59 uint32 h = bb->Bounds().IntegerHeight() + 1;
67 get_bitmap_color_space(const Bitmap* bitmap)
69 BBitmap *bb = (BBitmap*)bitmap;
71 return bb->ColorSpace();
72 return B_NO_COLOR_SPACE;
77 copy_bitmap_bits(const Bitmap* bitmap, void* data, int32 length)
79 BBitmap *bb = (BBitmap*)bitmap;
81 color_space cs = bb->ColorSpace();
82 bb->ImportBits(data, length, bb->BytesPerRow(), 0, cs);
88 delete_bitmap(Bitmap* bitmap)
90 BBitmap *bb = (BBitmap*)bitmap;
96 get_bitmap_bytes_per_row(const Bitmap* bitmap)
98 BBitmap *bb = (BBitmap*)bitmap;
100 return bb->BytesPerRow();
106 get_bitmap_bits_length(const Bitmap* bitmap)
108 BBitmap *bb = (BBitmap*)bitmap;
110 return bb->BitsLength();
116 dump_bitmap(const Bitmap* bitmap)
118 BBitmap *bb = (BBitmap*)bitmap;
122 BString filename("/boot/home/frame_");
123 filename << (int32)frameNo << ".png";
125 BTranslatorRoster *roster = BTranslatorRoster::Default();
126 BBitmapStream stream(bb);
127 BFile dump(filename, B_CREATE_FILE | B_WRITE_ONLY);
129 roster->Translate(&stream, NULL, NULL, &dump, 0);