1/**
2 * PIC_RW - Qt PIC Support
3 * Copyright (C) 2007 Ruben Lopez <r.lopez@bren.es>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser 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.
9 *
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 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * ----------------------------------------------------------------------------
19 */
20
21/* This code is based on the GIMP-PIC plugin by Halfdan Ingvarsson,
22 * and relicensed from GPL to LGPL to accomodate the KDE licensing policy
23 * with his permission.
24 * These is the original copyright:
25 * Copyright (C) 1998 Halfdan Ingvarsson
26 */
27
28#ifndef __PIC_RW_H__
29#define __PIC_RW_H__
30
31#define PIC_MAGIC_NUMBER 0x5380f634
32
33#include <QtCore/QFile>
34#include <QtGui/QImageIOPlugin>
35#include <QtGui/QColor>
36
37/**
38 * How fields are distributed over the image
39 */
40typedef enum {
41 NONE = 0, /* No picture */
42 ODD = 1, /* Odd scanlines */
43 EVEN = 2, /* Even scanlines */
44 BOTH = 3 /* Every scanline */
45} PICFields;
46
47/**
48 * Type of a channel
49 */
50typedef enum {
51 UNCOMPRESSED = 0, /* Image is uncompressed */
52 RLE = 2 /* Run length compression */
53} PICChannelType;
54
55/**
56 * Channel codes
57 */
58typedef enum {
59 RED = 0x80, /* Red channel */
60 GREEN = 0x40, /* Green channel */
61 BLUE = 0x20, /* Blue channel */
62 ALPHA = 0x10 /* Alpha channel */
63} PICChannelCode;
64
65/**
66 * PIC format header
67 */
68typedef struct {
69 qint32 magic; /* PIC_MAGIC_NUMBER */
70 float version; /* Version of format */
71 char comment[80]; /* Prototype description */
72 char id[4]; /* "PICT" */
73 qint16 width; /* Image width, in pixels */
74 qint16 height; /* Image height, in pixels */
75 float ratio; /* Pixel aspect ratio */
76 qint16 fields; /* Picture field type */
77 qint16 pad; /* Unused */
78} PICHeader;
79
80/**
81 * PIC channel header
82 */
83typedef struct {
84 char chained; /* 1 if another packet follows, else 0 */
85 char size; /* Bits per pixel by channel */
86 char type; /* RLE or uncompressed */
87 char channel; /* Channel code (which planes are affected by this channel) */
88} PICChannel;
89
90#define HEADER_SIZE sizeof(PICHeader)
91#define CHANNEL_SIZE sizeof(PICChannel)
92
93
94/**
95 * Reads the PIC header and checks that it is OK
96 * @param dev The QT device to read from
97 * @param hdr A pointer to the PIC header
98 * @param peek Keep bytes in the device
99 * @return true on success
100 */
101bool picReadHeader(QIODevice *dev, PICHeader *hdr, bool peek = false);
102
103/// Pic read handler for Qt / KDE
104void pic_read(QIODevice *dev, QImage *img);
105
106/// Pic write handler for Qt / KDE
107void pic_write(QIODevice *dev, const QImage *img);
108
109
110#endif//__PIC_RW_H__
111