Added ext/img.h

This commit is contained in:
mibi88 2023-01-16 19:41:49 +01:00
parent 2458478835
commit 0ffa9e9484
5 changed files with 70 additions and 1 deletions

View File

@ -4,7 +4,7 @@ AR = sh-elf-ar
OUT = libMicrofx.a
OUT_DIR = lib
SRC = src/start.c src/syscall.S src/microfx.c
SRC = src/start.c src/syscall.S src/microfx.c src/img.c
OBJ = $(SRC:src/%=build/%.o)
BUILD = build

View File

@ -0,0 +1,20 @@
#ifndef IMG_H
#define IMG_H
enum {SNORMAL = 0, SINVERTED, STRANSP, SNOWHITE, SNOBLACK};
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
Draws an image from a Sprite Coder string that is in img,
where the top left corner is at (sx, sy).
w is the width and h the height of the image.
mode can be :
SNORMAL : Draws the image normally.
SINVERTED : Draws the image with inverted colors.
STRANSP : Black is white and white is not drawn. Useful for
transparency in sprites.
*/
void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
#endif

29
microfx_src/src/img.c Normal file
View File

@ -0,0 +1,29 @@
#include "../include/microfx/ext/img.h"
#include <microfx/microfx.h>
void simage(int sx, int sy, int w, int h, unsigned char *img, int mode) {
/* Draws an image from a sprite coder string */
int x, y, rpos, gpos, bpos, color;
for(y=0;y<h;y++){
for(x=0;x<w;x++){
rpos = y*(w+(w%2))+x;
gpos = rpos/8;
bpos = rpos%8;
color = (img[gpos] << bpos) & 0x80;
switch(mode){
case STRANSP:
if(color) spixel(sx+x, sy+y, SWHITE);
break;
case SNOWHITE:
if(color) spixel(sx+x, sy+y, SBLACK);
break;
case SNOBLACK:
if(!color) spixel(sx+x, sy+y, SWHITE);
break;
default: /* SNORMAL or SINVERTED */
spixel(sx+x, sy+y, mode ? !color : color);
break;
}
}
}
}

View File

@ -0,0 +1,20 @@
#ifndef IMG_H
#define IMG_H
enum {SNORMAL = 0, SINVERTED, STRANSP, SNOWHITE, SNOBLACK};
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
Draws an image from a Sprite Coder string that is in img,
where the top left corner is at (sx, sy).
w is the width and h the height of the image.
mode can be :
SNORMAL : Draws the image normally.
SINVERTED : Draws the image with inverted colors.
STRANSP : Black is white and white is not drawn. Useful for
transparency in sprites.
*/
void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
#endif

Binary file not shown.