More corrections to texture scale handling with transparent textures

This commit is contained in:
Mike Primm 2011-10-30 12:58:28 +08:00 committed by mikeprimm
parent 05511f0495
commit 079f9dc8cd

View File

@ -672,10 +672,10 @@ public class TexturePack {
for(int x = 0; x < res; x++, off++) { for(int x = 0; x < res; x++, off++) {
int ind_x = offsets[x]; int ind_x = offsets[x];
int wgt_x = weights[x]; int wgt_x = weights[x];
int accum_red = 0; double accum_red = 0;
int accum_green = 0; double accum_green = 0;
int accum_blue = 0; double accum_blue = 0;
int accum_alpha = 0; double accum_alpha = 0;
for(int xx = 0; xx < 2; xx++) { for(int xx = 0; xx < 2; xx++) {
int wx = (xx==0)?wgt_x:(nativeres-wgt_x); int wx = (xx==0)?wgt_x:(nativeres-wgt_x);
if(wx == 0) continue; if(wx == 0) continue;
@ -685,17 +685,18 @@ public class TexturePack {
/* Accumulate */ /* Accumulate */
c.setARGB(src_argb[(ind_y+yy)*nativeres + ind_x + xx]); c.setARGB(src_argb[(ind_y+yy)*nativeres + ind_x + xx]);
int w = wx * wy; int w = wx * wy;
accum_red += c.getRed() * w; double a = (double)w * (double)c.getAlpha();
accum_green += c.getGreen() * w; accum_red += c.getRed() * a;
accum_blue += c.getBlue() * w; accum_green += c.getGreen() * a;
accum_alpha += c.getAlpha() * w; accum_blue += c.getBlue() * a;
accum_alpha += a;
} }
} }
int newalpha = accum_alpha / (nativeres*nativeres); double newalpha = accum_alpha;
if(newalpha == 0) newalpha = 1; if(newalpha == 0.0) newalpha = 1.0;
/* Generate weighted compnents into color */ /* Generate weighted compnents into color */
c.setRGBA(accum_red / (nativeres*nativeres), accum_green / (nativeres*nativeres), c.setRGBA((int)(accum_red / newalpha), (int)(accum_green / newalpha),
accum_blue / (nativeres*nativeres), accum_alpha / (nativeres*nativeres)); (int)(accum_blue / newalpha), (int)(accum_alpha / (nativeres*nativeres)));
dest_argb[(y*res) + x] = c.getARGB(); dest_argb[(y*res) + x] = c.getARGB();
} }
} }
@ -717,10 +718,10 @@ public class TexturePack {
weights[idx] = (offsets[idx]*nativeres + nativeres) - v; weights[idx] = (offsets[idx]*nativeres + nativeres) - v;
} }
} }
int accum_red[] = new int[res*res]; double accum_red[] = new double[res*res];
int accum_green[] = new int[res*res]; double accum_green[] = new double[res*res];
int accum_blue[] = new int[res*res]; double accum_blue[] = new double[res*res];
int accum_alpha[] = new int[res*res]; double accum_alpha[] = new double[res*res];
/* Now, use weights and indices to fill in scaled map */ /* Now, use weights and indices to fill in scaled map */
for(int y = 0; y < nativeres; y++) { for(int y = 0; y < nativeres; y++) {
@ -736,11 +737,12 @@ public class TexturePack {
for(int yy = 0; yy < 2; yy++) { for(int yy = 0; yy < 2; yy++) {
int wy = (yy==0)?wgt_y:(res-wgt_y); int wy = (yy==0)?wgt_y:(res-wgt_y);
if(wy == 0) continue; if(wy == 0) continue;
int w = wx * wy; double w = wx * wy;
accum_red[(ind_y+yy)*res + (ind_x+xx)] += c.getRed() * w; double a = w * c.getAlpha();
accum_green[(ind_y+yy)*res + (ind_x+xx)] += c.getGreen() * w; accum_red[(ind_y+yy)*res + (ind_x+xx)] += c.getRed() * a;
accum_blue[(ind_y+yy)*res + (ind_x+xx)] += c.getBlue() * w; accum_green[(ind_y+yy)*res + (ind_x+xx)] += c.getGreen() * a;
accum_alpha[(ind_y+yy)*res + (ind_x+xx)] += c.getAlpha() * w; accum_blue[(ind_y+yy)*res + (ind_x+xx)] += c.getBlue() * a;
accum_alpha[(ind_y+yy)*res + (ind_x+xx)] += a;
} }
} }
} }
@ -749,10 +751,10 @@ public class TexturePack {
for(int y = 0; y < res; y++) { for(int y = 0; y < res; y++) {
for(int x = 0; x < res; x++) { for(int x = 0; x < res; x++) {
int off = (y*res) + x; int off = (y*res) + x;
int aa = accum_alpha[off] / (nativeres*nativeres); double aa = accum_alpha[off];
if(aa == 0) aa = 1; if(aa == 0.0) aa = 1.0;
c.setRGBA(accum_red[off]/(nativeres*nativeres), accum_green[off]/(nativeres*nativeres), c.setRGBA((int)(accum_red[off]/aa), (int)(accum_green[off]/aa),
accum_blue[off]/(nativeres*nativeres), accum_alpha[off] / (nativeres*nativeres)); (int)(accum_blue[off]/aa), (int)(accum_alpha[off] / (nativeres*nativeres)));
dest_argb[y*res + x] = c.getARGB(); dest_argb[y*res + x] = c.getARGB();
} }
} }