Fix and extend imageviewer png support. FS#11641 by me
[kugel-rb.git] / apps / plugins / imageviewer / png / tinfzlib.c
blob711b6cf2e9d80119174c1023555c1f83a04c1a90
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Original source:
11 * Copyright (c) 2003 by Joergen Ibsen / Jibz
13 * Rockbox adaptation:
14 * Copyright (c) 2010 by Marcin Bukat
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ****************************************************************************/
27 * tinfzlib - tiny zlib decompressor
29 * Copyright (c) 2003 by Joergen Ibsen / Jibz
30 * All Rights Reserved
32 * http://www.ibsensoftware.com/
34 * This software is provided 'as-is', without any express
35 * or implied warranty. In no event will the authors be
36 * held liable for any damages arising from the use of
37 * this software.
39 * Permission is granted to anyone to use this software
40 * for any purpose, including commercial applications,
41 * and to alter it and redistribute it freely, subject to
42 * the following restrictions:
44 * 1. The origin of this software must not be
45 * misrepresented; you must not claim that you
46 * wrote the original software. If you use this
47 * software in a product, an acknowledgment in
48 * the product documentation would be appreciated
49 * but is not required.
51 * 2. Altered source versions must be plainly marked
52 * as such, and must not be misrepresented as
53 * being the original software.
55 * 3. This notice may not be removed or altered from
56 * any source distribution.
59 #include "tinf.h"
61 /* This routine do not check adler32 checksum
62 * as it is tailored to be used as PNG decompressor
63 * and PNG has crc32 check of the compressed block
64 * already
66 int tinf_zlib_uncompress(void *dest, unsigned int *destLen,
67 const void *source, unsigned int sourceLen)
69 unsigned char *src = (unsigned char *)source;
70 unsigned char *dst = (unsigned char *)dest;
71 int res;
72 unsigned char cmf, flg;
74 /* -- get header bytes -- */
76 cmf = src[0];
77 flg = src[1];
79 /* -- check format -- */
81 /* check checksum */
82 if (((cmf << 8) + flg) % 31) return TINF_DATA_ERROR;
84 /* check method is deflate */
85 if ((cmf & 0x0f) != 8) return TINF_DATA_ERROR;
87 /* check window size is valid */
88 if ((cmf >> 4) > 7) return TINF_DATA_ERROR;
90 /* check there is no preset dictionary */
91 if (flg & 0x20) return TINF_DATA_ERROR;
93 /* -- inflate -- */
95 res = tinf_uncompress(dst, destLen, src + 2, sourceLen - 6);
97 if (res != TINF_OK) return TINF_DATA_ERROR;
99 return TINF_OK;