1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h" 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSnapshot.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAnimateMaker.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h" 150f0cfaecf2c52e5fcb033c43df06f07a81c7b0c2reed@android.com#include "SkImageEncoder.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if SK_USE_CONDENSED_INFO == 0 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkMemberInfo SkSnapshot::fInfo[] = { 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SK_MEMBER(filename, String), 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SK_MEMBER(quality, Float), 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SK_MEMBER(sequence, Boolean), 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SK_MEMBER(type, BitmapEncoding) 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comDEFINE_GET_MEMBER(SkSnapshot); 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkSnapshot::SkSnapshot() 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com quality = 100 * SK_Scalar1; 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com type = (SkImageEncoder::Type) -1; 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sequence = false; 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fSeqVal = 0; 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDevice.h" 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkSnapshot::draw(SkAnimateMaker& maker) { 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(type >= 0); 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(filename.size() > 0); 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkImageEncoder* encoder = SkImageEncoder::Create((SkImageEncoder::Type) type); 447def5e1630d47cdbfa4b58a9c86bc060693c4d79scroggo@google.com if (!encoder) { 457def5e1630d47cdbfa4b58a9c86bc060693c4d79scroggo@google.com return false; 467def5e1630d47cdbfa4b58a9c86bc060693c4d79scroggo@google.com } 477def5e1630d47cdbfa4b58a9c86bc060693c4d79scroggo@google.com SkAutoTDelete<SkImageEncoder> ad(encoder); 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkString name(filename); 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (sequence) { 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com char num[4] = "000"; 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com num[0] = (char) (num[0] + fSeqVal / 100); 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com num[1] = (char) (num[1] + fSeqVal / 10 % 10); 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com num[2] = (char) (num[2] + fSeqVal % 10); 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com name.append(num); 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (++fSeqVal > 999) 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sequence = false; 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (type == SkImageEncoder::kJPEG_Type) 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com name.append(".jpg"); 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com else if (type == SkImageEncoder::kPNG_Type) 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com name.append(".png"); 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com encoder->encodeFile(name.c_str(), 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com maker.fCanvas->getDevice()->accessBitmap(false), 65e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com SkScalarFloorToInt(quality)); 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 68