Optimized and fixed canvas portion merging in final picture

This commit is contained in:
Michaël Lemaire 2014-08-21 15:30:09 +02:00
parent 04f6ab732d
commit 1afcb907c4
4 changed files with 48 additions and 11 deletions

View file

@ -6,6 +6,8 @@
#include "CanvasPreview.h" #include "CanvasPreview.h"
#include "CanvasPictureWriter.h" #include "CanvasPictureWriter.h"
#define CUTTER_SIZE 800
Canvas::Canvas() Canvas::Canvas()
{ {
horizontal_portion_count = 1; horizontal_portion_count = 1;
@ -28,8 +30,8 @@ Canvas::~Canvas()
void Canvas::setSize(int width, int height) void Canvas::setSize(int width, int height)
{ {
horizontal_portion_count = 1 + (width - 1) / 800; horizontal_portion_count = 1 + (width - 1) / CUTTER_SIZE;
vertical_portion_count = 1 + (height - 1) / 800; vertical_portion_count = 1 + (height - 1) / CUTTER_SIZE;
int portion_width = width / horizontal_portion_count; int portion_width = width / horizontal_portion_count;
int portion_height = height / vertical_portion_count; int portion_height = height / vertical_portion_count;

View file

@ -14,11 +14,19 @@ CanvasPictureWriter::CanvasPictureWriter(const Canvas *canvas):
antialias = 1; antialias = 1;
width = canvas->getWidth(); width = canvas->getWidth();
height = canvas->getHeight(); height = canvas->getHeight();
last_portion = NULL;
last_stream = NULL;
last_y = 0;
} }
CanvasPictureWriter::~CanvasPictureWriter() CanvasPictureWriter::~CanvasPictureWriter()
{ {
delete profile; delete profile;
if (last_stream)
{
delete last_stream;
}
} }
void CanvasPictureWriter::setAntialias(int antialias) void CanvasPictureWriter::setAntialias(int antialias)
@ -80,15 +88,29 @@ Color CanvasPictureWriter::getRawPixel(int x, int y)
// Get the portion this pixel is in // Get the portion this pixel is in
CanvasPortion *portion = canvas->atPixel(x, y); CanvasPortion *portion = canvas->atPixel(x, y);
// Get the pack stream positioned at the pixel // While we stay in the same portion line, read is sequential in the stream
PackStream stream; if (portion != last_portion or last_y != y)
if (not portion->getReadStream(stream, x - portion->getXOffset(), y - portion->getYOffset()))
{ {
return COLOR_BLACK; // Get the pack stream positioned at the pixel
if (last_stream)
{
delete last_stream;
}
last_stream = new PackStream;
if (portion->getReadStream(*last_stream, x - portion->getXOffset(), y - portion->getYOffset()))
{
last_portion = portion;
last_y = y;
}
else
{
// Portion has no stream
return COLOR_BLACK;
}
} }
// Load the pixel and apply tone mapping // Load the pixel
Color col; Color col;
col.load(&stream); col.load(last_stream);
return col; return col;
} }

View file

@ -46,6 +46,10 @@ private:
int width; int width;
int height; int height;
ColorProfile *profile; ColorProfile *profile;
CanvasPortion *last_portion;
int last_y;
PackStream *last_stream;
}; };
} }

View file

@ -108,11 +108,20 @@ bool CanvasPortion::getReadStream(PackStream &stream, int x, int y)
{ {
if (FileSystem::isFile(filepath)) if (FileSystem::isFile(filepath))
{ {
if (not stream.bindToFile(filepath))
{
return false;
}
int unused_i; int unused_i;
double unused_d;
stream.bindToFile(filepath);
stream.skip(unused_i, 2); stream.skip(unused_i, 2);
stream.skip(unused_d, (y * width + x - 1) * 4);
if (x > 0 or y > 0)
{
double unused_d;
stream.skip(unused_d, (y * width + x) * 4);
}
return true; return true;
} }
else else