summaryrefslogtreecommitdiff
path: root/apps/plugins/imageviewer/png/tinfzlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/imageviewer/png/tinfzlib.c')
-rw-r--r--apps/plugins/imageviewer/png/tinfzlib.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/apps/plugins/imageviewer/png/tinfzlib.c b/apps/plugins/imageviewer/png/tinfzlib.c
new file mode 100644
index 0000000000..711b6cf2e9
--- /dev/null
+++ b/apps/plugins/imageviewer/png/tinfzlib.c
@@ -0,0 +1,100 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Original source:
11 * Copyright (c) 2003 by Joergen Ibsen / Jibz
12 *
13 * Rockbox adaptation:
14 * Copyright (c) 2010 by Marcin Bukat
15 *
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.
20 *
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
23 *
24 ****************************************************************************/
25
26/*
27 * tinfzlib - tiny zlib decompressor
28 *
29 * Copyright (c) 2003 by Joergen Ibsen / Jibz
30 * All Rights Reserved
31 *
32 * http://www.ibsensoftware.com/
33 *
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.
38 *
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:
43 *
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.
50 *
51 * 2. Altered source versions must be plainly marked
52 * as such, and must not be misrepresented as
53 * being the original software.
54 *
55 * 3. This notice may not be removed or altered from
56 * any source distribution.
57 */
58
59#include "tinf.h"
60
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
65 */
66int tinf_zlib_uncompress(void *dest, unsigned int *destLen,
67 const void *source, unsigned int sourceLen)
68{
69 unsigned char *src = (unsigned char *)source;
70 unsigned char *dst = (unsigned char *)dest;
71 int res;
72 unsigned char cmf, flg;
73
74 /* -- get header bytes -- */
75
76 cmf = src[0];
77 flg = src[1];
78
79 /* -- check format -- */
80
81 /* check checksum */
82 if (((cmf << 8) + flg) % 31) return TINF_DATA_ERROR;
83
84 /* check method is deflate */
85 if ((cmf & 0x0f) != 8) return TINF_DATA_ERROR;
86
87 /* check window size is valid */
88 if ((cmf >> 4) > 7) return TINF_DATA_ERROR;
89
90 /* check there is no preset dictionary */
91 if (flg & 0x20) return TINF_DATA_ERROR;
92
93 /* -- inflate -- */
94
95 res = tinf_uncompress(dst, destLen, src + 2, sourceLen - 6);
96
97 if (res != TINF_OK) return TINF_DATA_ERROR;
98
99 return TINF_OK;
100}