зеркало из https://github.com/mozilla/moz-skia.git
Images are written by PictureRenderer and not render_pictures_main.
Review URL: https://codereview.appspot.com/6448174 git-svn-id: http://skia.googlecode.com/svn/trunk@5216 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
db9a5fb55f
Коммит
9299eded38
|
@ -76,7 +76,6 @@
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'core.gyp:core',
|
'core.gyp:core',
|
||||||
'images.gyp:images',
|
|
||||||
'ports.gyp:ports',
|
'ports.gyp:ports',
|
||||||
'tools.gyp:picture_renderer',
|
'tools.gyp:picture_renderer',
|
||||||
'tools.gyp:picture_utils',
|
'tools.gyp:picture_utils',
|
||||||
|
@ -94,10 +93,8 @@
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'core.gyp:core',
|
'core.gyp:core',
|
||||||
'ports.gyp:ports',
|
'ports.gyp:ports',
|
||||||
'images.gyp:images',
|
|
||||||
'tools.gyp:picture_utils',
|
'tools.gyp:picture_utils',
|
||||||
'tools.gyp:picture_benchmark',
|
'tools.gyp:picture_benchmark',
|
||||||
'bench.gyp:bench_timer',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -132,8 +129,12 @@
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'core.gyp:core',
|
'core.gyp:core',
|
||||||
|
'images.gyp:images',
|
||||||
'tools.gyp:picture_utils',
|
'tools.gyp:picture_utils',
|
||||||
],
|
],
|
||||||
|
'export_dependent_settings': [
|
||||||
|
'images.gyp:images',
|
||||||
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['skia_gpu == 1', {
|
['skia_gpu == 1', {
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
#include "SamplePipeControllers.h"
|
#include "SamplePipeControllers.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkDevice.h"
|
#include "SkDevice.h"
|
||||||
|
#include "SkImageEncoder.h"
|
||||||
#include "SkGPipe.h"
|
#include "SkGPipe.h"
|
||||||
#include "SkPicture.h"
|
#include "SkPicture.h"
|
||||||
|
#include "SkString.h"
|
||||||
#include "SkTDArray.h"
|
#include "SkTDArray.h"
|
||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
#include "picture_utils.h"
|
#include "picture_utils.h"
|
||||||
|
@ -109,6 +111,22 @@ void PictureRenderer::finishDraw() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PictureRenderer::write(const SkString& path) const {
|
||||||
|
SkASSERT(fCanvas.get() != NULL);
|
||||||
|
SkASSERT(fPicture != NULL);
|
||||||
|
if (NULL == fCanvas.get() || NULL == fPicture) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkBitmap bitmap;
|
||||||
|
sk_tools::setup_bitmap(&bitmap, fPicture->width(), fPicture->height());
|
||||||
|
|
||||||
|
fCanvas->readPixels(&bitmap, 0, 0);
|
||||||
|
sk_tools::force_all_opaque(bitmap);
|
||||||
|
|
||||||
|
return SkImageEncoder::EncodeFile(path.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
|
||||||
|
}
|
||||||
|
|
||||||
void PipePictureRenderer::render() {
|
void PipePictureRenderer::render() {
|
||||||
SkASSERT(fCanvas.get() != NULL);
|
SkASSERT(fCanvas.get() != NULL);
|
||||||
SkASSERT(fPicture != NULL);
|
SkASSERT(fPicture != NULL);
|
||||||
|
|
|
@ -20,6 +20,7 @@ class SkBitmap;
|
||||||
class SkCanvas;
|
class SkCanvas;
|
||||||
class SkGLContext;
|
class SkGLContext;
|
||||||
class SkPicture;
|
class SkPicture;
|
||||||
|
class SkString;
|
||||||
|
|
||||||
namespace sk_tools {
|
namespace sk_tools {
|
||||||
|
|
||||||
|
@ -37,10 +38,6 @@ public:
|
||||||
virtual void end();
|
virtual void end();
|
||||||
void resetState();
|
void resetState();
|
||||||
|
|
||||||
SkCanvas* getCanvas() {
|
|
||||||
return fCanvas.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDeviceType(SkDeviceTypes deviceType) {
|
void setDeviceType(SkDeviceTypes deviceType) {
|
||||||
fDeviceType = deviceType;
|
fDeviceType = deviceType;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +68,8 @@ public:
|
||||||
#endif
|
#endif
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
bool write(const SkString& path) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void finishDraw();
|
virtual void finishDraw();
|
||||||
SkCanvas* setupCanvas();
|
SkCanvas* setupCanvas();
|
||||||
|
|
|
@ -6,12 +6,27 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "picture_utils.h"
|
#include "picture_utils.h"
|
||||||
|
#include "SkColorPriv.h"
|
||||||
#include "SkBitmap.h"
|
#include "SkBitmap.h"
|
||||||
#include "SkPicture.h"
|
#include "SkPicture.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
#include "SkStream.h"
|
#include "SkStream.h"
|
||||||
|
|
||||||
namespace sk_tools {
|
namespace sk_tools {
|
||||||
|
void force_all_opaque(const SkBitmap& bitmap) {
|
||||||
|
SkASSERT(NULL == bitmap.getTexture());
|
||||||
|
SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
|
||||||
|
if (NULL != bitmap.getTexture() || SkBitmap::kARGB_8888_Config == bitmap.config()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkAutoLockPixels lock(bitmap);
|
||||||
|
for (int y = 0; y < bitmap.height(); y++) {
|
||||||
|
for (int x = 0; x < bitmap.width(); x++) {
|
||||||
|
*bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
|
void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
|
||||||
size_t len = dir.size();
|
size_t len = dir.size();
|
||||||
|
|
|
@ -15,6 +15,14 @@ class SkString;
|
||||||
class SkPicture;
|
class SkPicture;
|
||||||
|
|
||||||
namespace sk_tools {
|
namespace sk_tools {
|
||||||
|
// since PNG insists on unpremultiplying our alpha, we take no precision
|
||||||
|
// chances and force all pixels to be 100% opaque, otherwise on compare we
|
||||||
|
// may not get a perfect match.
|
||||||
|
//
|
||||||
|
// This expects a bitmap with a config type of 8888 and for the pixels to
|
||||||
|
// not be on the GPU.
|
||||||
|
void force_all_opaque(const SkBitmap& bitmap);
|
||||||
|
|
||||||
// Creates a posix style filepath by concatenating name onto dir with a
|
// Creates a posix style filepath by concatenating name onto dir with a
|
||||||
// forward slash into path.
|
// forward slash into path.
|
||||||
void make_filepath(SkString* path, const SkString&, const SkString& name);
|
void make_filepath(SkString* path, const SkString&, const SkString& name);
|
||||||
|
@ -22,7 +30,7 @@ namespace sk_tools {
|
||||||
// Returns the last part of the path (file name or leaf directory name)
|
// Returns the last part of the path (file name or leaf directory name)
|
||||||
//
|
//
|
||||||
// This basically just looks for a foward slash or backslash (windows
|
// This basically just looks for a foward slash or backslash (windows
|
||||||
// only)
|
// only).
|
||||||
void get_basename(SkString* basename, const SkString& path);
|
void get_basename(SkString* basename, const SkString& path);
|
||||||
|
|
||||||
// Returns true if the string ends with %
|
// Returns true if the string ends with %
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
#include "SkBitmap.h"
|
#include "SkBitmap.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkColorPriv.h"
|
|
||||||
#include "SkDevice.h"
|
#include "SkDevice.h"
|
||||||
#include "SkImageEncoder.h"
|
|
||||||
#include "SkOSFile.h"
|
#include "SkOSFile.h"
|
||||||
#include "SkPicture.h"
|
#include "SkPicture.h"
|
||||||
#include "SkStream.h"
|
#include "SkStream.h"
|
||||||
|
@ -68,32 +66,11 @@ static void make_output_filepath(SkString* path, const SkString& dir,
|
||||||
path->append("png");
|
path->append("png");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* since PNG insists on unpremultiplying our alpha, we take no precision chances
|
|
||||||
and force all pixels to be 100% opaque, otherwise on compare we may not get
|
|
||||||
a perfect match.
|
|
||||||
*/
|
|
||||||
static void force_all_opaque(const SkBitmap& bitmap) {
|
|
||||||
SkAutoLockPixels lock(bitmap);
|
|
||||||
for (int y = 0; y < bitmap.height(); y++) {
|
|
||||||
for (int x = 0; x < bitmap.width(); x++) {
|
|
||||||
*bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
|
|
||||||
SkBitmap copy;
|
|
||||||
bitmap.copyTo(©, SkBitmap::kARGB_8888_Config);
|
|
||||||
force_all_opaque(copy);
|
|
||||||
return SkImageEncoder::EncodeFile(path.c_str(), copy,
|
|
||||||
SkImageEncoder::kPNG_Type, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void write_output(const SkString& outputDir, const SkString& inputFilename,
|
static void write_output(const SkString& outputDir, const SkString& inputFilename,
|
||||||
const SkBitmap& bitmap) {
|
const sk_tools::PictureRenderer& renderer) {
|
||||||
SkString outputPath;
|
SkString outputPath;
|
||||||
make_output_filepath(&outputPath, outputDir, inputFilename);
|
make_output_filepath(&outputPath, outputDir, inputFilename);
|
||||||
bool isWritten = write_bitmap(outputPath, bitmap);
|
bool isWritten = renderer.write(outputPath);
|
||||||
if (!isWritten) {
|
if (!isWritten) {
|
||||||
SkDebugf("Could not write to file %s\n", outputPath.c_str());
|
SkDebugf("Could not write to file %s\n", outputPath.c_str());
|
||||||
}
|
}
|
||||||
|
@ -112,15 +89,12 @@ static void render_picture(const SkString& inputPath, const SkString& outputDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
SkPicture picture(&inputStream);
|
SkPicture picture(&inputStream);
|
||||||
SkBitmap bitmap;
|
|
||||||
sk_tools::setup_bitmap(&bitmap, picture.width(), picture.height());
|
|
||||||
|
|
||||||
renderer.init(&picture);
|
renderer.init(&picture);
|
||||||
|
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|
||||||
renderer.getCanvas()->readPixels(&bitmap, 0, 0);
|
write_output(outputDir, inputFilename, renderer);
|
||||||
write_output(outputDir, inputFilename, bitmap);
|
|
||||||
|
|
||||||
renderer.end();
|
renderer.end();
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче