-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dd9e9c
commit 85cef0d
Showing
8 changed files
with
513 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#include "canvas.h" | ||
|
||
__inline int rot_x(int t, int x, int y, int w, int h) { | ||
switch (t) { | ||
case 1: | ||
return r90_x(x,y,w,h); | ||
break; | ||
case 2: | ||
return r180_x(x,y,w,h); | ||
break; | ||
case 3: | ||
return r270_x(x,y,w,h); | ||
break; | ||
case 4: | ||
return fy180_x(x,y,w,h); | ||
break; | ||
} | ||
return x; | ||
} | ||
|
||
__inline int rot_y(int t, int x, int y, int w, int h) { | ||
switch (t) { | ||
case 1: | ||
return r90_y(x,y,w,h); | ||
break; | ||
case 2: | ||
return r180_y(x,y,w,h); | ||
break; | ||
case 3: | ||
return r270_y(x,y,w,h); | ||
break; | ||
case 4: | ||
return fy180_y(x,y,w,h); | ||
break; | ||
} | ||
return y; | ||
} | ||
|
||
|
||
void RGBA(int pix, void *destination, void *source, int yy, int yn, int xw, int xh, int dw, int pad, int rot) { | ||
switch (pix) { | ||
case BIT_SHORT5551: | ||
break; | ||
case BIT_INT_8888REV: | ||
if (rot == 0) { | ||
i8888(destination, source, yy, yn, xw, pad); | ||
} else { | ||
i8888r(destination, source, yy, yn, xw, xh, dw, pad, rot); | ||
} | ||
break; | ||
case BIT_SHORT565: | ||
if (rot == 0) { | ||
i565(destination, source, yy, yn, xw, pad); | ||
} else { | ||
i565r(destination, source, yy, yn, xw, xh, dw, pad, rot); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
void i565(void *destination, void *source, int yy, int yn, int xw, int pad) { | ||
uint8_t *src = source; // must be in bytes because of possible padding in bytes | ||
uint32_t *dst = destination; | ||
|
||
int y, x; | ||
uint32_t px; | ||
|
||
for (y = yy; y < yn; ++y) { | ||
for (x = 0; x < xw; ++x) { | ||
px = *(uint16_t *)src; | ||
src += 2; | ||
*dst++ = _565(px); | ||
} | ||
src += pad; | ||
} | ||
} | ||
|
||
void i565r(void *destination, void *source, int yy, int yn, int xw, int xh, int dw, int pad, int rot) { | ||
uint8_t *src = source; | ||
uint32_t *dst = destination; | ||
|
||
uint32_t px; | ||
|
||
int x, y, dx, dy; | ||
|
||
for (y = yy; y < yn; ++y) { | ||
for (x = 0; x < xw; ++x) { | ||
px = *(uint16_t *)src; | ||
src += 2; | ||
|
||
dx = rot_x(rot, x, y, xw, xh); | ||
dy = rot_y(rot, x, y, xw, xh); | ||
|
||
dst[dx+dy*dw] = _565(px); | ||
} | ||
src += pad; | ||
} | ||
} | ||
|
||
void i8888r(void *destination, void *source, int yy, int yn, int xw, int xh, int dw, int pad, int rot) { | ||
uint8_t *src = source; | ||
uint32_t *dst = destination; | ||
|
||
int y, x; | ||
uint32_t px; | ||
|
||
int dx, dy; | ||
|
||
for (y = yy; y < yn; ++y) { | ||
for (x = 0; x < xw; ++x) { | ||
px = *(uint32_t *)src; | ||
|
||
dx = rot_x(rot, x, y, xw, xh); | ||
dy = rot_y(rot, x, y, xw, xh); | ||
|
||
dst[dx+dy*dw] = _8888rev(px); | ||
src += 4; | ||
} | ||
src += pad; | ||
} | ||
} | ||
|
||
void i8888(void *destination, void *source, int yy, int yn, int xw, int pad) { | ||
uint8_t *src = source; // must be in bytes because of possible padding in bytes | ||
uint32_t *dst = destination; | ||
|
||
int y, x; | ||
uint32_t px; | ||
|
||
for (y = yy; y < yn; ++y) { | ||
for (x = 0; x < xw; ++x) { | ||
px = *(uint32_t *)src; | ||
src += 4; | ||
*dst++ = _8888rev(px); | ||
} | ||
src += pad; | ||
} | ||
} | ||
|
||
uint32_t px8888rev(uint32_t px) { | ||
return _8888rev(px); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef CANVAS_H__ | ||
#define CANVAS_H__ | ||
|
||
#include <stdint.h> | ||
|
||
#define BIT_SHORT5551 0 | ||
#define BIT_INT_8888REV 1 | ||
#define BIT_SHORT565 2 | ||
|
||
// Rotate90 is 90° CCW or 270° CW. | ||
#define r90_x(x, y, w, h) ( y ) | ||
#define r90_y(x, y, w, h) ( (w - 1) - x ) | ||
|
||
// Rotate180 is 180° CCW. | ||
#define r180_x(x, y, w, h) ( (w - 1) - x ) | ||
#define r180_y(x, y, w, h) ( (h - 1) - y ) | ||
|
||
// Rotate270 is 270° CCW or 90° CW. | ||
#define r270_x(x, y, w, h) ( (h - 1) - y ) | ||
#define r270_y(x, y, w, h) ( x ) | ||
|
||
// Flip Y | ||
#define fy180_x(x, y, w, h) ( x ) | ||
#define fy180_y(x, y, w, h) ( (h - 1) - y ) | ||
|
||
int rot_x(int t, int x, int y, int w, int h); | ||
int rot_y(int t, int x, int y, int w, int h); | ||
|
||
#define _565(x) ((x >> 8 & 0xf8) | ((x >> 3 & 0xfc) << 8) | ((x << 3 & 0xfc) << 16)); // | 0xff000000 | ||
#define _8888rev(px) (((px >> 16) & 0xff) | (px & 0xff00) | ((px << 16) & 0xff0000)); // | 0xff000000) | ||
|
||
|
||
void RGBA(int pix, void *destination, void *source, int yy, int yn, int xw, int xh, int dw, int pad, int rot); | ||
|
||
void i565(void *destination, void *source, int yy, int yn, int xw, int pad); | ||
void i8888(void *destination, void *source, int yy, int yn, int xw, int pad); | ||
void i565r(void *destination, void *source, int yy, int yn, int xw, int xh, int dw, int pad, int rot); | ||
void i8888r(void *destination, void *source, int yy, int yn, int xw, int xh, int dw, int pad, int rot); | ||
|
||
uint32_t px8888rev(uint32_t px); | ||
|
||
#endif |
Oops, something went wrong.