17ec681f3Smrg/************************************************************************** 27ec681f3Smrg * 37ec681f3Smrg * Copyright 2009 Artur Wyszynski <harakash@gmail.com> 47ec681f3Smrg * Copyright 2013 Alexander von Gluck IV <kallisti5@unixzen.com> 57ec681f3Smrg * 67ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 77ec681f3Smrg * copy of this software and associated documentation files (the 87ec681f3Smrg * "Software"), to deal in the Software without restriction, including 97ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish, 107ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to 117ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to 127ec681f3Smrg * the following conditions: 137ec681f3Smrg * 147ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 167ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 177ec681f3Smrg * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 187ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 197ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 207ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 217ec681f3Smrg * 227ec681f3Smrg * The above copyright notice and this permission notice (including the 237ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions 247ec681f3Smrg * of the Software. 257ec681f3Smrg * 267ec681f3Smrg **************************************************************************/ 277ec681f3Smrg 287ec681f3Smrg 297ec681f3Smrg#include <stdio.h> 307ec681f3Smrg#include <interface/Bitmap.h> 317ec681f3Smrg#include <storage/File.h> 327ec681f3Smrg#include <support/String.h> 337ec681f3Smrg#include <translation/BitmapStream.h> 347ec681f3Smrg#include <translation/TranslatorRoster.h> 357ec681f3Smrg 367ec681f3Smrg#include "bitmap_wrapper.h" 377ec681f3Smrg 387ec681f3Smrg 397ec681f3Smrgextern "C" { 407ec681f3Smrgstatic int frameNo = 0; 417ec681f3Smrg 427ec681f3Smrg 437ec681f3SmrgBitmap* 447ec681f3Smrgcreate_bitmap(int32 width, int32 height, color_space colorSpace) 457ec681f3Smrg{ 467ec681f3Smrg BBitmap *bb = new BBitmap(BRect(0, 0, width, height), colorSpace); 477ec681f3Smrg if (bb) 487ec681f3Smrg return (Bitmap*)bb; 497ec681f3Smrg return NULL; 507ec681f3Smrg} 517ec681f3Smrg 527ec681f3Smrg 537ec681f3Smrgvoid 547ec681f3Smrgget_bitmap_size(const Bitmap* bitmap, int32* width, int32* height) 557ec681f3Smrg{ 567ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 577ec681f3Smrg if (bb && width && height) { 587ec681f3Smrg uint32 w = bb->Bounds().IntegerWidth() + 1; 597ec681f3Smrg uint32 h = bb->Bounds().IntegerHeight() + 1; 607ec681f3Smrg *width = w; 617ec681f3Smrg *height = h; 627ec681f3Smrg } 637ec681f3Smrg} 647ec681f3Smrg 657ec681f3Smrg 667ec681f3Smrgcolor_space 677ec681f3Smrgget_bitmap_color_space(const Bitmap* bitmap) 687ec681f3Smrg{ 697ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 707ec681f3Smrg if (bb) 717ec681f3Smrg return bb->ColorSpace(); 727ec681f3Smrg return B_NO_COLOR_SPACE; 737ec681f3Smrg} 747ec681f3Smrg 757ec681f3Smrg 767ec681f3Smrgvoid 777ec681f3Smrgcopy_bitmap_bits(const Bitmap* bitmap, void* data, int32 length) 787ec681f3Smrg{ 797ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 807ec681f3Smrg 817ec681f3Smrg // We assume the data is 1:1 the format of the bitmap 827ec681f3Smrg if (bb) 837ec681f3Smrg bb->ImportBits(data, length, bb->BytesPerRow(), 0, bb->ColorSpace()); 847ec681f3Smrg} 857ec681f3Smrg 867ec681f3Smrg 877ec681f3Smrgvoid 887ec681f3Smrgimport_bitmap_bits(const Bitmap* bitmap, void* data, int32 length, 897ec681f3Smrg unsigned srcStride, color_space srcColorSpace) 907ec681f3Smrg{ 917ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 927ec681f3Smrg 937ec681f3Smrg // Import image and adjust image format from source to dest 947ec681f3Smrg if (bb) 957ec681f3Smrg bb->ImportBits(data, length, srcStride, 0, srcColorSpace); 967ec681f3Smrg} 977ec681f3Smrg 987ec681f3Smrg 997ec681f3Smrgvoid 1007ec681f3Smrgdelete_bitmap(Bitmap* bitmap) 1017ec681f3Smrg{ 1027ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 1037ec681f3Smrg delete bb; 1047ec681f3Smrg} 1057ec681f3Smrg 1067ec681f3Smrg 1077ec681f3Smrgint32 1087ec681f3Smrgget_bitmap_bytes_per_row(const Bitmap* bitmap) 1097ec681f3Smrg{ 1107ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 1117ec681f3Smrg if (bb) 1127ec681f3Smrg return bb->BytesPerRow(); 1137ec681f3Smrg return 0; 1147ec681f3Smrg} 1157ec681f3Smrg 1167ec681f3Smrg 1177ec681f3Smrgint32 1187ec681f3Smrgget_bitmap_bits_length(const Bitmap* bitmap) 1197ec681f3Smrg{ 1207ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 1217ec681f3Smrg if (bb) 1227ec681f3Smrg return bb->BitsLength(); 1237ec681f3Smrg return 0; 1247ec681f3Smrg} 1257ec681f3Smrg 1267ec681f3Smrg 1277ec681f3Smrgvoid 1287ec681f3Smrgdump_bitmap(const Bitmap* bitmap) 1297ec681f3Smrg{ 1307ec681f3Smrg BBitmap *bb = (BBitmap*)bitmap; 1317ec681f3Smrg if (!bb) 1327ec681f3Smrg return; 1337ec681f3Smrg 1347ec681f3Smrg BString filename("/boot/home/frame_"); 1357ec681f3Smrg filename << (int32)frameNo << ".png"; 1367ec681f3Smrg 1377ec681f3Smrg BTranslatorRoster *roster = BTranslatorRoster::Default(); 1387ec681f3Smrg BBitmapStream stream(bb); 1397ec681f3Smrg BFile dump(filename, B_CREATE_FILE | B_WRITE_ONLY); 1407ec681f3Smrg 1417ec681f3Smrg roster->Translate(&stream, NULL, NULL, &dump, 0); 1427ec681f3Smrg 1437ec681f3Smrg frameNo++; 1447ec681f3Smrg} 1457ec681f3Smrg 1467ec681f3Smrg} 147