]> git.vomp.tv Git - vompclient.git/blob - wjpeg.h
Switch trunk code to new boxes
[vompclient.git] / wjpeg.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP 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.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifndef WJPEG_H
22 #define WJPEG_H
23
24 #include <stdio.h>
25 #include <malloc.h>
26 #ifndef WIN32
27 extern "C"
28 {
29   #include <jpeglib.h>
30 }
31 #else
32 //TODO find a replacement on WIN32
33 #endif
34
35 #include "boxx.h"
36
37 class Surface;
38
39 //a reader to be implemented by the caller
40 class JpegReader {
41   public:
42   //init reading the file
43   //return <=0 if error or size of image
44   virtual ULONG initRead(const char *filename)=0;
45   //read the next chunk of jpeg data
46   //offset - from start of file
47   //len I buf len (max bytes to read)
48   //return read len, 0 on EOF, -1 on error, *buf set to buffer
49   //will be released with free(!!!) after decoding
50   virtual ULONG readChunk(ULONG offset,ULONG len,char **buf)=0;
51   virtual ~JpegReader(){};
52 };
53
54 class WJpeg : public Boxx
55 {
56   public:
57   
58     // temp for boxx
59     void setSurface(Surface* tsurface) {};
60     void setDimensions(int width, int height) {};
61     void setBackgroundColour(Colour& colour) {};
62   
63   
64     WJpeg();
65     virtual ~WJpeg();
66     int init(char* fileName, bool useImage=true, JpegReader *rdr=NULL);
67     //rotate (with next draw!) by 90/180/270
68     void setRotate(int amount);
69     static const int ROT_0=0;
70     static const int ROT_90=1;
71     static const int ROT_180=2;
72     static const int ROT_270=3;
73     void draw();
74     bool hasError();
75     /**
76       * get an integer info from the current picture
77       */
78     ULONG getJpegInfo(ULONG tag);
79     //in tags
80     static const ULONG JPEG_WIDTH=1;   //picture width
81     static const ULONG JPEG_HEIGHT=2;  //picture height
82     static const ULONG JPEG_SIZE=3;    //picture (compressed) size
83     static const ULONG JPEG_ROTATE=4;  //rotate setting
84     static const ULONG JPEG_SCALE=5;   //scale setting (1/n)
85     /**
86       * get a string info from the picture
87       * the user must provide a buffer of
88       * INFO_BUFFER size
89       */
90     int getJpegInfo(ULONG tag, char * buffer);
91     static const int INFO_BUFFER=200;
92     //string info tags
93     static const ULONG JPEG_FILENAME=100; //abbreviated filename
94
95   private:
96     int drawJpeg();
97     //our drawPixel with considers rotation
98     void  drawPixel(int x, int y,int w,int h,int xpos, int ypos,Colour c);
99     char* fileName;
100     JpegReader *reader;
101     bool useImageDimensions;
102     ULONG jsize;
103     ULONG jheight;
104     ULONG jwidth;
105     ULONG jscale;
106     bool jerror;
107     int rotate;
108 };
109
110 #endif