From 6755d5534280f1962991697ba8421da92fd66e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique=20Ivanchechen?= Date: Wed, 16 Aug 2023 15:40:27 -0300 Subject: [PATCH] first --- .gitignore | 3 + Controllers/Blur.cs | 59 ++++++++++++++++++ Program.cs | 18 ++++++ Properties/Resources.Designer.cs | 63 +++++++++++++++++++ Properties/Resources.resx | 101 +++++++++++++++++++++++++++++++ Properties/launchSettings.json | 31 ++++++++++ appsettings.Development.json | 8 +++ appsettings.json | 9 +++ tcc-app.csproj | 32 ++++++++++ tcc-app.sln | 25 ++++++++ 10 files changed, 349 insertions(+) create mode 100644 .gitignore create mode 100644 Controllers/Blur.cs create mode 100644 Program.cs create mode 100644 Properties/Resources.Designer.cs create mode 100644 Properties/Resources.resx create mode 100644 Properties/launchSettings.json create mode 100644 appsettings.Development.json create mode 100644 appsettings.json create mode 100644 tcc-app.csproj create mode 100644 tcc-app.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5003052 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vs +bin +obj \ No newline at end of file diff --git a/Controllers/Blur.cs b/Controllers/Blur.cs new file mode 100644 index 0000000..0bea165 --- /dev/null +++ b/Controllers/Blur.cs @@ -0,0 +1,59 @@ +using ImageMagick; +using Microsoft.AspNetCore.Mvc; + +namespace tcc_app.Controllers +{ + [ApiController] + [Route("")] + public class ImageController : ControllerBase + { + [HttpPost("blur")] + public async Task BlurImage() + { + MemoryStream mstream = new MemoryStream(); + await HttpContext.Request.Body.CopyToAsync(mstream); + + var image = new MagickImage(new MemoryStream(mstream.ToArray())); + var blurredImage = new MagickImage(image); + var pixels = image.GetPixels(); + var blurredPixels = blurredImage.GetPixelsUnsafe(); + + foreach (var pixel in pixels) + { + int x = pixel.X, + y = pixel.Y; + + long rTotal = 0, gTotal = 0, bTotal = 0; + int pixelCount = 0; + for (short offsetY = -5; offsetY <= 5; offsetY++) + { + for (short offsetX = -5; offsetX <= 5; offsetX++) + { + int newX = x + offsetX; + int newY = y + offsetY; + + if (newX >= 0 && newX < image.Width && newY >= 0 && newY < image.Height) + { + var pixelColor = pixels[newX, newY]; + rTotal += pixelColor.GetChannel(0); + gTotal += pixelColor.GetChannel(1); + bTotal += pixelColor.GetChannel(2); + pixelCount++; + } + } + } + + blurredPixels[x, y].SetChannel(0, Convert.ToUInt16(rTotal / pixelCount)); + blurredPixels[x, y].SetChannel(1, Convert.ToUInt16(gTotal / pixelCount)); + blurredPixels[x, y].SetChannel(2, Convert.ToUInt16(bTotal / pixelCount)); + } + + var blurredImageStream = new MemoryStream(); + blurredImage.Write(blurredImageStream); + blurredImageStream.Position = 0; + + return File(blurredImageStream, "image/png"); + } + + } +} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..f93b7c1 --- /dev/null +++ b/Program.cs @@ -0,0 +1,18 @@ +namespace tcc_app +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + builder.Services.AddControllers(); + + var app = builder.Build(); + + app.MapControllers(); + + app.Run(); + } + } +} \ No newline at end of file diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..31d9a2f --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace tcc_app.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("tcc_app.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..dbc3255 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:20012", + "sslPort": 0 + } + }, + "profiles": { + "tcc_app": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5100", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/tcc-app.csproj b/tcc-app.csproj new file mode 100644 index 0000000..18b136c --- /dev/null +++ b/tcc-app.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + tcc_app + AnyCPU + True + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + diff --git a/tcc-app.sln b/tcc-app.sln new file mode 100644 index 0000000..3a2915b --- /dev/null +++ b/tcc-app.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33927.249 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tcc-app", "tcc-app.csproj", "{FBD7660C-B50A-4776-AAEF-A1A0D0D253C3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FBD7660C-B50A-4776-AAEF-A1A0D0D253C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBD7660C-B50A-4776-AAEF-A1A0D0D253C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBD7660C-B50A-4776-AAEF-A1A0D0D253C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBD7660C-B50A-4776-AAEF-A1A0D0D253C3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B91FB0D3-3CDD-4AE8-A686-CBD748AD8096} + EndGlobalSection +EndGlobal