Index: libs/png/export/libpng.h |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2011 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emCORE.
|
| 8 | +//
|
| 9 | +// emCORE is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emCORE is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#ifndef __LIBPNG_H__
|
| 26 | +#define __LIBPNG_H__
|
| 27 | +
|
| 28 | +
|
| 29 | +#include "emcorelib.h"
|
| 30 | +
|
| 31 | +
|
| 32 | +#include "../png.h"
|
| 33 | +
|
| 34 | +
|
| 35 | +/* increase this every time the api struct changes */
|
| 36 | +#define LIBPNG_API_VERSION 1
|
| 37 | +
|
| 38 | +/* update this to latest version if a change to the api struct breaks
|
| 39 | + backwards compatibility (and please take the opportunity to sort in any
|
| 40 | + new function which are "waiting" at the end of the function table) */
|
| 41 | +#define LIBPNG_MIN_API_VERSION 1
|
| 42 | +
|
| 43 | +/* NOTE: To support backwards compatibility, only add new functions at
|
| 44 | + the end of the structure. Every time you add a new function,
|
| 45 | + remember to increase LIBPNG_API_VERSION. If you make changes to the
|
| 46 | + existing APIs, also update LIBPNG_MIN_API_VERSION to current version */
|
| 47 | +
|
| 48 | +struct libpng_api
|
| 49 | +{
|
| 50 | + typeof(png_open)* png_open;
|
| 51 | + typeof(png_get_width)* png_get_width;
|
| 52 | + typeof(png_get_height)* png_get_height;
|
| 53 | + typeof(png_set_background)* png_set_background;
|
| 54 | + typeof(png_decode_rgba)* png_decode_rgba;
|
| 55 | + typeof(png_decode_rgb)* png_decode_rgb;
|
| 56 | + typeof(png_destroy)* png_destroy;
|
| 57 | +};
|
| 58 | +
|
| 59 | +
|
| 60 | +#endif
|
Index: libs/png/png_format.h |
— | — | @@ -0,0 +1,68 @@ |
| 2 | +// |
| 3 | +// |
| 4 | +// Copyright 2011 TheSeven |
| 5 | +// |
| 6 | +// |
| 7 | +// This file is part of emCORE. |
| 8 | +// |
| 9 | +// emCORE is free software: you can redistribute it and/or |
| 10 | +// modify it under the terms of the GNU General Public License as |
| 11 | +// published by the Free Software Foundation, either version 2 of the |
| 12 | +// License, or (at your option) any later version. |
| 13 | +// |
| 14 | +// emCORE is distributed in the hope that it will be useful, |
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 17 | +// See the GNU General Public License for more details. |
| 18 | +// |
| 19 | +// You should have received a copy of the GNU General Public License along |
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +// |
| 22 | +// |
| 23 | + |
| 24 | + |
| 25 | +#ifndef __PNG_DECODER_H__ |
| 26 | +#define __PNG_DECODER_H__ |
| 27 | + |
| 28 | + |
| 29 | +#include "emcorelib.h" |
| 30 | + |
| 31 | + |
| 32 | +/* PNG chunk types signatures */ |
| 33 | +/* critical chunks */ |
| 34 | +#define PNG_CHUNK_IHDR 0x49484452 |
| 35 | +#define PNG_CHUNK_PLTE 0x504c5445 |
| 36 | +#define PNG_CHUNK_IDAT 0x49444154 |
| 37 | +#define PNG_CHUNK_IEND 0x49454e44 |
| 38 | + |
| 39 | +/* ancillary chunks */ |
| 40 | +#define PNG_CHUNK_bKGD 0x624b4744 |
| 41 | +#define PNG_CHUNK_cHRM 0x6348524d |
| 42 | +#define PNG_CHUNK_gAMA 0x67414d41 |
| 43 | +#define PNG_CHUNK_hIST 0x68495354 |
| 44 | +#define PNG_CHUNK_iCCP 0x69434350 |
| 45 | +#define PNG_CHUNK_pHYs 0x70485973 |
| 46 | +#define PNG_CHUNK_sBIT 0x73424954 |
| 47 | +#define PNG_CHUNK_sPLT 0x73504c54 |
| 48 | +#define PNG_CHUNK_sRGB 0x73524742 |
| 49 | +#define PNG_CHUNK_tEXt 0x74455874 |
| 50 | +#define PNG_CHUNK_tIME 0x74494d45 |
| 51 | +#define PNG_CHUNK_tRNS 0x74524e53 |
| 52 | +#define PNG_CHUNK_zTXt 0x7a545874 |
| 53 | + |
| 54 | +/* PNG color types */ |
| 55 | +#define PNG_COLORTYPE_GREY 0 |
| 56 | +#define PNG_COLORTYPE_RGB 2 |
| 57 | +#define PNG_COLORTYPE_PALETTE 3 |
| 58 | +#define PNG_COLORTYPE_GREYA 4 |
| 59 | +#define PNG_COLORTYPE_RGBA 6 |
| 60 | + |
| 61 | +/* PNG filter types */ |
| 62 | +#define PNG_FILTERTYPE_NONE 0 |
| 63 | +#define PNG_FILTERTYPE_SUB 1 |
| 64 | +#define PNG_FILTERTYPE_UP 2 |
| 65 | +#define PNG_FILTERTYPE_AVERAGE 3 |
| 66 | +#define PNG_FILTERTYPE_PAETH 4 |
| 67 | + |
| 68 | + |
| 69 | +#endif |
\ No newline at end of file |
Index: libs/png/tinfzlib.c |
— | — | @@ -0,0 +1,100 @@ |
| 2 | +/*************************************************************************** |
| 3 | + * __________ __ ___. |
| 4 | + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 5 | + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 6 | + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 7 | + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 8 | + * \/ \/ \/ \/ \/ |
| 9 | + * $Id$ |
| 10 | + * |
| 11 | + * Original source: |
| 12 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 13 | + * |
| 14 | + * Rockbox adaptation: |
| 15 | + * Copyright (c) 2010 by Marcin Bukat |
| 16 | + * |
| 17 | + * emCORE adaptation: |
| 18 | + * Copyright (c) 2011 by Michael Sparmann |
| 19 | + * |
| 20 | + * This program is free software; you can redistribute it and/or |
| 21 | + * modify it under the terms of the GNU General Public License |
| 22 | + * as published by the Free Software Foundation; either version 2 |
| 23 | + * of the License, or (at your option) any later version. |
| 24 | + * |
| 25 | + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 26 | + * KIND, either express or implied. |
| 27 | + * |
| 28 | + ****************************************************************************/ |
| 29 | + |
| 30 | +/* |
| 31 | + * tinfzlib - tiny zlib decompressor |
| 32 | + * |
| 33 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 34 | + * All Rights Reserved |
| 35 | + * |
| 36 | + * http://www.ibsensoftware.com/ |
| 37 | + * |
| 38 | + * This software is provided 'as-is', without any express |
| 39 | + * or implied warranty. In no event will the authors be |
| 40 | + * held liable for any damages arising from the use of |
| 41 | + * this software. |
| 42 | + * |
| 43 | + * Permission is granted to anyone to use this software |
| 44 | + * for any purpose, including commercial applications, |
| 45 | + * and to alter it and redistribute it freely, subject to |
| 46 | + * the following restrictions: |
| 47 | + * |
| 48 | + * 1. The origin of this software must not be |
| 49 | + * misrepresented; you must not claim that you |
| 50 | + * wrote the original software. If you use this |
| 51 | + * software in a product, an acknowledgment in |
| 52 | + * the product documentation would be appreciated |
| 53 | + * but is not required. |
| 54 | + * |
| 55 | + * 2. Altered source versions must be plainly marked |
| 56 | + * as such, and must not be misrepresented as |
| 57 | + * being the original software. |
| 58 | + * |
| 59 | + * 3. This notice may not be removed or altered from |
| 60 | + * any source distribution. |
| 61 | + */ |
| 62 | + |
| 63 | +#include "emcorelib.h" |
| 64 | +#include "tinf.h" |
| 65 | + |
| 66 | +/* This routine do not check adler32 checksum |
| 67 | + * as it is tailored to be used as PNG decompressor |
| 68 | + * and PNG has crc32 check of the compressed block |
| 69 | + * already |
| 70 | + */ |
| 71 | +int tinf_zlib_uncompress(void *dest, unsigned int *destLen, |
| 72 | + const void *source, unsigned int sourceLen) |
| 73 | +{ |
| 74 | + unsigned char *src = (unsigned char *)source; |
| 75 | + unsigned char *dst = (unsigned char *)dest; |
| 76 | + int res; |
| 77 | + unsigned char cmf, flg; |
| 78 | + |
| 79 | + /* -- get header bytes -- */ |
| 80 | + |
| 81 | + cmf = src[8]; |
| 82 | + flg = src[9]; |
| 83 | + |
| 84 | + /* -- check format -- */ |
| 85 | + |
| 86 | + /* check checksum */ |
| 87 | + if (((cmf << 8) + flg) % 31) return -1; |
| 88 | + |
| 89 | + /* check method is deflate */ |
| 90 | + if ((cmf & 0x0f) != 8) return -2; |
| 91 | + |
| 92 | + /* check window size is valid */ |
| 93 | + if ((cmf >> 4) > 7) return -3; |
| 94 | + |
| 95 | + /* check there is no preset dictionary */ |
| 96 | + if (flg & 0x20) return -4; |
| 97 | + |
| 98 | + /* -- inflate -- */ |
| 99 | + |
| 100 | + return tinf_uncompress(dst, destLen, src, sourceLen); |
| 101 | +} |
Index: libs/png/SOURCES |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +main.c |
| 3 | +tinflate.c |
| 4 | +tinfzlib.c |
| 5 | +png.c |
Index: libs/png/ls.x |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +ENTRY(__emcore_lib_header)
|
| 3 | +OUTPUT_FORMAT(elf32-littlearm)
|
| 4 | +OUTPUT_ARCH(arm)
|
| 5 | +
|
| 6 | +MEMORY
|
| 7 | +{
|
| 8 | + VIRTUAL : ORIGIN = 0x00000000, LENGTH = 0x10000000
|
| 9 | +}
|
| 10 | +
|
| 11 | +SECTIONS
|
| 12 | +{
|
| 13 | + .text :
|
| 14 | + {
|
| 15 | + __emcore_lib_base = .;
|
| 16 | + KEEP(.emcoreentrypoint*)
|
| 17 | + *(.emcoreentrypoint*)
|
| 18 | + *(.text*)
|
| 19 | + *(.glue_7)
|
| 20 | + *(.glue_7t)
|
| 21 | + . = ALIGN(0x10);
|
| 22 | + } > VIRTUAL
|
| 23 | +
|
| 24 | + .data :
|
| 25 | + {
|
| 26 | + *(.rodata*)
|
| 27 | + . = ALIGN(0x4);
|
| 28 | + *(.data*)
|
| 29 | + . = ALIGN(0x4);
|
| 30 | + } > VIRTUAL
|
| 31 | +
|
| 32 | + .bss (NOLOAD) :
|
| 33 | + {
|
| 34 | + *(.bss*)
|
| 35 | + *(COMMON)
|
| 36 | + } > VIRTUAL
|
| 37 | +
|
| 38 | + /DISCARD/ :
|
| 39 | + {
|
| 40 | + *(.eh_frame)
|
| 41 | + }
|
| 42 | +
|
| 43 | +}
|
Index: libs/png/main.c |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2011 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emCORE.
|
| 8 | +//
|
| 9 | +// emCORE is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emCORE is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#include "emcorelib.h"
|
| 26 | +#include "export/libpng.h"
|
| 27 | +
|
| 28 | +
|
| 29 | +struct libpng_api apitable =
|
| 30 | +{
|
| 31 | + .png_open = png_open,
|
| 32 | + .png_get_width = png_get_width,
|
| 33 | + .png_get_height = png_get_height,
|
| 34 | + .png_set_background = png_set_background,
|
| 35 | + .png_decode_rgba = png_decode_rgba,
|
| 36 | + .png_decode_rgb = png_decode_rgb,
|
| 37 | + .png_destroy = png_destroy
|
| 38 | +};
|
| 39 | +
|
| 40 | +EMCORE_LIB_HEADER(0x64474e50, LIBPNG_API_VERSION, LIBPNG_MIN_API_VERSION, NULL, NULL, apitable)
|
Index: libs/png/png.c |
— | — | @@ -0,0 +1,549 @@ |
| 2 | +// |
| 3 | +// |
| 4 | +// Copyright 2011 TheSeven |
| 5 | +// |
| 6 | +// |
| 7 | +// This file is part of emCORE. |
| 8 | +// |
| 9 | +// emCORE is free software: you can redistribute it and/or |
| 10 | +// modify it under the terms of the GNU General Public License as |
| 11 | +// published by the Free Software Foundation, either version 2 of the |
| 12 | +// License, or (at your option) any later version. |
| 13 | +// |
| 14 | +// emCORE is distributed in the hope that it will be useful, |
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 17 | +// See the GNU General Public License for more details. |
| 18 | +// |
| 19 | +// You should have received a copy of the GNU General Public License along |
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +// |
| 22 | +// |
| 23 | + |
| 24 | + |
| 25 | +//#define DEBUG_CONSOLES 2 |
| 26 | +//#define DEBUG_PRINT_SOURCE_LINE |
| 27 | + |
| 28 | + |
| 29 | +#include "emcorelib.h" |
| 30 | +#include "export/libpng.h" |
| 31 | +#include "tinf.h" |
| 32 | +#include "png_format.h" |
| 33 | + |
| 34 | + |
| 35 | +static uint32_t read32be(const uint8_t* in) |
| 36 | +{ |
| 37 | + return (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3]; |
| 38 | +} |
| 39 | + |
| 40 | +struct png_info* png_open(const void* data, size_t size) |
| 41 | +{ |
| 42 | + DEBUGF("png_open: Processing file at 0x%08X, size: %d", data, size); |
| 43 | + const uint8_t* in = (const uint8_t*)data; |
| 44 | + struct png_info info; |
| 45 | + memset(&info, 0, sizeof(info)); |
| 46 | + if (memcmp(in, "\x89PNG\r\n\x1a\n", 8)) |
| 47 | + { |
| 48 | + DEBUGF("png_open: Invalid signature: %02X %02X %02X %02X %02X %02X %02X %02X", |
| 49 | + in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]); |
| 50 | + return NULL; |
| 51 | + } |
| 52 | + in += 8; |
| 53 | + size -= 8; |
| 54 | + bool first = true; |
| 55 | + bool ihdr = false; |
| 56 | + int idat = 0; |
| 57 | + bool iend = false; |
| 58 | + while (size) |
| 59 | + { |
| 60 | + if (iend) |
| 61 | + { |
| 62 | + DEBUGF("png_open: %d bytes of garbage after IEND chunk", size); |
| 63 | + return NULL; |
| 64 | + } |
| 65 | + uint32_t length = read32be(in); |
| 66 | + DEBUGF("png_open: %08X (%d remaining): %c%c%c%c (%08X, %d+12 bytes)", |
| 67 | + in, size, in[4], in[5], in[6], in[7], read32be(in + 4), length); |
| 68 | + in += 4; |
| 69 | + if (length + 12 > size) |
| 70 | + { |
| 71 | + DEBUGF("png_open: Chunk reaches beyond end of file", size); |
| 72 | + return NULL; |
| 73 | + } |
| 74 | + if (crc32(in, length + 4) != read32be(in + length + 4)) |
| 75 | + { |
| 76 | + DEBUGF("png_open: Bad chunk CRC"); |
| 77 | + return NULL; |
| 78 | + } |
| 79 | + uint32_t chunk = read32be(in); |
| 80 | + if (chunk & 0x2000) |
| 81 | + { |
| 82 | + DEBUGF("png_open: Chunk name has reserved bit set: %08X", chunk); |
| 83 | + return NULL; |
| 84 | + } |
| 85 | + if (first && chunk != PNG_CHUNK_IHDR) |
| 86 | + { |
| 87 | + DEBUGF("png_open: First chunk is not IHDR"); |
| 88 | + return NULL; |
| 89 | + } |
| 90 | + if (idat && chunk != PNG_CHUNK_IDAT) idat = 2; |
| 91 | + in += 4; |
| 92 | + switch (chunk) |
| 93 | + { |
| 94 | + case PNG_CHUNK_IHDR: |
| 95 | + if (length != 13) |
| 96 | + { |
| 97 | + DEBUGF("png_open: Bad IHDR length: %d bytes", length); |
| 98 | + return NULL; |
| 99 | + } |
| 100 | + if (in[10]) |
| 101 | + { |
| 102 | + DEBUGF("png_open: Unknown compression type 0x%02X", in[10]); |
| 103 | + return NULL; |
| 104 | + } |
| 105 | + if (in[11]) |
| 106 | + { |
| 107 | + DEBUGF("png_open: Unknown filter type 0x%02X", in[11]); |
| 108 | + return NULL; |
| 109 | + } |
| 110 | + switch (in[9]) |
| 111 | + { |
| 112 | + case 0: |
| 113 | + if (in[8] == 16) break; |
| 114 | + case 3: |
| 115 | + if (in[8] == 1 || in[8] == 2 || in[8] == 4 || in[8] == 8) |
| 116 | + break; |
| 117 | + DEBUGF("png_open: Invalid depth 0x%02X for color type 0x%02X", in[8], in[9]); |
| 118 | + return NULL; |
| 119 | + case 2: |
| 120 | + case 4: |
| 121 | + case 6: |
| 122 | + if (in[8] == 8 || in[8] == 16) break; |
| 123 | + DEBUGF("png_open: Invalid depth %02X for color type 0x%02X", in[8], in[9]); |
| 124 | + return NULL; |
| 125 | + default: |
| 126 | + DEBUGF("png_open: Unknown color type 0x%02X", in[9]); |
| 127 | + return NULL; |
| 128 | + } |
| 129 | + if (in[12]) |
| 130 | + { |
| 131 | + DEBUGF("png_open: Only non-interlaced files are supported"); |
| 132 | + return NULL; |
| 133 | + } |
| 134 | + switch (in[9]) |
| 135 | + { |
| 136 | + case 0: |
| 137 | + case 3: |
| 138 | + info.channels = 1; |
| 139 | + break; |
| 140 | + case 4: |
| 141 | + info.channels = 2; |
| 142 | + break; |
| 143 | + case 2: |
| 144 | + info.channels = 3; |
| 145 | + break; |
| 146 | + case 6: |
| 147 | + info.channels = 4; |
| 148 | + break; |
| 149 | + default: |
| 150 | + DEBUGF("png_open: Unknown color type 0x%02X", info.colortype); |
| 151 | + return NULL; |
| 152 | + } |
| 153 | + info.width = read32be(in); |
| 154 | + info.height = read32be(in + 4); |
| 155 | + info.depth = in[8]; |
| 156 | + info.colortype = in[9]; |
| 157 | + info.comprtype = in[10]; |
| 158 | + info.filtertype = in[11]; |
| 159 | + in += length; |
| 160 | + break; |
| 161 | + case PNG_CHUNK_IDAT: |
| 162 | + if (idat == 2) |
| 163 | + { |
| 164 | + DEBUGF("png_open: IDAT chunks are not consecutive"); |
| 165 | + return NULL; |
| 166 | + } |
| 167 | + if (!idat) |
| 168 | + { |
| 169 | + info.idat = in - 8; |
| 170 | + info.idatlen += length + 12; |
| 171 | + idat = 1; |
| 172 | + } |
| 173 | + in += length; |
| 174 | + break; |
| 175 | + case PNG_CHUNK_IEND: |
| 176 | + if (length) |
| 177 | + { |
| 178 | + DEBUGF("png_open: IEND chunk has non-zero size"); |
| 179 | + return NULL; |
| 180 | + } |
| 181 | + iend = true; |
| 182 | + break; |
| 183 | + case PNG_CHUNK_PLTE: |
| 184 | + if (info.colortype != 3) |
| 185 | + { |
| 186 | + DEBUGF("png_open: Color type 0x%02X may not have a palette", info.colortype); |
| 187 | + return NULL; |
| 188 | + } |
| 189 | + if (length % 3) |
| 190 | + { |
| 191 | + DEBUGF("png_open: Palette size is not a multiple of 3"); |
| 192 | + return NULL; |
| 193 | + } |
| 194 | + info.palette = (const struct png_rgb*)in; |
| 195 | + in += length; |
| 196 | + break; |
| 197 | + case PNG_CHUNK_tRNS: |
| 198 | + switch (info.colortype) |
| 199 | + { |
| 200 | + case 2: |
| 201 | + info.key[0] = (in[0] << 8) | in[1]; |
| 202 | + info.key[1] = (in[2] << 8) | in[3]; |
| 203 | + info.key[2] = (in[4] << 8) | in[5]; |
| 204 | + break; |
| 205 | + case 0: |
| 206 | + info.key[0] = (in[0] << 8) | in[1]; |
| 207 | + info.key[1] = (in[0] << 8) | in[1]; |
| 208 | + info.key[2] = (in[0] << 8) | in[1]; |
| 209 | + info.keyvalid = 1; |
| 210 | + break; |
| 211 | + case 3: |
| 212 | + info.palalpha = in; |
| 213 | + info.palalphacnt = length; |
| 214 | + break; |
| 215 | + default: |
| 216 | + DEBUGF("png_open: Color type 0x%02X may not have a tRNS chunk", info.colortype); |
| 217 | + return NULL; |
| 218 | + } |
| 219 | + in += length; |
| 220 | + break; |
| 221 | + case PNG_CHUNK_bKGD: |
| 222 | + switch (info.colortype) |
| 223 | + { |
| 224 | + case 2: |
| 225 | + case 6: |
| 226 | + if (info.depth == 16) |
| 227 | + { |
| 228 | + info.bg.r = in[0]; |
| 229 | + info.bg.g = in[2]; |
| 230 | + info.bg.b = in[4]; |
| 231 | + } |
| 232 | + else |
| 233 | + { |
| 234 | + info.bg.r = in[1] << (8 - info.depth); |
| 235 | + info.bg.g = in[3] << (8 - info.depth); |
| 236 | + info.bg.b = in[5] << (8 - info.depth); |
| 237 | + } |
| 238 | + break; |
| 239 | + case 0: |
| 240 | + case 4: |
| 241 | + if (info.depth == 16) |
| 242 | + { |
| 243 | + info.bg.r = in[0]; |
| 244 | + info.bg.g = in[0]; |
| 245 | + info.bg.b = in[0]; |
| 246 | + } |
| 247 | + else |
| 248 | + { |
| 249 | + info.bg.r = in[1] << (8 - info.depth); |
| 250 | + info.bg.g = in[1] << (8 - info.depth); |
| 251 | + info.bg.b = in[1] << (8 - info.depth); |
| 252 | + } |
| 253 | + break; |
| 254 | + case 3: |
| 255 | + if (!info.palette) |
| 256 | + { |
| 257 | + DEBUGF("png_open: Indexed mode, but no palette before bKGD chunk"); |
| 258 | + return NULL; |
| 259 | + } |
| 260 | + info.bg = info.palette[*in]; |
| 261 | + break; |
| 262 | + default: |
| 263 | + DEBUGF("png_open: Unknown color type 0x%02X", info.colortype); |
| 264 | + return NULL; |
| 265 | + } |
| 266 | + in += length; |
| 267 | + break; |
| 268 | + default: |
| 269 | + if (!(chunk & 0x20000000)) |
| 270 | + { |
| 271 | + DEBUGF("png_open: Unknown critical chunk: %08X", chunk); |
| 272 | + return NULL; |
| 273 | + } |
| 274 | + in += length; |
| 275 | + } |
| 276 | + first = false; |
| 277 | + in += 4; |
| 278 | + size -= length + 12; |
| 279 | + } |
| 280 | + if (!iend) |
| 281 | + { |
| 282 | + DEBUGF("png_open: No IEND chunk"); |
| 283 | + return NULL; |
| 284 | + } |
| 285 | + if (info.colortype == 3 && !info.palette) |
| 286 | + { |
| 287 | + DEBUGF("png_open: Indexed mode, but no palette present"); |
| 288 | + return NULL; |
| 289 | + } |
| 290 | + struct png_info* ret = (struct png_info*)malloc(sizeof(info)); |
| 291 | + if (ret) memcpy(ret, &info, sizeof(info)); |
| 292 | + else DEBUGF("png_open: Could not allocate memory for png_info struct"); |
| 293 | + return ret; |
| 294 | +} |
| 295 | + |
| 296 | +uint32_t png_get_width(struct png_info* info) |
| 297 | +{ |
| 298 | + return info->width; |
| 299 | +} |
| 300 | + |
| 301 | +uint32_t png_get_height(struct png_info* info) |
| 302 | +{ |
| 303 | + return info->height; |
| 304 | +} |
| 305 | + |
| 306 | +void png_set_background(struct png_info* info, uint32_t color) |
| 307 | +{ |
| 308 | + info->bg.r = (color >> 0) & 0xff; |
| 309 | + info->bg.g = (color >> 8) & 0xff; |
| 310 | + info->bg.b = (color >> 16) & 0xff; |
| 311 | +} |
| 312 | + |
| 313 | +uint8_t* png_decode(struct png_info* info, bool alpha) |
| 314 | +{ |
| 315 | + int i, rc; |
| 316 | + int filterchannels = info->channels * ((info->depth + 7) / 8); |
| 317 | + int scanlinesize = (info->width * info->channels * info->depth + 7) / 8; |
| 318 | + int insize = info->height * (1 + scanlinesize); |
| 319 | + int unfilteredsize = info->height * scanlinesize; |
| 320 | + int outsize = info->height * info->width * (alpha ? 4 : 3); |
| 321 | + int bufsize = MAX(insize, outsize); |
| 322 | + DEBUGF("png_decode: Input data size: 0x%X", insize); |
| 323 | + DEBUGF("png_decode: Unfiltered data size: 0x%X", unfilteredsize); |
| 324 | + DEBUGF("png_decode: Output data size: 0x%X", outsize); |
| 325 | + DEBUGF("png_decode: Allocating 0x%X bytes of memory for decoding", bufsize); |
| 326 | + uint8_t* buf = (uint8_t*)malloc(bufsize); |
| 327 | + if (!buf) |
| 328 | + { |
| 329 | + DEBUGF("png_decode: Could not allocate memory for decompression"); |
| 330 | + return NULL; |
| 331 | + } |
| 332 | + uint8_t* in = buf + bufsize - insize; |
| 333 | + uint8_t* out = buf; |
| 334 | + DEBUGF("png_decode: Allocated decoding buffer at 0x%08X", buf); |
| 335 | + DEBUGF("png_decode: Decompressing input data to 0x%08X", in); |
| 336 | + if (rc = tinf_zlib_uncompress(in, &insize, info->idat, info->idatlen)) |
| 337 | + { |
| 338 | + DEBUGF("png_decode: Decompression failed: %d", rc); |
| 339 | + return NULL; |
| 340 | + } |
| 341 | + DEBUGF("png_decode: Unfiltering input data to 0x%08X", out); |
| 342 | + int row; |
| 343 | + for (row = 0; row < info->height; row++) |
| 344 | + { |
| 345 | + uint8_t filtertype = *in++; |
| 346 | + for (i = 0; i < scanlinesize; i++) |
| 347 | + { |
| 348 | + int predict; |
| 349 | + switch (filtertype) |
| 350 | + { |
| 351 | + case 1: |
| 352 | + if (i >= filterchannels) predict = *(out - filterchannels); |
| 353 | + else predict = 0; |
| 354 | + break; |
| 355 | + case 2: |
| 356 | + if (row) predict = *(out - scanlinesize); |
| 357 | + else predict = 0; |
| 358 | + break; |
| 359 | + case 3: |
| 360 | + predict = 0; |
| 361 | + if (i >= filterchannels) predict += *(out - filterchannels); |
| 362 | + if (row) predict += *(out - scanlinesize); |
| 363 | + predict >>= 1; |
| 364 | + break; |
| 365 | + case 4: |
| 366 | + { |
| 367 | + int a, b, c, p, pa, pb, pc; |
| 368 | + if (i >= filterchannels) a = *(out - filterchannels); |
| 369 | + else a = 0; |
| 370 | + if (row > 0) b = *(out - scanlinesize); |
| 371 | + else b = 0; |
| 372 | + if (row > 0 && i >= filterchannels) c = *(out - scanlinesize - filterchannels); |
| 373 | + else c = 0; |
| 374 | + p = a + b - c; |
| 375 | + pa = ABS(p - a); |
| 376 | + pb = ABS(p - b); |
| 377 | + pc = ABS(p - c); |
| 378 | + if (pa <= pb && pa <= pc) predict = a; |
| 379 | + else if (pb <= pc) predict = b; |
| 380 | + else predict = c; |
| 381 | + break; |
| 382 | + } |
| 383 | + default: |
| 384 | + predict = 0; |
| 385 | + } |
| 386 | + *out++ = predict + *in++; |
| 387 | + } |
| 388 | + } |
| 389 | + if (!(alpha && info->colortype == 6 && info->depth == 8) |
| 390 | + && !(!alpha && info->colortype == 2 && info->depth == 8 && !info->keyvalid)) |
| 391 | + { |
| 392 | + uint8_t* in = buf + bufsize - unfilteredsize; |
| 393 | + uint8_t* out = buf; |
| 394 | + DEBUGF("png_decode: Moving unfiltered data from 0x%08X to 0x%08X", out, in); |
| 395 | + memmove(in, out, unfilteredsize); |
| 396 | + DEBUGF("png_decode: Converting unfiltered data to 0x%08X", out); |
| 397 | + for (row = 0; row < info->height; row++) |
| 398 | + { |
| 399 | + int col = 0; |
| 400 | + while (col < info->width) |
| 401 | + { |
| 402 | + int i, a, d; |
| 403 | + if (info->depth < 8) |
| 404 | + { |
| 405 | + uint8_t byte = *buf++; |
| 406 | + for (i = 0; i < 8 && col < info->width; i += info->depth) |
| 407 | + { |
| 408 | + if (info->colortype == 3) |
| 409 | + { |
| 410 | + int index = byte >> (8 - info->depth); |
| 411 | + struct png_rgb color = info->palette[index]; |
| 412 | + if (index < info->palalphacnt) a = info->palalpha[index]; |
| 413 | + else a = 255; |
| 414 | + if (!alpha && a != 255) |
| 415 | + { |
| 416 | + *out++ = (color.r * a + info->bg.r * (255 - a)) >> 8; |
| 417 | + *out++ = (color.g * a + info->bg.g * (255 - a)) >> 8; |
| 418 | + *out++ = (color.b * a + info->bg.b * (255 - a)) >> 8; |
| 419 | + } |
| 420 | + else |
| 421 | + { |
| 422 | + *out++ = color.r; |
| 423 | + *out++ = color.g; |
| 424 | + *out++ = color.b; |
| 425 | + if (alpha) *out++ = a; |
| 426 | + } |
| 427 | + } |
| 428 | + else |
| 429 | + { |
| 430 | + int color = byte >> (8 - info->depth); |
| 431 | + for (d = info->depth; d < 8; d <<= 1) |
| 432 | + color |= color << d; |
| 433 | + if (info->keyvalid && color == info->key[0]) a = 0; |
| 434 | + else a = 255; |
| 435 | + if (!alpha && !a) |
| 436 | + { |
| 437 | + *out++ = info->bg.r; |
| 438 | + *out++ = info->bg.r; |
| 439 | + *out++ = info->bg.r; |
| 440 | + } |
| 441 | + else |
| 442 | + { |
| 443 | + *out++ = color; |
| 444 | + *out++ = color; |
| 445 | + *out++ = color; |
| 446 | + if (alpha) *out++ = a; |
| 447 | + } |
| 448 | + } |
| 449 | + byte <<= info->depth; |
| 450 | + col++; |
| 451 | + } |
| 452 | + } |
| 453 | + else |
| 454 | + { |
| 455 | + if (info->colortype == 3) |
| 456 | + { |
| 457 | + int index = *in++; |
| 458 | + struct png_rgb color = info->palette[index]; |
| 459 | + if (index < info->palalphacnt) a = info->palalpha[index]; |
| 460 | + else a = 255; |
| 461 | + if (!alpha && a != 255) |
| 462 | + { |
| 463 | + *out++ = (color.r * a + info->bg.r * (255 - a)) >> 8; |
| 464 | + *out++ = (color.g * a + info->bg.g * (255 - a)) >> 8; |
| 465 | + *out++ = (color.b * a + info->bg.b * (255 - a)) >> 8; |
| 466 | + } |
| 467 | + else |
| 468 | + { |
| 469 | + *out++ = color.r; |
| 470 | + *out++ = color.g; |
| 471 | + *out++ = color.b; |
| 472 | + if (alpha) *out++ = a; |
| 473 | + } |
| 474 | + } |
| 475 | + else |
| 476 | + { |
| 477 | + int chan[4]; |
| 478 | + for (i = 0; i < info->channels; i++) |
| 479 | + { |
| 480 | + chan[i] = *in++; |
| 481 | + if (info->depth == 16) chan[i] = (chan[i] << 8) | *in++; |
| 482 | + } |
| 483 | + if (!(info->colortype & 2)) |
| 484 | + { |
| 485 | + chan[3] = chan[1]; |
| 486 | + chan[2] = chan[0]; |
| 487 | + chan[1] = chan[0]; |
| 488 | + } |
| 489 | + if (!(info->colortype & 4)) |
| 490 | + { |
| 491 | + if (info->keyvalid && chan[0] == info->key[0] |
| 492 | + && chan[1] == info->key[1] && chan[2] == info->key[2]) a = 0; |
| 493 | + else a = 255; |
| 494 | + } |
| 495 | + else if (info->depth == 16) a = chan[3] >> 8; |
| 496 | + else a = chan[3]; |
| 497 | + if (info->depth == 16) |
| 498 | + { |
| 499 | + chan[0] >>= 8; |
| 500 | + chan[1] >>= 8; |
| 501 | + chan[2] >>= 8; |
| 502 | + } |
| 503 | + if (!alpha && a != 255) |
| 504 | + { |
| 505 | + *out++ = (chan[0] * a + info->bg.r * (255 - a)) >> 8; |
| 506 | + *out++ = (chan[1] * a + info->bg.g * (255 - a)) >> 8; |
| 507 | + *out++ = (chan[2] * a + info->bg.b * (255 - a)) >> 8; |
| 508 | + } |
| 509 | + else |
| 510 | + { |
| 511 | + *out++ = chan[0]; |
| 512 | + *out++ = chan[1]; |
| 513 | + *out++ = chan[2]; |
| 514 | + if (alpha) *out++ = a; |
| 515 | + } |
| 516 | + } |
| 517 | + col++; |
| 518 | + } |
| 519 | + } |
| 520 | + } |
| 521 | + } |
| 522 | + if (outsize != bufsize) |
| 523 | + { |
| 524 | + DEBUGF("png_decode: Shrinking buffer to 0x%X bytes", outsize); |
| 525 | + out = (uint8_t*)realloc(buf, outsize); |
| 526 | + if (!out) |
| 527 | + { |
| 528 | + free(buf); |
| 529 | + DEBUGF("png_decode: Failed to trim output buffer"); |
| 530 | + } |
| 531 | + DEBUGF("png_decode: Buffer is now at 0x%08X", out); |
| 532 | + return out; |
| 533 | + } |
| 534 | + return buf; |
| 535 | +} |
| 536 | + |
| 537 | +struct png_rgba* png_decode_rgba(struct png_info* info) |
| 538 | +{ |
| 539 | + return (struct png_rgba*)png_decode(info, true); |
| 540 | +} |
| 541 | + |
| 542 | +struct png_rgb* png_decode_rgb(struct png_info* info) |
| 543 | +{ |
| 544 | + return (struct png_rgb*)png_decode(info, false); |
| 545 | +} |
| 546 | + |
| 547 | +void png_destroy(struct png_info* info) |
| 548 | +{ |
| 549 | + free(info); |
| 550 | +} |
Index: libs/png/tinf.h |
— | — | @@ -0,0 +1,75 @@ |
| 2 | +/*************************************************************************** |
| 3 | + * __________ __ ___. |
| 4 | + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 5 | + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 6 | + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 7 | + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 8 | + * \/ \/ \/ \/ \/ |
| 9 | + * $Id$ |
| 10 | + * |
| 11 | + * Original source: |
| 12 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 13 | + * |
| 14 | + * Rockbox adaptation: |
| 15 | + * Copyright (c) 2010 by Marcin Bukat |
| 16 | + * |
| 17 | + * emCORE adaptation: |
| 18 | + * Copyright (c) 2011 by Michael Sparmann |
| 19 | + * |
| 20 | + * This program is free software; you can redistribute it and/or |
| 21 | + * modify it under the terms of the GNU General Public License |
| 22 | + * as published by the Free Software Foundation; either version 2 |
| 23 | + * of the License, or (at your option) any later version. |
| 24 | + * |
| 25 | + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 26 | + * KIND, either express or implied. |
| 27 | + * |
| 28 | + ****************************************************************************/ |
| 29 | + |
| 30 | +/* |
| 31 | + * tinf - tiny inflate library (inflate, gzip, zlib) |
| 32 | + * |
| 33 | + * version 1.00 |
| 34 | + * |
| 35 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 36 | + * All Rights Reserved |
| 37 | + * |
| 38 | + * http://www.ibsensoftware.com/ |
| 39 | + */ |
| 40 | + |
| 41 | +/* removed from original file: |
| 42 | + * tinf_gzip_uncompress() prototype |
| 43 | + * tinf_init() prototype |
| 44 | + */ |
| 45 | + |
| 46 | +#ifndef TINF_H_INCLUDED |
| 47 | +#define TINF_H_INCLUDED |
| 48 | + |
| 49 | +#include "emcorelib.h" |
| 50 | + |
| 51 | +/* calling convention */ |
| 52 | +#ifndef TINFCC |
| 53 | + #ifdef __WATCOMC__ |
| 54 | + #define TINFCC __cdecl |
| 55 | + #else |
| 56 | + #define TINFCC |
| 57 | + #endif |
| 58 | +#endif |
| 59 | + |
| 60 | +#ifdef __cplusplus |
| 61 | +extern "C" { |
| 62 | +#endif |
| 63 | + |
| 64 | +/* function prototypes */ |
| 65 | + |
| 66 | +int TINFCC tinf_uncompress(void *dest, unsigned int *destLen, |
| 67 | + const void *source, unsigned int sourceLen); |
| 68 | + |
| 69 | +int TINFCC tinf_zlib_uncompress(void *dest, unsigned int *destLen, |
| 70 | + const void *source, unsigned int sourceLen); |
| 71 | + |
| 72 | +#ifdef __cplusplus |
| 73 | +} /* extern "C" */ |
| 74 | +#endif |
| 75 | + |
| 76 | +#endif /* TINF_H_INCLUDED */ |
Index: libs/png/tinflate.c |
— | — | @@ -0,0 +1,531 @@ |
| 2 | +/*************************************************************************** |
| 3 | + * __________ __ ___. |
| 4 | + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 5 | + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 6 | + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 7 | + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 8 | + * \/ \/ \/ \/ \/ |
| 9 | + * $Id$ |
| 10 | + * |
| 11 | + * Original source: |
| 12 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 13 | + * |
| 14 | + * Rockbox adaptation: |
| 15 | + * Copyright (c) 2010 by Marcin Bukat |
| 16 | + * |
| 17 | + * emCORE adaptation: |
| 18 | + * Copyright (c) 2011 by Michael Sparmann |
| 19 | + * |
| 20 | + * This program is free software; you can redistribute it and/or |
| 21 | + * modify it under the terms of the GNU General Public License |
| 22 | + * as published by the Free Software Foundation; either version 2 |
| 23 | + * of the License, or (at your option) any later version. |
| 24 | + * |
| 25 | + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 26 | + * KIND, either express or implied. |
| 27 | + * |
| 28 | + ****************************************************************************/ |
| 29 | + |
| 30 | +/* |
| 31 | + * tinflate - tiny inflate |
| 32 | + * |
| 33 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 34 | + * All Rights Reserved |
| 35 | + * |
| 36 | + * http://www.ibsensoftware.com/ |
| 37 | + * |
| 38 | + * This software is provided 'as-is', without any express |
| 39 | + * or implied warranty. In no event will the authors be |
| 40 | + * held liable for any damages arising from the use of |
| 41 | + * this software. |
| 42 | + * |
| 43 | + * Permission is granted to anyone to use this software |
| 44 | + * for any purpose, including commercial applications, |
| 45 | + * and to alter it and redistribute it freely, subject to |
| 46 | + * the following restrictions: |
| 47 | + * |
| 48 | + * 1. The origin of this software must not be |
| 49 | + * misrepresented; you must not claim that you |
| 50 | + * wrote the original software. If you use this |
| 51 | + * software in a product, an acknowledgment in |
| 52 | + * the product documentation would be appreciated |
| 53 | + * but is not required. |
| 54 | + * |
| 55 | + * 2. Altered source versions must be plainly marked |
| 56 | + * as such, and must not be misrepresented as |
| 57 | + * being the original software. |
| 58 | + * |
| 59 | + * 3. This notice may not be removed or altered from |
| 60 | + * any source distribution. |
| 61 | + */ |
| 62 | + |
| 63 | + |
| 64 | +//#define DEBUG_CONSOLES 2
|
| 65 | +//#define DEBUG_PRINT_SOURCE_LINE
|
| 66 | +
|
| 67 | + |
| 68 | +#include "emcorelib.h" |
| 69 | +#include "tinf.h" |
| 70 | + |
| 71 | +/* ------------------------------ * |
| 72 | + * -- internal data structures -- * |
| 73 | + * ------------------------------ */ |
| 74 | + |
| 75 | +typedef struct { |
| 76 | + unsigned short table[16]; /* table of code length counts */ |
| 77 | + unsigned short trans[288]; /* code -> symbol translation table */ |
| 78 | +} TINF_TREE; |
| 79 | + |
| 80 | +typedef struct { |
| 81 | + unsigned short table[16]; |
| 82 | + unsigned short trans[32]; |
| 83 | +} TINF_SDTREE; |
| 84 | + |
| 85 | +typedef struct { |
| 86 | + TINF_TREE sltree; |
| 87 | + TINF_TREE sdtree; |
| 88 | + unsigned char length_bits[30]; |
| 89 | + unsigned short length_base[30]; |
| 90 | + unsigned char dist_bits[30]; |
| 91 | + unsigned short dist_base[30]; |
| 92 | + unsigned char clcidx[19]; |
| 93 | +} TINF_TABLES; |
| 94 | + |
| 95 | +typedef struct { |
| 96 | + const unsigned char *source; |
| 97 | + unsigned int tag; |
| 98 | + unsigned int bitcount; |
| 99 | + unsigned int bytecount; |
| 100 | + |
| 101 | + unsigned char *dest; |
| 102 | + unsigned int *destLen; |
| 103 | + |
| 104 | + TINF_TREE ltree; /* dynamic length/symbol tree */ |
| 105 | + TINF_TREE dtree; /* dynamic distance tree */ |
| 106 | +} TINF_DATA; |
| 107 | + |
| 108 | +/* static tables */ |
| 109 | +TINF_TABLES tbl = { |
| 110 | + .sltree = { |
| 111 | + .table = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0018, |
| 112 | + 0x0098, 0x0070, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, |
| 113 | + |
| 114 | + .trans = {0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, |
| 115 | + 0x0108, 0x0109, 0x010a, 0x010b, 0x010c, 0x010d, 0x010e, 0x010f, |
| 116 | + 0x0110, 0x0111, 0x0112, 0x0113, 0x0114, 0x0115, 0x0116, 0x0117, |
| 117 | + 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, |
| 118 | + 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 119 | + 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, |
| 120 | + 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 121 | + 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, |
| 122 | + 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 123 | + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, |
| 124 | + 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 125 | + 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, |
| 126 | + 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 127 | + 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, |
| 128 | + 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 129 | + 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, |
| 130 | + 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 131 | + 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, |
| 132 | + 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 133 | + 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, |
| 134 | + 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, |
| 135 | + 0x0118, 0x0119, 0x011a, 0x011b, 0x011c, 0x011d, 0x011e, 0x011f, |
| 136 | + 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, |
| 137 | + 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, |
| 138 | + 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, |
| 139 | + 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, |
| 140 | + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, |
| 141 | + 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, |
| 142 | + 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, |
| 143 | + 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, |
| 144 | + 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, |
| 145 | + 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, |
| 146 | + 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, |
| 147 | + 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, |
| 148 | + 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, |
| 149 | + 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}, |
| 150 | + }, |
| 151 | + |
| 152 | + .sdtree = { |
| 153 | + .table = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0000, 0x0000, |
| 154 | + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, |
| 155 | + |
| 156 | + .trans = {0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, |
| 157 | + 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 158 | + 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, |
| 159 | + 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f}, |
| 160 | + }, |
| 161 | + |
| 162 | + .length_bits = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 163 | + 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, |
| 164 | + 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, |
| 165 | + 0x05, 0x05, 0x05, 0x05, 0x00, 0x06}, |
| 166 | + |
| 167 | + .length_base = {0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, |
| 168 | + 0x000b, 0x000d, 0x000f, 0x0011, 0x0013, 0x0017, 0x001b, 0x001f, |
| 169 | + 0x0023, 0x002b, 0x0033, 0x003b, 0x0043, 0x0053, 0x0063, 0x0073, |
| 170 | + 0x0083, 0x00a3, 0x00c3, 0x00e3, 0x0102, 0x0143}, |
| 171 | + |
| 172 | + .dist_bits = {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, |
| 173 | + 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, |
| 174 | + 0x07, 0x07, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, |
| 175 | + 0x0b, 0x0b, 0x0c, 0x0c, 0x0d, 0x0d}, |
| 176 | + |
| 177 | + .dist_base = {0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d, |
| 178 | + 0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1, |
| 179 | + 0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01, |
| 180 | + 0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001}, |
| 181 | + |
| 182 | + .clcidx = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}, |
| 183 | +}; |
| 184 | + |
| 185 | + |
| 186 | +/* ----------------------- * |
| 187 | + * -- utility functions -- * |
| 188 | + * ----------------------- */ |
| 189 | + |
| 190 | +/* given an array of code lengths, build a tree */ |
| 191 | +static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned int num) |
| 192 | +{ |
| 193 | + unsigned short offs[16]; |
| 194 | + unsigned int i, sum; |
| 195 | + |
| 196 | + /* clear code length count table */ |
| 197 | + /* for (i = 0; i < 16; ++i) t->table[i] = 0; */ |
| 198 | + memset(t->table, 0, sizeof(short)*16); |
| 199 | + |
| 200 | + /* scan symbol lengths, and sum code length counts */ |
| 201 | + for (i = 0; i < num; ++i) t->table[lengths[i]]++; |
| 202 | + |
| 203 | + t->table[0] = 0; |
| 204 | + |
| 205 | + /* compute offset table for distribution sort */ |
| 206 | + for (sum = 0, i = 0; i < 16; ++i) |
| 207 | + { |
| 208 | + offs[i] = sum; |
| 209 | + sum += t->table[i]; |
| 210 | + } |
| 211 | + |
| 212 | + /* create code->symbol translation table (symbols sorted by code) */ |
| 213 | + for (i = 0; i < num; ++i) |
| 214 | + { |
| 215 | + if (lengths[i]) t->trans[offs[lengths[i]]++] = i; |
| 216 | + } |
| 217 | +} |
| 218 | + |
| 219 | +/* ---------------------- * |
| 220 | + * -- decode functions -- * |
| 221 | + * ---------------------- */ |
| 222 | + |
| 223 | +/* get one bit from source stream */ |
| 224 | +static int tinf_getbit(TINF_DATA *d) |
| 225 | +{ |
| 226 | + unsigned int bit; |
| 227 | +// DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X", |
| 228 | +// d->bytecount, d->bitcount, d->source); |
| 229 | + |
| 230 | + /* check if tag is empty */ |
| 231 | + if (!--d->bitcount) |
| 232 | + { |
| 233 | + while (!--d->bytecount) |
| 234 | + { |
| 235 | + DEBUGF("tinf_getbit: refilling bytes"); |
| 236 | + DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X", |
| 237 | + d->bytecount, d->bitcount, d->source); |
| 238 | + d->bytecount = (d->source[4] << 24) | (d->source[5] << 16) |
| 239 | + | (d->source[6] << 8) | d->source[7]; |
| 240 | + d->source += 12; |
| 241 | + DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X", |
| 242 | + d->bytecount, d->bitcount, d->source); |
| 243 | + } |
| 244 | + /* load next tag */ |
| 245 | + d->tag = *d->source++; |
| 246 | + d->bitcount = 8; |
| 247 | + } |
| 248 | + |
| 249 | + /* shift bit out of tag */ |
| 250 | + bit = d->tag & 1; |
| 251 | + d->tag >>= 1; |
| 252 | + |
| 253 | +// DEBUGF("tinf_getbit: returning bit %d", bit); |
| 254 | + return bit; |
| 255 | +} |
| 256 | + |
| 257 | +/* read a num bit value from a stream and add base */ |
| 258 | +static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) |
| 259 | +{ |
| 260 | + unsigned int val = 0; |
| 261 | + |
| 262 | + /* read num bits */ |
| 263 | + if (num) |
| 264 | + { |
| 265 | + unsigned int limit = 1 << (num); |
| 266 | + unsigned int mask; |
| 267 | + |
| 268 | + for (mask = 1; mask < limit; mask <<= 1) |
| 269 | + if (tinf_getbit(d)) val |= mask; |
| 270 | + } |
| 271 | + |
| 272 | + return val + base; |
| 273 | +} |
| 274 | + |
| 275 | +/* given a data stream and a tree, decode a symbol */ |
| 276 | +static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) |
| 277 | +{ |
| 278 | + int sum = 0, cur = 0, len = 0; |
| 279 | + |
| 280 | + /* get more bits while code value is above sum */ |
| 281 | + do { |
| 282 | + |
| 283 | + cur = (cur << 1) + tinf_getbit(d); |
| 284 | + |
| 285 | + ++len; |
| 286 | + |
| 287 | + sum += t->table[len]; |
| 288 | + cur -= t->table[len]; |
| 289 | + |
| 290 | + } while (cur >= 0); |
| 291 | + |
| 292 | + return t->trans[sum + cur]; |
| 293 | +} |
| 294 | + |
| 295 | +/* given a data stream, decode dynamic trees from it */ |
| 296 | +static void tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt, TINF_TABLES *tbl) |
| 297 | +{ |
| 298 | + TINF_TREE code_tree; |
| 299 | + unsigned char lengths[288+32]; |
| 300 | + unsigned int hlit, hdist, hclen; |
| 301 | + unsigned int i, num, length; |
| 302 | + |
| 303 | + /* get 5 bits HLIT (257-286) */ |
| 304 | + hlit = tinf_read_bits(d, 5, 257); |
| 305 | + |
| 306 | + /* get 5 bits HDIST (1-32) */ |
| 307 | + hdist = tinf_read_bits(d, 5, 1); |
| 308 | + |
| 309 | + /* get 4 bits HCLEN (4-19) */ |
| 310 | + hclen = tinf_read_bits(d, 4, 4); |
| 311 | + |
| 312 | + /* for (i = 0; i < 19; ++i) lengths[i] = 0; */ |
| 313 | + memset(lengths, 0, sizeof(unsigned char)*19); |
| 314 | + |
| 315 | + /* read code lengths for code length alphabet */ |
| 316 | + for (i = 0; i < hclen; ++i) |
| 317 | + { |
| 318 | + /* get 3 bits code length (0-7) */ |
| 319 | + unsigned int clen = tinf_read_bits(d, 3, 0); |
| 320 | + |
| 321 | + lengths[tbl->clcidx[i]] = clen; |
| 322 | + } |
| 323 | + |
| 324 | + /* build code length tree */ |
| 325 | + tinf_build_tree(&code_tree, lengths, 19); |
| 326 | + |
| 327 | + /* decode code lengths for the dynamic trees */ |
| 328 | + for (num = 0; num < hlit + hdist; ) |
| 329 | + { |
| 330 | + int sym = tinf_decode_symbol(d, &code_tree); |
| 331 | + |
| 332 | + switch (sym) |
| 333 | + { |
| 334 | + case 16: |
| 335 | + /* copy previous code length 3-6 times (read 2 bits) */ |
| 336 | + { |
| 337 | + unsigned char prev = lengths[num - 1]; |
| 338 | + for (length = tinf_read_bits(d, 2, 3); length; --length) |
| 339 | + { |
| 340 | + lengths[num++] = prev; |
| 341 | + } |
| 342 | + } |
| 343 | + break; |
| 344 | + case 17: |
| 345 | + /* repeat code length 0 for 3-10 times (read 3 bits) */ |
| 346 | + for (length = tinf_read_bits(d, 3, 3); length; --length) |
| 347 | + { |
| 348 | + lengths[num++] = 0; |
| 349 | + } |
| 350 | + break; |
| 351 | + case 18: |
| 352 | + /* repeat code length 0 for 11-138 times (read 7 bits) */ |
| 353 | + for (length = tinf_read_bits(d, 7, 11); length; --length) |
| 354 | + { |
| 355 | + lengths[num++] = 0; |
| 356 | + } |
| 357 | + break; |
| 358 | + default: |
| 359 | + /* values 0-15 represent the actual code lengths */ |
| 360 | + lengths[num++] = sym; |
| 361 | + break; |
| 362 | + } |
| 363 | + } |
| 364 | + |
| 365 | + /* build dynamic trees */ |
| 366 | + tinf_build_tree(lt, lengths, hlit); |
| 367 | + tinf_build_tree(dt, lengths + hlit, hdist); |
| 368 | +} |
| 369 | + |
| 370 | +/* ----------------------------- * |
| 371 | + * -- block inflate functions -- * |
| 372 | + * ----------------------------- */ |
| 373 | + |
| 374 | +/* given a stream and two trees, inflate a block of data */ |
| 375 | +static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt, TINF_TABLES *tbl) |
| 376 | +{ |
| 377 | + /* remember current output position */ |
| 378 | + unsigned char *start = d->dest; |
| 379 | + |
| 380 | + while (1) |
| 381 | + { |
| 382 | + int sym = tinf_decode_symbol(d, lt); |
| 383 | + |
| 384 | + /* check for end of block */ |
| 385 | + if (sym == 256) |
| 386 | + { |
| 387 | + *d->destLen += d->dest - start; |
| 388 | + return 0; |
| 389 | + } |
| 390 | + |
| 391 | + if (sym < 256) |
| 392 | + { |
| 393 | + *d->dest++ = sym; |
| 394 | + |
| 395 | + } else { |
| 396 | + |
| 397 | + int length, dist, offs; |
| 398 | + int i; |
| 399 | + |
| 400 | + sym -= 257; |
| 401 | + |
| 402 | + /* possibly get more bits from length code */ |
| 403 | + length = tinf_read_bits(d, tbl->length_bits[sym], tbl->length_base[sym]); |
| 404 | + |
| 405 | + dist = tinf_decode_symbol(d, dt); |
| 406 | + |
| 407 | + /* possibly get more bits from distance code */ |
| 408 | + offs = tinf_read_bits(d, tbl->dist_bits[dist], tbl->dist_base[dist]); |
| 409 | + |
| 410 | + /* copy match */ |
| 411 | + for (i = 0; i < length; ++i) |
| 412 | + { |
| 413 | + d->dest[i] = d->dest[i - offs]; |
| 414 | + } |
| 415 | + |
| 416 | + d->dest += length; |
| 417 | + } |
| 418 | + } |
| 419 | +} |
| 420 | + |
| 421 | +/* inflate an uncompressed block of data */ |
| 422 | +static int tinf_inflate_uncompressed_block(TINF_DATA *d) |
| 423 | +{ |
| 424 | + unsigned int length, invlength; |
| 425 | + /* unsigned int i; */ |
| 426 | + |
| 427 | + /* get length */ |
| 428 | + length = d->source[1]; |
| 429 | + length = (length << 8) + d->source[0]; |
| 430 | + |
| 431 | + /* get one's complement of length */ |
| 432 | + invlength = d->source[3]; |
| 433 | + invlength = (invlength << 8) + d->source[2]; |
| 434 | + |
| 435 | + /* check length */ |
| 436 | + if (length != (~invlength & 0x0000ffff)) return -5; |
| 437 | + |
| 438 | + d->source += 4; |
| 439 | + |
| 440 | + /* copy block */ |
| 441 | + /* for (i = length; i; --i) *d->dest++ = *d->source++; */ |
| 442 | + memcpy(d->dest, d->source, sizeof(unsigned char)*length); |
| 443 | + d->dest += sizeof(unsigned char)*length; |
| 444 | + d->source += sizeof(unsigned char)*length; |
| 445 | + |
| 446 | + /* make sure we start next block on a byte boundary */ |
| 447 | + d->bitcount = 0; |
| 448 | + |
| 449 | + *d->destLen += length; |
| 450 | + |
| 451 | + return 0; |
| 452 | +} |
| 453 | + |
| 454 | +/* inflate a block of data compressed with fixed huffman trees */ |
| 455 | +static int tinf_inflate_fixed_block(TINF_DATA *d, TINF_TABLES *tbl) |
| 456 | +{ |
| 457 | + /* decode block using fixed trees */ |
| 458 | + return tinf_inflate_block_data(d, &tbl->sltree, &tbl->sdtree, tbl); |
| 459 | +} |
| 460 | + |
| 461 | +/* inflate a block of data compressed with dynamic huffman trees */ |
| 462 | +static int tinf_inflate_dynamic_block(TINF_DATA *d, TINF_TABLES *tbl) |
| 463 | +{ |
| 464 | + /* decode trees from stream */ |
| 465 | + tinf_decode_trees(d, &d->ltree, &d->dtree, tbl); |
| 466 | + |
| 467 | + /* decode block using decoded trees */ |
| 468 | + return tinf_inflate_block_data(d, &d->ltree, &d->dtree, tbl); |
| 469 | +} |
| 470 | + |
| 471 | +/* ---------------------- * |
| 472 | + * -- public functions -- * |
| 473 | + * ---------------------- */ |
| 474 | + |
| 475 | +/* inflate stream from source to dest */ |
| 476 | +int tinf_uncompress(void *dest, unsigned int *destLen, |
| 477 | + const void *source, unsigned int sourceLen) |
| 478 | +{ |
| 479 | + TINF_DATA d; |
| 480 | + int bfinal; |
| 481 | + |
| 482 | + d.source = (const unsigned char *)(source + 10); |
| 483 | + d.bitcount = 1; |
| 484 | + d.bytecount = ((d.source[-10] << 24) | (d.source[-9] << 16) |
| 485 | + | (d.source[-8] << 8) | d.source[-7]) + 1; |
| 486 | + |
| 487 | + d.dest = (unsigned char *)dest; |
| 488 | + d.destLen = destLen; |
| 489 | + |
| 490 | + *destLen = 0; |
| 491 | + |
| 492 | + DEBUGF("start: bytecount=%d, bitcount=%d, source=0x%08X", |
| 493 | + d.bytecount, d.bitcount, d.source); |
| 494 | + |
| 495 | + do { |
| 496 | + |
| 497 | + unsigned int btype; |
| 498 | + int res; |
| 499 | + |
| 500 | + /* read final block flag */ |
| 501 | + bfinal = tinf_getbit(&d); |
| 502 | + |
| 503 | + /* read block type (2 bits) */ |
| 504 | + btype = tinf_read_bits(&d, 2, 0); |
| 505 | + |
| 506 | + /* decompress block */ |
| 507 | + switch (btype) |
| 508 | + { |
| 509 | + case 0: |
| 510 | + /* decompress uncompressed block */ |
| 511 | + res = tinf_inflate_uncompressed_block(&d); |
| 512 | + break; |
| 513 | + case 1: |
| 514 | + /* decompress block with fixed huffman trees */ |
| 515 | + res = tinf_inflate_fixed_block(&d,&tbl); |
| 516 | + break; |
| 517 | + case 2: |
| 518 | + /* decompress block with dynamic huffman trees */ |
| 519 | + res = tinf_inflate_dynamic_block(&d,&tbl); |
| 520 | + break; |
| 521 | + default: |
| 522 | + return -6; |
| 523 | + } |
| 524 | + |
| 525 | + if (res) return res; |
| 526 | + |
| 527 | + if (d.source > (unsigned char *)source + sourceLen) |
| 528 | + return -7; |
| 529 | + } while (!bfinal); |
| 530 | + |
| 531 | + return 0; |
| 532 | +} |
Index: libs/png/png.h |
— | — | @@ -0,0 +1,75 @@ |
| 2 | +// |
| 3 | +// |
| 4 | +// Copyright 2011 TheSeven |
| 5 | +// |
| 6 | +// |
| 7 | +// This file is part of emCORE. |
| 8 | +// |
| 9 | +// emCORE is free software: you can redistribute it and/or |
| 10 | +// modify it under the terms of the GNU General Public License as |
| 11 | +// published by the Free Software Foundation, either version 2 of the |
| 12 | +// License, or (at your option) any later version. |
| 13 | +// |
| 14 | +// emCORE is distributed in the hope that it will be useful, |
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 17 | +// See the GNU General Public License for more details. |
| 18 | +// |
| 19 | +// You should have received a copy of the GNU General Public License along |
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +// |
| 22 | +// |
| 23 | + |
| 24 | + |
| 25 | +#ifndef __PNG_H__ |
| 26 | +#define __PNG_H__ |
| 27 | + |
| 28 | + |
| 29 | +#include "emcorelib.h" |
| 30 | + |
| 31 | + |
| 32 | +struct png_rgb |
| 33 | +{ |
| 34 | + uint8_t r; |
| 35 | + uint8_t g; |
| 36 | + uint8_t b; |
| 37 | +} __attribute__((packed)); |
| 38 | + |
| 39 | +struct png_rgba |
| 40 | +{ |
| 41 | + uint8_t r; |
| 42 | + uint8_t g; |
| 43 | + uint8_t b; |
| 44 | + uint8_t a; |
| 45 | +} __attribute__((packed)); |
| 46 | + |
| 47 | +struct png_info |
| 48 | +{ |
| 49 | + uint32_t width; |
| 50 | + uint32_t height; |
| 51 | + uint8_t depth; |
| 52 | + uint8_t colortype; |
| 53 | + uint8_t comprtype; |
| 54 | + uint8_t filtertype; |
| 55 | + const struct png_rgb* palette; |
| 56 | + const uint8_t* palalpha; |
| 57 | + uint32_t palalphacnt; |
| 58 | + const void* idat; |
| 59 | + size_t idatlen; |
| 60 | + uint16_t key[3]; |
| 61 | + struct png_rgb bg; |
| 62 | + uint8_t keyvalid; |
| 63 | + uint8_t channels; |
| 64 | +} __attribute__((packed)); |
| 65 | + |
| 66 | + |
| 67 | +struct png_info* png_open(const void* data, size_t size); |
| 68 | +uint32_t png_get_width(struct png_info* info); |
| 69 | +uint32_t png_get_height(struct png_info* info); |
| 70 | +void png_set_background(struct png_info* info, uint32_t color); |
| 71 | +struct png_rgba* png_decode_rgba(struct png_info* info); |
| 72 | +struct png_rgb* png_decode_rgb(struct png_info* info); |
| 73 | +void png_destroy(struct png_info* info); |
| 74 | + |
| 75 | + |
| 76 | +#endif |
Index: libs/png/version.h |
— | — | @@ -0,0 +1,36 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2010 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emBIOS.
|
| 8 | +//
|
| 9 | +// emBIOS is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emBIOS is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#ifndef __VERSION_H__
|
| 26 | +#define __VERSION_H__
|
| 27 | +
|
| 28 | +
|
| 29 | +#define VERSION "0.0.1pre"
|
| 30 | +#define VERSION_MAJOR 0
|
| 31 | +#define VERSION_MINOR 0
|
| 32 | +#define VERSION_PATCH 1
|
| 33 | +#define VERSION_SVN "$REVISION$"
|
| 34 | +#define VERSION_SVN_INT $REVISIONINT$
|
| 35 | +
|
| 36 | +
|
| 37 | +#endif |
\ No newline at end of file |
Index: libs/png/Makefile |
— | — | @@ -0,0 +1,118 @@ |
| 2 | +NAME := png
|
| 3 | +COMPRESS := true
|
| 4 | +
|
| 5 | +EMCOREDIR ?= ../../emcore/trunk/
|
| 6 | +
|
| 7 | +ifeq ($(shell uname),WindowsNT)
|
| 8 | +CCACHE :=
|
| 9 | +else
|
| 10 | +CCACHE := $(shell which ccache)
|
| 11 | +endif
|
| 12 | +
|
| 13 | +CROSS ?= arm-elf-eabi-
|
| 14 | +CC := $(CCACHE) $(CROSS)gcc
|
| 15 | +AS := $(CROSS)as
|
| 16 | +LD := $(CROSS)ld
|
| 17 | +OBJCOPY := $(CROSS)objcopy
|
| 18 | +ELF2ECA := $(CROSS)elf2emcoreapp
|
| 19 | +
|
| 20 | +CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -I$(EMCOREDIR)/export -ffunction-sections -fdata-sections -mcpu=arm940t -DARM_ARCH=4
|
| 21 | +LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --emit-relocs --gc-sections
|
| 22 | +
|
| 23 | +preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
|
| 24 | +preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:")
|
| 25 | +
|
| 26 | +REVISION := $(shell svnversion .)
|
| 27 | +REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
|
| 28 | +
|
| 29 | +HELPERS := build/__emcore_armhelpers.o
|
| 30 | +
|
| 31 | +SRC := $(call preprocesspaths,SOURCES,-I. -I..)
|
| 32 | +OBJ := $(SRC:%.c=build/%.o)
|
| 33 | +OBJ := $(OBJ:%.S=build/%.o) $(HELPERS)
|
| 34 | +
|
| 35 | +all: $(NAME)
|
| 36 | +
|
| 37 | +-include $(OBJ:%=%.dep)
|
| 38 | +
|
| 39 | +$(NAME): build/$(NAME).emcorelib
|
| 40 | +
|
| 41 | +build/$(NAME).emcorelib: build/$(NAME).elf
|
| 42 | + @echo [EMCLIB] $<
|
| 43 | +ifeq ($(COMPRESS),true)
|
| 44 | + @$(ELF2ECA) -l -z -s 0 -o $@ $^
|
| 45 | +else
|
| 46 | + @$(ELF2ECA) -l -s 0 -o $@ $^
|
| 47 | +endif
|
| 48 | +
|
| 49 | +build/$(NAME).elf: ls.x $(OBJ)
|
| 50 | + @echo [LD] $@
|
| 51 | + @$(LD) $(LDFLAGS) -o $@ -T ls.x $(OBJ)
|
| 52 | +
|
| 53 | +build/%.o: %.c build/version.h
|
| 54 | + @echo [CC] $<
|
| 55 | +ifeq ($(shell uname),WindowsNT)
|
| 56 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| 57 | +else
|
| 58 | + @-mkdir -p $(dir $@)
|
| 59 | +endif
|
| 60 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| 61 | + @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
|
| 62 | + @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
|
| 63 | +ifeq ($(shell uname),WindowsNT)
|
| 64 | + @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
|
| 65 | +else
|
| 66 | + @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
|
| 67 | +endif
|
| 68 | + @rm -f $@.dep.tmp
|
| 69 | +
|
| 70 | +build/%.o: %.S build/version.h
|
| 71 | + @echo [CC] $<
|
| 72 | +ifeq ($(shell uname),WindowsNT)
|
| 73 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| 74 | +else
|
| 75 | + @-mkdir -p $(dir $@)
|
| 76 | +endif
|
| 77 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| 78 | + @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
|
| 79 | + @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
|
| 80 | +ifeq ($(shell uname),WindowsNT)
|
| 81 | + @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
|
| 82 | +else
|
| 83 | + @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
|
| 84 | +endif
|
| 85 | + @rm -f $@.dep.tmp
|
| 86 | +
|
| 87 | +build/__emcore_%.o: $(EMCOREDIR)/export/%.c
|
| 88 | + @echo [CC] $<
|
| 89 | +ifeq ($(shell uname),WindowsNT)
|
| 90 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| 91 | +else
|
| 92 | + @-mkdir -p $(dir $@)
|
| 93 | +endif
|
| 94 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| 95 | +
|
| 96 | +build/__emcore_%.o: $(EMCOREDIR)/export/%.S
|
| 97 | + @echo [CC] $<
|
| 98 | +ifeq ($(shell uname),WindowsNT)
|
| 99 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| 100 | +else
|
| 101 | + @-mkdir -p $(dir $@)
|
| 102 | +endif
|
| 103 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| 104 | +
|
| 105 | +build/version.h: version.h .svn/entries build
|
| 106 | + @echo [PP] $<
|
| 107 | +ifeq ($(shell uname),WindowsNT)
|
| 108 | + @sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
|
| 109 | +else
|
| 110 | + @sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
|
| 111 | +endif
|
| 112 | +
|
| 113 | +build:
|
| 114 | + @mkdir $@
|
| 115 | +
|
| 116 | +clean:
|
| 117 | + rm -rf build
|
| 118 | +
|
| 119 | +.PHONY: all clean $(NAME)
|
Index: libs/png |
Property changes on: libs/png |
___________________________________________________________________ |
Added: svn:ignore |
## -0,0 +1 ## |
| 120 | +build |