annotate src/dmgfx.c @ 1315:7687412f9aef

Fix jssmod sample conversion flags storing .. urgh.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 20 Aug 2017 01:54:54 +0300
parents e06abfde6c39
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 SDL_Rect rc;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 rc.x = x0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 rc.y = y0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 rc.w = x1 - x0 + 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 rc.h = y1 - y0 + 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 SDL_FillRect(screen, &rc, col);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 const int bpp = screen->format->BytesPerPixel,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
21
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 DM_SWAP(int, x0, x1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 if (x0 < cx0) x0 = cx0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 if (x1 > cx1) x1 = cx1;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
26
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
27 int x = x1 - x0 + 1;
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
28 Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 switch (screen->format->BitsPerPixel)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 case 8:
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
32 while (x--)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 *pix++ = col;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 break;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
35
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 case 32:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
38 Uint32 *p = (Uint32 *) pix;
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
39 while (x--)
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
40 *p++ = col;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 const int bpp = screen->format->BytesPerPixel,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 pitch = screen->pitch / bpp,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 DM_SWAP(int, y0, y1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 if (y0 < cy0) y0 = cy0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 if (y1 > cy1) y1 = cy1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
60 int y = y1 - y0 + 1;
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
61 Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 switch (screen->format->BitsPerPixel)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 case 8:
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
65 while (y--)
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
66 {
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 *pix = col;
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
68 pix += pitch;
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
69 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 break;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
71
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 case 32:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
717
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
74 Uint32 *p = (Uint32 *) pix;
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
75 while (y--)
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
76 {
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
77 *p = col;
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
78 p += pitch;
451fde45e116 Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 325
diff changeset
79 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
150
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
86 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol)
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
87 {
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
88 dmDrawHLine(screen, x0 , x1 - 1, y0, ucol);
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
89 dmDrawHLine(screen, x0 + 1, x1 , y1, dcol);
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
90
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
91 dmDrawVLine(screen, y0 , y1 - 1, x0, ucol);
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
92 dmDrawVLine(screen, y0 + 1, y1 , x1, dcol);
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
93 }
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
94
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
95
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
96 void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 SDL_Rect rc;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 rc.x = x0 + 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 rc.y = y0 + 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 rc.w = x1 - x0 - 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 rc.h = y1 - y0 - 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 SDL_FillRect(screen, &rc, bgcol);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
150
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
106 dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }