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

📄 image.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            }            if (best + h > BLOCK_HEIGHT)                continue;            for (i = 0; i < w; i++)                scrap_allocated[texnum][pos.x + i] = best + h;            return texnum;        }        return -1;    }    int scrap_uploads = 0;    void Scrap_Upload() {        scrap_uploads++;        GL_Bind(TEXNUM_SCRAPS);        GL_Upload8(scrap_texels[0], BLOCK_WIDTH, BLOCK_HEIGHT, false, false);        scrap_dirty = false;    }    /*     * ==================================================     *      * PCX LOADING     *      * ==================================================     */    private static byte[] tmpImage8 = new byte[512 * 512 * 4];    private static int[] tmpImage32 = new int[512 * 512];    /*     * LoadPCX     */    int LoadPCX(String filename, byte[][] palette, Dimension dim) {        qfiles.pcx_t pcx;        // load the file        ByteBuffer raw = FS.LoadMappedFile(filename);        if (raw == null) {            VID.Printf(Defines.PRINT_DEVELOPER, "Bad pcx file " + filename                    + '\n');            return 0;        }        // parse the PCX file        pcx = new qfiles.pcx_t(raw);        if (pcx.manufacturer != 0x0a || pcx.version != 5 || pcx.encoding != 1                || pcx.bits_per_pixel != 8 || pcx.xmax >= 640                || pcx.ymax >= 480) {            VID.Printf(Defines.PRINT_ALL, "Bad pcx file " + filename + '\n');            return 0;        }        int width = pcx.xmax - pcx.xmin + 1;        int height = pcx.ymax - pcx.ymin + 1;        byte[] pix = tmpImage8;        if (palette != null) {            palette[0] = new byte[768];            raw.position(raw.limit() - 768);            raw.get(palette[0]);        }        if (dim != null) {            dim.width = width;            dim.height = height;        }        //        // decode pcx        //        int count = 0;        byte dataByte = 0;        int runLength = 0;        int x, y;        // simple counter for buffer indexing        int p = 0;        for (y = 0; y < height; y++) {            for (x = 0; x < width;) {                dataByte = pcx.data.get(p++);                if ((dataByte & 0xC0) == 0xC0) {                    runLength = dataByte & 0x3F;                    dataByte = pcx.data.get(p++);                    // write runLength pixel                    while (runLength-- > 0) {                        pix[count++] = dataByte;                        x++;                    }                } else {                    // write one pixel                    pix[count++] = dataByte;                    x++;                }            }        }        return width * height;    }    /*     * ==================================================     *      * TARGA LOADING     *      * ==================================================     */    /*     * LoadTGA     */    int LoadTGA(String name, Dimension dim) {        int columns, rows, numPixels;        int pixbuf; // index into pic        int row, column;        ByteBuffer buf_p;        int length;        qfiles.tga_t targa_header;        byte[] pic = null;        //        // load the file        //        ByteBuffer raw = FS.LoadMappedFile(name);        if (raw == null) {            VID.Printf(Defines.PRINT_DEVELOPER, "Bad tga file " + name + '\n');            return 0;        }        targa_header = new qfiles.tga_t(raw);        if (targa_header.image_type != 2 && targa_header.image_type != 10)            Com.Error(Defines.ERR_DROP,                    "LoadTGA: Only type 2 and 10 targa RGB images supported\n");        if (targa_header.colormap_type != 0                || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24))            Com                    .Error(Defines.ERR_DROP,                            "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");        columns = targa_header.width;        rows = targa_header.height;        numPixels = columns * rows;        if (dim != null) {            dim.width = columns;            dim.height = rows;        }        // targa_rgba;        pic = tmpImage8;        // skip TARGA image comment        if (targa_header.id_length != 0)            targa_header.data.position(targa_header.id_length);        buf_p = targa_header.data;        byte red, green, blue, alphabyte;        red = green = blue = alphabyte = 0;        int packetHeader, packetSize, j;        if (targa_header.image_type == 2) { // Uncompressed,                                                             // RGB images            for (row = rows - 1; row >= 0; row--) {                pixbuf = row * columns * 4;                for (column = 0; column < columns; column++) {                    switch (targa_header.pixel_size) {                    case 24:                        blue = buf_p.get();                        green = buf_p.get();                        red = buf_p.get();                        pic[pixbuf++] = red;                        pic[pixbuf++] = green;                        pic[pixbuf++] = blue;                        pic[pixbuf++] = (byte) 255;                        break;                    case 32:                        blue = buf_p.get();                        green = buf_p.get();                        red = buf_p.get();                        alphabyte = buf_p.get();                        pic[pixbuf++] = red;                        pic[pixbuf++] = green;                        pic[pixbuf++] = blue;                        pic[pixbuf++] = alphabyte;                        break;                    }                }            }        } else if (targa_header.image_type == 10) { // Runlength                                                                         // encoded                                                                         // RGB            // images            for (row = rows - 1; row >= 0; row--) {                pixbuf = row * columns * 4;                try {                    for (column = 0; column < columns;) {                        packetHeader = buf_p.get() & 0xFF;                        packetSize = 1 + (packetHeader & 0x7f);                        if ((packetHeader & 0x80) != 0) { // run-length                                                                         // packet                            switch (targa_header.pixel_size) {                            case 24:                                blue = buf_p.get();                                green = buf_p.get();                                red = buf_p.get();                                alphabyte = (byte) 255;                                break;                            case 32:                                blue = buf_p.get();                                green = buf_p.get();                                red = buf_p.get();                                alphabyte = buf_p.get();                                break;                            }                            for (j = 0; j < packetSize; j++) {                                pic[pixbuf++] = red;                                pic[pixbuf++] = green;                                pic[pixbuf++] = blue;                                pic[pixbuf++] = alphabyte;                                column++;                                // run spans across rows                                if (column == columns) {                                    column = 0;                                    if (row > 0)                                        row--;                                    else                                        // goto label breakOut;                                        throw new longjmpException();                                    pixbuf = row * columns * 4;                                }                            }                        } else { // non run-length packet                            for (j = 0; j < packetSize; j++) {                                switch (targa_header.pixel_size) {                                case 24:                                    blue = buf_p.get();                                    green = buf_p.get();                                    red = buf_p.get();                                    pic[pixbuf++] = red;                                    pic[pixbuf++] = green;                                    pic[pixbuf++] = blue;                                    pic[pixbuf++] = (byte) 255;                                    break;                                case 32:                                    blue = buf_p.get();                                    green = buf_p.get();                                    red = buf_p.get();                                    alphabyte = buf_p.get();                                    pic[pixbuf++] = red;                                    pic[pixbuf++] = green;                                    pic[pixbuf++] = blue;                                    pic[pixbuf++] = alphabyte;                                    break;                                }                                column++;                                // pixel packet run spans across rows                                if (column == columns) {                                    column = 0;                                    if (row > 0)                                        row--;                                    else                                        // goto label breakOut;                                        throw new longjmpException();                                    pixbuf = row * columns * 4;                                }                            }                        }                    }                } catch (longjmpException e) {                    // label breakOut:                }            }        }        return numPixels * 4;    }    /*     * ==================================================     *      * IMAGE FLOOD FILLING     *      * ==================================================     */    /*     * Mod_FloodFillSkin     *      * Fill background pixels so mipmapping doesn't have haloes     */    static class floodfill_t {        short x, y;    }    // must be a power of 2    static final int FLOODFILL_FIFO_SIZE = 0x1000;    static final int FLOODFILL_FIFO_MASK = FLOODFILL_FIFO_SIZE - 1;    static floodfill_t[] fifo = new floodfill_t[FLOODFILL_FIFO_SIZE];    static {        for (int j = 0; j < fifo.length; j++) {            fifo[j] = new floodfill_t();        }    }    // TODO check this: R_FloodFillSkin( byte[] skin, int skinwidth, int    // skinheight)    void R_FloodFillSkin(byte[] skin, int skinwidth, int skinheight) {        // assume this is the pixel to fill        int fillcolor = skin[0] & 0xFF;        //		floodfill_t[] fifo = new floodfill_t[FLOODFILL_FIFO_SIZE];        int inpt = 0, outpt = 0;        int filledcolor = -1;        int i;        //		for (int j = 0; j < fifo.length; j++) {        //			fifo[j] = new floodfill_t();        //		}        if (filledcolor == -1) {            filledcolor = 0;            // attempt to find opaque black            for (i = 0; i < 256; ++i)                if (d_8to24table[i] == 0xFF000000) { // alpha                                                                      // 1.0                    filledcolor = i;                    break;                }        }        // can't fill to filled color or to transparent color (used as visited        // marker)        if ((fillcolor == filledcolor) || (fillcolor == 255)) {            return;        }        fifo[inpt].x = 0;        fifo[inpt].y = 0;        inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;        while (outpt != inpt) {            int x = fifo[outpt].x;            int y = fifo[outpt].y;            int fdc = filledcolor;            int pos = x + skinwidth * y;            //            outpt = (outpt + 1) & FLOODFILL_FIFO_MASK;            int off, dx, dy;            if (x > 0) {                // 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 (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);

⌨️ 快捷键说明

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