marker -> image conversion
This commit is contained in:
parent
71e31dcc22
commit
3b8408f7ac
@ -17,6 +17,7 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "nonogramimage.h"
|
#include "nonogramimage.h"
|
||||||
|
#include "nonogrammarker.h"
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
|
|
||||||
@ -69,15 +70,8 @@ namespace libqnono {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NonogramImage::NonogramImage(const QImage & image)
|
NonogramImage::NonogramImage(const QImage & image)
|
||||||
: m_size(image.size()), m_data(0), m_blackPixels(0) {
|
: m_size(0, 0), m_data(0), m_blackPixels(0) {
|
||||||
int rows = image.height(), cols = image.width();
|
load(image);
|
||||||
m_data = new bool[rows*cols];
|
|
||||||
for (int i = 0, y = 0; y < rows; ++y) {
|
|
||||||
for (int x = 0; x < cols; ++x, ++i) {
|
|
||||||
m_data[i] = (0 == (image.pixel(x, y) & 0x00FFFFFF));
|
|
||||||
if (m_data[i]) ++m_blackPixels;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NonogramImage::~NonogramImage() {
|
NonogramImage::~NonogramImage() {
|
||||||
@ -196,6 +190,34 @@ namespace libqnono {
|
|||||||
stream.writeRawData(bits, bitcount);
|
stream.writeRawData(bits, bitcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NonogramImage::load(const QImage & image) {
|
||||||
|
delete [] m_data; m_data = 0;
|
||||||
|
m_blackPixels = 0;
|
||||||
|
|
||||||
|
m_size = image.size();
|
||||||
|
int rows = m_size.height(), cols = m_size.width();
|
||||||
|
m_data = new bool[rows*cols];
|
||||||
|
for (int i = 0, y = 0; y < rows; ++y) {
|
||||||
|
for (int x = 0; x < cols; ++x, ++i) {
|
||||||
|
m_data[i] = (0 == (image.pixel(x, y) & 0x00FFFFFF));
|
||||||
|
if (m_data[i]) ++m_blackPixels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NonogramImage::load(const NonogramMarker & marker) {
|
||||||
|
delete [] m_data; m_data = 0;
|
||||||
|
m_blackPixels = 0;
|
||||||
|
|
||||||
|
m_size = marker.size();
|
||||||
|
int n = m_size.height() * m_size.width();
|
||||||
|
m_data = new bool[n];
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
m_data[i] = (NonogramMarker::MARKED == marker.m_data[i]);
|
||||||
|
if (m_data[i]) ++m_blackPixels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QDataStream & operator<<(QDataStream & stream, const NonogramImage & image) {
|
QDataStream & operator<<(QDataStream & stream, const NonogramImage & image) {
|
||||||
image.writeToStream(stream);
|
image.writeToStream(stream);
|
||||||
return stream;
|
return stream;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
namespace libqnono {
|
namespace libqnono {
|
||||||
|
class NonogramMarker;
|
||||||
|
|
||||||
class NonogramImageView {
|
class NonogramImageView {
|
||||||
public:
|
public:
|
||||||
virtual bool pixel(int coord1, int coord2) const = 0;
|
virtual bool pixel(int coord1, int coord2) const = 0;
|
||||||
@ -57,6 +59,9 @@ namespace libqnono {
|
|||||||
bool readFromStream(QDataStream & stream);
|
bool readFromStream(QDataStream & stream);
|
||||||
void writeToStream(QDataStream & stream) const;
|
void writeToStream(QDataStream & stream) const;
|
||||||
|
|
||||||
|
void load(const QImage & image);
|
||||||
|
void load(const NonogramMarker & marker);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSize m_size;
|
QSize m_size;
|
||||||
bool *m_data;
|
bool *m_data;
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
namespace libqnono {
|
namespace libqnono {
|
||||||
|
class NonogramImage;
|
||||||
|
|
||||||
class NonogramMarker {
|
class NonogramMarker {
|
||||||
public:
|
public:
|
||||||
enum Mark { NONE = 0, MARKED = 1, CROSSED = 2 };
|
enum Mark { NONE = 0, MARKED = 1, CROSSED = 2 };
|
||||||
@ -38,11 +40,15 @@ namespace libqnono {
|
|||||||
void setPixel(int x, int y, Mark value) { m_data[y*m_size.width()+x] = value; }
|
void setPixel(int x, int y, Mark value) { m_data[y*m_size.width()+x] = value; }
|
||||||
|
|
||||||
QSize size() const { return m_size; }
|
QSize size() const { return m_size; }
|
||||||
|
int width() const { return m_size.width(); }
|
||||||
|
int height() const { return m_size.height(); }
|
||||||
|
|
||||||
bool readFromStream(QDataStream & stream);
|
bool readFromStream(QDataStream & stream);
|
||||||
void writeToStream(QDataStream & stream) const;
|
void writeToStream(QDataStream & stream) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class NonogramImage;
|
||||||
|
|
||||||
QSize m_size;
|
QSize m_size;
|
||||||
Mark *m_data;
|
Mark *m_data;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user