[0576df9] | 1 | /*
|
---|
| 2 | * Copyright (c) 2014 Martin Decky
|
---|
| 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 |
|
---|
[fd05ea6] | 29 | /** @addtogroup libgfximage
|
---|
[0576df9] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <gzip.h>
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 | #include <gfximage/tga.h>
|
---|
| 40 | #include <gfximage/tga_gz.h>
|
---|
| 41 |
|
---|
| 42 | /** Decode gzipped Truevision TGA format
|
---|
| 43 | *
|
---|
| 44 | * Decode gzipped Truevision TGA format and create a bitmap
|
---|
| 45 | * from it. The supported variants of TGA are limited those
|
---|
| 46 | * supported by decode_tga().
|
---|
| 47 | *
|
---|
| 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
|
---|
| 53 | *
|
---|
| 54 | * @return EOK un success or an error code
|
---|
| 55 | */
|
---|
| 56 | errno_t decode_tga_gz(gfx_context_t *gc, void *data, size_t size,
|
---|
| 57 | gfx_bitmap_t **rbitmap, gfx_rect_t *rrect)
|
---|
| 58 | {
|
---|
| 59 | void *data_expanded;
|
---|
| 60 | size_t size_expanded;
|
---|
| 61 | errno_t rc;
|
---|
| 62 |
|
---|
| 63 | rc = gzip_expand(data, size, &data_expanded, &size_expanded);
|
---|
| 64 | if (rc != EOK)
|
---|
| 65 | return rc;
|
---|
| 66 |
|
---|
| 67 | rc = decode_tga(gc, data_expanded, size_expanded, rbitmap, rrect);
|
---|
| 68 | free(data_expanded);
|
---|
| 69 | return rc;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /** @}
|
---|
| 73 | */
|
---|