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, see <https://www.gnu.org/licenses/>.
35 #include "teletextdecodervbiebu.h"
37 enum SVGCommandInstr {
63 typedef VectorHandle ImageIndex;
64 typedef unsigned long long LoadIndex;
73 reference = VECTOR_HANDLE_INIT;
76 inline static SVGCommand PaintPath(float ix, float iy, float iw, float ih, PathIndex path, VectorHandle ref)
84 nc.target.path_index=path;
89 inline static SVGCommand PaintImageLoading(LoadIndex load_in, float ix, float iy, float iw, float ih, VectorHandle ref, Corner corner = TopLeft)
92 nc.instr=DrawImageLoading;
97 nc.target.loadindex=load_in;
103 inline static SVGCommand PaintImage(float ix, float iy, float iw, float ih, ImageIndex image_in, VectorHandle ref, Corner corner = TopLeft)
111 nc.target.image=image_in;
119 inline static SVGCommand PaintTTchar(float ix, float iy,float iw,float ih,unsigned int ttchar_in)
128 nc.target.ttchar=ttchar_in;
132 inline static SVGCommand PaintClipping(float ix, float iy,float iw,float ih)
135 nc.instr=DrawClipping;
146 inline static void PaintGlyph(SVGCommand& nc, float ix, float iy, wchar_t char_in, VectorHandle ref)
154 nc.target.textchar=char_in;
157 bool Test(float tx,float ty,float tw, float th)
159 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));
161 bool TTTest(float tox,float toy,float tx, float ty)
163 return (x==tox) && (toy==y) && (w==tx) && (h==ty);
165 bool Outside(float tx,float ty,float tw, float th)
167 return ((x+w)<tx) || ((y+h)<ty) || ((tx+tw) < x) || ((ty+th) < y);
170 VectorHandle getRef(){ return reference; };
171 ImageIndex getImageIndex() {
172 if (instr!=DrawImage) return 0;
173 else return target.image;
175 LoadIndex getLoadIndex() {
176 if (instr!=DrawImageLoading) return 0;
177 else return target.loadindex;
180 SVGCommandInstr instr;
183 VectorHandle reference;
185 PathIndex path_index; //path_index
196 class VDR_ResponsePacket;
198 struct SurfaceCommands{
199 const SurfaceVector* surf;
200 std::vector<SVGCommand> commands;
205 class OsdVector : public Osd
209 virtual ~OsdVector();
216 void screenShot(const char* fileName);
217 virtual bool screenShot(void *buffer, int width, int height, bool osd /*include osd*/)=0;
219 Surface * createNewSurface();
222 virtual void updateBackgroundColor(DrawStyle /* bg */) {};
224 void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,
225 std::vector<SVGCommand>& commands);
226 void removeSurface(const SurfaceVector *surf);
228 virtual float getFontHeight()=0;
229 virtual float getCharWidth(wchar_t c)=0;
230 float *getCharWidthArray() {return byte_char_width;};
232 //virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);
233 virtual LoadIndex getTVMediaRef(TVMediaInfo& tvmedia,ImageIndex& image);
234 virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);
235 virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);
238 virtual bool getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)=0;
240 void removeImageRef(const ImageIndex ref);
241 void removeLoadIndexRef(const LoadIndex ref);
242 VectorHandle getStyleRef(const DrawStyle &c);
243 virtual void removeStyleRef(VectorHandle ref);
244 virtual void getScreenSize(int &width, int &height)=0;
245 virtual void getRealScreenSize(int &width, int &height)=0;
247 // should be only called from command thread
248 void informPicture(LoadIndex index, ImageIndex i_index);
253 int charSet() {return 2;}; //UTF-8
256 class PictureDecoder;
273 PictureDecoder* decoder;
282 PictureDecoder(PictureReader * treader) {reader=treader;};
283 virtual ~PictureDecoder() {};
285 // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true;
286 virtual unsigned char * decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, bool freemem=true)=0;
288 virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0;
289 virtual void freeReference(void * ref)=0;
291 virtual void init() {};
292 virtual void shutdown() {};
295 PictureReader * reader;
298 class PictureReader: public Thread_TYPE {
304 void addDecoder(PictureDecoder*);
305 void removeDecoder(PictureDecoder*);
310 bool processReceivedPictures();
312 // should be called from command thread
313 void receivePicture(VDR_ResponsePacket *vresp);
315 void addStaticImage(unsigned int id);
317 void invalidateLoadIndex(LoadIndex index);
319 void informFallback(LoadIndex index, int fallback);
327 void threadPostStopCleanup();
329 Mutex pict_lock_incoming; //locks
331 std::queue<VDR_ResponsePacket*> pict_incoming;
332 std::queue<unsigned int> pict_incoming_static;
333 std::list<PictureDecoder*> decoders;
334 std::map<LoadIndex,int> inform_fallback;
335 std::set<LoadIndex> invalid_loadindex;
341 PictureReader *getPictReader() { return &reader;};
347 PictureReader reader;
349 void incImageRef(ImageIndex index);
350 int getImageRef(ImageIndex index);
351 virtual void destroyImageRef(ImageIndex index)=0;
352 void incLoadIndexRef(LoadIndex index);
353 int getLoadIndexRef(LoadIndex index);
356 //virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;
357 virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;
358 virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;
359 virtual void createPicture(struct PictureInfo& pict_inf)=0;
361 virtual LoadIndex loadTVMedia(TVMediaInfo& tvmedia);
365 std::map<ImageIndex,int> images_ref;
366 std::map<void *,ImageIndex> monobitmaps;
367 //map<string,ImageIndex> jpegs;
368 std::map<TVMediaInfo,ImageIndex> tvmedias;
369 std::list<ImageIndex> palettepics;
373 std::map<LoadIndex,int> loadindex_ref;
374 std::map<TVMediaInfo,LoadIndex> tvmedias_load;
375 std::map<LoadIndex,TVMediaInfo> tvmedias_load_inv;
376 std::map<LoadIndex,ImageIndex> tvmedias_loaded;
380 void incStyleRef(VectorHandle index);
381 int getStyleRef(VectorHandle index);
382 virtual void destroyStyleRef(VectorHandle index) = 0;
385 std::map<DrawStyle, VectorHandle> styles;
386 std::map<VectorHandle, int> styles_ref;
387 std::map<DrawStyle, VectorHandle>::iterator styles_lastit;
388 bool styles_lastit_valid;
389 std::map<VectorHandle, int>::iterator styles_ref_lastit;
390 bool styles_ref_lastit_valid;
392 virtual VectorHandle createStyleRef(const DrawStyle &c) = 0;
394 void dereferenceSVGCommand(std::vector<SVGCommand>& commands );
395 void referenceSVGCommand(std::vector<SVGCommand>& commands );
396 void cleanupOrphanedRefs();
400 virtual void drawSetTrans(SurfaceCommands & sc)=0;
401 virtual void executeDrawCommand(SVGCommand & command)=0;
404 std::list<SurfaceCommands> scommands;
406 Mutex surfaces_mutex;
408 float byte_char_width[256];