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 // We assume the data is 1:1 the format of the bitmap
83 bb
->ImportBits(data
, length
, bb
->BytesPerRow(), 0, bb
->ColorSpace());
88 import_bitmap_bits(const Bitmap
* bitmap
, void* data
, int32 length
,
89 unsigned srcStride
, color_space srcColorSpace
)
91 BBitmap
*bb
= (BBitmap
*)bitmap
;
93 // Import image and adjust image format from source to dest
95 bb
->ImportBits(data
, length
, srcStride
, 0, srcColorSpace
);
100 delete_bitmap(Bitmap
* bitmap
)
102 BBitmap
*bb
= (BBitmap
*)bitmap
;
108 get_bitmap_bytes_per_row(const Bitmap
* bitmap
)
110 BBitmap
*bb
= (BBitmap
*)bitmap
;
112 return bb
->BytesPerRow();
118 get_bitmap_bits_length(const Bitmap
* bitmap
)
120 BBitmap
*bb
= (BBitmap
*)bitmap
;
122 return bb
->BitsLength();
128 dump_bitmap(const Bitmap
* bitmap
)
130 BBitmap
*bb
= (BBitmap
*)bitmap
;
134 BString
filename("/boot/home/frame_");
135 filename
<< (int32
)frameNo
<< ".png";
137 BTranslatorRoster
*roster
= BTranslatorRoster::Default();
138 BBitmapStream
stream(bb
);
139 BFile
dump(filename
, B_CREATE_FILE
| B_WRITE_ONLY
);
141 roster
->Translate(&stream
, NULL
, NULL
, &dump
, 0);