michael@0: /* michael@0: * Copyright 2010 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkImageInfo.h" michael@0: #include "SkReadBuffer.h" michael@0: #include "SkWriteBuffer.h" michael@0: michael@0: static bool alpha_type_is_valid(SkAlphaType alphaType) { michael@0: return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); michael@0: } michael@0: michael@0: static bool color_type_is_valid(SkColorType colorType) { michael@0: return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); michael@0: } michael@0: michael@0: void SkImageInfo::unflatten(SkReadBuffer& buffer) { michael@0: fWidth = buffer.read32(); michael@0: fHeight = buffer.read32(); michael@0: michael@0: uint32_t packed = buffer.read32(); michael@0: SkASSERT(0 == (packed >> 16)); michael@0: fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); michael@0: fColorType = (SkColorType)((packed >> 0) & 0xFF); michael@0: buffer.validate(alpha_type_is_valid(fAlphaType) && michael@0: color_type_is_valid(fColorType)); michael@0: } michael@0: michael@0: void SkImageInfo::flatten(SkWriteBuffer& buffer) const { michael@0: buffer.write32(fWidth); michael@0: buffer.write32(fHeight); michael@0: michael@0: SkASSERT(0 == (fAlphaType & ~0xFF)); michael@0: SkASSERT(0 == (fColorType & ~0xFF)); michael@0: uint32_t packed = (fAlphaType << 8) | fColorType; michael@0: buffer.write32(packed); michael@0: }