return filter;\r
}\r
\r
-void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWeightTab **pWeightTabs) {\r
- double sx;\r
- double ratio = double(dst_x) / src_x;\r
+void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, double ratio, SFilterWeightTab **pWeightTabs) {\r
+ double sxc;\r
+ double offset = 0.5;\r
+\r
SFilter sFilter = filters[filter_id];\r
\r
*pWeightTabs = new SFilterWeightTab[dst_x];\r
\r
// Make the weight tab for the each dest x position\r
for (int x = 0; x < dst_x; x++) {\r
- sx = double(x) / ratio;\r
+ sxc = (double(x)+offset) / ratio;\r
\r
// Calculate the scale filter interval, [i0, i1)\r
- int i0 = int(__rfbmax(ceil(sx-sFilter.radius), 0));\r
- int i1 = int(__rfbmin(ceil(sx+sFilter.radius), src_x));\r
+ int i0 = int(__rfbmax(sxc-sFilter.radius+0.5, 0));\r
+ int i1 = int(__rfbmin(sxc+sFilter.radius+0.5, src_x));\r
+\r
weightTabs[x].i0 = i0; weightTabs[x].i1 = i1;\r
- weightTabs[x].weight = new float[i1-i0];\r
+ weightTabs[x].weight = new double[i1-i0];\r
\r
// Calculate the weight coeffs on the scale filter interval\r
for (int ci = 0, i = i0; i < i1; i++) {\r
- weightTabs[x].weight[ci++] = (float)sFilter.func(float(i)-sx);\r
+ weightTabs[x].weight[ci++] = (double)sFilter.func(double(i)-sxc+0.5);\r
}\r
}\r
}\r
// Scale filter weight table\r
typedef struct {\r
short int i0, i1; // Filter function interval, [i0..i1)\r
- float *weight; // Weight coefficients on the filter function interval\r
+ double *weight; // Weight coefficients on the filter function interval\r
} SFilterWeightTab;\r
\r
\r
\r
SFilter &operator[](unsigned int filter_id);\r
\r
- void makeWeightTabs(int filter, int src_x, int dst_x, SFilterWeightTab **weightTabs);\r
+ void makeWeightTabs(int filter, int src_x, int dst_x, double ratio, SFilterWeightTab **weightTabs);\r
\r
protected:\r
void initFilters();\r
src_width = w;
src_height = h;
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
}
void ScaledPixelBuffer::setPF(const PixelFormat &pf_) {
freeWeightTabs();
scale_ratio = scale_ratio_;
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
}
}
void ScaledPixelBuffer::scaleRect(const Rect& rect) {
Rect changed_rect;
- U8 *ptr, *pxs, *px;
- float rx, gx, bx, red, green, blue, *xweight, *yweight, xWeight, yWeight;
+ U8 *ptr;
+ double rx, gx, bx, red, green, blue, *xweight, *yweight, xWeight, yWeight;
int r, g, b, xwi, ywi;
// Calculate the changed pixel rect in the scaled image
for (int x = changed_rect.tl.x; x < changed_rect.br.x; x++) {
ywi = 0; red = 0; green = 0; blue = 0;
- pxs = &(*src_data)[(xWeightTabs[x].i0 + yWeightTabs[y].i0*src_width) * bytesPerPixel];
xweight = xWeightTabs[x].weight;
// Calculate the scaled pixel value at (x, y) coordinates by
// [(xWeight.i0,yWeight.i1-1)..(xWeight.i1-1,yWeight.i1-1)],
// where [i0, i1) is the scaled filter interval.
for (int ys = yWeightTabs[y].i0; ys < yWeightTabs[y].i1; ys++) {
- xwi = 0; rx = 0; gx = 0; bx = 0; px = pxs;
+ xwi = 0; rx = 0; gx = 0; bx = 0;
for (int xs = xWeightTabs[x].i0; xs < xWeightTabs[x].i1; xs++) {
- rgbFromPixel(*(U32*)(px), r, g, b);
+ rgbFromPixel(getSourcePixel(xs, ys), r, g, b);
xWeight = xweight[xwi++];
rx += r * xWeight;
gx += g * xWeight;
bx += b * xWeight;
- px += bytesPerPixel;
}
yWeight = yweight[ywi++];
red += rx * yWeight;
// Calculate the scale weight tabs must be in the ScalePixelBuffer class
freeWeightTabs();
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
recreateBuffers();
}
// Calculate the scale weight tabs must be in the ScalePixelBuffer class
freeWeightTabs();
calculateScaledBufferSize();
- scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs);
- scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs);
+ scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs);
recreateBuffers();
}