1
// vim: set tabstop=4 shiftwidth=4 noexpandtab
3
Gwenview - A simple image viewer for KDE
4
Copyright 2000-2004 Aur�lien G�teau
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include <string.h> // For memcpy
26
#if QT_VERSION>=0x030100
27
#include <qeventloop.h>
31
#include <kapplication.h>
35
#include <kmessagebox.h>
39
#include "gvjpegtran.moc"
43
#define LOG(x) kdDebug() << k_funcinfo << x << endl
48
const char* CONFIG_PROGRAM_PATH="path";
49
const unsigned int CHUNK_SIZE=1024;
51
static QString sProgramPath;
54
GVJPEGTran::GVJPEGTran()
57
void GVJPEGTran::writeChunk(KProcess* process) {
60
if (mSent>=mSrc.size()) {
62
process->closeStdin();
65
unsigned int size=QMIN(mSrc.size()-mSent, CHUNK_SIZE);
66
LOG("sending " << size << " bytes");
67
process->writeStdin( mSrc.data() + mSent, size );
71
void GVJPEGTran::slotReceivedStdout(KProcess*,char* data,int length) {
72
LOG("size:" << length);
73
uint oldSize=mDst.size();
74
mDst.resize(oldSize+length);
75
memcpy(mDst.data()+oldSize,data,length);
79
void GVJPEGTran::slotReceivedStderr(KProcess* process,char* data, int length) {
80
LOG("size:" << length);
81
kdWarning() << "Error: " << QCString(data,length) << endl;
87
void GVJPEGTran::slotProcessExited() {
89
#if QT_VERSION<0x030100
92
kapp->eventLoop()->exitLoop();
96
QByteArray GVJPEGTran::apply(const QByteArray& src,GVImageUtils::Orientation orientation) {
99
process << sProgramPath << "-copy" << "all";
101
switch (orientation) {
102
case GVImageUtils::HFLIP:
103
process << "-flip" << "horizontal";
105
case GVImageUtils::ROT_180:
106
process << "-rotate" << "180";
108
case GVImageUtils::VFlip:
109
process << "-flip" << "vertical";
111
case GVImageUtils::ROT_90_HFLIP:
112
process << "-transpose";
114
case GVImageUtils::ROT_90:
115
process << "-rotate" << "90";
117
case GVImageUtils::ROT_90_VFLIP:
118
process << "-transverse";
120
case GVImageUtils::ROT_270:
121
process << "-rotate" << "270";
127
connect(&process,SIGNAL(wroteStdin(KProcess*)),
128
&obj,SLOT(writeChunk(KProcess*)) );
130
connect(&process,SIGNAL(receivedStdout(KProcess*,char*,int)),
131
&obj,SLOT(slotReceivedStdout(KProcess*,char*,int)) );
133
connect(&process,SIGNAL(receivedStderr(KProcess*,char*,int)),
134
&obj,SLOT(slotReceivedStderr(KProcess*,char*,int)) );
136
connect(&process,SIGNAL(processExited(KProcess*)),
137
&obj,SLOT(slotProcessExited()) );
139
// Return an empty QByteArray on failure. GVDocument will thus consider the
140
// buffer as invalid and will fall back to lossy manipulations.
141
if ( !process.start(KProcess::NotifyOnExit, KProcess::All) ) {
142
KMessageBox::information(0L,
143
i18n("Gwenview couldn't perform lossless image manipulation.\n"
144
"Make sure that the jpegtran program is installed and that "
145
"its path in the configuration dialog is correct"
146
),QString::null,"jpegtran failed");
152
obj.writeChunk(&process);
154
kapp->setOverrideCursor(QCursor(WaitCursor));
155
#if QT_VERSION<0x030100
158
kapp->eventLoop()->enterLoop();
160
kapp->restoreOverrideCursor();
166
//---------------------------------------------------------------------------
170
//---------------------------------------------------------------------------
171
void GVJPEGTran::readConfig(KConfig* config, const QString& group) {
172
config->setGroup(group);
173
sProgramPath=config->readEntry(CONFIG_PROGRAM_PATH,"jpegtran");
177
void GVJPEGTran::writeConfig(KConfig* config, const QString& group) {
178
config->setGroup(group);
179
config->writeEntry(CONFIG_PROGRAM_PATH,sProgramPath);
183
void GVJPEGTran::setProgramPath(const QString& path) {
188
QString GVJPEGTran::programPath() {