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