internal static void ChangeTextureToRequestedFormat(TextureContent texture, Type originalType, TextureProcessorOutputFormat textureFormat) { switch (textureFormat) { case TextureProcessorOutputFormat.NoChange: if (originalType == null) { break; } texture.ConvertBitmapType(originalType); return; case TextureProcessorOutputFormat.Color: texture.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); return; case TextureProcessorOutputFormat.DxtCompressed: BestGuessCompress(texture); break; default: return; } }
private static void BestGuessCompress(TextureContent texture) { texture.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); if (!(texture is Texture3DContent)) { texture.ConvertBitmapType(HasFractionalAlpha(texture) ? typeof(Dxt5BitmapContent) : typeof(Dxt1BitmapContent)); } }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { if (input == null) { throw new ArgumentNullException("input"); } if (context == null) { throw new ArgumentNullException("context"); } if (!this.ForceDXT5) { return(base.Process(input, context)); } TextureContent ret = null; TextureProcessorOutputFormat fmt = this.TextureFormat; this.TextureFormat = TextureProcessorOutputFormat.NoChange; try { ret = base.Process(input, context); Type originalType = ret.Faces[0][0].GetType(); if (originalType != typeof(Dxt5BitmapContent)) { ret.ConvertBitmapType(typeof(Dxt5BitmapContent)); } } finally { this.TextureFormat = fmt; } return(ret); }
private TextureContent GenerateCubemap(TextureContent input, ContentProcessorContext context) { if (input.Faces[1].Count != 0) { //its already a cubemap return(base.Process(input, context)); } TextureCubeContent cubeContent = new TextureCubeContent(); // Convert the input data to Color format, for ease of processing. input.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); int height = input.Faces[0][0].Height; int width = input.Faces[0][0].Width / 6; //split the image into 6 pieces, setup: X+,X-, Y+,Y-, Z+, Z- cubeContent.Faces[(int)CubeMapFace.PositiveX] = CreateFace(input.Faces[0][0], width, height, 0); cubeContent.Faces[(int)CubeMapFace.NegativeX] = CreateFace(input.Faces[0][0], width, height, width * 1); cubeContent.Faces[(int)CubeMapFace.PositiveY] = CreateFace(input.Faces[0][0], width, height, width * 2); cubeContent.Faces[(int)CubeMapFace.NegativeY] = CreateFace(input.Faces[0][0], width, height, width * 3); cubeContent.Faces[(int)CubeMapFace.PositiveZ] = CreateFace(input.Faces[0][0], width, height, width * 4); cubeContent.Faces[(int)CubeMapFace.NegativeZ] = CreateFace(input.Faces[0][0], width, height, width * 5); // Calculate mipmap data. cubeContent.GenerateMipmaps(true); // Compress the cubemap into DXT1 format. cubeContent.ConvertBitmapType(typeof(Dxt1BitmapContent)); return(cubeContent); }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { TextureContent texContent = base.Process(input, context); texContent.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); for (int face = 0; face < texContent.Faces.Count; face++) { MipmapChain mipChain = texContent.Faces[face]; for (int mipLevel = 0; mipLevel < mipChain.Count; mipLevel++) { PixelBitmapContent <Color> image = (PixelBitmapContent <Color>)input.Faces[face][mipLevel]; Color toReplace = new Color(81, 92, 164); image.ReplaceColor(toReplace, Color.Yellow); } } return(texContent); }
internal void ProcessSingleFrame(TextureContent input) { bool colorKeyEnabled = ColorKeyEnabled; bool premultiplyAlpha = PremultiplyAlpha; Type bitmapType = null; if (colorKeyEnabled || premultiplyAlpha) { Type type2; input.Validate(null); bitmapType = input.Faces[0][0].GetType(); if (TextureProcessorUtils.IsHighPrecisionFormat(bitmapType)) { type2 = typeof(PixelBitmapContent <Vector4>); } else { type2 = typeof(PixelBitmapContent <Color>); } input.ConvertBitmapType(type2); } if (colorKeyEnabled) { TextureProcessorUtils.ColorKey(input, ColorKeyColor); } if (premultiplyAlpha) { TextureProcessorUtils.PremultiplyAlpha(input); } if (ResizeToPowerOfTwo) { TextureProcessorUtils.ResizeToPowerOfTwo(input); } if (GenerateMipmaps) { input.GenerateMipmaps(false); } TextureProcessorUtils.ChangeTextureToRequestedFormat(input, bitmapType, TextureFormat); }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { input.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); foreach (var mipmapChain in input.Faces) { for (int i = 0; i < mipmapChain.Count; i++) { var bitmap = mipmapChain[i] as PixelBitmapContent <Color>; int newWidth = (int)((float)bitmap.Width * Scale); int newHeight = (int)((float)bitmap.Height * Scale); var newBitmap = new PixelBitmapContent <Color>(newWidth, newHeight); for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { for (int scaleY = 0; scaleY < Scale; scaleY++) { for (int scaleX = 0; scaleX < Scale; scaleX++) { newBitmap.SetPixel( (int)(x * Scale) + scaleX, (int)(y * Scale) + scaleY, bitmap.GetPixel(x, y)); } } } } mipmapChain[i] = newBitmap; } } return(base.Process(input, context)); }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { TextureContent texContent = base.Process(input, context); texContent.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); for (int face = 0; face < input.Faces.Count; face++) { MipmapChain mipChain = input.Faces[face]; for (int mipLevel = 0; mipLevel < mipChain.Count; mipLevel++) { PixelBitmapContent <Color> oldImage = (PixelBitmapContent <Color>)input.Faces[face][mipLevel]; PixelBitmapContent <Color> grayImage = new PixelBitmapContent <Color>(oldImage.Width, oldImage.Height); for (int x = 0; x < oldImage.Width; x++) { for (int y = 0; y < oldImage.Height; y++) { Color oldColor = oldImage.GetPixel(x, y); float grayValue = oldColor.R * 0.299f / 255.0f; grayValue += oldColor.G * 0.596f / 255.0f; grayValue += oldColor.B * 0.211f / 255.0f; float alpha = oldColor.A / 255.0f; Color grayColor = new Color(grayValue, grayValue, grayValue, alpha); Color newColor = Color.Lerp(oldColor, grayColor, interpolation); grayImage.SetPixel(x, y, newColor); } } input.Faces[face][mipLevel] = grayImage; } } return(texContent); }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { string[] strs = context.OutputFilename.Split('\\'); /* // If assigning this processor to all textures, use something like this to only apply to certain folders * if (strs.Length > 2 && strs[strs.Length - 2] == "Animations") * { } */ //write_debug(context.OutputDirectory); //write_debug(context.OutputFilename); bool battler = (strs.Length > 2 && strs[strs.Length - 2] == "Battlers"); Dictionary <Color, int> palette = new Dictionary <Color, int>(); Dictionary <string, Color[]> palette_data = context.BuildAndLoadAsset <string, Dictionary <string, Color[]> >(new ExternalReference <string>(@"BattlerPalettes.xml"), ""); string filename = Path.GetFileNameWithoutExtension(context.OutputFilename); if (!palette_data.ContainsKey(filename)) { filename = filename.Split('-')[0]; } if (palette_data.ContainsKey(filename)) { for (int i = 0; i < palette_data[filename].Length; i++) { if (!palette.ContainsKey(palette_data[filename][i])) { palette.Add(palette_data[filename][i], i); } } } // The process for getting to this point has changed, so now if there is no palette entry for a texture it shouldn't be edited at all else { return(base.Process(input, context)); } // Otherwise we have palette data and the image will be remapped to color indices on the red channel input.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); foreach (MipmapChain image_face in input.Faces) { for (int i = 0; i < image_face.Count; i++) { PixelBitmapContent <Color> mip = (PixelBitmapContent <Color>)image_face[i]; Color original, edited; // Go through the whole image for (int y = 0; y < mip.Height; y++) { for (int x = 0; x < mip.Width; x++) { original = mip.GetPixel(x, y); // If this color isn't already in the palette, /leave the color alone/ // This is a new change to leave unpaletted colors alone if (original.A > 0 && palette.ContainsKey(original)) { edited = new Color((palette[original] * 1) % 256, 0, 0, original.A); mip.SetPixel(x, y, edited); } } } } } /* * if (false) * { * //write_debug(originalFilename + ", " + palette.Count.ToString()); * write_debug(originalFilename + ", " + new_colors.ToString() + "/" + palette.Count.ToString()); * for (int i = base_count; i < palette.Count; i++) * foreach (KeyValuePair<Color, int> entry in palette) * if (entry.Value == i) * { * if (entry.Key.A > 0) * write_debug(entry.Key.ToString()); * break; * } * }*/ return(base.Process(input, context)); }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { string[] strs = context.OutputFilename.Split('\\'); /* // If assigning this processor to all textures, use something like this to only apply to certain folders * if (strs.Length > 2 && strs[strs.Length - 2] == "Animations") * { } */ //write_debug(context.OutputDirectory); //write_debug(context.OutputFilename); Dictionary <Color, int> palette = new Dictionary <Color, int>(); Dictionary <string, Color[]> palette_data = context.BuildAndLoadAsset <string, Dictionary <string, Color[]> >( new ExternalReference <string>(@"Face_Palette_Data.xml"), ""); string filename = Path.GetFileNameWithoutExtension(context.OutputFilename); string doop = filename; // If palette data for the face exists if (palette_data.ContainsKey(filename) && palette_data[filename].Length > 0) { // Add the colors to a dictionary for (int i = 0; i < palette_data[filename].Length; i++) { if (!palette.ContainsKey(palette_data[filename][i])) { palette.Add(palette_data[filename][i], i); } } } // The process for getting to this point has changed, so now if there is no palette entry for a texture it shouldn't be edited at all else { return(base.Process(input, context)); } // Otherwise we have palette data and the image will be remapped to color indices on the red channel input.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); int base_count = palette.Count; int new_colors = 0; foreach (MipmapChain image_face in input.Faces) { for (int i = 0; i < image_face.Count; i++) { PixelBitmapContent <Color> mip = (PixelBitmapContent <Color>)image_face[i]; Color original, edited; for (int y = 0; y < mip.Height; y++) { for (int x = 0; x < mip.Width; x++) { original = mip.GetPixel(x, y); // Checks for new colors not in the palette data // Why would those exist? //Yeti if (!palette.ContainsKey(original)) { // Gets the smallest whole number that is not already in the palette values int index = 0; while (palette.Values.ToList().Contains(index)) { index++; } // Adds a new color palette.Add(original, index); // Keeps track of how many new colors have been added new_colors++; } edited = new Color((palette[original] * 1) % 256, 0, 0, original.A); mip.SetPixel(x, y, edited); } } } } if (false) { //write_debug(doop + ", " + palette.Count.ToString()); write_debug(doop + ", " + new_colors.ToString() + "/" + palette.Count.ToString()); for (int i = base_count; i < palette.Count; i++) { foreach (KeyValuePair <Color, int> entry in palette) { if (entry.Value == i) { if (entry.Key.A > 0) { write_debug(entry.Key.ToString()); } break; } } } } return(base.Process(input, context)); }
public override TextureContent Process(TextureContent input, ContentProcessorContext context) { TextureContent colorTexture = input; // The color texture was passed to us as input, but we also need to go // load in the texture containing our alpha information. We locate this // using a naming convention: it should have the same name as the main // color texture, but with a "_alpha" suffix, so for instance "cat.jpg" // goes with "cat_alpha.jpg". string colorFilename = colorTexture.Identity.SourceFilename; string alphaFilename = Path.GetDirectoryName(colorFilename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(colorFilename) + "_alpha" + Path.GetExtension(colorFilename); // Ask the content pipeline to load in the alpha texture. ExternalReference <TextureContent> alphaReference; alphaReference = new ExternalReference <TextureContent>(alphaFilename); TextureContent alphaTexture; alphaTexture = context.BuildAndLoadAsset <TextureContent, TextureContent> (alphaReference, null); // Convert both textures to Color format, for ease of processing. colorTexture.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); alphaTexture.ConvertBitmapType(typeof(PixelBitmapContent <Color>)); PixelBitmapContent <Color> colorBitmap, alphaBitmap; colorBitmap = (PixelBitmapContent <Color>)colorTexture.Faces[0][0]; alphaBitmap = (PixelBitmapContent <Color>)alphaTexture.Faces[0][0]; if ((colorBitmap.Width != alphaBitmap.Width) || (colorBitmap.Height != alphaBitmap.Height)) { throw new InvalidContentException( "Color and alpha bitmaps are not the same size."); } // Merge the two bitmaps. for (int y = 0; y < colorBitmap.Height; y++) { for (int x = 0; x < colorBitmap.Width; x++) { Color color = colorBitmap.GetPixel(x, y); Color alphaAsGreyscale = alphaBitmap.GetPixel(x, y); byte alpha = (byte)((alphaAsGreyscale.R + alphaAsGreyscale.G + alphaAsGreyscale.B) / 3); Color combinedColor = new Color(color.R, color.G, color.B, alpha); colorBitmap.SetPixel(x, y, combinedColor); } } // Chain to the base SpriteTextureProcessor. return(base.Process(colorTexture, context)); }