Browse Source

Fixed Wu Quantizer transparency

Former-commit-id: 79819485015944b40893f385643943b566fba85a
Former-commit-id: 253f7dd509357930ba5aacc2a5d40c1938161810
pull/17/head
James South 11 years ago
parent
commit
5e0fa4eba3
  1. 2
      src/ImageProcessor.Playground/Program.cs
  2. 1
      src/ImageProcessor.Playground/images/input/cow_PNG2140.png.REMOVED.git-id
  3. 1
      src/ImageProcessor.Playground/images/input/eye-162182_1280.png.REMOVED.git-id
  4. 1
      src/ImageProcessor.Playground/images/input/grad.png.REMOVED.git-id
  5. 1
      src/ImageProcessor.Playground/images/input/rose_PNG658.png.REMOVED.git-id
  6. 14
      src/ImageProcessor/Imaging/Formats/PngFormat.cs
  7. 4
      src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizer.cs
  8. 5
      src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs

2
src/ImageProcessor.Playground/Program.cs

@ -50,7 +50,7 @@ namespace ImageProcessor.PlayGround
}
// Image mask = Image.FromFile(Path.Combine(resolvedPath, "mask2.png"));
//FileInfo fileInfo = new FileInfo(Path.Combine(resolvedPath, "effect_24bit.png"));
//FileInfo fileInfo = new FileInfo(Path.Combine(resolvedPath, "circle.png"));
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".png");
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png", ".tif");

1
src/ImageProcessor.Playground/images/input/cow_PNG2140.png.REMOVED.git-id

@ -0,0 +1 @@
04b381ec37fffdbffa55d5b02478ad81375eaa4b

1
src/ImageProcessor.Playground/images/input/eye-162182_1280.png.REMOVED.git-id

@ -0,0 +1 @@
0693daaf5dc3451fcad6b9ad910fbdfcfa3f9882

1
src/ImageProcessor.Playground/images/input/grad.png.REMOVED.git-id

@ -0,0 +1 @@
c30305a6617a68a2f5671b6a69dbe832d9f73e08

1
src/ImageProcessor.Playground/images/input/rose_PNG658.png.REMOVED.git-id

@ -0,0 +1 @@
60379fd852541c3f736148862adf54691f39fdee

14
src/ImageProcessor/Imaging/Formats/PngFormat.cs

@ -100,8 +100,8 @@ namespace ImageProcessor.Imaging.Formats
if (this.IsIndexed)
{
// The Wu Quantizer expects a 32bbp image.
if (Image.GetPixelFormatSize(image.PixelFormat) != 32)
{
//if (Image.GetPixelFormatSize(image.PixelFormat) != 32)
//{
Bitmap clone = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
clone.SetResolution(image.HorizontalResolution, image.VerticalResolution);
@ -116,11 +116,11 @@ namespace ImageProcessor.Imaging.Formats
image = new WuQuantizer().QuantizeImage(clone);
// image = new OctreeQuantizer(255, 8).Quantize(image);
}
else
{
image = new WuQuantizer().QuantizeImage((Bitmap)image);
}
//}
//else
//{
// image = new WuQuantizer().QuantizeImage((Bitmap)image);
//}
}
return base.Save(path, image);

4
src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizer.cs

@ -92,12 +92,14 @@ namespace ImageProcessor.Imaging.Quantizers.WuQuantizer
byte[] lineIndexes = new byte[image.Image.Width];
PaletteLookup lookup = new PaletteLookup(lookups);
// Determine the correct fallback color.
byte fallback = (byte)(lookups.Length < AlphaColor ? 0 : AlphaColor);
foreach (Pixel[] pixelLine in image.PixelLines)
{
for (int pixelIndex = 0; pixelIndex < pixelLine.Length; pixelIndex++)
{
Pixel pixel = pixelLine[pixelIndex];
byte bestMatch = 0;
byte bestMatch = fallback;
if (pixel.Alpha > alphaThreshold)
{
bestMatch = lookup.GetPaletteIndex(pixel);

5
src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs

@ -168,9 +168,10 @@ namespace ImageProcessor.Imaging.Quantizers.WuQuantizer
moments[pixelAlpha, pixelRed, pixelGreen, pixelBlue].Add(pixel);
}
}
moments[0, 0, 0, 0].Add(new Pixel(0, 255, 255, 255));
}
// Set a default pixel for images with less than 256 colors.
moments[0, 0, 0, 0].Add(new Pixel(0, 0, 0, 0));
}
private static void CalculateMoments(ColorMoment[, , ,] moments)

Loading…
Cancel
Save