From 271db9dd02df475d673b5feebd313bf3e509afd1 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 18 Mar 2012 11:51:00 +0200 Subject: [PATCH] simplified video module --- src/video.h | 117 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 45 deletions(-) diff --git a/src/video.h b/src/video.h index 4aced8a..c013715 100644 --- a/src/video.h +++ b/src/video.h @@ -47,6 +47,7 @@ static inline void putPixelC32 (SDL_Surface *s, int x, int y, Uint32 col) { Uint8 *bits = ((Uint8 *)s->pixels)+(y*s->pitch)+(x*bpp); // switch (bpp) { +/* case 1: *((Uint8 *)(bits)) = (Uint8)col; break; @@ -58,6 +59,7 @@ static inline void putPixelC32 (SDL_Surface *s, int x, int y, Uint32 col) { *((bits)+s->format->Gshift/8) = (col>>s->format->Gshift)&0xFF; *((bits)+s->format->Bshift/8) = (col>>s->format->Bshift)&0xFF; break; +*/ case 4: *((Uint32 *)(bits)) = col; break; @@ -66,6 +68,51 @@ static inline void putPixelC32 (SDL_Surface *s, int x, int y, Uint32 col) { } +static inline void putPixel2x (SDL_Surface *s, int x, int y, Uint8 col) { + x *= 2; + y *= 2; + if (s && x >= s->clip_rect.x && y >= s->clip_rect.y && x < s->clip_rect.x+s->clip_rect.w && y < s->clip_rect.y+s->clip_rect.h) { + Uint8 bpp = s->format->BytesPerPixel; + Uint32 *bits = (Uint32 *)(((Uint8 *)s->pixels)+(y*s->pitch)+(x*bpp)); + Uint32 pix = palette[col]; + // + *bits = pix; + if (x+1 < s->clip_rect.x+s->clip_rect.w) bits[1] = pix; + if (y+1 < s->clip_rect.y+s->clip_rect.h) { + bits = (Uint32 *)((Uint8 *)bits+s->pitch); + *bits = pix; + if (x+1 < s->clip_rect.x+s->clip_rect.w) bits[1] = pix; + } + } +} + + +static inline void hlineC32 (SDL_Surface *s, int x, int y, int len, Uint32 col) { + if (s && y >= s->clip_rect.y && x < s->clip_rect.x+s->clip_rect.w && y < s->clip_rect.y+s->clip_rect.h) { + if (x < s->clip_rect.x) { + len -= s->clip_rect.x-x; + x = s->clip_rect.x; + } + if (x+len > s->clip_rect.x+s->clip_rect.w) len = s->clip_rect.x+s->clip_rect.w-x; + if (len > 0) { + Uint8 bpp = s->format->BytesPerPixel; + Uint32 *bits = (Uint32 *)(((Uint8 *)s->pixels)+(y*s->pitch)+(x*bpp)); + // + for (; len > 0; --len) *bits++ = col; + } + } +} + + +static inline void hline2x (SDL_Surface *s, int x, int y, int len, Uint8 col) { + x *= 2; + y *= 2; + len *= 2; + hlineC32(s, x, y, len, palette[col]); + hlineC32(s, x, y+1, len, palette[col]); +} + + static inline void putPixelA32 (SDL_Surface *s, int x, int y, Uint32 col, Uint8 alpha) { if (s && x >= s->clip_rect.x && y >= s->clip_rect.y && x < s->clip_rect.x+s->clip_rect.w && y < s->clip_rect.y+s->clip_rect.h) { Uint8 bpp = s->format->BytesPerPixel; @@ -74,19 +121,7 @@ static inline void putPixelA32 (SDL_Surface *s, int x, int y, Uint32 col, Uint8 unsigned char r, pr, g, pg, b, pb; // SDL_GetRGB(col, s->format, &pr, &pg, &pb); - // - switch (bpp) { - case 2: - pixel = *((Uint16 *)(bits)); - break; - case 3: - if (SDL_BYTEORDER == SDL_LIL_ENDIAN) pixel = bits[0]+(bits[1]<<8)+(bits[2]<<16); - else pixel = (bits[0]<<16)+(bits[1]<<8)+bits[2]; - break; - case 4: - pixel = *((Uint32 *)(bits)); - break; - } + pixel = *((Uint32 *)(bits)); // get RGB values from pixel r = (((pixel&s->format->Rmask)>>s->format->Rshift)<format->Rloss); g = (((pixel&s->format->Gmask)>>s->format->Gshift)<format->Gloss); @@ -96,47 +131,22 @@ static inline void putPixelA32 (SDL_Surface *s, int x, int y, Uint32 col, Uint8 g = (((pg-g)*alpha)>>8)+g; b = (((pb-b)*alpha)>>8)+b; // set - /* - *((bits)+s->format->Rshift/8) = (col>>s->format->Rshift)&0xFF; - *((bits)+s->format->Gshift/8) = (col>>s->format->Gshift)&0xFF; - *((bits)+s->format->Bshift/8) = (col>>s->format->Bshift)&0xFF; - */ pixel = SDL_MapRGB(s->format, r, g, b); *((Uint32 *)(bits)) = pixel; } } -// NO LOCKING! -static inline void putPixel2xC32 (SDL_Surface *s, int x, int y, Uint32 clr) { - putPixelC32(s, x*2+0, y*2+0, clr); - putPixelC32(s, x*2+1, y*2+0, clr); - putPixelC32(s, x*2+0, y*2+1, clr); - putPixelC32(s, x*2+1, y*2+1, clr); -} - - -static inline void putPixel (SDL_Surface *s, int x, int y, Uint8 clr) { - putPixelC32(s, x, y, palette[clr]); -} - - -// NO LOCKING! -static inline void putPixel2x (SDL_Surface *s, int x, int y, Uint8 clr) { - putPixel(s, x*2+0, y*2+0, clr); - putPixel(s, x*2+1, y*2+0, clr); - putPixel(s, x*2+0, y*2+1, clr); - putPixel(s, x*2+1, y*2+1, clr); -} - - static inline void putPixelA2x (SDL_Surface *s, int x, int y, Uint8 clr, Uint8 alpha) { if (clr != 0) { if (clr != 255) { - putPixelA32(s, x*2+0, y*2+0, palette[clr], alpha); - putPixelA32(s, x*2+1, y*2+0, palette[clr], alpha); - putPixelA32(s, x*2+0, y*2+1, palette[clr], alpha); - putPixelA32(s, x*2+1, y*2+1, palette[clr], alpha); + x *= 2; + y *= 2; + putPixelA32(s, x+0, y+0, palette[clr], alpha); + putPixelA32(s, x+1, y+0, palette[clr], alpha); + ++y; + putPixelA32(s, x+0, y+1, palette[clr], alpha); + putPixelA32(s, x+1, y+1, palette[clr], alpha); } else { putPixel2x(s, x, y, clr); } @@ -144,6 +154,23 @@ static inline void putPixelA2x (SDL_Surface *s, int x, int y, Uint8 clr, Uint8 a } +// NO LOCKING! +static inline void putPixel2xC32 (SDL_Surface *s, int x, int y, Uint32 clr) { + x *= 2; + y *= 2; + putPixelC32(s, x+0, y+0, clr); + putPixelC32(s, x+1, y+0, clr); + ++y; + putPixelC32(s, x+0, y, clr); + putPixelC32(s, x+1, y, clr); +} + + +static inline void putPixel (SDL_Surface *s, int x, int y, Uint8 clr) { + putPixelC32(s, x, y, palette[clr]); +} + + //////////////////////////////////////////////////////////////////////////////// extern void blitSurfaceEx (SDL_Surface *dests, int destx, int desty, SDL_Surface *srcs, int srcx, int srcy, int srcw, int srch); -- 2.11.4.GIT