Path: blob/21.2-virgl/src/gallium/frontends/hgl/bitmap_wrapper.cpp
4561 views
/**************************************************************************1*2* Copyright 2009 Artur Wyszynski <[email protected]>3* Copyright 2013 Alexander von Gluck IV <[email protected]>4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25**************************************************************************/262728#include <stdio.h>29#include <interface/Bitmap.h>30#include <storage/File.h>31#include <support/String.h>32#include <translation/BitmapStream.h>33#include <translation/TranslatorRoster.h>3435#include "bitmap_wrapper.h"363738extern "C" {39static int frameNo = 0;404142Bitmap*43create_bitmap(int32 width, int32 height, color_space colorSpace)44{45BBitmap *bb = new BBitmap(BRect(0, 0, width, height), colorSpace);46if (bb)47return (Bitmap*)bb;48return NULL;49}505152void53get_bitmap_size(const Bitmap* bitmap, int32* width, int32* height)54{55BBitmap *bb = (BBitmap*)bitmap;56if (bb && width && height) {57uint32 w = bb->Bounds().IntegerWidth() + 1;58uint32 h = bb->Bounds().IntegerHeight() + 1;59*width = w;60*height = h;61}62}636465color_space66get_bitmap_color_space(const Bitmap* bitmap)67{68BBitmap *bb = (BBitmap*)bitmap;69if (bb)70return bb->ColorSpace();71return B_NO_COLOR_SPACE;72}737475void76copy_bitmap_bits(const Bitmap* bitmap, void* data, int32 length)77{78BBitmap *bb = (BBitmap*)bitmap;7980// We assume the data is 1:1 the format of the bitmap81if (bb)82bb->ImportBits(data, length, bb->BytesPerRow(), 0, bb->ColorSpace());83}848586void87import_bitmap_bits(const Bitmap* bitmap, void* data, int32 length,88unsigned srcStride, color_space srcColorSpace)89{90BBitmap *bb = (BBitmap*)bitmap;9192// Import image and adjust image format from source to dest93if (bb)94bb->ImportBits(data, length, srcStride, 0, srcColorSpace);95}969798void99delete_bitmap(Bitmap* bitmap)100{101BBitmap *bb = (BBitmap*)bitmap;102delete bb;103}104105106int32107get_bitmap_bytes_per_row(const Bitmap* bitmap)108{109BBitmap *bb = (BBitmap*)bitmap;110if (bb)111return bb->BytesPerRow();112return 0;113}114115116int32117get_bitmap_bits_length(const Bitmap* bitmap)118{119BBitmap *bb = (BBitmap*)bitmap;120if (bb)121return bb->BitsLength();122return 0;123}124125126void127dump_bitmap(const Bitmap* bitmap)128{129BBitmap *bb = (BBitmap*)bitmap;130if (!bb)131return;132133BString filename("/boot/home/frame_");134filename << (int32)frameNo << ".png";135136BTranslatorRoster *roster = BTranslatorRoster::Default();137BBitmapStream stream(bb);138BFile dump(filename, B_CREATE_FILE | B_WRITE_ONLY);139140roster->Translate(&stream, NULL, NULL, &dump, 0);141142frameNo++;143}144145}146147148