1 /* libs/graphics/animator/SkSnapshot.cpp
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #include "SkTypes.h"
19
20 #include "SkSnapshot.h"
21 #include "SkAnimateMaker.h"
22 #include "SkCanvas.h"
23 #include "SkImageEncoder.h"
24
25 #if SK_USE_CONDENSED_INFO == 0
26
27 const SkMemberInfo SkSnapshot::fInfo[] = {
28 SK_MEMBER(filename, String),
29 SK_MEMBER(quality, Float),
30 SK_MEMBER(sequence, Boolean),
31 SK_MEMBER(type, BitmapEncoding)
32 };
33
34 #endif
35
36 DEFINE_GET_MEMBER(SkSnapshot);
37
SkSnapshot()38 SkSnapshot::SkSnapshot()
39 {
40 quality = 100 * SK_Scalar1;
41 type = (SkImageEncoder::Type) -1;
42 sequence = false;
43 fSeqVal = 0;
44 }
45
46 #include "SkDevice.h"
47
draw(SkAnimateMaker & maker)48 bool SkSnapshot::draw(SkAnimateMaker& maker) {
49 SkASSERT(type >= 0);
50 SkASSERT(filename.size() > 0);
51 SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type);
52
53 SkString name(filename);
54 if (sequence) {
55 char num[4] = "000";
56 num[0] = (char) (num[0] + fSeqVal / 100);
57 num[1] = (char) (num[1] + fSeqVal / 10 % 10);
58 num[2] = (char) (num[2] + fSeqVal % 10);
59 name.append(num);
60 if (++fSeqVal > 999)
61 sequence = false;
62 }
63 if (type == SkImageEncoder::kJPEG_Type)
64 name.append(".jpg");
65 else if (type == SkImageEncoder::kPNG_Type)
66 name.append(".png");
67 encoder->encodeFile(name.c_str(),
68 maker.fCanvas->getDevice()->accessBitmap(false),
69 SkScalarFloor(quality));
70 return false;
71 }
72
73