Implement image scale.

SVN revision: 30419
This commit is contained in:
Gustavo Sverzut Barbieri 2007-06-21 19:56:32 +00:00
parent b14f445960
commit 807b2d1912
1 changed files with 475 additions and 124 deletions

View File

@ -396,6 +396,9 @@ _soft16_adjust_areas(Evas_Rectangle *src,
return 1;
}
/***********************************************************************
* Unscaled
**********************************************************************/
static void
_soft16_image_draw_unscaled_solid_solid(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
@ -687,21 +690,482 @@ _soft16_image_draw_unscaled(Soft16_Image *src, Soft16_Image *dst,
cr.w, cr.h);
}
/***********************************************************************
* Scaled
***********************************************************************/
static void
_soft16_image_draw_scaled_solid_solid(Soft16_Image *src,
Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
DATA16 *dst_itr;
int y, w_align;
w_align = w & ~7;
dst_itr = dst->pixels + dst_offset;
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
int x;
s = src->pixels + offset_y[y];
pld(s, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(offset_x + x, 32);
UNROLL8({
_soft16_pt_blend_solid_solid(d, s[offset_x[x]]);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_solid_solid(d, s[offset_x[x]]);
}
}
static void
_soft16_image_draw_scaled_transp_solid(Soft16_Image *src,
Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
DATA16 *dst_itr;
int y, w_align;
w_align = w & ~7;
dst_itr = dst->pixels + dst_offset;
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
DATA8 *a;
int x;
s = src->pixels + offset_y[y];
a = src->alpha + offset_y[y];
pld(s, 0);
pld(a, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(a, 8);
pld(offset_x + x, 32);
UNROLL8({
int off_x = offset_x[x];
_soft16_pt_blend_transp_solid(d, s[off_x], a[off_x]);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_transp_solid(d, s[offset_x[x]], a[offset_x[x]]);
}
}
static inline void
_soft16_image_draw_scaled_no_mul(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
if (src->have_alpha && (!dst->have_alpha))
_soft16_image_draw_scaled_transp_solid
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else if ((!src->have_alpha) && (!dst->have_alpha))
_soft16_image_draw_scaled_solid_solid
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else
fprintf(stderr,
"Unsupported draw of scaled images src->have_alpha=%d, "
"dst->have_alpha=%d, WITHOUT COLOR MUL\n",
src->have_alpha, dst->have_alpha);
}
static void
_soft16_image_draw_scaled_solid_solid_mul_alpha(Soft16_Image *src,
Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
DATA16 *dst_itr;
int y, w_align, rel_alpha;
rel_alpha = A_VAL(&dc->mul.col) >> 3;
if ((rel_alpha < 1) || (rel_alpha > 31)) return;
rel_alpha = 31 - rel_alpha;
w_align = w & ~7;
dst_itr = dst->pixels + dst_offset;
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
int x;
s = src->pixels + offset_y[y];
pld(s, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(offset_x + x, 32);
UNROLL8({
_soft16_pt_blend_solid_solid_mul_alpha
(d, s[offset_x[x]], rel_alpha);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_solid_solid_mul_alpha
(d, s[offset_x[x]], rel_alpha);
}
}
static void
_soft16_image_draw_scaled_transp_solid_mul_alpha(Soft16_Image *src,
Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
DATA16 *dst_itr;
int y, w_align, rel_alpha;
rel_alpha = A_VAL(&dc->mul.col) >> 3;
if ((rel_alpha < 1) || (rel_alpha > 31)) return;
rel_alpha = 31 - rel_alpha;
w_align = w & ~7;
dst_itr = dst->pixels + dst_offset;
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
DATA8 *a;
int x;
s = src->pixels + offset_y[y];
a = src->alpha + offset_y[y];
pld(s, 0);
pld(a, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(a, 8);
pld(offset_x + x, 32);
UNROLL8({
int off_x = offset_x[x];
_soft16_pt_blend_transp_solid_mul_alpha
(d, s[off_x], a[off_x], rel_alpha);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_transp_solid_mul_alpha
(d, s[offset_x[x]], a[offset_x[x]], rel_alpha);
}
}
static inline void
_soft16_image_draw_scaled_mul_alpha(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
if (src->have_alpha && (!dst->have_alpha))
_soft16_image_draw_scaled_transp_solid_mul_alpha
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else if ((!src->have_alpha) && (!dst->have_alpha))
_soft16_image_draw_scaled_solid_solid_mul_alpha
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else
fprintf(stderr,
"Unsupported draw of scaled images src->have_alpha=%d, "
"dst->have_alpha=%d, WITH ALPHA MUL %d\n",
src->have_alpha, dst->have_alpha, A_VAL(&dc->mul.col));
}
static void
_soft16_image_draw_scaled_solid_solid_mul_color(Soft16_Image *src,
Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
DATA16 *dst_itr;
int y, w_align, rel_alpha, r, g, b;
rel_alpha = A_VAL(&dc->mul.col) >> 3;
if ((rel_alpha < 1) || (rel_alpha > 31)) return;
r = R_VAL(&dc->mul.col);
g = G_VAL(&dc->mul.col);
b = B_VAL(&dc->mul.col);
/* we'll divide by 256 to make it faster, try to improve things a bit */
if (r > 127) r++;
if (g > 127) g++;
if (b > 127) b++;
w_align = w & ~7;
dst_itr = dst->pixels + dst_offset;
if (rel_alpha == 31)
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
int x;
s = src->pixels + offset_y[y];
pld(s, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(offset_x + x, 32);
UNROLL8({
_soft16_pt_blend_solid_solid_mul_color_solid
(d, s[offset_x[x]], r, g, b);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_solid_solid_mul_color_solid
(d, s[offset_x[x]], r, g, b);
}
else
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
int x;
s = src->pixels + offset_y[y];
pld(s, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(offset_x + x, 32);
UNROLL8({
_soft16_pt_blend_solid_solid_mul_color_transp
(d, s[offset_x[x]], rel_alpha, r, g, b);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_solid_solid_mul_color_transp
(d, s[offset_x[x]], rel_alpha, r, g, b);
}
}
static void
_soft16_image_draw_scaled_transp_solid_mul_color(Soft16_Image *src,
Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
DATA16 *dst_itr;
int y, w_align, rel_alpha, r, g, b;
rel_alpha = A_VAL(&dc->mul.col) >> 3;
if ((rel_alpha < 1) || (rel_alpha > 31)) return;
rel_alpha = 31 - rel_alpha;
r = R_VAL(&dc->mul.col);
g = G_VAL(&dc->mul.col);
b = B_VAL(&dc->mul.col);
/* we'll divide by 256 to make it faster, try to improve things a bit */
if (r > 127) r++;
if (g > 127) g++;
if (b > 127) b++;
w_align = w & ~7;
dst_itr = dst->pixels + dst_offset;
if (rel_alpha == 0)
for (y = 0; y < h; y++, dst_itr += dst->stride)
{
DATA16 *d, *s;
DATA8 *a;
int x;
s = src->pixels + offset_y[y];
a = src->alpha + offset_y[y];
pld(s, 0);
pld(a, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(a, 8);
pld(offset_x + x, 32);
UNROLL8({
int off_x = offset_x[x];
_soft16_pt_blend_transp_solid_mul_color_solid
(d, s[off_x], a[off_x], r, g, b);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_transp_solid_mul_color_solid
(d, s[offset_x[x]], a[offset_x[x]], r, g, b);
}
else
{
DATA16 *d, *s;
DATA8 *a;
int x;
s = src->pixels + offset_y[y];
a = src->alpha + offset_y[y];
pld(s, 0);
pld(a, 0);
pld(offset_x, 0);
d = dst_itr;
x = 0;
while (x < w_align)
{
pld(s, 32);
pld(a, 8);
pld(offset_x + x, 32);
UNROLL8({
int off_x = offset_x[x];
_soft16_pt_blend_transp_solid_mul_color_transp
(d, s[off_x], a[off_x], rel_alpha, r, g, b);
x++;
d++;
});
}
for (; x < w; x++, d++)
_soft16_pt_blend_transp_solid_mul_color_transp
(d, s[offset_x[x]], a[offset_x[x]], rel_alpha, r, g, b);
}
}
static inline void
_soft16_image_draw_scaled_mul_color(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
if (src->have_alpha && (!dst->have_alpha))
_soft16_image_draw_scaled_transp_solid_mul_color
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else if ((!src->have_alpha) && (!dst->have_alpha))
_soft16_image_draw_scaled_solid_solid_mul_color
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else
fprintf(stderr,
"Unsupported draw of scaled images src->have_alpha=%d, "
"dst->have_alpha=%d, WITH COLOR MUL 0x%08x\n",
src->have_alpha, dst->have_alpha, dc->mul.col);
}
static inline void
_soft16_image_draw_scaled_mul(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
int dst_offset, int w, int h,
int *offset_x, int *offset_y)
{
if ((A_VAL(&dc->mul.col) == R_VAL(&dc->mul.col)) &&
(A_VAL(&dc->mul.col) == G_VAL(&dc->mul.col)) &&
(A_VAL(&dc->mul.col) == B_VAL(&dc->mul.col)))
_soft16_image_draw_scaled_mul_alpha
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
else
_soft16_image_draw_scaled_mul_color
(src, dst, dc, dst_offset, w, h, offset_x, offset_y);
}
static void
_soft16_image_draw_scaled(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
const Evas_Rectangle sr,
const Evas_Rectangle dr,
const Evas_Rectangle cr)
{
int x, y, dst_offset, *offset_x, *offset_y;
/* pre-calculated scale tables */
offset_x = alloca(cr.w * sizeof(*offset_x));
for (x = 0; x < cr.w; x++)
offset_x[x] = (((x + cr.x - dr.x) * sr.w) / dr.w) + sr.x;
offset_y = alloca(cr.h * sizeof(*offset_y));
for (y = 0; y < cr.h; y++)
offset_y[y] = (((((y + cr.y - dr.y) * sr.h) / dr.h) + sr.y)
* src->stride);
dst_offset = cr.x + (cr.y * dst->stride);
if ((!dc->mul.use) || (dc->mul.col == 0xffffffff))
_soft16_image_draw_scaled_no_mul
(src, dst, dc, dst_offset, cr.w, cr.h, offset_x, offset_y);
else if (dc->mul.col != 0x00000000)
_soft16_image_draw_scaled_mul
(src, dst, dc, dst_offset, cr.w, cr.h, offset_x, offset_y);
}
static void
_soft16_image_draw_sampled_int(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
Evas_Rectangle sr, Evas_Rectangle dr)
{
Evas_Rectangle cr;
/* Scanline_Func func; */
int x, y;
int *lin_ptr;
DATA16 *buf, *dptr;
DATA16 **row_ptr = NULL;
DATA16 *ptr, *dst_ptr, *src_data, *dst_data;
DATA8 *bufa, *daptr;
DATA8 **rowa_ptr = NULL;
DATA8 *aptr, *dsta_ptr, *srca_data, *dsta_data;
if (!(RECTS_INTERSECT(dr.x, dr.y, dr.w, dr.h, 0, 0, dst->w, dst->h)))
return;
@ -712,128 +1176,15 @@ _soft16_image_draw_sampled_int(Soft16_Image *src, Soft16_Image *dst,
if (!_soft16_adjust_areas(&sr, src->w, src->h, &dr, dst->w, dst->h, &cr))
return;
src_data = src->pixels;
srca_data = src->alpha;
dst_data = dst->pixels;
dsta_data = dst->alpha;
/* figure out dest start ptr */
dst_ptr = dst_data + cr.x + (cr.y * dst->stride);
dsta_ptr = dsta_data + cr.x + (cr.y * dst->stride);
/* func = _soft16_scanline_copy; */
/* if (( src->alpha) && ( dst->alpha)) func = _soft16_scanline_blend; */
/* else if (( src->alpha) && (!dst->alpha)) func = _soft16_scanline_blend; */
/* else if ((!src->alpha) && ( dst->alpha)) func = _soft16_scanline_copy; */
/* else if ((!src->alpha) && (!dst->alpha)) func = _soft16_scanline_copy; */
/* not being scaled at all */
if ((dr.w == sr.w) && (dr.h == sr.h))
_soft16_image_draw_unscaled(src, dst, dc, sr, dr, cr);
#if 0
else
{
/* allocate scale lookup tables */
lin_ptr = alloca(cr.w * sizeof(int));
row_ptr = alloca(cr.h * sizeof(DATA16 *));
rowa_ptr = alloca(cr.h * sizeof(DATA8 *));
/* fill scale tables */
for (x = 0; x < cr.w; x++)
lin_ptr[x] = (((x + cr.x - dr.x) * sr.w) / dr.w) + sr.x;
for (y = 0; y < cr.h; y++)
{
row_ptr[y] = src_data +
(((((y + cr.y - dr.y) * sr.h) /
dr.h) + sr.y) * src->stride);
rowa_ptr[y] = srca_data +
(((((y + cr.y - dr.y) * sr.h) /
dr.h) + sr.y) * src->stride);
}
/* scale to dst */
dptr = dst_ptr;
daptr = dsta_ptr;
if ((!(src->alpha)) && (!(dst->alpha)) && (!dc->mul.use))
{
for (y = 0; y < cr.h; y++)
{
dst_ptr = dptr;
for (x = 0; x < cr.w; x++)
{
ptr = row_ptr[y] + lin_ptr[x];
*dst_ptr = *ptr;
dst_ptr++;
}
dptr += dst->stride;
}
}
else
{
/* a scanline buffer */
buf = alloca(cr.w * sizeof(DATA16) * 2);
if (src->alpha)
{
bufa = alloca(cr.w * sizeof(DATA8) * 2);
for (y = 0; y < cr.h; y++)
{
dst_ptr = dptr;
for (x = 0; x < cr.w; x++)
{
ptr = row_ptr[y] + lin_ptr[x];
aptr = rowa_ptr[y] + lin_ptr[x];
BLEND(ptr, aptr, dst_ptr);
dst_ptr++;
}
/*
dst_ptr = buf;
dsta_ptr = bufa;
for (x = 0; x < cr.w; x++)
{
ptr = row_ptr[y] + lin_ptr[x];
*dst_ptr = *ptr;
dst_ptr++;
aptr = rowa_ptr[y] + lin_ptr[x];
*dsta_ptr = *aptr;
dsta_ptr++;
}
func(buf, bufa, NULL, dc->mul.col, dptr, cr.w);
*/
dptr += dst->stride;
}
}
else
{
for (y = 0; y < cr.h; y++)
{
dst_ptr = dptr;
for (x = 0; x < cr.w; x++)
{
ptr = row_ptr[y] + lin_ptr[x];
*dst_ptr = *ptr;
dst_ptr++;
}
/*
dst_ptr = buf;
for (x = 0; x < cr.w; x++)
{
ptr = row_ptr[y] + lin_ptr[x];
*dst_ptr = *ptr;
dst_ptr++;
}
func(buf, NULL, NULL, dc->mul.col, dptr, cr.w);
*/
dptr += dst->stride;
}
}
}
}
#endif
_soft16_image_draw_scaled(src, dst, dc, sr, dr, cr);
}
void
soft16_image_draw(Soft16_Image *src, Soft16_Image *dst,
RGBA_Draw_Context *dc,
RGBA_Draw_Context *dc,
int src_region_x, int src_region_y,
int src_region_w, int src_region_h,
int dst_region_x, int dst_region_y,