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;
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() {
}
}
+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);