[78a71936] | 1 | /*
|
---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libgfx
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file Bitmap
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <gfx/bitmap.h>
|
---|
| 37 | #include <stdint.h>
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 | #include "../private/bitmap.h"
|
---|
| 40 | #include "../private/context.h"
|
---|
| 41 |
|
---|
| 42 | /** Allocate bitmap in a graphics context.
|
---|
| 43 | *
|
---|
| 44 | * @param gc Graphic context
|
---|
| 45 | * @param params Bitmap parameters
|
---|
| 46 | * @param alloc Bitmap allocation info or @c NULL to let GC allocate
|
---|
| 47 | * pixel storage
|
---|
| 48 | * @param rbitmap Place to store pointer to new bitmap
|
---|
| 49 | *
|
---|
| 50 | * @return EOK on success, EINVAL if parameters are invald,
|
---|
| 51 | * ENOMEM if insufficient resources, EIO if grahic device connection
|
---|
| 52 | * was lost
|
---|
| 53 | */
|
---|
| 54 | errno_t gfx_bitmap_create(gfx_context_t *gc, gfx_bitmap_params_t *params,
|
---|
| 55 | gfx_bitmap_alloc_t *alloc, gfx_bitmap_t **rbitmap)
|
---|
| 56 | {
|
---|
[dcc4cb31] | 57 | void *bm_priv;
|
---|
| 58 | gfx_bitmap_t *bitmap;
|
---|
| 59 | errno_t rc;
|
---|
| 60 |
|
---|
| 61 | bitmap = calloc(1, sizeof(gfx_bitmap_t));
|
---|
| 62 | if (bitmap == NULL)
|
---|
| 63 | return ENOMEM;
|
---|
| 64 |
|
---|
| 65 | rc = gc->ops->bitmap_create(gc->arg, params, alloc, &bm_priv);
|
---|
| 66 | if (rc != EOK)
|
---|
| 67 | return rc;
|
---|
| 68 |
|
---|
| 69 | bitmap->gc = gc;
|
---|
| 70 | bitmap->gc_priv = bm_priv;
|
---|
| 71 | *rbitmap = bitmap;
|
---|
| 72 | return EOK;
|
---|
[78a71936] | 73 | }
|
---|
| 74 |
|
---|
[dcc4cb31] | 75 | /** Destroy bitmap from graphics context.
|
---|
[78a71936] | 76 | *
|
---|
| 77 | * @param bitmap Bitmap
|
---|
| 78 | *
|
---|
| 79 | * @return EOK on success, EIO if grahic device connection was lost
|
---|
| 80 | */
|
---|
[dcc4cb31] | 81 | errno_t gfx_bitmap_destroy(gfx_bitmap_t *bitmap)
|
---|
[78a71936] | 82 | {
|
---|
[dcc4cb31] | 83 | errno_t rc;
|
---|
| 84 |
|
---|
| 85 | rc = bitmap->gc->ops->bitmap_destroy(bitmap->gc_priv);
|
---|
| 86 | if (rc != EOK)
|
---|
| 87 | return rc;
|
---|
| 88 |
|
---|
| 89 | free(bitmap);
|
---|
| 90 | return EOK;
|
---|
[78a71936] | 91 | }
|
---|
| 92 |
|
---|
| 93 | /** Render bitmap in graphics context.
|
---|
| 94 | *
|
---|
| 95 | * @param bitmap Bitmap
|
---|
| 96 | * @param srect Source rectangle or @c NULL to render entire bitmap
|
---|
| 97 | * @param offs Bitmap offset or @c NULL for zero offset
|
---|
| 98 | *
|
---|
| 99 | * @return EOK on success, EIO if grahic device connection was lost
|
---|
| 100 | */
|
---|
| 101 | errno_t gfx_bitmap_render(gfx_bitmap_t *bitmap, gfx_rect_t *srect,
|
---|
| 102 | gfx_coord2_t *offs)
|
---|
| 103 | {
|
---|
[dcc4cb31] | 104 | return bitmap->gc->ops->bitmap_render(bitmap->gc_priv, srect, offs);
|
---|
[78a71936] | 105 | }
|
---|
| 106 |
|
---|
| 107 | /** Get bitmap allocation info.
|
---|
| 108 | *
|
---|
| 109 | * @param bitmap Bitmap
|
---|
| 110 | * @param alloc Allocation info structure to fill in
|
---|
| 111 | *
|
---|
| 112 | * @return EOK on success, EIO if grahic device connection was lost
|
---|
| 113 | */
|
---|
| 114 | errno_t gfx_bitmap_get_alloc(gfx_bitmap_t *bitmap, gfx_bitmap_alloc_t *alloc)
|
---|
| 115 | {
|
---|
[dcc4cb31] | 116 | return bitmap->gc->ops->bitmap_get_alloc(bitmap->gc_priv, alloc);
|
---|
[78a71936] | 117 | }
|
---|
| 118 |
|
---|
| 119 | /** @}
|
---|
| 120 | */
|
---|