Skip to content

Commit da51639

Browse files
committed
Clean canvas.c
1 parent e836140 commit da51639

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

pkg/worker/caged/libretro/image/canvas.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33
__inline xy rotate(int t, int x, int y, int w, int h) {
44
xy p = {x, y};
55
switch (t) {
6+
// 90° CCW or 270° CW
67
case A90:
7-
p.x = r90_x(x,y,w,h);
8-
p.y = r90_y(x,y,w,h);
8+
p.x = y;
9+
p.y = w - 1 - x;
910
break;
11+
// 180° CCW
1012
case A180:
11-
p.x = r180_x(x,y,w,h);
12-
p.y = r180_y(x,y,w,h);
13+
p.x = w - 1 - x;
14+
p.y = h - 1 - y;
1315
break;
16+
// 270° CCW or 90° CW
1417
case A270:
15-
p.x = r270_x(x,y,w,h);
16-
p.y = r270_y(x,y,w,h);
18+
p.x = h - 1 - y;
19+
p.y = x;
1720
break;
21+
// flip Y
1822
case F180:
19-
p.x = fy180_x(x,y,w,h);
20-
p.y = fy180_y(x,y,w,h);
23+
//p.x = x;
24+
p.y = h - 1 - y;
2125
break;
2226
}
2327
return p;
@@ -28,20 +32,20 @@ __inline uint32_t _565(uint32_t x) {
2832
}
2933

3034
__inline uint32_t _8888rev(uint32_t px) {
31-
return (((px >> 16) & 0xff) | (px & 0xff00) | ((px << 16) & 0xff0000)); // | 0xff000000)
35+
return (((px >> 16) & 0xff) | (px & 0xff00) | ((px << 16) & 0xff0000)); // | 0xff000000
3236
}
3337

34-
void RGBA(int pix, uint32_t *__restrict dst, void *__restrict source, int y, int h, int w, int hh, int dw, int pad, int rot) {
38+
void RGBA(int pix, uint32_t *__restrict dst, const void *__restrict source, int y, int h, int w, int hh, int dw, int pad, int rot) {
3539
int x;
3640
xy rxy;
37-
uint16_t *src16;
38-
uint32_t *src32;
41+
const uint16_t *src16;
42+
const uint32_t *src32;
3943

4044
switch (pix) {
4145
//case BIT_SHORT5551:
4246
// break;
4347
case BIT_INT_8888REV:
44-
src32 = (uint32_t *)source;
48+
src32 = (const uint32_t *)source;
4549
int pad32 = pad >> 2;
4650
if (rot == NO_ROT) {
4751
for (; y < h; ++y) {
@@ -54,14 +58,14 @@ void RGBA(int pix, uint32_t *__restrict dst, void *__restrict source, int y, int
5458
for (; y < h; ++y) {
5559
for (x = 0; x < w; ++x) {
5660
rxy = rotate(rot, x, y, w, hh);
57-
dst[rxy.x+rxy.y*w] = _8888rev(*src32++);
61+
dst[rxy.x+rxy.y*dw] = _8888rev(*src32++);
5862
}
5963
src32 += pad32;
6064
}
6165
}
6266
break;
6367
case BIT_SHORT565:
64-
src16 = (uint16_t *)source;
68+
src16 = (const uint16_t *)source;
6569
int pad16 = pad >> 1;
6670
if (rot == NO_ROT) {
6771
for (; y < h; ++y) {

pkg/worker/caged/libretro/image/canvas.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,13 @@
1313
#define A270 3
1414
#define F180 4
1515

16-
// Rotate90 is 90° CCW or 270° CW.
17-
#define r90_x(x, y, w, h) ( y )
18-
#define r90_y(x, y, w, h) ( (w - 1) - x )
19-
20-
// Rotate180 is 180° CCW.
21-
#define r180_x(x, y, w, h) ( (w - 1) - x )
22-
#define r180_y(x, y, w, h) ( (h - 1) - y )
23-
24-
// Rotate270 is 270° CCW or 90° CW.
25-
#define r270_x(x, y, w, h) ( (h - 1) - y )
26-
#define r270_y(x, y, w, h) ( x )
27-
28-
// Flip Y
29-
#define fy180_x(x, y, w, h) ( x )
30-
#define fy180_y(x, y, w, h) ( (h - 1) - y )
31-
3216
typedef struct XY {
3317
int x, y;
3418
} xy;
3519

3620
xy rotate(int t, int x, int y, int w, int h);
3721

38-
void RGBA(int pix, uint32_t *dst, void *source, int y, int h, int w, int hh, int dw, int pad, int rot);
22+
void RGBA(int pix, uint32_t *dst, const void *source, int y, int h, int w, int hh, int dw, int pad, int rot);
3923

4024
uint32_t _565(uint32_t x);
4125
uint32_t _8888rev(uint32_t px);

0 commit comments

Comments
 (0)