1 /* This file is part of the KDE libraries
2 Copyright (C) 2001 Malte Starostik <malte@kde.org>
3 Copyright (C) 2001 Leon Bottou <leon@bottou.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "djvucreator.h"
24 #include <config-runtime.h>
30 #ifdef HAVE_SYS_SELECT_H
31 #include <sys/select.h>
41 #include <kdemacros.h>
47 KDE_EXPORT ThumbCreator
*new_creator()
49 return new DjVuCreator
;
53 bool DjVuCreator::create(const QString
&path
, int width
, int height
, QImage
&img
)
56 QByteArray
data(1024, 'k');
59 if (pipe(output
) == -1)
63 QByteArray sizearg
, fnamearg
;
64 sizearg
= QByteArray::number(width
) + 'x' + QByteArray::number(height
);
65 fnamearg
= QFile::encodeName( path
);
70 argv
[4] = sizearg
.data();
71 argv
[5] = fnamearg
.data();
78 dup2(output
[1], STDOUT_FILENO
);
79 execvp(argv
[0], const_cast<char *const *>(argv
));
89 FD_SET(output
[0], &fds
);
93 if (select(output
[0] + 1, &fds
, 0, 0, &tv
) <= 0) {
94 if (errno
== EINTR
|| errno
== EAGAIN
)
96 break; // error or timeout
98 if (FD_ISSET(output
[0], &fds
)) {
99 int count
= read(output
[0], data
.data() + offset
, 1024);
102 if (count
) // prepare for next block
105 data
.resize(offset
+ 1024);
117 if (waitpid(pid
, &status
, 0) != pid
|| (status
!= 0 && status
!= 256) )
126 int l
= img
.loadFromData( data
);
131 ThumbCreator::Flags
DjVuCreator::flags() const
133 return static_cast<Flags
>(DrawFrame
);