• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #if SK_USE_CONDENSED_INFO == 0
25 
26 const SkMemberInfo SkSnapshot::fInfo[] = {
27     SK_MEMBER(filename, String),
28     SK_MEMBER(quality, Float),
29     SK_MEMBER(sequence, Boolean),
30     SK_MEMBER(type, BitmapEncoding)
31 };
32 
33 #endif
34 
35 DEFINE_GET_MEMBER(SkSnapshot);
36 
SkSnapshot()37 SkSnapshot::SkSnapshot()
38 {
39     quality     = 100 * SK_Scalar1;
40     type        = (SkImageEncoder::Type) -1;
41     sequence    = false;
42     fSeqVal     = 0;
43 }
44 
45 #include "SkDevice.h"
46 
draw(SkAnimateMaker & maker)47 bool SkSnapshot::draw(SkAnimateMaker& maker) {
48     SkASSERT(type >= 0);
49     SkASSERT(filename.size() > 0);
50     SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type);
51 
52     SkString name(filename);
53     if (sequence) {
54         char num[4] = "000";
55         num[0] = (char) (num[0] + fSeqVal / 100);
56         num[1] = (char) (num[1] + fSeqVal / 10 % 10);
57         num[2] = (char) (num[2] + fSeqVal % 10);
58         name.append(num);
59         if (++fSeqVal > 999)
60             sequence = false;
61     }
62     if (type == SkImageEncoder::kJPEG_Type)
63         name.append(".jpg");
64     else if (type == SkImageEncoder::kPNG_Type)
65         name.append(".png");
66     encoder->encodeFile(name.c_str(),
67                         maker.fCanvas->getDevice()->accessBitmap(false),
68                         SkScalarFloor(quality));
69     return false;
70 }
71 
72