- Timestamp:
- Oct 28, 2015, 7:51:20 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r244 r251 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO;4 3 using System.Net; 5 4 using System.Threading; … … 13 12 private string staticPart; 14 13 private bool logMissingFiles; 15 16 14 private Dictionary<string, byte[]> icons = new Dictionary<string, byte[]> (); 15 private bool loaded = false; 17 16 18 17 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base(moduleName) { … … 30 29 } 31 30 32 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length); 33 fn = fn.Remove (fn.LastIndexOf ('.')); 31 // BEGIN CHANGED BY PSOUZA4 32 string requestFileName = req.Url.AbsolutePath.Remove (0, staticPart.Length); 33 requestFileName = requestFileName.Remove (requestFileName.LastIndexOf ('.')); 34 34 35 if (icons.ContainsKey (fn)) { 35 string requestColorTintHex = string.Empty; 36 37 // Chose a split instead of using a querystring variable in the URI, but that may arguably be cleaner 38 if (requestFileName.Contains("@@")) { 39 try { 40 string[] tempTintingOptions = requestFileName.Split (new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); 41 requestFileName = tempTintingOptions [0]; 42 requestColorTintHex = tempTintingOptions [1].Trim ().ToUpper (); 43 } 44 catch { } 45 } 46 47 if (icons.ContainsKey (requestFileName) && req.Url.AbsolutePath.ToLower ().EndsWith(".png")) { 36 48 resp.ContentType = MimeType.GetMimeType (".png"); 37 resp.ContentLength64 = icons [fn].Length; 38 resp.OutputStream.Write (icons [fn], 0, icons [fn].Length); 49 50 byte[] itemIconData = icons [requestFileName]; 51 52 // Note: optionally split this code into a ImageMultiplyBlend method 53 if (!string.IsNullOrEmpty (requestColorTintHex) && (requestColorTintHex != "FFFFFF")) { 54 try { 55 System.Drawing.Color colorTint = System.Drawing.ColorTranslator.FromHtml ("#" + requestColorTintHex); 56 System.Drawing.Bitmap image = (System.Drawing.Bitmap)PetesUtils.GetImageFromBytes (itemIconData); 57 58 for (var x = 0; x < image.Width; x++) { 59 for (int y = 0; y < image.Height; y++) { 60 System.Drawing.Color originalColor = image.GetPixel (x, y); 61 System.Drawing.Color changedColor = originalColor; 62 63 // Only change the icon tinting if the alpha channel is fully opaque 64 if (originalColor.A == 255) { 65 // based on http://stackoverflow.com/questions/3837757/multiply-two-images-in-c-sharp-as-multiply-two-layers-in-photoshop 66 67 double component_R = (((double)originalColor.R) * ((double)colorTint.R)) / 255.0; 68 double component_G = (((double)originalColor.G) * ((double)colorTint.G)) / 255.0; 69 double component_B = (((double)originalColor.B) * ((double)colorTint.B)) / 255.0; 70 71 if (component_R > 255.0) component_R = 255.0; 72 if (component_G > 255.0) component_G = 255.0; 73 if (component_B > 255.0) component_B = 255.0; 74 75 // multiply blend shouldn't ever calculate below 0, but for completeness let's leave in this logic 76 if (component_R < 0.0) component_R = 0.0; 77 if (component_G < 0.0) component_G = 0.0; 78 if (component_B < 0.0) component_B = 0.0; 79 80 changedColor = System.Drawing.Color.FromArgb (originalColor.A, (int)component_R, (int)component_G, (int)component_B); 81 } 82 83 image.SetPixel (x, y, changedColor); 84 } 85 } 86 87 itemIconData = PetesUtils.SaveImage_ToBytes (image, true); 88 } 89 catch { } 90 } 91 92 resp.ContentLength64 = itemIconData.Length; 93 resp.OutputStream.Write (itemIconData, 0, itemIconData.Length); 94 // END CHANGED BY PSOUZA4 39 95 } else { 40 96 resp.StatusCode = (int)HttpStatusCode.NotFound;
Note:
See TracChangeset
for help on using the changeset viewer.