Illnab1024

Members
  • Content count

    1,178
  • Joined

  • Last visited

  • Days Won

    1

Illnab1024 last won the day on November 10 2011

Illnab1024 had the most liked content!

Community Reputation

10

About Illnab1024

  • Birthday 01/01/1970

Profile Information

  • Gender
    Not Telling
  • Location
    Middle Tennessee

Contact Methods

  • Website URL
    http://www.getpaint.net/users/Illnab1024/index.html
  1. .Exe FileType Plugin

    In the DLL there's an embedded resource with the .exe produced by building the C code. That executable has a static array from `const CHAR_INFO outChar[80][25] = { { {L'0', 0xf} } };` which is printed directly to the console using ConsoleWriteW. The Plugin writes that .exe to file but writes over the static array inside the executable to change the "image" that gets written to the console. It's just a "for-fun" plugin; there's absolutely no point to saving an image as an executable file, and even though you could do it as a full-color bitmap and use Windows GDI stuff to display it, that's also pointless when there's Windows Photo Viewer. If I really wanted to have fun, I'd do a 16-bit .COM FileType using int 21 stuff, but I'm on a 64-bit system, so meh.
  2. Just relaxing, decided to make this for fun. Hidden Content: C# source using System; using System.Collections.Generic; using System.Text; using PaintDotNet; using PaintDotNet.Data; using PaintDotNet.Rendering; using System.IO; using System.Drawing; using System.Windows.Forms; using System.Drawing.Imaging; using System.Linq; namespace DotExeFileType { public class MyFileType : FileType { public MyFileType() : base("Exe File", FileTypeFlags.SupportsSaving, new String[] { ".exe" }) { } protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { RenderArgs ra = new RenderArgs(new Surface(input.Size)); // input.Render(ra); input.Render(ra, false); var img = ra.Bitmap; Bitmap cells = new Bitmap(80 * 8, 25 * 12); Graphics ctx = Graphics.FromImage(cells); ctx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; ctx.DrawImage(img, 0, 0, 80 * 8, 25 * 12); ctx.Dispose(); byte[] outArr = new byte[80*25*4]; // Downsample to 4-bit colors for (int y = 0; y < 25*12; y++) { for (int x = 0; x < 80*8; x++) { Color c = cells.GetPixel(x, y); cells.SetPixel(x, y, bestMatch(ColorBgra.FromColor(cells.GetPixel(x, y)))); } } // Histogram the 8x12 characters and find // the closest match for (int y = 0; y < 25; y++) { for (int x = 0; x < 80; x++) { Dictionary<ColorBgra, int> histo = new Dictionary<ColorBgra, int>(); for (int j = 0; j < 12; j++) { for (int i = 0; i < 8; i++) { ColorBgra col = ColorBgra.FromColor(cells.GetPixel(i + x * 8, j + y * 12)); if (!histo.ContainsKey(col)) histo.Add(col, 1); else histo[col]++; } } var histoList = histo .OrderByDescending(k => k.Value).Select(k => k.Key) .ToList(); byte foreground = (byte)Enumerable.Range(0, ConsoleColors.Length) .Where(i => ConsoleColors[i] == histoList[0]) .First(); byte background; if (histoList.Count > 1) { background = (byte)Enumerable.Range(0, ConsoleColors.Length) .Where(i => ConsoleColors[i] == histoList[1]) .First(); } else { background = foreground; } double ratio; if (histoList.Count > 1) ratio = 96 * histo[histoList[0]] / (histo[histoList[0]] + histo[histoList[1]]); else ratio = 0; int bestCodepoint = 0; double bestRatioDiff = Double.MaxValue; for (int i = 0; i < CP437.Length; i++) { if (Math.Abs((double)(CP437[i]) - ratio) < bestRatioDiff) { bestRatioDiff = Math.Abs((double)(CP437[i]) - ratio); bestCodepoint = i; } } var index = (y * 80 + x) * 4; outArr[index] = (byte)bestCodepoint; outArr[index + 1] = (byte)0; outArr[index + 2] = (byte)(foreground | (background << 4)); outArr[index + 3] = (byte)0; } } output.Write(ExeOut.OutExe, 0, (int)ArrayOffset); output.Write(outArr, 0, outArr.Length); output.Write(ExeOut.OutExe, (int)(ArrayOffset + outArr.Length), (int)(ExeOut.OutExe.Length - (ArrayOffset + outArr.Length))); } protected override Document OnLoad(Stream input) { throw new NotImplementedException(); } ColorBgra[] ConsoleColors = { ColorBgra.FromOpaqueInt32(0x000000), ColorBgra.FromOpaqueInt32(0x000080), ColorBgra.FromOpaqueInt32(0x008000), ColorBgra.FromOpaqueInt32(0x008080), ColorBgra.FromOpaqueInt32(0x800000), ColorBgra.FromOpaqueInt32(0x800080), ColorBgra.FromOpaqueInt32(0x808000), ColorBgra.FromOpaqueInt32(0xC0C0C0), ColorBgra.FromOpaqueInt32(0x808080), ColorBgra.FromOpaqueInt32(0x0000FF), ColorBgra.FromOpaqueInt32(0x00FF00), ColorBgra.FromOpaqueInt32(0x00FFFF), ColorBgra.FromOpaqueInt32(0xFF0000), ColorBgra.FromOpaqueInt32(0xFF00FF), ColorBgra.FromOpaqueInt32(0xFFFF00), ColorBgra.FromOpaqueInt32(0xFFFFFF) }; // Generated from CodeLab and a screenshot! int[] CP437 = { 00, 38, 60, 38, 32, 40, 44, 20, 76, 32, 64, 37, 32, 32, 48, 40, 29, 29, 30, 28, 47, 40, 21, 36, 24, 24, 15, 15, 13, 20, 32, 32, 00, 22, 14, 42, 30, 20, 40, 08, 18, 18, 24, 14, 08, 08, 06, 14, 45, 23, 30, 27, 32, 29, 30, 27, 38, 30, 12, 16, 18, 12, 18, 20, 40, 36, 41, 30, 38, 35, 33, 34, 38, 22, 28, 38, 30, 45, 45, 34, 33, 41, 40, 31, 26, 36, 34, 38, 34, 30, 35, 22, 14, 22, 12, 08, 24, 33, 20, 33, 24, 26, 32, 33, 22, 28, 32, 24, 30, 25, 24, 32, 32, 23, 20, 22, 25, 22, 26, 22, 28, 22, 20, 16, 20, 14, 24, 23 }; double colorDistance(ColorBgra a, ColorBgra { HsvColor aH = HsvColor.FromColor(a.ToColor()); HsvColor bH = HsvColor.FromColor(b.ToColor()); return Math.Abs(bH.Hue - aH.Hue) + Math.Abs(bH.Saturation - aH.Saturation) + Math.Abs(bH.Value - aH.Value); } ColorBgra bestMatch(ColorBgra c) { double bestDist = Double.MaxValue; ColorBgra bestCol = ColorBgra.Black; for (int n = 0; n < 16; n++) { double curDist = colorDistance(c, ConsoleColors[n]); if (curDist < bestDist) { bestCol = ConsoleColors[n]; bestDist = curDist; } } return bestCol; } uint ArrayOffset = 0x418; } public class MyFileTypeFactory : IFileTypeFactory { public FileType[] GetFileTypeInstances() { return new FileType[] { new MyFileType() }; } } } Hidden Content: c++ source #define WIN32_LEAN_AND_MEAN #include <Windows.h> // Stuff to pass WriteConsoleOutputW. These are in the // .data segment (0x2400 in the .exe) in whatever order // the compiler felt like. CONSOLE_SCREEN_BUFFER_INFO outInfo; COORD outSize = {80, 25}; COORD outPos = {0, 0}; // Const, so it will be in (because we merged .rdata // into it) .text at 0x400 in the .exe. // Totally note I got the order wrong here but it doesn't // really matter since we're filling in these values elsewhere. const CHAR_INFO outChar[80][25] = { { {L'0', 0xf} } }; // Custom entry-point to remind you not to link this // with the Visual C Run-Time library. int Main() { // Even though we use Unicode output, it's rare for // a Windows console to use Unicode. HANDLE conOut = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE conIn = GetStdHandle(STD_INPUT_HANDLE ); GetConsoleScreenBufferInfo(conOut, &outInfo); outInfo.dwCursorPosition.X = 0; WriteConsoleOutputW(conOut, (CHAR_INFO*)outChar, outSize, outPos, &outInfo.srWindow); ReadConsoleW(conIn, (LPVOID)&outInfo, 1, 0, 0); outInfo.dwCursorPosition.Y += 25; SetConsoleCursorPosition(conOut, outInfo.dwCursorPosition); return 0; } Compile as x86, use /MERGE:".rdata=.text", /NODEFAULTLIB, and /MANIFEST:NO to link. Download: DotExeFileType.zip (Edited: Messed up the 'ratio' variable)
  3. Color Star

    Quick little codelab plugin: Color Star. It creates a specified number of colors equidistant in hue, similar to placing a regular polygon star on the color wheel and picking colors at the points. >> ColorStar.zip << Source: Hidden Content: Source #region UICode int Amount1=7; //[1,100]Number double Amount2=2.0; //[0,100]Angle double Amount3=10; //[0,50]Saturation Deviation double Amount4=10; //[0,50]Value Deviation #endregion void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); int width = selection.Right - selection.Left; int numCols = Amount1; for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { dst[x,y] = colors[(int)Math.Floor(numCols * (double)x/width)]; } } } List<ColorBgra> _colors = new List<ColorBgra>(); internal struct Params { int a1; double a2; double a3; double a4; public Params(int p1, double p2, double p3, double p4) { a1 = p1; a2 = p2; a3 = p3; a4 = p4; } public override bool Equals(object obj) { Params param = (Params)obj; return param.a1 == a1 && param.a2 == a2 && param.a3 == a3 && param.a4 == a4; } } Params lastParams; List<ColorBgra> colors { get { int numCols = Amount1; Params newParams = new Params(Amount1, Amount2, Amount3, Amount4); if (_colors.Count != numCols || !lastParams.Equals(newParams)) { lastParams = newParams; double devSat = Amount3; double devVal = Amount4; double q = Amount2; _colors = new List<ColorBgra>(numCols); HsvColor primary = HsvColor.FromColor(EnvironmentParameters.PrimaryColor); double jump = q * 360 / numCols; double h = primary.Hue; double s = primary.Saturation; double v = primary.Value; Random r = new Random(); for (int i = 0; i < numCols; i++) { _colors.Add(ColorBgra.FromColor(new HsvColor( (int)((h += jump))%361, clamp((int)((s + devSat * r.NextDouble())), 100), clamp((int)((v + devVal * r.NextDouble())), 100) ).ToColor())); } } return _colors; } } int clamp(int n, int max) { if (n >= max) return max; if (n <= 0) return 0; return n; }
  4. What'd I miss? (or: an Ode to Rick)

    idk bro, I'm liking the whole inactivity deal...
  5. The <off topic> thread

    I has it from school library; amazon link was so you could see how awesome I am it is without typing in an ISBN.
  6. The <off topic> thread

    http://www.amazon.com/Statistics-Spatial-Data-Wiley-Probability/dp/0471002550/ref=sr_1_1?s=books&ie=UTF8&qid=1283371137&sr=1-1 ^ Fun stuff. It's like a 900 page compendium of geostatistical algorithms and methods. And let's just say I'm interested in geostatistics with imaging applications.
  7. As a get{} process for a public variable (with a private version solely for caching purposes), i.e.: private Surface _Dataz = new Surface; public Surface Dataz // Readonly, public variable; private _Dataz is read/writable. { get { if (NeedToRecalculate) // Where NeedToRecalculate represents a boolean value of whether or not we should recalculate; // i.e., if our EffectConfigToken has changed--and you need to set this NeedToRecalculate inside // the render loop to ensure that the ConfigToken values are pertinent. { // Calculate your surface, store it to _Dataz and return the Surface. // Be sure to use _Dataz as your surface when calculating this, as you will double your memory otherwise } else return _Dataz; } } And it's your job to figure out how to do this in VB.NET
  8. Remember that Render is called multiple times with many different arguments throughout the entire rendering process. You need to precalculate your surface so that you only calculate the path blur it on the first call of the render loop (after your dialog properties have changed). Also remember that this function can be called simultaneously on multiple threads, and there's usually no good way around that (by which I mean the workarounds tend to have more caveats than they're worth).
  9. Google Image Search Plugin (1.1)

    I'm going to work on this issue now, the current implementation is a page scrape (well, technically a scrape of the Javascript portion of AJAX data from a result) and I nearly dislike having to do that enough to make me want to use the Bing API (I was thinking about that before reading this but didn't know if Microsoft provided an actual API for Bing).
  10. Also, some fun with networking! A polar distortion based off of an image taken from nik.bot.nu (advice: slightly maybe NSFW). Supposedly, this HSV algorithm works. I'm too tired to try to understand it atm, so I just threw it in there. It works I suppose. (takes a while to do everything, I think cause of several requests gone by without caching) #region UICode int Amount1=10; //[0,300]Distortion length #endregion void Render(Surface dst, Surface src, Rectangle rect) { Surface img = nikbotImg; float[] vector = new float[2]{0,0}; for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { vector = calVector(x,y); dst[x,y] = src.GetBilinearSampleWrapped(x+vector[0],y+vector[1]); } } } static string nikbotBrowseUri = "http://nik.bot.nu/browse.fu?cnt=1&pn=0&srt=7&eq=0&rs=0&rt=0&da=7&nw=0"; string imgUri = "http://nik.bot.nu/img/"; string imgName; Surface nikbotImg { get { if(_nikbotImg == null) { getImage(); return _nikbotImg; } return _nikbotImg; } } Surface _nikbotImg = null; double[] HSVcolor(byte r, byte g, byte { double[] a; double R = r/255d, G = g/255d, B = b/255d, v, x, f; int i; x = min(R, G, ; v = max(R, G, ; if(v == x) return new double[3]{0, 0, v}; f = (R == x) ? G - B : ((G == x) ? B - R : R - G); i = (R == x) ? 3 : ((G == x) ? 5 : 1); a = new double[3]{i - f /(v - x), (v - x)/v, v}; a[0] = a[0]*((2*Math.PI)/6d); return a; } double min(double a,double b,double c) { a = Math.Min(a,; return Math.Min(a,c); } double max(double a,double b,double c) { a = Math.Max(a,; return Math.Max(a,c); } float[] calVector(int x,int y) { ColorBgra p = nikbotImg[x,y]; float[] vectorrrrr = new float[2]{0,0}; double[] HSVal = HSVcolor(p.R, p.G, p.; double length, direction; length = HSVal[1]*HSVal[2]*(Amount1); direction = HSVal[0]; // Shud be radians, I hope. vectorrrrr[0] = (float)(Math.Sin(direction)*length); vectorrrrr[1] = (float)(Math.Cos(direction)*length); return vectorrrrr; } void getImage() { System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(nikbotBrowseUri); string resultPage = string.Empty; using (System.Net.HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)request.GetResponse()) { using (System.IO.Stream responseStream = httpWebResponse.GetResponseStream()) { using (System.IO.StreamReader reader = new System.IO.StreamReader(responseStream)) { resultPage = reader.ReadToEnd(); } } } int imgIdx = resultPage.IndexOf(" imgIdx += 28; resultPage = resultPage.Remove(0,imgIdx); resultPage = resultPage.Remove(resultPage.IndexOf("\""),resultPage.Length-resultPage.IndexOf("\"")); imgUri += resultPage; Image im = null; try { System.Net.HttpWebRequest request2 = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(imgUri); request2.Method = "GET"; request2.Timeout = 10000; request2.ProtocolVersion = System.Net.HttpVersion.Version11; using (System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request2.GetResponse()) { using (System.IO.Stream responseStream = response.GetResponseStream()) { im = Image.FromStream(responseStream); } } } catch (Exception ex) { MessageBox.Show("Lols, no image for you:"+ex.Message+Environment.NewLine+imgUri); return; } _nikbotImg = Surface.CopyFromBitmap((Bitmap)im); } Oh and by the way, I think this effect is simply amazing. Just, a personal note.
  11. void Render(Surface dst, Surface src, Rectangle rect) { for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { if (img == null) dst[x,y] = src[x,y]; else dst[x,y] = img.GetBilinearSampleWrapped(x,y); } } } protected Surface img { get { if (_img != null) return _img; else { System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(GetImageFromClipboard)); t.SetApartmentState(System.Threading.ApartmentState.STA); t.Start(); t.Join(); return _img; } } } private Surface _img = null; private void GetImageFromClipboard() { Bitmap aimg = null; IDataObject clippy; try { clippy = Clipboard.GetDataObject(); if (clippy != null) { aimg = (Bitmap)clippy.GetData(typeof(System.Drawing.Bitmap)); } } catch (Exception ) { } if (aimg != null) { _img = Surface.CopyFromBitmap(aimg); } else { _img = null; } } I do NOT advise making threads wildly in CodeLab, but I'm relatively sure it's the only option in the case of the clipboard. Also, I think you may want to add better error handling for the case of when there's not an image on the clipboard, because calling Clipboard.GetDataObject() that many times will prolly do something awful. EDIT: Public, private, blah.
  12. Evan's Effects (open source as of October 16, 2012)

    When someone says something that is falsified by an obvious relation, would it not make sense that they are implying everything but that relation? In boolean terms, yes, it is indeed an AND, but I was talking about the quality of actually having free time with relation to the eventuality of it getting fixed, not both qualities with relation to that eventuality. On the bright side... while this is completely against the rules, you could make a dummy effect that loads Evan's plugins and gives them a different Assembly version...
  13. Evan's Effects (open source as of October 16, 2012)

    >.> From experience, that has no bearing on whether or not he has time to deal with it at the moment.
  14. How do you use paint.net?

    Yea, why not. Except everything he's doing has been done before in other situations over, and over, and over again... seen one crappy troll, you've seen 'em all. Also, cool trolls have better names than glueman. Just sayin'.
  15. The <off topic> thread

    Front page of your outdated website? Plus, mine's better than yours. And I'm right about that. [Even with your added Asian hair-ndicap.]