├── .gitignore
├── ImageResizer.sln
├── ImageResizer
├── App.ico
├── Classes
│ ├── CLI.cs
│ ├── CLIExitCode.cs
│ ├── IImageManipulator.cs
│ ├── IScriptAction.cs
│ ├── ImageManipulators
│ │ ├── AScaler.cs
│ │ ├── Interpolator.cs
│ │ ├── PlaneExtractor.cs
│ │ ├── RadiusResampler.cs
│ │ ├── Resampler.cs
│ │ └── Scalers
│ │ │ ├── NqScaler.cs
│ │ │ ├── PixelScaler.cs
│ │ │ ├── XbrScaler.cs
│ │ │ └── XbrzScaler.cs
│ ├── ReflectionUtils.cs
│ ├── ScriptActions
│ │ ├── LoadFileCommand.cs
│ │ ├── LoadStdInCommand.cs
│ │ ├── NullTransformCommand.cs
│ │ ├── ResizeCommand.cs
│ │ ├── SaveFileCommand.cs
│ │ ├── SaveStdOutCommand.cs
│ │ └── TargetToSourceCommand.cs
│ ├── ScriptEngine.cs
│ ├── ScriptSerializer.cs
│ ├── ScriptSerializerException.cs
│ └── SupportedManipulators.cs
├── Framework
│ └── System.StringExtensions.cs
├── ImageResizer.csproj
├── Imager
│ ├── Classes
│ │ ├── EnumDisplayNameAttribute.cs
│ │ ├── FloatImage.cs
│ │ ├── Kernels.cs
│ │ └── Windows.cs
│ ├── Filters
│ │ ├── ReverseAntiAlias.cs
│ │ ├── lib2xSCL.cs
│ │ ├── libBasic.cs
│ │ ├── libDES.cs
│ │ ├── libEagle.cs
│ │ ├── libHQ.cs
│ │ ├── libHawkynt.cs
│ │ ├── libKreed.cs
│ │ ├── libMAME.cs
│ │ ├── libSNES9x.cs
│ │ ├── libVBA.cs
│ │ ├── libXBR.cs
│ │ └── libXBRz.cs
│ ├── Image.Bitmaps.cs
│ ├── Image.Resizer.Interpolation.cs
│ ├── Image.Resizer.Loop.cs
│ ├── Image.Resizer.Loop.tt
│ ├── Image.Resizer.Nx.cs
│ ├── Image.Resizer.Parameterless.cs
│ ├── Image.Resizer.Resample.cs
│ ├── Image.Resizer.Xbr.cs
│ ├── Image.Resizer.Xbrz.cs
│ ├── Interface
│ │ ├── NqMode.cs
│ │ ├── NqScalerType.cs
│ │ ├── OutOfBoundsMode.cs
│ │ ├── PixelScalerType.cs
│ │ ├── ScalerInformation.cs
│ │ ├── XbrScalerType.cs
│ │ └── XbrzScalerType.cs
│ ├── PixelWorker.cs
│ ├── PixelWorker.tt
│ ├── cImage.cs
│ ├── cRGBCache.cs
│ └── sPixel.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Resources
│ └── CLIHelpText.txt
└── app.config
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.userprefs
2 | .project
3 | build/
4 | bin/
5 | obj/
6 |
--------------------------------------------------------------------------------
/ImageResizer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageResizer", "ImageResizer\ImageResizer.csproj", "{D22BAAAE-F358-438F-BFB3-880DAC29B4D4}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {D22BAAAE-F358-438F-BFB3-880DAC29B4D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {D22BAAAE-F358-438F-BFB3-880DAC29B4D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {D22BAAAE-F358-438F-BFB3-880DAC29B4D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {D22BAAAE-F358-438F-BFB3-880DAC29B4D4}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/ImageResizer/App.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebreaker/2dimagefilter/b50d2705606dc39d533ef9ea0624549158055832/ImageResizer/App.ico
--------------------------------------------------------------------------------
/ImageResizer/Classes/CLI.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using System.Collections.Generic;
23 | using System.Diagnostics.Contracts;
24 | using System.Drawing;
25 | using System.Drawing.Imaging;
26 | using System.IO;
27 | using System.Linq;
28 | using System.Reflection;
29 |
30 | using Classes.ScriptActions;
31 |
32 | using ImageResizer.Properties;
33 |
34 | namespace Classes {
35 | ///
36 | /// The command line interface for the application.
37 | ///
38 | internal static class CLI {
39 |
40 | ///
41 | /// Parses the command line arguments.
42 | ///
43 | /// The arguments.
44 | public static CLIExitCode ParseCommandLineArguments(string[] arguments) {
45 | if (arguments == null || arguments.Length < 1)
46 | {
47 | _ShowHelp();
48 | return (CLIExitCode.OK);
49 | }
50 |
51 | var engine = new ScriptEngine();
52 | var line = string.Join(" ", arguments.Select(a => string.Format(@"""{0}""", a)));
53 | Console.WriteLine("Executing the following script:");
54 | Console.WriteLine(line);
55 | Console.WriteLine();
56 |
57 | // load script from command line parameters
58 | try {
59 | ScriptSerializer.LoadFromString(engine, line);
60 | } catch (ScriptSerializerException e) {
61 | _ShowHelp();
62 | return (e.ErrorType);
63 | }
64 |
65 | // execute script
66 | try {
67 | engine.RepeatActions(_PreAction, _PostAction);
68 | } catch (Exception e) {
69 | Console.WriteLine(e.Message);
70 | return (CLIExitCode.RuntimeError);
71 | }
72 |
73 | return (CLIExitCode.OK);
74 | }
75 |
76 | private static void _PreAction(ScriptEngine engine, IScriptAction command) {
77 | var loadCommand = command as LoadFileCommand;
78 | if (loadCommand != null) {
79 | Console.WriteLine("Loading from file " + loadCommand.FileName);
80 | return;
81 | }
82 |
83 | var saveCommand = command as SaveFileCommand;
84 | if (saveCommand != null) {
85 | Console.WriteLine("Saving to file " + saveCommand.FileName);
86 | }
87 |
88 | var resizeCommand = command as ResizeCommand;
89 | if (resizeCommand != null) {
90 | Console.WriteLine("Applying filter : {0}", SupportedManipulators.MANIPULATORS.First(k => k.Value == resizeCommand.Manipulator).Key);
91 | Console.WriteLine(" Target percentage : {0}", (resizeCommand.Percentage == 0 ? "auto" : resizeCommand.Percentage + "%"));
92 | Console.WriteLine(" Target width : {0}", (resizeCommand.Width == 0 ? "auto" : resizeCommand.Width + "pixels"));
93 | Console.WriteLine(" Target height : {0}", (resizeCommand.Height == 0 ? "auto" : resizeCommand.Height + "pixels"));
94 | Console.WriteLine(" Hori. BPH : {0}", resizeCommand.HorizontalBph);
95 | Console.WriteLine(" Vert. BPH : {0}", resizeCommand.VerticalBph);
96 | Console.WriteLine(" Use Thresholds : {0}", resizeCommand.UseThresholds);
97 | Console.WriteLine(" Centered Grid : {0}", resizeCommand.UseCenteredGrid);
98 | Console.WriteLine(" Radius : {0}", resizeCommand.Radius);
99 | Console.WriteLine(" Repeat : {0} times", resizeCommand.Count);
100 | }
101 |
102 | }
103 |
104 | private static void _PostAction(ScriptEngine engine, IScriptAction command) {
105 |
106 | var loadCommand = command as LoadFileCommand;
107 | if (loadCommand != null) {
108 | Console.WriteLine(" File : {0} Bytes", new FileInfo(loadCommand.FileName).Length);
109 | Console.WriteLine(" Width : {0} Pixel", engine.SourceImage.Width);
110 | Console.WriteLine(" Height : {0} Pixel", engine.SourceImage.Height);
111 | Console.WriteLine(" Size : {0:0.00} MegaPixel", (engine.SourceImage.Width * engine.SourceImage.Height / 1000000.0));
112 | Console.WriteLine(" Type : {0}", ImageCodecInfo.GetImageDecoders().First(d => d.FormatID == engine.GdiSource.RawFormat.Guid).FormatDescription);
113 | Console.WriteLine(" Format : {0}", engine.GdiSource.PixelFormat);
114 | return;
115 | }
116 |
117 | var saveCommand = command as SaveFileCommand;
118 | if (saveCommand != null) {
119 | var reloadedImage = Image.FromFile(saveCommand.FileName);
120 | Console.WriteLine(" File : {0} Bytes", new FileInfo(saveCommand.FileName).Length);
121 | Console.WriteLine(" Width : {0} Pixel", reloadedImage.Width);
122 | Console.WriteLine(" Height : {0} Pixel", reloadedImage.Height);
123 | Console.WriteLine(" Size : {0:0.00} MegaPixel", (reloadedImage.Width * reloadedImage.Height / 1000000.0));
124 | Console.WriteLine(" Type : {0}", ImageCodecInfo.GetImageDecoders().First(d => d.FormatID == reloadedImage.RawFormat.Guid).FormatDescription);
125 | Console.WriteLine(" Format : {0}", reloadedImage.PixelFormat);
126 | }
127 | }
128 |
129 | ///
130 | /// Shows the CLI help.
131 | ///
132 | private static void _ShowHelp() {
133 |
134 | var longestFilterNameLength = SupportedManipulators.MANIPULATORS.Select(k => k.Key.Length).Max();
135 |
136 | // we're loading the help text as a template from an internal resource and then filling out the fields
137 | var lines = Resources.CLIHelpText
138 | .Replace("{appname}", ReflectionUtils.GetEntryAssemblyAttribute(p => p.Product).ToString())
139 | .Replace("{version}", ReflectionUtils.GetEntryAssemblyAttribute(v => v.Version).ToString())
140 | .Replace("{copyright}", ReflectionUtils.GetEntryAssemblyAttribute(c => c.Copyright).ToString())
141 | .Replace("{location}", Path.GetFileName(Assembly.GetEntryAssembly().Location))
142 | .Replace("{filterlist}", string.Join(Environment.NewLine,
143 | from i in SupportedManipulators.MANIPULATORS
144 | let d = ReflectionUtils.GetDescriptionForClass(i.Value.GetType())
145 | group i by d into g
146 | select string.Format("{0}{1}:", g.Key, _GetSupportedParameterStringFromManipulator(g.First().Value)) + Environment.NewLine + string.Join(
147 | Environment.NewLine,
148 | g.Select(j => string.Format("{0,-" + longestFilterNameLength + "}", j.Key))
149 | ) + Environment.NewLine)
150 | )
151 | .Replace("{centered}", ScriptSerializer.CENTERED_GRID_PARAMETER_NAME)
152 | .Replace("{repeat}", ScriptSerializer.REPEAT_PARAMETER_NAME)
153 | .Replace("{thresholds}", ScriptSerializer.THRESHOLDS_PARAMETER_NAME)
154 | .Replace("{radius}", ScriptSerializer.RADIUS_PARAMETER_NAME)
155 | .Replace("{vbounds}", ScriptSerializer.VBOUNDS_PARAMETER_NAME)
156 | .Replace("{hbounds}", ScriptSerializer.HBOUNDS_PARAMETER_NAME)
157 | .Replace("{save}", ScriptSerializer.SAVE_COMMAND_NAME)
158 | .Replace("{load}", ScriptSerializer.LOAD_COMMAND_NAME)
159 | .Replace("{script}", ScriptSerializer.SCRIPT_COMMAND_NAME)
160 | .Replace("{resize}", ScriptSerializer.RESIZE_COMMAND_NAME)
161 | .Replace("{stdin}", ScriptSerializer.STDIN_COMMAND_NAME)
162 | .Replace("{stdout}", ScriptSerializer.STDOUT_COMMAND_NAME)
163 | ;
164 | Console.WriteLine(lines);
165 | }
166 |
167 | ///
168 | /// Gets the list of supported parameters for the given manipulator.
169 | ///
170 | /// The manipulator.
171 | /// A text representing the supported parameters.
172 | private static string _GetSupportedParameterStringFromManipulator(IImageManipulator manipulator) {
173 | if (manipulator == null)
174 | return (null);
175 |
176 | var result = new List();
177 |
178 | if (manipulator.SupportsWidth)
179 | result.Add("width");
180 |
181 | if (manipulator.SupportsHeight)
182 | result.Add("height");
183 |
184 | if (manipulator.SupportsRepetitionCount)
185 | result.Add(ScriptSerializer.REPEAT_PARAMETER_NAME);
186 |
187 | if (manipulator.SupportsThresholds)
188 | result.Add(ScriptSerializer.THRESHOLDS_PARAMETER_NAME);
189 |
190 | if (manipulator.SupportsRadius)
191 | result.Add(ScriptSerializer.RADIUS_PARAMETER_NAME);
192 |
193 | if (manipulator.SupportsGridCentering)
194 | result.Add(ScriptSerializer.CENTERED_GRID_PARAMETER_NAME);
195 |
196 | return (result.Count < 1 ? null : " (" + string.Join(", ", result) + ")");
197 | }
198 |
199 | ///
200 | /// Saves an image and adjust jpeg quality if saving to jpeg.
201 | ///
202 | /// The filename.
203 | /// The image.
204 | /// true on success; otherwise, false.
205 | internal static CLIExitCode SaveHelper(string filename, Image image) {
206 | Contract.Requires(filename != null);
207 |
208 | if (image == null)
209 | return (CLIExitCode.NothingToSave);
210 |
211 | var extension = Path.GetExtension(filename);
212 | if (extension != null)
213 | extension = extension.ToUpperInvariant();
214 |
215 | try {
216 | if (extension == ".JPG" || extension == ".JPEG") {
217 | var codecs = ImageCodecInfo.GetImageEncoders();
218 | codecs = codecs.Where(info => info != null && info.MimeType == "image/jpeg").ToArray();
219 | if (codecs.Length <= 0) {
220 | return (CLIExitCode.JpegNotSupportedOnThisPlatform);
221 | }
222 | Contract.Assume(Encoder.Quality != null);
223 | image.Save(filename, codecs[0], new EncoderParameters {
224 | Param = new[] {
225 | new EncoderParameter(Encoder.Quality, (long)100)
226 | }
227 | });
228 | } else if (extension == ".BMP")
229 | image.Save(filename, ImageFormat.Bmp);
230 | else if (extension == ".GIF")
231 | image.Save(filename, ImageFormat.Gif);
232 | else if (extension == ".TIF")
233 | image.Save(filename, ImageFormat.Tiff);
234 | else
235 | image.Save(filename, ImageFormat.Png);
236 | } catch (Exception) {
237 | return (CLIExitCode.ExceptionDuringImageWrite);
238 | }
239 |
240 | return (CLIExitCode.OK);
241 | }
242 |
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/CLIExitCode.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | namespace Classes {
22 | internal enum CLIExitCode {
23 | RestartingInGuiMode = -1,
24 | OK = 0,
25 | UnknownParameter,
26 | TooLessArguments,
27 | JpegNotSupportedOnThisPlatform,
28 | NothingToSave,
29 | FilenameMustNotBeNull,
30 | InvalidTargetDimensions,
31 | CouldNotParseDimensionsAsWord,
32 | NothingToResize,
33 | UnknownFilter,
34 | ExceptionDuringImageLoad,
35 | ExceptionDuringImageWrite,
36 | InvalidFilterDescription,
37 | CouldNotParseParameterAsFloat,
38 | CouldNotParseParameterAsByte,
39 | InvalidOutOfBoundsMode,
40 |
41 | RuntimeError,
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/IImageManipulator.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | namespace Classes {
22 | internal interface IImageManipulator {
23 | bool SupportsWidth { get; }
24 | bool SupportsHeight { get; }
25 | bool SupportsRepetitionCount { get; }
26 | bool SupportsGridCentering { get; }
27 | bool SupportsThresholds { get; }
28 | bool SupportsRadius { get; }
29 | bool ChangesResolution { get; }
30 | string Description { get; }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/IScriptAction.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.Drawing;
23 |
24 | using Imager;
25 |
26 | namespace Classes {
27 | internal interface IScriptAction {
28 |
29 | bool ChangesSourceImage { get; }
30 | bool ChangesTargetImage { get; }
31 | bool ProvidesNewGdiSource { get; }
32 |
33 | bool Execute();
34 | Bitmap GdiSource { get; }
35 |
36 | cImage SourceImage { get; set; }
37 | cImage TargetImage { get; set; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/AScaler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.ComponentModel;
23 |
24 | using Imager;
25 |
26 | namespace Classes.ImageManipulators {
27 | [Description("Pixel art filters")]
28 | internal abstract class AScaler : IImageManipulator {
29 | #region Implementation of IImageManipulator
30 | public bool SupportsWidth { get { return (false); } }
31 | public bool SupportsHeight { get { return (false); } }
32 | public bool SupportsRepetitionCount { get { return (true); } }
33 | public bool SupportsGridCentering { get { return (false); } }
34 | public bool SupportsRadius { get { return (false); } }
35 | public bool ChangesResolution { get { return (true); } }
36 | public bool SupportsThresholds { get { return (true); } }
37 | public abstract string Description { get; }
38 | #endregion
39 |
40 | public abstract cImage Apply(cImage source);
41 | public abstract byte ScaleFactorX { get; }
42 | public abstract byte ScaleFactorY { get; }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/Interpolator.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.ComponentModel;
23 | using System.Diagnostics.Contracts;
24 | using System.Drawing.Drawing2D;
25 |
26 | using Imager;
27 |
28 | namespace Classes.ImageManipulators {
29 | [Description("GDI+ .NET internal filters")]
30 | internal class Interpolator : IImageManipulator {
31 | private readonly InterpolationMode _type;
32 |
33 | #region Implementation of IImageManipulator
34 | public bool SupportsWidth { get { return (true); } }
35 | public bool SupportsHeight { get { return (true); } }
36 | public bool SupportsRepetitionCount { get { return (false); } }
37 | public bool SupportsGridCentering { get { return (false); } }
38 | public bool SupportsRadius { get { return (false); } }
39 | public bool ChangesResolution { get { return (true); } }
40 | public bool SupportsThresholds { get { return (false); } }
41 | public string Description {
42 | get {
43 | switch (this._type) {
44 | case InterpolationMode.NearestNeighbor: {
45 | return ("Nearest neighbor interpolation using the Microsoft GDI+ API.");
46 | }
47 | case InterpolationMode.Bilinear: {
48 | return ("Bilinear interpolation using the Microsoft GDI+ API. No prefiltering is done. This mode is not suitable for shrinking an image below 50 percent of its original size.");
49 | }
50 | case InterpolationMode.Bicubic: {
51 | return ("Bicubic interpolation using the Microsoft GDI+ API. No prefiltering is done. This mode is not suitable for shrinking an image below 25 percent of its original size.");
52 | }
53 | case InterpolationMode.HighQualityBilinear: {
54 | return ("Bilinear interpolation using the Microsoft GDI+ API. Prefiltering is performed to ensure high-quality shrinking.");
55 | }
56 | case InterpolationMode.HighQualityBicubic: {
57 | return ("Bicubic interpolation using the Microsoft GDI+ API. Prefiltering is performed to ensure high-quality shrinking.");
58 | }
59 | default: {
60 | return (null);
61 | }
62 | }
63 | }
64 | }
65 | #endregion
66 |
67 | public cImage Apply(cImage source, int width, int height) {
68 | Contract.Requires(source != null);
69 | return (source.ApplyScaler(this._type, width, height));
70 | }
71 |
72 | public Interpolator(InterpolationMode type) {
73 | this._type = type;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/PlaneExtractor.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using System.ComponentModel;
23 | using System.Diagnostics.Contracts;
24 |
25 | using Imager;
26 |
27 | namespace Classes.ImageManipulators {
28 | [Description("Color component extractors")]
29 | internal class PlaneExtractor : IImageManipulator {
30 | private readonly Func _planeExtractionFunction;
31 | private readonly string _description;
32 |
33 | #region Implementation of IImageManipulator
34 | public bool SupportsWidth { get { return (false); } }
35 | public bool SupportsHeight { get { return (false); } }
36 | public bool SupportsRepetitionCount { get { return (false); } }
37 | public bool SupportsGridCentering { get { return (false); } }
38 | public bool ChangesResolution { get { return (false); } }
39 | public bool SupportsThresholds { get { return (false); } }
40 | public bool SupportsRadius { get { return (false); } }
41 | public string Description { get { return (this._description); } }
42 | #endregion
43 |
44 | public cImage Apply(cImage source) {
45 | return (this._planeExtractionFunction(source));
46 | }
47 |
48 | public PlaneExtractor(Func planeExtractionFunction, string description) {
49 | Contract.Requires(planeExtractionFunction != null);
50 | this._planeExtractionFunction = planeExtractionFunction;
51 | this._description = description;
52 | }
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/RadiusResampler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.ComponentModel;
23 | using System.Diagnostics.Contracts;
24 | using Imager;
25 | using Imager.Classes;
26 |
27 | namespace Classes.ImageManipulators {
28 | [Description("Radius-based filters")]
29 | internal class RadiusResampler : IImageManipulator {
30 | private readonly WindowType _type;
31 |
32 | #region Implementation of IImageManipulator
33 | public bool SupportsWidth { get { return (true); } }
34 | public bool SupportsHeight { get { return (true); } }
35 | public bool SupportsRepetitionCount { get { return (false); } }
36 | public bool SupportsGridCentering { get { return (true); } }
37 | public bool SupportsThresholds { get { return (false); } }
38 | public bool SupportsRadius { get { return (true); } }
39 | public bool ChangesResolution { get { return (true); } }
40 | public string Description { get { return (ReflectionUtils.GetDescriptionForEnumValue(this._type)); } }
41 | #endregion
42 |
43 | public cImage Apply(cImage source, int width, int height, float radius, bool useCenteredGrid) {
44 | Contract.Requires(source != null);
45 | return (source.ApplyScaler(this._type, width, height, radius, useCenteredGrid));
46 | }
47 |
48 | public RadiusResampler(WindowType type) {
49 | this._type = type;
50 | }
51 |
52 | public Kernels.FixedRadiusKernelInfo GetKernelMethodInfo(float radius) {
53 | return (Windows.WINDOWS[this._type].WithRadius(radius));
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/Resampler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.ComponentModel;
23 | using System.Diagnostics.Contracts;
24 | using Imager;
25 | using Imager.Classes;
26 |
27 | namespace Classes.ImageManipulators {
28 | [Description("General purpose filters")]
29 | internal class Resampler : IImageManipulator {
30 | private readonly KernelType _type;
31 |
32 | #region Implementation of IImageManipulator
33 | public bool SupportsWidth { get { return (true); } }
34 | public bool SupportsHeight { get { return (true); } }
35 | public bool SupportsRepetitionCount { get { return (false); } }
36 | public bool SupportsGridCentering { get { return (true); } }
37 | public bool SupportsThresholds { get { return (false); } }
38 | public bool SupportsRadius { get { return (false); } }
39 | public bool ChangesResolution { get { return (true); } }
40 | public string Description { get { return (ReflectionUtils.GetDescriptionForEnumValue(this._type)); } }
41 | #endregion
42 |
43 | public cImage Apply(cImage source, int width, int height, bool useCenteredGrid) {
44 | Contract.Requires(source != null);
45 | return (source.ApplyScaler(this._type, width, height, useCenteredGrid));
46 | }
47 |
48 | public Resampler(KernelType type) {
49 | this._type = type;
50 | }
51 |
52 | public Kernels.FixedRadiusKernelInfo GetKernelMethodInfo() {
53 | return (Kernels.KERNELS[this._type]);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/Scalers/NqScaler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System.Diagnostics.Contracts;
22 |
23 | using Imager;
24 | using Imager.Interface;
25 |
26 | namespace Classes.ImageManipulators.Scalers {
27 | internal class NqScaler : AScaler {
28 | private readonly NqScalerType _type;
29 | private readonly NqMode _mode;
30 | private readonly byte _scaleFactorX;
31 | private readonly byte _scaleFactorY;
32 |
33 | #region Implementation of AScaler
34 | public override cImage Apply(cImage source) {
35 | Contract.Requires(source != null);
36 | return (source.ApplyScaler(this._type, this._mode));
37 | }
38 | public override byte ScaleFactorX { get { return (this._scaleFactorX); } }
39 | public override byte ScaleFactorY { get { return (this._scaleFactorY); } }
40 | public override string Description { get { return (ReflectionUtils.GetDescriptionForEnumValue(this._type)); } }
41 | #endregion
42 |
43 | public NqScaler(NqScalerType type, NqMode mode) {
44 | var info = cImage.GetPixelScalerInfo(type);
45 | this._type = type;
46 | this._mode = mode;
47 | this._scaleFactorX = info.Item1;
48 | this._scaleFactorY = info.Item2;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/Scalers/PixelScaler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System.Diagnostics.Contracts;
22 |
23 | using Imager;
24 | using Imager.Interface;
25 |
26 | namespace Classes.ImageManipulators.Scalers {
27 | internal class PixelScaler : AScaler {
28 | private readonly PixelScalerType _type;
29 | private readonly byte _scaleFactorX;
30 | private readonly byte _scaleFactorY;
31 |
32 | #region Implementation of AScaler
33 | public override cImage Apply(cImage source) {
34 | Contract.Requires(source != null);
35 | return (source.ApplyScaler(this._type));
36 | }
37 | public override byte ScaleFactorX { get { return (this._scaleFactorX); } }
38 | public override byte ScaleFactorY { get { return (this._scaleFactorY); } }
39 | public override string Description { get { return (ReflectionUtils.GetDescriptionForEnumValue(this._type)); } }
40 | #endregion
41 |
42 | public PixelScaler(PixelScalerType type) {
43 | var info = cImage.GetPixelScalerInfo(type);
44 | this._type = type;
45 | this._scaleFactorX = info.Item1;
46 | this._scaleFactorY = info.Item2;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/Scalers/XbrScaler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System.Diagnostics.Contracts;
22 |
23 | using Imager;
24 | using Imager.Interface;
25 |
26 | namespace Classes.ImageManipulators.Scalers {
27 | internal class XbrScaler : AScaler {
28 | private readonly XbrScalerType _type;
29 | private readonly bool _allowAlphaBlending;
30 | private readonly byte _scaleFactorX;
31 | private readonly byte _scaleFactorY;
32 |
33 | #region Implementation of AScaler
34 | public override cImage Apply(cImage source) {
35 | Contract.Requires(source != null);
36 | return (source.ApplyScaler(this._type, this._allowAlphaBlending));
37 | }
38 | public override byte ScaleFactorX { get { return (this._scaleFactorX); } }
39 | public override byte ScaleFactorY { get { return (this._scaleFactorY); } }
40 | public override string Description { get { return (ReflectionUtils.GetDescriptionForEnumValue(this._type)); } }
41 | #endregion
42 |
43 | public XbrScaler(XbrScalerType type, bool allowAlphaBlending) {
44 | var info = cImage.GetPixelScalerInfo(type);
45 | this._type = type;
46 | this._allowAlphaBlending = allowAlphaBlending;
47 | this._scaleFactorX = info.Item1;
48 | this._scaleFactorY = info.Item2;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ImageManipulators/Scalers/XbrzScaler.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using Imager;
22 | using Imager.Interface;
23 | using System.Diagnostics.Contracts;
24 |
25 | namespace Classes.ImageManipulators.Scalers {
26 | internal class XbrzScaler : AScaler {
27 | private readonly XbrzScalerType _type;
28 | private readonly byte _scaleFactorX;
29 | private readonly byte _scaleFactorY;
30 |
31 | #region Implementation of AScaler
32 | public override cImage Apply(cImage source) {
33 | Contract.Requires(source != null);
34 | return (source.ApplyScaler(this._type));
35 | }
36 | public override byte ScaleFactorX { get { return (this._scaleFactorX); } }
37 | public override byte ScaleFactorY { get { return (this._scaleFactorY); } }
38 | public override string Description { get { return (ReflectionUtils.GetDescriptionForEnumValue(this._type)); } }
39 | #endregion
40 |
41 | public XbrzScaler(XbrzScalerType type) {
42 | var info = cImage.GetPixelScalerInfo(type);
43 | this._type = type;
44 | this._scaleFactorX = info.Item1;
45 | this._scaleFactorY = info.Item2;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ReflectionUtils.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using System.Collections.Generic;
23 | using System.ComponentModel;
24 | using System.Diagnostics.Contracts;
25 | using System.Linq;
26 | using System.Reflection;
27 |
28 |
29 | namespace Classes {
30 | internal static class ReflectionUtils {
31 | ///
32 | /// Gets a typed enumeration of all values of a given enumeration.
33 | ///
34 | /// The type of enumeration.
35 | /// All values.
36 | public static IEnumerable GetEnumValues() where TEnumeration : struct {
37 | Contract.Requires(typeof(TEnumeration).IsEnum, "Only enums supported");
38 | return (from TEnumeration i in Enum.GetValues(typeof(TEnumeration))
39 | select i);
40 | }
41 |
42 | ///
43 | /// Gets a descriptive name for a given enum value by trying to find a description attribute first or using the name for the given value.
44 | ///
45 | /// The type of the enumeration.
46 | /// The value.
47 | /// A descriptive text.
48 | public static string GetDisplayNameForEnumValue(TEnumeration value) where TEnumeration : struct {
49 | Contract.Requires(typeof(TEnumeration).IsEnum, "Only enum supported");
50 | var valueName = Enum.GetName(typeof(TEnumeration), value);
51 | var fieldInfo = typeof(TEnumeration).GetMember(valueName)[0];
52 | var descriptionAttribute = (DisplayNameAttribute)fieldInfo.GetCustomAttributes(typeof(DisplayNameAttribute), false).FirstOrDefault();
53 | return (descriptionAttribute == null ? valueName : descriptionAttribute.DisplayName);
54 | }
55 |
56 | ///
57 | /// Gets a descriptive name for a given enum value by trying to find a description attribute first or using the name for the given value.
58 | ///
59 | /// The type of the enumeration.
60 | /// The value.
61 | /// A descriptive text.
62 | public static string GetDescriptionForEnumValue(TEnumeration value) where TEnumeration : struct {
63 | Contract.Requires(typeof(TEnumeration).IsEnum, "Only enum supported");
64 | var valueName = Enum.GetName(typeof(TEnumeration), value);
65 | var fieldInfo = typeof(TEnumeration).GetMember(valueName)[0];
66 | var descriptionAttribute = (DescriptionAttribute)fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault();
67 | return (descriptionAttribute == null ? null : descriptionAttribute.Description);
68 | }
69 |
70 | ///
71 | /// Gets an attribute from the entry assembly.
72 | ///
73 | /// The type of the attribute.
74 | /// The getter.
75 | /// The attribute value.
76 | public static object GetEntryAssemblyAttribute(Func getter) where TAttribute : Attribute {
77 | Contract.Requires(getter != null);
78 | var assembly = Assembly.GetEntryAssembly();
79 | var attribute = assembly.GetCustomAttributes(typeof(TAttribute), true).First();
80 | return (getter((TAttribute)attribute));
81 | }
82 |
83 | ///
84 | /// Gets the description for a class.
85 | ///
86 | /// Type of the class.
87 | ///
88 | /// A descriptive text
89 | ///
90 | public static string GetDescriptionForClass(Type classType) {
91 | Contract.Requires(classType != null);
92 | var attribute = (DescriptionAttribute)classType.GetCustomAttributes(typeof(DescriptionAttribute), true).FirstOrDefault();
93 | if (attribute == null) {
94 |
95 | // when no description attribute was found
96 | var name = classType.FullName;
97 | var lastDot = name == null ? -1 : name.LastIndexOf('.');
98 |
99 | // when there is no dot in the type name, just return the name
100 | if (lastDot < 0)
101 | return (name);
102 |
103 | // otherwise return the last part of the name
104 | return (name.Substring(lastDot + 1));
105 | }
106 |
107 | return (attribute.Description);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/LoadFileCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System.Diagnostics.Contracts;
22 | using System.Drawing;
23 |
24 | using Imager;
25 |
26 | namespace Classes.ScriptActions {
27 | internal class LoadFileCommand : IScriptAction {
28 | #region Implementation of IScriptAction
29 | public bool ChangesSourceImage { get { return (true); } }
30 |
31 | public bool ChangesTargetImage { get { return (true); } }
32 | public bool ProvidesNewGdiSource { get { return (true); } }
33 |
34 | public bool Execute() {
35 | this.SourceImage = cImage.FromBitmap(this.GdiSource = (Bitmap)Image.FromFile(this._fileName));
36 | return (true);
37 | }
38 |
39 | public cImage SourceImage { get; set; }
40 |
41 | public cImage TargetImage { get { return (null); } set { } }
42 |
43 | public Bitmap GdiSource { get; private set; }
44 | #endregion
45 |
46 | private readonly string _fileName;
47 |
48 | public string FileName { get { return (this._fileName); } }
49 |
50 | public LoadFileCommand(string fileName) {
51 | Contract.Requires(!string.IsNullOrWhiteSpace(fileName));
52 | this._fileName = fileName;
53 | }
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/LoadStdInCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using System.Drawing;
24 |
25 | using Imager;
26 |
27 | namespace Classes.ScriptActions {
28 | internal class LoadStdInCommand : IScriptAction {
29 | #region Implementation of IScriptAction
30 | public bool ChangesSourceImage { get { return (true); } }
31 |
32 | public bool ChangesTargetImage { get { return (true); } }
33 | public bool ProvidesNewGdiSource { get { return (true); } }
34 |
35 | public bool Execute() {
36 | using (var stream = Console.OpenStandardInput())
37 | this.SourceImage = cImage.FromBitmap(this.GdiSource = (Bitmap)Image.FromStream(stream, false));
38 | return (true);
39 | }
40 |
41 | public cImage SourceImage { get; set; }
42 |
43 | public cImage TargetImage { get { return (null); } set { } }
44 |
45 | public Bitmap GdiSource { get; private set; }
46 | #endregion
47 |
48 | public LoadStdInCommand() { }
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/NullTransformCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.Drawing;
23 |
24 | using Imager;
25 |
26 | namespace Classes.ScriptActions {
27 | internal class NullTransformCommand : IScriptAction {
28 | #region Implementation of IScriptAction
29 | public bool ChangesSourceImage { get { return (false); } }
30 |
31 | public bool ChangesTargetImage { get { return (true); } }
32 | public bool ProvidesNewGdiSource { get { return (false); } }
33 |
34 | public bool Execute() {
35 | this.TargetImage = this.SourceImage;
36 | return (true);
37 | }
38 |
39 | public Bitmap GdiSource { get { return (null); } }
40 |
41 | public cImage SourceImage { get; set; }
42 |
43 | public cImage TargetImage { get; set; }
44 | #endregion
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/ResizeCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using System.Drawing;
24 |
25 | using Classes.ImageManipulators;
26 | using Imager;
27 | using Imager.Interface;
28 |
29 | using word = System.UInt16;
30 |
31 | namespace Classes.ScriptActions {
32 | internal class ResizeCommand : IScriptAction {
33 | #region Implementation of IScriptAction
34 | public bool ChangesSourceImage { get { return (false); } }
35 |
36 | public bool ChangesTargetImage { get { return (true); } }
37 | public bool ProvidesNewGdiSource { get { return (false); } }
38 |
39 | public bool Execute() {
40 | var source = this._applyToTarget ? this.TargetImage : this.SourceImage;
41 |
42 | var width = this._width;
43 | var height = this._height;
44 |
45 | // pverwrite dimensions from percentage if needed
46 | var percentage = this._percentage;
47 | if (percentage > 0) {
48 | width = (word)Math.Round(source.Width * percentage / 100d);
49 | height = (word)Math.Round(source.Height * percentage / 100d);
50 | }
51 |
52 | // correct aspect ratio if needed
53 | if (this._maintainAspect) {
54 | if (width == 0) {
55 | width = (word)Math.Round((double)height * source.Width / source.Height);
56 | } else {
57 | height = (word)Math.Round((double)width * source.Height / source.Width);
58 | }
59 | }
60 |
61 | sPixel.AllowThresholds = this._useThresholds;
62 | source.HorizontalOutOfBoundsMode = this._horizontalBph;
63 | source.VerticalOutOfBoundsMode = this._verticalBph;
64 |
65 | cImage result = null;
66 | var method = this._manipulator;
67 | var scaler = method as AScaler;
68 | var interpolator = method as Interpolator;
69 | var planeExtractor = method as PlaneExtractor;
70 | var resampler = method as Resampler;
71 | var radiusResampler = method as RadiusResampler;
72 |
73 | if (scaler != null) {
74 | result = source;
75 | for (var i = 0; i < this._count; i++)
76 | result = scaler.Apply(result);
77 | } else {
78 | if (interpolator != null)
79 | result = interpolator.Apply(source, width, height);
80 | else if (planeExtractor != null)
81 | result = planeExtractor.Apply(source);
82 | else if (resampler != null)
83 | result = resampler.Apply(source, width, height, this._useCenteredGrid);
84 | else if (radiusResampler != null)
85 | result = radiusResampler.Apply(source, width, height, this._radius, this._useCenteredGrid);
86 | }
87 |
88 | this.TargetImage = result;
89 | return (true);
90 | }
91 |
92 | public Bitmap GdiSource { get { return (null); } }
93 |
94 | public cImage SourceImage { get; set; }
95 |
96 | public cImage TargetImage { get; set; }
97 | #endregion
98 |
99 | private readonly IImageManipulator _manipulator;
100 | public IImageManipulator Manipulator { get { return (this._manipulator); } }
101 |
102 | private readonly word _width;
103 | public word Width { get { return (this._width); } }
104 |
105 | private readonly word _height;
106 | public word Height { get { return (this._height); } }
107 |
108 | private readonly bool _maintainAspect;
109 | public bool MaintainAspect { get { return (this._maintainAspect); } }
110 |
111 | private readonly OutOfBoundsMode _horizontalBph;
112 | public OutOfBoundsMode HorizontalBph { get { return (this._horizontalBph); } }
113 |
114 | private readonly OutOfBoundsMode _verticalBph;
115 | public OutOfBoundsMode VerticalBph { get { return (this._verticalBph); } }
116 |
117 | private readonly byte _count;
118 | public byte Count { get { return (this._count); } }
119 |
120 | private readonly bool _useThresholds;
121 | public bool UseThresholds { get { return (this._useThresholds); } }
122 |
123 | private readonly bool _useCenteredGrid;
124 | public bool UseCenteredGrid { get { return (this._useCenteredGrid); } }
125 |
126 | private readonly float _radius;
127 | public float Radius { get { return (this._radius); } }
128 |
129 | private readonly word _percentage;
130 | public word Percentage { get { return (this._percentage); } }
131 |
132 | private readonly bool _applyToTarget;
133 |
134 | public ResizeCommand(bool applyToTarget, IImageManipulator manipulator, word width, word height, word percentage, bool maintainAspect, OutOfBoundsMode horizontalBph, OutOfBoundsMode verticalBph, byte count, bool useThresholds, bool useCenteredGrid, float radius) {
135 | this._applyToTarget = applyToTarget;
136 | this._manipulator = manipulator;
137 | this._width = width;
138 | this._height = height;
139 | this._maintainAspect = maintainAspect;
140 | this._horizontalBph = horizontalBph;
141 | this._verticalBph = verticalBph;
142 | this._count = count;
143 | this._useThresholds = useThresholds;
144 | this._useCenteredGrid = useCenteredGrid;
145 | this._radius = radius;
146 | this._percentage = percentage;
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/SaveFileCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using System.Diagnostics.Contracts;
24 | using System.Drawing;
25 |
26 | using Imager;
27 |
28 | namespace Classes.ScriptActions {
29 | internal class SaveFileCommand : IScriptAction {
30 | #region Implementation of IScriptAction
31 | public bool ChangesSourceImage { get { return (false); } }
32 |
33 | public bool ChangesTargetImage { get { return (false); } }
34 | public bool ProvidesNewGdiSource { get { return (false); } }
35 |
36 | public bool Execute() {
37 | var result = CLI.SaveHelper(this._fileName, this.TargetImage.ToBitmap());
38 | if (result == CLIExitCode.NothingToSave)
39 | throw new NullReferenceException("Nothing to save");
40 | if (result == CLIExitCode.JpegNotSupportedOnThisPlatform)
41 | throw new InvalidOperationException("Jpeg not supported");
42 |
43 | return (result == CLIExitCode.OK);
44 | }
45 |
46 | public Bitmap GdiSource { get { return (null); } }
47 |
48 | public cImage SourceImage { get; set; }
49 |
50 | public cImage TargetImage { get; set; }
51 | #endregion
52 |
53 | private readonly string _fileName;
54 |
55 | public string FileName { get { return (this._fileName); } }
56 |
57 | public SaveFileCommand(string fileName) {
58 | Contract.Requires(!string.IsNullOrWhiteSpace(fileName));
59 | this._fileName = fileName;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/SaveStdOutCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using System.Drawing;
24 | using System.Drawing.Imaging;
25 |
26 | using Imager;
27 |
28 | namespace Classes.ScriptActions {
29 | internal class SaveStdOutCommand : IScriptAction {
30 | #region Implementation of IScriptAction
31 | public bool ChangesSourceImage { get { return (false); } }
32 |
33 | public bool ChangesTargetImage { get { return (false); } }
34 | public bool ProvidesNewGdiSource { get { return (false); } }
35 |
36 | public bool Execute() {
37 | using (var stream = Console.OpenStandardOutput())
38 | this.TargetImage.ToBitmap().Save(stream, ImageFormat.Png);
39 | return (true);
40 | }
41 |
42 | public Bitmap GdiSource { get { return (null); } }
43 |
44 | public cImage SourceImage { get; set; }
45 |
46 | public cImage TargetImage { get; set; }
47 | #endregion
48 |
49 | public SaveStdOutCommand() { }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptActions/TargetToSourceCommand.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.Drawing;
23 |
24 | using Imager;
25 |
26 | namespace Classes.ScriptActions {
27 | internal class TargetToSourceCommand : IScriptAction {
28 | #region Implementation of IScriptAction
29 | public bool ChangesSourceImage { get { return (true); } }
30 | public bool ChangesTargetImage { get { return (true); } }
31 | public bool ProvidesNewGdiSource { get { return (false); } }
32 |
33 | public bool Execute() {
34 | this.SourceImage = this.TargetImage;
35 | this.TargetImage = null;
36 | return (true);
37 | }
38 |
39 | public Bitmap GdiSource { get { return (null); } }
40 |
41 | public cImage SourceImage { get; set; }
42 |
43 | public cImage TargetImage { get; set; }
44 | #endregion
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptEngine.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using System.Drawing;
24 | using System.Linq;
25 | using System.Collections.Generic;
26 | using System.Diagnostics.Contracts;
27 |
28 | using Imager;
29 |
30 | namespace Classes {
31 | internal class ScriptEngine {
32 |
33 | ///
34 | /// Current source image.
35 | ///
36 | private cImage _sourceImage;
37 | ///
38 | /// Current source image as a GDI+ version.
39 | ///
40 | private Bitmap _gdiSource;
41 | ///
42 | /// Current target image.
43 | ///
44 | private cImage _targetImage;
45 | ///
46 | /// Current source image as a GDI+ version.
47 | ///
48 | private Bitmap _gdiTarget;
49 |
50 | ///
51 | /// Gets or sets the source image.
52 | ///
53 | ///
54 | /// The source image.
55 | ///
56 | public cImage SourceImage {
57 | get { return (this._sourceImage); }
58 | private set {
59 | this._sourceImage = value;
60 | if (this._gdiSource != null)
61 | this._gdiSource.Dispose();
62 | this._gdiSource = null;
63 | }
64 | }
65 |
66 | ///
67 | /// Gets or sets the target image.
68 | ///
69 | ///
70 | /// The target image.
71 | ///
72 | public cImage TargetImage {
73 | get { return (this._targetImage); }
74 | private set {
75 | this._targetImage = value;
76 | if (this._gdiTarget != null)
77 | this._gdiTarget.Dispose();
78 | this._gdiTarget = null;
79 | }
80 | }
81 |
82 | ///
83 | /// Gets the GDI source.
84 | ///
85 | public Bitmap GdiSource { get { return (this._gdiSource ?? (this._gdiSource = this._sourceImage == null ? null : this._sourceImage.ToBitmap())); } }
86 |
87 | ///
88 | /// Gets the GDI target.
89 | ///
90 | public Bitmap GdiTarget { get { return (this._gdiTarget ?? (this._gdiTarget = this._targetImage == null ? null : this._targetImage.ToBitmap())); } }
91 |
92 | ///
93 | /// Current list of actions.
94 | ///
95 | private readonly List _actionList = new List();
96 |
97 | ///
98 | /// Gets a value indicating whether this instance is source image changed.
99 | ///
100 | ///
101 | /// true if this instance is source image changed; otherwise, false.
102 | ///
103 | public bool IsSourceImageChanged { get; private set; }
104 |
105 | ///
106 | /// Gets a value indicating whether this instance is target image changed.
107 | ///
108 | ///
109 | /// true if this instance is target image changed; otherwise, false.
110 | ///
111 | public bool IsTargetImageChanged { get; private set; }
112 |
113 | ///
114 | /// Clears the action list.
115 | ///
116 | public void Clear() {
117 | this._actionList.Clear();
118 | }
119 |
120 | ///
121 | /// Gets the actions.
122 | /// Note: We're creating an enumeration so our own list stays save and is not modified by another class.
123 | ///
124 | public IEnumerable Actions { get { return (this._actionList.Select(t => t)); } }
125 |
126 | ///
127 | /// Executes the action.
128 | ///
129 | /// The action.
130 | public void ExecuteAction(IScriptAction action) {
131 | this._ExecuteAction(action, true);
132 | }
133 |
134 | ///
135 | /// Repeats the actions from the action list.
136 | ///
137 | /// The pre action.
138 | /// The post action.
139 | public void RepeatActions(Action preAction = null, Action postAction = null) {
140 | var actions = this._actionList;
141 | foreach (var action in actions) {
142 | if (preAction != null)
143 | preAction(this, action);
144 | this._ExecuteAction(action, false);
145 | if (postAction != null)
146 | postAction(this, action);
147 | }
148 | }
149 |
150 | ///
151 | /// Adds the given action without executing it.
152 | ///
153 | /// The action.
154 | public void AddWithoutExecution(IScriptAction action) {
155 | Contract.Requires(action != null);
156 | this._actionList.Add(action);
157 | }
158 |
159 | ///
160 | /// Executes the given action.
161 | ///
162 | /// The action.
163 | /// if set to true the action will be added to the action list afterwards.
164 | private void _ExecuteAction(IScriptAction action, bool addToList) {
165 | Contract.Requires(action != null);
166 |
167 | action.SourceImage = this.SourceImage;
168 | action.TargetImage = this.TargetImage;
169 |
170 | this.IsSourceImageChanged = false;
171 | this.IsTargetImageChanged = false;
172 |
173 | var result = action.Execute();
174 |
175 | // execution of action failed
176 | Contract.Assert(result, "action failed somehow");
177 |
178 | if (addToList)
179 | this.AddWithoutExecution(action);
180 |
181 | if (action.ChangesSourceImage) {
182 | this.SourceImage = action.SourceImage;
183 | this.IsSourceImageChanged = true;
184 | }
185 |
186 | if (action.ChangesTargetImage) {
187 | this.TargetImage = action.TargetImage;
188 | this.IsTargetImageChanged = true;
189 | }
190 |
191 | if (action.ProvidesNewGdiSource)
192 | this._gdiSource = action.GdiSource;
193 | }
194 |
195 | ///
196 | /// Removes everything since the last source change.
197 | ///
198 | public void RevertToLastSource() {
199 | var actions = this._actionList;
200 | while (actions.Any() && !actions.Last().ChangesSourceImage)
201 | actions.RemoveAt(actions.Count - 1);
202 | }
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/ScriptSerializerException.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 |
23 | namespace Classes {
24 | internal class ScriptSerializerException : Exception {
25 | private readonly string _filename;
26 | public string Filename { get { return (this._filename); } }
27 |
28 | private readonly int _lineNumber;
29 | public int LineNumber { get { return (this._lineNumber); } }
30 |
31 | private readonly CLIExitCode _errorType;
32 | public CLIExitCode ErrorType { get { return (this._errorType); } }
33 |
34 | public ScriptSerializerException(string filename, int lineNumber, CLIExitCode errorType) {
35 | this._filename = filename;
36 | this._lineNumber = lineNumber;
37 | this._errorType = errorType;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ImageResizer/Classes/SupportedManipulators.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using Classes.ImageManipulators;
22 | using Classes.ImageManipulators.Scalers;
23 | using Imager;
24 | using Imager.Classes;
25 | using Imager.Interface;
26 | using System.Collections.Generic;
27 | using System.Linq;
28 |
29 | namespace Classes {
30 | internal static class SupportedManipulators {
31 | public static readonly KeyValuePair[] MANIPULATORS = new KeyValuePair[0]
32 |
33 | #region add interpolators
34 | .Concat(
35 | from p in cImage.INTERPOLATORS
36 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p) + " ", new Interpolator(p))
37 | )
38 | #endregion
39 |
40 | #region add resampler
41 | .Concat(
42 | from p in ReflectionUtils.GetEnumValues()
43 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p), new Resampler(p))
44 | )
45 | .Concat(
46 | from p in ReflectionUtils.GetEnumValues()
47 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p), new RadiusResampler(p))
48 | )
49 |
50 | #endregion
51 |
52 | #region add pixel resizer
53 | .Concat(
54 | from p in ReflectionUtils.GetEnumValues()
55 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p), new PixelScaler(p))
56 | )
57 | #endregion
58 |
59 | #region add xbr resizer
60 | .Concat(
61 | from p in ReflectionUtils.GetEnumValues()
62 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p) + " ", new XbrScaler(p, false))
63 | )
64 | .Concat(
65 | from p in ReflectionUtils.GetEnumValues()
66 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p), new XbrScaler(p, true))
67 | )
68 | #endregion
69 |
70 | #region add xbrz resizer
71 | .Concat(
72 | from p in ReflectionUtils.GetEnumValues()
73 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p), new XbrzScaler(p))
74 | )
75 | #endregion
76 |
77 | #region add nq resizer
78 | .Concat(
79 | from p in ReflectionUtils.GetEnumValues()
80 | from m in ReflectionUtils.GetEnumValues()
81 | select new KeyValuePair(ReflectionUtils.GetDisplayNameForEnumValue(p) + (m == NqMode.Normal ? string.Empty : " " + ReflectionUtils.GetDisplayNameForEnumValue(m)), new NqScaler(p, m))
82 | )
83 | #endregion
84 |
85 | #region plane extractors
86 | .Concat(
87 | new[] {
88 | new KeyValuePair("Red",new PlaneExtractor(c=>c.Red,"Returns only the red channel of the source image.")),
89 | new KeyValuePair("Green",new PlaneExtractor(c=>c.Green,"Returns only the green channel of the source image.")),
90 | new KeyValuePair("Blue",new PlaneExtractor(c=>c.Blue,"Returns only the blue channel of the source image.")),
91 | new KeyValuePair("Alpha",new PlaneExtractor(c=>c.Alpha,"Returns only the alpha channel of the source image.")),
92 | new KeyValuePair("Luminance",new PlaneExtractor(c=>c.Luminance,"Returns only the luminance channel of the source image.")),
93 | new KeyValuePair("ChrominanceU",new PlaneExtractor(c=>c.ChrominanceU,"Returns only the chroma-U channel of the source image.")),
94 | new KeyValuePair("ChrominanceV",new PlaneExtractor(c=>c.ChrominanceV,"Returns only the chroma-V channel of the source image.")),
95 | new KeyValuePair("u",new PlaneExtractor(c=>c.u,"Returns only the alternate chroma-U of the source image.")),
96 | new KeyValuePair("v",new PlaneExtractor(c=>c.v,"Returns only the alternate chroma-V channel of the source image.")),
97 | new KeyValuePair("Hue",new PlaneExtractor(c=>c.Hue,"Returns only the hue channel of the source image.")),
98 | new KeyValuePair("Hue Colored",new PlaneExtractor(c=>c.HueColored,"Returns the colorized hue channel of the source image.")),
99 | new KeyValuePair("Brightness",new PlaneExtractor(c=>c.Brightness,"Returns only the brightness channel of the source image.")),
100 | new KeyValuePair("Min",new PlaneExtractor(c=>c.Min,"Returns only the minimum component of the RGB channels of the source image.")),
101 | new KeyValuePair("Max",new PlaneExtractor(c=>c.Max,"Returns only the maximum component of the RGB channels of the source image.")),
102 | new KeyValuePair("ExtractColors",new PlaneExtractor(c=>c.ExtractColors,"Tries to extract the full saturated colors of the source image.")),
103 | new KeyValuePair("ExtractDeltas",new PlaneExtractor(c=>c.ExtractDeltas,"The difference between the original source image and the hue-colored result.")),
104 | }
105 | )
106 | #endregion
107 |
108 | .ToArray();
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/ImageResizer/Framework/System.StringExtensions.cs:
--------------------------------------------------------------------------------
1 | #region (c)2010-2020 Hawkynt
2 | /*
3 | This file is part of Hawkynt's .NET Framework extensions.
4 |
5 | Hawkynt's .NET Framework extensions are free software:
6 | you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | Hawkynt's .NET Framework extensions is distributed in the hope that
12 | it will be useful, but WITHOUT ANY WARRANTY; without even the implied
13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 | the GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with Hawkynt's .NET Framework extensions.
18 | If not, see .
19 | */
20 | #endregion
21 |
22 | using System.Collections.Generic;
23 |
24 | namespace System {
25 | internal static partial class StringExtensions {
26 | ///
27 | /// Determines whether the given string is null or whitespace-only.
28 | ///
29 | /// The this.
30 | ///
31 | /// true if the given string is null or whitespace-only; otherwise, false.
32 | ///
33 | public static bool IsNullOrWhiteSpace(this string This) {
34 | return (string.IsNullOrWhiteSpace(This));
35 | }
36 |
37 | ///
38 | /// Splits a string by a given delimiter and respects any quotes.
39 | ///
40 | /// This String.
41 | /// The delimiter.
42 | /// The quoting character.
43 | ///
44 | public static IEnumerable SplitWithQuotes(this string This, char delimiter = ',', char quotingCharacter = '"') {
45 | if (This == null)
46 | yield break;
47 |
48 | var lastPiece = string.Empty;
49 | var isInQuoteMode = false;
50 |
51 | var length = This.Length;
52 | for (var index = 0; index < length; index++) {
53 | var currentChar = This[index];
54 | if (isInQuoteMode) {
55 | if (currentChar == quotingCharacter)
56 | isInQuoteMode = false;
57 | else
58 | lastPiece += currentChar;
59 | } else {
60 | if (currentChar == delimiter) {
61 | yield return lastPiece;
62 | lastPiece = string.Empty;
63 | } else if (currentChar == quotingCharacter)
64 | isInQuoteMode = true;
65 | else
66 | lastPiece += currentChar;
67 | }
68 | }
69 | yield return lastPiece;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Classes/EnumDisplayNameAttribute.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using System.ComponentModel;
24 |
25 | namespace Imager.Classes {
26 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
27 | public class EnumDisplayNameAttribute : DisplayNameAttribute {
28 | public EnumDisplayNameAttribute(string name)
29 | : base(name) {
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/ReverseAntiAlias.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 |
4 | namespace Imager.Filters {
5 | internal static class ReverseAntiAlias {
6 | ///
7 | /// Christoph Feck's (christoph@maxiom.de) Reverse Anti-Alias filter
8 | /// TODO: make mathutils and join clamp, min and max with the ones from spixel
9 | ///
10 | /// The worker.
11 | public static void Process(PixelWorkerworker ) {
12 |
13 | var b1 = worker.SourceP0M2();
14 | var b = worker.SourceP0M1();
15 | var d = worker.SourceM1P0();
16 | var e = worker.SourceP0P0();
17 | var f = worker.SourceP1P0();
18 | var h = worker.SourceP0P1();
19 | var h5 = worker.SourceP0P2();
20 | var d0 = worker.SourceM2P0();
21 | var f4 = worker.SourceP2P0();
22 |
23 | var redPart = _ReverseAntiAlias(b1.Red, b.Red, d.Red, e.Red, f.Red, h.Red, h5.Red, d0.Red, f4.Red);
24 | var greenPart = _ReverseAntiAlias(b1.Green, b.Green, d.Green, e.Green, f.Green, h.Green, h5.Green, d0.Green, f4.Green);
25 | var bluePart = _ReverseAntiAlias(b1.Blue, b.Blue, d.Blue, e.Blue, f.Blue, h.Blue, h5.Blue, d0.Blue, f4.Blue);
26 | var alphaPart = _ReverseAntiAlias(b1.Alpha, b.Alpha, d.Alpha, e.Alpha, f.Alpha, h.Alpha, h5.Alpha, d0.Alpha, f4.Alpha);
27 |
28 | worker.TargetP0P0( sPixel.FromRGBA(redPart.Item1, greenPart.Item1, bluePart.Item1, alphaPart.Item1));
29 | worker.TargetP1P0(sPixel.FromRGBA(redPart.Item2, greenPart.Item2, bluePart.Item2, alphaPart.Item2));
30 | worker.TargetP0P1( sPixel.FromRGBA(redPart.Item3, greenPart.Item3, bluePart.Item3, alphaPart.Item3));
31 | worker.TargetP1P1( sPixel.FromRGBA(redPart.Item4, greenPart.Item4, bluePart.Item4, alphaPart.Item4));
32 | }
33 |
34 | ///
35 | /// The internal function which is called for each channel separately.
36 | ///
37 | /// The b1.
38 | /// The B.
39 | /// The D.
40 | /// The E.
41 | /// The F.
42 | /// The H.
43 | /// The h5.
44 | /// The d0.
45 | /// The f4.
46 | ///
47 | private static Tuple _ReverseAntiAlias(int b1, int b, int d, int e, int f, int h, int h5, int d0, int f4) {
48 |
49 | var n1 = b1;
50 | var n2 = b;
51 | var s = e;
52 | var n3 = h;
53 | var n4 = h5;
54 | var aa = n2 - n1;
55 | var bb = s - n2;
56 | var cc = n3 - s;
57 | var dd = n4 - n3;
58 |
59 | var tilt = (7 * (bb + cc) - 3 * (aa + dd)) / 16;
60 |
61 | var m = (s < 128) ? 2 * s : 2 * (byte.MaxValue - s);
62 |
63 | m = min(m, 2 * abs(bb));
64 | m = min(m, 2 * abs(cc));
65 |
66 | tilt = clamp(tilt, -m, m);
67 |
68 | var s1 = s + tilt / 2;
69 | var s0 = s1 - tilt;
70 |
71 | n1 = d0;
72 | n2 = d;
73 | s = s0;
74 | n3 = f;
75 | n4 = f4;
76 | aa = n2 - n1;
77 | bb = s - n2;
78 | cc = n3 - s;
79 | dd = n4 - n3;
80 |
81 | tilt = (7 * (bb + cc) - 3 * (aa + dd)) / 16;
82 |
83 | m = (s < 128) ? 2 * s : 2 * (byte.MaxValue - s);
84 |
85 | m = min(m, 2 * abs(bb));
86 | m = min(m, 2 * abs(cc));
87 |
88 | tilt = clamp(tilt, -m, m);
89 |
90 | var e1 = s + tilt / 2;
91 | var e0 = e1 - tilt;
92 |
93 | s = s1;
94 | bb = s - n2;
95 | cc = n3 - s;
96 |
97 | tilt = (7 * (bb + cc) - 3 * (aa + dd)) / 16;
98 |
99 | m = (s < 128) ? 2 * s : 2 * (byte.MaxValue - s);
100 |
101 | m = min(m, 2 * abs(bb));
102 | m = min(m, 2 * abs(cc));
103 |
104 | tilt = clamp(tilt, -m, m);
105 |
106 | var e3 = s + tilt / 2;
107 | var e2 = e3 - tilt;
108 |
109 | return (Tuple.Create(e0, e1, e2, e3));
110 | }
111 |
112 | private static int abs(int a) {
113 | return (a < 0 ? -a : a);
114 | }
115 |
116 | private static int min(int a, int b) {
117 | return (a < b ? a : b);
118 | }
119 |
120 | private static int clamp(int v, int min, int max) {
121 | return (v < min ? min : v > max ? max : v);
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/lib2xSCL.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.Runtime.CompilerServices;
23 |
24 | namespace Imager.Filters {
25 | internal static class lib2xSCL {
26 | ///
27 | /// FNES' 2xSCL
28 | ///
29 | /// The worker.
30 | public static void Do2XScl(PixelWorker worker) {
31 | var n = worker.SourceP0M1();
32 | var w = worker.SourceM1P0();
33 | var c = worker.SourceP0P0();
34 | var e = worker.SourceP1P0();
35 | var s = worker.SourceP0P1();
36 |
37 | var p0 = (((w.IsLike(n)) && (n.IsNotLike(e)) && (w.IsNotLike(s))) ? w : c);
38 | var p1 = (((n.IsLike(e)) && (n.IsNotLike(w)) && (e.IsNotLike(s))) ? e : c);
39 | var p2 = (((w.IsLike(s)) && (w.IsNotLike(n)) && (s.IsNotLike(e))) ? w : c);
40 | var p3 = (((s.IsLike(e)) && (w.IsNotLike(s)) && (n.IsNotLike(e))) ? e : c);
41 |
42 | worker.TargetP0P0(p0);
43 | worker.TargetP1P0(p1);
44 | worker.TargetP0P1(p2);
45 | worker.TargetP1P1(p3);
46 | }
47 |
48 | public static void DoSuper2XScl(PixelWorker worker) {
49 | var n = worker.SourceP0M1();
50 | var w = worker.SourceM1P0();
51 | var c = worker.SourceP0P0();
52 | var e = worker.SourceP1P0();
53 | var s = worker.SourceP0P1();
54 |
55 | var wx = w;
56 | var ex = e;
57 | var cw = _Mixpal(c, w);
58 | var ce = _Mixpal(c, e);
59 |
60 | var p0 = (((w.IsLike(n)) && (n.IsNotLike(e)) && (w.IsNotLike(s))) ? wx : cw);
61 | var p1 = (((n.IsLike(e)) && (n.IsNotLike(w)) && (e.IsNotLike(s))) ? ex : ce);
62 | var p2 = (((w.IsLike(s)) && (w.IsNotLike(n)) && (s.IsNotLike(e))) ? wx : cw);
63 | var p3 = (((s.IsLike(e)) && (w.IsNotLike(s)) && (n.IsNotLike(e))) ? ex : ce);
64 |
65 | worker.TargetP0P0(p0);
66 | worker.TargetP1P0(p1);
67 | worker.TargetP0P1(p2);
68 | worker.TargetP1P1(p3);
69 | }
70 |
71 | public static void DoUltra2XScl(PixelWorker worker) {
72 | var n = worker.SourceP0M1();
73 | var w = worker.SourceM1P0();
74 | var c = worker.SourceP0P0();
75 | var e = worker.SourceP1P0();
76 | var s = worker.SourceP0P1();
77 |
78 | var cx = c;
79 | var wx = w;
80 | var ex = e;
81 | var cw = _Mixpal(c, w);
82 | var ce = _Mixpal(c, e);
83 |
84 | var p0 = (((w.IsLike(n)) && (n.IsNotLike(e)) && (w.IsNotLike(s))) ? wx : cw);
85 | var p1 = (((n.IsLike(e)) && (n.IsNotLike(w)) && (e.IsNotLike(s))) ? ex : ce);
86 | var p2 = (((w.IsLike(s)) && (w.IsNotLike(n)) && (s.IsNotLike(e))) ? wx : cw);
87 | var p3 = (((s.IsLike(e)) && (w.IsNotLike(s)) && (n.IsNotLike(e))) ? ex : ce);
88 |
89 | p0 = _Unmix(p0, cx);
90 | p1 = _Unmix(p1, cx);
91 | p2 = _Unmix(p2, cx);
92 | p3 = _Unmix(p3, cx);
93 |
94 | worker.TargetP0P0(p0);
95 | worker.TargetP1P0(p1);
96 | worker.TargetP0P1(p2);
97 | worker.TargetP1P1(p3);
98 | }
99 |
100 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
101 | private static sPixel _Mixpal(sPixel c1, sPixel c2) {
102 | return (sPixel.Interpolate(c1, c2, 3, 1));
103 | }
104 |
105 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
106 | private static sPixel _Unmix(sPixel c1, sPixel c2) {
107 |
108 | /* A variant of an unsharp mask, without the blur part. */
109 |
110 | var ra = c1.Red;
111 | var ga = c1.Green;
112 | var ba = c1.Blue;
113 |
114 | var rb = c2.Red;
115 | var gb = c2.Green;
116 | var bb = c2.Blue;
117 |
118 | var r = ((_Fix((ra + (ra - rb)), 0, 255) + rb) >> 1);
119 | var g = ((_Fix((ga + (ga - gb)), 0, 255) + gb) >> 1);
120 | var b = ((_Fix((ba + (ba - bb)), 0, 255) + bb) >> 1);
121 |
122 | return (sPixel.FromRGBA(r, g, b, (c1.Alpha + c2.Alpha) >> 1));
123 | }
124 |
125 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
126 | private static int _Fix(int n, int min, int max) {
127 | return (n < min ? min : n > max ? max : n);
128 | }
129 |
130 | } // end class
131 | } // end namespace
132 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libBasic.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libBasic {
24 | ///
25 | /// Horizontal scanlines
26 | ///
27 | public static void HorizontalScanlines(PixelWorker worker , float grayFactor) {
28 | var pixel = worker.SourceP0P0();
29 | worker.TargetP0P0( pixel);
30 | var factor = grayFactor / 100f + 1f;
31 | worker.TargetP0P1(pixel * factor);
32 | }
33 |
34 | ///
35 | /// Vertical scanlines
36 | ///
37 | public static void VerticalScanlines(PixelWorkerworker , float grayFactor) {
38 | var pixel = worker.SourceP0P0();
39 | worker.TargetP0P0(pixel);
40 | var factor = grayFactor / 100f + 1f;
41 | worker.TargetP1P0( pixel * factor);
42 | }
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libDES.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libDES {
24 | ///
25 | /// DES filters from FNES
26 | ///
27 | public static void DES(PixelWorker worker) {
28 | var n = worker.SourceP0M1();
29 | var w = worker.SourceM1P0();
30 | var c = worker.SourceP0P0();
31 | var e = worker.SourceP1P0();
32 | var s = worker.SourceP0P1();
33 |
34 |
35 | var p0 = (((w.IsLike(n)) && (n.IsNotLike(e)) && (w.IsNotLike(s))) ? w : c);
36 | var p1 = (((n.IsLike(e)) && (n.IsNotLike(w)) && (e.IsNotLike(s))) ? e : c);
37 | var p2 = (((w.IsLike(s)) && (w.IsNotLike(n)) && (s.IsNotLike(e))) ? w : c);
38 | var p3 = (((s.IsLike(e)) && (w.IsNotLike(s)) && (n.IsNotLike(e))) ? e : c);
39 |
40 | var d = sPixel.Interpolate(p0, p1, p2, p3);
41 |
42 | worker.TargetP0P0(d);
43 | }
44 |
45 | public static void DES2(PixelWorker worker) {
46 | var n = worker.SourceP0M1();
47 | var w = worker.SourceM1P0();
48 | var c = worker.SourceP0P0();
49 | var e = worker.SourceP1P0();
50 | var s = worker.SourceP0P1();
51 | var se = worker.SourceP1P1();
52 |
53 | var p0 = (((w.IsLike(n)) && (n.IsNotLike(e)) && (w.IsNotLike(s))) ? w : c);
54 | var p1 = (((n.IsLike(e)) && (n.IsNotLike(w)) && (e.IsNotLike(s))) ? e : c);
55 | var p2 = (((w.IsLike(s)) && (w.IsNotLike(n)) && (s.IsNotLike(e))) ? w : c);
56 | var p3 = (((s.IsLike(e)) && (w.IsNotLike(s)) && (n.IsNotLike(e))) ? e : c);
57 |
58 | var cx = c;
59 | var ce = sPixel.Interpolate(c, e, 3, 1);
60 | var cs = sPixel.Interpolate(c, s, 3, 1);
61 | var cse = sPixel.Interpolate(c, se, 3, 1);
62 |
63 |
64 | var d1 = sPixel.Interpolate(p0, cx, 3, 1);
65 | var d2 = sPixel.Interpolate(p1, ce, 3, 1);
66 | var d3 = sPixel.Interpolate(p2, cs, 3, 1);
67 | var d4 = sPixel.Interpolate(p3, cse, 3, 1);
68 |
69 | worker.TargetP0P0(d1);
70 | worker.TargetP1P0(d2);
71 | worker.TargetP0P1(d3);
72 | worker.TargetP1P1(d4);
73 | }
74 | } // end class
75 | } // end namespace
76 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libEagle.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libEagle {
24 | ///
25 | /// good old Eagle Engine modified by Hawkynt to support thresholds
26 | ///
27 | public static void Eagle2x(PixelWorkerworker ) {
28 | var c0 = worker.SourceM1M1();
29 | var c1 = worker.SourceP0M1();
30 | var c2 = worker.SourceP1M1();
31 | var c3 = worker.SourceM1P0();
32 | var c4 = worker.SourceP0P0();
33 | var c5 = worker.SourceP1P0();
34 | var c6 = worker.SourceM1P1();
35 | var c7 = worker.SourceP0P1();
36 | var c8 = worker.SourceP1P1();
37 | sPixel e01, e10, e11;
38 | var e00 = e01 = e10 = e11 = c4;
39 | if ((c1.IsLike(c0)) && (c1.IsLike(c3)))
40 | e00 = sPixel.Interpolate(c1, c0, c3);
41 |
42 | if ((c2.IsLike(c1)) && (c2.IsLike(c5)))
43 | e01 = sPixel.Interpolate(c2, c1, c5);
44 |
45 | if ((c6.IsLike(c3)) && (c6.IsLike(c7)))
46 | e10 = sPixel.Interpolate(c6, c3, c7);
47 |
48 | if ((c7.IsLike(c5)) && (c7.IsLike(c8)))
49 | e11 = sPixel.Interpolate(c7, c5, c8);
50 |
51 | worker.TargetP0P0(e00);
52 | worker.TargetP1P0(e01);
53 | worker.TargetP0P1(e10);
54 | worker.TargetP1P1(e11);
55 | }
56 |
57 | ///
58 | /// AFAIK there is no eagle 3x so I made one (Hawkynt)
59 | ///
60 | public static void Eagle3x(PixelWorker worker) {
61 | var c0 = worker.SourceM1M1();
62 | var c1 = worker.SourceP0M1();
63 | var c2 = worker.SourceP1M1();
64 | var c3 = worker.SourceM1P0();
65 | var c4 = worker.SourceP0P0();
66 | var c5 = worker.SourceP1P0();
67 | var c6 = worker.SourceM1P1();
68 | var c7 = worker.SourceP0P1();
69 | var c8 = worker.SourceP1P1();
70 | sPixel e01, e02, e10, e12, e20, e21, e22;
71 | var e00 = e01 = e02 = e10 = e12 = e20 = e21 = e22 = c4;
72 |
73 | if ((c0.IsLike(c1)) && (c0.IsLike(c3)))
74 | e00 = sPixel.Interpolate(c0, c1, c3);
75 |
76 | if ((c2.IsLike(c1)) && (c2.IsLike(c5)))
77 | e02 = sPixel.Interpolate(c2, c1, c5);
78 |
79 | if ((c6.IsLike(c3)) && (c6.IsLike(c7)))
80 | e20 = sPixel.Interpolate(c6, c3, c7);
81 |
82 | if ((c8.IsLike(c5)) && (c8.IsLike(c7)))
83 | e22 = sPixel.Interpolate(c8, c5, c7);
84 |
85 | if ((c0.IsLike(c1)) && (c0.IsLike(c3)) && (c2.IsLike(c1)) && (c2.IsLike(c5)))
86 | e01 = sPixel.Interpolate(sPixel.Interpolate(c0, c1, c3), sPixel.Interpolate(c2, c1, c5));
87 |
88 | if ((c2.IsLike(c1)) && (c2.IsLike(c5)) && (c8.IsLike(c5)) && (c8.IsLike(c7)))
89 | e12 = sPixel.Interpolate(sPixel.Interpolate(c2, c1, c5), sPixel.Interpolate(c8, c5, c7));
90 |
91 | if ((c6.IsLike(c7)) && (c6.IsLike(c3)) && (c8.IsLike(c5)) && (c8.IsLike(c7)))
92 | e21 = sPixel.Interpolate(sPixel.Interpolate(c6, c7, c3), sPixel.Interpolate(c8, c5, c7));
93 |
94 | if ((c0.IsLike(c1)) && (c0.IsLike(c3)) && (c6.IsLike(c7)) && (c6.IsLike(c3)))
95 | e10 = sPixel.Interpolate(sPixel.Interpolate(c0, c1, c3), sPixel.Interpolate(c6, c3, c7));
96 |
97 | worker.TargetP0P0(e00);
98 | worker.TargetP1P0(e01);
99 | worker.TargetP2P0(e02);
100 | worker.TargetP0P1(e10);
101 | worker.TargetP1P1(c4);
102 | worker.TargetP2P1(e12);
103 | worker.TargetP0P2(e20);
104 | worker.TargetP1P2(e21);
105 | worker.TargetP2P2(e22);
106 | }
107 |
108 | ///
109 | /// another one that takes into account that normal eagle means that 3 surroundings should be equal
110 | /// looks ugly sometimes depends heavily on source image
111 | ///
112 | public static void Eagle3xB(PixelWorker worker) {
113 | var c0 = worker.SourceM1M1();
114 | var c1 = worker.SourceP0M1();
115 | var c2 = worker.SourceP1M1();
116 | var c3 = worker.SourceM1P0();
117 | var c4 = worker.SourceP0P0();
118 | var c5 = worker.SourceP1P0();
119 | var c6 = worker.SourceM1P1();
120 | var c7 = worker.SourceP0P1();
121 | var c8 = worker.SourceP1P1();
122 | sPixel e01, e02, e10, e12, e20, e21, e22;
123 | var e00 = e01 = e02 = e10 = e12 = e20 = e21 = e22 = c4;
124 |
125 | if ((c0.IsLike(c1)) && (c0.IsLike(c3)))
126 | e00 = sPixel.Interpolate(c0, c1, c3);
127 |
128 | if ((c2.IsLike(c1)) && (c2.IsLike(c5)))
129 | e02 = sPixel.Interpolate(c2, c1, c5);
130 |
131 | if ((c6.IsLike(c3)) && (c6.IsLike(c7)))
132 | e20 = sPixel.Interpolate(c6, c3, c7);
133 |
134 | if ((c8.IsLike(c5)) && (c8.IsLike(c7)))
135 | e22 = sPixel.Interpolate(c8, c5, c7);
136 |
137 | worker.TargetP0P0(e00);
138 | worker.TargetP1P0(e01);
139 | worker.TargetP2P0(e02);
140 | worker.TargetP0P1(e10);
141 | worker.TargetP1P1(c4);
142 | worker.TargetP2P1(e12);
143 | worker.TargetP0P2(e20);
144 | worker.TargetP1P2(e21);
145 | worker.TargetP2P2(e22);
146 | }
147 | } // end class
148 | } // end namespace
149 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libHawkynt.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libHawkynt {
24 | ///
25 | /// just a bad old-school TV effect
26 | ///
27 | public static void Tv2x(PixelWorker worker) {
28 | var pixel = worker.SourceP0P0();
29 | var luminance = pixel.Luminance;
30 | worker.TargetP0P0(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
31 | worker.TargetP1P0(new sPixel(0, pixel.Green, 0, pixel.Alpha));
32 | worker.TargetP0P1(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
33 | worker.TargetP1P1(sPixel.FromGrey(luminance, pixel.Alpha));
34 | }
35 |
36 | ///
37 | /// another bad one a made for MS-Dos in 1998
38 | ///
39 | public static void Tv3x(PixelWorker worker) {
40 | var pixel = worker.SourceP0P0();
41 | worker.TargetP0P0(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
42 | worker.TargetP1P0(new sPixel(0, pixel.Green, 0, pixel.Alpha));
43 | worker.TargetP2P0(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
44 | if ((worker.SourceX() & 1) == 0) {
45 | worker.TargetP0P1(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
46 | if (worker.SourceY() > 0)
47 | worker.TargetP1M1(new sPixel(0, pixel.Green, 0, pixel.Alpha));
48 | worker.TargetP2P1(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
49 | } else {
50 | if (worker.SourceY() > 0)
51 | worker.TargetP0M1(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
52 | worker.TargetP1P1(new sPixel(0, pixel.Green, 0, pixel.Alpha));
53 | if (worker.SourceY() > 0)
54 | worker.TargetP2M1(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
55 | }
56 |
57 | }
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libMAME.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libMAME {
24 | private const float _gamma58 = 5f / 8f;
25 | private const float _gamma516 = 5f / 16f;
26 |
27 | ///
28 | /// MAME's TV effect in 2x
29 | ///
30 | public static void Tv2x(PixelWorker worker) {
31 | var pixel = worker.SourceP0P0();
32 | var subPixel = pixel * _gamma58;
33 | worker.TargetP0P0(pixel);
34 | worker.TargetP1P0(pixel);
35 | worker.TargetP0P1(subPixel);
36 | worker.TargetP1P1(subPixel);
37 | }
38 |
39 | ///
40 | /// MAME's TV effect 3x
41 | ///
42 | public static void Tv3x(PixelWorker worker) {
43 | var pixel = worker.SourceP0P0();
44 | var subPixel = pixel * _gamma58;
45 | var subPixel2 = pixel * _gamma516;
46 | worker.TargetP0P0(pixel);
47 | worker.TargetP1P0(pixel);
48 | worker.TargetP2P0(pixel);
49 | worker.TargetP0P1(subPixel);
50 | worker.TargetP1P1(subPixel);
51 | worker.TargetP2P1(subPixel);
52 | worker.TargetP0P2(subPixel2);
53 | worker.TargetP1P2(subPixel2);
54 | worker.TargetP2P2(subPixel2);
55 | }
56 |
57 | ///
58 | /// MAME's RGB 2x
59 | ///
60 | public static void Rgb2x(PixelWorker worker) {
61 | var pixel = worker.SourceP0P0();
62 | worker.TargetP0P0(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
63 | worker.TargetP1P0(new sPixel(0, pixel.Green, 0, pixel.Alpha));
64 | worker.TargetP0P1(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
65 | worker.TargetP1P1(pixel);
66 | }
67 |
68 | ///
69 | /// MAME's RGB 3x
70 | ///
71 | public static void Rgb3x(PixelWorker worker) {
72 | var pixel = worker.SourceP0P0();
73 | worker.TargetP0P0(pixel);
74 | worker.TargetP1P0(new sPixel(0, pixel.Green, 0, pixel.Alpha));
75 | worker.TargetP2P0(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
76 | worker.TargetP0P1(new sPixel(0, 0, pixel.Blue, pixel.Alpha));
77 | worker.TargetP1P1(pixel);
78 | worker.TargetP2P1(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
79 | worker.TargetP0P2(new sPixel(pixel.Red, 0, 0, pixel.Alpha));
80 | worker.TargetP1P2(new sPixel(0, pixel.Green, 0, pixel.Alpha));
81 | worker.TargetP2P2(pixel);
82 | }
83 |
84 | ///
85 | /// MAME's AdvInterp2x, very similar to Scale2x but uses interpolation, modified by Hawkynt to support thresholds
86 | ///
87 | public static void AdvInterp2x(PixelWorker worker) {
88 | var c1 = worker.SourceP0M1();
89 | var c3 = worker.SourceM1P0();
90 | var c4 = worker.SourceP0P0();
91 | var c5 = worker.SourceP1P0();
92 | var c7 = worker.SourceP0P1();
93 | sPixel e01, e10, e11;
94 | var e00 = e01 = e10 = e11 = c4;
95 | if (c1.IsNotLike(c7) && c3.IsNotLike(c5)) {
96 | if (c3.IsLike(c1))
97 | e00 = sPixel.Interpolate(sPixel.Interpolate(c1, c3), c4, 5, 3);
98 | if (c5.IsLike(c1))
99 | e01 = sPixel.Interpolate(sPixel.Interpolate(c1, c5), c4, 5, 3);
100 | if (c3.IsLike(c7))
101 | e10 = sPixel.Interpolate(sPixel.Interpolate(c7, c3), c4, 5, 3);
102 | if (c5.IsLike(c7))
103 | e11 = sPixel.Interpolate(sPixel.Interpolate(c7, c5), c4, 5, 3);
104 | }
105 | worker.TargetP0P0(e00);
106 | worker.TargetP1P0(e01);
107 | worker.TargetP0P1(e10);
108 | worker.TargetP1P1(e11);
109 | }
110 |
111 | ///
112 | /// MAME's AdvInterp3x, very similar to Scale3x but uses interpolation, modified by Hawkynt to support thresholds
113 | ///
114 | public static void AdvInterp3x(PixelWorker worker) {
115 | var c0 = worker.SourceM1M1();
116 | var c1 = worker.SourceP0M1();
117 | var c2 = worker.SourceP1M1();
118 | var c3 = worker.SourceM1P0();
119 | var c4 = worker.SourceP0P0();
120 | var c5 = worker.SourceP1P0();
121 | var c6 = worker.SourceM1P1();
122 | var c7 = worker.SourceP0P1();
123 | var c8 = worker.SourceP1P1();
124 | sPixel e01, e02, e10, e11, e12, e20, e21, e22;
125 | var e00 = e01 = e02 = e10 = e11 = e12 = e20 = e21 = e22 = c4;
126 | if (c1.IsNotLike(c7) && c3.IsNotLike(c5)) {
127 | if (c3.IsLike(c1)) {
128 | e00 = sPixel.Interpolate(sPixel.Interpolate(c3, c1), c4, 5, 3);
129 | }
130 | if (c1.IsLike(c5)) {
131 | e02 = sPixel.Interpolate(sPixel.Interpolate(c5, c1), c4, 5, 3);
132 | }
133 | if (c3.IsLike(c7)) {
134 | e20 = sPixel.Interpolate(sPixel.Interpolate(c3, c7), c4, 5, 3);
135 | }
136 | if (c7.IsLike(c5)) {
137 | e22 = sPixel.Interpolate(sPixel.Interpolate(c7, c5), c4, 5, 3);
138 | }
139 |
140 | if (
141 | (c3.IsLike(c1) && c4.IsNotLike(c2)) &&
142 | (c5.IsLike(c1) && c4.IsNotLike(c0))
143 | )
144 | e01 = sPixel.Interpolate(c1, c3, c5);
145 | else if (c3.IsLike(c1) && c4.IsNotLike(c2))
146 | e01 = sPixel.Interpolate(c3, c1);
147 | else if (c5.IsLike(c1) && c4.IsNotLike(c0))
148 | e01 = sPixel.Interpolate(c5, c1);
149 |
150 | if (
151 | (c3.IsLike(c1) && c4.IsNotLike(c6)) &&
152 | (c3.IsLike(c7) && c4.IsNotLike(c0))
153 | )
154 | e10 = sPixel.Interpolate(c3, c1, c7);
155 | else if (c3.IsLike(c1) && c4.IsNotLike(c6))
156 | e10 = sPixel.Interpolate(c3, c1);
157 | else if (c3.IsLike(c7) && c4.IsNotLike(c0))
158 | e10 = sPixel.Interpolate(c3, c7);
159 |
160 | if (
161 | (c5.IsLike(c1) && c4.IsNotLike(c8)) &&
162 | (c5.IsLike(c7) && c4.IsNotLike(c2))
163 | )
164 | e12 = sPixel.Interpolate(c5, c1, c7);
165 | else if (c5.IsLike(c1) && c4.IsNotLike(c8))
166 | e12 = sPixel.Interpolate(c5, c1);
167 | else if (c5.IsLike(c7) && c4.IsNotLike(c2))
168 | e12 = sPixel.Interpolate(c5, c7);
169 |
170 | if (
171 | (c3.IsLike(c7) && c4.IsNotLike(c8)) &&
172 | (c5.IsLike(c7) && c4.IsNotLike(c6))
173 | )
174 | e21 = sPixel.Interpolate(c7, c3, c5);
175 | else if (c3.IsLike(c7) && c4.IsNotLike(c8))
176 | e21 = sPixel.Interpolate(c3, c7);
177 | else if (c5.IsLike(c7) && c4.IsNotLike(c6))
178 | e21 = sPixel.Interpolate(c5, c7);
179 | }
180 | worker.TargetP0P0(e00);
181 | worker.TargetP1P0(e01);
182 | worker.TargetP2P0(e02);
183 | worker.TargetP0P1(e10);
184 | worker.TargetP1P1(e11);
185 | worker.TargetP2P1(e12);
186 | worker.TargetP0P2(e20);
187 | worker.TargetP1P2(e21);
188 | worker.TargetP2P2(e22);
189 | }
190 |
191 | ///
192 | /// Andrea Mazzoleni's Scale2X modified by Hawkynt to support thresholds
193 | ///
194 | public static void Scale2x(PixelWorker worker) {
195 | var c1 = worker.SourceP0M1();
196 | var c3 = worker.SourceM1P0();
197 | var c4 = worker.SourceP0P0();
198 | var c5 = worker.SourceP1P0();
199 | var c7 = worker.SourceP0P1();
200 | sPixel e01, e10, e11;
201 | var e00 = e01 = e10 = e11 = c4;
202 | if (c3.IsNotLike(c5) && c1.IsNotLike(c7)) {
203 | if (c1.IsLike(c3)) {
204 | e00 = sPixel.Interpolate(c1, c3);
205 | }
206 | if (c1.IsLike(c5)) {
207 | e01 = sPixel.Interpolate(c1, c5);
208 | }
209 | if (c7.IsLike(c3)) {
210 | e10 = sPixel.Interpolate(c7, c3);
211 | }
212 | if (c7.IsLike(c5)) {
213 | e11 = sPixel.Interpolate(c7, c5);
214 | }
215 | }
216 | worker.TargetP0P0(e00);
217 | worker.TargetP1P0(e01);
218 | worker.TargetP0P1(e10);
219 | worker.TargetP1P1(e11);
220 | }
221 |
222 | ///
223 | /// Andrea Mazzoleni's Scale3X modified by Hawkynt to support thresholds
224 | ///
225 | public static void Scale3x(PixelWorker worker) {
226 | var c0 = worker.SourceM1M1();
227 | var c1 = worker.SourceP0M1();
228 | var c2 = worker.SourceP1M1();
229 | var c3 = worker.SourceM1P0();
230 | var c4 = worker.SourceP0P0();
231 | var c5 = worker.SourceP1P0();
232 | var c6 = worker.SourceM1P1();
233 | var c7 = worker.SourceP0P1();
234 | var c8 = worker.SourceP1P1();
235 | sPixel e01, e02, e10, e11, e12, e20, e21, e22 = c4;
236 | var e00 = e01 = e02 = e10 = e11 = e12 = e20 = e21 = e22 = c4;
237 | if (c1.IsNotLike(c7) && c3.IsNotLike(c5)) {
238 | if (c3.IsLike(c1))
239 | e00 = sPixel.Interpolate(c3, c1);
240 | if (c1.IsLike(c5))
241 | e02 = sPixel.Interpolate(c1, c5);
242 | if (c3.IsLike(c7))
243 | e20 = sPixel.Interpolate(c3, c7);
244 | if (c7.IsLike(c5))
245 | e22 = sPixel.Interpolate(c7, c5);
246 |
247 | if (
248 | (c3.IsLike(c1) && c4.IsNotLike(c2)) &&
249 | (c5.IsLike(c1) && c4.IsNotLike(c0))
250 | )
251 | e01 = sPixel.Interpolate(c1, c3, c5);
252 | else if (c3.IsLike(c1) && c4.IsNotLike(c2))
253 | e01 = sPixel.Interpolate(c3, c1);
254 | else if (c5.IsLike(c1) && c4.IsNotLike(c0))
255 | e01 = sPixel.Interpolate(c5, c1);
256 |
257 | if (
258 | (c3.IsLike(c1) && c4.IsNotLike(c6)) &&
259 | (c3.IsLike(c7) && c4.IsNotLike(c0))
260 | )
261 | e10 = sPixel.Interpolate(c3, c1, c7);
262 | else if (c3.IsLike(c1) && c4.IsNotLike(c6))
263 | e10 = sPixel.Interpolate(c3, c1);
264 | else if (c3.IsLike(c7) && c4.IsNotLike(c0))
265 | e10 = sPixel.Interpolate(c3, c7);
266 |
267 | if (
268 | (c5.IsLike(c1) && c4.IsNotLike(c8)) &&
269 | (c5.IsLike(c7) && c4.IsNotLike(c2))
270 | )
271 | e12 = sPixel.Interpolate(c5, c1, c7);
272 | else if (c5.IsLike(c1) && c4.IsNotLike(c8))
273 | e12 = sPixel.Interpolate(c5, c1);
274 | else if (c5.IsLike(c7) && c4.IsNotLike(c2))
275 | e12 = sPixel.Interpolate(c5, c7);
276 |
277 | if (
278 | (c3.IsLike(c7) && c4.IsNotLike(c8)) &&
279 | (c5.IsLike(c7) && c4.IsNotLike(c6))
280 | )
281 | e21 = sPixel.Interpolate(c7, c3, c5);
282 | else if (c3.IsLike(c7) && c4.IsNotLike(c8))
283 | e21 = sPixel.Interpolate(c3, c7);
284 | else if (c5.IsLike(c7) && c4.IsNotLike(c6))
285 | e21 = sPixel.Interpolate(c5, c7);
286 |
287 | }
288 | worker.TargetP0P0(e00);
289 | worker.TargetP1P0(e01);
290 | worker.TargetP2P0(e02);
291 | worker.TargetP0P1(e10);
292 | worker.TargetP1P1(e11);
293 | worker.TargetP2P1(e12);
294 | worker.TargetP0P2(e20);
295 | worker.TargetP1P2(e21);
296 | worker.TargetP2P2(e22);
297 | }
298 |
299 |
300 | } // end class
301 | } // end namespace
302 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libSNES9x.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libSNES9x {
24 | ///
25 | /// SNES9x's EPXB modified by Hawkynt to support thresholds
26 | ///
27 | public static void EpxB(PixelWorker worker ) {
28 | var c0 = worker.SourceM1M1();
29 | var c1 = worker.SourceP0M1();
30 | var c2 = worker.SourceP1M1();
31 | var c3 = worker.SourceM1P0();
32 | var c4 = worker.SourceP0P0();
33 | var c5 = worker.SourceP1P0();
34 | var c6 = worker.SourceM1P1();
35 | var c7 = worker.SourceP0P1();
36 | var c8 = worker.SourceP1P1();
37 | sPixel e01, e10, e11;
38 | var e00 = e01 = e10 = e11 = c4;
39 | if (
40 | c3.IsNotLike(c5) &&
41 | c1.IsNotLike(c7) && ( // diagonal
42 | (
43 | c4.IsLike(c3) ||
44 | c4.IsLike(c7) ||
45 | c4.IsLike(c5) ||
46 | c4.IsLike(c1) || ( // edge smoothing
47 | (
48 | c0.IsNotLike(c8) ||
49 | c4.IsLike(c6) ||
50 | c4.IsLike(c2)
51 | ) && (
52 | c6.IsNotLike(c2) ||
53 | c4.IsLike(c0) ||
54 | c4.IsLike(c8)
55 | )
56 | )
57 | )
58 | )
59 | ) {
60 | if (
61 | c1.IsLike(c3) && (
62 | c4.IsNotLike(c0) ||
63 | c4.IsNotLike(c8) ||
64 | c1.IsNotLike(c2) ||
65 | c3.IsNotLike(c6)
66 | )
67 | ) {
68 | e00 = sPixel.Interpolate(c1, c3);
69 | }
70 | if (
71 | c5.IsLike(c1) && (
72 | c4.IsNotLike(c2) ||
73 | c4.IsNotLike(c6) ||
74 | c5.IsNotLike(c8) ||
75 | c1.IsNotLike(c0)
76 | )
77 | ) {
78 | e01 = sPixel.Interpolate(c5, c1);
79 | }
80 | if (
81 | c3.IsLike(c7) && (
82 | c4.IsNotLike(c6) ||
83 | c4.IsNotLike(c2) ||
84 | c3.IsNotLike(c0) ||
85 | c7.IsNotLike(c8)
86 | )
87 | ) {
88 | e10 = sPixel.Interpolate(c3, c7);
89 | }
90 | if (
91 | c7.IsLike(c5) && (
92 | c4.IsNotLike(c8) ||
93 | c4.IsNotLike(c0) ||
94 | c7.IsNotLike(c6) ||
95 | c5.IsNotLike(c2)
96 | )
97 | ) {
98 | e11 = sPixel.Interpolate(c7, c5);
99 | }
100 | }
101 |
102 | worker.TargetP0P0(e00);
103 | worker.TargetP1P0(e01);
104 | worker.TargetP0P1(e10);
105 | worker.TargetP1P1(e11);
106 | }
107 |
108 | ///
109 | /// SNES9x's EPX3 modified by Hawkynt to support thresholds
110 | ///
111 | public static void Epx3(PixelWorkerworker ) {
112 | var c0 = worker.SourceM1M1();
113 | var c1 = worker.SourceP0M1();
114 | var c2 = worker.SourceP1M1();
115 | var c3 = worker.SourceM1P0();
116 | var c4 = worker.SourceP0P0();
117 | var c5 = worker.SourceP1P0();
118 | var c6 = worker.SourceM1P1();
119 | var c7 = worker.SourceP0P1();
120 | var c8 = worker.SourceP1P1();
121 | sPixel e01, e02, e10, e11, e12, e20, e21, e22;
122 | var e00 = e01 = e02 = e10 = e11 = e12 = e20 = e21 = e22 = c4;
123 |
124 | if (c3.IsNotLike(c5) && c7.IsNotLike(c1)) {
125 | var neq40 = c4.IsNotLike(c0);
126 | var neq41 = c4.IsNotLike(c1);
127 | var neq42 = c4.IsNotLike(c2);
128 | var neq43 = c4.IsNotLike(c3);
129 | var neq45 = c4.IsNotLike(c5);
130 | var neq46 = c4.IsNotLike(c6);
131 | var neq47 = c4.IsNotLike(c7);
132 | var neq48 = c4.IsNotLike(c8);
133 |
134 | var eq13 = c1.IsLike(c3) && (neq40 || neq48 || c1.IsNotLike(c2) || c3.IsNotLike(c6));
135 | var eq37 = c3.IsLike(c7) && (neq46 || neq42 || c3.IsNotLike(c0) || c7.IsNotLike(c8));
136 | var eq75 = c7.IsLike(c5) && (neq48 || neq40 || c7.IsNotLike(c6) || c5.IsNotLike(c2));
137 | var eq51 = c5.IsLike(c1) && (neq42 || neq46 || c5.IsNotLike(c8) || c1.IsNotLike(c0));
138 | if (
139 | (!neq40) ||
140 | (!neq41) ||
141 | (!neq42) ||
142 | (!neq43) ||
143 | (!neq45) ||
144 | (!neq46) ||
145 | (!neq47) ||
146 | (!neq48)
147 | ) {
148 | if (eq13)
149 | e00 = sPixel.Interpolate(c1, c3);
150 | if (eq51)
151 | e02 = sPixel.Interpolate(c5, c1);
152 | if (eq37)
153 | e20 = sPixel.Interpolate(c3, c7);
154 | if (eq75)
155 | e22 = sPixel.Interpolate(c7, c5);
156 |
157 | if ((eq51 && neq40) && (eq13 && neq42))
158 | e01 = sPixel.Interpolate(c1, c3, c5);
159 | else if (eq51 && neq40)
160 | e01 = sPixel.Interpolate(c1, c5);
161 | else if (eq13 && neq42)
162 | e01 = sPixel.Interpolate(c1, c3);
163 |
164 | if ((eq13 && neq46) && (eq37 && neq40))
165 | e10 = sPixel.Interpolate(c3, c1, c7);
166 | else if (eq13 && neq46)
167 | e10 = sPixel.Interpolate(c3, c1);
168 | else if (eq37 && neq40)
169 | e10 = sPixel.Interpolate(c3, c7);
170 |
171 | if ((eq75 && neq42) && (eq51 && neq48))
172 | e12 = sPixel.Interpolate(c5, c1, c7);
173 | else if (eq75 && neq42)
174 | e12 = sPixel.Interpolate(c5, c7);
175 | else if (eq51 && neq48)
176 | e12 = sPixel.Interpolate(c5, c1);
177 |
178 | if ((eq37 && neq48) && (eq75 && neq46))
179 | e21 = sPixel.Interpolate(c7, c3, c5);
180 | else if (eq75 && neq46)
181 | e21 = sPixel.Interpolate(c7, c5);
182 | else if (eq37 && neq48)
183 | e21 = sPixel.Interpolate(c7, c3);
184 |
185 | } else {
186 | if (eq13)
187 | e00 = sPixel.Interpolate(c1, c3);
188 | if (eq51)
189 | e02 = sPixel.Interpolate(c5, c1);
190 | if (eq37)
191 | e20 = sPixel.Interpolate(c3, c7);
192 | if (eq75)
193 | e22 = sPixel.Interpolate(c7, c5);
194 | }
195 | }
196 |
197 | worker.TargetP0P0(e00);
198 | worker.TargetP1P0(e01);
199 | worker.TargetP2P0(e02);
200 | worker.TargetP0P1(e10);
201 | worker.TargetP1P1(e11);
202 | worker.TargetP2P1(e12);
203 | worker.TargetP0P2(e20);
204 | worker.TargetP1P2(e21);
205 | worker.TargetP2P2(e22);
206 | }
207 |
208 | ///
209 | /// SNES9x's EPXC modified by Hawkynt to support thresholds
210 | ///
211 | public static void EpxC(PixelWorker worker) {
212 | var c0 = worker.SourceM1M1();
213 | var c1 = worker.SourceP0M1();
214 | var c2 = worker.SourceP1M1();
215 | var c3 = worker.SourceM1P0();
216 | var c4 = worker.SourceP0P0();
217 | var c5 = worker.SourceP1P0();
218 | var c6 = worker.SourceM1P1();
219 | var c7 = worker.SourceP0P1();
220 | var c8 = worker.SourceP1P1();
221 | sPixel e01, e10, e11;
222 | var e00 = e01 = e10 = e11 = c4;
223 |
224 | if (c3.IsNotLike(c5) && c7.IsNotLike(c1)) {
225 | var neq40 = c4.IsNotLike(c0);
226 | var neq41 = c4.IsNotLike(c1);
227 | var neq42 = c4.IsNotLike(c2);
228 | var neq43 = c4.IsNotLike(c3);
229 | var neq45 = c4.IsNotLike(c5);
230 | var neq46 = c4.IsNotLike(c6);
231 | var neq47 = c4.IsNotLike(c7);
232 | var neq48 = c4.IsNotLike(c8);
233 |
234 | var eq13 = c1.IsLike(c3) && (neq40 || neq48 || c1.IsNotLike(c2) || c3.IsNotLike(c6));
235 | var eq37 = c3.IsLike(c7) && (neq46 || neq42 || c3.IsNotLike(c0) || c7.IsNotLike(c8));
236 | var eq75 = c7.IsLike(c5) && (neq48 || neq40 || c7.IsNotLike(c6) || c5.IsNotLike(c2));
237 | var eq51 = c5.IsLike(c1) && (neq42 || neq46 || c5.IsNotLike(c8) || c1.IsNotLike(c0));
238 | if (
239 | (!neq40) ||
240 | (!neq41) ||
241 | (!neq42) ||
242 | (!neq43) ||
243 | (!neq45) ||
244 | (!neq46) ||
245 | (!neq47) ||
246 | (!neq48)
247 | ) {
248 | sPixel c3A;
249 | if ((eq13 && neq46) && (eq37 && neq40))
250 | c3A = sPixel.Interpolate(c3, c1, c7);
251 | else if (eq13 && neq46)
252 | c3A = sPixel.Interpolate(c3, c1);
253 | else if (eq37 && neq40)
254 | c3A = sPixel.Interpolate(c3, c7);
255 | else
256 | c3A = c4;
257 |
258 | sPixel c7B;
259 | if ((eq37 && neq48) && (eq75 && neq46))
260 | c7B = sPixel.Interpolate(c7, c3, c5);
261 | else if (eq37 && neq48)
262 | c7B = sPixel.Interpolate(c7, c3);
263 | else if (eq75 && neq46)
264 | c7B = sPixel.Interpolate(c7, c5);
265 | else
266 | c7B = c4;
267 |
268 | sPixel c5C;
269 | if ((eq75 && neq42) && (eq51 && neq48))
270 | c5C = sPixel.Interpolate(c5, c1, c7);
271 | else if (eq75 && neq42)
272 | c5C = sPixel.Interpolate(c5, c7);
273 | else if (eq51 && neq48)
274 | c5C = sPixel.Interpolate(c5, c1);
275 | else
276 | c5C = c4;
277 |
278 | sPixel c1D;
279 |
280 | if ((eq51 && neq40) && (eq13 && neq42))
281 | c1D = sPixel.Interpolate(c1, c3, c5);
282 | else if (eq51 && neq40)
283 | c1D = sPixel.Interpolate(c1, c5);
284 | else if (eq13 && neq42)
285 | c1D = sPixel.Interpolate(c1, c3);
286 | else
287 | c1D = c4;
288 |
289 | if (eq13)
290 | e00 = sPixel.Interpolate(c1, c3);
291 | if (eq51)
292 | e01 = sPixel.Interpolate(c5, c1);
293 | if (eq37)
294 | e10 = sPixel.Interpolate(c3, c7);
295 | if (eq75)
296 | e11 = sPixel.Interpolate(c7, c5);
297 |
298 | e00 = sPixel.Interpolate(e00, c1D, c3A, c4, 5, 1, 1, 1);
299 | e01 = sPixel.Interpolate(e01, c7B, c5C, c4, 5, 1, 1, 1);
300 | e10 = sPixel.Interpolate(e10, c3A, c7B, c4, 5, 1, 1, 1);
301 | e11 = sPixel.Interpolate(e11, c5C, c1D, c4, 5, 1, 1, 1);
302 |
303 | } else {
304 |
305 | if (eq13)
306 | e00 = sPixel.Interpolate(c1, c3);
307 | if (eq51)
308 | e01 = sPixel.Interpolate(c5, c1);
309 | if (eq37)
310 | e10 = sPixel.Interpolate(c3, c7);
311 | if (eq75)
312 | e11 = sPixel.Interpolate(c7, c5);
313 |
314 | e00 = sPixel.Interpolate(c4, e00, 3, 1);
315 | e01 = sPixel.Interpolate(c4, e01, 3, 1);
316 | e10 = sPixel.Interpolate(c4, e10, 3, 1);
317 | e11 = sPixel.Interpolate(c4, e11, 3, 1);
318 |
319 | }
320 | }
321 |
322 | worker.TargetP0P0(e00);
323 | worker.TargetP1P0(e01);
324 | worker.TargetP0P1(e10);
325 | worker.TargetP1P1(e11);
326 | }
327 |
328 |
329 | } // end class
330 | } // end namespace
331 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Filters/libVBA.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | namespace Imager.Filters {
23 | internal static class libVBA {
24 | ///
25 | /// Bilinear Plus Original
26 | ///
27 | public static void BilinearPlusOriginal(PixelWorkerworker ) {
28 | var c00 = worker.SourceP0P0();
29 | var c01 = worker.SourceP1P0();
30 | var c10 = worker.SourceP0P1();
31 | var c11 = worker.SourceP1P1();
32 |
33 | var e00 = sPixel.Interpolate(c00, c01, c10, 5, 2, 1);
34 | var e01 = sPixel.Interpolate(c00, c01);
35 | var e10 = sPixel.Interpolate(c00, c10);
36 | var e11 = sPixel.Interpolate(c00, c01, c10, c11);
37 |
38 | worker.TargetP0P0(e00);
39 | worker.TargetP1P0(e01);
40 | worker.TargetP0P1(e10);
41 | worker.TargetP1P1(e11);
42 | }
43 |
44 | ///
45 | /// Bilinear Plus
46 | ///
47 | public static void BilinearPlus(PixelWorkerworker ) {
48 | var c00 = worker.SourceP0P0();
49 | var c01 = worker.SourceP1P0();
50 | var c10 = worker.SourceP0P1();
51 | var c11 = worker.SourceP1P1();
52 |
53 | const float gamma = 14f / 16f;
54 |
55 | var e00 = sPixel.Interpolate(c00, c01, c10, 10, 2, 2) * gamma;
56 | var e01 = sPixel.Interpolate(c00, c01);
57 | var e10 = sPixel.Interpolate(c00, c10);
58 | var e11 = sPixel.Interpolate(c00, c01, c10, c11);
59 |
60 | worker.TargetP0P0(e00);
61 | worker.TargetP1P0(e01);
62 | worker.TargetP0P1(e10);
63 | worker.TargetP1P1(e11);
64 | }
65 | } // end class
66 | } // end namespace
67 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Bitmaps.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System.Drawing;
22 | using System.Drawing.Imaging;
23 |
24 | namespace Imager {
25 | partial class cImage {
26 | ///
27 | /// Converts this image to a instance.
28 | ///
29 | /// The start x.
30 | /// The start y.
31 | /// The width.
32 | /// The height.
33 | ///
34 | /// The instance
35 | ///
36 | public Bitmap ToBitmap(int sx, int sy, int width, int height) {
37 | var result = new Bitmap(width, height);
38 | // NOTE: fucking bitmap does not allow parallel writes
39 | var bitmapData = result.LockBits(
40 | new Rectangle(0, 0, width, height),
41 | ImageLockMode.WriteOnly,
42 | PixelFormat.Format32bppArgb
43 | );
44 | var fillBytes = bitmapData.Stride - bitmapData.Width * 4;
45 | unsafe {
46 | var offset = (byte*)bitmapData.Scan0.ToPointer();
47 | for (var y = sy; y < sy + height; y++) {
48 | for (var x = sx; x < sx + width; x++) {
49 | var pixel = this[x, y];
50 | *(offset + 3) = pixel.Alpha;
51 | *(offset + 2) = pixel.Red;
52 | *(offset + 1) = pixel.Green;
53 | *(offset + 0) = pixel.Blue;
54 | offset += 4;
55 | }
56 | offset += fillBytes;
57 | }
58 | }
59 | result.UnlockBits(bitmapData);
60 | return (result);
61 | }
62 |
63 | ///
64 | /// Converts this image to a instance.
65 | ///
66 | /// The instance
67 | public Bitmap ToBitmap() {
68 | return (ToBitmap(0, 0, this._width, this._height));
69 | }
70 |
71 | // NOTE: Bitmap objects does not support parallel read-outs blame Microsoft
72 | ///
73 | /// Initializes a new instance of the class from a instance.
74 | ///
75 | /// The bitmap.
76 | public static cImage FromBitmap(Bitmap bitmap) {
77 | if (bitmap == null)
78 | return (null);
79 | var result = new cImage(bitmap.Width, bitmap.Height);
80 |
81 | var height = result._height;
82 | var width = result._width;
83 |
84 | var bitmapData = bitmap.LockBits(
85 | new Rectangle(0, 0, width, height),
86 | ImageLockMode.ReadOnly,
87 | PixelFormat.Format32bppArgb
88 | );
89 | var intFillX = bitmapData.Stride - bitmapData.Width * 4;
90 | unsafe {
91 | var ptrOffset = (byte*)bitmapData.Scan0.ToPointer();
92 | for (var y = 0; y < height; y++) {
93 | for (var x = 0; x < width; x++) {
94 | result[x, y] = new sPixel(*(ptrOffset + 2), *(ptrOffset + 1), *(ptrOffset + 0), *(ptrOffset + 3));
95 | ptrOffset += 4;
96 | }
97 | ptrOffset += intFillX;
98 | }
99 | }
100 | bitmap.UnlockBits(bitmapData);
101 |
102 | return (result);
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Interpolation.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using System.Collections.Generic;
23 | using System.Drawing;
24 | using System.Drawing.Drawing2D;
25 |
26 | namespace Imager {
27 | public partial class cImage {
28 | ///
29 | /// Stores all available parameterless pixel scalers.
30 | ///
31 | internal static readonly InterpolationMode[] INTERPOLATORS = new[] {
32 | InterpolationMode.NearestNeighbor,
33 | InterpolationMode.Bilinear,
34 | InterpolationMode.Bicubic,
35 | InterpolationMode.HighQualityBilinear,
36 | InterpolationMode.HighQualityBicubic,
37 | };
38 |
39 | ///
40 | /// Applies the GDI+ pixel scaler.
41 | ///
42 | /// The type of scaler to use.
43 | /// The width.
44 | /// The height.
45 | /// The filter region, if any.
46 | ///
47 | /// The rescaled image.
48 | ///
49 | public cImage ApplyScaler(InterpolationMode type, int width, int height, Rectangle? filterRegion = null) {
50 | if (!((IList)INTERPOLATORS).Contains(type))
51 | throw new NotSupportedException(string.Format("Interpolation mode '{0}' not supported.", type));
52 |
53 | var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left);
54 | var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top);
55 |
56 | var endX = filterRegion == null ? this.Width : Math.Min(this.Width, filterRegion.Value.Right);
57 | var endY = filterRegion == null ? this.Height : Math.Min(this.Height, filterRegion.Value.Bottom);
58 |
59 | // run through scaler
60 | var bitmap = new Bitmap(width, height);
61 | using (var graphics = Graphics.FromImage(bitmap)) {
62 |
63 | //set the resize quality modes to high quality
64 | graphics.CompositingQuality = CompositingQuality.HighQuality;
65 | graphics.InterpolationMode = type;
66 | graphics.SmoothingMode = SmoothingMode.HighQuality;
67 |
68 | //draw the image into the target bitmap
69 | //graphics.DrawImage(source, 0, 0, result.Width, result.Height);
70 |
71 | // FIXME: this is a hack to prevent the microsoft bug from creating a white pixel on top and left border (see http://forums.asp.net/t/1031961.aspx/1)
72 | graphics.DrawImage(filterRegion == null ? this.ToBitmap() : this.ToBitmap(startX, startY, endX - startX, endY - startY), -1, -1, bitmap.Width + 1, bitmap.Height + 1);
73 | }
74 | var result = FromBitmap(bitmap);
75 | result.HorizontalOutOfBoundsMode = this.HorizontalOutOfBoundsMode;
76 | result.VerticalOutOfBoundsMode = this.VerticalOutOfBoundsMode;
77 | return (result);
78 |
79 | }
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Loop.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | // This file is only generated to unroll the main image working loop upon compile time
22 | using System;
23 | using System.Drawing;
24 | using System.Collections.Concurrent;
25 | using System.Threading.Tasks;
26 |
27 | namespace Imager {
28 | partial class cImage {
29 | private cImage _RunLoop(Rectangle? filterRegion, byte scaleX, byte scaleY, Action> scaler) {
30 | var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left);
31 | var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top);
32 |
33 | var endX = filterRegion == null ? this.Width : Math.Min(this.Width, filterRegion.Value.Right);
34 | var endY = filterRegion == null ? this.Height : Math.Min(this.Height, filterRegion.Value.Bottom);
35 |
36 | var width = endX - startX;
37 |
38 | var result = new cImage(width * scaleX, (endY - startY) * scaleY);
39 |
40 | Parallel.ForEach(
41 | Partitioner.Create(startY, endY),
42 | () => 0,
43 | (range, _, threadStorage) => {
44 | var threadSrcMinY = range.Item1;
45 | var threadSrcMaxY = range.Item2;
46 |
47 | var targetY = (threadSrcMinY - startY) * scaleY;
48 | for (var sourceY = threadSrcMinY; sourceY < threadSrcMaxY;++sourceY) {
49 | var worker=new PixelWorker(
50 | this.GetImageData(),
51 | startX,
52 | sourceY,
53 | this._width,
54 | this._height,
55 | this._horizontalOutOfBoundsHandler,
56 | this._verticalOutOfBoundsHandler,
57 | result.GetImageData(),
58 | 0,
59 | targetY,
60 | result._width
61 | );
62 | var xRange=width;
63 | while(xRange>=64){
64 | xRange-=64;
65 | scaler(worker);
66 | worker.IncrementX(scaleX);
67 | scaler(worker);
68 | worker.IncrementX(scaleX);
69 | scaler(worker);
70 | worker.IncrementX(scaleX);
71 | scaler(worker);
72 | worker.IncrementX(scaleX);
73 | scaler(worker);
74 | worker.IncrementX(scaleX);
75 | scaler(worker);
76 | worker.IncrementX(scaleX);
77 | scaler(worker);
78 | worker.IncrementX(scaleX);
79 | scaler(worker);
80 | worker.IncrementX(scaleX);
81 | scaler(worker);
82 | worker.IncrementX(scaleX);
83 | scaler(worker);
84 | worker.IncrementX(scaleX);
85 | scaler(worker);
86 | worker.IncrementX(scaleX);
87 | scaler(worker);
88 | worker.IncrementX(scaleX);
89 | scaler(worker);
90 | worker.IncrementX(scaleX);
91 | scaler(worker);
92 | worker.IncrementX(scaleX);
93 | scaler(worker);
94 | worker.IncrementX(scaleX);
95 | scaler(worker);
96 | worker.IncrementX(scaleX);
97 | scaler(worker);
98 | worker.IncrementX(scaleX);
99 | scaler(worker);
100 | worker.IncrementX(scaleX);
101 | scaler(worker);
102 | worker.IncrementX(scaleX);
103 | scaler(worker);
104 | worker.IncrementX(scaleX);
105 | scaler(worker);
106 | worker.IncrementX(scaleX);
107 | scaler(worker);
108 | worker.IncrementX(scaleX);
109 | scaler(worker);
110 | worker.IncrementX(scaleX);
111 | scaler(worker);
112 | worker.IncrementX(scaleX);
113 | scaler(worker);
114 | worker.IncrementX(scaleX);
115 | scaler(worker);
116 | worker.IncrementX(scaleX);
117 | scaler(worker);
118 | worker.IncrementX(scaleX);
119 | scaler(worker);
120 | worker.IncrementX(scaleX);
121 | scaler(worker);
122 | worker.IncrementX(scaleX);
123 | scaler(worker);
124 | worker.IncrementX(scaleX);
125 | scaler(worker);
126 | worker.IncrementX(scaleX);
127 | scaler(worker);
128 | worker.IncrementX(scaleX);
129 | scaler(worker);
130 | worker.IncrementX(scaleX);
131 | scaler(worker);
132 | worker.IncrementX(scaleX);
133 | scaler(worker);
134 | worker.IncrementX(scaleX);
135 | scaler(worker);
136 | worker.IncrementX(scaleX);
137 | scaler(worker);
138 | worker.IncrementX(scaleX);
139 | scaler(worker);
140 | worker.IncrementX(scaleX);
141 | scaler(worker);
142 | worker.IncrementX(scaleX);
143 | scaler(worker);
144 | worker.IncrementX(scaleX);
145 | scaler(worker);
146 | worker.IncrementX(scaleX);
147 | scaler(worker);
148 | worker.IncrementX(scaleX);
149 | scaler(worker);
150 | worker.IncrementX(scaleX);
151 | scaler(worker);
152 | worker.IncrementX(scaleX);
153 | scaler(worker);
154 | worker.IncrementX(scaleX);
155 | scaler(worker);
156 | worker.IncrementX(scaleX);
157 | scaler(worker);
158 | worker.IncrementX(scaleX);
159 | scaler(worker);
160 | worker.IncrementX(scaleX);
161 | scaler(worker);
162 | worker.IncrementX(scaleX);
163 | scaler(worker);
164 | worker.IncrementX(scaleX);
165 | scaler(worker);
166 | worker.IncrementX(scaleX);
167 | scaler(worker);
168 | worker.IncrementX(scaleX);
169 | scaler(worker);
170 | worker.IncrementX(scaleX);
171 | scaler(worker);
172 | worker.IncrementX(scaleX);
173 | scaler(worker);
174 | worker.IncrementX(scaleX);
175 | scaler(worker);
176 | worker.IncrementX(scaleX);
177 | scaler(worker);
178 | worker.IncrementX(scaleX);
179 | scaler(worker);
180 | worker.IncrementX(scaleX);
181 | scaler(worker);
182 | worker.IncrementX(scaleX);
183 | scaler(worker);
184 | worker.IncrementX(scaleX);
185 | scaler(worker);
186 | worker.IncrementX(scaleX);
187 | scaler(worker);
188 | worker.IncrementX(scaleX);
189 | scaler(worker);
190 | worker.IncrementX(scaleX);
191 | scaler(worker);
192 | worker.IncrementX(scaleX);
193 | }
194 | for (; xRange>0;--xRange) {
195 | scaler(worker);
196 | worker.IncrementX(scaleX);
197 | }
198 |
199 | targetY += scaleY;
200 | }
201 | return (threadStorage);
202 | },
203 | _ => { }
204 | );
205 |
206 | return(result);
207 | }
208 | }
209 | }
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Loop.tt:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | <#@ template debug="false" hostspecific="false" language="C#" #>
22 | <#@ assembly name="System.Core" #>
23 | <#@ output extension=".cs" #>
24 | <# const int UNROLL_AMOUNT=64; #>
25 | // This file is only generated to unroll the main image working loop upon compile time
26 | using System;
27 | using System.Drawing;
28 | using System.Collections.Concurrent;
29 | using System.Threading.Tasks;
30 |
31 | namespace Imager {
32 | partial class cImage {
33 | private cImage _RunLoop(Rectangle? filterRegion, byte scaleX, byte scaleY, Action> scaler) {
34 | var startX = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Left);
35 | var startY = filterRegion == null ? 0 : Math.Max(0, filterRegion.Value.Top);
36 |
37 | var endX = filterRegion == null ? this.Width : Math.Min(this.Width, filterRegion.Value.Right);
38 | var endY = filterRegion == null ? this.Height : Math.Min(this.Height, filterRegion.Value.Bottom);
39 |
40 | var width = endX - startX;
41 |
42 | var result = new cImage(width * scaleX, (endY - startY) * scaleY);
43 |
44 | Parallel.ForEach(
45 | Partitioner.Create(startY, endY),
46 | () => 0,
47 | (range, _, threadStorage) => {
48 | var threadSrcMinY = range.Item1;
49 | var threadSrcMaxY = range.Item2;
50 |
51 | var targetY = (threadSrcMinY - startY) * scaleY;
52 | for (var sourceY = threadSrcMinY; sourceY < threadSrcMaxY;++sourceY) {
53 | var worker=new PixelWorker(
54 | this.GetImageData(),
55 | startX,
56 | sourceY,
57 | this._width,
58 | this._height,
59 | this._horizontalOutOfBoundsHandler,
60 | this._verticalOutOfBoundsHandler,
61 | result.GetImageData(),
62 | 0,
63 | targetY,
64 | result._width
65 | );
66 | <# if (UNROLL_AMOUNT>1) {#>
67 | var xRange=width;
68 | while(xRange>=<#=UNROLL_AMOUNT#>){
69 | xRange-=<#=UNROLL_AMOUNT#>;
70 | <# for(var i=0;i
71 | scaler(worker);
72 | worker.IncrementX(scaleX);
73 | <# } #>
74 | }
75 | <# } #>
76 | for (; xRange>0;--xRange) {
77 | scaler(worker);
78 | worker.IncrementX(scaleX);
79 | }
80 |
81 | targetY += scaleY;
82 | }
83 | return (threadStorage);
84 | },
85 | _ => { }
86 | );
87 |
88 | return(result);
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Nx.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | // TODO: consider a second alpha handling mode like in https://code.google.com/p/hqx-sharp/
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Drawing;
26 | using Classes;
27 | using Imager.Filters;
28 | using Imager.Interface;
29 |
30 | namespace Imager {
31 | ///
32 | ///
33 | ///
34 | public partial class cImage {
35 | ///
36 | /// The NQ kernel.
37 | ///
38 | /// The pattern.
39 | /// The c0.
40 | /// The c1.
41 | /// The c2.
42 | /// The c3.
43 | /// The c4.
44 | /// The c5.
45 | /// The c6.
46 | /// The c7.
47 | /// The c8.
48 | ///
49 | internal delegate void NqKernel(byte pattern, sPixel c0, sPixel c1, sPixel c2, sPixel c3, sPixel c4, sPixel c5, sPixel c6, sPixel c7, sPixel c8,PixelWorker worker);
50 |
51 | ///
52 | /// The NQ filter itself
53 | ///
54 | internal delegate void NqFilter(PixelWorker worker , byte scx, byte scy, NqKernel kernel);
55 |
56 | ///
57 | /// Stores all available parameterless pixel scalers.
58 | ///
59 | internal static readonly Dictionary> NQ_SCALERS = new Dictionary> {
60 | {NqScalerType.Hq2,Tuple.Create(2,2,libHQ.Hq2xKernel)},
61 | {NqScalerType.Hq2X3,Tuple.Create(2,3,libHQ.Hq2x3Kernel)},
62 | {NqScalerType.Hq2X4,Tuple.Create(2,4,libHQ.Hq2x4Kernel)},
63 | {NqScalerType.Hq3,Tuple.Create(3,3,libHQ.Hq3xKernel)},
64 | {NqScalerType.Hq4,Tuple.Create(4,4,libHQ.Hq4xKernel)},
65 |
66 | {NqScalerType.Lq2,Tuple.Create(2,2,libHQ.Lq2xKernel)},
67 | {NqScalerType.Lq2X3,Tuple.Create(2,3,libHQ.Lq2x3Kernel)},
68 | {NqScalerType.Lq2X4,Tuple.Create(2,4,libHQ.Lq2x4Kernel)},
69 | {NqScalerType.Lq3,Tuple.Create(3,3,libHQ.Lq3xKernel)},
70 | {NqScalerType.Lq4,Tuple.Create(4,4,libHQ.Lq4xKernel)},
71 | };
72 |
73 | ///
74 | /// The different NQ modes.
75 | ///
76 | internal static readonly Dictionary NQ_MODES = new Dictionary {
77 | {NqMode.Normal,libHQ.ComplexFilter},
78 | {NqMode.Bold,libHQ.ComplexFilterBold},
79 | {NqMode.Smart,libHQ.ComplexFilterSmart},
80 | };
81 |
82 | ///
83 | /// Applies the NQ pixel scaler.
84 | ///
85 | /// The type of scaler to use.
86 | /// The mode.
87 | /// The filter region, if any.
88 | ///
89 | /// The rescaled image.
90 | ///
91 | public cImage ApplyScaler(NqScalerType type, NqMode mode, Rectangle? filterRegion = null) {
92 | var info = GetPixelScalerInfo(type);
93 | var scaler = GetPixelScalerInfo(mode);
94 |
95 | var scaleX = info.Item1;
96 | var scaleY = info.Item2;
97 | var kernel = info.Item3;
98 |
99 | return (this._RunLoop(filterRegion, scaleX, scaleY, worker => scaler(worker, scaleX, scaleY, kernel)));
100 | }
101 |
102 | ///
103 | /// Gets the pixel scaler info.
104 | ///
105 | /// The type.
106 | ///
107 | internal static Tuple GetPixelScalerInfo(NqScalerType type) {
108 | Tuple info;
109 | if (NQ_SCALERS.TryGetValue(type, out info))
110 | return (info);
111 | throw new NotSupportedException(string.Format("NQ scaler '{0}' not supported.", type));
112 | }
113 |
114 | ///
115 | /// Gets the pixel scaler info.
116 | ///
117 | /// The type.
118 | ///
119 | internal static NqFilter GetPixelScalerInfo(NqMode type) {
120 | NqFilter info;
121 | if (NQ_MODES.TryGetValue(type, out info))
122 | return (info);
123 | throw new NotSupportedException(string.Format("NQ mode '{0}' not supported.", type));
124 | }
125 |
126 | ///
127 | /// Gets the scaler information.
128 | ///
129 | /// The type of nq scaler.
130 | ///
131 | ///
132 | public static ScalerInformation GetScalerInformation(NqScalerType type) {
133 | Tuple info;
134 | if (NQ_SCALERS.TryGetValue(type, out info))
135 | return (new ScalerInformation(ReflectionUtils.GetDisplayNameForEnumValue(type), ReflectionUtils.GetDescriptionForEnumValue(type), info.Item1, info.Item2));
136 | throw new NotSupportedException(string.Format("NQ scaler '{0}' not supported.", type));
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Parameterless.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using Classes;
22 | using Imager.Filters;
23 | using Imager.Interface;
24 | using System;
25 | using System.Collections.Generic;
26 | using System.Drawing;
27 |
28 | namespace Imager {
29 | ///
30 | ///
31 | ///
32 | public partial class cImage {
33 | ///
34 | /// The kernel of a parameterless pixel scaler.
35 | ///
36 | internal delegate void ParameterlessPixelScaler(PixelWorker worker);
37 |
38 | ///
39 | /// Stores all available parameterless pixel scalers.
40 | ///
41 | internal static readonly Dictionary> PIXEL_SCALERS = new Dictionary> {
42 | {PixelScalerType.HorizontalHalfDarkScanlines,Tuple.Create(1,2,w=>libBasic.HorizontalScanlines(w,-50f))},
43 | {PixelScalerType.HorizontalHalfLightScanlines,Tuple.Create(1,2,w=>libBasic.HorizontalScanlines(w,+50f))},
44 | {PixelScalerType.HorizontalFullLightScanlines,Tuple.Create(1,2,w=>libBasic.HorizontalScanlines(w,+100f))},
45 | {PixelScalerType.VerticalHalfDarkScanlines,Tuple.Create(2,1,w=>libBasic.VerticalScanlines(w,-50f))},
46 | {PixelScalerType.VerticalHalfLightScanlines,Tuple.Create(2,1,w=>libBasic.VerticalScanlines(w,+50f))},
47 | {PixelScalerType.VerticalFullLightScanlines,Tuple.Create(2,1,w=>libBasic.VerticalScanlines(w,+100f))},
48 |
49 | {PixelScalerType.MameTv,Tuple.Create(2,2,libMAME.Tv2x)},
50 | {PixelScalerType.MameTv3,Tuple.Create(3,3,libMAME.Tv3x)},
51 | {PixelScalerType.MameRgb,Tuple.Create(2,2,libMAME.Rgb2x)},
52 | {PixelScalerType.MameRgb3,Tuple.Create(3,3,libMAME.Rgb3x)},
53 | {PixelScalerType.HawkyntTv,Tuple.Create(2,2,libHawkynt.Tv2x)},
54 | {PixelScalerType.HawkyntTv3,Tuple.Create(3,2,libHawkynt.Tv3x)},
55 |
56 | {PixelScalerType.BilinearPlusOriginal,Tuple.Create(2,2,libVBA.BilinearPlusOriginal)},
57 | {PixelScalerType.BilinearPlus,Tuple.Create(2,2,libVBA.BilinearPlus)},
58 |
59 | {PixelScalerType.Eagle,Tuple.Create(2,2,libEagle.Eagle2x)},
60 | {PixelScalerType.Eagle3,Tuple.Create(3,3,libEagle.Eagle3x)},
61 | {PixelScalerType.Eagle3B,Tuple.Create(3,3,libEagle.Eagle3xB)},
62 | {PixelScalerType.SuperEagle,Tuple.Create(2,2,libKreed.SuperEagle)},
63 |
64 | {PixelScalerType.SaI,Tuple.Create(2,2,libKreed.SaI2X)},
65 | {PixelScalerType.SuperSaI,Tuple.Create(2,2,libKreed.SuperSaI)},
66 |
67 | {PixelScalerType.AdvInterp2,Tuple.Create(2,2,libMAME.AdvInterp2x)},
68 | {PixelScalerType.AdvInterp3,Tuple.Create(3,3,libMAME.AdvInterp3x)},
69 | {PixelScalerType.Scale2,Tuple.Create(2,2,libMAME.Scale2x)},
70 | {PixelScalerType.Scale3,Tuple.Create(3,3,libMAME.Scale3x)},
71 |
72 | {PixelScalerType.EpxB,Tuple.Create(2,2,libSNES9x.EpxB)},
73 | {PixelScalerType.EpxC,Tuple.Create(2,2,libSNES9x.EpxC)},
74 | {PixelScalerType.Epx3,Tuple.Create(3,3,libSNES9x.Epx3)},
75 |
76 | {PixelScalerType.ReverseAntiAlias,Tuple.Create(2,2,ReverseAntiAlias.Process)},
77 |
78 | {PixelScalerType.DES,Tuple.Create(1,1,libDES.DES)},
79 | {PixelScalerType.DES2,Tuple.Create(2,2,libDES.DES2)},
80 | {PixelScalerType.Normal2xScl,Tuple.Create(2,2,lib2xSCL.Do2XScl)},
81 | {PixelScalerType.Super2xScl,Tuple.Create(2,2,lib2xSCL.DoSuper2XScl)},
82 | {PixelScalerType.Ultra2xScl,Tuple.Create(2,2,lib2xSCL.DoUltra2XScl)},
83 | };
84 |
85 | ///
86 | /// Applies the pixel scaler without any parameters.
87 | ///
88 | /// The type of scaler to use.
89 | /// The filter region, if any.
90 | ///
91 | /// The rescaled image.
92 | ///
93 | public cImage ApplyScaler(PixelScalerType type, Rectangle? filterRegion = null) {
94 | var info = GetPixelScalerInfo(type);
95 | var scaleX = info.Item1;
96 | var scaleY = info.Item2;
97 | var scaler = info.Item3;
98 |
99 | return (this._RunLoop(filterRegion, scaleX, scaleY, w => scaler(w)));
100 | }
101 |
102 | ///
103 | /// Gets the parameterless pixel scaler info.
104 | ///
105 | /// The type.
106 | ///
107 | internal static Tuple GetPixelScalerInfo(PixelScalerType type) {
108 | Tuple info;
109 | if (PIXEL_SCALERS.TryGetValue(type, out info))
110 | return (info);
111 | throw new NotSupportedException(string.Format("Parameterless scaler '{0}' not supported.", type));
112 | }
113 |
114 | ///
115 | /// Gets the scaler information.
116 | ///
117 | /// The type of pixel scaler.
118 | ///
119 | ///
120 | public static ScalerInformation GetScalerInformation(PixelScalerType type) {
121 | Tuple info;
122 | if (PIXEL_SCALERS.TryGetValue(type, out info))
123 | return (new ScalerInformation(ReflectionUtils.GetDisplayNameForEnumValue(type), ReflectionUtils.GetDescriptionForEnumValue(type), info.Item1, info.Item2));
124 | throw new NotSupportedException(string.Format("Parameterless scaler '{0}' not supported.", type));
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Resample.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System.Drawing;
22 | using Imager.Classes;
23 |
24 | namespace Imager {
25 | public partial class cImage {
26 |
27 | ///
28 | /// Applies the pixel scaler for float32 images.
29 | ///
30 | /// The type of scaler to use.
31 | /// The width.
32 | /// The height.
33 | /// if set to true [centered grid].
34 | /// The filter region, if any.
35 | ///
36 | /// The rescaled image.
37 | ///
38 | public cImage ApplyScaler(KernelType type, int width, int height, bool centeredGrid, Rectangle? filterRegion = null) {
39 | var fpImage = FloatImage.FromImage(this, filterRegion);
40 | var fpResult = fpImage.Resize(width, height, type, centeredGrid);
41 | var result = fpResult.ToImage();
42 | return (result);
43 | }
44 |
45 | ///
46 | /// Applies the pixel scaler for float32 images.
47 | ///
48 | /// The type of scaler to use.
49 | /// The width.
50 | /// The height.
51 | /// The radius.
52 | /// if set to true [centered grid].
53 | /// The filter region, if any.
54 | ///
55 | /// The rescaled image.
56 | ///
57 | public cImage ApplyScaler(WindowType type, int width, int height, float radius, bool centeredGrid, Rectangle? filterRegion = null) {
58 | var fpImage = FloatImage.FromImage(this, filterRegion);
59 | var fpResult = fpImage.Resize(width, height, type, radius, centeredGrid);
60 | var result = fpResult.ToImage();
61 | return (result);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Xbr.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using System.Collections.Generic;
23 | using System.Drawing;
24 | using Classes;
25 | using Imager.Filters;
26 | using Imager.Interface;
27 |
28 | namespace Imager {
29 | public partial class cImage {
30 | ///
31 | /// The XBR filter itself
32 | ///
33 | /// The worker.
34 | /// if set to true [allow alpha blending].
35 | internal delegate void XbrFilter(PixelWorker worker , bool allowAlphaBlending);
36 |
37 | ///
38 | /// Stores all available parameterless pixel scalers.
39 | ///
40 | internal static readonly Dictionary> XBR_SCALERS = new Dictionary> {
41 | {XbrScalerType.Xbr2, Tuple.Create(2, 2, libXBR.Xbr2X)},
42 | {XbrScalerType.Xbr3, Tuple.Create(3, 3, (worker, a) => libXBR.Xbr3X(worker, a, true))},
43 | {XbrScalerType.Xbr3Modified, Tuple.Create(3, 3, (worker, a) => libXBR.Xbr3X(worker, a, false))},
44 | {XbrScalerType.Xbr4, Tuple.Create(4, 4, libXBR.Xbr4X)},
45 | };
46 |
47 | ///
48 | /// Applies the XBR pixel scaler.
49 | ///
50 | /// The type of scaler to use.
51 | /// if set to true [allow alpha blending].
52 | /// The filter region, if any.
53 | ///
54 | /// The rescaled image.
55 | ///
56 | public cImage ApplyScaler(XbrScalerType type, bool allowAlphaBlending, Rectangle? filterRegion = null) {
57 | var info = GetPixelScalerInfo(type);
58 | var scaleX = info.Item1;
59 | var scaleY = info.Item2;
60 | var scaler = info.Item3;
61 |
62 | return (this._RunLoop(filterRegion, scaleX, scaleY, worker => scaler(worker, allowAlphaBlending)));
63 | }
64 |
65 | ///
66 | /// Gets the pixel scaler info.
67 | ///
68 | /// The type.
69 | ///
70 | internal static Tuple GetPixelScalerInfo(XbrScalerType type) {
71 | Tuple info;
72 | if (XBR_SCALERS.TryGetValue(type, out info))
73 | return (info);
74 | throw new NotSupportedException(string.Format("XBR scaler '{0}' not supported.", type));
75 | }
76 |
77 | ///
78 | /// Gets the scaler information.
79 | ///
80 | /// The type of XBR scaler.
81 | ///
82 | ///
83 | public static ScalerInformation GetScalerInformation(XbrScalerType type) {
84 | Tuple info;
85 | if (XBR_SCALERS.TryGetValue(type, out info))
86 | return (new ScalerInformation(ReflectionUtils.GetDisplayNameForEnumValue(type), ReflectionUtils.GetDescriptionForEnumValue(type), info.Item1, info.Item2));
87 | throw new NotSupportedException(string.Format("XBR scaler '{0}' not supported.", type));
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Image.Resizer.Xbrz.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using Classes;
22 | using Imager.Filters;
23 | using Imager.Interface;
24 | using System;
25 | using System.Collections.Generic;
26 | using System.Drawing;
27 |
28 | namespace Imager {
29 | public partial class cImage {
30 | ///
31 | /// The XBRz filter
32 | ///
33 | /// The source.
34 | /// The target.
35 | /// The width.
36 | /// The height.
37 | /// The minimum y.
38 | /// The maximum y.
39 | internal delegate void XbrzFilter(sPixel[] src, sPixel[] tgt, int width, int height, int minX, int minY, int maxX, int maxY);
40 |
41 | ///
42 | /// Stores all available parameterless pixel scalers.
43 | ///
44 | internal static readonly Dictionary> XBRz_SCALERS = new Dictionary> {
45 | {XbrzScalerType.Xbrz2, Tuple.Create(2, 2, (src,tgt,w,h,minx,miny,maxx,maxy)=>libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES2, src,tgt,w,h,minx,miny,maxx,maxy))},
46 | {XbrzScalerType.Xbrz3, Tuple.Create(3, 3, (src,tgt,w,h,minx,miny,maxx,maxy)=>libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES3, src,tgt,w,h,minx,miny,maxx,maxy))},
47 | {XbrzScalerType.Xbrz4, Tuple.Create(4, 4, (src,tgt,w,h,minx,miny,maxx,maxy)=>libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES4, src,tgt,w,h,minx,miny,maxx,maxy))},
48 | {XbrzScalerType.Xbrz5, Tuple.Create(5, 5, (src,tgt,w,h,minx,miny,maxx,maxy)=>libXBRz.ScaleImage(libXBRz.ScaleSize.TIMES5, src,tgt,w,h,minx,miny,maxx,maxy))},
49 | };
50 |
51 | ///
52 | /// Applies the XBR pixel scaler.
53 | ///
54 | /// The type of scaler to use.
55 | /// The filter region, if any.
56 | ///
57 | /// The rescaled image.
58 | ///
59 | public cImage ApplyScaler(XbrzScalerType type, Rectangle? filterRegion = null) {
60 | var info = GetPixelScalerInfo(type);
61 | var scaleX = info.Item1;
62 | var scaleY = info.Item2;
63 | var scaler = info.Item3;
64 |
65 | if (filterRegion == null)
66 | filterRegion = new Rectangle(0, 0, this.Width, this.Height);
67 |
68 | var result = new cImage(this.Width * scaleX, this.Height * scaleY);
69 | // TODO: generic pixel loop
70 | scaler(this.GetImageData(), result.GetImageData(), this.Width, this.Height, filterRegion.Value.Left, filterRegion.Value.Top, filterRegion.Value.Right, filterRegion.Value.Bottom);
71 | return (result);
72 | }
73 |
74 | ///
75 | /// Gets the pixel scaler info.
76 | ///
77 | /// The type.
78 | ///
79 | internal static Tuple GetPixelScalerInfo(XbrzScalerType type) {
80 | Tuple info;
81 | if (XBRz_SCALERS.TryGetValue(type, out info))
82 | return (info);
83 | throw new NotSupportedException(string.Format("XBRz scaler '{0}' not supported.", type));
84 | }
85 |
86 | ///
87 | /// Gets the scaler information.
88 | ///
89 | /// The type of XBR scaler.
90 | ///
91 | ///
92 | public static ScalerInformation GetScalerInformation(XbrzScalerType type) {
93 | Tuple info;
94 | if (XBRz_SCALERS.TryGetValue(type, out info))
95 | return (new ScalerInformation(ReflectionUtils.GetDisplayNameForEnumValue(type), ReflectionUtils.GetDescriptionForEnumValue(type), info.Item1, info.Item2));
96 | throw new NotSupportedException(string.Format("XBRz scaler '{0}' not supported.", type));
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/NqMode.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | namespace Imager.Interface {
22 | public enum NqMode {
23 | Normal,
24 | Bold,
25 | Smart
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/NqScalerType.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.ComponentModel;
23 |
24 | using Imager.Classes;
25 |
26 | namespace Imager.Interface {
27 | public enum NqScalerType {
28 |
29 | #region hq group
30 | [EnumDisplayName("HQ 2x")]
31 | [Description("Maxim Stepin's HQ 2x")]
32 | Hq2,
33 | [EnumDisplayName("HQ 2x3")]
34 | Hq2X3,
35 | [EnumDisplayName("HQ 2x4")]
36 | Hq2X4,
37 | [EnumDisplayName("HQ 3x")]
38 | [Description("Maxim Stepin's HQ 3x")]
39 | Hq3,
40 | [EnumDisplayName("HQ 4x")]
41 | [Description("Maxim Stepin's HQ 4x")]
42 | Hq4,
43 | #endregion
44 |
45 | #region lq group
46 | [EnumDisplayName("LQ 2x")]
47 | Lq2,
48 | [EnumDisplayName("LQ 2x3")]
49 | Lq2X3,
50 | [EnumDisplayName("LQ 2x4")]
51 | Lq2X4,
52 | [EnumDisplayName("LQ 3x")]
53 | Lq3,
54 | [EnumDisplayName("LQ 4x")]
55 | Lq4,
56 | #endregion
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/OutOfBoundsMode.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using System.Collections.Generic;
23 | using System.Diagnostics.Contracts;
24 | using System.Runtime;
25 | using System.Runtime.CompilerServices;
26 |
27 | namespace Imager.Interface {
28 | ///
29 | /// This tells us how to handle read requests to pixels which are out of image bounds.
30 | ///
31 | public enum OutOfBoundsMode {
32 | ///
33 | /// aaa abcde eee
34 | ///
35 | ConstantExtension = 0,
36 | ///
37 | /// cba abcde edc
38 | ///
39 | HalfSampleSymmetric,
40 | ///
41 | /// dcb abcde dcb
42 | ///
43 | WholeSampleSymmetric,
44 | ///
45 | /// cde abcde abc
46 | ///
47 | WrapAround
48 | }
49 |
50 | internal static class OutOfBoundsUtils {
51 |
52 | public delegate int OutOfBoundsHandler(int index, int count,bool isUnderflow);
53 |
54 | private static readonly Dictionary _OUT_OF_BOUNDS_HANDLERS = new Dictionary {
55 | {OutOfBoundsMode.ConstantExtension,_ConstantExtension},
56 | {OutOfBoundsMode.WrapAround,_WrapAround},
57 | {OutOfBoundsMode.HalfSampleSymmetric,_HalfSampleSymmetric},
58 | {OutOfBoundsMode.WholeSampleSymmetric,_WholeSampleSymmetric}
59 | };
60 |
61 | #region out of bounds handlers
62 | private static int _ConstantExtension(int index, int count,bool isUnderflow) {
63 | return (isUnderflow ? 0 : count - 1);
64 | }
65 |
66 | private static int _WrapAround(int index, int count,bool isUnderflow) {
67 | /*
68 | c:2
69 | -3 -2 -1 0 +1 +2 +3
70 | 1 0 1 0 1 0 1
71 |
72 | c:3
73 | -3 -2 -1 0 +1 +2 +3
74 | 0 1 2 0 1 2 0
75 | */
76 |
77 | if (!isUnderflow)
78 | return (index % count);
79 | /*
80 | // Loop-version
81 | if (overflow)
82 | while(true)
83 | if(index>=count)
84 | index-=count;
85 | else
86 | return(index);
87 | */
88 |
89 | return (count - ((-index) % count)) % count;
90 |
91 | /*
92 | // Loop-Version
93 | while (index < 0)
94 | index += count;
95 | return (index);
96 | */
97 | }
98 |
99 | private static int _HalfSampleSymmetric(int index, int count, bool isUnderflow) {
100 |
101 | // FIXME: calculate this without a loop
102 | while (true) {
103 | if (index < 0)
104 | index = -1 - index;
105 | else if (index >= count)
106 | index = (2 * count - 1) - index;
107 | else
108 | return (index);
109 | }
110 | }
111 |
112 | private static int _WholeSampleSymmetric(int index, int count, bool isUnderflow) {
113 |
114 | // FIXME: calculate this without a loop
115 | while (true) {
116 | if (index < 0)
117 | index = -index;
118 | else if (index >= count)
119 | index = (2 * count - 2) - index;
120 | else
121 | return (index);
122 | }
123 | }
124 | #endregion
125 |
126 | ///
127 | /// Gets the out of bounds handler or crashes.
128 | ///
129 | /// The mode.
130 | ///
131 | public static OutOfBoundsHandler GetHandlerOrCrash(OutOfBoundsMode mode) {
132 | OutOfBoundsHandler result;
133 | if (_OUT_OF_BOUNDS_HANDLERS.TryGetValue(mode, out result))
134 | return (result);
135 |
136 | throw new NotSupportedException("The OutOfBoundsMode " + mode + " is not supported");
137 | }
138 |
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/PixelScalerType.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using Imager.Classes;
23 | using System.ComponentModel;
24 |
25 | namespace Imager.Interface {
26 | public enum PixelScalerType {
27 |
28 | #region scanline effects
29 | [EnumDisplayName("-50% Scanlines")]
30 | [Description("A scanline which is 50% darker is inserted every second line.")]
31 | HorizontalHalfDarkScanlines,
32 | [EnumDisplayName("+50% Scanlines")]
33 | [Description("A scanline which is 50% lighter is inserted every second line.")]
34 | HorizontalHalfLightScanlines,
35 | [EnumDisplayName("+100% Scanlines")]
36 | [Description("A scanline which is 100% lighter is inserted every second line.")]
37 | HorizontalFullLightScanlines,
38 |
39 | [EnumDisplayName("-50% VScanlines")]
40 | [Description("A scanline which is 50% darker is inserted every second column.")]
41 | VerticalHalfDarkScanlines,
42 | [EnumDisplayName("+50% VScanlines")]
43 | [Description("A scanline which is 50% lighter is inserted every second column.")]
44 | VerticalHalfLightScanlines,
45 | [EnumDisplayName("+100% VScanlines")]
46 | [Description("A scanline which is 100% lighter is inserted every second column.")]
47 | VerticalFullLightScanlines,
48 | #endregion
49 |
50 | #region CRT effects
51 | [EnumDisplayName("MAME TV 2x")]
52 | [Description("MAME's interlace filter, tries to emulate a TV-CRT screen.")]
53 | MameTv,
54 | [EnumDisplayName("MAME TV 3x")]
55 | [Description("MAME's interlace filter, tries to emulate a TV-CRT screen.")]
56 | MameTv3,
57 | [EnumDisplayName("MAME RGB 2x")]
58 | [Description("MAME's RGB filter, tries to emulate a LCD-Screen.")]
59 | MameRgb,
60 | [EnumDisplayName("MAME RGB 3x")]
61 | [Description("MAME's RGB filter, tries to emulate a LCD-Screen.")]
62 | MameRgb3,
63 | [EnumDisplayName("Hawkynt TV 2x")]
64 | [Description("Hawkynt's TV effect, uses no more than 256 shades of red, green, blue and grey (=1024 colors) to display images.")]
65 | HawkyntTv,
66 | [EnumDisplayName("Hawkynt TV 3x")]
67 | [Description("Hawkynt's TV effect, uses no more than 256 shades of red, green and blue (=768 colors) to display images.")]
68 | HawkyntTv3,
69 | #endregion
70 |
71 | #region VBA special
72 | [EnumDisplayName("Bilinear Plus Original")]
73 | [Description("VBA's bilinear plus filter, in the original mode of operation.")]
74 | BilinearPlusOriginal,
75 | [EnumDisplayName("Bilinear Plus")]
76 | [Description("VBA's bilinear plus filter.")]
77 | BilinearPlus,
78 | #endregion
79 |
80 | #region eagle group
81 | [EnumDisplayName("Eagle 2x")]
82 | [Description("The original eagle filter.")]
83 | Eagle,
84 | [EnumDisplayName("Eagle 3x")]
85 | [Description("The eagle filter for using in 3-times enlargement by Hawkynt.")]
86 | Eagle3,
87 | [EnumDisplayName("Eagle 3xB")]
88 | [Description("The eagle filter for using in 3-times enlargement by Hawkynt (alternate version).")]
89 | Eagle3B,
90 | [EnumDisplayName("SuperEagle")]
91 | [Description("SNES9x's SuperEagle filter from Derek Liauw Kie Fa aka Kreed.")]
92 | SuperEagle,
93 | #endregion
94 |
95 | #region sai group
96 | [EnumDisplayName("SaI 2x")]
97 | [Description("SNES9x's 2xSaI filter from Derek Liauw Kie Fa aka Kreed.")]
98 | SaI,
99 | [EnumDisplayName("Super SaI")]
100 | [Description("SNES9x's Super2xSaI filter from Derek Liauw Kie Fa aka Kreed.")]
101 | SuperSaI,
102 | #endregion
103 |
104 | #region scale nx group
105 | [EnumDisplayName("AdvInterp 2x")]
106 | [Description("MAME's double-scaling from Andrea Mazzoleni which does use interpolation.")]
107 | AdvInterp2,
108 | [EnumDisplayName("AdvInterp 3x")]
109 | [Description("MAME's tripple-scaling from Andrea Mazzoleni which does use interpolation.")]
110 | AdvInterp3,
111 | [EnumDisplayName("Scale 2x")]
112 | [Description("MAME's double-scaling from Andrea Mazzoleni which does not use interpolation.")]
113 | Scale2,
114 | [EnumDisplayName("Scale 3x")]
115 | [Description("MAME's tripple-scaling from Andrea Mazzoleni which does not use interpolation.")]
116 | Scale3,
117 | #endregion
118 |
119 | #region epx group
120 | [EnumDisplayName("EPXB")]
121 | [Description("SNES9x-ReRecording's EPX-B scaler.")]
122 | EpxB,
123 | [EnumDisplayName("EPXC")]
124 | [Description("SNES9x-ReRecording's EPX-C scaler.")]
125 | EpxC,
126 | [EnumDisplayName("EPX3")]
127 | [Description("SNES9x-ReRecording's EPX-3 scaler.")]
128 | Epx3,
129 | #endregion
130 |
131 | #region reverse AA
132 | [EnumDisplayName("Reverse AA")]
133 | [Description("Hyllian's OpenGL reverse anti-alias filter.")]
134 | ReverseAntiAlias,
135 | #endregion
136 |
137 | #region FNES
138 | [EnumDisplayName("DES")]
139 | [Description("FNES' DES filter.")]
140 | DES,
141 | [EnumDisplayName("DES II")]
142 | [Description("FNES' DES2 filter.")]
143 | DES2,
144 | [EnumDisplayName("2xSCL")]
145 | [Description("FNES' 2xSCL filter.")]
146 | Normal2xScl,
147 | [EnumDisplayName("Super 2xSCL")]
148 | [Description("FNES' Super 2xSCL filter.")]
149 | Super2xScl,
150 | [EnumDisplayName("Ultra 2xSCL")]
151 | [Description("FNES' Ultra 2xSCL filter.")]
152 | Ultra2xScl,
153 | #endregion
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/ScalerInformation.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Imager.Interface {
3 | public class ScalerInformation {
4 | private readonly string _displayName;
5 | private readonly string _description;
6 | private readonly byte _scaleFactorX;
7 | private readonly byte _scaleFactorY;
8 | public ScalerInformation(string displayName, string description, byte scaleFactorX, byte scaleFactorY) {
9 | this._description = description;
10 | this._scaleFactorX = scaleFactorX;
11 | this._scaleFactorY = scaleFactorY;
12 | this._displayName = displayName;
13 | }
14 |
15 | public string Description {
16 | get { return this._description; }
17 | }
18 |
19 | public byte ScaleFactorX {
20 | get { return this._scaleFactorX; }
21 | }
22 |
23 | public byte ScaleFactorY {
24 | get { return this._scaleFactorY; }
25 | }
26 |
27 | public string DisplayName {
28 | get { return this._displayName; }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/XbrScalerType.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System.ComponentModel;
23 |
24 | using Imager.Classes;
25 |
26 | namespace Imager.Interface {
27 | public enum XbrScalerType {
28 | #region xbr group
29 | [EnumDisplayName("XBR 2x")]
30 | [Description("Hyllian's XBR 2x")]
31 | Xbr2,
32 | [EnumDisplayName("XBR 3x")]
33 | [Description("Hyllian's XBR 3x")]
34 | Xbr3,
35 | [EnumDisplayName("XBR 3x(modified)")]
36 | [Description("Hyllian's XBR 3x (non-original version)")]
37 | Xbr3Modified,
38 | [EnumDisplayName("XBR 4x")]
39 | [Description("Hyllian's XBR 4x")]
40 | Xbr4,
41 | #endregion
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/Interface/XbrzScalerType.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using Imager.Classes;
23 | using System.ComponentModel;
24 |
25 | namespace Imager.Interface {
26 | public enum XbrzScalerType {
27 | [EnumDisplayName("XBRz 2x")]
28 | [Description("Zenju's XBRz 2x")]
29 | Xbrz2,
30 | [EnumDisplayName("XBRz 3x")]
31 | [Description("Zenju's XBRz 3x")]
32 | Xbrz3,
33 | [EnumDisplayName("XBRz 4x")]
34 | [Description("Zenju's XBRz 4x")]
35 | Xbrz4,
36 | [EnumDisplayName("XBRz 5x")]
37 | [Description("Zenju's XBRz 5x")]
38 | Xbrz5,
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ImageResizer/Imager/PixelWorker.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="false" language="C#" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ import namespace="System.Linq" #>
4 | <#@ import namespace="System.Text" #>
5 | <#@ import namespace="System.Collections.Generic" #>
6 | <#@ output extension=".cs" #>
7 | <#
8 | var shiftMultipliers=Enumerable.Range(0,8).ToDictionary(i=>1<i);
9 | var sourceXRange=new[]{-2,-1,0,1,2};
10 | var sourceYRange=new[]{-2,-1,0,1,2};
11 | var targetXRange=new[]{0,1,2,3};
12 | var targetYRange=new[]{-1,0,1,2,3};
13 | Func GetLineDescription=v=>v<0?"M"+Math.Abs(v).ToString():"P"+v.ToString();
14 | Func GetPointDescription=(x,y)=>GetLineDescription(x)+GetLineDescription(y);
15 | #>
16 |
17 | using System;
18 | using System.Collections.Generic;
19 | using System.Diagnostics.Contracts;
20 | using Imager.Interface;
21 |
22 | namespace Imager {
23 | ///
24 | /// This class gets us fast access to a small window of pixels in the source and target images.
25 | ///
26 | internal class PixelWorker {
27 | private readonly IList _sourceImage;
28 | private int _sourceX;
29 | private readonly int _sourceY;
30 | private int _sourceOffset;
31 |
32 | private readonly int _sourceWidth;
33 | private readonly int _sourceHeight;
34 | private readonly OutOfBoundsUtils.OutOfBoundsHandler _sourceXWrapper;
35 | private readonly OutOfBoundsUtils.OutOfBoundsHandler _sourceYWrapper;
36 |
37 | private readonly IList _targetImage;
38 | private int _targetOffset;
39 |
40 | #region offset calculators for source image
41 | // these are lazy calculated offsets, so once used, the method pointer gets replaced by a function that returns the calculated constant
42 | <# foreach(var i in sourceXRange.Where(i=>i!=0)) { #>
43 | private Func _sourceOffset<#=GetLineDescription(i)#>X;
44 | private int _sourceOffset<#=GetLineDescription(i)#>XValue;
45 | <# } #>
46 | <# foreach(var i in sourceYRange.Where(i=>i!=0)) { #>
47 | private Func _sourceOffset<#=GetLineDescription(i)#>Y;
48 | private int _sourceOffset<#=GetLineDescription(i)#>YValue;
49 | <# } #>
50 | #endregion
51 |
52 | #region offsets for target image
53 | <# foreach(var i in targetXRange.Where(i=>i!=0)) { #>
54 | private const int _targetOffset<#=GetLineDescription(i)#>X = <#=i#>;
55 | <# } #>
56 | <# foreach(var i in targetYRange.Where(i=>i!=0)) { #>
57 | private readonly int _targetOffset<#=GetLineDescription(i)#>Y;
58 | <# } #>
59 | #endregion
60 |
61 | public PixelWorker(IList sourceImage, int sourceX, int sourceY, int sourceWidth, int sourceHeight, OutOfBoundsUtils.OutOfBoundsHandler sourceXWrapper, OutOfBoundsUtils.OutOfBoundsHandler sourceYWrapper, IList targetImage, int targetX, int targetY, int targetWidth) {
62 | Contract.Requires(sourceX >= 0 && sourceX < sourceWidth && sourceY >= 0 && sourceY < sourceHeight);
63 | this._sourceImage = sourceImage;
64 | this._sourceX = sourceX;
65 | this._sourceY = sourceY;
66 | this._sourceWidth = sourceWidth;
67 | this._sourceHeight = sourceHeight;
68 |
69 | // we can safely calculate this offset, because we assume that the central source pixel is never out of bounds
70 | this._sourceOffset = sourceWidth * sourceY + sourceX;
71 |
72 | // we only check pixels in a row or column once for over-/underflow, to avoid calling the wrappers over and over again
73 | this._sourceXWrapper = sourceXWrapper;
74 | this._sourceYWrapper = sourceYWrapper;
75 |
76 | // we calculate a delta offset for pixels around the center and store these independent X from Y
77 | <# foreach(var i in sourceXRange.Where(i=>i!=0)) { #>
78 | this._sourceOffset<#=GetLineDescription(i)#>X = this._CalculateOffset<#=GetLineDescription(i)#>X;
79 | <# } #>
80 | <# foreach(var i in sourceYRange.Where(i=>i!=0)) { #>
81 | this._sourceOffset<#=GetLineDescription(i)#>Y = this._CalculateOffset<#=GetLineDescription(i)#>Y;
82 | <# } #>
83 |
84 | this._targetImage = targetImage;
85 | this._targetOffset = targetWidth * targetY + targetX;
86 |
87 | // pre-calculating the row offset for target image, because they surely get used
88 | <# foreach(var i in targetYRange.Where(i=>i!=0)) { #>
89 | this._targetOffset<#=GetLineDescription(i)#>Y = targetWidth<#=i==1?" ":(shiftMultipliers.ContainsKey(i)?" << "+shiftMultipliers[i].ToString():" * "+i.ToString())#>; // for nx<#=(i+1)#> filters
90 | <# } #>
91 | }
92 |
93 | public int SourceX(){
94 | return(this._sourceX);
95 | }
96 |
97 | public int SourceY(){
98 | return(this._sourceY);
99 | }
100 |
101 | public int SourceHeight(){
102 | return(this._sourceHeight);
103 | }
104 |
105 | public void IncrementX(int targetXIncrementor){
106 | this._targetOffset+=targetXIncrementor;
107 | this._sourceOffset++;
108 | this._sourceX++;
109 | <# foreach(var i in sourceXRange.Where(i=>i!=0)) { #>
110 | <# if(i==-1){ #>
111 | this._sourceOffset<#=GetLineDescription(i)#>X = this._GetOffset<#=GetLineDescription(i)#>X;
112 | this._sourceOffset<#=GetLineDescription(i)#>XValue = -1;
113 | <# } else { #>
114 | this._sourceOffset<#=GetLineDescription(i)#>X = this._CalculateOffset<#=GetLineDescription(i)#>X;
115 | <# } #>
116 | <# } #>
117 | }
118 |
119 | #region access source points
120 | <# foreach(var y in sourceYRange) { #>
121 | <# foreach(var x in sourceXRange) { #>
122 | public TColorStorage Source<#=GetPointDescription(x,y)#>() {
123 | return (this._sourceImage[this._sourceOffset<#=x==0?string.Empty:" + this._sourceOffset"+GetLineDescription(x)+"X()"#><#=y==0?string.Empty:" + this._sourceOffset"+GetLineDescription(y)+"Y()"#>]);
124 | }
125 | <# } #>
126 | <# } #>
127 | #endregion
128 |
129 | #region access target points
130 | <# foreach(var y in targetYRange) { #>
131 | <# foreach(var x in targetXRange) { #>
132 | public void Target<#=GetPointDescription(x,y)#>(TColorStorage value) {
133 | this._targetImage[this._targetOffset<#=x==0?string.Empty:" + _targetOffset"+GetLineDescription(x)+"X"#><#=y==0?string.Empty:" + this._targetOffset"+GetLineDescription(y)+"Y"#>] = value;
134 | }
135 | <# } #>
136 | <# } #>
137 | #endregion
138 |
139 | #region calculate source offset deltas
140 |
141 | <# foreach(var i in sourceXRange.Where(i=>i!=0)) { #>
142 | private int _GetOffset<#=GetLineDescription(i)#>X() { return (this._sourceOffset<#=GetLineDescription(i)#>XValue); }
143 | private int _CalculateOffset<#=GetLineDescription(i)#>X() {
144 | var current = this._sourceX;
145 | var value = current <#=i<0?"- "+Math.Abs(i).ToString():"+ "+i.ToString()#>;
146 | if (value <#=i<0?"< 0":">= this._sourceWidth"#>)
147 | value = this._sourceXWrapper(value, this._sourceWidth, <#=i<0?"true":"false"#>);
148 |
149 | var result = value - current;
150 | this._sourceOffset<#=GetLineDescription(i)#>XValue = result;
151 | this._sourceOffset<#=GetLineDescription(i)#>X = this._GetOffset<#=GetLineDescription(i)#>X;
152 | return (result);
153 | }
154 | <# } #>
155 | <# foreach(var i in sourceYRange.Where(i=>i!=0)) { #>
156 | private int _GetOffset<#=GetLineDescription(i)#>Y() { return (this._sourceOffset<#=GetLineDescription(i)#>YValue); }
157 | private int _CalculateOffset<#=GetLineDescription(i)#>Y() {
158 | var current = this._sourceY;
159 | var value = current <#=i<0?"- "+Math.Abs(i).ToString():"+ "+i.ToString()#>;
160 | if (value <#=i<0?"< 0":">= this._sourceHeight"#>)
161 | value = this._sourceYWrapper(value, this._sourceHeight, <#=i<0?"true":"false"#>);
162 |
163 | var result = (value - current) * this._sourceWidth;
164 | this._sourceOffset<#=GetLineDescription(i)#>YValue = result;
165 | this._sourceOffset<#=GetLineDescription(i)#>Y = this._GetOffset<#=GetLineDescription(i)#>Y;
166 | return (result);
167 | }
168 | <# } #>
169 | #endregion
170 |
171 | }
172 | }
--------------------------------------------------------------------------------
/ImageResizer/Imager/cRGBCache.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 |
22 | using System;
23 | using dword = System.UInt32;
24 | namespace Imager {
25 | ///
26 | /// A little cache that holds calculation results based on the three color components red, green and blue.
27 | ///
28 | public class cRGBCache {
29 | private readonly ushort[] _valueCache = new ushort[256 * 256 * 256];
30 |
31 | ///
32 | /// Gets a value directly from the cache or first calculates that value and writes it the cache.
33 | ///
34 | /// The 32-bit color code.
35 | /// The factory that would calculate a result if it's not already in the cache.
36 | /// The calculation result.
37 | public unsafe byte GetOrAdd(dword key, Func factory) {
38 | fixed (ushort* ptr = this._valueCache) {
39 | var result = ptr[key];
40 | if (result > 255)
41 | return (byte) (result & 255);
42 |
43 | result = factory(key);
44 | ptr[key] = (ushort) (result | 256);
45 | System.Threading.Thread.MemoryBarrier();
46 | return ((byte) result);
47 | }
48 | }
49 | } // end class
50 | } // end namespace
--------------------------------------------------------------------------------
/ImageResizer/Program.cs:
--------------------------------------------------------------------------------
1 | #region (c)2008-2015 Hawkynt
2 | /*
3 | * cImage
4 | * Image filtering library
5 | Copyright (C) 2008-2015 Hawkynt
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | #endregion
21 | using System;
22 | using Classes;
23 |
24 | namespace ImageResizer {
25 | class Program {
26 | ///
27 | /// The main entry point for the application.
28 | ///
29 | [STAThread]
30 | static void Main(string[] args) {
31 | Environment.Exit((int) CLI.ParseCommandLineArguments(args));
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ImageResizer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Windows;
4 |
5 | // Allgemeine Informationen über eine Assembly werden über die folgenden
6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
7 | // die mit einer Assembly verknüpft sind.
8 | [assembly: AssemblyTitle("ImageResizer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("»SynthelicZ«")]
12 | [assembly: AssemblyProduct("ImageResizer")]
13 | [assembly: AssemblyCopyright("Copyright © 2008-2015 Hawkynt")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
20 | [assembly: ComVisible(false)]
21 |
22 | //Um mit dem Erstellen lokalisierbarer Anwendungen zu beginnen, legen Sie
23 | //ImCodeVerwendeteKultur in der .csproj-Datei
24 | //in einer fest. Wenn Sie in den Quelldateien beispielsweise Deutsch
25 | //(Deutschland) verwenden, legen Sie auf \"de-DE\" fest. Heben Sie dann die Auskommentierung
26 | //des nachstehenden NeutralResourceLanguage-Attributs auf. Aktualisieren Sie "en-US" in der nachstehenden Zeile,
27 | //sodass es mit der UICulture-Einstellung in der Projektdatei übereinstimmt.
28 |
29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
30 |
31 |
32 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
33 | //
34 | // Hauptversion
35 | // Nebenversion
36 | // Buildnummer
37 | // Revision
38 | //
39 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
40 | // übernehmen, indem Sie "*" eingeben:
41 | // [assembly: AssemblyVersion("1.0.*")]
42 | [assembly: AssemblyVersion("1.1.3.3")]
43 | [assembly: AssemblyFileVersion("1.1.3.3")]
44 |
--------------------------------------------------------------------------------
/ImageResizer/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | Failed to load
123 |
124 |
125 | JPEG Encoder missing
126 |
127 |
128 | No image
129 |
130 |
131 | No image
132 |
133 |
134 | Unknown filter
135 |
136 |
137 | Could not load {0}\r\n\r\n{1}
138 |
139 |
140 | System has no support to save as JPEG !
141 |
142 |
143 | Unable to resize file: there is nothing to resize!
144 |
145 |
146 | There is nothing to save.
147 |
148 |
149 | Unable to resize file: there is no filter named '{0}'
150 |
151 |
152 | Value too small
153 |
154 |
155 | Need a width and height > 0 to apply interpolation.
156 |
157 |
158 | ..\Resources\CLIHelpText.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
159 |
160 |
161 | No script
162 |
163 |
164 | There is no script to save.
165 |
166 |
167 | https://code.google.com/p/2dimagefilter/
168 |
169 |
170 | https://code.google.com/p/2dimagefilter/w/list
171 |
172 |
173 |
--------------------------------------------------------------------------------
/ImageResizer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Dieser Code wurde von einem Tool generiert.
4 | // Laufzeitversion:4.0.30319.34014
5 | //
6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
7 | // der Code erneut generiert wird.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageResizer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ImageResizer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ImageResizer/Resources/CLIHelpText.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | ** {appname} v{version}, {copyright}
3 | Version for Windows NT/9x/2000/XP/Vista/7 (All rights reserved)
4 | ------------------------------------------------------------------------
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | ========================================================================
18 |
19 | ============
20 | How to use :
21 | ============
22 |
23 | {location} [{load} ] [{stdin}] [{resize} [(|)]] [{save} ] [{script}