📄 image.java
字号:
for (texnum = 0; texnum < MAX_SCRAPS; texnum++) { best = BLOCK_HEIGHT; for (i = 0; i < BLOCK_WIDTH - w; i++) { best2 = 0; for (j = 0; j < w; j++) { if (scrap_allocated[texnum][i + j] >= best) break; if (scrap_allocated[texnum][i + j] > best2) best2 = scrap_allocated[texnum][i + j]; } if (j == w) { // this is a valid spot pos.x = i; pos.y = best = best2; } } if (best + h > BLOCK_HEIGHT) continue; for (i = 0; i < w; i++) scrap_allocated[texnum][pos.x + i] = best + h; return texnum; } return -1; // Sys_Error ("Scrap_AllocBlock: full"); } 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 * * ================================================================= */ /* * ============== LoadPCX ============== */ byte[] LoadPCX(String filename, byte[][] palette, Dimension dim) { qfiles.pcx_t pcx; // // load the file // byte[] raw = FS.LoadFile(filename); if (raw == null) { VID.Printf(Defines.PRINT_DEVELOPER, "Bad pcx file " + filename + '\n'); return null; } // // 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 null; } int width = pcx.xmax - pcx.xmin + 1; int height = pcx.ymax - pcx.ymin + 1; byte[] pix = new byte[width * height]; if (palette != null) { palette[0] = new byte[768]; System.arraycopy(raw, raw.length - 768, palette[0], 0, 768); } if (dim != null) { dim.width = width; dim.height = height; } // // decode pcx // int count = 0; byte dataByte = 0; int runLength = 0; int x, y; for (y = 0; y < height; y++) { for (x = 0; x < width;) { dataByte = pcx.data.get(); if ((dataByte & 0xC0) == 0xC0) { runLength = dataByte & 0x3F; dataByte = pcx.data.get(); // write runLength pixel while (runLength-- > 0) { pix[count++] = dataByte; x++; } } else { // write one pixel pix[count++] = dataByte; x++; } } } return pix; } // /* // ========================================================= // // TARGA LOADING // // ========================================================= // */ /* * ============= LoadTGA ============= */ byte[] LoadTGA(String name, Dimension dim) { int columns, rows, numPixels; int pixbuf; // index into pic int row, column; byte[] raw; ByteBuffer buf_p; int length; qfiles.tga_t targa_header; byte[] pic = null; // // load the file // raw = FS.LoadFile(name); if (raw == null) { VID.Printf(Defines.PRINT_DEVELOPER, "Bad tga file " + name + '\n'); return null; } 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; } pic = new byte[numPixels * 4]; // targa_rgba; if (targa_header.id_length != 0) targa_header.data.position(targa_header.id_length); // skip TARGA // image comment 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++; if (column == columns) { // run spans across // rows 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++; if (column == columns) { // pixel packet run // spans across rows column = 0; if (row > 0) row--; else // goto label breakOut; throw new longjmpException(); pixbuf = row * columns * 4; } } } } } catch (longjmpException e) { // label breakOut: } } } return pic; } /* * ==================================================================== * * 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; // // #define FLOODFILL_STEP( off, dx, dy ) \ // { \ // if (pos[off] == fillcolor) \ // { \ // pos[off] = 255; \ // fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \ // inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \ // } \ // else if (pos[off] != 255) fdc = pos[off]; \ // } // void FLOODFILL_STEP( int off, int dx, int dy ) // { // if (pos[off] == fillcolor) // { // pos[off] = 255; // fifo[inpt].x = x + dx; fifo[inpt].y = y + dy; // inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; // } // else if (pos[off] != 255) fdc = pos[off]; // } 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) { // byte fillcolor = *skin; // assume this is the pixel to fill int fillcolor = skin[0] & 0xff; int inpt = 0, outpt = 0; int filledcolor = -1; int i; if (filledcolor == -1) { filledcolor = 0; // attempt to find opaque black for (i = 0; i < 256; ++i) // TODO check this if (d_8to24table[i] == 0xFF000000) { // alpha 1.0 //if (d_8to24table[i] == (255 << 0)) // 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; // byte *pos = &skin[x + skinwidth * y]; 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -