internal static string GetStatus(ImporterStatus status) { switch (status) { case ImporterStatus.ADDED: return(Translation.StatusADDED); case ImporterStatus.GETTING_IMDB: return(Translation.StatusGETTING_IMDB); case ImporterStatus.GETTING_INFO: return(Translation.StatusGETTING_INFO); case ImporterStatus.QUEUED_IMDB: return(Translation.StatusQUEUED_IMDB); case ImporterStatus.QUEUED_INFO: return(Translation.StatusQUEUED_INFO); case ImporterStatus.SKIP: return(Translation.StatusSKIP); case ImporterStatus.WAITING: return(Translation.StatusWAITING); case ImporterStatus.COMPLETE: return(Translation.StatusCOMPLETE); case ImporterStatus.ERROR: return(Translation.StatusERROR); case ImporterStatus.NONE: return(Translation.StatusNONE); } return(string.Empty); }
void Worker_DoWork(object sender, DoWorkEventArgs e) { // make things more accessible var source = this.sourceBitmap; var target = this.targetBitmap; var width = this.targetBitmap.Width; var height = this.targetBitmap.Height; // limit the rate of updates var update = 0; var updateModulo = targetBitmap.Length / 10; if (updateModulo > 32) { updateModulo = 32; } // fire an initial update { var status = new ImporterStatus(0, target.Length); worker.ReportProgress(status.PercentInt, status); } // get to work for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (worker.CancellationPending) { e.Result = false; e.Cancel = true; return; } Color thisColor = source.GetPixel(x, y); if (update++ >= updateModulo) { var status = new ImporterStatus(y * width + x, target.Length); worker.ReportProgress(status.PercentInt, status); update = 0; } if (thisColor.A == 0) { target.Data[y * width + x] = 0x00; continue; } // get hsv values for current color double h, s, v; Palette.ToHsv(thisColor, out h, out s, out v); // catch black and white if (v == 0) { target.SetPixel(x, y, 0); continue; } if (s == 0 && v == 1) { target.SetPixel(x, y, 15); continue; } // deal with greyscale first if (s < 0.125) { byte color = (byte)(16 + v * 16); target.SetPixel(x, y, color); continue; } Debug.Assert(s >= 0.125, "Saturation must be over 0.125.", "Saturation is " + s.ToString()); // palette indeces int hueIndex, satIndex, lumIndex; // adjust hue to start from blue and assign index h -= 240; if (h < 0) { h = 360 + h; } hueIndex = (int)(h / 15); // determine saturation and luminance satIndex = 0; // full sat if (s <= 0.5) { satIndex = 1; // half sat } else if (s <= 0.25) { satIndex = 2; // quarter sat } lumIndex = 0; if (v <= 0.5) { lumIndex = 1; } else if (v <= 0.25) { lumIndex = 2; } // calculate the pallete entry location byte paletteEntry = (byte)(32 + lumIndex * 72 + satIndex * 24 + hueIndex); target.SetPixel(x, y, paletteEntry); } } }
internal static string GetIcon(ImporterStatus status) { return("importer_" + status.ToString() + ".png"); }
void Worker_DoWork(object sender, DoWorkEventArgs e) { // make things more accessible var source = this.sourceBitmap; var target = this.targetBitmap; var width = this.targetBitmap.Width; var height = this.targetBitmap.Height; // limit the rate of updates var update = 0; var updateModulo = targetBitmap.Length / 10; if (updateModulo > 32) { updateModulo = 32; } // fire an initial update { var status = new ImporterStatus(0, target.Length); worker.ReportProgress(status.PercentInt, status); } // get to work for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (worker.CancellationPending) { e.Result = false; e.Cancel = true; return; } Color thisColor = source.GetPixel(x, y); if (update++ >= updateModulo) { var status = new ImporterStatus(y * width + x, target.Length); worker.ReportProgress(status.PercentInt, status); update = 0; } if (thisColor.A == 0) { target.Data[y * width + x] = 0x00; continue; } int minIndex = -1, min = int.MaxValue; int[] overallDiff = new int[Palette.Length]; for (int i = 0; i < overallDiff.Length; i++) { Color vgaColor = args.Palette[i]; overallDiff[i] += Math.Abs(thisColor.R - vgaColor.R); overallDiff[i] += Math.Abs(thisColor.G - vgaColor.G); overallDiff[i] += Math.Abs(thisColor.B - vgaColor.B); if (overallDiff[i] < min) { min = overallDiff[i]; minIndex = i; } } // set this pixel to the color target.Data[y * width + x] = (byte)minIndex; } } }