Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/draw/codec/tga.c

    r9250517 ra35b458  
    4646        uint8_t cmap_type;
    4747        uint8_t img_type;
    48        
     48
    4949        uint16_t cmap_first_entry;
    5050        uint16_t cmap_entries;
    5151        uint8_t cmap_bpp;
    52        
     52
    5353        uint16_t startx;
    5454        uint16_t starty;
     
    7979        cmap_type_t cmap_type;
    8080        img_type_t img_type;
    81        
     81
    8282        uint16_t cmap_first_entry;
    8383        uint16_t cmap_entries;
    8484        uint8_t cmap_bpp;
    85        
     85
    8686        uint16_t startx;
    8787        uint16_t starty;
     
    9191        uint8_t img_alpha_bpp;
    9292        uint8_t img_alpha_dir;
    93        
     93
    9494        void *id_data;
    9595        size_t id_length;
    96        
     96
    9797        void *cmap_data;
    9898        size_t cmap_length;
    99        
     99
    100100        void *img_data;
    101101        size_t img_length;
     
    117117        if (size < sizeof(tga_header_t))
    118118                return false;
    119        
     119
    120120        tga_header_t *head = (tga_header_t *) data;
    121        
     121
    122122        /* Image ID field */
    123123        tga->id_data = data + sizeof(tga_header_t);
    124124        tga->id_length = head->id_length;
    125        
     125
    126126        if (size < sizeof(tga_header_t) + tga->id_length)
    127127                return false;
    128        
     128
    129129        /* Color map type */
    130130        tga->cmap_type = head->cmap_type;
    131        
     131
    132132        /* Image type */
    133133        tga->img_type = head->img_type;
    134        
     134
    135135        /* Color map specification */
    136136        tga->cmap_first_entry = uint16_t_le2host(head->cmap_first_entry);
     
    139139        tga->cmap_data = tga->id_data + tga->id_length;
    140140        tga->cmap_length = ALIGN_UP(tga->cmap_entries * tga->cmap_bpp, 8) >> 3;
    141        
     141
    142142        if (size < sizeof(tga_header_t) + tga->id_length +
    143143            tga->cmap_length)
    144144                return false;
    145        
     145
    146146        /* Image specification */
    147147        tga->startx = uint16_t_le2host(head->startx);
     
    154154        tga->img_data = tga->cmap_data + tga->cmap_length;
    155155        tga->img_length = ALIGN_UP(tga->width * tga->height * tga->img_bpp, 8) >> 3;
    156        
     156
    157157        if (size < sizeof(tga_header_t) + tga->id_length +
    158158            tga->cmap_length + tga->img_length)
    159159                return false;
    160        
     160
    161161        return true;
    162162}
     
    182182        if (!decode_tga_header(data, size, &tga))
    183183                return NULL;
    184        
     184
    185185        /*
    186186         * Check for unsupported features.
    187187         */
    188        
     188
    189189        switch (tga.cmap_type) {
    190190        case CMAP_NOT_PRESENT:
     
    194194                return NULL;
    195195        }
    196        
     196
    197197        switch (tga.img_type) {
    198198        case IMG_BGRA:
     
    208208                return NULL;
    209209        }
    210        
     210
    211211        if (tga.img_alpha_bpp != 0)
    212212                return NULL;
    213        
     213
    214214        sysarg_t twidth = tga.startx + tga.width;
    215215        sysarg_t theight = tga.starty + tga.height;
    216        
     216
    217217        surface_t *surface = surface_create(twidth, theight, NULL, flags);
    218218        if (surface == NULL)
    219219                return NULL;
    220        
     220
    221221        /*
    222222         * TGA is encoded in a bottom-up manner, the true-color
    223223         * variant is in BGR 8:8:8 encoding.
    224224         */
    225        
     225
    226226        switch (tga.img_type) {
    227227        case IMG_BGRA:
     
    230230                                size_t offset =
    231231                                    ((y - tga.starty) * tga.width + (x - tga.startx)) * 3;
    232                                
     232
    233233                                pixel_t pixel =
    234234                                    bgr_888_2pixel(((uint8_t *) tga.img_data) + offset);
     
    242242                                size_t offset =
    243243                                    (y - tga.starty) * tga.width + (x - tga.startx);
    244                                
     244
    245245                                pixel_t pixel =
    246246                                    gray_8_2pixel(((uint8_t *) tga.img_data) + offset);
     
    252252                break;
    253253        }
    254        
     254
    255255        return surface;
    256256}
Note: See TracChangeset for help on using the changeset viewer.