public int TgaPfim() { using (var image = Targa.Create(this.data, this.pfimConfig)) { return(image.Width); } }
public static ImageData Load(Stream s) { ImageData img; BinaryReader br = new BinaryReader(s); var magic = br.ReadUInt32(); s.Position = 0; if (magic == 0xE0FFD8FF) { System.Drawing.Bitmap image = new System.Drawing.Bitmap(s); img = FromBitmap(image); } else if (magic == 0x20534444) { IImage image = Dds.Create(s); img = FromPfimImg(image); } //tga image else { IImage image = Targa.Create(s); img = FromPfimImg(image); } return(img); }
public int Pfim() { using (var image = Targa.Create(data, _pfimConfig)) { return(image.BitsPerPixel); } }
private static void outputLightmaps(String uncompressedPath, String ambientPath, List <LightMap> lightmaps) { Settings.stream.SetProgressBarMaximum(lightmaps.Count); foreach (LightMap l in lightmaps) { /* for reference * int[,] boxFilter = { * {1,1,1}, * {1,1,1}, * {1,1,1} * }; */ int[,] gaussFilter = { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } }; Targa lightMap = l.makeLightMapTexture(uncompressedPath); lightMap.applyFilter(gaussFilter); lightMap.writeToFile(); l.makeAmbientOcclusionTexture(ambientPath).writeToFile(); l.makeShadowMapTexture(uncompressedPath).writeToFile(); Settings.stream.UpdateProgress(); } }
public static int generateGradient(int heapOffset) { const int width = 8; const int height = 8; const int xScale = 256 / width; const int yScale = 256 / height; const int bytesPerPixel = Targa.BPP / 8; heapOffset = Targa.EmitHeader(heapOffset, width, height); for (int y = 0; y < height; y++) { int rowOffset = heapOffset + ((width * bytesPerPixel) * y); for (int x = 0; x < width; x++) { int pixelOffset = rowOffset + (x * bytesPerPixel); U8[pixelOffset, 0] = (byte)(y * yScale); U8[pixelOffset, 1] = 0; U8[pixelOffset, 2] = (byte)(x * xScale); } } const int length = (width * height * bytesPerPixel); SetStdout("gradient.tga"); Write(heapOffset, length); return(heapOffset + length); }
public void ParseTargaTopLeftRleStride() { var data = File.ReadAllBytes(Path.Combine("data", "DSCN1910_24bpp_uncompressed_10_2.tga")); var image = Targa.Create(data, new PfimConfig()); Assert.Equal(461, image.Width); }
public void ParseTargaTopLeftStride() { var data = File.ReadAllBytes(Path.Combine("data", "DSCN1910_24bpp_uncompressed_10_3.tga")); var image = Targa.Create(data, new PfimConfig()); Assert.Equal(461, image.Width); Assert.True(image.Data[460 * 3] != 0 && image.Data[461 * 3 + 1] != 0 && image.Data[461 * 3 + 2] != 0); }
public Targa makeLightMapTexture(String directory, String outputName) { Pixel[] pixels = new Pixel[width * height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { pixels[(height - j - 1) * width + i] = new Pixel(texels[i, j].excidentLight); } } Targa texture = new Targa(directory + "\\" + outputName, pixels, (short)width, (short)height, 24); return(texture); }
public static int test() { var offset = Targa.EmitHeader(0, width, height); byte *dest = &U8.Base[offset]; byte *src = &dest[numBytes]; rasterize(blend50, src, dest); SetStdout("blendfunc.tga"); Write(offset, numBytes); return(offset + numBytes); }
public TgaFrame(Stream stream) { using (var tga = Targa.Create(stream, new PfimConfig())) { Size = FrameSize = new Size(tga.Width, tga.Height); Data = tga.Data; switch (tga.Format) { // SpriteFrameType refers to the channel byte order, which is reversed from the little-endian bit order case ImageFormat.Rgba32: Type = SpriteFrameType.Bgra32; break; case ImageFormat.Rgb24: Type = SpriteFrameType.Bgr24; break; default: throw new InvalidDataException($"Unhandled ImageFormat {tga.Format}"); } } }
private void outputLightmaps(List <LightMap> lightmaps) { Settings.stream.SetProgressBarMaximum(lightmaps.Count); foreach (LightMap l in lightmaps) { int[,] boxFilter = { { 1, 1, 1 }, { 1, 0, 1 }, { 1, 1, 1 } }; /* * int[,] gaussFilter = { * {0,1,2,1,0}, * {1,2,4,2,1}, * {2,4,8,4,2}, * {1,2,4,2,1}, * {0,1,2,1,0} * }; */ int[,] gaussFilter = { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } }; String lightmapPath = lightmapJobs[l.model.name][l.mesh.name]; Targa lightMap = l.makeLightMapTexture(Path.GetDirectoryName(lightmapPath), Path.GetFileName(lightmapPath)); /*lightMap.grow(boxFilter); * lightMap.grow(boxFilter); * lightMap.grow(boxFilter); * lightMap.grow(boxFilter); * lightMap.grow(boxFilter); * lightMap.grow(boxFilter);*/ lightMap.applyFilter(gaussFilter); lightMap.writeToFile(); String ambientPath = ambientJobs[l.model.name][l.mesh.name]; l.makeAmbientOcclusionTexture(Path.GetDirectoryName(ambientPath), Path.GetFileName(ambientPath)).writeToFile(); String shadowmapPath = shadowmapJobs[l.model.name][l.mesh.name]; Targa shadowMap = l.makeShadowMapTexture(Path.GetDirectoryName(shadowmapPath), Path.GetFileName(shadowmapPath)); /* * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.grow(boxFilter); * shadowMap.applyFilter(gaussFilter); * //*/ shadowMap.applyFilter(gaussFilter); shadowMap.writeToFile(); Settings.stream.UpdateProgress(); } }
public void displayTarga(Targa t) { }
private void btn_load_Click(object sender, EventArgs e) { setButtons(false); String filePath = tb_path.Text; file = filePath; String extention = Path.GetExtension(filePath); List <Mesh> renderableMeshes = new List <Mesh>(); drawString = "File: " + file; updateBitmap(drawString); //Try and find the model file if (extention == ".mmh") { GFF tempGFF = new GFF(filePath); ModelHierarchy mh = new ModelHierarchy(tempGFF); currentlyShowing = Showing.Model; meshes = mh.mesh.toModel().meshes; setButtons(true); if (meshes.Length > 0) { setMeshNum(0); } } else if (extention == ".msh") { GFF tempGFF = new GFF(filePath); ModelMesh mm = new ModelMesh(tempGFF); currentlyShowing = Showing.Model; meshes = mm.toModel().meshes; setButtons(true); if (meshes.Length > 0) { setMeshNum(0); } } else if (extention == ".tga") { texture = new Targa(filePath); currentlyShowing = Showing.Texture; } else if (extention == ".lvl") { level = new LevelScene(filePath); currentlyShowing = Showing.Level; List <Patch> patchList = new List <Patch>(); List <Triangle> tris = new List <Triangle>(); foreach (ModelInstance m in level.lightmapModels) { for (int i = 0; i < m.meshes.Length; i++) { if (m.meshes[i].isLightmapped) { //Make the lightmap LightMap temp = new LightMap(m, m.meshes[i]); //For each patch instance in the lightmap foreach (Patch p in temp.patches) { patchList.Add(p); } } } if (m.baseModel.castsShadows) { tris.AddRange(m.tris); } } octree = new Octree(tris); patches = patchList.ToArray(); } else if (extention == ".xml") { level = new XMLScene(filePath); currentlyShowing = Showing.Level; List <Patch> patchList = new List <Patch>(); List <Triangle> tris = new List <Triangle>(); foreach (ModelInstance m in level.lightmapModels) { for (int i = 0; i < m.meshes.Length; i++) { if (m.meshes[i].isLightmapped) { //Make the lightmap LightMap temp = new LightMap(m, m.meshes[i]); //For each patch instance in the lightmap foreach (Patch p in temp.patches) { patchList.Add(p); } } } if (m.baseModel.castsShadows) { tris.AddRange(m.tris); } } octree = new Octree(tris); patches = patchList.ToArray(); } //If its not the right type of file then print an error else { drawString = "This is not a valid model (.mmh or .msh), texture (.tga), level (.lvl), or scene (.xml) file!"; } refreshView(); }