Loading libs/hwui/CanvasTransform.cpp +5 −8 Original line number Diff line number Diff line Loading @@ -143,8 +143,7 @@ static BitmapPalette paletteForColorHSV(SkColor color) { } BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) { if ((palette != BitmapPalette::Light && palette != BitmapPalette::Dark) || !paint || !paint->getColorFilter()) { if (palette == BitmapPalette::Unknown || !paint || !paint->getColorFilter()) { return palette; } Loading @@ -162,13 +161,11 @@ bool transformPaint(ColorTransform transform, SkPaint* paint) { bool transformPaint(ColorTransform transform, SkPaint* paint, BitmapPalette palette) { bool shouldInvert = false; if (transform == ColorTransform::Invert) { if (palette != BitmapPalette::Barcode && palette != BitmapPalette::Colorful) { // When the transform is Invert we invert any image that is not deemed "colorful" // or a barcode, regardless of calculated image brightness. if (transform == ColorTransform::Invert && palette != BitmapPalette::Colorful) { // When the transform is Invert we invert any image that is not deemed "colorful", // regardless of calculated image brightness. shouldInvert = true; } } palette = filterPalette(paint, palette); if (palette == BitmapPalette::Light && transform == ColorTransform::Dark) { shouldInvert = true; Loading libs/hwui/ColorArea.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,6 @@ void ColorArea::addArea(const SkRect& bounds, const SkPaint& paint, addArea(area, Dark); break; case android::BitmapPalette::Colorful: case android::BitmapPalette::Barcode: case android::BitmapPalette::Unknown: addArea(area, Unknown); break; Loading libs/hwui/RecordingCanvas.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -104,8 +104,6 @@ enum class Type : uint8_t { }; #undef X static constexpr uint32_t BARCODE_QUIET_ZONE_PX = 5; struct Op { uint32_t type : 8; uint32_t skip : 24; Loading Loading @@ -493,23 +491,13 @@ struct DrawImageRect final : Op { if (ATRACE_ENABLED()) { traceBitmapScaling(c, image, src, dst); } SkRect destination = dst; if (CC_UNLIKELY(palette == BitmapPalette::Barcode)) { // Draw an extra quiet zone around the bitmap in order to guarantee that there // is a white border between the likely-black background and the black portion of // the barcode. SkPaint whitePaint; whitePaint.setColor(SkColors::kWhite); c->drawRect(destination, whitePaint); destination.inset(BARCODE_QUIET_ZONE_PX, BARCODE_QUIET_ZONE_PX); } if (gainmap) { DrawGainmapBitmap(c, image, src, destination, sampling, &paint, constraint, gainmap, DrawGainmapBitmap(c, image, src, dst, sampling, &paint, constraint, gainmap, gainmapInfo); } else { SkPaint newPaint = paint; tonemapPaint(image->imageInfo(), c->imageInfo(), -1, newPaint); c->drawImageRect(image.get(), src, destination, sampling, &newPaint, constraint); c->drawImageRect(image.get(), src, dst, sampling, &newPaint, constraint); } } Loading libs/hwui/hwui/Bitmap.cpp +1 −37 Original line number Diff line number Diff line Loading @@ -525,24 +525,6 @@ private: int mCount = 0; }; template <int N> class Histogram { public: // Expects values between 0f and 1f void add(float sample) { if (sample >= 0.f && sample <= 1.f) { buckets[std::min(N - 1, static_cast<int>(sample * N))]++; } } int size() { return N; } int operator[](int i) const { return buckets[i]; } private: std::array<int, N> buckets; }; BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, size_t rowBytes) { ATRACE_CALL(); Loading @@ -554,7 +536,6 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, MinMaxAverage hue, saturation, value; int sampledCount = 0; Histogram<10> valueHistogram; // Sample a grid of 100 pixels to get an overall estimation of the colors in play const int x_step = std::max(1, pixmap.width() / 10); Loading @@ -571,9 +552,7 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, SkColorToHSV(color, hsv); hue.add(hsv[0]); saturation.add(hsv[1]); float val = hsv[2]; value.add(val); valueHistogram.add(val); value.add(hsv[2]); } } Loading @@ -591,21 +570,6 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, saturation.average(), info.width(), info.height()); if (CC_UNLIKELY(view_accessibility_flags::force_invert_color())) { // The following palettes only apply when the app is applying Force Invert and are not // used by classic Force Dark. // TODO: b/411725862 - Improve the barcode heuristic by incorporating actual barcode specs if (sampledCount > 80) { // The image should be majority pure black and white, but not entirely one color. int expectedBlackAndWhiteSamples = sampledCount * 0.9; int expectedBlackOrWhiteSamples = sampledCount * 0.25; int blackSamples = valueHistogram[0]; int whiteSamples = valueHistogram[valueHistogram.size() - 1]; if (blackSamples + whiteSamples >= expectedBlackAndWhiteSamples && blackSamples >= expectedBlackOrWhiteSamples && whiteSamples >= expectedBlackOrWhiteSamples) { return BitmapPalette::Barcode; } } if (saturation.delta() > 0.1f || (hue.delta() > 20 && saturation.average() > 0.2f && value.average() < 0.9f)) { return BitmapPalette::Colorful; Loading libs/hwui/hwui/Bitmap.h +0 −6 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ enum class BitmapPalette { Light, Dark, Colorful, Barcode, }; namespace uirenderer { Loading Loading @@ -172,11 +171,6 @@ public: return mPalette; } void setPalette(BitmapPalette palette) { mPalette = palette; mPaletteGenerationId = getGenerationID(); } // returns true if rowBytes * height can be represented by a positive int32_t value // and places that value in size. static bool computeAllocationSize(size_t rowBytes, int height, size_t* size); Loading Loading
libs/hwui/CanvasTransform.cpp +5 −8 Original line number Diff line number Diff line Loading @@ -143,8 +143,7 @@ static BitmapPalette paletteForColorHSV(SkColor color) { } BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) { if ((palette != BitmapPalette::Light && palette != BitmapPalette::Dark) || !paint || !paint->getColorFilter()) { if (palette == BitmapPalette::Unknown || !paint || !paint->getColorFilter()) { return palette; } Loading @@ -162,13 +161,11 @@ bool transformPaint(ColorTransform transform, SkPaint* paint) { bool transformPaint(ColorTransform transform, SkPaint* paint, BitmapPalette palette) { bool shouldInvert = false; if (transform == ColorTransform::Invert) { if (palette != BitmapPalette::Barcode && palette != BitmapPalette::Colorful) { // When the transform is Invert we invert any image that is not deemed "colorful" // or a barcode, regardless of calculated image brightness. if (transform == ColorTransform::Invert && palette != BitmapPalette::Colorful) { // When the transform is Invert we invert any image that is not deemed "colorful", // regardless of calculated image brightness. shouldInvert = true; } } palette = filterPalette(paint, palette); if (palette == BitmapPalette::Light && transform == ColorTransform::Dark) { shouldInvert = true; Loading
libs/hwui/ColorArea.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,6 @@ void ColorArea::addArea(const SkRect& bounds, const SkPaint& paint, addArea(area, Dark); break; case android::BitmapPalette::Colorful: case android::BitmapPalette::Barcode: case android::BitmapPalette::Unknown: addArea(area, Unknown); break; Loading
libs/hwui/RecordingCanvas.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -104,8 +104,6 @@ enum class Type : uint8_t { }; #undef X static constexpr uint32_t BARCODE_QUIET_ZONE_PX = 5; struct Op { uint32_t type : 8; uint32_t skip : 24; Loading Loading @@ -493,23 +491,13 @@ struct DrawImageRect final : Op { if (ATRACE_ENABLED()) { traceBitmapScaling(c, image, src, dst); } SkRect destination = dst; if (CC_UNLIKELY(palette == BitmapPalette::Barcode)) { // Draw an extra quiet zone around the bitmap in order to guarantee that there // is a white border between the likely-black background and the black portion of // the barcode. SkPaint whitePaint; whitePaint.setColor(SkColors::kWhite); c->drawRect(destination, whitePaint); destination.inset(BARCODE_QUIET_ZONE_PX, BARCODE_QUIET_ZONE_PX); } if (gainmap) { DrawGainmapBitmap(c, image, src, destination, sampling, &paint, constraint, gainmap, DrawGainmapBitmap(c, image, src, dst, sampling, &paint, constraint, gainmap, gainmapInfo); } else { SkPaint newPaint = paint; tonemapPaint(image->imageInfo(), c->imageInfo(), -1, newPaint); c->drawImageRect(image.get(), src, destination, sampling, &newPaint, constraint); c->drawImageRect(image.get(), src, dst, sampling, &newPaint, constraint); } } Loading
libs/hwui/hwui/Bitmap.cpp +1 −37 Original line number Diff line number Diff line Loading @@ -525,24 +525,6 @@ private: int mCount = 0; }; template <int N> class Histogram { public: // Expects values between 0f and 1f void add(float sample) { if (sample >= 0.f && sample <= 1.f) { buckets[std::min(N - 1, static_cast<int>(sample * N))]++; } } int size() { return N; } int operator[](int i) const { return buckets[i]; } private: std::array<int, N> buckets; }; BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, size_t rowBytes) { ATRACE_CALL(); Loading @@ -554,7 +536,6 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, MinMaxAverage hue, saturation, value; int sampledCount = 0; Histogram<10> valueHistogram; // Sample a grid of 100 pixels to get an overall estimation of the colors in play const int x_step = std::max(1, pixmap.width() / 10); Loading @@ -571,9 +552,7 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, SkColorToHSV(color, hsv); hue.add(hsv[0]); saturation.add(hsv[1]); float val = hsv[2]; value.add(val); valueHistogram.add(val); value.add(hsv[2]); } } Loading @@ -591,21 +570,6 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr, saturation.average(), info.width(), info.height()); if (CC_UNLIKELY(view_accessibility_flags::force_invert_color())) { // The following palettes only apply when the app is applying Force Invert and are not // used by classic Force Dark. // TODO: b/411725862 - Improve the barcode heuristic by incorporating actual barcode specs if (sampledCount > 80) { // The image should be majority pure black and white, but not entirely one color. int expectedBlackAndWhiteSamples = sampledCount * 0.9; int expectedBlackOrWhiteSamples = sampledCount * 0.25; int blackSamples = valueHistogram[0]; int whiteSamples = valueHistogram[valueHistogram.size() - 1]; if (blackSamples + whiteSamples >= expectedBlackAndWhiteSamples && blackSamples >= expectedBlackOrWhiteSamples && whiteSamples >= expectedBlackOrWhiteSamples) { return BitmapPalette::Barcode; } } if (saturation.delta() > 0.1f || (hue.delta() > 20 && saturation.average() > 0.2f && value.average() < 0.9f)) { return BitmapPalette::Colorful; Loading
libs/hwui/hwui/Bitmap.h +0 −6 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ enum class BitmapPalette { Light, Dark, Colorful, Barcode, }; namespace uirenderer { Loading Loading @@ -172,11 +171,6 @@ public: return mPalette; } void setPalette(BitmapPalette palette) { mPalette = palette; mPaletteGenerationId = getGenerationID(); } // returns true if rowBytes * height can be represented by a positive int32_t value // and places that value in size. static bool computeAllocationSize(size_t rowBytes, int height, size_t* size); Loading