From e4b3c2c9f7a9b40d091ce6e012e4b891569b952b Mon Sep 17 00:00:00 2001 From: george82 Date: Tue, 5 Sep 2006 06:43:28 +0000 Subject: [PATCH] Added the ScaledDIBSectionBuffer::recreateBuffers method. ScaledDIBSectionBuffer class code improvements. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@644 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- win/rfb_win32/ScaledDIBSectionBuffer.cxx | 72 ++++++++++++++---------- win/rfb_win32/ScaledDIBSectionBuffer.h | 1 + 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/win/rfb_win32/ScaledDIBSectionBuffer.cxx b/win/rfb_win32/ScaledDIBSectionBuffer.cxx index df3a6c93..e0091877 100644 --- a/win/rfb_win32/ScaledDIBSectionBuffer.cxx +++ b/win/rfb_win32/ScaledDIBSectionBuffer.cxx @@ -40,38 +40,24 @@ ScaledDIBSectionBuffer::~ScaledDIBSectionBuffer() { void ScaledDIBSectionBuffer::setScaleRatio(double scale_ratio_) { if (scale_ratio == scale_ratio_) return; - if (format.depth != 24) throw rfb::UnsupportedPixelFormatException(); + if (format.depth != 24 && format.depth != 0) throw rfb::UnsupportedPixelFormatException(); - if (scale_ratio_ != 1) { - scaling = true; - if (!src_buffer) { - src_buffer = new ManagedPixelBuffer(format, src_width, src_height); - src_data = &(src_buffer->data); - memcpy(src_buffer->data, data, area() * (getPF().bpp/8)); - } - } else { - scaling = false; - } + if (scale_ratio_ != 1) scaling = true; + else scaling = false; ScaledPixelBuffer::setScaleRatio(scale_ratio_); - recreateScaledBuffer(); - if (scaling) { - scaleRect(Rect(0, 0, src_width, src_height)); - } else { - memcpy(data, src_buffer->data, src_buffer->area() * (src_buffer->getPF().bpp/8)); - if (src_buffer) { - delete src_buffer; - src_buffer = 0; - src_data = 0; - } - } + recreateBuffers(); } void ScaledDIBSectionBuffer::setPF(const PixelFormat &pf_) { - if (memcmp(&getPF(), &pf_, sizeof(pf_)) == 0) return; + if (memcmp(&(ScaledPixelBuffer::pf), &pf_, sizeof(pf_)) == 0) return; + ScaledPixelBuffer::pf = pf_; if (scaling) { - ScaledPixelBuffer::setPF(pf_); - src_buffer->setPF(pf_); + if (src_buffer) src_buffer->setPF(pf_); + else { + src_buffer = new ManagedPixelBuffer(pf_, src_width, src_height); + src_data = &(src_buffer->data); + } } DIBSectionBuffer::setPF(pf_); scaled_data = data; @@ -82,12 +68,8 @@ void ScaledDIBSectionBuffer::setSize(int src_width_, int src_height_) { src_width = src_width_; src_height = src_height_; - if (scaling) { - src_buffer->setSize(src_width, src_height); - } calculateScaledBufferSize(); - recreateScaledBuffer(); - scaled_data = data; + recreateBuffers(); } void ScaledDIBSectionBuffer::recreateScaledBuffer() { @@ -99,6 +81,36 @@ void ScaledDIBSectionBuffer::recreateScaledBuffer() { } } +void ScaledDIBSectionBuffer::recreateBuffers() { + width_ = scaled_width; + height_ = scaled_height; + if (scaled_width && scaled_height && format.depth != 0 && scale_ratio != 0) { + if (scaling) { + if (src_buffer) { + if (src_buffer->width() != src_width || src_buffer->width() != src_height) + src_buffer->setSize(src_width, src_height); + if (memcmp(&src_buffer->getPF(), &pf, sizeof(pf)) == 0) + src_buffer->setPF(pf); + } else { + src_buffer = new ManagedPixelBuffer(format, src_width, src_height); + src_data = &(src_buffer->data); + memcpy(src_buffer->data, data, src_width * src_height * (getPF().bpp/8)); + } + } + recreateScaledBuffer(); + if (scaling) { + scaleRect(Rect(0, 0, src_width, src_height)); + } else { + memcpy(data, src_buffer->data, src_buffer->area() * (src_buffer->getPF().bpp/8)); + if (src_buffer) { + delete src_buffer; + src_buffer = 0; + src_data = 0; + } + } + } +} + void ScaledDIBSectionBuffer::fillRect(const Rect &dest, Pixel pix) { if (scaling) { src_buffer->fillRect(dest, pix); diff --git a/win/rfb_win32/ScaledDIBSectionBuffer.h b/win/rfb_win32/ScaledDIBSectionBuffer.h index 86771918..c2b8ed7d 100644 --- a/win/rfb_win32/ScaledDIBSectionBuffer.h +++ b/win/rfb_win32/ScaledDIBSectionBuffer.h @@ -65,6 +65,7 @@ namespace rfb { protected: virtual void recreateScaledBuffer(); + virtual void recreateBuffers(); virtual void recreateBuffer() { recreateScaledBuffer(); }; -- 2.39.5