• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #include "SkTypes.h"
11 
12 #include "SkSnapshot.h"
13 #include "SkAnimateMaker.h"
14 #include "SkCanvas.h"
15 #include "SkImageEncoder.h"
16 
17 #if SK_USE_CONDENSED_INFO == 0
18 
19 const SkMemberInfo SkSnapshot::fInfo[] = {
20     SK_MEMBER(filename, String),
21     SK_MEMBER(quality, Float),
22     SK_MEMBER(sequence, Boolean),
23     SK_MEMBER(type, BitmapEncoding)
24 };
25 
26 #endif
27 
28 DEFINE_GET_MEMBER(SkSnapshot);
29 
SkSnapshot()30 SkSnapshot::SkSnapshot()
31 {
32     quality     = 100 * SK_Scalar1;
33     type        = (SkImageEncoder::Type) -1;
34     sequence    = false;
35     fSeqVal     = 0;
36 }
37 
38 #include "SkDevice.h"
39 
draw(SkAnimateMaker & maker)40 bool SkSnapshot::draw(SkAnimateMaker& maker) {
41     SkASSERT(type >= 0);
42     SkASSERT(filename.size() > 0);
43     SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type);
44 
45     SkString name(filename);
46     if (sequence) {
47         char num[4] = "000";
48         num[0] = (char) (num[0] + fSeqVal / 100);
49         num[1] = (char) (num[1] + fSeqVal / 10 % 10);
50         num[2] = (char) (num[2] + fSeqVal % 10);
51         name.append(num);
52         if (++fSeqVal > 999)
53             sequence = false;
54     }
55     if (type == SkImageEncoder::kJPEG_Type)
56         name.append(".jpg");
57     else if (type == SkImageEncoder::kPNG_Type)
58         name.append(".png");
59     encoder->encodeFile(name.c_str(),
60                         maker.fCanvas->getDevice()->accessBitmap(false),
61                         SkScalarFloor(quality));
62     return false;
63 }
64 
65