Commit 7da70afd authored by Boudewijn Rempt's avatar Boudewijn Rempt

Remove unused vectorimage library

parent 4c891723
...@@ -14,7 +14,6 @@ add_subdirectory( psd ) ...@@ -14,7 +14,6 @@ add_subdirectory( psd )
add_subdirectory( color ) add_subdirectory( color )
add_subdirectory( image ) add_subdirectory( image )
add_subdirectory( ui ) add_subdirectory( ui )
add_subdirectory( vectorimage )
add_subdirectory( impex ) add_subdirectory( impex )
add_subdirectory( libkis ) add_subdirectory( libkis )
if (NOT APPLE AND HAVE_QT_QUICK) if (NOT APPLE AND HAVE_QT_QUICK)
......
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/libemf
${CMAKE_CURRENT_SOURCE_DIR}/libsvm
${CMAKE_CURRENT_SOURCE_DIR}/libwmf
)
set(vectorimage_LIB_SRCS
libemf/EmfRecords.cpp
libemf/EmfObjects.cpp
libemf/EmfHeader.cpp
libemf/BitmapHeader.cpp
libemf/Bitmap.cpp
libemf/EmfParser.cpp
libemf/EmfOutput.cpp
libemf/EmfOutputDebugStrategy.cpp
libemf/EmfOutputPainterStrategy.cpp
libsvm/SvmStructs.cpp
libsvm/SvmGraphicsContext.cpp
libsvm/SvmParser.cpp
libsvm/SvmPainterBackend.cpp
libwmf/WmfStack.cpp
libwmf/WmfDeviceContext.cpp
libwmf/WmfParser.cpp
libwmf/WmfAbstractBackend.cpp
libwmf/WmfPainterBackend.cpp
libwmf/WmfWriter.cpp
VectorImageDebug.cpp
)
add_library(kritavectorimage SHARED ${vectorimage_LIB_SRCS})
generate_export_header(kritavectorimage BASE_NAME kritavectorimage)
target_include_directories(kritavectorimage
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libemf>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libwmf>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libsvm>
)
target_link_libraries(kritavectorimage KF5::I18n Qt5::Gui Qt5::PrintSupport)
set_target_properties(kritavectorimage PROPERTIES
VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION}
)
install(TARGETS kritavectorimage ${INSTALL_TARGETS_DEFAULT_ARGS} )
/**
* \mainpage
*
* KritaVectorImage is a library bundling libemf, libsvm and libwmf.
*/
// DOXYGEN_SET_PROJECT_NAME = KritaVectorImage
/*
* Copyright (c) 2015 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "VectorImageDebug.h"
const QLoggingCategory &VECTOR_IMAGE_LOG() \
{
static const QLoggingCategory category("krita.lib.vectorimage", QtInfoMsg);
return category;
}
/*
* Copyright (c) 2015 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef VECTOR_IMAGE_DEBUG_H_
#define VECTOR_IMAGE_DEBUG_H_
#include <QDebug>
#include <QLoggingCategory>
#include <kritavectorimage_export.h>
extern const KRITAVECTORIMAGE_EXPORT QLoggingCategory &VECTOR_IMAGE_LOG();
#define debugVectorImage qCDebug(VECTOR_IMAGE_LOG)
#define warnVectorImage qCWarning(VECTOR_IMAGE_LOG)
#define errorVectorImage qCCritical(VECTOR_IMAGE_LOG)
#endif
/*
* Copyright 2010 Inge Wallin <inge@lysator.liu.se>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Bitmap.h"
#include <QDataStream>
#include <QImage>
#include <VectorImageDebug.h>
#include "EmfEnums.h"
namespace Libemf
{
static void soakBytes( QDataStream &stream, int numBytes )
{
quint8 scratch;
for ( int i = 0; i < numBytes; ++i ) {
stream >> scratch;
}
}
Bitmap::Bitmap( QDataStream &stream,
quint32 recordSize, // total size of the EMF record
quint32 usedBytes, // used bytes of the EMF record before the bitmap part
quint32 offBmiSrc, // offset to start of bitmapheader
quint32 cbBmiSrc, // size of bitmap header
quint32 offBitsSrc,// offset to source bitmap
quint32 cbBitsSrc) // size of source bitmap
: m_hasImage(false)
, m_header(0)
, m_imageIsValid(false)
{
// If necessary read away garbage before the bitmap header.
if (offBmiSrc > usedBytes) {
//debugVectorImage << "soaking " << offBmiSrc - usedBytes << "bytes before the header";
soakBytes(stream, offBmiSrc - usedBytes);
usedBytes = offBmiSrc;
}
// Create the header
m_header = new BitmapHeader(stream, cbBmiSrc);
usedBytes += cbBmiSrc;
// If necessary read away garbage between the bitmap header and the picture.
if (offBitsSrc > usedBytes) {
//debugVectorImage << "soaking " << offBmiSrc - usedBytes << "bytes between the header and the image";
soakBytes(stream, offBitsSrc - usedBytes);
usedBytes = offBitsSrc;
}
// Read the image data
if (cbBitsSrc > 0) {
//debugVectorImage << "reading bitmap (" << cbBitsSrc << "bytes)";
m_imageData.resize( cbBitsSrc );
stream.readRawData( m_imageData.data(), cbBitsSrc );
m_hasImage = true;
usedBytes += cbBitsSrc;
}
// If necessary, read away garbage after the image.
if (recordSize > usedBytes) {
//debugVectorImage << "soaking " << recordSize - usedBytes << "bytes after the image";
soakBytes(stream, recordSize - usedBytes);
usedBytes = recordSize;
}
}
Bitmap::~Bitmap()
{
delete m_header;
//delete m_image;
}
#if 1
QImage Bitmap::image()
{
if (!m_hasImage) {
return QImage();
}
if (m_imageIsValid) {
return m_image;
}
QImage::Format format = QImage::Format_Invalid;
// Start by determining which QImage format we are going to use.
if (m_header->bitCount() == BI_BITCOUNT_1) {
format = QImage::Format_Mono;
} else if ( m_header->bitCount() == BI_BITCOUNT_4 ) {
if ( m_header->compression() == BI_RGB ) {
format = QImage::Format_RGB555;
} else {
//debugVectorImage << "Unexpected compression format for BI_BITCOUNT_4:"
// << m_header->compression();
//Q_ASSERT( 0 );
return QImage();
}
} else if ( m_header->bitCount() == BI_BITCOUNT_5 ) {
format = QImage::Format_RGB888;
} else if ( m_header->bitCount() == BI_BITCOUNT_6 ) {
if (m_header->compression() == BI_RGB) {
format = QImage::Format_RGB32;
//format = QImage::Format_RGB888;
} else if (m_header->compression() == BI_BITFIELDS) {
// FIXME: The number of bits is correct, but we need to
// handle the actual bits per colors specifically.
//
// The spec says (MS_WMF section 2.1.1.3):
// If the Compression field of the BitmapInfoHeader
// Object is set to BI_BITFIELDS, the Colors field
// contains three DWORD color masks that specify the
// red, green, and blue components, respectively, of
// each pixel. Each DWORD in the bitmap array represents
// a single pixel.
format = QImage::Format_RGB32;
}
else
return QImage();
} else {
//debugVectorImage << "Unexpected format:" << m_header->bitCount();
//Q_ASSERT(0);
return QImage();
}
// According to MS-WMF 2.2.2.3, the sign of the height decides if
// this is a compressed bitmap or not.
if (m_header->height() > 0) {
// This bitmap is a top-down bitmap without compression.
m_image = QImage( (const uchar*)m_imageData.constData(),
m_header->width(), m_header->height(), format );
// This is a workaround around a strange bug. Without this
// code it shows nothing. Note that if we use Format_ARGB32
// to begin with, nothing is shown anyway.
//
// FIXME: Perhaps it could be tested again with a later
// version of Qt (I have 4.6.3) /iw
if (m_header->bitCount() == BI_BITCOUNT_6
&& m_header->compression() == BI_RGB) {
m_image = m_image.convertToFormat(QImage::Format_ARGB32);
}
// The WMF images are in the BGR color order.
if (format == QImage::Format_RGB888)
m_image = m_image.rgbSwapped();
// We have to mirror this bitmap in the X axis since WMF images are stored bottom-up.
m_image = m_image.mirrored(false, true);
} else {
// This bitmap is a bottom-up bitmap which uses compression.
switch (m_header->compression()) {
case BI_RGB:
m_image = QImage( (const uchar*)m_imageData.constData(),
m_header->width(), -m_header->height(), format );
// The WMF images are in the BGR color order.
m_image = m_image.rgbSwapped();
break;
// These compressions are not yet supported, so return an empty image.
case BI_RLE8:
case BI_RLE4:
case BI_BITFIELDS:
case BI_JPEG:
case BI_PNG:
case BI_CMYK:
case BI_CMYKRLE8:
case BI_CMYKRLE4:
default:
m_image = QImage(m_header->width(), m_header->height(), format);
break;
}
}
m_imageIsValid = true;
return m_image;
}
#else
QImage *Bitmap::image()
{
if (!m_hasImage) {
return 0;
}
if (m_image) {
return m_image;
}
QImage::Format format = QImage::Format_Invalid;
if ( m_header->bitCount() == BI_BITCOUNT_4 ) {
if ( m_header->compression() == 0x00 ) {
format = QImage::Format_RGB555;
} else {
//debugVectorImage << "Unexpected compression format for BI_BITCOUNT_4:"
// << m_header->compression();
//Q_ASSERT( 0 );
return 0;
}
} else if ( m_header->bitCount() == BI_BITCOUNT_5 ) {
format = QImage::Format_RGB888;
} else {
debugVectorImage << "Unexpected format:" << m_header->bitCount();
//Q_ASSERT( 0 );
return 0;
}
m_image = new QImage( (const uchar*)m_imageData.constData(),
m_header->width(), m_header->height(), format );
return m_image;
}
#endif
} // namespace Libemf
/*
Copyright 2008 Brad Hards <bradh@frogmouth.net>
Copyright 2010 Inge Wallin <inge@lysator.liu.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EMFBITMAP_H
#define EMFBITMAP_H
#include <Qt> // For qint, etc.
#include <QByteArray>
#include <QImage>
#include "BitmapHeader.h"
class QDataStream;
/**
* @file
*
* definitions for Device Independent Bitmaps, as used in both WMF and EMF files.
*/
/// Namespace for Enhanced Metafile (EMF) classes
namespace Libemf
{
/**
* @class Bitmap
*
* Representation of a bitmap from an EMF file
*/
class Bitmap
{
public:
/**
* Constructor
*
* The Bitmap structure is built from the specified stream.
*
* \param stream the data stream to read from.
* \param recordSize the size of the EMF record that this bitmap is part of.
* \param usedBytes number of already used bytes of the EMF record before the bitmap part
* \param offBmiSrc offset to start of bitmapheader
* \param cbBmiSrc size of bitmap header
* \param offBitsSrc offset to source bitmap
* \param cbBitsSrc size of source bitmap
*/
Bitmap( QDataStream &stream,
quint32 recordSize, // total size of the EMF record
quint32 usedBytes, // used bytes of the EMF record before the bitmap part
quint32 offBmiSrc, // offset to start of bitmapheader
quint32 cbBmiSrc, // size of bitmap header
quint32 offBitsSrc, // offset to source bitmap
quint32 cbBitsSrc); // size of source bitmap
~Bitmap();
/**
The bitmap header
*/
BitmapHeader *header() const { return m_header; };
/**
Return true if there is an image in this record.
*/
bool hasImage() const { return m_hasImage; };
/**
The image.
QImage shares its memory already.
*/
QImage image();
private:
// No copying for now, because we will get into trouble with the pointers.
// The remedy is to write a real operator=() and Bitmap(Bitmap&).
explicit Bitmap(Bitmap&);
Bitmap &operator=(Bitmap&);
private:
bool m_hasImage;
BitmapHeader *m_header;
QByteArray m_imageData;
QImage m_image;
bool m_imageIsValid;
};
} // namespace Libemf
#endif
/*
* Copyright 2010 Inge Wallin <inge@lysator.liu.se>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BitmapHeader.h"
#include <QDataStream>
//#include <QColor>
//#include <QImage>
//#include <QRect> // also provides QSize
//#include <QString>
#include <VectorImageDebug.h>
namespace Libemf
{
static void soakBytes( QDataStream &stream, int numBytes )
{
quint8 scratch;
for ( int i = 0; i < numBytes; ++i ) {
stream >> scratch;
}
}
BitmapHeader::BitmapHeader( QDataStream &stream, int size )
{
m_headerType = BitmapInfoHeader; // The default
int read = 40; // Keep track of how many bytes we have read;
// Read the data that is present in a BitmapInfoHeader (size 40)
stream >> m_headerSize;
stream >> m_width;
stream >> m_height;
stream >> m_planes; // 16 bits
stream >> m_bitCount; // 16 bits
stream >> m_compression;
stream >> m_imageSize;
stream >> m_xPelsPerMeter;
stream >> m_yPelsPerMeter;
stream >> m_colorUsed;
stream >> m_colorImportant;
#if 0
debugVectorImage << "Width:" << m_width;
debugVectorImage << "Height:" << m_height;
debugVectorImage << "planes:" << m_planes;
debugVectorImage << "BitCount:" << m_bitCount;
debugVectorImage << "Compression:" << m_compression;
debugVectorImage << "ImageSize:" << m_imageSize;
debugVectorImage << "Colors used:" << m_colorUsed;
#endif
// BitmapV4Header (size 40+68 = 108)
if (size >= 108) {
m_headerType = BitmapV4Header;
read = 108;
stream >> m_redMask;
stream >> m_greenMask;
stream >> m_blueMask;
stream >> m_alphaMask;
stream >> m_colorSpaceType;
// FIXME sometime: Implement the real CIEXYZTriple
for (int i = 0; i < 9; ++i)
stream >> m_endpoints[i];
stream >> m_gammaRed;
stream >> m_gammaGreen;
stream >> m_gammaBlue;
}
// BitmapV5Header (size 108+16 = 124)
if (size >= 124) {
m_headerType = BitmapV5Header;
read = 124;
stream >> m_intent;
stream >> m_profileData;
stream >> m_profileSize;
stream >> m_reserved;
}
#if 0
debugVectorImage << "header type:" << m_headerType;
debugVectorImage << "header size:" << size;
debugVectorImage << "read bytes: " << read;
#endif
// Read away the overshot from the size parameter;
if (size > read)
soakBytes(stream, size - read);
}
BitmapHeader::~BitmapHeader()
{
}
} // namespace Libemf
/*
Copyright 2008 Brad Hards <bradh@frogmouth.net>
Copyright 2010 Inge Wallin <inge@lysator.liu.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EMFBITMAPHEADER_H
#define EMFBITMAPHEADER_H
#include <Qt> // For qint, etc.
class QDataStream;
/**
* @file
*
* definitions for Device Independent Bitmaps, as used in both WMF and EMF files.
*/
/// Namespace for Enhanced Metafile (EMF) classes
namespace Libemf
{
/**
* @class BitmapHeader
*
* Representation of a bitmap header, including the following formats:
* - BitmapInfoHeader [MS-WMF].pdf 2.2.2.3
* - BitmapV4Header [MS-WMF].pdf 2.2.2.4
* - BitmapV5Header [MS-WMF].pdf 2.2.2.5
*/
class BitmapHeader
{
public:
typedef enum {
//BitmapCoreHeader, Not yet supported
BitmapInfoHeader,
BitmapV4Header,
BitmapV5Header
} Type;
/**
* Constructor
*
* The header structure is built from the specified stream.
*
* \param stream the data stream to read from.
* \param size the size of the header. This decides what type it is.
*/
BitmapHeader( QDataStream &stream, int size );
~BitmapHeader();
/**
The width of the bitmap, in pixels
*/
qint32 width() const { return m_width; };
/**
The height of the bitmap, in pixels
*/
qint32 height() const { return m_height; };
/**
The number of bits that make up a pixel
This is an enumerated type - see the BitCount enum
*/
quint16 bitCount() const { return m_bitCount; };
/**
The type of compression used in the image
This is an enumerated type
*/
quint32 compression() const { return m_compression; };
//private:
Type m_headerType; /// Which header type that is represented.
// Data to be found in a BitmapInfoHeader
quint32 m_headerSize;
qint32 m_width;
qint32 m_height;
quint16 m_planes;
quint16 m_bitCount;
quint32 m_compression;
quint32 m_imageSize;
qint32 m_xPelsPerMeter;
qint32 m_yPelsPerMeter;
quint32 m_colorUsed;
quint32 m_colorImportant;
// Additional data to be found in a BitmapV4Header
quint32 m_redMask;
quint32 m_greenMask;
quint32 m_blueMask;
quint32 m_alphaMask;
quint32 m_colorSpaceType;
quint32 m_endpoints[9]; // Actually a CIEXYZTriple
qint32 m_gammaRed;