blob: 91ff787ec0c0579b4e81341230844473aca15ad0 [file] [log] [blame]
Pierre Ossmanac13abe2014-02-07 14:46:26 +01001/* Copyright 2011-2014 Pierre Ossman for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <FL/fl_draw.H>
20
21#include <rfb/Exception.h>
22
23#include "FLTKPixelBuffer.h"
24
25FLTKPixelBuffer::FLTKPixelBuffer(int width, int height) :
26 PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true,
27 255, 255, 255, 0, 8, 16),
28 width, height, NULL)
29{
30 data = new rdr::U8[width * height * format.bpp/8];
31 if (data == NULL)
32 throw rfb::Exception("Error: Not enough memory for framebuffer");
33}
34
35FLTKPixelBuffer::~FLTKPixelBuffer()
36{
37 delete [] data;
38}
39
40void FLTKPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h)
41{
42 int pixel_bytes, stride_bytes;
43 const uchar *buf_start;
44
45 pixel_bytes = format.bpp/8;
46 stride_bytes = pixel_bytes * getStride();
47 buf_start = data +
48 pixel_bytes * src_x +
49 stride_bytes * src_y;
50
51 fl_draw_image(buf_start, x, y, w, h, pixel_bytes, stride_bytes);
52}