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

Side by Side Diff: tools/SkMultiPictureDocumentReader.cpp

Issue 2023593002: SkMultiPictureDocument & SkMultiPictureDocumentReader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkMultiPictureDocumentPriv.h"
9 #include "SkMultiPictureDocumentReader.h"
10 #include "SkPicture.h"
11 #include "SkStream.h"
12
13 bool SkMultiPictureDocumentReader::init(SkStreamSeekable* stream) {
14 stream->seek(0);
15 const size_t size = sizeof(SkMultiPictureDocumentProtocol::kMagic) - 1;
16 char buffer[size];
17 if (size != stream->read(buffer, size) ||
18 0 != memcmp(SkMultiPictureDocumentProtocol::kMagic, buffer, size)) {
19 stream = nullptr;
20 return false;
21 }
22 bool good = true;
23 uint32_t versionNumber = stream->readU32();
24 if (versionNumber != 1) {
25 return false;
26 }
27 uint32_t pageCount = stream->readU32();
28 fSizes.reset(pageCount);
29 fOffsets.reset(pageCount);
30 for (uint32_t i = 0; i < pageCount; ++i) {
31 SkMultiPictureDocumentProtocol::Entry entry;
32 good &= sizeof(entry) == stream->read(&entry, sizeof(entry));
33 fSizes[i] = SkSize::Make(entry.sizeX, entry.sizeY);
34 good &= SkTFitsIn<size_t>(entry.offset);
35 fOffsets[i] = static_cast<size_t>(entry.offset);
36 }
37 return good;
38 }
39
40 sk_sp<SkPicture> SkMultiPictureDocumentReader::readPage(SkStreamSeekable* stream ,
41 int pageNumber) const {
42 SkASSERT(pageNumber >= 0);
43 SkASSERT(pageNumber < fOffsets.count());
44 SkAssertResult(stream->seek(fOffsets[pageNumber]));
45 return SkPicture::MakeFromStream(stream);
46 }
OLDNEW
« src/core/SkMultiPictureDocument.cpp ('K') | « tools/SkMultiPictureDocumentReader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698