2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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.
21 #ifndef WJPEGCOMPLEX_H
22 #define WJPEGCOMPLEX_H
24 // This is the complex jpeg readeing stuff not supported on all plattforms
38 //#define NEED_FAR_POINTERS
39 #define XMD_H //workaround some compiling issues
45 //a reader to be implemented by the caller
48 //read the next chunk of jpeg data
49 //offset - from start of file
50 //len I buf len (max bytes to read)
51 //return read len, 0 on EOF, -1 on error, *buf set to buffer
52 //will be released with free(!!!) after decoding
53 virtual ULONG readChunk(ULONG offset,ULONG len,char **buf)=0;
54 //a callback when the drawing is complete
55 //the implementation is optional
56 virtual void drawingDone(){};
57 //get the size of the current picture
58 virtual ULONG getSize(){ return 0;}
59 virtual ~JpegReader(){};
61 class WJpegComplex : public WJpeg
66 void setDimensions(int width, int height) {area.w=width;area.h=height;};
70 virtual ~WJpegComplex();
71 //old style usage - load local file
72 //the sequence is init(filename), draw
73 //the new usage is drawJpeg (with having the right offsets computed)
74 int init(const char* fileName);
79 //mode for scaling pictures
94 //the available drawing area
97 //the maximum allowed scale factor after decompress
101 //the size value if scaleMode==cropPercent
102 //%of the drawing area size
104 //the rotation (user defined as input)
105 //if exif rotation is found this will be added
106 enum Rotation rotation;
108 //paremeters filled during Jpeg parsing
109 enum Rotation exifRotation;
114 ULONG compressedSize;
116 //parameters computed to display picture
117 enum Rotation finalRotation;
141 //the standalone drawing function
142 //this will draw into the provided surface
143 //the reader has to be initialized before
144 //calling this function does not need a WJpeg being instantiated
145 //it simply draws into the surface
146 bool static drawJpeg(JpegControl * control, Surface* sfc, JpegReader *rdr, DrawStyle & backgroundColour);
149 //our drawPixel with considers rotation
150 /* handle picture rotation
159 inline static void drawPixel(Surface * sfc,enum Rotation rotate,int x, int y,int w,int h,int xpos, int ypos,Colour c){
182 if (xb < 0 || yb < 0 ) {
185 sfc->drawPixel((UINT)xb,(UINT)yb,c,true);
189 draw a line of pixels coming from the decompressor
190 if scaleafter > 1 we draw that many lines (numlines is the# lines in the buffer)
191 picturew is the resulting width of the picture
193 inline static void drawLine(Surface *sfc,enum Rotation rotate, unsigned char *cp,UINT scaleafter,UINT picturew,UINT pictureh,
194 UINT xpos, UINT ypos, UINT outy, UINT linelen,UINT pixeloffset, UINT numlines, UINT fac) {
196 for (UINT x = 0; x < picturew; x++)
198 if (scaleafter > 1 ) {
199 //boxfilter scalefactor*scalefactor
200 //take 0...scalefactor pixels in x and y direction
201 for (int colornum=0;colornum<3;colornum++) {
203 unsigned char * accp=cp;
204 for (UINT rows=0;rows<scaleafter;rows++) {
205 unsigned char * pp=accp;
206 for (UINT cols=0;cols<scaleafter;cols++) {
208 if (pp-accp < (int)linelen-3) pp+=3;
210 if (rows < numlines) accp+=linelen;
212 comp=(comp*fac) >> 10;
213 if (colornum == 0) c.red=comp;
214 if (colornum == 1) c.green=comp;
215 if (colornum == 2) c.blue=comp;
226 drawPixel(sfc,rotate,x, outy, picturew,pictureh,xpos,ypos,c);
230 //find my own surface and fill the area with my x and y offset within
231 Surface * getSurface(Region &a);