michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: #include "SkSnapshot.h" michael@0: #include "SkAnimateMaker.h" michael@0: #include "SkCanvas.h" michael@0: #include "SkImageEncoder.h" michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkSnapshot::fInfo[] = { michael@0: SK_MEMBER(filename, String), michael@0: SK_MEMBER(quality, Float), michael@0: SK_MEMBER(sequence, Boolean), michael@0: SK_MEMBER(type, BitmapEncoding) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkSnapshot); michael@0: michael@0: SkSnapshot::SkSnapshot() michael@0: { michael@0: quality = 100 * SK_Scalar1; michael@0: type = (SkImageEncoder::Type) -1; michael@0: sequence = false; michael@0: fSeqVal = 0; michael@0: } michael@0: michael@0: #include "SkDevice.h" michael@0: michael@0: bool SkSnapshot::draw(SkAnimateMaker& maker) { michael@0: SkASSERT(type >= 0); michael@0: SkASSERT(filename.size() > 0); michael@0: SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type); michael@0: if (!encoder) { michael@0: return false; michael@0: } michael@0: SkAutoTDelete ad(encoder); michael@0: michael@0: SkString name(filename); michael@0: if (sequence) { michael@0: char num[4] = "000"; michael@0: num[0] = (char) (num[0] + fSeqVal / 100); michael@0: num[1] = (char) (num[1] + fSeqVal / 10 % 10); michael@0: num[2] = (char) (num[2] + fSeqVal % 10); michael@0: name.append(num); michael@0: if (++fSeqVal > 999) michael@0: sequence = false; michael@0: } michael@0: if (type == SkImageEncoder::kJPEG_Type) michael@0: name.append(".jpg"); michael@0: else if (type == SkImageEncoder::kPNG_Type) michael@0: name.append(".png"); michael@0: encoder->encodeFile(name.c_str(), michael@0: maker.fCanvas->getDevice()->accessBitmap(false), michael@0: SkScalarFloorToInt(quality)); michael@0: return false; michael@0: }