-static int monochrome_warning = 0;
-RGBA* swf_ImageScale(RGBA*data, int width, int height, int newwidth, int newheight)
-{
- int x,y;
- RGBA* newdata;
- scale_lookup_t *p, **lblockx,**lblocky;
- rgba_int_t*tmpline;
-
- if(newwidth<1 || newheight<1)
- return 0;
-
- /* this is bad because this scaler doesn't yet handle monochrome
- images with 2 colors in a way that the final image hasn't more
- than 256 colors */
- if(swf_ImageGetNumberOfPaletteEntries2(data, width, height) == 2) {
- if(!monochrome_warning) {
- fprintf(stderr, "Warning: scaling monochrome image\n");
- monochrome_warning = 1;
- }
- }
-
- tmpline = (rgba_int_t*)malloc(width*sizeof(rgba_int_t));
- newdata = (RGBA*)malloc(newwidth*newheight*sizeof(RGBA));
-
- lblockx = make_scale_lookup(width, newwidth);
- lblocky = make_scale_lookup(height, newheight);
-
- for(p=lblocky[0];p<lblocky[newheight];p++)
- p->pos*=width;
-
- for(y=0;y<newheight;y++) {
- RGBA*destline = &newdata[y*newwidth];
-
- /* create lookup table for y */
- rgba_int_t*l = tmpline;
- scale_lookup_t*p_y,*p_x;
- memset(tmpline, 0, width*sizeof(rgba_int_t));
- for(p_y=lblocky[y];p_y<lblocky[y+1];p_y++) {
- RGBA*line = &data[p_y->pos];
- scale_lookup_t*p_x;
- int weight = p_y->weight;
- for(x=0;x<width;x++) {
- tmpline[x].r += line[x].r*weight;
- tmpline[x].g += line[x].g*weight;
- tmpline[x].b += line[x].b*weight;
- tmpline[x].a += line[x].a*weight;
- }
- }
-
- /* process x direction */
- p_x = lblockx[0];
- for(x=0;x<newwidth;x++) {
- unsigned int r=0,g=0,b=0,a=0;
- scale_lookup_t*p_x_to = lblockx[x+1];
- do {
- rgba_int_t* col = &tmpline[p_x->pos];
- unsigned int weight = p_x->weight;
- r += col->r*weight;
- g += col->g*weight;
- b += col->b*weight;
- a += col->a*weight;
- p_x++;
- } while (p_x<p_x_to);
-
- destline->r = r >> 16;
- destline->g = g >> 16;
- destline->b = b >> 16;
- destline->a = a >> 16;
-
- destline++;
- }
- }
- free(tmpline);
- free(*lblockx);
- free(lblockx);
- free(*lblocky);
- free(lblocky);
- return newdata;
-}
-