/// <summary> /// Gets the channel value of a specific color. /// </summary> /// <param name="value">The color to get the channel.</param> /// <param name="channel">The channel to get.</param> /// <returns>The channel value.</returns> public static byte GetChannelValue(Color value, ColorChannels channel) { var arr = new List <byte>(); if (channel.HasFlag((ColorChannels)8)) { arr.Add(value.A); } if (channel.HasFlag(ColorChannels.Red)) { arr.Add(value.R); } if (channel.HasFlag(ColorChannels.Green)) { arr.Add(value.G); } if (channel.HasFlag(ColorChannels.Blue)) { arr.Add(value.B); } if (arr.Count == 0) { return(127); } float count = 0; foreach (var n in arr) { count += n; } return((byte)Math.Round(count / arr.Count)); }
/// <summary> /// Sets the color channel filter on currently displayed image based on selected color checkboxes. /// </summary> private void SetColorChannelFilter() { float r = RedChecked == true ? 1.0f : 0.0f; float g = GreenChecked == true ? 1.0f : 0.0f; float b = BlueChecked == true ? 1.0f : 0.0f; float a = AlphaChecked == true ? 1.0f : 0.0f; BitmapSource img; if (AlphaChecked == true) { img = alphaBitmap; } else { img = noAlphaBitmap; } ColorChannels CC = new ColorChannels() { Channel = new System.Windows.Media.Media3D.Point4D(r, g, b, a) }; ImageEffect = CC; ImageSource = img; }
/// <summary> /// Gets the number of bits used by the specified <see cref="ColorChannels"/> configuration. /// </summary> /// <param name="channel">The channel or channels to query.</param> /// <returns>The number of bits used by the <see cref="ColorChannels"/> specified.</returns> public override int BitsPerChannel(ColorChannels channel) { return((channel & ColorChannels.Red) == ColorChannels.Red ? 32 : 0 + (channel & ColorChannels.Green) == ColorChannels.Green ? 32 : 0 + (channel & ColorChannels.Blue) == ColorChannels.Blue ? 32 : 0 + (channel & ColorChannels.Alpha) == ColorChannels.Alpha ? 32 : 0); }
public override void Transform(ColorChannels channels) { foreach (var color in new[] { channels.Red, channels.Green, channels.Blue }) { Transform2D(color, false, this.Iterations); } }
byte[] get_color_channel(Texture2D source_tex, ColorChannels sourceChannel) { Color32[] cols = source_tex.GetPixels32(); byte[] ret = new byte[cols.Length]; if (sourceChannel == ColorChannels.R) { for (int i = 0; i < cols.Length; i++) { ret[i] = cols[i].r; } } if (sourceChannel == ColorChannels.G) { for (int i = 0; i < cols.Length; i++) { ret[i] = cols[i].g; } } if (sourceChannel == ColorChannels.B) { for (int i = 0; i < cols.Length; i++) { ret[i] = cols[i].b; } } if (sourceChannel == ColorChannels.A) { for (int i = 0; i < cols.Length; i++) { ret[i] = cols[i].a; } } return(ret); }
bool LsbExtract(ColorChannels channels, ref byte value, BitWriter bitWriter) { if (!_options.ColorChannelsToUse.Has(channels)) { return(true); } return(_lsbSteganographer.Extract(value, bitWriter)); }
bool LsbEmbed(ColorChannels channels, ref byte value, BitReader bitReader) { if (!_options.ColorChannelsToUse.Has(channels)) { return(true); } return(_lsbSteganographer.Embed(ref value, bitReader)); }
byte[] get_color_channel(Texture2D source_tex, ColorChannels sourceChannel) { Color32[] cols=source_tex.GetPixels32(); byte[] ret=new byte[cols.Length]; if (sourceChannel==ColorChannels.R) for(int i=0; i<cols.Length; i++) ret[i]=cols[i].r; if (sourceChannel==ColorChannels.G) for(int i=0; i<cols.Length; i++) ret[i]=cols[i].g; if (sourceChannel==ColorChannels.B) for(int i=0; i<cols.Length; i++) ret[i]=cols[i].b; if (sourceChannel==ColorChannels.A) for(int i=0; i<cols.Length; i++) ret[i]=cols[i].a; return ret; }
public override int BitsPerChannel(ColorChannels channel) { if (channel == ColorChannels.Black) { return(32); } else { return(0); } }
private void OnChannelChanged(ColorChannels colorChannel, bool newValue) { // If Shift is pressed, we toggle RGB together. if (colorChannel != ColorChannels.Alpha && (Keyboard.Modifiers & ModifierKeys.Shift) != 0) { EnableRedChannel = newValue; EnableGreenChannel = newValue; EnableBlueChannel = newValue; } }
/// <summary> /// Creates new instance of blend state /// </summary> /// <param name="mask"></param> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="srcA"></param> /// <param name="dstA"></param> public static BlendState Create ( ColorChannels mask=ColorChannels.All, Blend src = Blend.One, Blend dst = Blend.Zero, Blend srcA = Blend.One, Blend dstA = Blend.Zero ) { BlendState bs = new BlendState(); bs.SrcColor = src; bs.DstColor = dst; bs.SrcAlpha = srcA; bs.DstAlpha = dstA; bs.ColorOp = BlendOp.Add; bs.AlphaOp = BlendOp.Add; bs.WriteMask = mask; bs.MultiSampleMask = -1; bs.BlendFactor = new Color4(0,0,0,0); return bs; }
private void hsvComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (hsvInputImgBox.Image != null) { if (hsvComboBox.SelectedItem.Equals("S channel")) { var imageOperations = new ColorChannels(); hsvOutputImgBox.Image = imageOperations.SaveSChannel(hsvInputImgBox.Image); } else if (hsvComboBox.SelectedItem.Equals("V channel")) { hsvOutputImgBox.Image = new ColorChannels().SaveVChannel(hsvInputImgBox.Image); } } }
/// <summary> /// Creates new instance of blend state /// </summary> /// <param name="mask"></param> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="srcA"></param> /// <param name="dstA"></param> public static BlendState Create(ColorChannels mask = ColorChannels.All, Blend src = Blend.One, Blend dst = Blend.Zero, Blend srcA = Blend.One, Blend dstA = Blend.Zero) { BlendState bs = new BlendState(); bs.SrcColor = src; bs.DstColor = dst; bs.SrcAlpha = srcA; bs.DstAlpha = dstA; bs.ColorOp = BlendOp.Add; bs.AlphaOp = BlendOp.Add; bs.WriteMask = mask; bs.MultiSampleMask = -1; bs.BlendFactor = new Color4(0, 0, 0, 0); return(bs); }
/// <summary> /// Adjusts color balance. /// </summary> /// <param name="value">The source color value.</param> /// <param name="channel">The channel to set.</param> /// <param name="ratio">The ratio to change. Value is from -1 to 1.</param> /// <returns>The color after color balance.</returns> public static Color ColorBalance(Color value, ColorChannels channel, float ratio) { if (ratio == 0) { return(value); } var white = ratio > 0 ? 255 : 0; var black = ratio < 0 ? 255 : 0; ratio = Math.Abs(ratio); return(Color.FromArgb( value.A, ToChannel(((channel.HasFlag(ColorChannels.Red) ? white : black) - value.R) * ratio + value.R), ToChannel(((channel.HasFlag(ColorChannels.Green) ? white : black) - value.G) * ratio + value.G), ToChannel(((channel.HasFlag(ColorChannels.Blue) ? white : black) - value.B) * ratio + value.B))); }
public static JpegEncoder WithImageFromFile(string filename) { FileStream fileStream = new FileStream(filename, FileMode.Open); MemoryStream memoryStream = new MemoryStream(); fileStream.CopyTo(memoryStream); fileStream.Close(); memoryStream.Seek(0, SeekOrigin.Begin); RGBImage rgbImage = RGBImage.RGBImageBuilder.From(memoryStream).Build(); YCbCrImage yCbCrImage = ColorChannels.RgbToYCbCr(rgbImage); return(new JpegEncoder(yCbCrImage)); }
void OnEnable() { #if (UNITY_5_0) title = "UV Inspector"; #else titleContent = new GUIContent("UV Inspector"); #endif this.minSize = new Vector2(350, 400); previewUVSet = (UVSet)EditorPrefs.GetInt("nTools.UVInspector.previewUVSet", (int)previewUVSet); subMeshToggleField = EditorPrefs.GetInt("nTools.UVInspector.subMeshToggleField", subMeshToggleField.bitfield); showVertexColors = EditorPrefs.GetBool("nTools.UVInspector.showVertexColors", showVertexColors); showGrid = EditorPrefs.GetBool("nTools.UVInspector.showGrid", showGrid); showSubmeshesByOne = EditorPrefs.GetBool("nTools.UVInspector.showSubmeshesByOne", showSubmeshesByOne); tilePreviewTexture = EditorPrefs.GetBool("nTools.UVInspector.tilePreviewTexture", tilePreviewTexture); previewTextureSource = (PreviewTextureSource)EditorPrefs.GetInt("nTools.UVInspector.previewTextureSource", (int)previewTextureSource); customPreviewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(EditorPrefs.GetString("nTools.UVInspector.customPreviewTexture", ""), typeof(Texture2D)); previewTextureTintColor = IntToColor(EditorPrefs.GetInt("nTools.UVInspector.previewTextureTintColor", ColorToInt(previewTextureTintColor))); preferredTextureProperty = EditorPrefs.GetString("nTools.UVInspector.preferredTextureProperty", preferredTextureProperty); previewTextureChannels = (ColorChannels)EditorPrefs.GetInt("nTools.UVInspector.previewTextureChannels", (int)previewTextureChannels); settingsFoldout = EditorPrefs.GetBool("nTools.UVInspector.settingsFoldout", settingsFoldout); previewFoldout = EditorPrefs.GetBool("nTools.UVInspector.previewFoldout", previewFoldout); if (!LoadMaterials()) { Debug.LogWarning("UV Inspector Error: shaders not found. Reimport asset."); Close(); return; } #if NO_ON_SELECTION_CHANGED if (EditorApplication.update != OnEditorUpdate) { EditorApplication.update += OnEditorUpdate; } #else if (Selection.selectionChanged != OnSelectionChanged) { Selection.selectionChanged += OnSelectionChanged; } #endif LoadMeshes(); }
static void ApplyWavelet() { int times = 7; string[] images = Directory.GetFiles(@"..\..\..\TestHaarCSharp\Resources_Noisy\", "*", SearchOption.AllDirectories); Parallel.ForEach(images, (i) => { Bitmap initial = new Bitmap(Image.FromFile(i)); //var res = AddNoise(initial, 50); //res.Save($@"..\..\..\TestHaarCSharp\Resources_noisy\{Path.GetFileName(i)}", res.RawFormat); Bitmap forward = new Bitmap(initial); var channels = ColorChannels.CreateColorChannels(initial.Width, initial.Height); var transform = WaveletTransform.CreateTransform(true, times); var imageProcessor = new ImageProcessor(channels, transform); imageProcessor.ApplyTransform(forward); string newPath = Path.Combine(@"..\..\..\TestHaarCSharp\Forward_Noisy", Path.GetFileName(i)); string dirName = Path.GetDirectoryName(newPath); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } forward.Save(newPath, initial.RawFormat); Bitmap inverse = new Bitmap(forward); transform = WaveletTransform.CreateTransform(false, times); imageProcessor = new ImageProcessor(channels, transform); imageProcessor.ApplyTransform(inverse); var rmse = GetRMSE(initial, inverse); newPath = Path.Combine(@"..\..\..\TestHaarCSharp\Inverse_Noisy", $"{Path.GetFileNameWithoutExtension(i)}_{rmse.ToString("#.##")}{Path.GetExtension(i)}"); dirName = Path.GetDirectoryName(newPath); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } inverse.Save(newPath, inverse.RawFormat); }); }
/// <summary> /// Gets a bit mask that indicates which portions of a pixel are occupied by the specified color channels. /// </summary> /// <param name="channels">The color channel(s) to get the mask for.</param> /// <returns>A new byte array that is the same number of bytes as required to represent a single pixel.</returns> public override byte[] GetBitMask(ColorChannels channels) { var result = new byte[12]; if ((channels & ColorChannels.Red) == ColorChannels.Red) { result[0] = result[1] = result[2] = result[3] = 0xFF; } if ((channels & ColorChannels.Green) == ColorChannels.Green) { result[4] = result[5] = result[6] = result[7] = 0xFF; } if ((channels & ColorChannels.Blue) == ColorChannels.Blue) { result[8] = result[9] = result[10] = result[11] = 0xFF; } return(result); }
private Bitmap ApplyHaarTransform(bool forward, bool safe, int iterations, Bitmap bmp) { var maxScale = WaveletTransform.GetMaxScale(bmp.Width, bmp.Height); if (iterations < 1 || iterations > maxScale) { MessageBox.Show(string.Format("Iteration must be Integer from 1 to {0}", maxScale)); return(new Bitmap(bmp.Width, bmp.Height)); } var channels = ColorChannels.CreateColorChannels(safe, bmp.Width, bmp.Height); var transform = WaveletTransform.CreateTransform(forward, iterations); var imageProcessor = new ImageProcessor(channels, transform); imageProcessor.ApplyTransform(bmp); return(bmp); }
/// <summary> /// Gets a bit mask that indicates which portions of a pixel are occupied by the specified color channels. /// </summary> /// <param name="channels">The color channel(s) to get the mask for.</param> /// <returns>A new byte array that is the same number of bytes as required to represent a single pixel.</returns> public override byte[] GetBitMask(ColorChannels channels) { var result = new byte[4]; if ((channels & ColorChannels.Red) == ColorChannels.Red) { result[0] = 0xFF; } if ((channels & ColorChannels.Green) == ColorChannels.Green) { result[1] = 0xFF; } if ((channels & ColorChannels.Blue) == ColorChannels.Blue) { result[2] = 0xFF; } if ((channels & ColorChannels.Alpha) == ColorChannels.Alpha) { result[3] = 0xFF; } return(result); }
/// <summary> /// Gets a bit mask that indicates which portions of a pixel are occupied by the specified color channels. /// </summary> /// <param name="channels">The color channel(s) to get the mask for.</param> /// <returns>A new byte array that is the same number of bytes as required to represent a single pixel.</returns> public override byte[] GetBitMask(ColorChannels channels) { var result = new byte[16]; if ((channels & ColorChannels.Red) == ColorChannels.Red) { result[0x0] = result[0x1] = result[0x2] = result[0x3] = 0xFF; } if ((channels & ColorChannels.Green) == ColorChannels.Green) { result[0x4] = result[0x5] = result[0x6] = result[0x7] = 0xFF; } if ((channels & ColorChannels.Blue) == ColorChannels.Blue) { result[0x8] = result[0x9] = result[0xA] = result[0xB] = 0xFF; } if ((channels & ColorChannels.Alpha) == ColorChannels.Alpha) { result[0xC] = result[0xD] = result[0xE] = result[0xF] = 0xFF; } return(result); }
// This variation works with three dimensional arrays (used in OpenCV) public static void Gaussian(byte[, ,] original, byte[, ,] destination, int rows, int cols, ColorChannels channels) { int sum_r, sum_g, sum_b; for (int i = 2; i < rows - 2; i++) { for (int j = 2; j < cols - 2; j++) { sum_r = 0; sum_g = 0; sum_b = 0; for (int ri = -2; ri <= 2; ri++) { for (int ci = -2; ci <= 2; ci++) { switch (channels) { case ColorChannels.Red: sum_r += original[i + ri, j + ci, 2] * gaussianMatrix[ri + 2, ci + 2]; break; case ColorChannels.Green: sum_g += original[i + ri, j + ci, 1] * gaussianMatrix[ri + 2, ci + 2]; break; case ColorChannels.Blue: sum_b += original[i + ri, j + ci, 0] * gaussianMatrix[ri + 2, ci + 2]; break; case ColorChannels.RGB: case ColorChannels.ARGB: sum_r += original[i + ri, j + ci, 2] * gaussianMatrix[ri + 2, ci + 2]; sum_g += original[i + ri, j + ci, 1] * gaussianMatrix[ri + 2, ci + 2]; sum_b += original[i + ri, j + ci, 0] * gaussianMatrix[ri + 2, ci + 2]; break; case ColorChannels.Gray: sum_b += original[i + ri, j + ci, 0] * gaussianMatrix[ri + 2, ci + 2]; break; default: break; } // End switch } // End ci } // End ri switch (channels) { case ColorChannels.Red: destination[i, j, 2] = (byte)(sum_r / 256f); break; case ColorChannels.Green: destination[i, j, 1] = (byte)(sum_g / 256f); break; case ColorChannels.Gray: case ColorChannels.Blue: destination[i, j, 0] = (byte)(sum_b / 256f); break; case ColorChannels.RGB: case ColorChannels.ARGB: destination[i, j, 2] = (byte)(sum_r / 256f); destination[i, j, 1] = (byte)(sum_g / 256f); destination[i, j, 0] = (byte)(sum_b / 256f); break; default: break; } // End switch } // End j } // End i } // End Gaussian Filter
public static bool Has(this ColorChannels first, ColorChannels second) { return((first & second) == second); }
public override void Copy_to_Array(ref int[] dest, ColorChannels numChannels) { throw new NotImplementedException(); }
/// <summary> /// Applies a convolution filter to the drawing image. /// </summary> /// <param name="filter">The convolution filter.</param> /// <param name="colorChannels">The color channels to modify.</param> public void Filter(BitmapFilter filter, ColorChannels colorChannels = ColorChannels.All) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } filter.Apply(this.image, colorChannels); }
/// <summary> /// Gets the texture data and displays it for the currently selected item given a specified race, part, type(if applicable), and map /// </summary> private void MapComboBoxChanged() { if (saveClone != null) { //saveClone.UnlockBits(cloneLock); saveClone.Dispose(); } Bitmap colorBmp = null; int offset = 0; bool isVFX = false; bool isUI = false; if (selectedMap.Name.Equals(Strings.Normal)) { fullPath = mtrlData.NormalPath; offset = mtrlData.NormalOffset; FullPathString = fullPath; } else if (selectedMap.Name.Equals(Strings.Specular)) { fullPath = mtrlData.SpecularPath; offset = mtrlData.SpecularOffset; FullPathString = fullPath; } else if (selectedMap.Name.Equals(Strings.Diffuse)) { fullPath = mtrlData.DiffusePath; offset = mtrlData.DiffuseOffset; FullPathString = fullPath; } else if (selectedMap.Name.Equals(Strings.Mask) || selectedMap.Name.Equals(Strings.Skin)) { if (selectedItem.ItemName.Equals(Strings.Face_Paint) || selectedItem.ItemName.Equals(Strings.Equipment_Decals)) { string part; if (selectedItem.ItemName.Equals(Strings.Equipment_Decals)) { if (!SelectedPart.Name.Contains("stigma")) { part = selectedPart.Name.PadLeft(3, '0'); } else { part = SelectedPart.Name; } } else { part = selectedPart.Name; } fullPath = String.Format(mtrlData.MaskPath, part); offset = MTRL.GetDecalOffset(selectedItem.ItemName, selectedPart.Name); } else { fullPath = mtrlData.MaskPath; offset = mtrlData.MaskOffset; } FullPathString = fullPath; } else if (selectedMap.Name.Equals(Strings.ColorSet)) { colorBmp = TEX.TextureToBitmap(mtrlData.ColorData, 9312, 4, 16); fullPath = mtrlData.MTRLPath; FullPathString = fullPath; } else if (SelectedMap.Name.Contains("Icon")) { if (SelectedMap.Name.Contains("HQ")) { fullPath = mtrlData.UIHQPath; offset = mtrlData.UIHQOffset; } else { fullPath = mtrlData.UIPath; offset = mtrlData.UIOffset; } FullPathString = fullPath; isUI = true; } else if (selectedItem.ItemCategory.Equals(Strings.Maps)) { if (selectedMap.Name.Contains("HighRes Map")) { fullPath = string.Format(mtrlData.UIPath, "_m"); offset = mtrlData.UIOffset = int.Parse(selectedMap.ID); } else if (selectedMap.Name.Contains("LowRes Map")) { fullPath = string.Format(mtrlData.UIPath, "_s"); offset = mtrlData.UIOffset = int.Parse(selectedMap.ID); } else if (selectedMap.Name.Contains("PoI")) { fullPath = string.Format(mtrlData.UIPath, "d"); offset = mtrlData.UIOffset = int.Parse(selectedMap.ID); } else if (selectedMap.Name.Contains("HighRes Mask")) { fullPath = string.Format(mtrlData.UIPath, "m_m"); offset = mtrlData.UIOffset = int.Parse(selectedMap.ID); } else if (selectedMap.Name.Contains("LowRes Mask")) { fullPath = string.Format(mtrlData.UIPath, "m_s"); offset = mtrlData.UIOffset = int.Parse(selectedMap.ID); } FullPathString = fullPath; isUI = true; } else if (selectedItem.ItemCategory.Equals("HUD") || selectedItem.ItemCategory.Equals("LoadingImage")) { fullPath = mtrlData.UIPath; offset = mtrlData.UIOffset; FullPathString = fullPath; isUI = true; } else { fullPath = SelectedMap.ID; var VFXFolder = fullPath.Substring(0, fullPath.LastIndexOf("/")); var VFXFile = fullPath.Substring(fullPath.LastIndexOf("/") + 1); offset = Helper.GetDataOffset(FFCRC.GetHash(VFXFolder), FFCRC.GetHash(VFXFile), Strings.ItemsDat); FullPathString = fullPath; isVFX = true; } string line; JsonEntry modEntry = null; bool inModList = false; try { using (StreamReader sr = new StreamReader(Properties.Settings.Default.Modlist_Directory)) { while ((line = sr.ReadLine()) != null) { modEntry = JsonConvert.DeserializeObject <JsonEntry>(line); if (modEntry.fullPath.Equals(fullPath)) { inModList = true; break; } } } } catch (Exception ex) { MessageBox.Show("[TVM] Error Accessing .modlist File \n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } if (inModList) { var currOffset = Helper.GetDataOffset(FFCRC.GetHash(modEntry.fullPath.Substring(0, modEntry.fullPath.LastIndexOf("/"))), FFCRC.GetHash(Path.GetFileName(modEntry.fullPath)), modEntry.datFile); if (currOffset == modEntry.modOffset) { ActiveToggle = "Disable"; } else if (currOffset == modEntry.originalOffset) { ActiveToggle = "Enable"; } else { ActiveToggle = "Error"; } ActiveEnabled = true; } else { ActiveEnabled = false; ActiveToggle = "Enable/Disable"; } if (offset == 0) { TextureType = "Type: 16.16.16.16f ABGR\nMipMaps: None"; TextureDimensions = "(4 x 16)"; alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); alphaBitmap.Freeze(); var removeAlphaBitmap = SetAlpha(colorBmp, 255); noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); noAlphaBitmap.Freeze(); colorBmp.Dispose(); removeAlphaBitmap.Dispose(); } else { if (!isVFX) { if (!isUI) { texData = TEX.GetTex(offset, Strings.ItemsDat); } else { texData = TEX.GetTex(offset, Strings.UIDat); } } else { texData = TEX.GetVFX(offset, Strings.ItemsDat); } string mipMaps = "Yes (" + texData.MipCount + ")"; if (texData.MipCount < 1) { mipMaps = "None"; } TextureType = "Type: " + texData.TypeString + "\nMipMaps: " + mipMaps; TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")"; var clonerect = new Rectangle(0, 0, texData.Width, texData.Height); saveClone = texData.BMP.Clone(new Rectangle(0, 0, texData.Width, texData.Height), PixelFormat.Format32bppArgb); alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); alphaBitmap.Freeze(); if (!isUI) { var removeAlphaBitmap = SetAlpha(texData.BMP, 255); noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); noAlphaBitmap.Freeze(); removeAlphaBitmap.Dispose(); } } try { ImageEffect = new ColorChannels() { Channel = new System.Windows.Media.Media3D.Point4D(1.0f, 1.0f, 1.0f, 0.0f) }; } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } if (!isUI) { ImageSource = noAlphaBitmap; SetColorChannelFilter(imageEffect); ChannelsEnabled = true; } else { ImageSource = alphaBitmap; SetColorChannelFilter(imageEffect); ChannelsEnabled = true; } SaveEnabled = true; texData.Dispose(); string dxPath = Path.GetFileNameWithoutExtension(fullPath); string savePath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemName + "/" + dxPath + ".dds"; if (selectedCategory.Equals("UI")) { savePath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemCategory + "/" + dxPath + ".dds"; } if (File.Exists(savePath)) { ImportEnabled = true; } else { ImportEnabled = false; } string folderPath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemName; if (selectedCategory.Equals("UI")) { folderPath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemCategory; } if (Directory.Exists(folderPath)) { OpenEnabled = true; } else { OpenEnabled = false; } }
private bool checkChange(ref ColorChannels val, ColorChannels nval) { bool changed=(nval!=val); if (changed) { if ((EditorApplication.timeSinceStartup-changedTime)>0.5) { changedTime=EditorApplication.timeSinceStartup; Undo.RegisterUndo((ReliefTerrain)target, "Undo relief terrain edit"); } } dirtyFlag=dirtyFlag || changed; val=nval; return changed; }
/// <summary> /// Initializes a new instance of the <see cref="ColorChannelShiftEffect"/> class. /// </summary> /// <param name="channel">The channel.</param> public ColorChannelShiftEffect(ColorChannels channel) { this.ColorChannel = channel; }
public override void Copy_to_Array(ref byte[] dest, ColorChannels numChannels) { int size = localImage.Height * localImage.Width; byte* ptr = Scan0; unsafe { switch(numChannels) { case ColorChannels.Gray: for(int n = 0; n < dest.Length; n++) { dest[n] = (byte)((*ptr++ * 0.3) + (*ptr++ * 0.59) + (*ptr++ * 0.11)); ptr++; } break; case ColorChannels.RGB: for(int n = 0; n < dest.Length; n += 3) { dest[n + 0] = *ptr++; dest[n + 1] = *ptr++; dest[n + 2] = *ptr++; ptr++; } break; case ColorChannels.RGBA: for(int n = 0; n < dest.Length; n++) dest[n] = *ptr++; break; default: break; } } }
internal GenerateTask(float value, ColorChannels colorChannels) : base(value, colorChannels) { }
public PixelFormatInfo(int bitsPerPixel, ColorModel model, ColorChannels channels) { BitsPerPixel = bitsPerPixel; ColorModel = model; Channels = channels; }
public override byte[] GetBitMask(ColorChannels channels) { throw new NotImplementedException(); }
/// <summary> /// Gets the number of bits used by the specified <see cref="ColorChannels"/> configuration. /// </summary> /// <param name="channel">The channel or channels to query.</param> /// <returns>The number of bits used by the <see cref="ColorChannels"/> specified.</returns> public abstract int BitsPerChannel(ColorChannels channel);
public override void Copy_to_Array(ref byte[] dest, ColorChannels numChannels) { int size = localImage.Height * localImage.Width; unsafe { switch(numChannels) { case ColorChannels.Gray: Marshal.Copy(ImageData.Scan0, dest, 0, size); //Array.Copy((byte[])ImageData.Scan0, dest, size); break; case ColorChannels.RGB: { byte *pSrc = Scan0; byte *pSrcEnd = Scan0 + size; fixed(byte *d = dest) { byte *pDest = d; for(; pSrc < pSrcEnd; pSrc++) { byte value = *pSrc; *(pDest++) = value;// B *(pDest++) = value;// G *(pDest++) = value;// R } } } break; case ColorChannels.RGBA: { byte *pSrc = Scan0; byte *pSrcEnd = Scan0 + size; fixed(byte *d = dest) { byte *pDest = d; for(; pSrc < pSrcEnd; pSrc++) { byte value = *pSrc; *(pDest++) = value;// B *(pDest++) = value;// G *(pDest++) = value;// R *(pDest++) = 1;// A } } } break; default: break; } } }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- private void OnChannelChanged(ColorChannels colorChannel, bool newValue) { // If Shift is pressed, we toggle RGB together. if (colorChannel != ColorChannels.Alpha && (Keyboard.Modifiers & ModifierKeys.Shift) != 0) { EnableRedChannel = newValue; EnableGreenChannel = newValue; EnableBlueChannel = newValue; } }
public override void Copy_to_Array(ref int[] dest, ColorChannels numChannels) { byte* ptr = Scan0; int* dest_ptr = (int*)ptr; for (int n = 0; n < dest.Length; n++) dest[n] = *dest_ptr++; }
/// <summary> /// Gets the texture data and displays it for the currently selected item given a specified race, part, type(if applicable), and map /// </summary> private void MapComboBoxChanged() { Bitmap colorBmp = null; int offset = 0; bool isVFX = false; if (selectedMap.Name.Equals(Strings.Normal)) { fullPath = mtrlData.NormalPath; offset = mtrlData.NormalOffset; FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]"; } else if (selectedMap.Name.Equals(Strings.Specular)) { fullPath = mtrlData.SpecularPath; offset = mtrlData.SpecularOffset; FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]"; } else if (selectedMap.Name.Equals(Strings.Diffuse)) { fullPath = mtrlData.DiffusePath; offset = mtrlData.DiffuseOffset; FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]"; } else if (selectedMap.Name.Equals(Strings.Mask) || selectedMap.Name.Equals(Strings.Skin)) { if (selectedItem.ItemName.Equals(Strings.Face_Paint) || selectedItem.ItemName.Equals(Strings.Equipment_Decals)) { string part; if (selectedItem.ItemName.Equals(Strings.Equipment_Decals)) { part = selectedPart.Name.PadLeft(3, '0'); } else { part = selectedPart.Name; } fullPath = String.Format(mtrlData.MaskPath, part); offset = MTRL.GetDecalOffset(selectedItem.ItemName, selectedPart.Name); FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]"; } else { fullPath = mtrlData.MaskPath; offset = mtrlData.MaskOffset; FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]"; } } else if (selectedMap.Name.Equals(Strings.ColorSet)) { colorBmp = TEX.TextureToBitmap(mtrlData.ColorData, 9312, 4, 16); fullPath = mtrlData.MTRLPath; FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]"; } else { fullPath = SelectedMap.ID; var VFXFolder = fullPath.Substring(0, fullPath.LastIndexOf("/")); var VFXFile = fullPath.Substring(fullPath.LastIndexOf("/") + 1); offset = Helper.GetItemOffset(FFCRC.GetHash(VFXFolder), FFCRC.GetHash(VFXFile)); FullPathString = fullPath; isVFX = true; } if (Properties.Settings.Default.Mod_List == 0) { string line; JsonEntry modEntry = null; bool inModList = false; try { using (StreamReader sr = new StreamReader(Info.modListDir)) { while ((line = sr.ReadLine()) != null) { modEntry = JsonConvert.DeserializeObject <JsonEntry>(line); if (modEntry.fullPath.Equals(fullPath)) { inModList = true; break; } } } } catch (Exception ex) { MessageBox.Show("[Main] Error Accessing .modlist File \n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } if (inModList) { var currOffset = Helper.GetItemOffset(FFCRC.GetHash(modEntry.fullPath.Substring(0, modEntry.fullPath.LastIndexOf("/"))), FFCRC.GetHash(Path.GetFileName(modEntry.fullPath))); if (currOffset == modEntry.modOffset) { ActiveToggle = "Disable"; } else if (currOffset == modEntry.originalOffset) { ActiveToggle = "Enable"; } else { ActiveToggle = "Error"; } ActiveEnabled = true; } else { ActiveEnabled = false; ActiveToggle = "Enable/Disable"; } } else { ActiveEnabled = false; ActiveToggle = "Enable/Disable"; } if (offset == 0) { TextureType = "A16B16G16R16F"; textureType = "A16B16G16R16F"; TextureDimensions = "(4 x 16)"; textureDimensions = "(4 x 16)"; alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); var removeAlphaBitmap = SetAlpha(colorBmp, 255); noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); colorBmp.Dispose(); removeAlphaBitmap.Dispose(); } else { if (!isVFX) { texData = TEX.GetTex(offset); } else { texData = TEX.GetVFX(offset); } TextureType = texData.TypeString; TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")"; alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); var removeAlphaBitmap = SetAlpha(texData.BMP, 255); noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); removeAlphaBitmap.Dispose(); } try { ImageEffect = new ColorChannels() { Channel = new System.Windows.Media.Media3D.Point4D(1.0f, 1.0f, 1.0f, 0.0f) }; } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } ImageSource = noAlphaBitmap; SetColorChannelFilter(); SaveEnabled = true; texData.Dispose(); string dxPath = Path.GetFileNameWithoutExtension(fullPath); if (File.Exists(Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemName + "/" + dxPath + ".dds")) { ImportEnabled = true; } else { ImportEnabled = false; } }
protected AdjustColorsTaskBase(float value, ColorChannels colorChannels) { Value = value; ColorChannels = colorChannels; }
public void RestorePreset(ReliefTerrainPresetHolder holder) { numLayers=holder.numLayers; splats=new Texture2D[holder.splats.Length]; for(int i=0; i<holder.splats.Length; i++) { splats[i]=holder.splats[i]; } splat_atlases=new Texture2D[holder.splat_atlases.Length]; for(int i=0; i<splat_atlases.Length; i++) { splat_atlases[i]=holder.splat_atlases[i]; } RTP_MIP_BIAS=holder.RTP_MIP_BIAS; _SpecColor=holder._SpecColor; SuperDetailA_channel=holder.SuperDetailA_channel; SuperDetailB_channel=holder.SuperDetailB_channel; Bump01=holder.Bump01; Bump23=holder.Bump23; Bump45=holder.Bump45; Bump67=holder.Bump67; Bump89=holder.Bump89; BumpAB=holder.BumpAB; SSColorCombined=holder.SSColorCombined; BumpGlobal=holder.BumpGlobal; VerticalTexture=holder.VerticalTexture; BumpMapGlobalScale=holder.BumpMapGlobalScale; GlobalColorMapBlendValues=holder.GlobalColorMapBlendValues; GlobalColorMapSaturation=holder.GlobalColorMapSaturation; GlobalColorMapBrightness=holder.GlobalColorMapBrightness; _GlobalColorMapNearMIP=holder._GlobalColorMapNearMIP; _FarNormalDamp=holder._FarNormalDamp; blendMultiplier=holder.blendMultiplier; HeightMap=holder.HeightMap; HeightMap2=holder.HeightMap2; HeightMap3=holder.HeightMap3; ReliefTransform=holder.ReliefTransform; DIST_STEPS=holder.DIST_STEPS; WAVELENGTH=holder.WAVELENGTH; ReliefBorderBlend=holder.ReliefBorderBlend; ExtrudeHeight=holder.ExtrudeHeight; LightmapShading=holder.LightmapShading; SHADOW_STEPS=holder.SHADOW_STEPS; WAVELENGTH_SHADOWS=holder.WAVELENGTH_SHADOWS; SHADOW_SMOOTH_STEPS=holder.SHADOW_SMOOTH_STEPS; SelfShadowStrength=holder.SelfShadowStrength; ShadowSmoothing=holder.ShadowSmoothing; ShadowColor=holder.ShadowColor; distance_start=holder.distance_start; distance_transition=holder.distance_transition; distance_start_bumpglobal=holder.distance_start_bumpglobal; distance_transition_bumpglobal=holder.distance_transition_bumpglobal; rtp_perlin_start_val=holder.rtp_perlin_start_val; trees_shadow_distance_start=holder.trees_shadow_distance_start; trees_shadow_distance_transition=holder.trees_shadow_distance_transition; trees_shadow_value=holder.trees_shadow_value; trees_pixel_distance_start=holder.trees_pixel_distance_start; trees_pixel_distance_transition=holder.trees_pixel_distance_transition; trees_pixel_blend_val=holder.trees_pixel_blend_val; global_normalMap_multiplier=holder.global_normalMap_multiplier; rtp_mipoffset_globalnorm=holder.rtp_mipoffset_globalnorm; _SuperDetailTiling=holder._SuperDetailTiling; SuperDetailA=holder.SuperDetailA; SuperDetailB=holder.SuperDetailB; // reflection TERRAIN_ReflectionMap=holder.TERRAIN_ReflectionMap; TERRAIN_ReflectionMap_channel=holder.TERRAIN_ReflectionMap_channel; TERRAIN_ReflColorA=holder.TERRAIN_ReflColorA; TERRAIN_ReflColorB=holder.TERRAIN_ReflColorB; TERRAIN_ReflDistortion=holder.TERRAIN_ReflDistortion; TERRAIN_ReflectionRotSpeed=holder.TERRAIN_ReflectionRotSpeed; TERRAIN_FresnelPow=holder.TERRAIN_FresnelPow; TERRAIN_FresnelOffset=holder.TERRAIN_FresnelOffset; // water/wet TERRAIN_GlobalWetness=holder.TERRAIN_GlobalWetness; TERRAIN_WaterSpecularity=holder.TERRAIN_WaterSpecularity; TERRAIN_RippleMap=holder.TERRAIN_RippleMap; TERRAIN_RippleScale=holder.TERRAIN_RippleScale; TERRAIN_FlowScale=holder.TERRAIN_FlowScale; TERRAIN_FlowSpeed=holder.TERRAIN_FlowSpeed; TERRAIN_FlowMipOffset=holder.TERRAIN_FlowMipOffset; TERRAIN_WetDarkening=holder.TERRAIN_WetDarkening; TERRAIN_WetDropletsStrength=holder.TERRAIN_WetDropletsStrength; TERRAIN_RainIntensity=holder.TERRAIN_RainIntensity; TERRAIN_DropletsSpeed=holder.TERRAIN_DropletsSpeed; TERRAIN_mipoffset_flowSpeed=holder.TERRAIN_mipoffset_flowSpeed; // caustics TERRAIN_CausticsAnimSpeed=holder.TERRAIN_CausticsAnimSpeed; TERRAIN_CausticsColor=holder.TERRAIN_CausticsColor; TERRAIN_CausticsWaterLevel=holder.TERRAIN_CausticsWaterLevel; TERRAIN_CausticsWaterLevelByAngle=holder.TERRAIN_CausticsWaterLevelByAngle; TERRAIN_CausticsWaterDeepFadeLength=holder.TERRAIN_CausticsWaterDeepFadeLength; TERRAIN_CausticsWaterShallowFadeLength=holder.TERRAIN_CausticsWaterShallowFadeLength; TERRAIN_CausticsTilingScale=holder.TERRAIN_CausticsTilingScale; TERRAIN_CausticsTex=holder.TERRAIN_CausticsTex; rtp_customAmbientCorrection=holder.rtp_customAmbientCorrection; RTP_AOsharpness=holder.RTP_AOsharpness; RTP_AOamp=holder.RTP_AOamp; RTP_LightDefVector=holder.RTP_LightDefVector; RTP_ReflexLightDiffuseColor=holder.RTP_ReflexLightDiffuseColor; RTP_ReflexLightSpecColor=holder.RTP_ReflexLightSpecColor; VerticalTextureGlobalBumpInfluence=holder.VerticalTextureGlobalBumpInfluence; VerticalTextureTiling=holder.VerticalTextureTiling; // snow _snow_strength=holder._snow_strength; _global_color_brightness_to_snow=holder._global_color_brightness_to_snow; _snow_slope_factor=holder._snow_slope_factor; _snow_edge_definition=holder._snow_edge_definition; _snow_height_treshold=holder._snow_height_treshold; _snow_height_transition=holder._snow_height_transition; _snow_color=holder._snow_color; _snow_specular=holder._snow_specular; _snow_gloss=holder._snow_gloss; _snow_reflectivness=holder._snow_reflectivness; _snow_deep_factor=holder._snow_deep_factor; ////////////////////// // layer_dependent arrays ////////////////////// Bumps=new Texture2D[holder.Bumps.Length]; Spec=new float[holder.Bumps.Length]; FarGlossCorrection=new float[holder.Bumps.Length]; MixScale=new float[holder.Bumps.Length]; MixBlend=new float[holder.Bumps.Length]; MixSaturation=new float[holder.Bumps.Length]; GlobalColorPerLayer=new float[holder.Bumps.Length]; PER_LAYER_HEIGHT_MODIFIER=new float[holder.Bumps.Length]; _SuperDetailStrengthMultA=new float[holder.Bumps.Length]; _SuperDetailStrengthMultASelfMaskNear=new float[holder.Bumps.Length]; _SuperDetailStrengthMultASelfMaskFar=new float[holder.Bumps.Length]; _SuperDetailStrengthMultB=new float[holder.Bumps.Length]; _SuperDetailStrengthMultBSelfMaskNear=new float[holder.Bumps.Length]; _SuperDetailStrengthMultBSelfMaskFar=new float[holder.Bumps.Length]; _SuperDetailStrengthNormal=new float[holder.Bumps.Length]; _BumpMapGlobalStrength=new float[holder.Bumps.Length]; AO_strength=new float[holder.Bumps.Length]; VerticalTextureStrength=new float[holder.Bumps.Length]; Heights=new Texture2D[holder.Bumps.Length]; _snow_strength_per_layer=new float[holder.Bumps.Length]; Substances=new ProceduralMaterial[holder.Bumps.Length]; // wet TERRAIN_LayerWetStrength=new float[holder.Bumps.Length]; TERRAIN_WaterLevel=new float[holder.Bumps.Length]; TERRAIN_WaterLevelSlopeDamp=new float[holder.Bumps.Length]; TERRAIN_WaterEdge=new float[holder.Bumps.Length]; TERRAIN_WaterGloss=new float[holder.Bumps.Length]; TERRAIN_WaterOpacity=new float[holder.Bumps.Length]; TERRAIN_Refraction=new float[holder.Bumps.Length]; TERRAIN_WetRefraction=new float[holder.Bumps.Length]; TERRAIN_Flow=new float[holder.Bumps.Length]; TERRAIN_WetSpecularity=new float[holder.Bumps.Length]; TERRAIN_WetReflection=new float[holder.Bumps.Length]; TERRAIN_WaterColor=new Color[holder.Bumps.Length]; TERRAIN_LayerReflection=new float[holder.Bumps.Length]; for(int i=0; i<holder.Bumps.Length; i++) { Bumps[i]=holder.Bumps[i]; Spec[i]=holder.Spec[i]; FarGlossCorrection[i]=holder.FarGlossCorrection[i]; MixScale[i]=holder.MixScale[i]; MixBlend[i]=holder.MixBlend[i]; MixSaturation[i]=holder.MixSaturation[i]; GlobalColorPerLayer[i]=holder.GlobalColorPerLayer[i]; PER_LAYER_HEIGHT_MODIFIER[i]=holder.PER_LAYER_HEIGHT_MODIFIER[i]; _SuperDetailStrengthMultA[i]=holder._SuperDetailStrengthMultA[i]; _SuperDetailStrengthMultASelfMaskNear[i]=holder._SuperDetailStrengthMultASelfMaskNear[i]; _SuperDetailStrengthMultASelfMaskFar[i]=holder._SuperDetailStrengthMultASelfMaskFar[i]; _SuperDetailStrengthMultB[i]=holder._SuperDetailStrengthMultB[i]; _SuperDetailStrengthMultBSelfMaskNear[i]=holder._SuperDetailStrengthMultBSelfMaskNear[i]; _SuperDetailStrengthMultBSelfMaskFar[i]=holder._SuperDetailStrengthMultBSelfMaskFar[i]; _SuperDetailStrengthNormal[i]=holder._SuperDetailStrengthNormal[i]; _BumpMapGlobalStrength[i]=holder._BumpMapGlobalStrength[i]; VerticalTextureStrength[i]=holder.VerticalTextureStrength[i]; AO_strength[i]=holder.AO_strength[i]; Heights[i]=holder.Heights[i]; _snow_strength_per_layer[i]=holder._snow_strength_per_layer[i]; Substances[i]=holder.Substances[i]; // wet TERRAIN_LayerWetStrength[i]=holder.TERRAIN_LayerWetStrength[i]; TERRAIN_WaterLevel[i]=holder.TERRAIN_WaterLevel[i]; TERRAIN_WaterLevelSlopeDamp[i]=holder.TERRAIN_WaterLevelSlopeDamp[i]; TERRAIN_WaterEdge[i]=holder.TERRAIN_WaterEdge[i]; TERRAIN_WaterGloss[i]=holder.TERRAIN_WaterGloss[i]; TERRAIN_WaterOpacity[i]=holder.TERRAIN_WaterOpacity[i]; TERRAIN_Refraction[i]=holder.TERRAIN_Refraction[i]; TERRAIN_WetRefraction[i]=holder.TERRAIN_WetRefraction[i]; TERRAIN_Flow[i]=holder.TERRAIN_Flow[i]; TERRAIN_WetSpecularity[i]=holder.TERRAIN_WetSpecularity[i]; TERRAIN_WetReflection[i]=holder.TERRAIN_WetReflection[i]; TERRAIN_WaterColor[i]=holder.TERRAIN_WaterColor[i]; TERRAIN_LayerReflection[i]=holder.TERRAIN_LayerReflection[i]; } }
/// <summary> /// Applies the convolution filter to the bitmap. /// </summary> /// <param name="bitmap">The bitmap.</param> /// <param name="colorChannels">The color channels to modify.</param> public unsafe void Apply(Bitmap bitmap, ColorChannels colorChannels = ColorChannels.All) { using (var copy = new Bitmap(bitmap)) { copy.PinAsReadOnly(sourceBits => bitmap.PinAsWriteOnly(targetBits => { var source = (uint*)sourceBits.ToPointer(); var target = (uint*)targetBits.ToPointer(); for (var y = 0; y < bitmap.Height; y++) { var y1 = bitmap.Width * (y - 1); var y2 = bitmap.Width * y; var y3 = bitmap.Width * (y + 1); for (var x = 0; x < bitmap.Width; x++) { var output = source[y2 + x]; var x1 = x - 1; var x2 = x; var x3 = x + 1; if (x <= 0) x1 = x2; if (x >= bitmap.Width - 1) x3 = x2; if (y <= 0) y1 = y2; if (y >= bitmap.Height - 1) y3 = y2; for (var i = 0; i < 4; i++) { if ((colorChannels & channel[i]) != 0) { var channelMask = mask[i]; var channelBits = shift[i]; var value = 0; value += m11 * (int)((source[y1 + x1] & channelMask) >> channelBits); value += m12 * (int)((source[y1 + x2] & channelMask) >> channelBits); value += m13 * (int)((source[y1 + x3] & channelMask) >> channelBits); value += m21 * (int)((source[y2 + x1] & channelMask) >> channelBits); value += m22 * (int)((source[y2 + x2] & channelMask) >> channelBits); value += m23 * (int)((source[y2 + x3] & channelMask) >> channelBits); value += m31 * (int)((source[y3 + x1] & channelMask) >> channelBits); value += m32 * (int)((source[y3 + x2] & channelMask) >> channelBits); value += m33 * (int)((source[y3 + x3] & channelMask) >> channelBits); value /= divisor; value += bias; if (value < Byte.MinValue) value = Byte.MinValue; if (value > Byte.MaxValue) value = Byte.MaxValue; output = (output & ~channelMask) | ((uint)value << channelBits); } } target[y2 + x] = output; } } })); } }
public bool ClearBlend(ColorChannels channel=ColorChannels.A) { if (!blendedObject || blendedObject.GetComponent(typeof(Collider))==null || ((blendedObject.GetComponent(typeof(MeshRenderer))==null) && (blendedObject.GetComponent(typeof(Terrain))==null))) { Debug.LogError("Select an object (terrain or GameObject with mesh) to be blended with this object."); return false; } Mesh mesh = ((MeshFilter)GetComponent(typeof(MeshFilter))).sharedMesh; Color[] colors=mesh.colors; if (colors==null || colors.Length==0) { colors=new Color[mesh.vertices.Length]; } for(int i=0; i<colors.Length; i++) { colors[i][(int)channel]=0; } mesh.colors=colors; pmesh=mesh; if (channel==ColorChannels.A) { if (underlying_renderer) { MeshFilter mf=underlying_renderer.GetComponent(typeof(MeshFilter)) as MeshFilter; if (mf) { colors=mf.sharedMesh.colors; if (colors==null || colors.Length==0) { colors=new Color[mf.sharedMesh.vertices.Length]; } for(int i=0; i<colors.Length; i++) { colors[i][(int)channel]=0; } mf.sharedMesh.colors=colors; } } } return true; }
void OnGUI() { if (finalize) { // select created texture Selection.activeObject=AssetDatabase.LoadAssetAtPath(save_path, typeof(Texture2D)); finalize=false; } EditorGUILayout.Space(); source_tex0 = EditorGUILayout.ObjectField("Source Texture 0", source_tex0, typeof(Texture2D), false) as Texture2D; EditorGUILayout.Space(); source_tex1 = EditorGUILayout.ObjectField("Source Texture 1", source_tex1, typeof(Texture2D), false) as Texture2D; EditorGUILayout.Space(); source_tex2 = EditorGUILayout.ObjectField("Source Texture 2", source_tex2, typeof(Texture2D), false) as Texture2D; EditorGUILayout.Space(); source_tex3 = EditorGUILayout.ObjectField("Source Texture 3", source_tex3, typeof(Texture2D), false) as Texture2D; EditorGUILayout.Space(); if (source_tex0) { int sources_ready=0; if (check_texture(source_tex0, 0, source_tex0.width, source_tex0.height)) { sources_ready++; sourceChannel0 = (ColorChannels)EditorGUILayout.EnumPopup("Target R from source 0", sourceChannel0); } if (check_texture(source_tex1, 1, source_tex0.width, source_tex0.height)) { sources_ready++; sourceChannel1 = (ColorChannels)EditorGUILayout.EnumPopup("Target G from source 1", sourceChannel1); } if (check_texture(source_tex2, 2, source_tex0.width, source_tex0.height)) { sources_ready++; sourceChannel2 = (ColorChannels)EditorGUILayout.EnumPopup("Target B from source 2", sourceChannel2); } if (check_texture(source_tex3, 3, source_tex0.width, source_tex0.height)) { sources_ready++; sourceChannel3 = (ColorChannels)EditorGUILayout.EnumPopup("Target A from source 3", sourceChannel3); } if (sources_ready==4) { if (GUILayout.Button("Render mixed texture")) { rendered_tex=new Texture2D(source_tex0.width, source_tex0.height, TextureFormat.ARGB32, true); byte[] colsR=get_color_channel(source_tex0, sourceChannel0); byte[] colsG=get_color_channel(source_tex1, sourceChannel1); byte[] colsB=get_color_channel(source_tex2, sourceChannel2); byte[] colsA=get_color_channel(source_tex3, sourceChannel3); Color32[] cols=rendered_tex.GetPixels32(); for(int i=0; i<cols.Length; i++) { cols[i].r=colsR[i]; cols[i].g=colsG[i]; cols[i].b=colsB[i]; cols[i].a=colsA[i]; } rendered_tex.SetPixels32(cols); if (Selection.activeObject is Texture2D) { save_path=AssetDatabase.GetAssetPath(Selection.activeObject as Texture2D); directory=Path.GetDirectoryName(save_path); file=Path.GetFileNameWithoutExtension(save_path)+".png"; } else { if (save_path=="") { directory=Path.GetDirectoryName(AssetDatabase.GetAssetPath(source_tex0)); file=Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(source_tex0))+"(mixed).png"; } } } } } if (rendered_tex) { linearTexture=GUILayout.Toggle(linearTexture, "Linear texture (Bypass sRGB Sampling)"); if (GUILayout.Button("Save texture")) { SaveTexture(directory, file); } } }
public override void Copy_to_Array(ref byte[] dest, ColorChannels numChannels) { int size = localImage.Height * localImage.Width; byte* ptr = Scan0; unsafe { switch(numChannels) { case ColorChannels.Gray: fixed(byte *d = dest) { byte *pDest = d; byte *pDestEnd = d + dest.Length; for(; pDest < pDestEnd; pDest++) { *pDest = (byte)((*ptr++ * 0.3) + (*ptr++ * 0.59) + (*ptr++ * 0.11)); } } break; case ColorChannels.RGB: Marshal.Copy(ImageData.Scan0, dest, 0, dest.Length); break; case ColorChannels.RGBA: fixed(byte *d = dest) { byte *pDest = d; for(int i=0; i < size; i++) { *(pDest++) = *ptr++;// B *(pDest++) = *ptr++;// G *(pDest++) = *ptr++;// R *(pDest++) = 1;// A } } break; default: break; } } }
/// <summary> /// Gets a bit mask that indicates which portions of a pixel are occupied by the specified color channels. /// </summary> /// <param name="channels">The color channel(s) to get the mask for.</param> /// <returns>A new byte array that is the same number of bytes as required to represent a single pixel.</returns> public abstract byte[] GetBitMask(ColorChannels channels);
public ImageRgba32SteganographerBuilder ColorChannelsToUse(ColorChannels colorChannelsToUse) { _options.ColorChannelsToUse = colorChannelsToUse; return(this); }