From c1f22927bbfffe1694139ea40a4f4c4baa35fbde Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 21 May 2020 18:12:14 +0100 Subject: [PATCH] Formatting --- surface.cc | 349 ++++++++++++++++++++++++++++++----------------------- surface.h | 66 +++++----- 2 files changed, 231 insertions(+), 184 deletions(-) diff --git a/surface.cc b/surface.cc index 9c17aa8..94ece40 100644 --- a/surface.cc +++ b/surface.cc @@ -32,7 +32,7 @@ Surface* Surface::screen = NULL; #ifndef GRADIENT_DRAWING -osd_font_t* Surface::font = &font_helvB18; + osd_font_t* Surface::font = &font_helvB18; #endif Surface::Surface(int id) @@ -51,36 +51,44 @@ Surface* Surface::getScreen() void Surface::initpol_tables() { - int charsizex; - int charsizey; - charsizex=16; - if (Video::getInstance()->getFormat() == Video::PAL) + int charsizex; + int charsizey; + charsizex = 16; + + if (Video::getInstance()->getFormat() == Video::PAL) + { + charsizey = 22; + } + else + { + charsizey = 18; + } + + int ttcharsizex = 12; + int ttcharsizey = 10; + + for (int py = 0; py < charsizey; py++) + { + float fposy = ((float)(ttcharsizey)) / ((float)(charsizey)) * ((float)py); + float yweight = fposy - floor(fposy); + float yinvweight = 1. - yweight; + interpol_upline[py] = std::min((int)(ceil(fposy)), 9); + interpol_lowline[py] = std::max((int)(floor(fposy)), 0); + + for (int px = 0; px < charsizex; px++) { - charsizey=22; - } else { - charsizey=18; - } - int ttcharsizex=12; - int ttcharsizey=10; - for (int py=0;pycontent[font->offset[ch]]; + unsigned long* character = &font->content[font->offset[ch]]; int w = font->width[ch]; int pixels = 0; - for (X=0; (X> (32 - X)) & 0x1) { - drawPixel(x+X+cx, y+Y, rgba,true); + drawPixel(x + X + cx, y + Y, rgba, true); pixels++; } } } + cx += w; } + endFastDraw(); return 1; } @@ -175,42 +186,59 @@ int Surface::getFontHeight() Colour Surface::enumTeletextColorToCoulour(enumTeletextColor ttcol) { - switch (ttcol) { - case ttcBlack: - return Colour(0,0,0); - case ttcRed: - return Colour(255,0,0); - case ttcGreen: - return Colour(0,255,0); - case ttcYellow: - return Colour(255,255,0); - case ttcBlue: - return Colour(0,0,255); - case ttcMagenta: - return Colour(255,0,255); - case ttcCyan: - return Colour(0,255,255); - case ttcWhite: - return Colour(255,255,255); - case ttcTransparent: - return Colour(0,0,0,0); - case ttcHalfRed: - return Colour(127,0,0); - case ttcHalfGreen: - return Colour(0,127,0); - case ttcHalfYellow: - return Colour(127,127,0); - case ttcHalfBlue: - return Colour(0,0,127); - case ttcHalfMagenta: - return Colour(127,0,127); - case ttcHalfCyan: - return Colour(0,127,127); - case ttcGrey: - return Colour(127,127,127); - default: - return Colour(0,0,0); - }; + switch (ttcol) + { + case ttcBlack: + return Colour(0, 0, 0); + + case ttcRed: + return Colour(255, 0, 0); + + case ttcGreen: + return Colour(0, 255, 0); + + case ttcYellow: + return Colour(255, 255, 0); + + case ttcBlue: + return Colour(0, 0, 255); + + case ttcMagenta: + return Colour(255, 0, 255); + + case ttcCyan: + return Colour(0, 255, 255); + + case ttcWhite: + return Colour(255, 255, 255); + + case ttcTransparent: + return Colour(0, 0, 0, 0); + + case ttcHalfRed: + return Colour(127, 0, 0); + + case ttcHalfGreen: + return Colour(0, 127, 0); + + case ttcHalfYellow: + return Colour(127, 127, 0); + + case ttcHalfBlue: + return Colour(0, 0, 127); + + case ttcHalfMagenta: + return Colour(127, 0, 127); + + case ttcHalfCyan: + return Colour(0, 127, 127); + + case ttcGrey: + return Colour(127, 127, 127); + + default: + return Colour(0, 0, 0); + }; } @@ -218,97 +246,118 @@ Colour Surface::enumTeletextColorToCoulour(enumTeletextColor ttcol) //Next function inspired by osdteletext plugin void Surface::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c) { - if (!pol_table_inited){ - initpol_tables(); - pol_table_inited=true; - } - unsigned int buffer [10]; - unsigned int * charmap=GetFontChar(c,buffer); - if (!charmap) { //invalid char - memset(&buffer,0,10); - charmap=buffer; - } - enumTeletextColor ttforegcolour=c.GetFGColor(); - enumTeletextColor ttbackgcolour=c.GetBGColor(); - if (c.GetBoxedOut()) { - ttforegcolour=ttcTransparent; - ttbackgcolour=ttcTransparent; - } - int charsizex; - int charsizey; - charsizex=16; + if (!pol_table_inited) + { + initpol_tables(); + pol_table_inited = true; + } - if (Video::getInstance()->getFormat() == Video::PAL) + unsigned int buffer [10]; + unsigned int* charmap = GetFontChar(c, buffer); + + if (!charmap) //invalid char + { + memset(&buffer, 0, 10); + charmap = buffer; + } + + enumTeletextColor ttforegcolour = c.GetFGColor(); + enumTeletextColor ttbackgcolour = c.GetBGColor(); + + if (c.GetBoxedOut()) + { + ttforegcolour = ttcTransparent; + ttbackgcolour = ttcTransparent; + } + + int charsizex; + int charsizey; + charsizex = 16; + + if (Video::getInstance()->getFormat() == Video::PAL) + { + charsizey = 22; + } + else + { + charsizey = 18; + } + + //int ttcharsizex=12; + //int ttcharsizey=10; + int screenposx = charsizex * x + ox; //12*40= 480 250 + int screenposy = y * charsizey + oy; + + + // Log::getInstance()->log("Surface", Log::ERR, "TTpos %d %d %d %d %d %d",x,y,ox,oy,screenposx,screenposy); + Colour fgcharcl = enumTeletextColorToCoulour(ttforegcolour); + Colour bgcharcl = enumTeletextColorToCoulour(ttbackgcolour); + + startFastDraw(); + + for (int py = 0; py < charsizey; py++) + { + int upperbitline = charmap[interpol_upline[py]]; + int lowerbitline = charmap[interpol_lowline[py]]; + + for (int px = 0; px < charsizex; px++) { - charsizey=22; - } else { - charsizey=18; - } - //int ttcharsizex=12; - //int ttcharsizey=10; - int screenposx=charsizex*x+ox; //12*40= 480 250 - int screenposy=y*charsizey+oy; - - - // Log::getInstance()->log("Surface", Log::ERR, "TTpos %d %d %d %d %d %d",x,y,ox,oy,screenposx,screenposy); - Colour fgcharcl=enumTeletextColorToCoulour(ttforegcolour); - Colour bgcharcl=enumTeletextColorToCoulour(ttbackgcolour); - - startFastDraw(); - for (int py=0;py>upperbit)) ? fgcharcl: bgcharcl; - Colour ulc=( upperbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl; - Colour luc=( lowerbitline &(0x8000>>upperbit)) ? fgcharcl: bgcharcl; - Colour llc=( lowerbitline &(0x8000>>lowerbit)) ? fgcharcl: bgcharcl; - unsigned int fac1,fac2,fac3,fac4; - fac1=interpol_table_fac1[px][py]; - fac2=interpol_table_fac2[px][py]; - fac3=interpol_table_fac3[px][py]; - fac4=interpol_table_fac4[px][py]; - - Colour res((uuc.red*fac1+ulc.red*fac2+luc.red*fac3+llc.red*fac4)/256, - (uuc.green*fac1+ulc.green*fac2+luc.green*fac3+llc.green*fac4)/256, - (uuc.blue*fac1+ulc.blue*fac2+luc.blue*fac3+llc.blue*fac4)/256, - (uuc.alpha*fac1+ulc.alpha*fac2+luc.alpha*fac3+llc.alpha*fac4)/256); //if this is too slow make a table - int newcolour = ( (res.alpha << 24) - | (res.red << 16) - | (res.green << 8) - | (res.blue ) ); - drawPixel(screenposx+px, screenposy+py, newcolour, true); - } + int upperbit = interpol_upbit[px]; + int lowerbit = interpol_lowbit[px]; + Colour uuc = ( upperbitline & (0x8000 >> upperbit)) ? fgcharcl : bgcharcl; + Colour ulc = ( upperbitline & (0x8000 >> lowerbit)) ? fgcharcl : bgcharcl; + Colour luc = ( lowerbitline & (0x8000 >> upperbit)) ? fgcharcl : bgcharcl; + Colour llc = ( lowerbitline & (0x8000 >> lowerbit)) ? fgcharcl : bgcharcl; + unsigned int fac1, fac2, fac3, fac4; + fac1 = interpol_table_fac1[px][py]; + fac2 = interpol_table_fac2[px][py]; + fac3 = interpol_table_fac3[px][py]; + fac4 = interpol_table_fac4[px][py]; + + Colour res((uuc.red * fac1 + ulc.red * fac2 + luc.red * fac3 + llc.red * fac4) / 256, + (uuc.green * fac1 + ulc.green * fac2 + luc.green * fac3 + llc.green * fac4) / 256, + (uuc.blue * fac1 + ulc.blue * fac2 + luc.blue * fac3 + llc.blue * fac4) / 256, + (uuc.alpha * fac1 + ulc.alpha * fac2 + luc.alpha * fac3 + llc.alpha * fac4) / 256); //if this is too slow make a table + int newcolour = ( (res.alpha << 24) + | (res.red << 16) + | (res.green << 8) + | (res.blue ) ); + drawPixel(screenposx + px, screenposy + py, newcolour, true); } + } - endFastDraw(); + endFastDraw(); } void Surface::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height, - unsigned int width, DrawStyle& nextColour) { - startFastDraw(); - unsigned int x, y; - unsigned int bytesIn, bitsIn; - int widthBytes=width/8; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - bytesIn = (y * widthBytes) + (int) (x / 8); - bitsIn = x % 8; - - if ((base[bytesIn] >> (7 - bitsIn)) & 0x01) { - drawPixel(dx+x, dy+y, nextColour, true); - } - } - } - endFastDraw(); + unsigned int width, DrawStyle& nextColour) +{ + startFastDraw(); + unsigned int x, y; + unsigned int bytesIn, bitsIn; + int widthBytes = width / 8; + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + bytesIn = (y * widthBytes) + (int) (x / 8); + bitsIn = x % 8; + + if ((base[bytesIn] >> (7 - bitsIn)) & 0x01) + { + drawPixel(dx + x, dy + y, nextColour, true); + } + } + } + + endFastDraw(); } void Surface::drawPoint(int x, int y, DrawStyle& c, bool fastdraw) { - drawPixel(x,y,c,fastdraw); + drawPixel(x, y, c, fastdraw); } diff --git a/surface.h b/surface.h index b0effd3..bf720f8 100644 --- a/surface.h +++ b/surface.h @@ -30,13 +30,14 @@ // Font stuff // FIXME does anything use this anymore? -typedef struct bogl_font { - char *name; /* Font name. */ +typedef struct bogl_font +{ + char* name; /* Font name. */ int height; /* Height in pixels. */ int spacing; /* Vertical spacing in pixels. */ - unsigned long *content; /* 32-bit right-padded bitmap array. */ - short *offset; /* 256 offsets into content. */ - unsigned char *width; /* 256 character widths. */ + unsigned long* content; /* 32-bit right-padded bitmap array. */ + short* offset; /* 256 offsets into content. */ + unsigned char* width; /* 256 character widths. */ } osd_font_t; //extern osd_font_t font_CaslonRoman_1_25; @@ -47,27 +48,25 @@ extern osd_font_t font_helvB18; class Bitmap; class DisplayRegion; - - class Surface { - // classes that need surface access, their usage is forbidden for vector based - friend class WJpegComplex;// implementations of osd - friend class VColourTuner; + // classes that need surface access, their usage is forbidden for vector based + friend class WJpegComplex;// implementations of osd + friend class VColourTuner; -public: + public: Surface(int id = 0); virtual ~Surface(); static Surface* getScreen(); #ifdef GRADIENT_DRAWING - virtual int getFontHeight()=0; - virtual float getCharWidth(wchar_t c)=0; - virtual int drawText(const char* text, int x, int y, const DrawStyle& c)=0; - virtual int drawText(const char* text, int x, int y, int width, const DrawStyle& c)=0; - virtual int drawTextRJ(const char* text, int x, int y, const DrawStyle& c)=0; - virtual int drawTextCentre(const char* text, int x, int y, const DrawStyle& c)=0; + virtual int getFontHeight() = 0; + virtual float getCharWidth(wchar_t c) = 0; + virtual int drawText(const char* text, int x, int y, const DrawStyle& c) = 0; + virtual int drawText(const char* text, int x, int y, int width, const DrawStyle& c) = 0; + virtual int drawTextRJ(const char* text, int x, int y, const DrawStyle& c) = 0; + virtual int drawTextCentre(const char* text, int x, int y, const DrawStyle& c) = 0; #else //May be move this stuff to a new Basis class surface pixel virtual int getFontHeight(); @@ -80,28 +79,27 @@ public: virtual void drawJpeg(const char* /* fileName */, int /* x */, int /* y */, int* /* width */, int* /* height */) {} - virtual int create(UINT width, UINT height)=0; - virtual void display()=0; + virtual int create(UINT width, UINT height) = 0; + virtual void display() = 0; - virtual int fillblt(int x, int y, int width, int height, const DrawStyle& c)=0; - virtual void drawHorzLine(int x1, int x2, int y, const DrawStyle& c)=0; - virtual void drawVertLine(int x, int y1, int y2, const DrawStyle& c)=0; - virtual void drawBitmap(int x, int y, const Bitmap& bm,const DisplayRegion & region)=0; - virtual void drawPoint(int x, int y, DrawStyle& c, bool fastdraw=false); // This draws a point, must not be a pixel - virtual void drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour); - virtual int updateToScreen(int sx, int sy, int w, int h, int dx, int dy)=0; - virtual void readPixel(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b)=0; - virtual bool screenShot(const char* fileName)=0; + virtual int fillblt(int x, int y, int width, int height, const DrawStyle& c) = 0; + virtual void drawHorzLine(int x1, int x2, int y, const DrawStyle& c) = 0; + virtual void drawVertLine(int x, int y1, int y2, const DrawStyle& c) = 0; + virtual void drawBitmap(int x, int y, const Bitmap& bm, const DisplayRegion& region) = 0; + virtual void drawPoint(int x, int y, DrawStyle& c, bool fastdraw = false); // This draws a point, must not be a pixel + virtual void drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height, unsigned int width, DrawStyle& nextColour); + virtual int updateToScreen(int sx, int sy, int w, int h, int dx, int dy) = 0; + virtual void readPixel(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b) = 0; + virtual bool screenShot(const char* fileName) = 0; /* This is for system which need a locking of the drawing surface to speed up drawing */ virtual void startFastDraw() {}; virtual void endFastDraw() {}; - virtual void drawTTChar(int ox, int oy,int x, int y, cTeletextChar c); + virtual void drawTTChar(int ox, int oy, int x, int y, cTeletextChar c); static Colour enumTeletextColorToCoulour(enumTeletextColor ttcol); - - // virtual int blt(int fd, unsigned long shandle, int sx, int sy, int width, int height, unsigned long dhandle, int dx, int dy)=0; + // virtual int blt(int fd, unsigned long shandle, int sx, int sy, int width, int height, unsigned long dhandle, int dx, int dy)=0; const static int SCREEN = 1; const static int BUFFER = 2; @@ -112,8 +110,8 @@ public: static osd_font_t* font; #endif - virtual void drawPixel(int x, int y, unsigned int c, bool fastdraw=false)=0; // deprecated preparation for vector based drawing, only allowed to be called inside implementation - virtual void drawPixel(int x, int y, Colour& c, bool fastdraw=false)=0; // deprecated preparation for vector based drawing, only allowed to be called inside implementation + virtual void drawPixel(int x, int y, unsigned int c, bool fastdraw = false) = 0; // deprecated preparation for vector based drawing, only allowed to be called inside implementation + virtual void drawPixel(int x, int y, Colour& c, bool fastdraw = false) = 0; // deprecated preparation for vector based drawing, only allowed to be called inside implementation private: void initpol_tables(); @@ -125,7 +123,7 @@ public: int interpol_upbit[16]; int interpol_lowline[22]; int interpol_upline[22]; - bool pol_table_inited=false; + bool pol_table_inited = false; }; #endif -- 2.39.5