1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/animator/SkSnapshot.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkTypes.h" 1.14 + 1.15 +#include "SkSnapshot.h" 1.16 +#include "SkAnimateMaker.h" 1.17 +#include "SkCanvas.h" 1.18 +#include "SkImageEncoder.h" 1.19 + 1.20 +#if SK_USE_CONDENSED_INFO == 0 1.21 + 1.22 +const SkMemberInfo SkSnapshot::fInfo[] = { 1.23 + SK_MEMBER(filename, String), 1.24 + SK_MEMBER(quality, Float), 1.25 + SK_MEMBER(sequence, Boolean), 1.26 + SK_MEMBER(type, BitmapEncoding) 1.27 +}; 1.28 + 1.29 +#endif 1.30 + 1.31 +DEFINE_GET_MEMBER(SkSnapshot); 1.32 + 1.33 +SkSnapshot::SkSnapshot() 1.34 +{ 1.35 + quality = 100 * SK_Scalar1; 1.36 + type = (SkImageEncoder::Type) -1; 1.37 + sequence = false; 1.38 + fSeqVal = 0; 1.39 +} 1.40 + 1.41 +#include "SkDevice.h" 1.42 + 1.43 +bool SkSnapshot::draw(SkAnimateMaker& maker) { 1.44 + SkASSERT(type >= 0); 1.45 + SkASSERT(filename.size() > 0); 1.46 + SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type); 1.47 + if (!encoder) { 1.48 + return false; 1.49 + } 1.50 + SkAutoTDelete<SkImageEncoder> ad(encoder); 1.51 + 1.52 + SkString name(filename); 1.53 + if (sequence) { 1.54 + char num[4] = "000"; 1.55 + num[0] = (char) (num[0] + fSeqVal / 100); 1.56 + num[1] = (char) (num[1] + fSeqVal / 10 % 10); 1.57 + num[2] = (char) (num[2] + fSeqVal % 10); 1.58 + name.append(num); 1.59 + if (++fSeqVal > 999) 1.60 + sequence = false; 1.61 + } 1.62 + if (type == SkImageEncoder::kJPEG_Type) 1.63 + name.append(".jpg"); 1.64 + else if (type == SkImageEncoder::kPNG_Type) 1.65 + name.append(".png"); 1.66 + encoder->encodeFile(name.c_str(), 1.67 + maker.fCanvas->getDevice()->accessBitmap(false), 1.68 + SkScalarFloorToInt(quality)); 1.69 + return false; 1.70 +}