OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkAtomics.h" | 8 #include "SkAtomics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 } | 1093 } |
1094 | 1094 |
1095 /////////////////////////////////////////////////////////////////////////////// | 1095 /////////////////////////////////////////////////////////////////////////////// |
1096 | 1096 |
1097 static void write_raw_pixels(SkWriteBuffer* buffer, const SkPixmap& pmap) { | 1097 static void write_raw_pixels(SkWriteBuffer* buffer, const SkPixmap& pmap) { |
1098 const SkImageInfo& info = pmap.info(); | 1098 const SkImageInfo& info = pmap.info(); |
1099 const size_t snugRB = info.width() * info.bytesPerPixel(); | 1099 const size_t snugRB = info.width() * info.bytesPerPixel(); |
1100 const char* src = (const char*)pmap.addr(); | 1100 const char* src = (const char*)pmap.addr(); |
1101 const size_t ramRB = pmap.rowBytes(); | 1101 const size_t ramRB = pmap.rowBytes(); |
1102 | 1102 |
1103 buffer->write32(SkToU32(snugRB)); | 1103 buffer->write32("snugRB", SkToU32(snugRB)); |
1104 info.flatten(*buffer); | 1104 info.flatten(*buffer); |
1105 | 1105 |
1106 const size_t size = snugRB * info.height(); | 1106 const size_t size = snugRB * info.height(); |
1107 SkAutoTMalloc<char> storage(size); | 1107 SkAutoTMalloc<char> storage(size); |
1108 char* dst = storage.get(); | 1108 char* dst = storage.get(); |
1109 for (int y = 0; y < info.height(); ++y) { | 1109 for (int y = 0; y < info.height(); ++y) { |
1110 memcpy(dst, src, snugRB); | 1110 memcpy(dst, src, snugRB); |
1111 dst += snugRB; | 1111 dst += snugRB; |
1112 src += ramRB; | 1112 src += ramRB; |
1113 } | 1113 } |
1114 buffer->writeByteArray(storage.get(), size); | 1114 buffer->writeByteArray("storage", storage.get(), size); |
1115 | 1115 |
1116 const SkColorTable* ct = pmap.ctable(); | 1116 const SkColorTable* ct = pmap.ctable(); |
1117 if (kIndex_8_SkColorType == info.colorType() && ct) { | 1117 if (kIndex_8_SkColorType == info.colorType() && ct) { |
1118 buffer->writeBool(true); | 1118 buffer->writeBool("hasColorTable", true); |
1119 ct->writeToBuffer(*buffer); | 1119 ct->writeToBuffer(*buffer); |
1120 } else { | 1120 } else { |
1121 buffer->writeBool(false); | 1121 buffer->writeBool("hasColorTable", false); |
1122 } | 1122 } |
1123 } | 1123 } |
1124 | 1124 |
1125 void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) { | 1125 void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) { |
1126 const SkImageInfo info = bitmap.info(); | 1126 const SkImageInfo info = bitmap.info(); |
1127 if (0 == info.width() || 0 == info.height() || nullptr == bitmap.pixelRef())
{ | 1127 if (0 == info.width() || 0 == info.height() || nullptr == bitmap.pixelRef())
{ |
1128 buffer->writeUInt(0); // instead of snugRB, signaling no pixels | 1128 buffer->writeUInt("snugRB", 0); // instead of snugRB, signaling no pixel
s |
1129 return; | 1129 return; |
1130 } | 1130 } |
1131 | 1131 |
1132 SkAutoPixmapUnlock result; | 1132 SkAutoPixmapUnlock result; |
1133 if (!bitmap.requestLock(&result)) { | 1133 if (!bitmap.requestLock(&result)) { |
1134 buffer->writeUInt(0); // instead of snugRB, signaling no pixels | 1134 buffer->writeUInt("snugRB", 0); // instead of snugRB, signaling no pixel
s |
1135 return; | 1135 return; |
1136 } | 1136 } |
1137 | 1137 |
1138 write_raw_pixels(buffer, result.pixmap()); | 1138 write_raw_pixels(buffer, result.pixmap()); |
1139 } | 1139 } |
1140 | 1140 |
1141 bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { | 1141 bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) { |
1142 const size_t snugRB = buffer->readUInt(); | 1142 const size_t snugRB = buffer->readUInt(); |
1143 if (0 == snugRB) { // no pixels | 1143 if (0 == snugRB) { // no pixels |
1144 return false; | 1144 return false; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 /////////////////////////////////////////////////////////////////////////////// | 1349 /////////////////////////////////////////////////////////////////////////////// |
1350 | 1350 |
1351 #ifdef SK_DEBUG | 1351 #ifdef SK_DEBUG |
1352 void SkImageInfo::validate() const { | 1352 void SkImageInfo::validate() const { |
1353 SkASSERT(fWidth >= 0); | 1353 SkASSERT(fWidth >= 0); |
1354 SkASSERT(fHeight >= 0); | 1354 SkASSERT(fHeight >= 0); |
1355 SkASSERT(SkColorTypeIsValid(fColorType)); | 1355 SkASSERT(SkColorTypeIsValid(fColorType)); |
1356 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1356 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1357 } | 1357 } |
1358 #endif | 1358 #endif |
OLD | NEW |