]> git.vomp.tv Git - vompclient.git/blob - wjpeg.h
Media Player From Andreas Vogel
[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 "log.h"
36 #include "widget.h"
37 #include "surface.h"
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 Widget
55 {
56   public:
57     WJpeg();
58     virtual ~WJpeg();
59     int init(char* fileName, bool useImage=true, JpegReader *rdr=NULL);
60     //rotate (with next draw!) by 90/180/270
61     void setRotate(int amount);
62     static const int ROT_0=0;
63     static const int ROT_90=1;
64     static const int ROT_180=2;
65     static const int ROT_270=3;
66     void draw();
67     bool hasError();
68     /**
69       * get an integer info from the current picture
70       */
71     ULONG getJpegInfo(ULONG tag);
72     //in tags
73     static const ULONG JPEG_WIDTH=1;   //picture width
74     static const ULONG JPEG_HEIGHT=2;  //picture height
75     static const ULONG JPEG_SIZE=3;    //picture (compressed) size
76     static const ULONG JPEG_ROTATE=4;  //rotate setting
77     static const ULONG JPEG_SCALE=5;   //scale setting (1/n)
78     /**
79       * get a string info from the picture
80       * the user must provide a buffer of
81       * INFO_BUFFER size
82       */
83     int getJpegInfo(ULONG tag, char * buffer);
84     static const int INFO_BUFFER=200;
85     //string info tags
86     static const ULONG JPEG_FILENAME=100; //abbreviated filename
87
88   private:
89     int drawJpeg();
90     //our drawPixel with considers rotation
91     void  drawPixel(int x, int y,int w,int h,int xpos, int ypos,Colour c);
92     char* fileName;
93     JpegReader *reader;
94     bool useImageDimensions;
95     ULONG jsize;
96     ULONG jheight;
97     ULONG jwidth;
98     ULONG jscale;
99     bool jerror;
100     int rotate;
101 };
102
103 #endif