move SkImageInfo into its own header
BUG=
R=djsollen@google.com
Review URL: https://codereview.chromium.org/71813002
git-svn-id: http://skia.googlecode.com/svn/trunk/include@12273 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkAlpha.h b/core/SkAlpha.h
deleted file mode 100644
index 74ea687..0000000
--- a/core/SkAlpha.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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
-};
-
-static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
- return (unsigned)at <= kOpaque_SkAlphaType;
-}
-#endif
diff --git a/core/SkBitmap.h b/core/SkBitmap.h
index 16f54b1..dd2d2cf 100644
--- a/core/SkBitmap.h
+++ b/core/SkBitmap.h
@@ -11,13 +11,12 @@
#define SkBitmap_DEFINED
#include "Sk64.h"
-#include "SkAlpha.h"
#include "SkColor.h"
#include "SkColorTable.h"
+#include "SkImageInfo.h"
#include "SkPoint.h"
#include "SkRefCnt.h"
-struct SkImageInfo;
struct SkIRect;
struct SkRect;
class SkPaint;
diff --git a/core/SkColorTable.h b/core/SkColorTable.h
index 8a21258..52300fc 100644
--- a/core/SkColorTable.h
+++ b/core/SkColorTable.h
@@ -10,9 +10,9 @@
#ifndef SkColorTable_DEFINED
#define SkColorTable_DEFINED
-#include "SkAlpha.h"
#include "SkColor.h"
#include "SkFlattenable.h"
+#include "SkImageInfo.h"
/** \class SkColorTable
diff --git a/core/SkImage.h b/core/SkImage.h
index 39f2ec9..accfc0d 100644
--- a/core/SkImage.h
+++ b/core/SkImage.h
@@ -8,7 +8,7 @@
#ifndef SkImage_DEFINED
#define SkImage_DEFINED
-#include "SkAlpha.h"
+#include "SkImageInfo.h"
#include "SkImageEncoder.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
@@ -23,34 +23,6 @@
// need for TileMode
#include "SkShader.h"
-enum SkColorType {
- kAlpha_8_SkColorType,
- kRGB_565_SkColorType,
- kRGBA_8888_SkColorType,
- kBGRA_8888_SkColorType,
-
-#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
- kPMColor_SkColorType = kBGRA_8888_SkColorType,
-#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
- kPMColor_SkColorType = kRGBA_8888_SkColorType,
-#else
- #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
-#endif
-
- kIndex8_SkColorType,
- kLastEnum_SkColorType = kIndex8_SkColorType
-};
-
-struct SkImageInfo {
- int fWidth;
- int fHeight;
- SkColorType fColorType;
- SkAlphaType fAlphaType;
-};
-
-bool operator==(const SkImageInfo& lhs, const SkImageInfo& rhs);
-bool operator!=(const SkImageInfo& lhs, const SkImageInfo& rhs);
-
/**
* SkImage is an abstraction for drawing a rectagle of pixels, though the
* particular type of image could be actually storing its data on the GPU, or
diff --git a/core/SkImageInfo.h b/core/SkImageInfo.h
new file mode 100644
index 0000000..270ff01
--- /dev/null
+++ b/core/SkImageInfo.h
@@ -0,0 +1,123 @@
+/*
+ * 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 SkImageInfo_DEFINED
+#define SkImageInfo_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
+};
+
+static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
+ SK_COMPILE_ASSERT(kIgnore_SkAlphaType < kOpaque_SkAlphaType, bad_alphatype_order);
+ SK_COMPILE_ASSERT(kPremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype_order);
+ SK_COMPILE_ASSERT(kUnpremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype_order);
+
+ return (unsigned)at <= kOpaque_SkAlphaType;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Describes how to interpret the components of a pixel.
+ */
+enum SkColorType {
+ kAlpha_8_SkColorType,
+ kRGB_565_SkColorType,
+ kRGBA_8888_SkColorType,
+ kBGRA_8888_SkColorType,
+ kIndex8_SkColorType,
+
+ kLastEnum_SkColorType = kIndex8_SkColorType,
+
+#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
+ kPMColor_SkColorType = kBGRA_8888_SkColorType
+#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
+ kPMColor_SkColorType = kRGBA_8888_SkColorType
+#else
+#error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
+#endif
+};
+
+static int SkColorTypeBytesPerPixel(SkColorType ct) {
+ static const uint8_t gSize[] = {
+ 1, // Alpha_8
+ 2, // RGB_565
+ 4, // RGBA_8888
+ 4, // BGRA_8888
+ 1, // kIndex_8
+ };
+ SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1),
+ size_mismatch_with_SkColorType_enum);
+
+ SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize));
+ return gSize[ct];
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Describe an image's dimensions and pixel type.
+ */
+struct SkImageInfo {
+ int fWidth;
+ int fHeight;
+ SkColorType fColorType;
+ SkAlphaType fAlphaType;
+
+ bool isOpaque() const {
+ return SkAlphaTypeIsOpaque(fAlphaType);
+ }
+
+ int bytesPerPixel() const {
+ return SkColorTypeBytesPerPixel(fColorType);
+ }
+
+ bool operator==(const SkImageInfo& other) const {
+ return 0 == memcmp(this, &other, sizeof(other));
+ }
+ bool operator!=(const SkImageInfo& other) const {
+ return 0 != memcmp(this, &other, sizeof(other));
+ }
+};
+
+#endif