private void CheckArea(int x, int y, int width, int height) { CheckIndex(x, y); Throw.IfOutOfRange(nameof(width), 1, Image.Width - x, width, "Invalid width: {0}.", width); Throw.IfOutOfRange(nameof(height), 1, Image.Height - y, height, "Invalid height: {0}.", height); }
private DrawableComposite(MagickImage image) { Throw.IfNull("image", image); _Image = image; }
internal static ExifValue Create(ExifTag tag, object value) { Throw.IfTrue(nameof(tag), tag == ExifTag.Unknown, "Invalid Tag"); ExifValue exifValue = null; Type type = value != null?value.GetType() : null; if (type != null && type.IsArray) { type = type.GetElementType(); } switch (tag) { case ExifTag.ImageDescription: case ExifTag.Make: case ExifTag.Model: case ExifTag.Software: case ExifTag.DateTime: case ExifTag.Artist: case ExifTag.HostComputer: case ExifTag.Copyright: case ExifTag.DocumentName: case ExifTag.PageName: case ExifTag.InkNames: case ExifTag.TargetPrinter: case ExifTag.ImageID: case ExifTag.MDLabName: case ExifTag.MDSampleInfo: case ExifTag.MDPrepDate: case ExifTag.MDPrepTime: case ExifTag.MDFileUnits: case ExifTag.SEMInfo: case ExifTag.SpectralSensitivity: case ExifTag.DateTimeOriginal: case ExifTag.DateTimeDigitized: case ExifTag.SubsecTime: case ExifTag.SubsecTimeOriginal: case ExifTag.SubsecTimeDigitized: case ExifTag.RelatedSoundFile: case ExifTag.FaxSubaddress: case ExifTag.OffsetTime: case ExifTag.OffsetTimeOriginal: case ExifTag.OffsetTimeDigitized: case ExifTag.SecurityClassification: case ExifTag.ImageHistory: case ExifTag.ImageUniqueID: case ExifTag.OwnerName: case ExifTag.SerialNumber: case ExifTag.LensMake: case ExifTag.LensModel: case ExifTag.LensSerialNumber: case ExifTag.GDALMetadata: case ExifTag.GDALNoData: case ExifTag.GPSLatitudeRef: case ExifTag.GPSLongitudeRef: case ExifTag.GPSSatellites: case ExifTag.GPSStatus: case ExifTag.GPSMeasureMode: case ExifTag.GPSSpeedRef: case ExifTag.GPSTrackRef: case ExifTag.GPSImgDirectionRef: case ExifTag.GPSMapDatum: case ExifTag.GPSDestLatitudeRef: case ExifTag.GPSDestLongitudeRef: case ExifTag.GPSDestBearingRef: case ExifTag.GPSDestDistanceRef: case ExifTag.GPSDateStamp: exifValue = new ExifValue(tag, ExifDataType.Ascii, true); break; case ExifTag.ClipPath: case ExifTag.VersionYear: case ExifTag.XMP: case ExifTag.CFAPattern2: case ExifTag.TIFFEPStandardID: case ExifTag.XPTitle: case ExifTag.XPComment: case ExifTag.XPAuthor: case ExifTag.XPKeywords: case ExifTag.XPSubject: case ExifTag.GPSVersionID: exifValue = new ExifValue(tag, ExifDataType.Byte, true); break; case ExifTag.FaxProfile: case ExifTag.ModeNumber: case ExifTag.GPSAltitudeRef: exifValue = new ExifValue(tag, ExifDataType.Byte, false); break; case ExifTag.FreeOffsets: case ExifTag.FreeByteCounts: case ExifTag.ColorResponseUnit: case ExifTag.TileOffsets: case ExifTag.SMinSampleValue: case ExifTag.SMaxSampleValue: case ExifTag.JPEGQTables: case ExifTag.JPEGDCTables: case ExifTag.JPEGACTables: case ExifTag.StripRowCounts: case ExifTag.IntergraphRegisters: case ExifTag.TimeZoneOffset: exifValue = new ExifValue(tag, ExifDataType.Long, true); break; case ExifTag.SubfileType: case ExifTag.SubIFDOffset: case ExifTag.GPSIFDOffset: case ExifTag.T4Options: case ExifTag.T6Options: case ExifTag.XClipPathUnits: case ExifTag.YClipPathUnits: case ExifTag.ProfileType: case ExifTag.CodingMethods: case ExifTag.T82ptions: case ExifTag.JPEGInterchangeFormat: case ExifTag.JPEGInterchangeFormatLength: case ExifTag.MDFileTag: case ExifTag.StandardOutputSensitivity: case ExifTag.RecommendedExposureIndex: case ExifTag.ISOSpeed: case ExifTag.ISOSpeedLatitudeyyy: case ExifTag.ISOSpeedLatitudezzz: case ExifTag.FaxRecvParams: case ExifTag.FaxRecvTime: case ExifTag.ImageNumber: exifValue = new ExifValue(tag, ExifDataType.Long, false); break; case ExifTag.WhitePoint: case ExifTag.PrimaryChromaticities: case ExifTag.YCbCrCoefficients: case ExifTag.ReferenceBlackWhite: case ExifTag.PixelScale: case ExifTag.IntergraphMatrix: case ExifTag.ModelTiePoint: case ExifTag.ModelTransform: case ExifTag.GPSLatitude: case ExifTag.GPSLongitude: case ExifTag.GPSTimestamp: case ExifTag.GPSDestLatitude: case ExifTag.GPSDestLongitude: exifValue = new ExifValue(tag, ExifDataType.Rational, true); break; case ExifTag.XPosition: case ExifTag.YPosition: case ExifTag.XResolution: case ExifTag.YResolution: case ExifTag.BatteryLevel: case ExifTag.ExposureTime: case ExifTag.FNumber: case ExifTag.MDScalePixel: case ExifTag.CompressedBitsPerPixel: case ExifTag.ApertureValue: case ExifTag.MaxApertureValue: case ExifTag.SubjectDistance: case ExifTag.FocalLength: case ExifTag.FlashEnergy2: case ExifTag.FocalPlaneXResolution2: case ExifTag.FocalPlaneYResolution2: case ExifTag.ExposureIndex2: case ExifTag.Humidity: case ExifTag.Pressure: case ExifTag.Acceleration: case ExifTag.FlashEnergy: case ExifTag.FocalPlaneXResolution: case ExifTag.FocalPlaneYResolution: case ExifTag.ExposureIndex: case ExifTag.DigitalZoomRatio: case ExifTag.LensInfo: case ExifTag.GPSAltitude: case ExifTag.GPSDOP: case ExifTag.GPSSpeed: case ExifTag.GPSTrack: case ExifTag.GPSImgDirection: case ExifTag.GPSDestBearing: case ExifTag.GPSDestDistance: exifValue = new ExifValue(tag, ExifDataType.Rational, false); break; case ExifTag.BitsPerSample: case ExifTag.MinSampleValue: case ExifTag.MaxSampleValue: case ExifTag.GrayResponseCurve: case ExifTag.ColorMap: case ExifTag.ExtraSamples: case ExifTag.PageNumber: case ExifTag.TransferFunction: case ExifTag.Predictor: case ExifTag.HalftoneHints: case ExifTag.SampleFormat: case ExifTag.TransferRange: case ExifTag.DefaultImageColor: case ExifTag.JPEGLosslessPredictors: case ExifTag.JPEGPointTransforms: case ExifTag.YCbCrSubsampling: case ExifTag.CFARepeatPatternDim: case ExifTag.IntergraphPacketData: case ExifTag.ISOSpeedRatings: case ExifTag.SubjectArea: case ExifTag.SubjectLocation: exifValue = new ExifValue(tag, ExifDataType.Short, true); break; case ExifTag.OldSubfileType: case ExifTag.Compression: case ExifTag.PhotometricInterpretation: case ExifTag.Thresholding: case ExifTag.CellWidth: case ExifTag.CellLength: case ExifTag.FillOrder: case ExifTag.Orientation: case ExifTag.SamplesPerPixel: case ExifTag.PlanarConfiguration: case ExifTag.GrayResponseUnit: case ExifTag.ResolutionUnit: case ExifTag.CleanFaxData: case ExifTag.InkSet: case ExifTag.NumberOfInks: case ExifTag.DotRange: case ExifTag.Indexed: case ExifTag.OPIProxy: case ExifTag.JPEGProc: case ExifTag.JPEGRestartInterval: case ExifTag.YCbCrPositioning: case ExifTag.Rating: case ExifTag.RatingPercent: case ExifTag.ExposureProgram: case ExifTag.Interlace: case ExifTag.SelfTimerMode: case ExifTag.SensitivityType: case ExifTag.MeteringMode: case ExifTag.LightSource: case ExifTag.FocalPlaneResolutionUnit2: case ExifTag.SensingMethod2: case ExifTag.Flash: case ExifTag.ColorSpace: case ExifTag.FocalPlaneResolutionUnit: case ExifTag.SensingMethod: case ExifTag.CustomRendered: case ExifTag.ExposureMode: case ExifTag.WhiteBalance: case ExifTag.FocalLengthIn35mmFilm: case ExifTag.SceneCaptureType: case ExifTag.GainControl: case ExifTag.Contrast: case ExifTag.Saturation: case ExifTag.Sharpness: case ExifTag.SubjectDistanceRange: case ExifTag.GPSDifferential: exifValue = new ExifValue(tag, ExifDataType.Short, false); break; case ExifTag.Decode: exifValue = new ExifValue(tag, ExifDataType.SignedRational, true); break; case ExifTag.ShutterSpeedValue: case ExifTag.BrightnessValue: case ExifTag.ExposureBiasValue: case ExifTag.AmbientTemperature: case ExifTag.WaterDepth: case ExifTag.CameraElevationAngle: exifValue = new ExifValue(tag, ExifDataType.SignedRational, false); break; case ExifTag.JPEGTables: case ExifTag.OECF: case ExifTag.ExifVersion: case ExifTag.ComponentsConfiguration: case ExifTag.MakerNote: case ExifTag.UserComment: case ExifTag.FlashpixVersion: case ExifTag.SpatialFrequencyResponse: case ExifTag.SpatialFrequencyResponse2: case ExifTag.Noise: case ExifTag.CFAPattern: case ExifTag.DeviceSettingDescription: case ExifTag.ImageSourceData: case ExifTag.GPSProcessingMethod: case ExifTag.GPSAreaInformation: exifValue = new ExifValue(tag, ExifDataType.Undefined, true); break; case ExifTag.FileSource: case ExifTag.SceneType: exifValue = new ExifValue(tag, ExifDataType.Undefined, false); break; case ExifTag.StripOffsets: case ExifTag.TileByteCounts: case ExifTag.ImageLayer: exifValue = CreateNumber(tag, type, true); break; case ExifTag.ImageWidth: case ExifTag.ImageLength: case ExifTag.TileWidth: case ExifTag.TileLength: case ExifTag.BadFaxLines: case ExifTag.ConsecutiveBadFaxLines: case ExifTag.PixelXDimension: case ExifTag.PixelYDimension: exifValue = CreateNumber(tag, type, false); break; default: throw new NotSupportedException(); } exifValue.Value = value; return(exifValue); }
public static StreamWrapper CreateForWriting(Stream stream) { Throw.IfFalse(nameof(stream), stream.CanWrite, "The stream should be writeable."); return(new StreamWrapper(stream)); }
private static void CheckLength(long length) { Throw.IfFalse(nameof(length), IsSupportedLength(length), "Streams with a length larger than 2147483591 are not supported, read from file instead."); }
/// <summary> /// Returns the value of a format-specific option. /// </summary> /// <param name="format">The format to get the option for.</param> /// <param name="name">The name of the option.</param> /// <returns>The value of a format-specific option.</returns> public string GetDefine(MagickFormat format, string name) { Throw.IfNullOrEmpty(nameof(name), name); return(GetOption(ParseDefine(format, name))); }
/// <summary> /// Hclp hu perceptual hash. /// </summary> /// <param name="index">The index to use.</param> /// <returns>The Hclp hu perceptual hash.</returns> public double HclpHuPhash(int index) { Throw.IfOutOfRange(nameof(index), index, 7); return(_hclpHuPhash[index]); }
/// <summary> /// Initializes a new instance of the <see cref="MagickScript"/> class. /// </summary> /// <param name="xml">The IXPathNavigable that contains the script.</param> public MagickScript(IXPathNavigable xml) { Throw.IfNull(nameof(xml), xml); Initialize(xml.CreateNavigator()); }
/// <summary> /// Initializes a new instance of the <see cref="MagickScript"/> class. /// </summary> /// <param name="xml">The <see cref="XElement"/> that contains the script.</param> public MagickScript(XElement xml) { Throw.IfNull(nameof(xml), xml); Initialize(xml.CreateNavigator()); }
public override void SetPixel(IEnumerable <Pixel> pixels) { Throw.IfNull(nameof(pixels), pixels); base.SetPixel(pixels); }
public override void SetPixel(int x, int y, QuantumType[] value) { Throw.IfNullOrEmpty(nameof(value), value); SetPixelPrivate(x, y, value); }
public override void SetPixel(Pixel pixel) { Throw.IfNull(nameof(pixel), pixel); SetPixelPrivate(pixel.X, pixel.Y, pixel.Value); }
public override QuantumType[] GetArea(MagickGeometry geometry) { Throw.IfNull(nameof(geometry), geometry); return(base.GetArea(geometry)); }
private void CheckIndex(int x, int y) { Throw.IfOutOfRange(nameof(x), 0, Image.Width - 1, x, "Invalid X coordinate: {0}.", x); Throw.IfOutOfRange(nameof(y), 0, Image.Height - 1, y, "Invalid Y coordinate: {0}.", y); }
/// <summary> /// Performs compression on the specified the file. With some formats the image will be decoded /// and encoded and this will result in a small quality reduction. If the new file size is not /// smaller the file won't be overwritten. /// </summary> /// <param name="file">The image file to compress</param> public void Compress(FileInfo file) { Throw.IfNull(nameof(file), file); DoCompress(file); }
/// <summary> /// Performs compression on the specified file. With some formats the image will be decoded /// and encoded and this will result in a small quality reduction. If the new file size is not /// smaller the file won't be overwritten. /// </summary> /// <param name="file">The image file to compress.</param> /// <returns>True when the image could be compressed otherwise false.</returns> public bool Compress(FileInfo file) { Throw.IfNull(nameof(file), file); return(DoCompress(file)); }
private DrawableComposite(IMagickImage <QuantumType> image) { Throw.IfNull(nameof(image), image); _image = image; }
/// <summary> /// Returns a string that represents the current value with the specified encoding. /// </summary> /// <param name="encoding">The encoding to use.</param> /// <returns>A string that represents the current value with the specified encoding.</returns> public string ToString(Encoding encoding) { Throw.IfNull(nameof(encoding), encoding); return(encoding.GetString(_data)); }
/// <summary> /// Returns the value of a format-specific option. /// </summary> /// <param name="name">The name of the option.</param> /// <returns>The value of a format-specific option.</returns> public string GetDefine(string name) { Throw.IfNullOrEmpty(nameof(name), name); return(GetOption(name)); }
public static void IfNull(string paramName, object value) { Throw.IfNull(paramName, value); }
public static StreamWrapper CreateForReading(Stream stream) { Throw.IfFalse(nameof(stream), stream.CanRead, "The stream should be readable."); return(new StreamWrapper(stream)); }
/// <summary> /// Performs lossless compression on the file. If the new file size is not smaller the file /// won't be overwritten. /// </summary> /// <param name="file">The image file to optimize</param> public void LosslessCompress(FileInfo file) { Throw.IfNull("file", file); DoLosslessCompress(file); }
///<summary> /// Initializes a new instance of the ImageProfile class. ///</summary> ///<param name="name">The name of the profile.</param> protected ImageProfile(string name) { Throw.IfNullOrEmpty("name", name); Name = name; }
///<summary> /// Returns the value of the variable with the specified name. ///</summary> ///<param name="name">The name of the variable</param> public object Get(string name) { Throw.IfNullOrEmpty("name", name); return(_Variables[name]); }
private static void CheckChannels(int channels) { Throw.IfTrue(nameof(channels), channels < 1 || channels > 5, "Invalid number of channels (supported sizes are 1-5)."); }
/// <summary> /// Returns the Hu invariants. /// </summary> /// <param name="index">The index to use.</param> /// <returns>The Hu invariants.</returns> public double HuInvariants(int index) { Throw.IfOutOfRange(nameof(index), index, 8); return(_huInvariants[index]); }
protected DrawableCoordinates(IEnumerable <TCoordinateType> coordinates, int minCount) { Throw.IfNull(nameof(coordinates), coordinates); CheckCoordinates(new List <TCoordinateType>(coordinates), minCount); }
/// <summary> /// Performs lossless compression on the specified the file. If the new file size is not smaller /// the file won't be overwritten. /// </summary> /// <param name="file">The image file to compress</param> public void LosslessCompress(FileInfo file) { Throw.IfNull(nameof(file), file); DoLosslessCompress(file); }
private void CheckValue(object value) { if (value == null) { return; } Type type = value.GetType(); if (DataType == ExifDataType.Ascii) { Throw.IfFalse(nameof(value), type == typeof(string), "Value should be a string."); return; } if (type.IsArray) { Throw.IfTrue(nameof(value), !IsArray, "Value should not be an array."); type = type.GetElementType(); } else { Throw.IfTrue(nameof(value), IsArray, "Value should be an array."); } switch (DataType) { case ExifDataType.Byte: Throw.IfFalse(nameof(value), type == typeof(byte), "Value should be a byte{0}", IsArray ? " array." : "."); break; case ExifDataType.DoubleFloat: Throw.IfFalse(nameof(value), type == typeof(double), "Value should be a double{0}", IsArray ? " array." : "."); break; case ExifDataType.Long: Throw.IfFalse(nameof(value), type == typeof(uint), "Value should be an unsigned int{0}", IsArray ? " array." : "."); break; case ExifDataType.Rational: Throw.IfFalse(nameof(value), type == typeof(Rational), "Value should be a rational{0}", IsArray ? " array." : "."); break; case ExifDataType.Short: Throw.IfFalse(nameof(value), type == typeof(ushort), "Value should be an unsigned short{0}", IsArray ? " array." : "."); break; case ExifDataType.SignedByte: Throw.IfFalse(nameof(value), type == typeof(sbyte), "Value should be a signed byte{0}", IsArray ? " array." : "."); break; case ExifDataType.SignedLong: Throw.IfFalse(nameof(value), type == typeof(int), "Value should be an int{0}", IsArray ? " array." : "."); break; case ExifDataType.SignedRational: Throw.IfFalse(nameof(value), type == typeof(SignedRational), "Value should be a signed rational{0}", IsArray ? " array." : "."); break; case ExifDataType.SignedShort: Throw.IfFalse(nameof(value), type == typeof(short), "Value should be a short{0}", IsArray ? " array." : "."); break; case ExifDataType.SingleFloat: Throw.IfFalse(nameof(value), type == typeof(float), "Value should be a float{0}", IsArray ? " array." : "."); break; case ExifDataType.Undefined: Throw.IfFalse(nameof(value), type == typeof(byte), "Value should be a byte array."); break; default: throw new NotSupportedException(); } }
public override ushort[] ToShortArray(MagickGeometry geometry, string mapping) { Throw.IfNull(nameof(geometry), geometry); return(base.ToShortArray(geometry, mapping)); }