MCPcopy Create free account
hub / github.com/SmingHub/Sming / draw

Function draw

Sming/Libraries/AnimatedGIF/src/AnimatedGifTask.cpp:20–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#include "AnimatedGifTask.h"
19
20void draw(GIFDRAW* pDraw)
21{
22 auto surface = static_cast<Graphics::Surface*>(pDraw->pUser);
23 if(surface == nullptr) {
24 return;
25 }
26
27 const auto& tftSize = surface->getSize();
28 const int DISPLAY_WIDTH = tftSize.w;
29 const int DISPLAY_HEIGHT = tftSize.h;
30
31 auto pixelFormat = surface->getPixelFormat();
32 auto bytesPerPixel = Graphics::getBytesPerPixel(pixelFormat);
33
34 uint16_t usTemp[DISPLAY_WIDTH];
35 Graphics::SharedBuffer buffer(bytesPerPixel * DISPLAY_WIDTH);
36
37 int iWidth = pDraw->iWidth;
38 if(iWidth + pDraw->iX > DISPLAY_WIDTH) {
39 iWidth = DISPLAY_WIDTH - pDraw->iX;
40 }
41 const uint16_t* usPalette = pDraw->pPalette;
42 int y = pDraw->iY + pDraw->y; // current line
43 if(y >= DISPLAY_HEIGHT || pDraw->iX >= DISPLAY_WIDTH || iWidth < 1) {
44 return;
45 }
46
47 auto s = pDraw->pPixels;
48 if(pDraw->ucDisposalMethod == 2) // restore to background color
49 {
50 for(int x = 0; x < iWidth; x++) {
51 if(s[x] == pDraw->ucTransparent) {
52 s[x] = pDraw->ucBackground;
53 }
54 }
55 pDraw->ucHasTransparency = 0;
56 }
57
58 // Apply the new pixels to the main image
59 if(pDraw->ucHasTransparency) // if transparency used
60 {
61 uint8_t ucTransparent = pDraw->ucTransparent;
62 uint8_t* pEnd = s + iWidth;
63 int x = 0;
64 int iCount = 0; // count non-transparent pixels
65 while(x < iWidth) {
66 uint8_t c = ucTransparent - 1;
67 uint16_t* d = usTemp;
68 while(c != ucTransparent && s < pEnd) {
69 c = *s++;
70 if(c == ucTransparent) {
71 // done, stop: back up to treat it like transparent
72 s--;
73 } else {
74 // opaque
75 *d++ = __builtin_bswap16(usPalette[c]);
76 iCount++;
77 }

Callers

nothing calls this directly

Calls 5

convertFunction · 0.85
setAddrWindowMethod · 0.80
getSizeMethod · 0.45
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected