Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2009 Artur Wyszynski <harakash@gmail.com>
  4.  * Copyright 2013 Alexander von Gluck IV <kallisti5@unixzen.com>
  5.  *
  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:
  13.  *
  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.
  21.  *
  22.  * The above copyright notice and this permission notice (including the
  23.  * next paragraph) shall be included in all copies or substantial portions
  24.  * of the Software.
  25.  *
  26.  **************************************************************************/
  27.  
  28.  
  29. #include <stdio.h>
  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>
  35.  
  36. #include "bitmap_wrapper.h"
  37.  
  38.  
  39. extern "C" {
  40. static int frameNo = 0;
  41.  
  42.  
  43. Bitmap*
  44. create_bitmap(int32 width, int32 height, color_space colorSpace)
  45. {
  46.         BBitmap *bb = new BBitmap(BRect(0, 0, width, height), colorSpace);
  47.         if (bb)
  48.                 return (Bitmap*)bb;
  49.         return NULL;
  50. }
  51.  
  52.  
  53. void
  54. get_bitmap_size(const Bitmap* bitmap, int32* width, int32* height)
  55. {
  56.         BBitmap *bb = (BBitmap*)bitmap;
  57.         if (bb && width && height) {
  58.                 uint32 w = bb->Bounds().IntegerWidth() + 1;
  59.                 uint32 h = bb->Bounds().IntegerHeight() + 1;
  60.                 *width = w;
  61.                 *height = h;
  62.         }
  63. }
  64.  
  65.  
  66. color_space
  67. get_bitmap_color_space(const Bitmap* bitmap)
  68. {
  69.         BBitmap *bb = (BBitmap*)bitmap;
  70.         if (bb)
  71.                 return bb->ColorSpace();
  72.         return B_NO_COLOR_SPACE;
  73. }
  74.  
  75.  
  76. void
  77. copy_bitmap_bits(const Bitmap* bitmap, void* data, int32 length)
  78. {
  79.         BBitmap *bb = (BBitmap*)bitmap;
  80.         if (bb) {
  81.                 color_space cs = bb->ColorSpace();
  82.                 bb->ImportBits(data, length, bb->BytesPerRow(), 0, cs);
  83.         }
  84. }
  85.  
  86.  
  87. void
  88. delete_bitmap(Bitmap* bitmap)
  89. {
  90.         BBitmap *bb = (BBitmap*)bitmap;
  91.         delete bb;
  92. }
  93.  
  94.  
  95. int32
  96. get_bitmap_bytes_per_row(const Bitmap* bitmap)
  97. {
  98.         BBitmap *bb = (BBitmap*)bitmap;
  99.         if (bb)
  100.                 return bb->BytesPerRow();
  101.         return 0;
  102. }
  103.  
  104.  
  105. int32
  106. get_bitmap_bits_length(const Bitmap* bitmap)
  107. {
  108.         BBitmap *bb = (BBitmap*)bitmap;
  109.         if (bb)
  110.                 return bb->BitsLength();
  111.         return 0;
  112. }
  113.  
  114.  
  115. void
  116. dump_bitmap(const Bitmap* bitmap)
  117. {
  118.         BBitmap *bb = (BBitmap*)bitmap;
  119.         if (!bb)
  120.                 return;
  121.  
  122.         BString filename("/boot/home/frame_");
  123.         filename << (int32)frameNo << ".png";
  124.  
  125.         BTranslatorRoster *roster = BTranslatorRoster::Default();
  126.         BBitmapStream stream(bb);
  127.         BFile dump(filename, B_CREATE_FILE | B_WRITE_ONLY);
  128.  
  129.         roster->Translate(&stream, NULL, NULL, &dump, 0);
  130.  
  131.         frameNo++;
  132. }
  133.  
  134. }
  135.