further code cleanup and some documentation
svn path=/trunk/; revision=26752
This commit is contained in:
@ -38,135 +38,137 @@
|
|||||||
(((h) + (TILE_HEIGHT - 1)) / TILE_HEIGHT))
|
(((h) + (TILE_HEIGHT - 1)) / TILE_HEIGHT))
|
||||||
|
|
||||||
|
|
||||||
static void scale_region_buffer (PixelRegion *srcPR,
|
static void scale_determine_levels (PixelRegion *srcPR,
|
||||||
PixelRegion *dstPR,
|
PixelRegion *dstPR,
|
||||||
GimpInterpolationType interpolation,
|
gint *levelx,
|
||||||
GimpProgressFunc progress_callback,
|
gint *levely);
|
||||||
gpointer progress_data);
|
static gint scale_determine_progress (PixelRegion *srcPR,
|
||||||
static void scale_region_tile (PixelRegion *srcPR,
|
PixelRegion *dstPR,
|
||||||
PixelRegion *dstPR,
|
gint levelx,
|
||||||
GimpInterpolationType interpolation,
|
gint levely);
|
||||||
GimpProgressFunc progress_callback,
|
|
||||||
gpointer progress_data);
|
static void scale_region_buffer (PixelRegion *srcPR,
|
||||||
static void scale (TileManager *srcTM,
|
PixelRegion *dstPR,
|
||||||
TileManager *dstTM,
|
GimpInterpolationType interpolation,
|
||||||
GimpInterpolationType interpolation,
|
GimpProgressFunc progress_callback,
|
||||||
GimpProgressFunc progress_callback,
|
gpointer progress_data);
|
||||||
gpointer progress_data,
|
static void scale_region_tile (PixelRegion *srcPR,
|
||||||
gint *progress,
|
PixelRegion *dstPR,
|
||||||
gint max_progress);
|
GimpInterpolationType interpolation,
|
||||||
static void scale_pr (PixelRegion *srcPR,
|
GimpProgressFunc progress_callback,
|
||||||
PixelRegion *dstPR,
|
gpointer progress_data);
|
||||||
GimpInterpolationType interpolation);
|
static void scale (TileManager *srcTM,
|
||||||
static void interpolate_bilinear (TileManager *srcTM,
|
TileManager *dstTM,
|
||||||
const gint x0,
|
GimpInterpolationType interpolation,
|
||||||
const gint y0,
|
GimpProgressFunc progress_callback,
|
||||||
const gint x1,
|
gpointer progress_data,
|
||||||
const gint y1,
|
gint *progress,
|
||||||
const gdouble xfrac,
|
gint max_progress);
|
||||||
const gdouble yfrac,
|
static void scale_pr (PixelRegion *srcPR,
|
||||||
guchar *pixel);
|
PixelRegion *dstPR,
|
||||||
static void interpolate_nearest (TileManager *srcTM,
|
GimpInterpolationType interpolation);
|
||||||
const gint x0,
|
|
||||||
const gint y0,
|
static void interpolate_bilinear (TileManager *srcTM,
|
||||||
const gint x1,
|
const gint x0,
|
||||||
const gint y1,
|
const gint y0,
|
||||||
const gdouble xfrac,
|
const gint x1,
|
||||||
const gdouble yfrac,
|
const gint y1,
|
||||||
guchar *pixel);
|
const gdouble xfrac,
|
||||||
static void interpolate_cubic (TileManager *srcTM,
|
const gdouble yfrac,
|
||||||
const gint x0,
|
guchar *pixel);
|
||||||
const gint y0,
|
static void interpolate_nearest (TileManager *srcTM,
|
||||||
const gdouble xfrac,
|
const gint x0,
|
||||||
const gdouble yfrac,
|
const gint y0,
|
||||||
guchar *pixel);
|
const gint x1,
|
||||||
static void decimate_gauss (TileManager *srcTM,
|
const gint y1,
|
||||||
const gint x0,
|
const gdouble xfrac,
|
||||||
const gint y0,
|
const gdouble yfrac,
|
||||||
guchar *pixel);
|
guchar *pixel);
|
||||||
static void decimate_average (TileManager *srcTM,
|
static void interpolate_cubic (TileManager *srcTM,
|
||||||
const gint x0,
|
const gint x0,
|
||||||
const gint y0,
|
const gint y0,
|
||||||
const gint x1,
|
const gdouble xfrac,
|
||||||
const gint y1,
|
const gdouble yfrac,
|
||||||
guchar *pixel);
|
guchar *pixel);
|
||||||
static gfloat * create_lanczos3_lookup (void);
|
static void decimate_gauss (TileManager *srcTM,
|
||||||
static void interpolate_lanczos3 (TileManager *srcTM,
|
const gint x0,
|
||||||
const gint x0,
|
const gint y0,
|
||||||
const gint y0,
|
guchar *pixel);
|
||||||
const gint x1,
|
static void decimate_average (TileManager *srcTM,
|
||||||
const gint y1,
|
const gint x0,
|
||||||
const gdouble xfrac,
|
const gint y0,
|
||||||
const gdouble yfrac,
|
const gint x1,
|
||||||
guchar *pixel,
|
const gint y1,
|
||||||
const gfloat *kernel_lookup);
|
guchar *pixel);
|
||||||
static void decimate_average_pr (PixelRegion *srcPR,
|
static gfloat * create_lanczos3_lookup (void);
|
||||||
const gint x0,
|
static void interpolate_lanczos3 (TileManager *srcTM,
|
||||||
const gint y0,
|
const gint x0,
|
||||||
const gint x1,
|
const gint y0,
|
||||||
const gint y1,
|
const gint x1,
|
||||||
guchar *pixel);
|
const gint y1,
|
||||||
static void interpolate_bilinear_pr (PixelRegion *srcPR,
|
const gdouble xfrac,
|
||||||
const gint x0,
|
const gdouble yfrac,
|
||||||
const gint y0,
|
guchar *pixel,
|
||||||
const gint x1,
|
const gfloat *kernel_lookup);
|
||||||
const gint y1,
|
static void decimate_average_pr (PixelRegion *srcPR,
|
||||||
const gdouble xfrac,
|
const gint x0,
|
||||||
const gdouble yfrac,
|
const gint y0,
|
||||||
guchar *pixel);
|
const gint x1,
|
||||||
static void determine_levels (PixelRegion *srcPR,
|
const gint y1,
|
||||||
PixelRegion *dstPR,
|
guchar *pixel);
|
||||||
gint *levelx,
|
static void interpolate_bilinear_pr (PixelRegion *srcPR,
|
||||||
gint *levely);
|
const gint x0,
|
||||||
static gint determine_progress (PixelRegion *srcPR,
|
const gint y0,
|
||||||
PixelRegion *dstPR,
|
const gint x1,
|
||||||
gint levelx,
|
const gint y1,
|
||||||
gint levely);
|
const gdouble xfrac,
|
||||||
static inline void gaussan_lanczos2 (const guchar *pixels,
|
const gdouble yfrac,
|
||||||
const gint bytes,
|
guchar *pixel);
|
||||||
guchar *pixel);
|
static inline void gaussan_lanczos2 (const guchar *pixels,
|
||||||
static inline void decimate_lanczos2 (TileManager *srcTM,
|
const gint bytes,
|
||||||
const gint x0,
|
guchar *pixel);
|
||||||
const gint y0,
|
static inline void decimate_lanczos2 (TileManager *srcTM,
|
||||||
guchar *pixel);
|
const gint x0,
|
||||||
static inline void pixel_average (const guchar *p1,
|
const gint y0,
|
||||||
const guchar *p2,
|
guchar *pixel);
|
||||||
const guchar *p3,
|
static inline void pixel_average (const guchar *p1,
|
||||||
const guchar *p4,
|
const guchar *p2,
|
||||||
guchar *pixel,
|
const guchar *p3,
|
||||||
const gint bytes);
|
const guchar *p4,
|
||||||
static inline void gaussan_decimate (const guchar *pixels,
|
guchar *pixel,
|
||||||
const gint bytes,
|
const gint bytes);
|
||||||
guchar *pixel);
|
static inline void gaussan_decimate (const guchar *pixels,
|
||||||
static inline gdouble cubic_spline_fit (const gdouble dx,
|
const gint bytes,
|
||||||
const gint pt0,
|
guchar *pixel);
|
||||||
const gint pt1,
|
static inline gdouble cubic_spline_fit (const gdouble dx,
|
||||||
const gint pt2,
|
const gint pt0,
|
||||||
const gint pt3);
|
const gint pt1,
|
||||||
static inline gdouble weighted_sum (const gdouble dx,
|
const gint pt2,
|
||||||
const gdouble dy,
|
const gint pt3);
|
||||||
const gint s00,
|
static inline gdouble weighted_sum (const gdouble dx,
|
||||||
const gint s10,
|
const gdouble dy,
|
||||||
const gint s01,
|
const gint s00,
|
||||||
const gint s11);
|
const gint s10,
|
||||||
static inline gdouble sinc (const gdouble x);
|
const gint s01,
|
||||||
static inline gdouble lanczos3_mul_alpha (const guchar *pixels,
|
const gint s11);
|
||||||
const gdouble *x_kernel,
|
static inline gdouble sinc (const gdouble x);
|
||||||
const gdouble *y_kernel,
|
static inline gdouble lanczos3_mul_alpha (const guchar *pixels,
|
||||||
const gint bytes,
|
const gdouble *x_kernel,
|
||||||
const gint byte);
|
const gdouble *y_kernel,
|
||||||
static inline gdouble lanczos3_mul (const guchar *pixels,
|
const gint bytes,
|
||||||
const gdouble *x_kernel,
|
const gint byte);
|
||||||
const gdouble *y_kernel,
|
static inline gdouble lanczos3_mul (const guchar *pixels,
|
||||||
const gint bytes,
|
const gdouble *x_kernel,
|
||||||
const gint byte);
|
const gdouble *y_kernel,
|
||||||
|
const gint bytes,
|
||||||
|
const gint byte);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
determine_levels (PixelRegion *srcPR,
|
scale_determine_levels (PixelRegion *srcPR,
|
||||||
PixelRegion *dstPR,
|
PixelRegion *dstPR,
|
||||||
gint *levelx,
|
gint *levelx,
|
||||||
gint *levely)
|
gint *levely)
|
||||||
{
|
{
|
||||||
gdouble scalex = (gdouble) dstPR->w / (gdouble) srcPR->w;
|
gdouble scalex = (gdouble) dstPR->w / (gdouble) srcPR->w;
|
||||||
gdouble scaley = (gdouble) dstPR->h / (gdouble) srcPR->h;
|
gdouble scaley = (gdouble) dstPR->h / (gdouble) srcPR->h;
|
||||||
@ -203,16 +205,22 @@ determine_levels (PixelRegion *srcPR,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function calculates the number of tiles that are written in
|
||||||
|
* one scale operation. This number is used as the max_progress
|
||||||
|
* parameter in calls to GimpProgressFunc.
|
||||||
|
*/
|
||||||
static gint
|
static gint
|
||||||
determine_progress (PixelRegion *srcPR,
|
scale_determine_progress (PixelRegion *srcPR,
|
||||||
PixelRegion *dstPR,
|
PixelRegion *dstPR,
|
||||||
gint levelx,
|
gint levelx,
|
||||||
gint levely)
|
gint levely)
|
||||||
{
|
{
|
||||||
gint width = srcPR->w;
|
gint width = srcPR->w;
|
||||||
gint height = srcPR->h;
|
gint height = srcPR->h;
|
||||||
gint tiles = 0;
|
gint tiles = 0;
|
||||||
|
|
||||||
|
/* The logic here should be kept in sync with scale_region_buffer(). */
|
||||||
|
|
||||||
while (levelx < 0 && levely < 0)
|
while (levelx < 0 && levely < 0)
|
||||||
{
|
{
|
||||||
width <<= 1;
|
width <<= 1;
|
||||||
@ -287,8 +295,8 @@ scale_region_buffer (PixelRegion *srcPR,
|
|||||||
gint levely = 0;
|
gint levely = 0;
|
||||||
|
|
||||||
/* determine scaling levels */
|
/* determine scaling levels */
|
||||||
determine_levels (srcPR, dstPR, &levelx, &levely);
|
scale_determine_levels (srcPR, dstPR, &levelx, &levely);
|
||||||
max_progress = determine_progress (srcPR, dstPR, levelx, levely);
|
max_progress = scale_determine_progress (srcPR, dstPR, levelx, levely);
|
||||||
|
|
||||||
pixel_region_init_data (&tmpPR0,
|
pixel_region_init_data (&tmpPR0,
|
||||||
g_memdup (srcPR->data, width * height * bytes),
|
g_memdup (srcPR->data, width * height * bytes),
|
||||||
@ -431,8 +439,8 @@ scale_region_tile (PixelRegion *srcPR,
|
|||||||
gint levely = 0;
|
gint levely = 0;
|
||||||
|
|
||||||
/* determine scaling levels */
|
/* determine scaling levels */
|
||||||
determine_levels (srcPR, dstPR, &levelx, &levely);
|
scale_determine_levels (srcPR, dstPR, &levelx, &levely);
|
||||||
max_progress = determine_progress (srcPR, dstPR, levelx, levely);
|
max_progress = scale_determine_progress (srcPR, dstPR, levelx, levely);
|
||||||
|
|
||||||
if (levelx == 0 && levely == 0)
|
if (levelx == 0 && levely == 0)
|
||||||
{
|
{
|
||||||
@ -637,7 +645,7 @@ scale (TileManager *srcTM,
|
|||||||
decimate_average (srcTM, sx0, sy0, sx1, sy1, pixel);
|
decimate_average (srcTM, sx0, sy0, sx1, sy1, pixel);
|
||||||
else
|
else
|
||||||
interpolate_bilinear (srcTM, sx0, sy0, sx1, sy1,
|
interpolate_bilinear (srcTM, sx0, sy0, sx1, sy1,
|
||||||
xfrac, yfrac, pixel);
|
xfrac, yfrac, pixel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_INTERPOLATION_CUBIC:
|
case GIMP_INTERPOLATION_CUBIC:
|
||||||
@ -653,8 +661,7 @@ scale (TileManager *srcTM,
|
|||||||
decimate_lanczos2 (srcTM, sx0, sy0, pixel);
|
decimate_lanczos2 (srcTM, sx0, sy0, pixel);
|
||||||
else
|
else
|
||||||
interpolate_lanczos3 (srcTM, sx0, sy0, sx1, sy1,
|
interpolate_lanczos3 (srcTM, sx0, sy0, sx1, sy1,
|
||||||
xfrac, yfrac, pixel,
|
xfrac, yfrac, pixel, kernel_lookup);
|
||||||
kernel_lookup);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1234,7 +1241,8 @@ interpolate_bilinear (TileManager *srcTM,
|
|||||||
alphasum = weighted_sum (xfrac, yfrac, p1[1], p2[1], p3[1], p4[1]);
|
alphasum = weighted_sum (xfrac, yfrac, p1[1], p2[1], p3[1], p4[1]);
|
||||||
if (alphasum > 0)
|
if (alphasum > 0)
|
||||||
{
|
{
|
||||||
sum = weighted_sum (xfrac, yfrac, p1[0] * p1[1], p2[0] * p2[1],
|
sum = weighted_sum (xfrac, yfrac,
|
||||||
|
p1[0] * p1[1], p2[0] * p2[1],
|
||||||
p3[0] * p3[1], p4[0] * p4[1]);
|
p3[0] * p3[1], p4[0] * p4[1]);
|
||||||
sum /= alphasum;
|
sum /= alphasum;
|
||||||
|
|
||||||
@ -1261,7 +1269,8 @@ interpolate_bilinear (TileManager *srcTM,
|
|||||||
{
|
{
|
||||||
for (b = 0; b < 3; b++)
|
for (b = 0; b < 3; b++)
|
||||||
{
|
{
|
||||||
sum = weighted_sum (xfrac, yfrac, p1[b] * p1[3], p2[b] * p2[3],
|
sum = weighted_sum (xfrac, yfrac,
|
||||||
|
p1[b] * p1[3], p2[b] * p2[3],
|
||||||
p3[b] * p3[3], p4[b] * p4[3]);
|
p3[b] * p3[3], p4[b] * p4[3]);
|
||||||
sum /= alphasum;
|
sum /= alphasum;
|
||||||
pixel[b] = (guchar) CLAMP (sum, 0, 255);
|
pixel[b] = (guchar) CLAMP (sum, 0, 255);
|
||||||
@ -1495,7 +1504,8 @@ interpolate_lanczos3 (TileManager *srcTM,
|
|||||||
gint b, i;
|
gint b, i;
|
||||||
gint x, y;
|
gint x, y;
|
||||||
gdouble kx_sum, ky_sum;
|
gdouble kx_sum, ky_sum;
|
||||||
gdouble x_kernel[6], y_kernel[6];
|
gdouble x_kernel[6];
|
||||||
|
gdouble y_kernel[6];
|
||||||
guchar pixels[36 * 4];
|
guchar pixels[36 * 4];
|
||||||
gdouble sum, alphasum;
|
gdouble sum, alphasum;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user