Merge branch 'master'

This commit is contained in:
David Capello 2015-12-22 10:56:56 -03:00
commit e8ecbbb4d7
8 changed files with 118 additions and 86 deletions

View File

@ -28,7 +28,7 @@ Cmd::~Cmd()
void Cmd::execute(Context* ctx)
{
DLOG("Cmd: Executing cmd '%s'\n", typeid(*this).name());
TRACE("Cmd: Executing cmd '%s'\n", typeid(*this).name());
ASSERT(m_state == State::NotExecuted);
m_ctx = ctx;
@ -43,7 +43,7 @@ void Cmd::execute(Context* ctx)
void Cmd::undo()
{
DLOG("Cmd: Undo cmd '%s'\n", typeid(*this).name());
TRACE("Cmd: Undo cmd '%s'\n", typeid(*this).name());
ASSERT(m_state == State::Executed || m_state == State::Redone);
onUndo();
@ -56,7 +56,7 @@ void Cmd::undo()
void Cmd::redo()
{
DLOG("Cmd: Redo cmd '%s'\n", typeid(*this).name());
TRACE("Cmd: Redo cmd '%s'\n", typeid(*this).name());
ASSERT(m_state == State::Undone);
onRedo();

View File

@ -189,10 +189,10 @@ public:
, m_remap(256)
, m_hasLocalColormaps(false)
, m_firstLocalColormap(nullptr) {
DLOG("[GifDecoder] GIF background index=%d\n", (int)m_gifFile->SBackGroundColor);
DLOG("[GifDecoder] GIF global colormap=%d, ncolors=%d\n",
(m_gifFile->SColorMap ? 1: 0),
(m_gifFile->SColorMap ? m_gifFile->SColorMap->ColorCount: 0));
TRACE("[GifDecoder] GIF background index=%d\n", (int)m_gifFile->SBackGroundColor);
TRACE("[GifDecoder] GIF global colormap=%d, ncolors=%d\n",
(m_gifFile->SColorMap ? 1: 0),
(m_gifFile->SColorMap ? m_gifFile->SColorMap->ColorCount: 0));
}
~GifDecoder() {
@ -310,7 +310,7 @@ private:
UniquePtr<Image> frameImage(
readFrameIndexedImage(frameBounds));
DLOG("[GifDecoder] Frame[%d] transparent index = %d\n", (int)m_frameNum, m_localTransparentIndex);
TRACE("[GifDecoder] Frame[%d] transparent index = %d\n", (int)m_frameNum, m_localTransparentIndex);
if (m_frameNum == 0) {
if (m_localTransparentIndex >= 0)
@ -325,8 +325,8 @@ private:
// Convert the sprite to RGB if we have more than 256 colors
if ((m_sprite->pixelFormat() == IMAGE_INDEXED) &&
(m_sprite->palette(m_frameNum)->size() > 256)) {
DLOG("[GifDecoder] Converting to RGB because we have %d colors\n",
m_sprite->palette(m_frameNum)->size());
TRACE("[GifDecoder] Converting to RGB because we have %d colors\n",
m_sprite->palette(m_frameNum)->size());
convertIndexedSpriteToRgb();
}
@ -444,7 +444,7 @@ private:
int ncolors = colormap->ColorCount;
bool isLocalColormap = (m_gifFile->Image.ColorMap ? true: false);
DLOG("[GifDecoder] Local colormap=%d, ncolors=%d\n", isLocalColormap, ncolors);
TRACE("[GifDecoder] Local colormap=%d, ncolors=%d\n", isLocalColormap, ncolors);
// We'll calculate the list of used colormap indexes in this
// frameImage.
@ -527,17 +527,17 @@ private:
// Number of colors in the image that aren't in the palette.
int missing = (usedNColors - found);
DLOG("[GifDecoder] Bg index=%d,\n"
" Local transparent index=%d,\n"
" Need extra index to show bg color=%d,\n "
" Found colors in palette=%d,\n"
" Used colors in local pixels=%d,\n"
" Base for new colors in palette=%d,\n"
" Colors in the image missing in the palette=%d,\n"
" New palette size=%d\n",
m_bgIndex, m_localTransparentIndex, needsExtraBgColor,
found, usedNColors, base, missing,
base + missing + (needsExtraBgColor ? 1: 0));
TRACE("[GifDecoder] Bg index=%d,\n"
" Local transparent index=%d,\n"
" Need extra index to show bg color=%d,\n "
" Found colors in palette=%d,\n"
" Used colors in local pixels=%d,\n"
" Base for new colors in palette=%d,\n"
" Colors in the image missing in the palette=%d,\n"
" New palette size=%d\n",
m_bgIndex, m_localTransparentIndex, needsExtraBgColor,
found, usedNColors, base, missing,
base + missing + (needsExtraBgColor ? 1: 0));
Palette oldPalette(*palette);
palette->resize(base + missing + (needsExtraBgColor ? 1: 0));
@ -645,8 +645,8 @@ private:
m_localTransparentIndex = (extension[1] & 1) ? extension[4]: -1;
m_frameDelay = (extension[3] << 8) | extension[2];
DLOG("[GifDecoder] Disposal method: %d\n Transparent index: %d\n Frame delay: %d\n",
m_disposalMethod, m_localTransparentIndex, m_frameDelay);
TRACE("[GifDecoder] Disposal method: %d\n Transparent index: %d\n Frame delay: %d\n",
m_disposalMethod, m_localTransparentIndex, m_frameDelay);
}
}
@ -1046,10 +1046,10 @@ private:
}
}
DLOG("[GifEncoder] frameBounds=%d %d %d %d prev=%d %d %d %d next=%d %d %d %d\n",
frameBounds.x, frameBounds.y, frameBounds.w, frameBounds.h,
prev.x, prev.y, prev.w, prev.h,
next.x, next.y, next.w, next.h);
TRACE("[GifEncoder] frameBounds=%d %d %d %d prev=%d %d %d %d next=%d %d %d %d\n",
frameBounds.x, frameBounds.y, frameBounds.w, frameBounds.h,
prev.x, prev.y, prev.w, prev.h,
next.x, next.y, next.w, next.h);
}
}

View File

@ -13,67 +13,32 @@
#include "app/app.h"
#include "app/resource_finder.h"
#include "ui/base.h"
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <string>
#include "base/log.h"
namespace app {
static FILE* log_fileptr = NULL;
static LoggerModule* logger_instance = NULL;
LoggerModule::LoggerModule(bool verbose)
: m_verbose(verbose)
{
logger_instance = this;
if (verbose) {
app::ResourceFinder rf(false);
rf.includeUserDir("aseprite.log");
auto filename = rf.defaultFilename();
base_set_log_filename(filename.c_str());
}
}
LoggerModule::~LoggerModule()
{
LOG("Logger module: shutting down (this is the last line)\n");
if (log_fileptr) {
fclose(log_fileptr);
log_fileptr = NULL;
}
logger_instance = NULL;
// Close log file
base_set_log_filename("");
logger_instance = nullptr;
}
} // namespace app
void verbose_log(const char* format, ...)
{
if (app::logger_instance && !app::logger_instance->isVerbose())
return;
if (!app::log_fileptr) {
std::string filename;
app::ResourceFinder rf(false);
rf.includeUserDir("aseprite.log");
filename = rf.defaultFilename();
if (filename.size() > 0)
app::log_fileptr = fopen(filename.c_str(), "w");
}
if (app::log_fileptr) {
va_list ap;
va_start(ap, format);
vfprintf(app::log_fileptr, format, ap);
fflush(app::log_fileptr);
#ifdef _DEBUG
va_start(ap, format);
vfprintf(stderr, format, ap);
fflush(stderr);
#endif
va_end(ap);
}
}

View File

@ -53,6 +53,7 @@ set(BASE_SOURCES
file_handle.cpp
fs.cpp
launcher.cpp
log.cpp
mem_utils.cpp
memory.cpp
memory_dump.cpp

56
src/base/log.cpp Normal file
View File

@ -0,0 +1,56 @@
// Aseprite Base Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "base/log.h"
#include "base/file_handle.h"
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <string>
static FILE* log_fileptr = nullptr;
static std::string log_filename;
void base_set_log_filename(const char* filename)
{
if (log_fileptr) {
fclose(log_fileptr);
log_fileptr = nullptr;
}
log_filename = filename;
}
void base_log(const char* format, ...)
{
if (!log_fileptr) {
if (log_filename.empty())
return;
log_fileptr = base::open_file_raw(log_filename, "w");
}
if (log_fileptr) {
va_list ap;
va_start(ap, format);
vfprintf(log_fileptr, format, ap);
fflush(log_fileptr);
#ifdef _DEBUG
va_start(ap, format);
vfprintf(stderr, format, ap);
fflush(stderr);
#endif
va_end(ap);
}
}

19
src/base/log.h Normal file
View File

@ -0,0 +1,19 @@
// Aseprite Base Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef BASE_LOG_H_INCLUDED
#define BASE_LOG_H_INCLUDED
#pragma once
// Define BASE_DONT_DEFINE_LOG_MACRO in case that you don't need LOG
#ifndef BASE_DONT_DEFINE_LOG_MACRO
#define LOG base_log
#endif
void base_set_log_filename(const char* filename);
void base_log(const char* format, ...);
#endif

View File

@ -35,15 +35,6 @@
#define UPDATE_URL WEBSITE "update/?xml=1"
#define COPYRIGHT "Copyright (C) 2001-2015 David Capello"
#define LOG verbose_log
#ifdef _DEBUG
#define DLOG LOG
#else
#define DLOG(...) ((void)0)
#endif
// verbose_log() is defined in src/app/log.cpp and used through LOG macro
void verbose_log(const char* format, ...);
#include "base/base.h"
#include "base/debug.h"
#include "base/log.h"

View File

@ -117,8 +117,8 @@ public:
HttpResponse response(&body);
request.send(response);
DLOG("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
DLOG("Response:\n--\n%s--\n", body.str().c_str());
TRACE("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
TRACE("Response:\n--\n%s--\n", body.str().c_str());
CheckUpdateResponse data(body.str());
delegate->onResponse(data);