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

Side by Side Diff: src/core/SkOrderedReadBuffer.cpp

Issue 15713015: Read and write pixel offset when serializing bitmaps. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/core/SkOrderedWriteBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkErrorInternals.h" 10 #include "SkErrorInternals.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // fall through to use a place holder bitmap. 185 // fall through to use a place holder bitmap.
186 SkErrorInternals::SetError(kParseError_SkError, "SkOrderedWriteBuffe r::writeBitmap " 186 SkErrorInternals::SetError(kParseError_SkError, "SkOrderedWriteBuffe r::writeBitmap "
187 "stored the SkBitmap in an SkBitmapHeap, but " 187 "stored the SkBitmap in an SkBitmapHeap, but "
188 "SkOrderedReadBuffer has no SkBitmapHeapR eader to " 188 "SkOrderedReadBuffer has no SkBitmapHeapR eader to "
189 "retrieve the SkBitmap."); 189 "retrieve the SkBitmap.");
190 } 190 }
191 } else { 191 } else {
192 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap. 192 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap.
193 const size_t length = this->readUInt(); 193 const size_t length = this->readUInt();
194 if (length > 0) { 194 if (length > 0) {
195 // A non-zero size means the SkBitmap was encoded. 195 // A non-zero size means the SkBitmap was encoded. Read the data and pixel
196 // offset.
196 const void* data = this->skip(length); 197 const void* data = this->skip(length);
198 const int32_t xOffset = fReader.readS32();
199 const int32_t yOffset = fReader.readS32();
197 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) { 200 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) {
198 if (bitmap->width() == width && bitmap->height() == height) { 201 if (bitmap->width() == width && bitmap->height() == height) {
202 // If the width and height match, there should be no offset.
203 SkASSERT(0 == xOffset && 0 == yOffset);
199 return; 204 return;
200 } 205 }
201 206
202 // This case can only be reached if extractSubset was called, so 207 // This case can only be reached if extractSubset was called, so
203 // the recorded width and height must be smaller than (or equal to 208 // the recorded width and height must be smaller than (or equal to
204 // the encoded width and height. 209 // the encoded width and height.
205 SkASSERT(width <= bitmap->width() && height <= bitmap->height()) ; 210 SkASSERT(width <= bitmap->width() && height <= bitmap->height()) ;
206 211
207 // FIXME: Once the writer is changed to record the (x,y) offset,
208 // they will be used to store the correct portion of the picture .
209 SkBitmap subsetBm; 212 SkBitmap subsetBm;
210 #ifdef BUMP_PICTURE_VERSION 213 SkIRect subset = SkIRect::MakeXYWH(xOffset, yOffset, width, heig ht);
211 int32_t x = fReader.readS32();
212 int32_t y = fReader.readS32();
213 SkIRect subset = SkIRect::MakeXYWH(x, y, width, height);
214 #else
215 SkIRect subset = SkIRect::MakeWH(width, height);
216 #endif
217 if (bitmap->extractSubset(&subsetBm, subset)) { 214 if (bitmap->extractSubset(&subsetBm, subset)) {
218 bitmap->swap(subsetBm); 215 bitmap->swap(subsetBm);
219 return; 216 return;
220 } 217 }
221 } 218 }
222 // This bitmap was encoded when written, but we are unable to decode , possibly due to 219 // This bitmap was encoded when written, but we are unable to decode , possibly due to
223 // not having a decoder. 220 // not having a decoder.
224 SkErrorInternals::SetError(kParseError_SkError, 221 SkErrorInternals::SetError(kParseError_SkError,
225 "Could not decode bitmap. Resulting bitma p will be red."); 222 "Could not decode bitmap. Resulting bitma p will be red.");
226 } else { 223 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (sizeRecorded != sizeRead) { 283 if (sizeRecorded != sizeRead) {
287 // we could try to fix up the offset... 284 // we could try to fix up the offset...
288 sk_throw(); 285 sk_throw();
289 } 286 }
290 } else { 287 } else {
291 // we must skip the remaining data 288 // we must skip the remaining data
292 fReader.skip(sizeRecorded); 289 fReader.skip(sizeRecorded);
293 } 290 }
294 return obj; 291 return obj;
295 } 292 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkOrderedWriteBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698