1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkImageInfo.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,40 @@ 1.4 +/* 1.5 + * Copyright 2010 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "SkImageInfo.h" 1.12 +#include "SkReadBuffer.h" 1.13 +#include "SkWriteBuffer.h" 1.14 + 1.15 +static bool alpha_type_is_valid(SkAlphaType alphaType) { 1.16 + return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); 1.17 +} 1.18 + 1.19 +static bool color_type_is_valid(SkColorType colorType) { 1.20 + return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); 1.21 +} 1.22 + 1.23 +void SkImageInfo::unflatten(SkReadBuffer& buffer) { 1.24 + fWidth = buffer.read32(); 1.25 + fHeight = buffer.read32(); 1.26 + 1.27 + uint32_t packed = buffer.read32(); 1.28 + SkASSERT(0 == (packed >> 16)); 1.29 + fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); 1.30 + fColorType = (SkColorType)((packed >> 0) & 0xFF); 1.31 + buffer.validate(alpha_type_is_valid(fAlphaType) && 1.32 + color_type_is_valid(fColorType)); 1.33 +} 1.34 + 1.35 +void SkImageInfo::flatten(SkWriteBuffer& buffer) const { 1.36 + buffer.write32(fWidth); 1.37 + buffer.write32(fHeight); 1.38 + 1.39 + SkASSERT(0 == (fAlphaType & ~0xFF)); 1.40 + SkASSERT(0 == (fColorType & ~0xFF)); 1.41 + uint32_t packed = (fAlphaType << 8) | fColorType; 1.42 + buffer.write32(packed); 1.43 +}