libavcodec-dev libavformat-dev libavutil-dev libblkid-dev libcups2-dev \
libdjvulibre-dev libepub-dev libexiv2-dev libfreetype6-dev \
libgcrypt20-dev libgettextpo-dev libgmp-dev libmms-dev \
- libjpeg-dev libpng-dev libparted-dev libqalculate-dev \
+ libjpeg-dev libparted-dev libqalculate-dev \
libsane-dev libspectre-dev libspeechd-dev libswscale-dev libtag1-dev \
uuid-dev libudev-dev libvncserver-dev freerdp2-dev \
libboost-dev libffmpegthumbnailer-dev libbz2-dev libtorrent-rasterbar-dev \
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
endif()
-find_package(PNG REQUIRED)
-
set(SKANLITE_VERSION_MAJOR "1")
set(SKANLITE_VERSION_MINOR "1")
set(SKANLITE_VERSION_STRING "${SKANLITE_VERSION_MAJOR}.${SKANLITE_VERSION_MINOR}")
main.cpp
skanlite.cpp
ImageViewer.cpp
- KSaneImageSaver.cpp
SaveLocation.cpp
settings.ui
SaveLocation.ui
add_executable(skanlite ${skanlite_SRCS})
-target_link_libraries(skanlite ${KDE4_KIO_LIBS} ${PNG_LIBRARY} ksane)
+target_link_libraries(skanlite
+ ${KDE4_KIO_LIBS}
+ ksane
+)
-install(TARGETS skanlite ${INSTALL_TARGETS_DEFAULT_ARGS})
-install( PROGRAMS skanlite.desktop DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR} )
+install(
+ TARGETS skanlite ${INSTALL_TARGETS_DEFAULT_ARGS}
+)
+install(
+ PROGRAMS skanlite.desktop
+ DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR}
+)
+++ /dev/null
-/* ============================================================
-* Date : 2010-07-02
-* Description : Image saver class for libksane image data.
-*
-* Copyright (C) 2010-2012 by Kåre Särs <kare.sars@iki .fi>
-*
-* 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) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* 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, see <http://www.gnu.org/licenses/>
-*
-* ============================================================ */
-
-#include "KSaneImageSaver.h"
-
-#include <png.h>
-
-#include <KDebug>
-#include <QMutex>
-
-
-struct KSaneImageSaver::Private
-{
- enum ImageType {
- ImageTypePNG,
- ImageTypeTIFF
- };
-
- bool m_savedOk;
- QMutex m_runMutex;
- KSaneImageSaver *q;
-
- QString m_name;
- QByteArray m_data;
- int m_width;
- int m_height;
- int m_format;
- ImageType m_type;
-
- bool savePng();
- bool saveTiff();
-};
-
-// ------------------------------------------------------------------------
-KSaneImageSaver::KSaneImageSaver(QObject *parent) : QThread(parent), d(new Private)
-{
- d->q = this;
-}
-
-// ------------------------------------------------------------------------
-KSaneImageSaver::~KSaneImageSaver()
-{
- delete d;
-}
-
-bool KSaneImageSaver::savePng(const QString &name, const QByteArray &data, int width, int height, int format)
-{
- if (!d->m_runMutex.tryLock()) return false;
-
- d->m_name = name;
- d->m_data = data;
- d->m_width = width;
- d->m_height = height;
- d->m_format = format;
- d->m_type = Private::ImageTypePNG;
-
- start();
- return true;
-}
-
-bool KSaneImageSaver::savePngSync(const QString &name, const QByteArray &data, int width, int height, int format)
-{
- if (!savePng(name, data, width, height, format)) {
- kDebug() << "fail";
- return false;
- }
- wait();
- return d->m_savedOk;
-}
-
-bool KSaneImageSaver::saveTiff(const QString &name, const QByteArray &data, int width, int height, int format)
-{
- if (!d->m_runMutex.tryLock()) return false;
-
- d->m_name = name;
- d->m_data = data;
- d->m_width = width;
- d->m_height = height;
- d->m_format = format;
- d->m_type = Private::ImageTypeTIFF;
-
- kDebug() << "saving Tiff images is not yet supported";
- d->m_runMutex.unlock();
- return false;
-}
-
-bool KSaneImageSaver::saveTiffSync(const QString &name, const QByteArray &data, int width, int height, int format)
-{
- if (!saveTiff(name, data, width, height, format)) {
- return false;
- }
- wait();
- return d->m_savedOk;
-}
-
-void KSaneImageSaver::run()
-{
- if (d->m_type == Private::ImageTypeTIFF) {
- d->m_savedOk = d->saveTiff();
- emit imageSaved(d->m_savedOk);
- }
- else {
- d->m_savedOk = d->savePng();
- emit imageSaved(d->m_savedOk);
- }
- d->m_runMutex.unlock();
-}
-
-bool KSaneImageSaver::Private::saveTiff()
-{
- return false;
-}
-
-bool KSaneImageSaver::Private::savePng()
-{
- FILE *file;
- png_structp png_ptr;
- png_infop info_ptr;
- png_color_8 sig_bit;
- png_bytep row_ptr;
- int bytesPerPixel;
-
- // open the file
- file = fopen(qPrintable(m_name), "wb");
- if (!file) return false;
-
- // create the png struct
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
- fclose(file);
- return false;
- }
-
- // create the image information srtuct
- info_ptr = png_create_info_struct(png_ptr);
- if (!png_ptr) {
- fclose(file);
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
- return false;
- }
-
- // initialize IO
- png_init_io(png_ptr, file);
-
- // set the image attributes
- switch ((KSaneIface::KSaneWidget::ImageFormat)m_format)
- {
- case KSaneIface::KSaneWidget::FormatGrayScale16:
- png_set_IHDR(png_ptr, info_ptr, m_width, m_height, 16, PNG_COLOR_TYPE_GRAY,
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
- sig_bit.gray = 16;
- bytesPerPixel = 2;
- break;
- case KSaneIface::KSaneWidget::FormatRGB_16_C:
- png_set_IHDR(png_ptr, info_ptr, m_width, m_height, 16, PNG_COLOR_TYPE_RGB,
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
- sig_bit.red = 16;
- sig_bit.green = 16;
- sig_bit.blue = 16;
- bytesPerPixel = 6;
- break;
- default:
- fclose(file);
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
- return false;
- }
-
- png_set_sBIT(png_ptr, info_ptr, &sig_bit);
-
- /* Optionally write comments into the image */
-// text_ptr[0].key = "Title";
-// text_ptr[0].text = "Mona Lisa";
-// text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
-// text_ptr[1].key = "Author";
-// text_ptr[1].text = "Leonardo DaVinci";
-// text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
-// text_ptr[2].key = "Description";
-// text_ptr[2].text = "<long text>";
-// text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
-// png_set_text(png_ptr, info_ptr, text_ptr, 2);
-
- /* Write the file header information. */
- png_write_info(png_ptr, info_ptr);
-
- //png_set_shift(png_ptr, &sig_bit);
- //png_set_packing(png_ptr);
-
- png_set_compression_level(png_ptr, 9);
-
- // This is not nice :( swap bytes in the 16 bit color....
- char tmp;
- // Make sure we have a buffer size that is divisible by 2
- int dataSize = m_data.size();
- if ((dataSize % 2) > 0) dataSize--;
- for (int i=0; i<dataSize; i+=2) {
- tmp = m_data[i];
- m_data[i] = m_data[i+1];
- m_data[i+1] = tmp;
- }
-
- row_ptr = (png_bytep)m_data.data();
-
- for (int i=0; i<m_height; i++) {
- png_write_rows(png_ptr, &row_ptr, 1);
- row_ptr += m_width * bytesPerPixel;
- }
-
- png_write_end(png_ptr, info_ptr);
- png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
- png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
- fclose(file);
-
- return true;
-}
-
+++ /dev/null
-/* ============================================================
-* Date : 2010-07-02
-* Description : Image saver class for libksane image data.
-*
-* Copyright (C) 2010-2012 by Kåre Särs <kare.sars@iki .fi>
-*
-* 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) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* 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, see <http://www.gnu.org/licenses/>
-*
-* ============================================================ */
-
-#ifndef KSaneImageSaver_h
-#define KSaneImageSaver_h
-
-#include <libksane/ksane.h>
-
-#include <QThread>
-
-class KSaneImageSaver : public QThread
-{
- Q_OBJECT
- public:
- KSaneImageSaver(QObject *parent = 0);
- ~KSaneImageSaver();
-
- bool savePng(const QString &name, const QByteArray &data, int width, int height, int format);
-
- bool savePngSync(const QString &name, const QByteArray &data, int width, int height, int format);
-
- bool saveTiff(const QString &name, const QByteArray &data, int width, int height, int format);
-
- bool saveTiffSync(const QString &name, const QByteArray &data, int width, int height, int format);
-
- Q_SIGNALS:
- void imageSaved(bool success);
-
- protected:
- void run();
-
- private:
- struct Private;
- Private * const d;
-
-};
-
-#endif
-
-
#include "skanlite.h"
#include "moc_skanlite.cpp"
-
-#include "KSaneImageSaver.h"
#include "SaveLocation.h"
-
#include <QApplication>
#include <QScrollArea>
#include <QStringList>
+#include <QImageWriter>
#include <KAboutApplicationDialog>
#include <KAction>
#include <errno.h>
+#if QT_VERSION >= 0x041200
+static const QByteArray imageFormat = QImageWriter::defaultImageFormat();
+#else
+static const QByteArray imageFormat = "png";
+#endif
+
Skanlite::Skanlite(const QString &device, QWidget *parent)
: KDialog(parent)
{
// add the supported image types
m_filterList = KImageIO::mimeTypes(KImageIO::Writing);
- // Put first class citizens at first place
- m_filterList.removeAll("image/jpeg");
- m_filterList.removeAll("image/tiff");
- m_filterList.removeAll("image/png");
- m_filterList.insert(0, "image/png");
- m_filterList.insert(1, "image/jpeg");
- m_filterList.insert(2, "image/tiff");
-
- m_filter16BitList << "image/png";
- //m_filter16BitList << "image/tiff";
QStringList type;
foreach (const QString &mime , m_filterList) {
if (m_settingsUi.saveModeCB->currentIndex() != SaveModeAskFirst) m_firstImage = false;
m_settingsUi.saveDirLEdit->setText(saving.readEntry("Location", QDir::homePath()));
m_settingsUi.imgPrefix->setText(saving.readEntry("NamePrefix", i18nc("prefix for auto naming", "Image-")));
- m_settingsUi.imgFormat->setCurrentItem(saving.readEntry("ImgFormat", "png"));
+ m_settingsUi.imgFormat->setCurrentItem(saving.readEntry("ImgFormat", imageFormat));
m_settingsUi.imgQuality->setValue(saving.readEntry("ImgQuality", 90));
m_settingsUi.setQuality->setChecked(saving.readEntry("SetQuality", false));
m_settingsUi.showB4Save->setChecked(saving.readEntry("ShowBeforeSave", true));
QString prefix = m_saveLocation->u_imgPrefix->text();
QString type = m_saveLocation->u_imgFormat->currentText().toLower();
int fileNumber = m_saveLocation->u_numStartFrom->value();
- QStringList filterList = m_filterList;
- if ((m_format==KSaneIface::KSaneWidget::FormatRGB_16_C) ||
- (m_format==KSaneIface::KSaneWidget::FormatGrayScale16))
- {
- filterList = m_filter16BitList;
- if (type != "png") {
- type = "png";
- KMessageBox::information(this, i18n("The image will be saved in the PNG format, as Skanlite only supports saving 16 bit color images in the PNG format."));
- }
- }
-
// find next available file name for name suggestion
KUrl fileUrl;
if (m_settingsUi.saveModeCB->currentIndex() == SaveModeManual) {
// ask for a filename if requested.
m_saveDialog->setSelection(fileUrl.url());
- m_saveDialog->setMimeFilter(filterList, "image/"+type);
-
+#warning FIXME: bogus default MIME type for some image formats
+ m_saveDialog->setMimeFilter(m_filterList, "image/"+type);
do {
if (m_saveDialog->exec() != KFileDialog::Accepted) return;
}
// Save
- if ((m_format==KSaneIface::KSaneWidget::FormatRGB_16_C) ||
- (m_format==KSaneIface::KSaneWidget::FormatGrayScale16))
- {
- KSaneImageSaver saver;
- if (saver.savePngSync(fname, m_data, m_width, m_height, m_format)) {
- m_showImgDialog->close(); // closing the window if it is closed should not be a problem.
- }
- else {
- perrorMessageBox(i18n("Failed to save image"));
- }
+ // create the image if needed.
+ if (m_img.width() < 1) {
+ m_img = m_ksanew->toQImage(m_data, m_width, m_height, m_bytesPerLine, (KSaneIface::KSaneWidget::ImageFormat)m_format);
}
- else {
- // create the image if needed.
- if (m_img.width() < 1) {
- m_img = m_ksanew->toQImage(m_data, m_width, m_height, m_bytesPerLine, (KSaneIface::KSaneWidget::ImageFormat)m_format);
- }
- if (m_img.save(fname, 0, quality)) {
- m_showImgDialog->close(); // calling close() on a closed window does nothing.
- }
- else {
- perrorMessageBox(i18n("Failed to save image"));
- }
+ if (m_img.save(fname, 0, quality)) {
+ m_showImgDialog->close(); // calling close() on a closed window does nothing.
+ }
+ else {
+ perrorMessageBox(i18n("Failed to save image"));
}
if (!fileUrl.isLocalFile()) {
ImageViewer m_imageViewer;
QStringList m_filterList;
- QStringList m_filter16BitList;
QStringList m_typeList;
bool m_firstImage;
};