22 #ifndef STLL_LAYOUTER_SDL
23 #define STLL_LAYOUTER_SDL
33 #include "internal/glyphCache.h"
34 #include "internal/blitter.h"
35 #include "internal/gamma.h"
48 template <
class G =
internal::Gamma_c<>>
53 internal::GlyphCache_c cache;
57 std::tuple<uint8_t, uint8_t, uint8_t> getpixel(
const uint8_t * p,
const SDL_PixelFormat * f)
61 switch(f->BytesPerPixel) {
65 case 2: val = *(Uint16 *)p;
69 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
70 val = p[0] << 16 | p[1] << 8 | p[2];
72 val = p[0] | p[1] << 8 | p[2] << 16;
75 case 4: val = *(Uint32 *)p;
84 SDL_GetRGB(val, f, &r, &g, &b);
86 return std::make_tuple(r, g, b);
90 void putpixel(uint8_t * p, uint8_t r, uint8_t g, uint8_t b,
const SDL_PixelFormat * f)
92 uint32_t pixel = SDL_MapRGB(f, r, g, b);
94 switch(f->BytesPerPixel) {
100 *(Uint16 *)p = pixel;
104 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
105 p[0] = (pixel >> 16) & 0xff;
106 p[1] = (pixel >> 8) & 0xff;
110 p[1] = (pixel >> 8) & 0xff;
111 p[2] = (pixel >> 16) & 0xff;
116 *(Uint32 *)p = pixel;
123 return (
int)(sp)+format*8;
126 static int getSurfaceFormat(SDL_Surface * s)
130 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
131 if (f->Rmask == 0xFF0000 && f->Gmask == 0xFF00 && f->Bmask == 0xFF)
150 switch (calcFormatID(getSurfaceFormat(s), sp))
155 sx, sy, img, c, (uint8_t*)s->pixels, s->pitch, s->format->BytesPerPixel, s->w, s->h,
156 [s,
this](
const uint8_t * p) ->
auto { return getpixel(p, s->format); },
157 [s,
this](uint8_t * p, uint8_t r, uint8_t g, uint8_t b) ->
void { putpixel(p, r, g, b, s->format); },
158 [
this](
int a1,
int a2,
int b1,
int b2,
int c) ->
auto { return internal::blend(a1, a2, b1, b2, c, g); },
163 sx, sy, img, c, (uint8_t*)s->pixels, s->pitch, s->format->BytesPerPixel, s->w, s->h,
164 [](
const uint8_t * p) ->
auto { return std::make_tuple(p[2], p[1], p[0]); },
165 [](uint8_t * p, uint8_t r, uint8_t g, uint8_t b) ->
void { p[2] = r; p[1] = g; p[0] = b; },
166 [
this](
int a1,
int a2,
int b1,
int b2,
int c) ->
auto { return internal::blend(a1, a2, b1, b2, c, g); },
170 outputGlyph_HorizontalRGB(
171 sx, sy, img, c.r(), c.g(), c.b(), c.a(), (uint8_t*)s->pixels, s->pitch, s->format->BytesPerPixel, s->w, s->h,
172 [s,
this](
const uint8_t * p) ->
auto {
return getpixel(p, s->format); },
173 [s,
this](uint8_t * p, uint8_t r, uint8_t g, uint8_t b) ->
void { putpixel(p, r, g, b, s->format); },
174 [
this](
int a1,
int a2,
int b1,
int b2,
int c) ->
auto {
return internal::blend(a1, a2, b1, b2, c, g); },
178 outputGlyph_HorizontalRGB(
179 sx, sy, img, c.r(), c.g(), c.b(), c.a(), (uint8_t*)s->pixels, s->pitch, s->format->BytesPerPixel, s->w, s->h,
180 [](
const uint8_t * p) ->
auto {
return std::make_tuple(p[2], p[1], p[0]); },
181 [](uint8_t * p, uint8_t sp1, uint8_t sp2, uint8_t sp3) ->
void { p[2] = sp1; p[1] = sp2; p[0] = sp3; },
182 [
this](
int a1,
int a2,
int b1,
int b2,
int c) ->
auto {
return internal::blend(a1, a2, b1, b2, c, g); },
186 outputGlyph_HorizontalRGB(
187 sx, sy, img, c.b(), c.g(), c.r(), c.a(), (uint8_t*)s->pixels, s->pitch, s->format->BytesPerPixel, s->w, s->h,
188 [s,
this](
const uint8_t * p) ->
auto {
auto t = getpixel(p, s->format);
return std::make_tuple(std::get<2>(t), std::get<1>(t), std::get<0>(t)); },
189 [s,
this](uint8_t * p, uint8_t sp1, uint8_t sp2, uint8_t sp3) ->
void { putpixel(p, sp3, sp2, sp1, s->format); },
190 [
this](
int a1,
int a2,
int b1,
int b2,
int c) ->
auto {
return internal::blend(a1, a2, b1, b2, c, g); },
194 outputGlyph_HorizontalRGB(
195 sx, sy, img, c.b(), c.g(), c.r(), c.a(), (uint8_t*)s->pixels, s->pitch, s->format->BytesPerPixel, s->w, s->h,
196 [](
const uint8_t * p) ->
auto {
return std::make_tuple(p[0], p[1], p[2]); },
197 [](uint8_t * p, uint8_t sp1, uint8_t sp2, uint8_t sp3) ->
void { p[0] = sp1; p[1] = sp2; p[2] = sp3; },
198 [
this](
int a1,
int a2,
int b1,
int b2,
int c) ->
auto {
return internal::blend(a1, a2, b1, b2, c, g); },
206 showSDL(
void) : cx(0), cy(0), cw(std::numeric_limits<int>::max()), ch(std::numeric_limits<int>::max())
230 virtual void draw(int32_t x, int32_t y, uint32_t w, uint32_t h, SDL_Surface * s,
const std::string & url) = 0;
259 outputGlyph(sx+i.x, sy+i.y, cache.getGlyph(i.font, i.glyphIndex, sp, i.blurr), sp, g.forward(i.c), s);
265 r.x = (i.x+sx+32)/64;
266 r.y = (i.y+sy+32)/64;
267 r.w = (i.x+sx+i.w+32)/64-r.x;
268 r.h = (i.y+sy+i.h+32)/64-r.y;
269 SDL_FillRect(s, &r, SDL_MapRGBA(s->format, i.c.r(), i.c.g(), i.c.b(), i.c.a()));
273 outputGlyph(sx+i.x, sy+i.y, cache.getRect(i.w, i.h, sp, i.blurr), sp, g.forward(i.c), s);
279 images->draw(i.x+sx, i.y+sy, i.w, i.h, s, i.imageURL);
309 void setClipRect(uint16_t x = 0, uint16_t y = 0, uint16_t w = std::numeric_limits<uint16_t>::max(), uint16_t h = std::numeric_limits<uint16_t>::max())
a little class representing an RGBA colour value, an a value of 255 is assumed to be opaque ...
Definition: color.h:36
void showLayout(const TextLayout_c &l, int sx, int sy, SDL_Surface *s, SubPixelArrangement sp=SUBP_NONE, ImageDrawer_c *images=0)
display a single layout
Definition: output_SDL.h:248
const std::vector< CommandData_c > getData(void) const
get the command vector
Definition: layouter.h:121
use horizontal RGB
Definition: layouterFont.h:62
void trimCache(size_t num)
trims the font cache down to a maximal number of entries
Definition: output_SDL.h:326
SubPixelArrangement
define, which sub-pixel arrangement you want to use for sub-pixel output
Definition: layouterFont.h:59
use horizontal BGR
Definition: layouterFont.h:63
class used to encapsulate image drawing
Definition: output_SDL.h:218
draw a rectangle
Definition: layouter.h:55
The namespace for the library. Every function and class is within this namespace. ...
Definition: color.h:31
a class to output layouts using SDL
Definition: output_SDL.h:49
encapsulates a finished layout.
Definition: layouter.h:105
this file contains just a little helper class for a 4-value colour
void setGamma(uint8_t gamma=22)
update the gamma value used for output
Definition: output_SDL.h:292
void setClipRect(uint16_t x=0, uint16_t y=0, uint16_t w=std::numeric_limits< uint16_t >::max(), uint16_t h=std::numeric_limits< uint16_t >::max())
set the clip rectangle
Definition: output_SDL.h:309
don't use sub-pixel output (e.g. non LCD)
Definition: layouterFont.h:61
the paragraph layouter and its helpers
draw an image
Definition: layouter.h:56
showSDL(void)
Definition: output_SDL.h:206
draw a glyph from a font
Definition: layouter.h:54
virtual void draw(int32_t x, int32_t y, uint32_t w, uint32_t h, SDL_Surface *s, const std::string &url)=0
function called to draw an image