blob: ab116d1a44102595e4c1bdbc3ad1e747174daea3 [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
Pierre Ossman8ca4c1d2014-09-22 12:54:26 +020023#include "i18n.h"
Pierre Ossmanac13abe2014-02-07 14:46:26 +010024#include "FLTKPixelBuffer.h"
25
26FLTKPixelBuffer::FLTKPixelBuffer(int width, int height) :
27 PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true,
28 255, 255, 255, 0, 8, 16),
Pierre Ossman2e5a1062014-01-30 17:57:27 +010029 width, height, NULL, width)
Pierre Ossmanac13abe2014-02-07 14:46:26 +010030{
31 data = new rdr::U8[width * height * format.bpp/8];
32 if (data == NULL)
Pierre Ossman90347ae2014-11-19 13:47:39 +010033 throw rfb::Exception(_("Not enough memory for framebuffer"));
Pierre Ossmanac13abe2014-02-07 14:46:26 +010034}
35
36FLTKPixelBuffer::~FLTKPixelBuffer()
37{
38 delete [] data;
39}
40
41void FLTKPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h)
42{
43 int pixel_bytes, stride_bytes;
44 const uchar *buf_start;
45
46 pixel_bytes = format.bpp/8;
Pierre Ossman2e5a1062014-01-30 17:57:27 +010047 stride_bytes = pixel_bytes * stride;
Pierre Ossmanac13abe2014-02-07 14:46:26 +010048 buf_start = data +
49 pixel_bytes * src_x +
50 stride_bytes * src_y;
51
52 fl_draw_image(buf_start, x, y, w, h, pixel_bytes, stride_bytes);
53}