public PngHeader(int width, int height, byte bitdepth, ColorModel colorModel) { Width = width; Height = height; BitDepth = bitdepth; ColorModel = colorModel; bool alpha = (colorModel & ColorModel.Alpha) == ColorModel.Alpha; bool palette = (colorModel & ColorModel.Palette) == ColorModel.Palette; bool grayscale = (colorModel & ColorModel.Color) != ColorModel.Color; bool packed = bitdepth < 8; if (grayscale && palette) throw new ArgumentOutOfRangeException("palette and greyscale are exclusive"); int channels = (grayscale || palette) ? (alpha ? 2 : 1) : // Grayscale or Palette (alpha ? 4 : 3); // RGB int bpp = channels * BitDepth; BytesPerPixel = (bpp + 7) / 8; Stride = (bpp * width + 7) / 8; int samplesPerRow = channels * width; int samplesPerRowPacked = (packed) ? Stride : samplesPerRow; }
public static void GetColorComponents(ColorModel colorModel, Color color, out Single componentA, out Single componentB, out Single componentC) { componentA = 0.0f; componentB = 0.0f; componentC = 0.0f; switch (colorModel) { case ColorModel.RedGreenBlue: componentA = color.R; componentB = color.G; componentC = color.B; break; case ColorModel.HueSaturationBrightness: componentA = color.GetHue(); componentB = color.GetSaturation(); componentC = color.GetBrightness(); break; case ColorModel.LabColorSpace: RGBtoLab(color.R, color.G, color.B, out componentA, out componentB, out componentC); break; case ColorModel.XYZ: RGBtoXYZ(color.R, color.G, color.B, out componentA, out componentB, out componentC); break; } }
/// <summary> /// Converts the PCS color into the device color /// </summary> /// <param name="Profile">The profile that will be used for the conversion</param> /// <param name="pcs">The PCS color (has to match the profiles PCS color type)</param> /// <param name="PrefRenderingIntent">The preferred rendering intent</param> /// <returns>The converted color in the device color type</returns> public Color ToDevice(ICC Profile, Color pcs, RenderingIntent PrefRenderingIntent) { InValues = pcs.ColorArray; InModel = pcs.Model; this.Profile = Profile; PreferredRenderingIntent = PrefRenderingIntent; IsDefault = true; return Do_PCS(); }
public static ColorModel Invert(this ColorModel color) { ColorModel model = new ColorModel() { Red = ~(byte)color.Red, Green = ~(byte)color.Green, Blue = ~(byte)color.Blue }; return model; }
public ColorConverterSmartTagAction(ITrackingSpan span, ParseItem item, ColorModel colorModel, ColorFormat format) { _span = span; _item = item; _format = format; _colorModel = colorModel; if (Icon == null) { Icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2013;component/Resources/palette.png", UriKind.RelativeOrAbsolute)); } SetDisplayText(); }
public static void GetColorComponents(ColorModel colorModel, Color color, Color targetColor, out Single componentA, out Single componentB, out Single componentC) { componentA = 0.0f; componentB = 0.0f; componentC = 0.0f; switch (colorModel) { case ColorModel.RedGreenBlue: componentA = color.R - targetColor.R; componentB = color.G - targetColor.G; componentC = color.B - targetColor.B; break; case ColorModel.HueSaturationBrightness: componentA = color.GetHue() - targetColor.GetHue(); componentB = color.GetSaturation() - targetColor.GetSaturation(); componentC = color.GetBrightness() - targetColor.GetBrightness(); break; case ColorModel.LabColorSpace: Single sourceL, sourceA, sourceB; Single targetL, targetA, targetB; RGBtoLab(color.R, color.G, color.B, out sourceL, out sourceA, out sourceB); RGBtoLab(targetColor.R, targetColor.G, targetColor.B, out targetL, out targetA, out targetB); componentA = sourceL - targetL; componentB = sourceA - targetA; componentC = sourceB - targetB; break; case ColorModel.XYZ: Single sourceX, sourceY, sourceZ; Single targetX, targetY, targetZ; RGBtoXYZ(color.R, color.G, color.B, out sourceX, out sourceY, out sourceZ); RGBtoXYZ(targetColor.R, targetColor.G, targetColor.B, out targetX, out targetY, out targetZ); componentA = sourceX - targetX; componentB = sourceY - targetY; componentC = sourceZ - targetZ; break; } }
private static string FormatHslColor(ColorModel colorModel) { if (colorModel.Alpha < 1) { // HSL can't specify alpha return FormatHslaColor(colorModel); } else { HslColor hsl = colorModel.HSL; return string.Format(CultureInfo.InvariantCulture, "hsl({0}, {1}%, {2}%)", Math.Round(hsl.Hue * 360, 1), Math.Round(hsl.Saturation * 100, 1), Math.Round(hsl.Lightness * 100, 1)); } }
public ColorConverterSmartTagAction(ITrackingSpan span, ColorModel colorModel, ColorFormat format) { _span = span; if (format == ColorFormat.RgbHex6) format = ColorFormat.RgbHex3; _format = format; _colorModel = colorModel.Clone(); _colorModel.Format = format; if (Icon == null) { Icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/palette.png", UriKind.RelativeOrAbsolute)); } _displayText = "Convert to " + GetColorString(_format, _colorModel); }
private static string GetColorString(ColorFormat format, ColorModel model) { switch (format) { case ColorFormat.Name: return GetNamedColor(model.Color); case ColorFormat.Hsl: return FormatHslColor(model); //ColorFormatter.FormatColorAs(_colorModel, ColorFormat.Hsl); case ColorFormat.Rgb: case ColorFormat.RgbHex3: case ColorFormat.RgbHex6: return ColorFormatter.FormatColor(model, format); default: throw new InvalidEnumArgumentException("format", (int)format, typeof(ColorFormat)); } }
/// <summary> /// 创建Color值之间的线性动画 /// </summary> public static ColorAnimation BuildColorAnimation(ColorModel Model) { ColorAnimation _colorAnimation = new ColorAnimation(); _colorAnimation.From = Model.From; _colorAnimation.To = Model.To; _colorAnimation.Duration = new Duration(TimeSpan.FromSeconds(Model.Duration)); _colorAnimation.AutoReverse = Model.AutoReverse; _colorAnimation.BeginTime = TimeSpan.FromSeconds(Model.BeginTime); _colorAnimation.By = Model.By; _colorAnimation.FillBehavior = Model.FillBehavior; _colorAnimation.RepeatBehavior = Model.RepeatBehavior; _colorAnimation.SpeedRatio = Model.SpeedRatio; if (Model.EasingFunction != null) _colorAnimation.EasingFunction = Model.EasingFunction; Storyboard.SetTarget(_colorAnimation, Model.Target); Storyboard.SetTargetProperty(_colorAnimation, new PropertyPath(Model.PropertyPath)); return _colorAnimation; }
private static void GetSize() { try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)EditorExtensionsPackage.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = (int)Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; storage.GetItem("Plain Text", info); _backgroundColor = ConvertFromWin32Color((int)info[0].crBackground); } } catch { } }
public static Int32 GetComponentC(ColorModel colorModel, Color color) { Int32 result = 0; switch (colorModel) { case ColorModel.RedGreenBlue: result = color.B; break; case ColorModel.HueSaturationBrightness: result = Convert.ToInt32(color.GetBrightness() * 255); break; case ColorModel.LabColorSpace: Single l, a, b; RGBtoLab(color.R, color.G, color.B, out l, out a, out b); result = Convert.ToInt32(b * 255.0f); break; } return result; }
private void ChangeColorModel() { activeColorModel = colorModelList[listColorModel.SelectedIndex]; // applies current UI selection if (activeColorCache is BaseColorCache) { BaseColorCache colorCache = (BaseColorCache) activeColorCache; colorCache.ChangeColorModel(activeColorModel); } }
public static Int64 GetColorEuclideanDistance(ColorModel colorModel, Color requestedColor, Color realColor) { Single componentA, componentB, componentC; GetColorComponents(colorModel, requestedColor, realColor, out componentA, out componentB, out componentC); return (Int64)(componentA * componentA + componentB * componentB + componentC * componentC); }
public static Int32 GetEuclideanDistance(Color color, ColorModel colorModel, IList<Color> palette) { // initializes the best difference, set it for worst possible, it can only get better Int64 leastDistance = Int64.MaxValue; Int32 result = 0; for (Int32 index = 0; index < palette.Count; index++) { Color targetColor = palette[index]; Int64 distance = GetColorEuclideanDistance(colorModel, color, targetColor); // if a difference is zero, we're good because it won't get better if (distance == 0) { result = index; break; } // if a difference is the best so far, stores it as our best candidate if (distance < leastDistance) { leastDistance = distance; result = index; } } return result; }
/// <summary> /// Changes the color model. /// </summary> /// <param name="colorModel">The color model.</param> public void ChangeColorModel(ColorModel colorModel) { ColorModel = colorModel; }
/// <summary> /// Converts a color to a Lab color /// </summary> /// <param name="InColor">The color to convert</param> /// <param name="RefWhite">The reference white to be used for the converted color</param> /// <returns>The converted color</returns> public ColorLab ToLab(Color InColor, WhitepointName RefWhite) { if (RefWhite != WhitepointName.Custom) OutReferenceWhite = WhitepointArr[(int)RefWhite]; else OutReferenceWhite = ReferenceWhite; OutputModel = ColorModel.CIELab; SetInputColor(InColor); varArr = Do(); return new ColorLab(OutReferenceWhite, varArr[0], varArr[1], varArr[2]); }
void Start() { GameObject.Find("RotatingBlock").renderer.material.color = ColorModel.RandomColor(); }
/// <summary> /// Creates a new instance of a specific color with the standard settings /// </summary> /// <param name="Model">The colormodel the new color will be in</param> /// <returns>A color in the given colormodel or null if not possible to create color</returns> public static Color GetColor(ColorModel Model) { switch (Model) { case ColorModel.CIELab: return new ColorLab(); case ColorModel.CIELCHab: return new ColorLCHab(); case ColorModel.CIELCHuv: return new ColorLCHuv(); case ColorModel.CIELuv: return new ColorLuv(); case ColorModel.CIEXYZ: return new ColorXYZ(); case ColorModel.CIEYxy: return new ColorYxy(); case ColorModel.Gray: return new ColorGray(); case ColorModel.HSL: return new ColorHSL(); case ColorModel.HSV: return new ColorHSV(); case ColorModel.LCH99: return new ColorLCH99(); case ColorModel.LCH99b: return new ColorLCH99b(); case ColorModel.LCH99c: return new ColorLCH99c(); case ColorModel.LCH99d: return new ColorLCH99d(); case ColorModel.RGB: return new ColorRGB(); case ColorModel.YCbCr: return new ColorYCbCr(); default: return null; } }
/// <summary> /// Converts the device color into the PCS color /// </summary> /// <param name="Profile">The profile that will be used for the conversion</param> /// <param name="inColor">The device color (has to match the profiles device color type)</param> /// <param name="PrefRenderingIntent">The preferred rendering intent</param> /// <returns>The converted color in the PCS color type</returns> public Color ToPCS(ICC Profile, Color inColor, RenderingIntent PrefRenderingIntent) { InValues = inColor.ColorArray; InModel = inColor.Model; this.Profile = Profile; PreferredRenderingIntent = PrefRenderingIntent; IsDefault = true; return Do_Device(); }
/// <summary> /// Converts the device color into the PCS color /// </summary> /// <param name="Profile">The profile that will be used for the conversion</param> /// <param name="inColor">The device color (has to match the profiles device color type)</param> /// <param name="PrefRenderingIntent">The preferred rendering intent</param> /// <param name="ConversionMethod">The method of conversion</param> /// <param name="ConversionType">The type of conversion</param> /// <returns>The converted color in the PCS color type</returns> public Color ToPCS(ICC Profile, Color inColor, RenderingIntent PrefRenderingIntent, ICCconversionMethod ConversionMethod, ICCconversionType ConversionType) { InValues = inColor.ColorArray; InModel = inColor.Model; this.Profile = Profile; PreferredRenderingIntent = PrefRenderingIntent; this.ConversionMethod = ConversionMethod; this.ConversionType = ConversionType; IsDefault = false; return Do_Device(); }
/// <summary> /// Creates a context for the compositing operation. /// The context contains state that is used in performing /// the compositing operation. </summary> /// <param name="srcColorModel"> the <seealso cref="ColorModel"/> of the source </param> /// <param name="dstColorModel"> the <code>ColorModel</code> of the destination </param> /// <returns> the <code>CompositeContext</code> object to be used to perform /// compositing operations. </returns> public CompositeContext CreateContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { return(new SunCompositeContext(this, srcColorModel, dstColorModel)); }
public ThumbnailCreator(ColorModel colorModel) { _colorModel = colorModel; }
public PixelFormatInfo(int bitsPerPixel, ColorModel model, ColorChannels channels) { BitsPerPixel = bitsPerPixel; ColorModel = model; Channels = channels; }
public void setColorModel(ColorModel model) { mColorModel = model; }
public DecodedJpeg Decode() { // The frames in this jpeg are loaded into a list. There is // usually just one frame except in heirarchial progression where // there are multiple frames. JPEGFrame frame = null; // The restart interval defines how many MCU's we should have // between the 8-modulo restart marker. The restart markers allow // us to tell whether or not our decoding process is working // correctly, also if there is corruption in the image we can // recover with these restart intervals. (See RSTm DRI). int resetInterval = 0; bool haveMarker = false; bool foundJFIF = false; List<JpegHeader> headers = new List<JpegHeader>(); // Loop through until there are no more markers to read in, at // that point everything is loaded into the jpegFrames array and // can be processed. while (true) { if (DecodeProgress.Abort) return null; #region Switch over marker types switch (marker) { case JPEGMarker.APP0: // APP1 is used for EXIF data case JPEGMarker.APP1: // Seldomly, APP2 gets used for extended EXIF, too case JPEGMarker.APP2: case JPEGMarker.APP3: case JPEGMarker.APP4: case JPEGMarker.APP5: case JPEGMarker.APP6: case JPEGMarker.APP7: case JPEGMarker.APP8: case JPEGMarker.APP9: case JPEGMarker.APP10: case JPEGMarker.APP11: case JPEGMarker.APP12: case JPEGMarker.APP13: case JPEGMarker.APP14: case JPEGMarker.APP15: // COM: Comment case JPEGMarker.COM: // Debug.WriteLine(string.Format("Extracting Header, Type={0:X}", marker)); JpegHeader header = ExtractHeader(); #region Check explicitly for Exif Data if (header.Marker == JPEGMarker.APP1 && header.Data.Length >= 6) { byte[] d = header.Data; if( d[0] == 'E' && d[1] == 'x' && d[2] == 'i' && d[3] == 'f' && d[4] == 0 && d[5] == 0) { // Exif. Do something? } } #endregion #region Check for Adobe header if (header.Data.Length >= 5 && header.Marker == JPEGMarker.APP14) { string asText = UTF8Encoding.UTF8.GetString(header.Data, 0, 5); if (asText == "Adobe") { // ADOBE HEADER. Do anything? } } #endregion headers.Add(header); if (!foundJFIF && marker == JPEGMarker.APP0) { foundJFIF = TryParseJFIF(header.Data); if (foundJFIF) // Found JFIF... do JFIF extension follow? { header.IsJFIF = true; marker = jpegReader.GetNextMarker(); // Yes, they do. if (marker == JPEGMarker.APP0) { header = ExtractHeader(); headers.Add(header); } else // No. Delay processing this one. haveMarker = true; } } break; case JPEGMarker.SOF0: case JPEGMarker.SOF2: // SOFn Start of Frame Marker, Baseline DCT - This is the start // of the frame header that defines certain variables that will // be carried out through the rest of the encoding. Multiple // frames are used in a hierarchical system, however most JPEG's // only contain a single frame. // Progressive or baseline? progressive = marker == JPEGMarker.SOF2; jpegFrames.Add(new JPEGFrame()); frame = (JPEGFrame)jpegFrames[jpegFrames.Count - 1]; frame.ProgressUpdateMethod = new Action<long>(UpdateStreamProgress); // Skip the frame length. jpegReader.ReadShort(); // Bits percision, either 8 or 12. frame.setPrecision(jpegReader.ReadByte()); // Scan lines (height) frame.ScanLines = jpegReader.ReadShort(); // Scan samples per line (width) frame.SamplesPerLine = jpegReader.ReadShort(); // Number of Color Components (channels). frame.ComponentCount = jpegReader.ReadByte(); DecodeProgress.Height = frame.Height; DecodeProgress.Width = frame.Width; DecodeProgress.SizeReady = true; if(DecodeProgressChanged != null) { DecodeProgressChanged(this, DecodeProgress); if (DecodeProgress.Abort) return null; } // Add all of the necessary components to the frame. for (int i = 0; i < frame.ComponentCount; i++) { byte compId = jpegReader.ReadByte(); byte sampleFactors = jpegReader.ReadByte(); byte qTableId = jpegReader.ReadByte(); byte sampleHFactor = (byte)(sampleFactors >> 4); byte sampleVFactor = (byte)(sampleFactors & 0x0f); frame.AddComponent(compId, sampleHFactor, sampleVFactor, qTableId); } break; case JPEGMarker.DHT: // DHT non-SOF Marker - Huffman Table is required for decoding // the JPEG stream, when we receive a marker we load in first // the table length (16 bits), the table class (4 bits), table // identifier (4 bits), then we load in 16 bytes and each byte // represents the count of bytes to load in for each of the 16 // bytes. We load this into an array to use later and move on 4 // huffman tables can only be used in an image. int huffmanLength = (jpegReader.ReadShort() - 2); // Keep looping until we are out of length. int index = huffmanLength; // Multiple tables may be defined within a DHT marker. This // will keep reading until there are no tables left, most // of the time there are just one tables. while (index > 0) { // Read the identifier information and class // information about the Huffman table, then read the // 16 byte codelength in and read in the Huffman values // and put it into table info. byte huffmanInfo = jpegReader.ReadByte(); byte tableClass = (byte)(huffmanInfo >> 4); byte huffmanIndex = (byte)(huffmanInfo & 0x0f); short[] codeLength = new short[16]; for (int i = 0; i < codeLength.Length; i++) codeLength[i] = jpegReader.ReadByte(); int huffmanValueLen = 0; for (int i = 0; i < 16; i++) huffmanValueLen += codeLength[i]; index -= (huffmanValueLen + 17); short[] huffmanVal = new short[huffmanValueLen]; for (int i = 0; i < huffmanVal.Length; i++) { huffmanVal[i] = jpegReader.ReadByte(); } // Assign DC Huffman Table. if (tableClass == HuffmanTable.JPEG_DC_TABLE) dcTables[(int)huffmanIndex] = new JpegHuffmanTable(codeLength, huffmanVal); // Assign AC Huffman Table. else if (tableClass == HuffmanTable.JPEG_AC_TABLE) acTables[(int)huffmanIndex] = new JpegHuffmanTable(codeLength, huffmanVal); } break; case JPEGMarker.DQT: // DQT non-SOF Marker - This defines the quantization // coeffecients, this allows us to figure out the quality of // compression and unencode the data. The data is loaded and // then stored in to an array. short quantizationLength = (short)(jpegReader.ReadShort() - 2); for (int j = 0; j < quantizationLength / 65; j++) { byte quantSpecs = jpegReader.ReadByte(); int[] quantData = new int[64]; if ((byte)(quantSpecs >> 4) == 0) // Precision 8 bit. { for (int i = 0; i < 64; i++) quantData[i] = jpegReader.ReadByte(); } else if ((byte)(quantSpecs >> 4) == 1) // Precision 16 bit. { for (int i = 0; i < 64; i++) quantData[i] = jpegReader.ReadShort(); } qTables[(int)(quantSpecs & 0x0f)] = new JpegQuantizationTable(quantData); } break; case JPEGMarker.SOS: Debug.WriteLine("Start of Scan (SOS)"); // SOS non-SOF Marker - Start Of Scan Marker, this is where the // actual data is stored in a interlaced or non-interlaced with // from 1-4 components of color data, if three components most // likely a YCrCb model, this is a fairly complex process. // Read in the scan length. ushort scanLen = jpegReader.ReadShort(); // Number of components in the scan. byte numberOfComponents = jpegReader.ReadByte(); byte[] componentSelector = new byte[numberOfComponents]; for (int i = 0; i < numberOfComponents; i++) { // Component ID, packed byte containing the Id for the // AC table and DC table. byte componentID = jpegReader.ReadByte(); byte tableInfo = jpegReader.ReadByte(); int DC = (tableInfo >> 4) & 0x0f; int AC = (tableInfo) & 0x0f; frame.setHuffmanTables(componentID, acTables[(byte)AC], dcTables[(byte)DC]); componentSelector[i] = componentID; } byte startSpectralSelection = jpegReader.ReadByte(); byte endSpectralSelection = jpegReader.ReadByte(); byte successiveApproximation = jpegReader.ReadByte(); #region Baseline JPEG Scan Decoding if (!progressive) { frame.DecodeScanBaseline(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker); haveMarker = true; // use resultant marker for the next switch(..) } #endregion #region Progressive JPEG Scan Decoding if (progressive) { frame.DecodeScanProgressive( successiveApproximation, startSpectralSelection, endSpectralSelection, numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker); haveMarker = true; // use resultant marker for the next switch(..) } #endregion break; case JPEGMarker.DRI: jpegReader.BaseStream.Seek(2, System.IO.SeekOrigin.Current); resetInterval = jpegReader.ReadShort(); break; /// Defines the number of lines. (Not usually present) case JPEGMarker.DNL: frame.ScanLines = jpegReader.ReadShort(); break; /// End of Image. Finish the decode. case JPEGMarker.EOI: if (jpegFrames.Count == 0) { throw new NotSupportedException("No JPEG frames could be located."); } else if (jpegFrames.Count == 1) { // Only one frame, JPEG Non-Heirarchial Frame. byte[][,] raster = Image.CreateRaster(frame.Width, frame.Height, frame.ComponentCount); IList<JpegComponent> components = frame.Scan.Components; int totalSteps = components.Count * 3; // Three steps per loop int stepsFinished = 0; for(int i = 0; i < components.Count; i++) { JpegComponent comp = components[i]; comp.QuantizationTable = qTables[comp.quant_id].Table; // 1. Quantize comp.quantizeData(); UpdateProgress(++stepsFinished, totalSteps); // 2. Run iDCT (expensive) comp.idctData(); UpdateProgress(++stepsFinished, totalSteps); // 3. Scale the image and write the data to the raster. comp.writeDataScaled(raster, i, BlockUpsamplingMode); UpdateProgress(++stepsFinished, totalSteps); // Ensure garbage collection. comp = null; GC.Collect(); } // Grayscale Color Image (1 Component). if (frame.ComponentCount == 1) { ColorModel cm = new ColorModel() { colorspace = ColorSpace.Gray, Opaque = true }; image = new Image(cm, raster); } // YCbCr Color Image (3 Components). else if (frame.ComponentCount == 3) { ColorModel cm = new ColorModel() { colorspace = ColorSpace.YCbCr, Opaque = true }; image = new Image(cm, raster); } // Possibly CMYK or RGBA ? else { throw new NotSupportedException("Unsupported Color Mode: 4 Component Color Mode found."); } // If needed, convert centimeters to inches. Func<double, double> conv = x => Units == UnitType.Inches ? x : x / 2.54; image.DensityX = conv(XDensity); image.DensityY = conv(YDensity); height = frame.Height; width = frame.Width; } else { // JPEG Heirarchial Frame throw new NotSupportedException("Unsupported Codec Type: Hierarchial JPEG"); } break; // Only SOF0 (baseline) and SOF2 (progressive) are supported by FJCore case JPEGMarker.SOF1: case JPEGMarker.SOF3: case JPEGMarker.SOF5: case JPEGMarker.SOF6: case JPEGMarker.SOF7: case JPEGMarker.SOF9: case JPEGMarker.SOF10: case JPEGMarker.SOF11: case JPEGMarker.SOF13: case JPEGMarker.SOF14: case JPEGMarker.SOF15: throw new NotSupportedException("Unsupported codec type."); default: break; // ignore } #endregion switch over markers if (haveMarker) haveMarker = false; else { try { marker = jpegReader.GetNextMarker(); } catch (System.IO.EndOfStreamException) { break; /* done reading the file */ } } } DecodedJpeg result = new DecodedJpeg(image, headers); return result; }
/// <summary> /// Initializes a new instance of the <see cref="EuclideanDistanceColorCache"/> class. /// </summary> /// <param name="colorModel">The color model.</param> public EuclideanDistanceColorCache(ColorModel colorModel) { ColorModel = colorModel; }
/// <summary> /// Converts a color to a Lab color /// </summary> /// <param name="InColor">The color to convert</param> /// <param name="RefWhite">The reference white to be used for the converted color</param> /// <returns>The converted color</returns> public ColorLab ToLab(Color InColor, Whitepoint RefWhite) { OutputModel = ColorModel.CIELab; OutReferenceWhite = RefWhite; SetInputColor(InColor); varArr = Do(); return new ColorLab(OutReferenceWhite, varArr[0], varArr[1], varArr[2]); }
private bool IsXColor(ColorModel model) { switch (model) { case ColorModel.Color2: case ColorModel.Color3: case ColorModel.Color4: case ColorModel.Color5: case ColorModel.Color6: case ColorModel.Color7: case ColorModel.Color8: case ColorModel.Color9: case ColorModel.Color10: case ColorModel.Color11: case ColorModel.Color12: case ColorModel.Color13: case ColorModel.Color14: case ColorModel.Color15: return true; default: return false; } }
private void SetInputColor(UColor inColor) { InputModel = inColor.Model; DoAdaption = inColor.ReferenceWhite != OutReferenceWhite.Name; if (InputModel != ColorModel.Gray) { ValArr1 = inColor.DoubleColorArray; ValArr2 = inColor.DoubleColorArray; } else { ValArr1 = new double[] { ((UColorGray)inColor).G / 65535d, 0, 0 }; ValArr2 = new double[] { ((UColorGray)inColor).G / 65535d, 0, 0 }; } switch (InputModel) { case ColorModel.CIELab: case ColorModel.CIELCHab: case ColorModel.CIELCHuv: case ColorModel.LCH99: case ColorModel.LCH99b: case ColorModel.LCH99c: case ColorModel.LCH99d: case ColorModel.CIELuv: case ColorModel.CIEXYZ: case ColorModel.CIEYxy: case ColorModel.Gray: case ColorModel.DEF: case ColorModel.Bef: case ColorModel.BCH: if (inColor.ReferenceWhite == WhitepointName.Custom || OutReferenceWhite.Name == WhitepointName.Custom) DoAdaption = true; InputWhitepoint = WhitepointArr[(int)inColor.ReferenceWhite]; break; case ColorModel.HSL: InputRGBSpace = ((UColorHSL)inColor).Space; InputWhitepoint = InputRGBSpace.ReferenceWhite; DoAdaptionRGB(); break; case ColorModel.HSV: InputRGBSpace = ((UColorHSV)inColor).Space; InputWhitepoint = InputRGBSpace.ReferenceWhite; DoAdaptionRGB(); break; case ColorModel.RGB: InputRGBSpace = ((UColorRGB)inColor).Space; IsRGBLinear = ((UColorRGB)inColor).IsLinear; InputWhitepoint = InputRGBSpace.ReferenceWhite; DoAdaptionRGB(); break; case ColorModel.YCbCr: InputRGBSpace = ((UColorYCbCr)inColor).BaseSpace; InputYCbCrSpace = ((UColorYCbCr)inColor).Space; InputWhitepoint = InputRGBSpace.ReferenceWhite; DoAdaptionYCbCr(); break; default: throw new NotImplementedException(); } }
protected override void UpdateModelForGradientMax(ColorModel model) { model.ScG = 1f; }
/// <summary> /// Converts a color to a LCH99c color /// </summary> /// <param name="InColor">The color to convert</param> /// <returns>The converted color</returns> public ColorLCH99c ToLCH99c(Color InColor) { OutReferenceWhite = WhitepointArr[(int)WhitepointName.D65]; OutputModel = ColorModel.LCH99c; SetInputColor(InColor); varArr = Do(); return new ColorLCH99c(varArr[0], varArr[1], varArr[2]); }
/// <summary> /// Converts the PCS color into the device color /// </summary> /// <param name="Profile">The profile that will be used for the conversion</param> /// <param name="pcs">The PCS color (has to match the profiles PCS color type)</param> /// <param name="ConversionMethod">The method of conversion</param> /// <param name="ConversionType">The type of conversion</param> /// <returns>The converted color in the device color type</returns> public Color ToDevice(ICC Profile, Color pcs, ICCconversionMethod ConversionMethod, ICCconversionType ConversionType) { InValues = pcs.ColorArray; InModel = pcs.Model; this.Profile = Profile; PreferredRenderingIntent = ColorConverter.PreferredRenderingIntent; this.ConversionMethod = ConversionMethod; this.ConversionType = ConversionType; IsDefault = false; return Do_PCS(); }
/// <summary> /// The runnable method for this class. This will produce an image using /// the current RenderableImage and RenderContext and send it to all the /// ImageConsumer currently registered with this class. /// </summary> public virtual void Run() { // First get the rendered image RenderedImage rdrdImage; if (Rc != null) { rdrdImage = RdblImage.CreateRendering(Rc); } else { rdrdImage = RdblImage.CreateDefaultRendering(); } // And its ColorModel ColorModel colorModel = rdrdImage.ColorModel; Raster raster = rdrdImage.Data; SampleModel sampleModel = raster.SampleModel; DataBuffer dataBuffer = raster.DataBuffer; if (colorModel == null) { colorModel = ColorModel.RGBdefault; } int minX = raster.MinX; int minY = raster.MinY; int width = raster.Width; int height = raster.Height; System.Collections.IEnumerator icList; ImageConsumer ic; // Set up the ImageConsumers icList = Ics.elements(); while (icList.hasMoreElements()) { ic = (ImageConsumer)icList.nextElement(); ic.SetDimensions(width, height); ic.Hints = java.awt.image.ImageConsumer_Fields.TOPDOWNLEFTRIGHT | java.awt.image.ImageConsumer_Fields.COMPLETESCANLINES | java.awt.image.ImageConsumer_Fields.SINGLEPASS | java.awt.image.ImageConsumer_Fields.SINGLEFRAME; } // Get RGB pixels from the raster scanline by scanline and // send to consumers. int[] pix = new int[width]; int i, j; int numBands = sampleModel.NumBands; int[] tmpPixel = new int[numBands]; for (j = 0; j < height; j++) { for (i = 0; i < width; i++) { sampleModel.GetPixel(i, j, tmpPixel, dataBuffer); pix[i] = colorModel.GetDataElement(tmpPixel, 0); } // Now send the scanline to the Consumers icList = Ics.elements(); while (icList.hasMoreElements()) { ic = (ImageConsumer)icList.nextElement(); ic.SetPixels(0, j, width, 1, colorModel, pix, 0, width); } } // Now tell the consumers we're done. icList = Ics.elements(); while (icList.hasMoreElements()) { ic = (ImageConsumer)icList.nextElement(); ic.ImageComplete(java.awt.image.ImageConsumer_Fields.STATICIMAGEDONE); } }
internal static bool IsSameSpace(ColorModel Model, ColorSpaceType Space) { if (Enum.GetName(typeof(ColorModel), Model).ToLower() == Enum.GetName(typeof(ColorSpaceType), Space).ToLower()) return true; else return false; }
/// <summary> /// Constructor for MultipleGradientPaintContext superclass. /// </summary> protected internal MultipleGradientPaintContext(MultipleGradientPaint mgp, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace) { if (deviceBounds == null) { throw new NullPointerException("Device bounds cannot be null"); } if (userBounds == null) { throw new NullPointerException("User bounds cannot be null"); } if (t == null) { throw new NullPointerException("Transform cannot be null"); } if (hints == null) { throw new NullPointerException("RenderingHints cannot be null"); } // The inverse transform is needed to go from device to user space. // Get all the components of the inverse transform matrix. AffineTransform tInv; try { // the following assumes that the caller has copied the incoming // transform and is not concerned about it being modified t.Invert(); tInv = t; } catch (NoninvertibleTransformException) { // just use identity transform in this case; better to show // (incorrect) results than to throw an exception and/or no-op tInv = new AffineTransform(); } double[] m = new double[6]; tInv.GetMatrix(m); A00 = (float)m[0]; A10 = (float)m[1]; A01 = (float)m[2]; A11 = (float)m[3]; A02 = (float)m[4]; A12 = (float)m[5]; // copy some flags this.CycleMethod = cycleMethod; this.ColorSpace = colorSpace; // we can avoid copying this array since we do not modify its values this.Fractions = fractions; // note that only one of these values can ever be non-null (we either // store the fast gradient array or the slow one, but never both // at the same time) int[] gradient = (mgp.Gradient != null) ? mgp.Gradient.get() : null; int[][] gradients = (mgp.Gradients != null) ? mgp.Gradients.get() : null; if (gradient == null && gradients == null) { // we need to (re)create the appropriate values CalculateLookupData(colors); // now cache the calculated values in the // MultipleGradientPaint instance for future use mgp.Model = this.Model; mgp.NormalizedIntervals = this.NormalizedIntervals; mgp.IsSimpleLookup = this.IsSimpleLookup; if (IsSimpleLookup) { // only cache the fast array mgp.FastGradientArraySize = this.FastGradientArraySize; mgp.Gradient = new SoftReference <int[]>(this.Gradient); } else { // only cache the slow array mgp.Gradients = new SoftReference <int[][]>(this.Gradients); } } else { // use the values cached in the MultipleGradientPaint instance this.Model = mgp.Model; this.NormalizedIntervals = mgp.NormalizedIntervals; this.IsSimpleLookup = mgp.IsSimpleLookup; this.Gradient = gradient; this.FastGradientArraySize = mgp.FastGradientArraySize; this.Gradients = gradients; } }
private ActionResult ColorByName(string color) { ColorModel model = new ColorModel { Title = "Color: " + color, TopText = TopText, Color = color }; model.NetsyControl = new NetsySilverlightModel { Heading = string.Format("Etsy listings in color '{0}'", color), Params = string.Format("Retrieval=FrontListingsByColor,Color={0},ItemsPerPage=16", color), Height = 560, Width = 660 }; return this.View(model); }
protected override void UpdateModelForGradientMin(ColorModel model) { model.ScG = 0.0f; }