private void BtnRepack4Bit_Click(object sender, EventArgs e) { if (CurrentImage != null) { GRLoader X = (GRLoader)CurrentImage.artdata; X.Convert(); } }
public static void setPixelAtLocation(BitmapUW currentimg, PictureBox img, int x, int y, int newpixel, int auxpixel) { if (currentimg.artdata == null) { return; } if (img.Image == null) { return; } currentimg.artdata.ImageCache[currentimg.ImageNo].image.SetPixel(x, y, currentimg.ImagePalette.ColorAtPixel((byte)newpixel, false)); switch (main.CurrentImage.ImageType) { case BitmapUW.ImageTypes.Texture: { TextureLoader texdata = (TextureLoader)currentimg.artdata; switch (main.curgame) { case main.GAME_UW1: { if (currentimg.ImageNo < 210) { texdata.texturebufferW[currentimg.FileOffset + y * 64 + x] = (char)newpixel; } else { texdata.texturebufferF[currentimg.FileOffset + y * 32 + x] = (char)newpixel; } currentimg.artdata.Modified = true; break; } case main.GAME_UW2: { texdata.texturebufferT[currentimg.FileOffset + y * 64 + x] = (char)newpixel; currentimg.artdata.Modified = true; break; } } break; } case BitmapUW.ImageTypes.Byt: { switch (main.curgame) { case main.GAME_UW1: { BytLoader byt = (BytLoader)currentimg.artdata; byt.ImageFileData[currentimg.FileOffset + y * (currentimg.image.Width) + x] = (char)newpixel; currentimg.artdata.Modified = true; break; } } break; } case BitmapUW.ImageTypes.EightBitUncompressed: { GRLoader gr = (GRLoader)currentimg.artdata; gr.ImageFileData[currentimg.FileOffset + y * (currentimg.image.Width) + x] = (char)newpixel; currentimg.artdata.Modified = true; break; } case BitmapUW.ImageTypes.FourBitUncompress: { GRLoader gr = (GRLoader)currentimg.artdata; int Offset = y * (currentimg.image.Width) + x; long NibbleAddress = currentimg.FileOffset + (Offset / 2); int HiOrLow = Offset % 2; if (HiOrLow == 1) { //low nibble gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] & 0xF0); gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] | ((char)auxpixel & 0xf)); } else { gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] & 0x0F); gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] | ((char)(auxpixel << 4) & 0xf0)); } currentimg.artdata.Modified = true; break; } //case BitmapUW.ImageTypes.FourBitRunLength: // { //GRLoader gr = (GRLoader)currentimg.artdata; //currentimg.UncompressedData[y * (currentimg.image.Width) + x] = (char)auxpixel; //currentimg.artdata.Modified = true; // break; // } default: { return; // img.Image = main.CurrentImage.image; //break; } } currentimg.Modified = true; main.CurrentImage = currentimg.artdata.ImageCache[currentimg.ImageNo]; img.Image = main.CurrentImage.image; }
/// <summary> /// Handles selection of an art file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TreeArt_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = TreeArt.SelectedNode; BtnRepack4Bit.Enabled = false; if (node.Parent != null) { string partext = node.Parent.Text.ToUpper(); switch (partext) { case "TEXTURES": case "WALL TEXTURES": case "FLOOR TEXTURES": { //loading a texture int index; if (node.Tag == null) { return; } if (int.TryParse(node.Tag.ToString(), out index)) { CurrentImage = tex.LoadImageAt(index); } break; } case "GRAPHIC RESOURCES": { int index; if (node.Tag == null) { return; } if (int.TryParse(node.Tag.ToString(), out index)) { if (grfile[index] == null) { //Load the gr file and populate the tree. grfile[index] = new GRLoader(main.basepath + "\\data\\" + node.Text); for (int i = 0; i <= grfile[index].ImageCache.GetUpperBound(0); i++) { TreeNode img = node.Nodes.Add(i.ToString()); img.Tag = i; } } } break; } case "BITMAP RESOURCES": { int index; if (node.Tag == null) { return; } if (int.TryParse(node.Tag.ToString(), out index)) { if (bytfile[index] == null) { bytfile[index] = new BytLoader(); } CurrentImage = bytfile[index].LoadImageAt(index); } break; } case "BYT.ARK": { int index; if (node.Tag == null) { return; } if (int.TryParse(node.Tag.ToString(), out index)) { if (bytfile[0] == null) { bytfile[0] = new BytLoader(); } CurrentImage = bytfile[0].LoadImageAt(index); } break; } default: if (partext.ToUpper().Contains(".GR")) { int parentindex; if (node.Parent.Tag == null) { return; } if (int.TryParse(node.Parent.Tag.ToString(), out parentindex)) { int index; if (node.Tag == null) { return; } if (int.TryParse(node.Tag.ToString(), out index)) { //load the gr file CurrentImage = grfile[parentindex].LoadImageAt(index); switch (CurrentImage.ImageType) { case BitmapUW.ImageTypes.FourBitRunLength: case BitmapUW.ImageTypes.FourBitUncompress: BtnRepack4Bit.Enabled = true; break; } } } } break; } } if (CurrentImage != null) { ImgOut.Image = CurrentImage.image; PicPalette.Image = ArtLoader.Palette(CurrentImage.ImagePalette, CurrentImage.PaletteRef).image; ImgOut.Width = CurrentImage.image.Width * (int)NumZoom.Value; ImgOut.Height = CurrentImage.image.Height * (int)NumZoom.Value; LblImageDetails.Text = CurrentImage.image.Height + "x" + CurrentImage.image.Width + "\n" + CurrentImage.ImageType.ToString(); } }