⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            if (x < skinwidth - 1) {                // FLOODFILL_STEP( 1, 1, 0 );                off = 1;                dx = 1;                dy = 0;                if (skin[pos + off] == (byte) fillcolor) {                    skin[pos + off] = (byte) 255;                    fifo[inpt].x = (short) (x + dx);                    fifo[inpt].y = (short) (y + dy);                    inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;                } else if (skin[pos + off] != (byte) 255)                    fdc = skin[pos + off] & 0xff;            }            if (y > 0) {                // FLOODFILL_STEP( -skinwidth, 0, -1 );                off = -skinwidth;                dx = 0;                dy = -1;                if (skin[pos + off] == (byte) fillcolor) {                    skin[pos + off] = (byte) 255;                    fifo[inpt].x = (short) (x + dx);                    fifo[inpt].y = (short) (y + dy);                    inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;                } else if (skin[pos + off] != (byte) 255)                    fdc = skin[pos + off] & 0xff;            }            if (y < skinheight - 1) {                // FLOODFILL_STEP( skinwidth, 0, 1 );                off = skinwidth;                dx = 0;                dy = 1;                if (skin[pos + off] == (byte) fillcolor) {                    skin[pos + off] = (byte) 255;                    fifo[inpt].x = (short) (x + dx);                    fifo[inpt].y = (short) (y + dy);                    inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;                } else if (skin[pos + off] != (byte) 255)                    fdc = skin[pos + off] & 0xff;            }            skin[x + skinwidth * y] = (byte) fdc;        }    }    //	  =======================================================    /*     * ================ 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);        image.setRGB(0, 0, inwidth, inheight, in, 0, inwidth);        AffineTransformOp op = new AffineTransformOp(AffineTransform                .getScaleInstance(outwidth * 1.0 / inwidth, outheight * 1.0                        / inheight), AffineTransformOp.TYPE_NEAREST_NEIGHBOR);        BufferedImage tmp = op.filter(image, null);        tmp.getRGB(0, 0, outwidth, outheight, out, 0, outwidth);        // *** end ***        //		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;        //			}        //		}    }    /*     * ================ GL_LightScaleTexture     *      * Scale up the pixel values in a texture to increase the lighting range     * ================     */    void GL_LightScaleTexture(int[] in, int inwidth, int inheight,            boolean only_gamma) {        if (only_gamma) {            int i, c;            int r, g, b, color;            c = inwidth * inheight;            for (i = 0; i < c; i++) {                color = in[i];                r = (color >> 0) & 0xFF;                g = (color >> 8) & 0xFF;                b = (color >> 16) & 0xFF;                r = gammatable[r] & 0xFF;                g = gammatable[g] & 0xFF;                b = gammatable[b] & 0xFF;                in[i] = (r << 0) | (g << 8) | (b << 16) | (color & 0xFF000000);            }        } else {            int i, c;            int r, g, b, color;            c = inwidth * inheight;            for (i = 0; i < c; i++) {                color = in[i];                r = (color >> 0) & 0xFF;                g = (color >> 8) & 0xFF;                b = (color >> 16) & 0xFF;                r = gammatable[intensitytable[r] & 0xFF] & 0xFF;                g = gammatable[intensitytable[g] & 0xFF] & 0xFF;                b = gammatable[intensitytable[b] & 0xFF] & 0xFF;                in[i] = (r << 0) | (g << 8) | (b << 16) | (color & 0xFF000000);            }        }    }    /*     * ================ GL_MipMap     *      * Operates in place, quartering the size of the texture ================     */    void GL_MipMap(int[] in, int width, int height) {        int i, j;        int[] out;        out = in;        int inIndex = 0;        int outIndex = 0;        int r, g, b, a;        int p1, p2, p3, p4;        for (i = 0; i < height; i += 2, inIndex += width) {            for (j = 0; j < width; j += 2, outIndex += 1, inIndex += 2) {                p1 = in[inIndex + 0];                p2 = in[inIndex + 1];                p3 = in[inIndex + width + 0];                p4 = in[inIndex + width + 1];                r = (((p1 >> 0) & 0xFF) + ((p2 >> 0) & 0xFF)                        + ((p3 >> 0) & 0xFF) + ((p4 >> 0) & 0xFF)) >> 2;                g = (((p1 >> 8) & 0xFF) + ((p2 >> 8) & 0xFF)                        + ((p3 >> 8) & 0xFF) + ((p4 >> 8) & 0xFF)) >> 2;                b = (((p1 >> 16) & 0xFF) + ((p2 >> 16) & 0xFF)                        + ((p3 >> 16) & 0xFF) + ((p4 >> 16) & 0xFF)) >> 2;                a = (((p1 >> 24) & 0xFF) + ((p2 >> 24) & 0xFF)                        + ((p3 >> 24) & 0xFF) + ((p4 >> 24) & 0xFF)) >> 2;                out[outIndex] = (r << 0) | (g << 8) | (b << 16) | (a << 24);            }        }    }    /*     * =============== GL_Upload32     *      * Returns has_alpha ===============     */    void GL_BuildPalettedTexture(byte[] paletted_texture, int[] scaled,            int scaled_width, int scaled_height) {        int r, g, b, c;        int size = scaled_width * scaled_height;        for (int i = 0; i < size; i++) {            r = (scaled[i] >> 3) & 31;            g = (scaled[i] >> 10) & 63;            b = (scaled[i] >> 19) & 31;            c = r | (g << 5) | (b << 11);            paletted_texture[i] = gl_state.d_16to8table[c];        }    }    int upload_width, upload_height;    boolean uploaded_paletted;    /*     * =============== GL_Upload32     *      * Returns has_alpha ===============     */    int[] scaled = new int[256 * 256];    byte[] paletted_texture = new byte[256 * 256];    IntBuffer tex = Lib.newIntBuffer(512 * 256, ByteOrder.LITTLE_ENDIAN);    boolean GL_Upload32(int[] data, int width, int height, boolean mipmap) {        int samples;        int scaled_width, scaled_height;        int i, c;        int comp;        Arrays.fill(scaled, 0);        Arrays.fill(paletted_texture, (byte) 0);        uploaded_paletted = false;        for (scaled_width = 1; scaled_width < width; scaled_width <<= 1)            ;        if (gl_round_down.value > 0.0f && scaled_width > width && mipmap)            scaled_width >>= 1;        for (scaled_height = 1; scaled_height < height; scaled_height <<= 1)            ;        if (gl_round_down.value > 0.0f && scaled_height > height && mipmap)            scaled_height >>= 1;        // let people sample down the world textures for speed        if (mipmap) {            scaled_width >>= (int) gl_picmip.value;            scaled_height >>= (int) gl_picmip.value;        }        // don't ever bother with >256 textures        if (scaled_width > 256)            scaled_width = 256;        if (scaled_height > 256)            scaled_height = 256;        if (scaled_width < 1)            scaled_width = 1;        if (scaled_height < 1)            scaled_height = 1;        upload_width = scaled_width;        upload_height = scaled_height;        if (scaled_width * scaled_height > 256 * 256)            Com.Error(Defines.ERR_DROP, "GL_Upload32: too big");        // scan the texture for any non-255 alpha        c = width * height;        samples = gl_solid_format;        for (i = 0; i < c; i++) {            if ((data[i] & 0xff000000) != 0xff000000) {                samples = gl_alpha_format;                break;            }        }        if (samples == gl_solid_format)            comp = gl_tex_solid_format;        else if (samples == gl_alpha_format)            comp = gl_tex_alpha_format;        else {            VID.Printf(Defines.PRINT_ALL,                    "Unknown number of texture components " + samples + '\n');            comp = samples;        }        // simulates a goto        try {            if (scaled_width == width && scaled_height == height) {                if (!mipmap) {                    if (qglColorTableEXT                            && gl_ext_palettedtexture.value != 0.0f                            && samples == gl_solid_format) {                        uploaded_paletted = true;                        GL_BuildPalettedTexture(paletted_texture, data,                                scaled_width, scaled_height);                        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0,                                GL_COLOR_INDEX8_EXT, scaled_width,                                scaled_height, 0, GL.GL_COLOR_INDEX,                                GL.GL_UNSIGNED_BYTE, paletted_texture);                    } else {                        tex.rewind();                        tex.put(data);                        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, comp,                                scaled_width, scaled_height, 0, GL.GL_RGBA,                                GL.GL_UNSIGNED_BYTE, tex);                    }                    //goto done;                    throw new longjmpException();                }                //memcpy (scaled, data, width*height*4); were bytes                System.arraycopy(data, 0, scaled, 0, width * height);            } else                GL_ResampleTexture(data, width, height, scaled, scaled_width,                        scaled_height);            GL_LightScaleTexture(scaled, scaled_width, scaled_height, !mipmap);            if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f                    && (samples == gl_solid_format)) {                uploaded_paletted = true;                GL_BuildPalettedTexture(paletted_texture, scaled, scaled_width,                        scaled_height);                gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,                        scaled_width, scaled_height, 0, GL.GL_COLOR_INDEX,                        GL.GL_UNSIGNED_BYTE, paletted_texture);            } else {                tex.rewind();                tex.put(scaled);                gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, comp, scaled_width,                        scaled_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, tex);            }            if (mipmap) {                int miplevel;                miplevel = 0;                while (scaled_width > 1 || scaled_height > 1) {                    GL_MipMap(scaled, scaled_width, scaled_height);                    scaled_width >>= 1;                    scaled_height >>= 1;                    if (scaled_width < 1)                        scaled_width = 1;                    if (scaled_height < 1)                        scaled_height = 1;                    miplevel++;                    if (qglColorTableEXT                            && gl_ext_palettedtexture.value != 0.0f                            && samples == gl_solid_format) {                        uploaded_paletted = true;                        GL_BuildPalettedTexture(paletted_texture, scaled,                                scaled_width, scaled_height);                        gl.glTexImage2D(GL.GL_TEXTURE_2D, miplevel,                                GL_COLOR_INDEX8_EXT, scaled_width,                                scaled_height, 0, GL.GL_COLOR_INDEX,                                GL.GL_UNSIGNED_BYTE, paletted_texture);                    } else {                        tex.rewind();                        tex.put(scaled);                        gl.glTexImage2D(GL.GL_TEXTURE_2D, miplevel, comp,                                scaled_width, scaled_height, 0, GL.GL_RGBA,                                GL.GL_UNSIGNED_BYTE, tex);                    }                }            }            // label done:        } catch (longjmpException e) {            ; // replaces label done        }        if (mipmap) {            gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,                    gl_filter_min);            gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,                    gl_filter_max);        } else {            gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,                    gl_filter_max);            gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,                    gl_filter_max);        }        return (samples == gl_alpha_format);    }    /*     * =============== GL_Upload8     *      * Returns has_alpha ===============     */    int[] trans = new int[512 * 256];    boolean GL_Upload8(byte[] data, int width, int height, boolean mipmap,            boolean is_sky) {        Arrays.fill(trans, 0);        int s = width * height;        if (s > trans.length)            Com.Error(Defines.ERR_DROP, "GL_Upload8: too large");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -