diff options
author | Carsten Weisse <[email protected]> | 2007-01-10 03:01:31 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2007-01-10 03:01:31 +0000 |
commit | 95f80ad38640176ac2c182f468d3fb763ac95135 (patch) | |
tree | 7295db0d3469f2b982995a6badda18f4b43fadd8 | |
parent | b91bcfb49a7933fc6893ff195538f2ccd14aca54 (diff) |
original texture resampling (lesser memory garbage)
-rw-r--r-- | src/jake2/render/fast/Image.java | 110 |
1 files changed, 50 insertions, 60 deletions
diff --git a/src/jake2/render/fast/Image.java b/src/jake2/render/fast/Image.java index a1566e7..7848ea2 100644 --- a/src/jake2/render/fast/Image.java +++ b/src/jake2/render/fast/Image.java @@ -2,7 +2,7 @@ * Image.java * Copyright (C) 2003 * - * $Id: Image.java,v 1.3 2006-11-21 02:22:19 cawe Exp $ + * $Id: Image.java,v 1.4 2007-01-10 03:01:31 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -858,72 +858,62 @@ public abstract class Image extends Main { } } - // ======================================================= + // ================================================== - /* - ================ - GL_ResampleTexture - ================ - */ - // cwei :-) - void GL_ResampleTexture(int[] in, int inwidth, int inheight, int[] out, int outwidth, int outheight) { - // int i, j; - // unsigned *inrow, *inrow2; - // int frac, fracstep; - // int[] p1 = new int[1024]; - // int[] p2 = new int[1024]; - // - - // *** this source do the same *** - BufferedImage image = new BufferedImage(inwidth, inheight, BufferedImage.TYPE_INT_ARGB); + final int[] p1 = new int[1024]; + final int[] p2 = new int[1024]; - image.setRGB(0, 0, inwidth, inheight, in, 0, inwidth); + /* + * GL_ResampleTexture + */ + void GL_ResampleTexture(int[] in, int inwidth, int inheight, int[] out, + int outwidth, int outheight) { - AffineTransformOp op = - new AffineTransformOp( - AffineTransform.getScaleInstance(outwidth * 1.0 / inwidth, outheight * 1.0 / inheight), - AffineTransformOp.TYPE_NEAREST_NEIGHBOR); - BufferedImage tmp = op.filter(image, null); + Arrays.fill(p1, 0); + Arrays.fill(p2, 0); - tmp.getRGB(0, 0, outwidth, outheight, out, 0, outwidth); + int fracstep = (inwidth * 0x10000) / outwidth; - // *** end *** + int i, j; + int frac = fracstep >> 2; + for (i = 0; i < outwidth; i++) { + p1[i] = frac >> 16; + frac += fracstep; + } + frac = 3 * (fracstep >> 2); + for (i = 0; i < outwidth; i++) { + p2[i] = frac >> 16; + frac += fracstep; + } - // byte *pix1, *pix2, *pix3, *pix4; - // - // fracstep = inwidth*0x10000/outwidth; - // - // frac = fracstep>>2; - // for (i=0 ; i<outwidth ; i++) - // { - // p1[i] = 4*(frac>>16); - // frac += fracstep; - // } - // frac = 3*(fracstep>>2); - // for (i=0 ; i<outwidth ; i++) - // { - // p2[i] = 4*(frac>>16); - // frac += fracstep; - // } - // - // for (i=0 ; i<outheight ; i++, out += outwidth) - // { - // inrow = in + inwidth*(int)((i+0.25)*inheight/outheight); - // inrow2 = in + inwidth*(int)((i+0.75)*inheight/outheight); - // frac = fracstep >> 1; - // for (j=0 ; j<outwidth ; j++) - // { - // pix1 = (byte *)inrow + p1[j]; - // pix2 = (byte *)inrow + p2[j]; - // pix3 = (byte *)inrow2 + p1[j]; - // pix4 = (byte *)inrow2 + p2[j]; - // ((byte *)(out+j))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2; - // ((byte *)(out+j))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2; - // ((byte *)(out+j))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2; - // ((byte *)(out+j))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3])>>2; - // } - // } + int outp = 0; + int r, g, b, a; + int inrow, inrow2; + int pix1, pix2, pix3, pix4; + + for (i = 0; i < outheight; i++) { + inrow = inwidth * (int) ((i + 0.25f) * inheight / outheight); + inrow2 = inwidth * (int) ((i + 0.75f) * inheight / outheight); + frac = fracstep >> 1; + for (j = 0; j < outwidth; j++) { + pix1 = in[inrow + p1[j]]; + pix2 = in[inrow + p2[j]]; + pix3 = in[inrow2 + p1[j]]; + pix4 = in[inrow2 + p2[j]]; + + r = (((pix1 >> 0) & 0xFF) + ((pix2 >> 0) & 0xFF) + + ((pix3 >> 0) & 0xFF) + ((pix4 >> 0) & 0xFF)) >> 2; + g = (((pix1 >> 8) & 0xFF) + ((pix2 >> 8) & 0xFF) + + ((pix3 >> 8) & 0xFF) + ((pix4 >> 8) & 0xFF)) >> 2; + b = (((pix1 >> 16) & 0xFF) + ((pix2 >> 16) & 0xFF) + + ((pix3 >> 16) & 0xFF) + ((pix4 >> 16) & 0xFF)) >> 2; + a = (((pix1 >> 24) & 0xFF) + ((pix2 >> 24) & 0xFF) + + ((pix3 >> 24) & 0xFF) + ((pix4 >> 24) & 0xFF)) >> 2; + + out[outp++] = (a << 24) | (b << 16) | (g << 8) | r; + } } + } /* ================ |