Changeset 204 for libcaca/trunk/src
- Timestamp:
- Nov 21, 2003, 3:34:07 PM (19 years ago)
- Location:
- libcaca/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/blit.c
r200 r204 84 84 } 85 85 86 void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) 87 { 86 struct caca_bitmap 87 { 88 int bpp; 89 int w, h, pitch; 90 int rmask, gmask, bmask; 91 }; 92 93 struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, 94 int rmask, int gmask, int bmask) 95 { 96 struct caca_bitmap *bitmap; 97 98 /* Currently only this format is supported. Will improve later. */ 99 if(!w || !h || !pitch || bpp != 32 || 100 rmask != 0x00ff0000 || gmask != 0x0000ff00 || bmask != 0x000000ff) 101 return NULL; 102 103 bitmap = malloc(sizeof(struct caca_bitmap)); 104 if(!bitmap) 105 return NULL; 106 107 bitmap->bpp = bpp; 108 109 bitmap->w = w; 110 bitmap->h = h; 111 bitmap->pitch = pitch; 112 113 bitmap->rmask = rmask; 114 bitmap->gmask = gmask; 115 bitmap->bmask = bmask; 116 117 return bitmap; 118 } 119 120 void caca_free_bitmap(struct caca_bitmap *bitmap) 121 { 122 if(!bitmap) 123 return; 124 125 free(bitmap); 126 } 127 128 void caca_draw_bitmap(int x1, int y1, int x2, int y2, 129 struct caca_bitmap *bitmap, char *pixels) 130 { 131 /* FIXME: this code is shite! */ 88 132 static int white_colors[] = {CACA_COLOR_DARKGRAY, CACA_COLOR_LIGHTGRAY, CACA_COLOR_WHITE}; 89 133 static int light_colors[] = {CACA_COLOR_LIGHTMAGENTA, CACA_COLOR_LIGHTRED, CACA_COLOR_YELLOW, CACA_COLOR_LIGHTGREEN, CACA_COLOR_LIGHTCYAN, CACA_COLOR_LIGHTBLUE, CACA_COLOR_LIGHTMAGENTA}; 90 134 static int dark_colors[] = {CACA_COLOR_MAGENTA, CACA_COLOR_RED, CACA_COLOR_BROWN, CACA_COLOR_GREEN, CACA_COLOR_CYAN, CACA_COLOR_BLUE, CACA_COLOR_MAGENTA}; 91 135 static char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' }; 92 int x, y, pitch; 136 int x, y, w, h, pitch; 137 138 if(!bitmap || !pixels) 139 return; 140 141 w = bitmap->w; 142 h = bitmap->h; 143 pitch = bitmap->pitch; 93 144 94 145 if(x1 > x2) … … 101 152 int tmp = y2; y2 = y1; y1 = tmp; 102 153 } 103 104 //pitch = (3 * w + 3) / 4 * 4;105 pitch = 4 * w;106 154 107 155 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++) … … 115 163 int fromx = w * (x - x1) / (x2 - x1 + 1); 116 164 int fromy = h * (y - y1) / (y2 - y1 + 1); 117 //int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy]; 118 //int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy]; 119 //int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy]; 165 /* FIXME: bwahaaa, we don't even respect masks */ 120 166 int b = ((unsigned char *)pixels)[4 * fromx + pitch * fromy]; 121 167 int g = ((unsigned char *)pixels)[4 * fromx + 1 + pitch * fromy]; -
libcaca/trunk/src/caca.h
r199 r204 102 102 103 103 /* 104 * Types104 * Internal types 105 105 */ 106 106 struct caca_sprite; 107 struct caca_bitmap; 107 108 108 109 /* 109 * Prototypes110 * Basic functions 110 111 */ 111 112 int caca_init(void); … … 119 120 void caca_end(void); 120 121 122 /* 123 * Events 124 */ 121 125 int caca_get_event(void); 122 126 127 /* 128 * Character graphics 129 */ 123 130 void caca_set_color(enum caca_color); 124 131 enum caca_color caca_get_color(void); … … 128 135 void caca_clear(void); 129 136 137 /* 138 * Graphics primitives 139 */ 130 140 void caca_draw_line(int, int, int, int, char); 131 141 void caca_draw_polyline(const int[], const int[], int, char); … … 146 156 void caca_fill_triangle(int, int, int, int, int, int, char); 147 157 158 /* 159 * Maths 160 */ 148 161 int caca_rand(int, int); 149 162 unsigned int caca_sqrt(unsigned int); 150 163 164 /* 165 * Sprite handling 166 */ 151 167 struct caca_sprite * caca_load_sprite(const char *); 152 168 int caca_get_sprite_frames(struct caca_sprite *); … … 158 174 void caca_free_sprite(struct caca_sprite *); 159 175 160 void caca_blit(int, int, int, int, void *, int, int); 176 /* 177 * Bitmap handling 178 */ 179 struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int); 180 void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *); 181 void caca_free_bitmap(struct caca_bitmap *); 161 182 162 183 #ifdef __cplusplus
Note: See TracChangeset
for help on using the changeset viewer.