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

Side by Side Diff: src/codec/SkCodec.cpp

Issue 930283002: Add SkCodec, including PNG implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Check in prebuilt file directly Created 5 years, 9 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
« no previous file with comments | « include/codec/SkCodec.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 "SkCodec.h"
9 #include "SkData.h"
10 #include "SkCodec_libpng.h"
11 #include "SkStream.h"
12
13 SkCodec* SkCodec::NewFromStream(SkStream* stream) {
14 if (!stream) {
15 return NULL;
16 }
17 SkAutoTDelete<SkStream> streamDeleter(stream);
18 const bool isPng = SkPngCodec::IsPng(stream);
19 // TODO: Avoid rewinding.
20 if (!stream->rewind()) {
21 return NULL;
22 }
23 if (isPng) {
24 streamDeleter.detach();
25 return SkPngCodec::NewFromStream(stream);
26 }
27 // TODO: Check other image types.
28 return NULL;
29 }
30
31 SkCodec* SkCodec::NewFromData(SkData* data) {
32 if (!data) {
33 return NULL;
34 }
35 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data)));
36 }
37
38 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
39 : fInfo(info)
40 , fStream(stream)
41 , fNeedsRewind(false)
42 {}
43
44 bool SkCodec::rewindIfNeeded() {
45 // Store the value of fNeedsRewind so we can update it. Next read will
46 // require a rewind.
47 const bool neededRewind = fNeedsRewind;
48 fNeedsRewind = true;
49 return !neededRewind || fStream->rewind();
50 }
OLDNEW
« no previous file with comments | « include/codec/SkCodec.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698