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.
33 //#define NEED_FAR_POINTERS
34 #define XMD_H //workaround some compiling issues
40 //a reader to be implemented by the caller
43 //read the next chunk of jpeg data
44 //offset - from start of file
45 //len I buf len (max bytes to read)
46 //return read len, 0 on EOF, -1 on error, *buf set to buffer
47 //will be released with free(!!!) after decoding
48 virtual ULONG readChunk(ULONG offset,ULONG len,char **buf)=0;
49 //a callback when the drawing is complete
50 //the implementation is optional
51 virtual void drawingDone(){};
52 //get the size of the current picture
53 virtual ULONG getSize(){ return 0;}
54 virtual ~JpegReader(){};
56 class WJpeg : public Boxx
61 void setDimensions(int width, int height) {area.w=width;area.h=height;};
66 //old style usage - load local file
67 //the sequence is init(filename), draw
68 //the new usage is drawJpeg (with having the right offsets computed)
69 int init(char* fileName);
74 //mode for scaling pictures
89 //the available drawing area
92 //the maximum allowed scale factor after decompress
96 //the size value if scaleMode==cropPercent
97 //%of the drawing area size
99 //the rotation (user defined as input)
100 //if exif rotation is found this will be added
101 enum Rotation rotation;
103 //paremeters filled during Jpeg parsing
104 enum Rotation exifRotation;
109 ULONG compressedSize;
111 //parameters computed to display picture
112 enum Rotation finalRotation;
136 //the standalone drawing function
137 //this will draw into the provided surface
138 //the reader has to be initialized before
139 //calling this function does not need a WJpeg being instantiated
140 //it simply draws into the surface
141 bool static drawJpeg(JpegControl * control, Surface* sfc, JpegReader *rdr, Colour & backgroundColour);
144 //our drawPixel with considers rotation
145 /* handle picture rotation
153 inline static void drawPixel(Surface * sfc,enum Rotation rotate,int x, int y,int w,int h,int xpos, int ypos,Colour c){
176 if (xb < 0 || yb < 0 ) {
179 sfc->drawPixel((UINT)xb,(UINT)yb,c,true);
183 draw a line of pixels coming from the decompressor
184 if scaleafter > 1 we draw that many lines (numlines is the# lines in the buffer)
185 picturew is the resulting width of the picture
187 inline static void drawLine(Surface *sfc,enum Rotation rotate, unsigned char *cp,UINT scaleafter,UINT picturew,UINT pictureh,
188 UINT xpos, UINT ypos, UINT outy, UINT linelen,UINT pixeloffset, UINT numlines, UINT fac) {
190 for (UINT x = 0; x < picturew; x++)
192 if (scaleafter > 1 ) {
193 //boxfilter scalefactor*scalefactor
194 //take 0...scalefactor pixels in x and y direction
195 for (int colornum=0;colornum<3;colornum++) {
197 unsigned char * accp=cp;
198 for (UINT rows=0;rows<scaleafter;rows++) {
199 unsigned char * pp=accp;
200 for (UINT cols=0;cols<scaleafter;cols++) {
202 if (pp-accp < (int)linelen-3) pp+=3;
204 if (rows < numlines) accp+=linelen;
206 comp=(comp*fac) >> 10;
207 if (colornum == 0) c.red=comp;
208 if (colornum == 1) c.green=comp;
209 if (colornum == 2) c.blue=comp;
220 drawPixel(sfc,rotate,x, outy, picturew,pictureh,xpos,ypos,c);
223 //find my own surface and fill the area with my x and y offset within
224 Surface * getSurface(Region &a);