📄 image.java
字号:
if (qglColorTableEXT && gl_ext_palettedtexture.value != 0.0f && is_sky) { gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, width, height, 0, GL.GL_COLOR_INDEX, GL.GL_UNSIGNED_BYTE, data); 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 false; } else { int p; int rgb; for (int i = 0; i < s; i++) { p = data[i] & 0xff; trans[i] = d_8to24table[p]; if (p == 255) { // transparent, so scan around for another // color // to avoid alpha fringes // FIXME: do a full flood fill so mips work... if (i > width && (data[i - width] & 0xff) != 255) p = data[i - width] & 0xff; else if (i < s - width && (data[i + width] & 0xff) != 255) p = data[i + width] & 0xff; else if (i > 0 && (data[i - 1] & 0xff) != 255) p = data[i - 1] & 0xff; else if (i < s - 1 && (data[i + 1] & 0xff) != 255) p = data[i + 1] & 0xff; else p = 0; // copy rgb components trans[i] = d_8to24table[p] & 0x00FFFFFF; // only // rgb } } return GL_Upload32(trans, width, height, mipmap); } } /* * GL_LoadPic * * This is also used as an entry point for the generated r_notexture */ image_t GL_LoadPic(String name, byte[] pic, int width, int height, int type, int bits) { image_t image; int i; // find a free image_t for (i = 0; i < numgltextures; i++) { image = gltextures[i]; if (image.texnum == 0) break; } if (i == numgltextures) { if (numgltextures == MAX_GLTEXTURES) Com.Error(Defines.ERR_DROP, "MAX_GLTEXTURES"); numgltextures++; } image = gltextures[i]; if (name.length() > Defines.MAX_QPATH) Com.Error(Defines.ERR_DROP, "Draw_LoadPic: \"" + name + "\" is too long"); image.name = name; image.registration_sequence = registration_sequence; image.width = width; image.height = height; image.type = type; if (type == it_skin && bits == 8) R_FloodFillSkin(pic, width, height); // load little pics into the scrap if (image.type == it_pic && bits == 8 && image.width < 64 && image.height < 64) { pos_t pos = new pos_t(0, 0); int j, k; int texnum = Scrap_AllocBlock(image.width, image.height, pos); if (texnum == -1) { // replace goto nonscrap image.scrap = false; // image pos in array image.texnum = TEXNUM_IMAGES + image.getId(); GL_Bind(image.texnum); if (bits == 8) { image.has_alpha = GL_Upload8(pic, width, height, (image.type != it_pic && image.type != it_sky), image.type == it_sky); } else { int[] tmp = tmpImage32; int size = width * height; for (i = 0; i < size; i++) { tmp[i] = ((pic[4 * i + 0] & 0xFF) << 0); tmp[i] |= ((pic[4 * i + 1] & 0xFF) << 8); tmp[i] |= ((pic[4 * i + 2] & 0xFF) << 16); tmp[i] |= ((pic[4 * i + 3] & 0xFF) << 24); } image.has_alpha = GL_Upload32(tmp, width, height, (image.type != it_pic && image.type != it_sky)); } // after power of 2 and scales image.upload_width = upload_width; image.upload_height = upload_height; image.paletted = uploaded_paletted; image.sl = 0; image.sh = 1; image.tl = 0; image.th = 1; return image; } scrap_dirty = true; // copy the texels into the scrap block k = 0; for (i = 0; i < image.height; i++) for (j = 0; j < image.width; j++, k++) scrap_texels[texnum][(pos.y + i) * BLOCK_WIDTH + pos.x + j] = pic[k]; image.texnum = TEXNUM_SCRAPS + texnum; image.scrap = true; image.has_alpha = true; image.sl = (pos.x + 0.01f) / (float) BLOCK_WIDTH; image.sh = (pos.x + image.width - 0.01f) / (float) BLOCK_WIDTH; image.tl = (pos.y + 0.01f) / (float) BLOCK_WIDTH; image.th = (pos.y + image.height - 0.01f) / (float) BLOCK_WIDTH; } else { // this was label nonscrap image.scrap = false; image.texnum = TEXNUM_IMAGES + image.getId(); //image // pos // in // array GL_Bind(image.texnum); if (bits == 8) { image.has_alpha = GL_Upload8(pic, width, height, (image.type != it_pic && image.type != it_sky), image.type == it_sky); } else { int[] tmp = tmpImage32; int size = width * height; for (i = 0; i < size; i++) { tmp[i] = ((pic[4 * i + 0] & 0xFF) << 0); tmp[i] |= ((pic[4 * i + 1] & 0xFF) << 8); tmp[i] |= ((pic[4 * i + 2] & 0xFF) << 16); tmp[i] |= ((pic[4 * i + 3] & 0xFF) << 24); } image.has_alpha = GL_Upload32(tmp, width, height, (image.type != it_pic && image.type != it_sky)); } // after power of 2 and scales image.upload_width = upload_width; image.upload_height = upload_height; image.paletted = uploaded_paletted; image.sl = 0; image.sh = 1; image.tl = 0; image.th = 1; } return image; } /* * GL_LoadWal */ image_t GL_LoadWal(String name) { image_t image = null; ByteBuffer raw = FS.LoadMappedFile(name); if (raw == null) { VID.Printf(Defines.PRINT_ALL, "GL_FindImage: can't load " + name + '\n'); return r_notexture; } qfiles.miptex_t mt = new qfiles.miptex_t(raw); byte[] pix = tmpImage8; raw.position(mt.offsets[0]); raw.get(pix, 0, mt.width * mt.height); image = GL_LoadPic(name, pix, mt.width, mt.height, it_wall, 8); return image; } /* * GL_FindImage * * Finds or loads the given image */ image_t GL_FindImage(String name, int type) { image_t image = null; if (name == null || name.length() < 5) return null; // look for it for (int i = 0; i < numgltextures; i++) { image = gltextures[i]; if (name.equals(image.name)) { image.registration_sequence = registration_sequence; return image; } } // // load the pic from disk // image = null; int size = 0; Dimension dim = new Dimension(); if (name.endsWith(".pcx")) { size = LoadPCX(name, null, dim); if (size == 0) return null; image = GL_LoadPic(name, tmpImage8, dim.width, dim.height, type, 8); } else if (name.endsWith(".wal")) { image = GL_LoadWal(name); } else if (name.endsWith(".tga")) { size = LoadTGA(name, dim); if (size == 0) return null; image = GL_LoadPic(name, tmpImage8, dim.width, dim.height, type, 32); } return image; } /* * R_RegisterSkin */ protected image_t R_RegisterSkin(String name) { return GL_FindImage(name, it_skin); } /* * GL_FreeUnusedImages * * Any image that was not touched on this registration sequence will be * freed. */ void GL_FreeUnusedImages() { // never free r_notexture or particle texture r_notexture.registration_sequence = registration_sequence; r_particletexture.registration_sequence = registration_sequence; image_t image = null; for (int i = 0; i < numgltextures; i++) { image = gltextures[i]; // used this sequence if (image.registration_sequence == registration_sequence) continue; // free image_t slot if (image.registration_sequence == 0) continue; // don't free pics if (image.type == it_pic) continue; // free it gl.glDeleteTextures(1, new int[] { image.texnum }); image.clear(); } } /* * Draw_GetPalette */ protected void Draw_GetPalette() { Dimension dim; // replaces an array pointer (byte[768]) byte[][] palette = new byte[1][]; // get the palette int size = LoadPCX("pics/colormap.pcx", palette, dim = new Dimension()); if (palette[0] == null || palette[0].length != 768) Com.Error(Defines.ERR_FATAL, "Couldn't load pics/colormap.pcx"); byte[] pal = palette[0]; int j = 0; int r, g, b; for (int i = 0; i < 256; i++) { r = pal[j++] & 0xFF; g = pal[j++] & 0xFF; b = pal[j++] & 0xFF; d_8to24table[i] = (255 << 24) | (b << 16) | (g << 8) | (r << 0); } d_8to24table[255] &= 0x00FFFFFF; // 255 is transparent particle_t.setColorPalette(d_8to24table); } /* * GL_InitImages */ void GL_InitImages() { int i, j; float g = vid_gamma.value; registration_sequence = 1; // init intensity conversions intensity = Cvar.Get("intensity", "2", 0); if (intensity.value <= 1) Cvar.Set("intensity", "1"); gl_state.inverse_intensity = 1 / intensity.value; Draw_GetPalette(); if (qglColorTableEXT) { gl_state.d_16to8table = FS.LoadFile("pics/16to8.dat"); if (gl_state.d_16to8table == null) Com.Error(Defines.ERR_FATAL, "Couldn't load pics/16to8.pcx"); } if ((gl_config.renderer & (GL_RENDERER_VOODOO | GL_RENDERER_VOODOO2)) != 0) { g = 1.0F; } for (i = 0; i < 256; i++) { if (g == 1.0f) { gammatable[i] = (byte) i; } else { int inf = (int) (255.0f * Math.pow((i + 0.5) / 255.5, g) + 0.5); if (inf < 0) inf = 0; if (inf > 255) inf = 255; gammatable[i] = (byte) inf; } } for (i = 0; i < 256; i++) { j = (int) (i * intensity.value); if (j > 255) j = 255; intensitytable[i] = (byte) j; } } /* * GL_ShutdownImages */ void GL_ShutdownImages() { image_t image; for (int i = 0; i < numgltextures; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; // free image_t slot // free it gl.glDeleteTextures(1, new int[] { image.texnum }); image.clear(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -