summaryrefslogtreecommitdiffstats
path: root/ksquirrel/imageedit/sq_converter.h
blob: 8a7d1ecc0aa3f9f2aea08dc09e16f139eec7bfca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/***************************************************************************
                          sq_converter.h  -  description
                             -------------------
    begin                : ??? Mar 3 2005
    copyright            : (C) 2005 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SQ_CONVERTER_H
#define SQ_CONVERTER_H

#include <tqobject.h>
#include <tqstringlist.h>

#include <sstream>
#include <csetjmp>

#include <ksquirrel-libs/fmt_utils.h>
#include <ksquirrel-libs/fmt_codec_base.h>
#include <ksquirrel-libs/error.h>

#include "sq_imageedit.h"

struct SQ_LIBRARY;

class KTempFile;

class SQ_ImageConvert;
class SQ_ImageConvertOptions;

/*
 *  Base class for all edit tools. It contains all methods needed by
 *  converter, resizer, printer etc. It decodes an image, writes it back to
 *  disk. All specific actions (like colorizing, resizing etc.) are done by
 *  appropriate edit tool.
 */

class SQ_Converter : public TQObject
{
    Q_OBJECT
  TQ_OBJECT

    public:
        SQ_Converter(TQObject *tqparent);
        ~SQ_Converter();

    public:
         static SQ_Converter* instance() { return m_sing; }

    private:
        /*
         *  Create edit tool-specific dialog, and wait for user
         *  input
         */
        void startEditPrivate();

        /*
         *  Do something with decoded image(manipDecodedImage()) and write it
         *  on disk.
         */
        int manipAndWriteDecodedImage(const TQString &name, fmt_image *im);

        /*
         *  Main decoding loop.
         */
        void decodingCycle();

        /*
         *  Determine file name. In this file SQ_Converter will save new image.
         */
        TQString adjustFileName(const TQString &globalprefix, const TQString &name, int replace,
                    TQString putto, bool paged = false, int page = 0);

        void determineNextScan(const fmt_image &im, RGBA *scan, int y);

        /*
         *  Copy file :-)
         */
        int copyFile(const TQString &src, const TQString &dst) const;

        void errorjmp(jmp_buf jmp, const int code);

    signals:
        void convertText(const TQString &, bool);
        void oneFileProcessed();
        void done(bool allok);

    private slots:
        void slotStartEdit();
        void slotStartConvert(SQ_ImageOptions*, SQ_ImageConvertOptions*);

    protected:
        TQStringList         files;
        TQString             err_internal, err_failed;
        TQString             currentFile;
        int                 error_code, current_page;
        SQ_ImageOptions     imageopt;
        fmt_writeoptions    opt;
        SQ_LIBRARY          *lr, *lw, *altw;
        RGBA                *image;
        TQString             special_action, prefix;
        bool                multi, last, lastFrame;
        KTempFile           *tempfile;
        fmt_image           *im;
        static SQ_Converter    *m_sing;

        SQ_ImageConvert    *convert;
        SQ_ImageConvertOptions convopt;
};

#endif