Pierre Ossman | ac13abe | 2014-02-07 14:46:26 +0100 | [diff] [blame] | 1 | /* 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 Ossman | 8ca4c1d | 2014-09-22 12:54:26 +0200 | [diff] [blame] | 23 | #include "i18n.h" |
Pierre Ossman | ac13abe | 2014-02-07 14:46:26 +0100 | [diff] [blame] | 24 | #include "FLTKPixelBuffer.h" |
| 25 | |
| 26 | FLTKPixelBuffer::FLTKPixelBuffer(int width, int height) : |
| 27 | PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true, |
| 28 | 255, 255, 255, 0, 8, 16), |
Pierre Ossman | 2e5a106 | 2014-01-30 17:57:27 +0100 | [diff] [blame] | 29 | width, height, NULL, width) |
Pierre Ossman | ac13abe | 2014-02-07 14:46:26 +0100 | [diff] [blame] | 30 | { |
| 31 | data = new rdr::U8[width * height * format.bpp/8]; |
| 32 | if (data == NULL) |
Pierre Ossman | 8ca4c1d | 2014-09-22 12:54:26 +0200 | [diff] [blame] | 33 | throw rfb::Exception(_("Error: Not enough memory for framebuffer")); |
Pierre Ossman | ac13abe | 2014-02-07 14:46:26 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | FLTKPixelBuffer::~FLTKPixelBuffer() |
| 37 | { |
| 38 | delete [] data; |
| 39 | } |
| 40 | |
| 41 | void 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 Ossman | 2e5a106 | 2014-01-30 17:57:27 +0100 | [diff] [blame] | 47 | stride_bytes = pixel_bytes * stride; |
Pierre Ossman | ac13abe | 2014-02-07 14:46:26 +0100 | [diff] [blame] | 48 | 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 | } |