Project

General

Profile

Revision 208

changed graph

View differences:

proj/include/graph.h
18 18
/// PUBLIC GET
19 19
uint16_t   (graph_get_XRes)         (void);
20 20
uint16_t   (graph_get_YRes)         (void);
21
uint16_t   (graph_get_bytes_pixel)  (void);
21 22

  
22 23
/// INIT
23 24
int (graph_init)(uint16_t mode);
......
27 28

  
28 29
/// PIXEL DRAWING
29 30
int (graph_set_pixel)             (uint16_t x, uint16_t y, uint32_t color);
30
int (graph_set_pixel_buffer)      (uint16_t x, uint16_t y, uint32_t color, uint8_t *buf, uint16_t W, uint16_t H);
31
int (graph_set_pixel_alpha_buffer)(uint16_t x, uint16_t y, uint8_t alpha, uint8_t *alp_buf, uint16_t W, uint16_t H);
32
//int (graph_set_pixel_alpha)       (uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
31
void (graph_set_pixel_pos)         (unsigned pos          , uint32_t color);
33 32

  
34 33
/// SCREEN
35 34
int (graph_clear_screen)(void);
proj/src/font.c
35 35
}
36 36
static int (glyph_draw_to_alpha_buffer)(const glyph_t *p, int16_t x, int16_t y, uint8_t *alp_buf, uint16_t W, uint16_t H){
37 37
    if(p == NULL) return NULL_PTR;
38
    int r;
39 38
    for(int16_t h = 0; h < p->h; ++h){
40 39
        for(int16_t w = 0; w < p->w; ++w){
41 40
            uint32_t c = *((uint32_t*)p->map + w + h*p->w);
42 41
            uint8_t a = GET_ALP(c);
43
            //c = c & 0xFF000000;
44
            //if(c != 0) printf("%d %d 0x%X\n", w, h, c);
45
            //else       printf("%d %d <========================\n");
46

  
47
            r = graph_set_pixel_alpha_buffer(x+w, y-p->h+h, a, alp_buf, W, H);
48

  
49

  
50
            //r = graph_set_pixel_alpha(x+w, y-p->h+h, GET_COLOR(c), GET_ALP(c));
51

  
52
            //printf("%d %d 0x%X\n", x, y, *(buf+(x+y*p->w)*sizeof(uint32_t)));
53
            if(r != SUCCESS && r != OUT_OF_RANGE) return r;
42
            
43
            int16_t x_ = x+w, y_ = y-p->h+h;
44
            unsigned pos = x_ +y_*W;
45
            alp_buf[pos] = a;
54 46
        }
55 47
    }
56 48
    return SUCCESS;
proj/src/graph.c
29 29

  
30 30
static vbe_mode_info_t vbe_mem_info;
31 31

  
32
/// PUBLIC GET
33
uint16_t   (graph_get_XRes)         (void){ return vbe_mem_info.XResolution; }
34
uint16_t   (graph_get_YRes)         (void){ return vbe_mem_info.YResolution; }
35

  
36 32
/// PRIVATE GET
37 33
static uint16_t   (graph_get_bits_pixel)   (void){ return vbe_mem_info.BitsPerPixel; }
38
static uint16_t   (graph_get_bytes_pixel)  (void){ return (graph_get_bits_pixel() + 7) >> 3; }
39 34
static phys_bytes (graph_get_phys_addr)    (void){ return vbe_mem_info.PhysBasePtr; }
40 35
static unsigned   (graph_get_vram_size)    (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * graph_get_bytes_pixel(); }
41 36
//static uint16_t   (graph_get_RedMaskSize)  (void){ return vbe_mem_info.RedMaskSize  ; }
42 37
//static uint16_t   (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; }
43 38
//static uint16_t   (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; }
44 39

  
40
/// PUBLIC GET
41
uint16_t   (graph_get_XRes)         (void){ return vbe_mem_info.XResolution; }
42
uint16_t   (graph_get_YRes)         (void){ return vbe_mem_info.YResolution; }
43
uint16_t   (graph_get_bytes_pixel)  (void){ return (graph_get_bits_pixel() + 7) >> 3; }
44

  
45
///
45 46
static int (get_permission)(unsigned int base_addr, unsigned int size) {
46 47
    struct minix_mem_range mmr;
47 48
    mmr.mr_base = base_addr;
......
244 245

  
245 246
/// PIXEL DRAWING
246 247
int (graph_set_pixel)(uint16_t x, uint16_t y, uint32_t color) {
247
    /*
248 248
    if (x < 0 || vbe_mem_info.XResolution <= x || y < 0 || vbe_mem_info.YResolution <= y) {
249 249
        //printf("%s: invalid pixel.\n", __func__);
250 250
        return OUT_OF_RANGE;
......
252 252
    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
253 253
    memcpy(video_buf + pos, &color, graph_get_bytes_pixel());
254 254
    return SUCCESS;
255
    */
256
    return graph_set_pixel_buffer(x, y, color, video_buf, graph_get_XRes(), graph_get_YRes());
257 255
}
258
int (graph_set_pixel_buffer)(uint16_t x, uint16_t y, uint32_t color, uint8_t *buf, uint16_t W, uint16_t H) {
259
    if(buf == NULL) return NULL_PTR;
260
    if (x < 0 || W <= x || y < 0 || H <= y) {
261
        //printf("%s: invalid pixel.\n", __func__);
262
        return OUT_OF_RANGE;
263
    }
264
    unsigned int pos = (x + y * W) * graph_get_bytes_pixel();
265
    memcpy(buf + pos, &color, graph_get_bytes_pixel());
266
    return SUCCESS;
267
}
268
int (graph_set_pixel_alpha_buffer)(uint16_t x, uint16_t y, uint8_t alpha, uint8_t *alp_buf, uint16_t W, uint16_t H) {
269
    if(alp_buf == NULL) return NULL_PTR;
270
    if (x < 0 || W <= x || y < 0 || H <= y) {
271
        //printf("%s: invalid pixel.\n", __func__);
272
        return OUT_OF_RANGE;
273
    }
274
    unsigned int pos = x + y * W;
275
    memcpy(alp_buf + pos, &alpha, 1);
276
    return SUCCESS;
277
}
278
/*
279
int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha){
280
    if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) {
281
        //printf("%s: invalid pixel.\n", __func__);
282
        return OUT_OF_RANGE;
283
    }
284
    unsigned int pos = (x + y * vbe_mem_info.XResolution) * graph_get_bytes_pixel();
285
    uint32_t color_;
286
    memcpy(&color_, video_buf + pos, graph_get_bytes_pixel());
287
    float a = 1.0-(alpha&0xFF)/(float)0xFF;
288
    uint8_t r = GET_RED(color)*a + GET_RED(color_)*(1.0-a);
289
    uint8_t g = GET_GRE(color)*a + GET_GRE(color_)*(1.0-a);
290
    uint8_t b = GET_BLU(color)*a + GET_BLU(color_)*(1.0-a); (void)(r*g*b);
291
    //return graph_set_pixel(x,y,SET_RGB(r,g,b));
292
    color = SET_RGB(r,g,b);
293
    //unsigned int pos = (x + y * W) * graph_get_bytes_pixel();
256
void (graph_set_pixel_pos)(unsigned pos, uint32_t color){
294 257
    memcpy(video_buf + pos, &color, graph_get_bytes_pixel());
295
    return SUCCESS;
296 258
}
297
*/
298
int (graph_clear_screen)(void){
299
    //return graph_paint_screen(BLACK);
300
    memset(video_buf, 0, graph_get_vram_size());
301
    return SUCCESS;
302
}
259
int (graph_clear_screen)(void){ memset(video_buf, 0, graph_get_vram_size()); return SUCCESS; }
260
int (graph_draw)(void){ memcpy(video_mem, video_buf, graph_get_vram_size()); return SUCCESS; }
303 261

  
304
int (graph_draw)(void){
305
    memcpy(video_mem, video_buf, graph_get_vram_size());
306
    return 0;
307
}
262
/// SPRITE
proj/src/sprite.c
104 104
        ymin = max(ymin-2, 0); ymax = min(ymax+2, graph_get_YRes());
105 105
    }
106 106
    const uint8_t *map = basic_sprite_get_map(p->bsp);
107
    int16_t u, v;
108
    for(int16_t y = ymin; y < ymax; ++y){
109
        for(int16_t x = xmin; x < xmax; ++x){
107
    const uint16_t bytes_pixel = graph_get_bytes_pixel();
108
    for(int16_t u, v, y = ymin; y < ymax; ++y){
109
        unsigned pos = (xmin + y*graph_get_XRes())*bytes_pixel;
110
        for(int16_t x = xmin; x < xmax; ++x, pos += bytes_pixel){
110 111
            sprite_src2pic(p, x, y, &u, &v);
111 112
            if(0 <= u && u < w && 0 <= v && v < h){
112 113
                uint32_t c = *(uint32_t*)(map + (v*w + u)*4);
113 114
                if(GET_ALP(c) < 0x7F)
114
                    graph_set_pixel(x, y, GET_COLOR(c));
115
                    graph_set_pixel_pos(pos, c);
115 116
            }
116 117
        }
117 118
    }

Also available in: Unified diff