summaryrefslogtreecommitdiffstats
path: root/scribus/rawimage.cpp
diff options
context:
space:
mode:
authorcraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-01-01 11:40:09 +0000
committercraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-01-01 11:40:09 +0000
commit7ed83b6c6666eb8b6b104c211ae7e52907350372 (patch)
tree4430b556abac0ad660a0aacf1887d77f85d8be02 /scribus/rawimage.cpp
downloadscribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.gz
scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.xz
scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.zip
Branch 1.3.5 tree to 1.4.x tree, goodbye 1.3.x
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17163 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/rawimage.cpp')
-rw-r--r--scribus/rawimage.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/scribus/rawimage.cpp b/scribus/rawimage.cpp
new file mode 100644
index 0000000..b15eafd
--- /dev/null
+++ b/scribus/rawimage.cpp
@@ -0,0 +1,116 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#include "rawimage.h"
+
+RawImage::RawImage()
+{
+ m_width = 0;
+ m_height = 0;
+ m_channels = 0;
+ resize(0);
+}
+
+RawImage::RawImage( int width, int height, int channels )
+{
+ create(width, height, channels);
+}
+
+RawImage::~RawImage()
+{
+ resize(0);
+}
+
+bool RawImage::create( int width, int height, int channels )
+{
+ m_width = width;
+ m_height = height;
+ m_channels = channels;
+ int finalSize=width * height * channels;
+ resize(finalSize);
+ return (size()==finalSize);
+}
+
+uchar *RawImage::scanLine(int row)
+{
+ if (row < m_height)
+ return (uchar*)(data() + (row * m_channels * m_width));
+ else
+ return (uchar*)data();
+}
+
+void RawImage::setAlpha(int x, int y, int alpha)
+{
+ uchar *d;
+ if ((y < m_height) && (x < m_width))
+ {
+ d = (uchar*)(data() + (y * m_channels * m_width) + (x * m_channels));
+ d[m_channels-1] = alpha;
+ }
+}
+
+QImage RawImage::convertToQImage(bool cmyk, bool raw)
+{
+ int chans = channels();
+ QImage img = QImage(width(), height(), QImage::Format_ARGB32);
+ QRgb *ptr;
+ uchar *src;
+ uchar cr, cg, cb, ck, ca;
+// img.create(width(), height(), 32);
+ if (raw)
+ {
+ for (int i = 0; i < height(); i++)
+ {
+ ptr = (QRgb *)img.scanLine(i);
+ src = scanLine(i);
+ for (int j = 0; j < width(); j++)
+ {
+ *ptr++ = qRgba(src[0],src[1],src[2],src[3]);
+ src += chans;
+ }
+ }
+ }
+ else
+ {
+// img.setAlphaBuffer( true );
+ for (int i = 0; i < height(); i++)
+ {
+ ptr = (QRgb *)img.scanLine(i);
+ src = scanLine(i);
+ for (int j = 0; j < width(); j++)
+ {
+ if (chans > 1)
+ {
+ if (cmyk)
+ {
+ ck = src[3];
+ cr = 255 - qMin(255, src[0] + ck);
+ cg = 255 - qMin(255, src[1] + ck);
+ cb = 255 - qMin(255, src[2] + ck);
+ if (chans > 4)
+ {
+ ca = src[4];
+ *ptr++ = qRgba(cr,cg,cb,ca);
+ }
+ else
+ *ptr++ = qRgba(cr,cg,cb,255);
+ }
+ else
+ {
+ if (chans > 3)
+ *ptr++ = qRgba(src[0],src[1],src[2],src[3]);
+ else
+ *ptr++ = qRgba(src[0],src[1],src[2],255);
+ }
+ }
+ else
+ *ptr++ = qRgba(src[0],src[0],src[0],255);
+ src += chans;
+ }
+ }
+ }
+ return img;
+}