Optimize dithering (#66)

This commit is contained in:
adroitwhiz 2021-02-25 16:09:53 -05:00 committed by GitHub
parent 928eb7fa16
commit 4842479001
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 236 additions and 15 deletions

View file

@ -26,7 +26,15 @@ class BlurWorker : public Napi::AsyncWorker {
for_each(coalesced.begin(), coalesced.end(), magickImage(type));
optimizeTransparency(coalesced.begin(), coalesced.end());
if (delay != 0) for_each(coalesced.begin(), coalesced.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : coalesced) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(coalesced.begin(), coalesced.end(), &blob);
}

View file

@ -27,6 +27,15 @@ class BlurpleWorker : public Napi::AsyncWorker {
}
optimizeTransparency(blurpled.begin(), blurpled.end());
if (type == "gif") {
for (Image &image : blurpled) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(blurpled.begin(), blurpled.end(), &blob);
}

View file

@ -45,6 +45,15 @@ class CaptionWorker : public Napi::AsyncWorker {
}
optimizeTransparency(captioned.begin(), captioned.end());
if (type == "gif") {
for (Image &image : captioned) {
image.quantizeDither(false);
image.quantize();
}
}
writeImages(captioned.begin(), captioned.end(), &blob);
}

View file

@ -43,6 +43,14 @@ class CaptionTwoWorker : public Napi::AsyncWorker {
}
optimizeTransparency(captioned.begin(), captioned.end());
if (type == "gif") {
for (Image &image : captioned) {
image.quantizeDither(false);
image.quantize();
}
}
writeImages(captioned.begin(), captioned.end(), &blob);
}

View file

@ -25,7 +25,15 @@ class CircleWorker : public Napi::AsyncWorker {
}
optimizeTransparency(blurred.begin(), blurred.end());
if (delay != 0) for_each(blurred.begin(), blurred.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
}

View file

@ -26,7 +26,15 @@ class CropWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -25,7 +25,15 @@ class ExplodeWorker : public Napi::AsyncWorker {
}
optimizeTransparency(blurred.begin(), blurred.end());
if (delay != 0) for_each(blurred.begin(), blurred.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
}

View file

@ -31,7 +31,15 @@ class FlagWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -25,7 +25,15 @@ class FlipWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -30,7 +30,15 @@ class GamexplainWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -48,6 +48,12 @@ class GlobeWorker : public Napi::AsyncWorker {
} else if (type != "GIF") {
for_each(mid.begin(), mid.end(), animationDelayImage(5));
}
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -27,7 +27,15 @@ class InvertWorker : public Napi::AsyncWorker {
for_each(mid.begin(), mid.end(), magickImage(type));
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -31,7 +31,15 @@ class LeakWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -27,7 +27,15 @@ class MagikWorker : public Napi::AsyncWorker {
}
optimizeTransparency(blurred.begin(), blurred.end());
if (delay != 0) for_each(blurred.begin(), blurred.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
}

View file

@ -57,7 +57,15 @@ class MemeWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -53,6 +53,15 @@ class MirrorWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -25,7 +25,15 @@ class SwirlWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -60,6 +60,15 @@ class MotivateWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -32,7 +32,15 @@ class ResizeWorker : public Napi::AsyncWorker {
}
optimizeTransparency(blurred.begin(), blurred.end());
if (delay != 0) for_each(blurred.begin(), blurred.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
}

View file

@ -28,7 +28,15 @@ class ReverseWorker : public Napi::AsyncWorker {
for_each(coalesced.begin(), coalesced.end(), magickImage("GIF"));
optimizeTransparency(coalesced.begin(), coalesced.end());
if (delay != 0) for_each(coalesced.begin(), coalesced.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : coalesced) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(coalesced.begin(), coalesced.end(), &blob);
}

View file

@ -35,6 +35,15 @@ class ScottWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -42,6 +42,12 @@ class SpinWorker : public Napi::AsyncWorker {
} else if (type != "GIF") {
for_each(mid.begin(), mid.end(), animationDelayImage(5));
}
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -40,6 +40,15 @@ class TileWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -35,6 +35,15 @@ class TrumpWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -32,7 +32,15 @@ class WallWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) for_each(mid.begin(), mid.end(), animationDelayImage(delay));
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -51,6 +51,15 @@ class WatermarkWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}

View file

@ -30,6 +30,15 @@ class WdtWorker : public Napi::AsyncWorker {
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}