OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 | 9 |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
11 | 11 |
| 12 #include "SkEncodedFormat.h" |
12 #include "SkSnapshot.h" | 13 #include "SkSnapshot.h" |
13 #include "SkAnimateMaker.h" | 14 #include "SkAnimateMaker.h" |
14 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
15 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
16 | 17 |
17 #if SK_USE_CONDENSED_INFO == 0 | 18 #if SK_USE_CONDENSED_INFO == 0 |
18 | 19 |
19 const SkMemberInfo SkSnapshot::fInfo[] = { | 20 const SkMemberInfo SkSnapshot::fInfo[] = { |
20 SK_MEMBER(filename, String), | 21 SK_MEMBER(filename, String), |
21 SK_MEMBER(quality, Float), | 22 SK_MEMBER(quality, Float), |
22 SK_MEMBER(sequence, Boolean), | 23 SK_MEMBER(sequence, Boolean), |
23 SK_MEMBER(type, BitmapEncoding) | 24 SK_MEMBER(type, BitmapEncoding) |
24 }; | 25 }; |
25 | 26 |
26 #endif | 27 #endif |
27 | 28 |
28 DEFINE_GET_MEMBER(SkSnapshot); | 29 DEFINE_GET_MEMBER(SkSnapshot); |
29 | 30 |
30 SkSnapshot::SkSnapshot() | 31 SkSnapshot::SkSnapshot() |
31 { | 32 { |
32 quality = 100 * SK_Scalar1; | 33 quality = 100 * SK_Scalar1; |
33 type = (SkImageEncoder::Type) -1; | 34 type = (SkEncodedFormat) -1; |
34 sequence = false; | 35 sequence = false; |
35 fSeqVal = 0; | 36 fSeqVal = 0; |
36 } | 37 } |
37 | 38 |
38 #include "SkDevice.h" | 39 #include "SkDevice.h" |
39 | 40 |
40 bool SkSnapshot::draw(SkAnimateMaker& maker) { | 41 bool SkSnapshot::draw(SkAnimateMaker& maker) { |
41 SkASSERT(type >= 0); | 42 SkASSERT(type >= 0); |
42 SkASSERT(filename.size() > 0); | 43 SkASSERT(filename.size() > 0); |
43 SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type
); | 44 SkImageEncoder* encoder = SkImageEncoder::Create((SkEncodedFormat) type); |
44 if (!encoder) { | 45 if (!encoder) { |
45 return false; | 46 return false; |
46 } | 47 } |
47 SkAutoTDelete<SkImageEncoder> ad(encoder); | 48 SkAutoTDelete<SkImageEncoder> ad(encoder); |
48 | 49 |
49 SkString name(filename); | 50 SkString name(filename); |
50 if (sequence) { | 51 if (sequence) { |
51 char num[4] = "000"; | 52 char num[4] = "000"; |
52 num[0] = (char) (num[0] + fSeqVal / 100); | 53 num[0] = (char) (num[0] + fSeqVal / 100); |
53 num[1] = (char) (num[1] + fSeqVal / 10 % 10); | 54 num[1] = (char) (num[1] + fSeqVal / 10 % 10); |
54 num[2] = (char) (num[2] + fSeqVal % 10); | 55 num[2] = (char) (num[2] + fSeqVal % 10); |
55 name.append(num); | 56 name.append(num); |
56 if (++fSeqVal > 999) | 57 if (++fSeqVal > 999) |
57 sequence = false; | 58 sequence = false; |
58 } | 59 } |
59 if (type == SkImageEncoder::kJPEG_Type) | 60 if (type == kJPEG_SkEncodedFormat) |
60 name.append(".jpg"); | 61 name.append(".jpg"); |
61 else if (type == SkImageEncoder::kPNG_Type) | 62 else if (type == kPNG_SkEncodedFormat) |
62 name.append(".png"); | 63 name.append(".png"); |
63 | 64 |
64 SkBitmap pixels; | 65 SkBitmap pixels; |
65 pixels.allocPixels(maker.fCanvas->imageInfo()); | 66 pixels.allocPixels(maker.fCanvas->imageInfo()); |
66 maker.fCanvas->readPixels(&pixels, 0, 0); | 67 maker.fCanvas->readPixels(&pixels, 0, 0); |
67 encoder->encodeFile(name.c_str(), pixels, SkScalarFloorToInt(quality)); | 68 encoder->encodeFile(name.c_str(), pixels, SkScalarFloorToInt(quality)); |
68 return false; | 69 return false; |
69 } | 70 } |
OLD | NEW |