]> git.vomp.tv Git - vompclient.git/blob - wjpeg.h
Sleep timer
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef WJPEG_H
22 #define WJPEG_H
23
24 #include <stdio.h>
25 #include <malloc.h>
26
27 #ifdef WIN32
28
29 #include <winsock2.h>
30 #include <windows.h>
31
32
33 //#define NEED_FAR_POINTERS
34 #define XMD_H //workaround some compiling issues
35 #endif
36
37 //#ifndef WIN32
38 extern "C"
39 {
40   #include <jpeglib.h>
41 }
42 /*#else
43 //TODO find a replacement on WIN32
44 #endif*/
45
46 class Surface;
47 class Boxx;
48
49 //a reader to be implemented by the caller
50 class JpegReader {
51   public:
52   //init reading the file
53   //return <=0 if error or size of image
54   virtual ULONG initRead(const char *filename)=0;
55   //read the next chunk of jpeg data
56   //offset - from start of file
57   //len I buf len (max bytes to read)
58   //return read len, 0 on EOF, -1 on error, *buf set to buffer
59   //will be released with free(!!!) after decoding
60   virtual ULONG readChunk(ULONG offset,ULONG len,char **buf)=0;
61   virtual ~JpegReader(){};
62 };
63 #ifdef WIN32
64 class WindowsResourceJpegReader: public JpegReader {
65   public:
66   virtual ULONG initRead(const char *filename);
67   virtual ULONG readChunk(ULONG offset,ULONG len,char **buf);
68   virtual ~WindowsResourceJpegReader();
69 protected:
70   HGLOBAL hres;
71   LPVOID buffer;
72   DWORD size;
73 };
74 #endif
75
76 class WJpeg : public Boxx
77 {
78   public:
79   
80     // temp for boxx
81     void setDimensions(int width, int height) {area.w=width;area.h=height;};
82   
83   
84     WJpeg();
85     virtual ~WJpeg();
86     int init(char* fileName, bool useImage=true, JpegReader *rdr=NULL);
87     //rotate (with next draw!) by 90/180/270
88     void setRotate(int amount);
89     static const int ROT_0=0;
90     static const int ROT_90=1;
91     static const int ROT_180=2;
92     static const int ROT_270=3;
93     void draw();
94     bool hasError();
95     /**
96       * get an integer info from the current picture
97       */
98     ULONG getJpegInfo(ULONG tag);
99     //in tags
100     static const ULONG JPEG_WIDTH=1;   //picture width
101     static const ULONG JPEG_HEIGHT=2;  //picture height
102     static const ULONG JPEG_SIZE=3;    //picture (compressed) size
103     static const ULONG JPEG_ROTATE=4;  //rotate setting
104     static const ULONG JPEG_SCALE=5;   //scale setting (1/n)
105     /**
106       * get a string info from the picture
107       * the user must provide a buffer of
108       * INFO_BUFFER size
109       */
110     int getJpegInfo(ULONG tag, char * buffer);
111     static const int INFO_BUFFER=200;
112     //string info tags
113     static const ULONG JPEG_FILENAME=100; //abbreviated filename
114
115   private:
116     int drawJpeg();
117     //our drawPixel with considers rotation
118     void  drawPixel(int x, int y,int w,int h,int xpos, int ypos, const Colour& c);
119     char* fileName;
120     JpegReader *reader;
121 #ifdef WIN32
122     WindowsResourceJpegReader winread;
123 #endif
124     bool useImageDimensions;
125     ULONG jsize;
126     ULONG jheight;
127     ULONG jwidth;
128     ULONG jscale;
129     bool jerror;
130     int rotate;
131 };
132
133 #endif