2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #ifndef WJPEGCOMPLEX_H
\r
22 #define WJPEGCOMPLEX_H
\r
24 // This is the complex jpeg readeing stuff not supported on all plattforms
\r
32 #include <winsock2.h>
\r
33 #include <windows.h>
\r
36 //#define NEED_FAR_POINTERS
\r
37 #define XMD_H //workaround some compiling issues
\r
43 //a reader to be implemented by the caller
\r
46 //read the next chunk of jpeg data
\r
47 //offset - from start of file
\r
48 //len I buf len (max bytes to read)
\r
49 //return read len, 0 on EOF, -1 on error, *buf set to buffer
\r
50 //will be released with free(!!!) after decoding
\r
51 virtual ULONG readChunk(ULONG offset,ULONG len,char **buf)=0;
\r
52 //a callback when the drawing is complete
\r
53 //the implementation is optional
\r
54 virtual void drawingDone(){};
\r
55 //get the size of the current picture
\r
56 virtual ULONG getSize(){ return 0;}
\r
57 virtual ~JpegReader(){};
\r
59 class WJpegComplex : public WJpeg
\r
64 void setDimensions(int width, int height) {area.w=width;area.h=height;};
\r
68 virtual ~WJpegComplex();
\r
69 //old style usage - load local file
\r
70 //the sequence is init(filename), draw
\r
71 //the new usage is drawJpeg (with having the right offsets computed)
\r
72 int init(const char* fileName);
\r
77 //mode for scaling pictures
\r
90 struct JpegControl {
\r
92 //the available drawing area
\r
95 //the maximum allowed scale factor after decompress
\r
98 enum ScaleMode mode;
\r
99 //the size value if scaleMode==cropPercent
\r
100 //%of the drawing area size
\r
102 //the rotation (user defined as input)
\r
103 //if exif rotation is found this will be added
\r
104 enum Rotation rotation;
\r
106 //paremeters filled during Jpeg parsing
\r
107 enum Rotation exifRotation;
\r
112 ULONG compressedSize;
\r
114 //parameters computed to display picture
\r
115 enum Rotation finalRotation;
\r
128 exifRotation=ROT_0;
\r
129 finalRotation=ROT_0;
\r
139 //the standalone drawing function
\r
140 //this will draw into the provided surface
\r
141 //the reader has to be initialized before
\r
142 //calling this function does not need a WJpeg being instantiated
\r
143 //it simply draws into the surface
\r
144 bool static drawJpeg(JpegControl * control, Surface* sfc, JpegReader *rdr, Colour & backgroundColour);
\r
147 //our drawPixel with considers rotation
\r
148 /* handle picture rotation
\r
156 #ifndef __ANDROID__
\r
157 inline static void drawPixel(Surface * sfc,enum Rotation rotate,int x, int y,int w,int h,int xpos, int ypos,Colour c){
\r
180 if (xb < 0 || yb < 0 ) {
\r
183 sfc->drawPixel((UINT)xb,(UINT)yb,c,true);
\r
187 draw a line of pixels coming from the decompressor
\r
188 if scaleafter > 1 we draw that many lines (numlines is the# lines in the buffer)
\r
189 picturew is the resulting width of the picture
\r
191 inline static void drawLine(Surface *sfc,enum Rotation rotate, unsigned char *cp,UINT scaleafter,UINT picturew,UINT pictureh,
\r
192 UINT xpos, UINT ypos, UINT outy, UINT linelen,UINT pixeloffset, UINT numlines, UINT fac) {
\r
194 for (UINT x = 0; x < picturew; x++)
\r
196 if (scaleafter > 1 ) {
\r
197 //boxfilter scalefactor*scalefactor
\r
198 //take 0...scalefactor pixels in x and y direction
\r
199 for (int colornum=0;colornum<3;colornum++) {
\r
201 unsigned char * accp=cp;
\r
202 for (UINT rows=0;rows<scaleafter;rows++) {
\r
203 unsigned char * pp=accp;
\r
204 for (UINT cols=0;cols<scaleafter;cols++) {
\r
206 if (pp-accp < (int)linelen-3) pp+=3;
\r
208 if (rows < numlines) accp+=linelen;
\r
210 comp=(comp*fac) >> 10;
\r
211 if (colornum == 0) c.red=comp;
\r
212 if (colornum == 1) c.green=comp;
\r
213 if (colornum == 2) c.blue=comp;
\r
220 c.green = *cp;cp++;
\r
224 drawPixel(sfc,rotate,x, outy, picturew,pictureh,xpos,ypos,c);
\r
228 //find my own surface and fill the area with my x and y offset within
\r
229 Surface * getSurface(Region &a);
\r
231 JpegReader *reader;
\r