Changeset 204 for libcaca/trunk/src/blit.c
- Timestamp:
- Nov 21, 2003, 3:34:07 PM (19 years ago)
- File:
-
- 1 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];
Note: See TracChangeset
for help on using the changeset viewer.