Modified the Quantizer to Xiaolin Wu's, updated the BitmapBuffer to support 8BPP but you still need to know what to call.... (needs some additional refactoring)

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1712 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-03-20 15:53:50 +00:00
parent 3250eee533
commit b464480bf6
7 changed files with 101 additions and 726 deletions

View file

@ -993,10 +993,61 @@ namespace GreenshotPlugin.Core {
return newImage;
}
/// <summary>
/// Rotate the bitmap
/// </summary>
/// <param name="sourceBitmap"></param>
/// <param name="rotateFlipType"></param>
/// <returns></returns>
public static Bitmap RotateFlip(Bitmap sourceBitmap, RotateFlipType rotateFlipType) {
Bitmap returnBitmap = Clone(sourceBitmap);
returnBitmap.RotateFlip(rotateFlipType);
return returnBitmap;
}
/// <summary>
/// Get a quantizer, so we can check if it pays off to quantize
/// </summary>
/// <param name="sourceBitmap"></param>
/// <returns>IColorQuantizer</returns>
public static IColorQuantizer PrepareQuantize(Bitmap sourceBitmap) {
IColorQuantizer quantizer = new WuColorQuantizer();
quantizer.Prepare(sourceBitmap);
using (BitmapBuffer bbbSrc = new BitmapBuffer(sourceBitmap, false)) {
bbbSrc.Lock();
for (int y = 0; y < bbbSrc.Height; y++) {
for (int x = 0; x < bbbSrc.Width; x++) {
quantizer.AddColor(bbbSrc.GetColorAt(x, y));
}
}
}
return quantizer;
}
public static Bitmap Quantize(Bitmap sourceBitmap, IColorQuantizer quantizer) {
Bitmap result = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format8bppIndexed);
List<Color> palette = quantizer.GetPalette(255);
ColorPalette imagePalette = result.Palette;
// copies all color entries
for (Int32 index = 0; index < palette.Count; index++) {
imagePalette.Entries[index] = palette[index];
}
result.Palette = imagePalette;
using (BitmapBuffer bbbDest = new BitmapBuffer(result, false)) {
bbbDest.Lock();
using (BitmapBuffer bbbSrc = new BitmapBuffer(sourceBitmap, false)) {
bbbSrc.Lock();
for (int y = 0; y < bbbSrc.Height; y++) {
for (int x = 0; x < bbbSrc.Width; x++) {
Color originalColor = bbbSrc.GetColorAt(x, y);
Int32 paletteIndex = quantizer.GetPaletteIndex(originalColor);
bbbDest.SetColorIndexAt(x,y, (byte)paletteIndex);
}
}
}
}
return result;
}
}
}