Changeset 7e38970d in mainline for uspace/lib/gfximage/src


Ignore:
Timestamp:
2020-12-07T00:08:37Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
Children:
25f26600
Parents:
7a873f0 (diff), 8596474 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'jxsvoboda-gfx' into master

Location:
uspace/lib/gfximage/src
Files:
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfximage/src/tga.c

    r7a873f0 r7e38970d  
    4040#include <stdbool.h>
    4141#include <pixconv.h>
    42 #include <draw/codec.h>
     42#include <gfx/bitmap.h>
     43#include <gfximage/tga.h>
     44#include <io/pixelmap.h>
    4345
    4446typedef struct {
     
    169171 * alpha channel.
    170172 *
    171  * @param[in] data  Memory representation of TGA.
    172  * @param[in] size  Size of the representation (in bytes).
    173  * @param[in] flags Surface creation flags.
    174  *
    175  * @return Newly allocated surface with the decoded content.
    176  * @return NULL on error or unsupported format.
    177  *
    178  */
    179 surface_t *decode_tga(void *data, size_t size, surface_flags_t flags)
     173 * @param gc      Graphic context
     174 * @param data    Memory representation of gzipped TGA.
     175 * @param size    Size of the representation (in bytes).
     176 * @param rbitmap Place to store pointer to new bitmap
     177 * @param rrect   Place to store bitmap rectangle
     178 *
     179 * @return EOK un success or an error code
     180 */
     181errno_t decode_tga(gfx_context_t *gc, void *data, size_t size,
     182    gfx_bitmap_t **rbitmap, gfx_rect_t *rrect)
    180183{
     184        gfx_bitmap_params_t params;
     185        gfx_bitmap_alloc_t alloc;
     186        gfx_bitmap_t *bitmap = NULL;
     187        pixelmap_t pixelmap;
     188        errno_t rc;
     189
    181190        tga_t tga;
    182191        if (!decode_tga_header(data, size, &tga))
    183                 return NULL;
     192                return EINVAL;
    184193
    185194        /*
     
    192201        default:
    193202                /* Unsupported */
    194                 return NULL;
     203                return ENOTSUP;
    195204        }
    196205
     
    198207        case IMG_BGRA:
    199208                if (tga.img_bpp != 24)
    200                         return NULL;
     209                        return ENOTSUP;
    201210                break;
    202211        case IMG_GRAY:
    203212                if (tga.img_bpp != 8)
    204                         return NULL;
     213                        return ENOTSUP;
    205214                break;
    206215        default:
    207216                /* Unsupported */
    208                 return NULL;
     217                return ENOTSUP;
    209218        }
    210219
    211220        if (tga.img_alpha_bpp != 0)
    212                 return NULL;
     221                return ENOTSUP;
    213222
    214223        sysarg_t twidth = tga.startx + tga.width;
    215224        sysarg_t theight = tga.starty + tga.height;
    216225
    217         surface_t *surface = surface_create(twidth, theight, NULL, flags);
    218         if (surface == NULL)
    219                 return NULL;
     226        gfx_bitmap_params_init(&params);
     227        params.rect.p1.x = twidth;
     228        params.rect.p1.y = theight;
     229
     230        rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
     231        if (rc != EOK)
     232                return rc;
     233
     234        rc = gfx_bitmap_get_alloc(bitmap, &alloc);
     235        if (rc != EOK) {
     236                gfx_bitmap_destroy(bitmap);
     237                return rc;
     238        }
     239
     240        pixelmap.width = twidth;
     241        pixelmap.height = theight;
     242        pixelmap.data = alloc.pixels;
    220243
    221244        /*
     
    233256                                pixel_t pixel =
    234257                                    bgr_888_2pixel(((uint8_t *) tga.img_data) + offset);
    235                                 surface_put_pixel(surface, x, theight - y - 1, pixel);
     258                                pixelmap_put_pixel(&pixelmap, x, theight - y - 1, pixel);
    236259                        }
    237260                }
     
    245268                                pixel_t pixel =
    246269                                    gray_8_2pixel(((uint8_t *) tga.img_data) + offset);
    247                                 surface_put_pixel(surface, x, theight - y - 1, pixel);
     270                                pixelmap_put_pixel(&pixelmap, x, theight - y - 1, pixel);
    248271                        }
    249272                }
     
    253276        }
    254277
    255         return surface;
     278        *rbitmap = bitmap;
     279        *rrect = params.rect;
     280        return EOK;
    256281}
    257282
    258 /** Encode Truevision TGA format
    259  *
    260  * Encode Truevision TGA format into an array.
    261  *
    262  * @param[in]  surface Surface to be encoded into TGA.
    263  * @param[out] pdata   Pointer to the resulting array.
    264  * @param[out] psize   Pointer to the size of the resulting array.
    265  *
    266  * @return True on succesful encoding.
    267  * @return False on failure.
    268  *
    269  */
    270 bool encode_tga(surface_t *surface, void **pdata, size_t *psize)
    271 {
    272         // TODO
    273         return false;
    274 }
    275 
    276283/** @}
    277284 */
  • uspace/lib/gfximage/src/tga_gz.c

    r7a873f0 r7e38970d  
    3737#include <gzip.h>
    3838#include <stdlib.h>
    39 #include <draw/codec.h>
     39#include <gfximage/tga.h>
     40#include <gfximage/tga_gz.h>
    4041
    4142/** Decode gzipped Truevision TGA format
    4243 *
    43  * Decode gzipped Truevision TGA format and create a surface
     44 * Decode gzipped Truevision TGA format and create a bitmap
    4445 * from it. The supported variants of TGA are limited those
    4546 * supported by decode_tga().
    4647 *
    47  * @param[in] data  Memory representation of gzipped TGA.
    48  * @param[in] size  Size of the representation (in bytes).
    49  * @param[in] flags Surface creation flags.
     48 * @param gc      Graphic context
     49 * @param data    Memory representation of gzipped TGA.
     50 * @param size    Size of the representation (in bytes).
     51 * @param rbitmap Place to store pointer to new bitmap
     52 * @param rrect   Place to store bitmap rectangle
    5053 *
    51  * @return Newly allocated surface with the decoded content.
    52  * @return NULL on error or unsupported format.
    53  *
     54 * @return EOK un success or an error code
    5455 */
    55 surface_t *decode_tga_gz(void *data, size_t size, surface_flags_t flags)
     56errno_t decode_tga_gz(gfx_context_t *gc, void *data, size_t size,
     57    gfx_bitmap_t **rbitmap, gfx_rect_t *rrect)
    5658{
    5759        void *data_expanded;
    5860        size_t size_expanded;
     61        errno_t rc;
    5962
    60         errno_t ret = gzip_expand(data, size, &data_expanded, &size_expanded);
    61         if (ret != EOK)
    62                 return NULL;
     63        rc = gzip_expand(data, size, &data_expanded, &size_expanded);
     64        if (rc != EOK)
     65                return rc;
    6366
    64         surface_t *surface = decode_tga(data_expanded, size_expanded, flags);
    65 
     67        rc = decode_tga(gc, data_expanded, size_expanded, rbitmap, rrect);
    6668        free(data_expanded);
    67         return surface;
    68 }
    69 
    70 /** Encode gzipped Truevision TGA format
    71  *
    72  * Encode gzipped Truevision TGA format into an array.
    73  *
    74  * @param[in]  surface Surface to be encoded into gzipped TGA.
    75  * @param[out] pdata   Pointer to the resulting array.
    76  * @param[out] psize   Pointer to the size of the resulting array.
    77  *
    78  * @return True on succesful encoding.
    79  * @return False on failure.
    80  *
    81  */
    82 bool encode_tga_gz(surface_t *surface, void **pdata, size_t *psize)
    83 {
    84         // TODO
    85         return false;
     69        return rc;
    8670}
    8771
Note: See TracChangeset for help on using the changeset viewer.