Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Unified Diff: src/codec/SkCodecPriv.h

Issue 1016443003: Revert "Revert of fix for invalid for loop syntax broke build (patchset #1 id:1 of https://coderevi… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | src/codec/SkCodec_libbmp.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodecPriv.h
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
new file mode 100644
index 0000000000000000000000000000000000000000..a0e5c9490038c500e873d344a5b1bbd3f407383f
--- /dev/null
+++ b/src/codec/SkCodecPriv.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkCodecPriv_DEFINED
+#define SkCodecPriv_DEFINED
+
+#include "SkImageInfo.h"
+#include "SkSwizzler.h"
+#include "SkTypes.h"
+
+/*
+ *
+ * Helper routine for alpha result codes
+ *
+ */
+#define INIT_RESULT_ALPHA \
+ uint8_t zeroAlpha = 0; \
+ uint8_t maxAlpha = 0xFF;
+
+#define UPDATE_RESULT_ALPHA(alpha) \
+ zeroAlpha |= (alpha); \
+ maxAlpha &= (alpha);
+
+#define COMPUTE_RESULT_ALPHA \
+ SkSwizzler::GetResult(zeroAlpha, maxAlpha);
+
+/*
+ *
+ * Compute row bytes for an image using pixels per byte
+ *
+ */
+static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) {
+ return (width + pixelsPerByte - 1) / pixelsPerByte;
+}
+
+/*
+ *
+ * Compute row bytes for an image using bytes per pixel
+ *
+ */
+static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) {
+ return width * bytesPerPixel;
+}
+
+/*
+ *
+ * Compute row bytes for an image
+ *
+ */
+static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) {
+ if (bitsPerPixel < 16) {
+ SkASSERT(0 == 8 % bitsPerPixel);
+ const uint32_t pixelsPerByte = 8 / bitsPerPixel;
+ return compute_row_bytes_ppb(width, pixelsPerByte);
+ } else {
+ SkASSERT(0 == bitsPerPixel % 8);
+ const uint32_t bytesPerPixel = bitsPerPixel / 8;
+ return compute_row_bytes_bpp(width, bytesPerPixel);
+ }
+}
+
+/*
+ *
+ * Checks if alpha types are premul and unpremul
+ *
+ */
+static inline bool premul_and_unpremul(SkAlphaType dst, SkAlphaType src) {
+ return kPremul_SkAlphaType == dst && kUnpremul_SkAlphaType == src;
+}
+
+/*
+ *
+ * Get a byte from a buffer
+ * This method is unsafe, the caller is responsible for performing a check
+ *
+ */
+static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) {
+ return buffer[i];
+}
+
+/*
+ *
+ * Get a short from a buffer
+ * This method is unsafe, the caller is responsible for performing a check
+ *
+ */
+static inline uint16_t get_short(uint8_t* buffer, uint32_t i) {
+ uint16_t result;
+ memcpy(&result, &(buffer[i]), 2);
+#ifdef SK_CPU_BENDIAN
+ return SkEndianSwap16(result);
+#else
+ return result;
+#endif
+}
+
+/*
+ *
+ * Get an int from a buffer
+ * This method is unsafe, the caller is responsible for performing a check
+ *
+ */
+static inline uint32_t get_int(uint8_t* buffer, uint32_t i) {
+ uint32_t result;
+ memcpy(&result, &(buffer[i]), 4);
+#ifdef SK_CPU_BENDIAN
+ return SkEndianSwap32(result);
+#else
+ return result;
+#endif
+}
+
+#endif // SkCodecPriv_DEFINED
« no previous file with comments | « src/codec/SkCodec.cpp ('k') | src/codec/SkCodec_libbmp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698