return filter;\r
}\r
\r
-void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, double ratio, SFilterWeightTab **pWeightTabs) {\r
+void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWeightTab **pWeightTabs) {\r
double sxc;\r
double offset = 0.5;\r
+ double ratio = (double)dst_x / src_x;\r
\r
SFilter sFilter = filters[filter_id];\r
\r
\r
SFilter &operator[](unsigned int filter_id);\r
\r
- void makeWeightTabs(int filter, int src_x, int dst_x, double ratio, SFilterWeightTab **weightTabs);\r
+ void makeWeightTabs(int filter, int src_x, int dst_x, SFilterWeightTab **weightTabs);\r
\r
protected:\r
void initFilters();\r
ScaledPixelBuffer::ScaledPixelBuffer(U8 **src_data_, int src_width_,
int src_height_, int scale, PixelFormat pf_)
- : scale_ratio(1), scaleFilterID(scaleFilterBicubic),
+ : scale(100), scale_ratio_x(1), scale_ratio_y(1), scaleFilterID(scaleFilterBicubic),
xWeightTabs(0), yWeightTabs(0), scaled_data(0) {
setSourceBuffer(src_data_, src_width_, src_height_);
}
ScaledPixelBuffer::ScaledPixelBuffer()
- : src_width(0), src_height(0), scaled_width(0), scaled_height(0),
- scale_ratio(1), scaleFilterID(scaleFilterBicubic),
+ : src_width(0), src_height(0), scaled_width(0), scaled_height(0), scale(100),
+ scale_ratio_x(1), scale_ratio_y(1), scaleFilterID(scaleFilterBicubic),
xWeightTabs(0), yWeightTabs(0), src_data(0), scaled_data(0) {
memset(&pf, 0, sizeof(pf));
}
src_width = w;
src_height = h;
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
}
void ScaledPixelBuffer::setPF(const PixelFormat &pf_) {
pf = pf_;
}
-void ScaledPixelBuffer::setScaleRatio(double scale_ratio_) {
- if (scale_ratio != scale_ratio_) {
+void ScaledPixelBuffer::setScale(int scale_) {
+ if (scale != scale_ && scale_ > 0) {
freeWeightTabs();
- scale_ratio = scale_ratio_;
+ scale = scale_;
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
}
}
Rect ScaledPixelBuffer::calculateScaleBoundary(const Rect& r) {
int x_start, y_start, x_end, y_end;
double radius = scaleFilters[scaleFilterID].radius;
- double translate = 0.5*scale_ratio - 0.5;
- x_start = (int)ceil(scale_ratio*(r.tl.x-radius) + translate);
- y_start = (int)ceil(scale_ratio*(r.tl.y-radius) + translate);
- x_end = (int)ceil(scale_ratio*(r.br.x+radius) + translate);
- y_end = (int)ceil(scale_ratio*(r.br.y+radius) + translate);
+ double translate_x = 0.5*scale_ratio_x - 0.5;
+ double translate_y = 0.5*scale_ratio_y - 0.5;
+ x_start = (int)ceil(scale_ratio_x*(r.tl.x-radius) + translate_x);
+ y_start = (int)ceil(scale_ratio_y*(r.tl.y-radius) + translate_y);
+ x_end = (int)ceil(scale_ratio_x*(r.br.x+radius) + translate_x);
+ y_end = (int)ceil(scale_ratio_y*(r.br.y+radius) + translate_y);
if (x_start < 0) x_start = 0;
if (y_start < 0) y_start = 0;
if (x_end > scaled_width) x_end = scaled_width;
}
void ScaledPixelBuffer::calculateScaledBufferSize() {
+ double scale_ratio = (double)scale / 100;
scaled_width = (int)ceil(src_width * scale_ratio);
scaled_height = (int)ceil(src_height * scale_ratio);
+ scale_ratio_x = (double)scaled_width / src_width;
+ scale_ratio_y = (double)scaled_height / src_height;
}
int getSrcWidth() const { return src_width; }
int getSrcHeight() const { return src_height; }
int area() const { return scaled_width * scaled_height; }
- int getScale() const { return int(scale_ratio * 100 + 0.5); }
- double getScaleRatio() const { return scale_ratio; }
+ int getScale() const { return scale; }
+ double getScaleRatioX() const { return scale_ratio_x; }
+ double getScaleRatioY() const { return scale_ratio_y; }
// Pixel manipulation routines
inline U32 getSourcePixel(int x, int y);
void setPF(const PixelFormat &pf);
// Set the new scale, in percent
- virtual void setScale(int scale) { setScaleRatio(double(scale)/100.0); }
- virtual void setScaleRatio(double scale_ratio);
+ virtual void setScale(int scale);
// Scale rect from the source image buffer to the destination buffer
// using the current interpolation method
int src_height;
int scaled_width;
int scaled_height;
+ int scale;
+ double scale_ratio_x;
+ double scale_ratio_y;
PixelFormat pf;
- double scale_ratio;
unsigned int scaleFilterID;
ScaleFilters scaleFilters;
SFilterWeightTab *xWeightTabs;
if (src_buffer) delete src_buffer;
}
-void ScaledDIBSectionBuffer::setScaleRatio(double scale_ratio_) {
- if (scale_ratio == scale_ratio_ || scale_ratio <= 0) return;
+void ScaledDIBSectionBuffer::setScale(int scale_) {
+ if (scale == scale_ || scale_ <= 0) return;
- scale_ratio = scale_ratio_;
- if (scale_ratio == 1) scaling = false;
+ scale = scale_;
+ if (scale == 100) scaling = false;
else scaling = true;
// FIXME:
// Calculate the scale weight tabs must be in the ScalePixelBuffer class
freeWeightTabs();
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
recreateBuffers();
}
// Calculate the scale weight tabs must be in the ScalePixelBuffer class
freeWeightTabs();
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
recreateBuffers();
}
virtual const PixelFormat& getPixelFormat() const { return pf; }
virtual const PixelFormat& getScaledPixelFormat() const { return getPF(); }
virtual void setSize(int w, int h);
- virtual void setScale(int scale) { setScaleRatio(double(scale)/100.0); };
- virtual void setScaleRatio(double scale_ratio);
-
+ virtual void setScale(int scale);
+
virtual void calculateScaledBufferSize();
Rect getRect() const { return ScaledPixelBuffer::getRect(); }
// Send a pointer event to the server
oldpos = p;
if (buffer->isScaling()) {
- p.x /= buffer->getScaleRatio();
- p.y /= buffer->getScaleRatio();
+ p.x /= buffer->getScaleRatioX();
+ p.y /= buffer->getScaleRatioY();
}
ptr.pointerEvent(callback, p, mask);
#ifdef WM_MOUSEWHEEL
void DesktopWindow::setAutoScaling(bool as) {
autoScaling = as;
+ if (isToolbarEnabled()) refreshToolbarButtons();
if (as) fitBufferToWindow();
}
-void DesktopWindow::setDesktopScaleRatio(double scale_ratio) {
- buffer->setScaleRatio(scale_ratio);
- if (!isAutoScaling()) resizeDesktopWindowToBuffer();
+void DesktopWindow::setDesktopScale(int scale_) {
+ if (buffer->getScale() == scale_ || scale_ <= 0) return;
+ buffer->setScale(scale_);
if (isToolbarEnabled()) refreshToolbarButtons();
+ if (!isAutoScaling()) resizeDesktopWindowToBuffer();
char *newTitle = new char[strlen(desktopName)+20];
sprintf(newTitle, "%s @ %i%%", desktopName, getDesktopScale());
SetWindowText(handle, TStr(newTitle));
} else {
scale_ratio = double(client_size.width()) / buffer->getSrcWidth();
}
- setDesktopScaleRatio(scale_ratio);
+ setDesktopScale(int(scale_ratio * 100));
}
void
void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);}
void setAutoScaling(bool as);
bool isAutoScaling() const { return autoScaling; }
- void setDesktopScaleRatio(double scale_ratio);
- void setDesktopScale(int scale) { setDesktopScaleRatio(double(scale)/100); }
+ void setDesktopScale(int scale);
int getDesktopScale() const { return buffer->getScale(); }
void fitBufferToWindow(bool repaint = true);