2 Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
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.
36 #include "teletextdecodervbiebu.h"
38 enum SVGCommandInstr {
64 typedef VectorHandle ImageIndex;
65 typedef unsigned long long LoadIndex;
74 reference = VECTOR_HANDLE_INIT;
77 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
85 nc.target.path_index=path;
90 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, VectorHandle ref, Corner corner = TopLeft)
93 nc.instr=DrawImageLoading;
98 nc.target.loadindex=load_in;
104 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
112 nc.target.image=image_in;
120 inline static SVGCommand PaintTTchar(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
129 nc.target.ttchar=ttchar_in;
133 inline static SVGCommand PaintClipping(float ix, float iy,float iw,float ih)
136 nc.instr=DrawClipping;
147 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
155 nc.target.textchar=char_in;
158 bool Test(float tx,float ty,float tw, float th)
160 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
162 bool TTTest(float tox,float toy,float tx, float ty)
164 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
166 bool Outside(float tx,float ty,float tw, float th)
168 return ((x+w)<tx) || ((y+h)<ty) || ((tx+tw) < x) || ((ty+th) < y);
171 VectorHandle getRef(){ return reference; };
172 ImageIndex getImageIndex() {
173 if (instr!=DrawImage) return 0;
174 else return target.image;
176 LoadIndex getLoadIndex() {
177 if (instr!=DrawImageLoading) return 0;
178 else return target.loadindex;
181 SVGCommandInstr instr;
184 VectorHandle reference;
186 PathIndex path_index; //path_index
197 class VDR_ResponsePacket;
199 struct SurfaceCommands{
200 const SurfaceVector* surf;
201 vector<SVGCommand> commands;
206 class OsdVector : public Osd
210 virtual ~OsdVector();
217 void screenShot(const char* fileName);
218 virtual bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/)=0;
220 Surface * createNewSurface();
223 virtual void updateBackgroundColor(DrawStyle bg) {};
225 void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
226 std::vector<SVGCommand>& commands);
227 void removeSurface(const SurfaceVector *surf);
229 virtual float getFontHeight()=0;
230 virtual float getCharWidth(wchar_t c)=0;
231 float *getCharWidthArray() {return byte_char_width;};
233 //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
234 virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia,ImageIndex& image);
235 virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
236 virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
239 virtual bool getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)=0;
241 void removeImageRef(const ImageIndex ref);
242 void removeLoadIndexRef(const LoadIndex ref);
243 VectorHandle getStyleRef(const DrawStyle &c);
244 virtual void removeStyleRef(VectorHandle ref);
245 virtual void getScreenSize(int &width, int &height)=0;
246 virtual void getRealScreenSize(int &width, int &height)=0;
248 // should be only called from command thread
249 void informPicture(LoadIndex index, ImageIndex i_index);
254 int charSet() {return 2;}; //UTF-8
257 class PictureDecoder;
274 PictureDecoder* decoder;
283 PictureDecoder(PictureReader * treader) {reader=treader;};
284 virtual ~PictureDecoder() {};
286 // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
287 virtual unsigned char * decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem=true)=0;
289 virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
290 virtual void freeReference(void * ref)=0;
292 virtual void init() {};
293 virtual void shutdown() {};
296 PictureReader * reader;
299 class PictureReader: public Thread_TYPE {
305 void addDecoder(PictureDecoder*);
306 void removeDecoder(PictureDecoder*);
311 bool processReceivedPictures();
313 // should be called from command thread
314 void receivePicture(VDR_ResponsePacket *vresp);
316 void addStaticImage(unsigned int id);
318 void invalidateLoadIndex(LoadIndex index);
320 void informFallback(LoadIndex index, int fallback);
328 void threadPostStopCleanup();
330 Mutex pict_lock_incoming; //locks
332 std::queue<VDR_ResponsePacket*> pict_incoming;
333 std::queue<unsigned int> pict_incoming_static;
334 std::list<PictureDecoder*> decoders;
335 std::map<LoadIndex,int> inform_fallback;
336 set<LoadIndex> invalid_loadindex;
342 PictureReader *getPictReader() { return &reader;};
348 PictureReader reader;
350 void incImageRef(ImageIndex index);
351 int getImageRef(ImageIndex index);
352 virtual void destroyImageRef(ImageIndex index)=0;
353 void incLoadIndexRef(LoadIndex index);
354 int getLoadIndexRef(LoadIndex index);
357 //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
358 virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
359 virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
360 virtual void createPicture(struct PictureInfo& pict_inf)=0;
362 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
366 map<ImageIndex,int> images_ref;
367 map<void *,ImageIndex> monobitmaps;
368 //map<string,ImageIndex> jpegs;
369 map<TVMediaInfo,ImageIndex> tvmedias;
370 list<ImageIndex> palettepics;
374 map<LoadIndex,int> loadindex_ref;
375 map<TVMediaInfo,LoadIndex> tvmedias_load;
376 map<LoadIndex,TVMediaInfo> tvmedias_load_inv;
377 map<LoadIndex,ImageIndex> tvmedias_loaded;
381 void incStyleRef(VectorHandle index);
382 int getStyleRef(VectorHandle index);
383 virtual void destroyStyleRef(VectorHandle index) = 0;
386 map<DrawStyle, VectorHandle> styles;
387 map<VectorHandle, int> styles_ref;
388 map<DrawStyle, VectorHandle>::iterator styles_lastit;
389 bool styles_lastit_valid;
390 map<VectorHandle, int>::iterator styles_ref_lastit;
391 bool styles_ref_lastit_valid;
393 virtual VectorHandle createStyleRef(const DrawStyle &c) = 0;
395 void dereferenceSVGCommand(std::vector<SVGCommand>& commands );
396 void referenceSVGCommand(std::vector<SVGCommand>& commands );
397 void cleanupOrphanedRefs();
401 virtual void drawSetTrans(SurfaceCommands & sc)=0;
402 virtual void executeDrawCommand(SVGCommand & command)=0;
407 std::list<SurfaceCommands> scommands;
409 Mutex surfaces_mutex;
411 float byte_char_width[256];