diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-20 19:33:52 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-20 19:33:52 +0000 |
commit | d28ba8010c6058bf073f7e815d5b2d7fdf698601 (patch) | |
tree | 25d4f972fc63d9f8a39544bec50d53ee1c29f2ac | |
parent | d2cfa7422e2b0928970b3b0fa1abe1d73113fc1d (diff) |
promote SkImage::AlphaType to SkAlphaType
BUG=
R=bsalomon@google.com
Review URL: https://codereview.chromium.org/24130009
git-svn-id: http://skia.googlecode.com/svn/trunk@11421 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/DeferredSurfaceCopyBench.cpp | 2 | ||||
-rw-r--r-- | gm/fatpathfill.cpp | 8 | ||||
-rw-r--r-- | gm/image.cpp | 9 | ||||
-rw-r--r-- | gm/srcmode.cpp | 2 | ||||
-rw-r--r-- | gyp/core.gypi | 1 | ||||
-rw-r--r-- | include/core/SkAlpha.h | 50 | ||||
-rw-r--r-- | include/core/SkImage.h | 26 | ||||
-rw-r--r-- | include/core/SkSurface.h | 2 | ||||
-rw-r--r-- | samplecode/SampleFatBits.cpp | 11 | ||||
-rw-r--r-- | src/image/SkImagePriv.cpp | 30 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 2 | ||||
-rw-r--r-- | src/image/SkSurface_Picture.cpp | 2 | ||||
-rw-r--r-- | tests/DeferredCanvasTest.cpp | 4 | ||||
-rw-r--r-- | tests/DrawPathTest.cpp | 5 | ||||
-rw-r--r-- | tests/PathTest.cpp | 15 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 2 | ||||
-rw-r--r-- | tools/skhello.cpp | 5 |
17 files changed, 104 insertions, 72 deletions
diff --git a/bench/DeferredSurfaceCopyBench.cpp b/bench/DeferredSurfaceCopyBench.cpp index 2aaebe74ec..f9f8c8e95b 100644 --- a/bench/DeferredSurfaceCopyBench.cpp +++ b/bench/DeferredSurfaceCopyBench.cpp @@ -38,7 +38,7 @@ protected: info.fWidth = kSurfaceWidth; info.fHeight = kSurfaceHeight; info.fColorType = SkImage::kPMColor_ColorType; - info.fAlphaType = SkImage::kPremul_AlphaType; + info.fAlphaType = kPremul_SkAlphaType; const SkRect fullCanvasRect = SkRect::MakeWH( SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight)); SkSurface* surface; diff --git a/gm/fatpathfill.cpp b/gm/fatpathfill.cpp index 44988795b4..8b892327a9 100644 --- a/gm/fatpathfill.cpp +++ b/gm/fatpathfill.cpp @@ -16,13 +16,7 @@ #define REPEAT_LOOP 5 static SkSurface* new_surface(int width, int height) { - SkImage::Info info = { - width, - height, - SkImage::kPMColor_ColorType, - SkImage::kPremul_AlphaType - }; - return SkSurface::NewRaster(info); + return SkSurface::NewRasterPMColor(width, height); } static void draw_pixel_centers(SkCanvas* canvas) { diff --git a/gm/image.cpp b/gm/image.cpp index 6dada0d949..e9378be0e2 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -178,12 +178,9 @@ protected: // since we draw into this directly, we need to start fresh sk_bzero(fBuffer, fBufferSize); - SkImage::Info info; - - info.fWidth = W; - info.fHeight = H; - info.fColorType = SkImage::kPMColor_ColorType; - info.fAlphaType = SkImage::kPremul_AlphaType; + SkImage::Info info = { + W, H, SkImage::kPMColor_ColorType, kPremul_SkAlphaType + }; SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB)); SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); SkAutoTUnref<SkSurface> surf2(SkSurface::NewPicture(info.fWidth, info.fHeight)); diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp index e8a97e2b7b..0f2591c828 100644 --- a/gm/srcmode.cpp +++ b/gm/srcmode.cpp @@ -121,7 +121,7 @@ protected: size.width(), size.height(), SkImage::kPMColor_ColorType, - SkImage::kPremul_AlphaType + kPremul_SkAlphaType }; #if SK_SUPPORT_GPU SkBaseDevice* dev = canvas->getDevice(); diff --git a/gyp/core.gypi b/gyp/core.gypi index 3fdca921b9..51208056fa 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -214,6 +214,7 @@ '<(skia_include_path)/core/Sk64.h', '<(skia_include_path)/core/SkAdvancedTypefaceMetrics.h', + '<(skia_include_path)/core/SkAlpha.h', '<(skia_include_path)/core/SkBitmap.h', '<(skia_include_path)/core/SkBitmapDevice.h', '<(skia_include_path)/core/SkBlitRow.h', diff --git a/include/core/SkAlpha.h b/include/core/SkAlpha.h new file mode 100644 index 0000000000..662b741a95 --- /dev/null +++ b/include/core/SkAlpha.h @@ -0,0 +1,50 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkAlpha_DEFINED +#define SkAlpha_DEFINED + +#include "SkTypes.h" + +/** + * Describes how to interpret the alpha compoent of a pixel. + */ +enum SkAlphaType { + /** + * All pixels should be treated as opaque, regardless of the value stored + * in their alpha field. Used for legacy images that wrote 0 or garbarge + * in their alpha field, but intended the RGB to be treated as opaque. + */ + kIgnore_SkAlphaType, + + /** + * All pixels are stored as opaque. This differs slightly from kIgnore in + * that kOpaque has correct "opaque" values stored in the pixels, while + * kIgnore may not, but in both cases the caller should treat the pixels + * as opaque. + */ + kOpaque_SkAlphaType, + + /** + * All pixels have their alpha premultiplied in their color components. + * This is the natural format for the rendering target pixels. + */ + kPremul_SkAlphaType, + + /** + * All pixels have their color components stored without any regard to the + * alpha. e.g. this is the default configuration for PNG images. + * + * This alpha-type is ONLY supported for input images. Rendering cannot + * generate this on output. + */ + kUnpremul_SkAlphaType, + + kLastEnum_SkAlphaType = kUnpremul_SkAlphaType +}; + +#endif diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 871d4612c7..f6f6a41eaf 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -8,6 +8,7 @@ #ifndef SkImage_DEFINED #define SkImage_DEFINED +#include "SkAlpha.h" #include "SkImageEncoder.h" #include "SkRefCnt.h" #include "SkScalar.h" @@ -41,25 +42,32 @@ public: kRGB_565_ColorType, kRGBA_8888_ColorType, kBGRA_8888_ColorType, - kPMColor_ColorType, + +#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) + kPMColor_ColorType = kBGRA_8888_ColorType, +#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) + kPMColor_ColorType = kRGBA_8888_ColorType, +#else + #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order +#endif - kLastEnum_ColorType = kPMColor_ColorType + kLastEnum_ColorType = kBGRA_8888_ColorType }; +#ifdef SK_ENABLE_LEGACY_API_ALIASING enum AlphaType { - kIgnore_AlphaType, - kOpaque_AlphaType, - kPremul_AlphaType, - kUnpremul_AlphaType, - - kLastEnum_AlphaType = kUnpremul_AlphaType + kIgnore_AlphaType = kIgnore_SkAlphaType, + kOpaque_AlphaType = kOpaque_SkAlphaType, + kPremul_AlphaType = kPremul_SkAlphaType, + kUnpremul_AlphaType = kUnpremul_SkAlphaType, }; +#endif struct Info { int fWidth; int fHeight; ColorType fColorType; - AlphaType fAlphaType; + SkAlphaType fAlphaType; }; static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes); diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 663cea0875..d197a57eaf 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -53,7 +53,7 @@ public: */ static SkSurface* NewRasterPMColor(int width, int height) { SkImage::Info info = { - width, height, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType + width, height, SkImage::kPMColor_ColorType, kPremul_SkAlphaType }; return NewRaster(info); } diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp index 04fa1a39cb..8159cc5db8 100644 --- a/samplecode/SampleFatBits.cpp +++ b/samplecode/SampleFatBits.cpp @@ -91,13 +91,10 @@ public: fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); fShader->setLocalMatrix(fMatrix); - SkImage::Info info = { - width, height, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType - }; - fMinSurface.reset(SkSurface::NewRaster(info)); - info.fWidth *= zoom; - info.fHeight *= zoom; - fMaxSurface.reset(SkSurface::NewRaster(info)); + fMinSurface.reset(SkSurface::NewRasterPMColor(width, height)); + width *= zoom; + height *= zoom; + fMaxSurface.reset(SkSurface::NewRasterPMColor(width, height)); } void drawBG(SkCanvas*); diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp index 9454272373..1e722365f0 100644 --- a/src/image/SkImagePriv.cpp +++ b/src/image/SkImagePriv.cpp @@ -14,16 +14,16 @@ SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info& info, switch (info.fColorType) { case SkImage::kAlpha_8_ColorType: switch (info.fAlphaType) { - case SkImage::kIgnore_AlphaType: + case kIgnore_SkAlphaType: // makes no sense return SkBitmap::kNo_Config; - case SkImage::kOpaque_AlphaType: + case kOpaque_SkAlphaType: *isOpaque = true; return SkBitmap::kA8_Config; - case SkImage::kPremul_AlphaType: - case SkImage::kUnpremul_AlphaType: + case kPremul_SkAlphaType: + case kUnpremul_SkAlphaType: *isOpaque = false; return SkBitmap::kA8_Config; } @@ -34,27 +34,25 @@ SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info& info, *isOpaque = true; return SkBitmap::kRGB_565_Config; - case SkImage::kRGBA_8888_ColorType: - case SkImage::kBGRA_8888_ColorType: - // not supported yet - return SkBitmap::kNo_Config; - case SkImage::kPMColor_ColorType: switch (info.fAlphaType) { - case SkImage::kIgnore_AlphaType: - case SkImage::kUnpremul_AlphaType: + case kIgnore_SkAlphaType: + case kUnpremul_SkAlphaType: // not supported yet return SkBitmap::kNo_Config; - case SkImage::kOpaque_AlphaType: + case kOpaque_SkAlphaType: *isOpaque = true; return SkBitmap::kARGB_8888_Config; - case SkImage::kPremul_AlphaType: + case kPremul_SkAlphaType: *isOpaque = false; return SkBitmap::kARGB_8888_Config; } break; + + default: + // break for unsupported colortypes + break; } - SkDEBUGFAIL("how did we get here"); return SkBitmap::kNo_Config; } @@ -91,8 +89,8 @@ bool SkBitmapToImageInfo(const SkBitmap& bm, SkImage::Info* info) { info->fWidth = bm.width(); info->fHeight = bm.height(); - info->fAlphaType = bm.isOpaque() ? SkImage::kOpaque_AlphaType : - SkImage::kPremul_AlphaType; + info->fAlphaType = bm.isOpaque() ? kOpaque_SkAlphaType : + kPremul_SkAlphaType; return true; } diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 3e2685606d..cd9b70f018 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -27,7 +27,7 @@ public: if ((unsigned)info.fColorType > (unsigned)kLastEnum_ColorType) { return false; } - if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_AlphaType) { + if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) { return false; } diff --git a/src/image/SkSurface_Picture.cpp b/src/image/SkSurface_Picture.cpp index 79812c4a61..915530c8dc 100644 --- a/src/image/SkSurface_Picture.cpp +++ b/src/image/SkSurface_Picture.cpp @@ -62,7 +62,7 @@ SkImage* SkSurface_Picture::onNewImageSnapshot() { SkImage::Info info; info.fWidth = info.fHeight = 0; info.fColorType = SkImage::kPMColor_ColorType; - info.fAlphaType = SkImage::kOpaque_AlphaType; + info.fAlphaType = kOpaque_SkAlphaType; return SkImage::NewRasterCopy(info, NULL, 0); } } diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp index 7593ba877c..e8075bd68f 100644 --- a/tests/DeferredCanvasTest.cpp +++ b/tests/DeferredCanvasTest.cpp @@ -696,7 +696,7 @@ static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac 10, // width 10, // height SkImage::kPMColor_ColorType, - SkImage::kPremul_AlphaType + kPremul_SkAlphaType }; SkSurface* surface; bool useGpu = NULL != factory; @@ -763,7 +763,7 @@ static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext 10, // width 10, // height SkImage::kPMColor_ColorType, - SkImage::kPremul_AlphaType + kPremul_SkAlphaType }; SkSurface* surface; SkSurface* alternateSurface; diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp index 9f440f6231..40f4a047b2 100644 --- a/tests/DrawPathTest.cpp +++ b/tests/DrawPathTest.cpp @@ -36,10 +36,7 @@ static void test_big_aa_rect(skiatest::Reporter* reporter) { output.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 4); output.setPixels(pixel); - SkImage::Info info = { - 300, 33300, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType - }; - SkSurface* surf = SkSurface::NewRaster(info); + SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300); SkCanvas* canvas = surf->getCanvas(); SkRect r = { 0, 33000, 300, 33300 }; diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index 080ce285e0..ff51edd1d8 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -25,13 +25,6 @@ #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) #endif -static SkSurface* new_surface(int w, int h) { - SkImage::Info info = { - w, h, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType - }; - return SkSurface::NewRaster(info); -} - static void test_path_close_issue1474(skiatest::Reporter* reporter) { // This test checks that r{Line,Quad,Conic,Cubic}To following a close() // are relative to the point we close to, not relative to the point we close from. @@ -141,7 +134,7 @@ static void test_bad_cubic_crbug234190() { SkPaint paint; paint.setAntiAlias(true); - SkAutoTUnref<SkSurface> surface(new_surface(84, 88)); + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88)); surface->getCanvas()->drawPath(path, paint); } @@ -260,7 +253,7 @@ static void test_crbug_170666() { SkPaint paint; paint.setAntiAlias(true); - SkAutoTUnref<SkSurface> surface(new_surface(1000, 1000)); + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000)); build_path_simple_170666(path); surface->getCanvas()->drawPath(path, paint); @@ -312,7 +305,7 @@ static void build_big_path(SkPath* path, bool reducedCase) { } static void test_clipped_cubic() { - SkAutoTUnref<SkSurface> surface(new_surface(640, 480)); + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480)); // This path used to assert, because our cubic-chopping code incorrectly // moved control points after the chop. This test should be run in SK_DEBUG @@ -348,7 +341,7 @@ static void test_tricky_cubic() { SkPaint paint; paint.setAntiAlias(true); - SkSurface* surface = new_surface(19, 130); + SkSurface* surface = SkSurface::NewRasterPMColor(19, 130); surface->getCanvas()->drawPath(path, paint); surface->unref(); } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 049f250667..80822a15b6 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -28,7 +28,7 @@ static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context) { 10, // width 10, // height SkImage::kPMColor_ColorType, - SkImage::kPremul_AlphaType + kPremul_SkAlphaType }; switch (surfaceType) { diff --git a/tools/skhello.cpp b/tools/skhello.cpp index bd3174252e..d30849bcfb 100644 --- a/tools/skhello.cpp +++ b/tools/skhello.cpp @@ -30,10 +30,7 @@ static void doDraw(SkCanvas* canvas, const SkPaint& paint, const char text[]) { static bool do_surface(int w, int h, const char path[], const char text[], const SkPaint& paint) { - SkImage::Info info = { - w, h, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType - }; - SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(w, h)); doDraw(surface->getCanvas(), paint, text); SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |