Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
494 theseven 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
 * emCORE adaptation:
17
 * Copyright (c) 2011 by Michael Sparmann
18
 *
19
 * This program is free software; you can redistribute it and/or
20
 * modify it under the terms of the GNU General Public License
21
 * as published by the Free Software Foundation; either version 2
22
 * of the License, or (at your option) any later version.
23
 *
24
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25
 * KIND, either express or implied.
26
 *
27
 ****************************************************************************/
28
 
29
/*
30
 * tinfzlib  -  tiny zlib decompressor
31
 *
32
 * Copyright (c) 2003 by Joergen Ibsen / Jibz
33
 * All Rights Reserved
34
 *
35
 * http://www.ibsensoftware.com/
36
 *
37
 * This software is provided 'as-is', without any express
38
 * or implied warranty.  In no event will the authors be
39
 * held liable for any damages arising from the use of
40
 * this software.
41
 *
42
 * Permission is granted to anyone to use this software
43
 * for any purpose, including commercial applications,
44
 * and to alter it and redistribute it freely, subject to
45
 * the following restrictions:
46
 *
47
 * 1. The origin of this software must not be
48
 *    misrepresented; you must not claim that you
49
 *    wrote the original software. If you use this
50
 *    software in a product, an acknowledgment in
51
 *    the product documentation would be appreciated
52
 *    but is not required.
53
 *
54
 * 2. Altered source versions must be plainly marked
55
 *    as such, and must not be misrepresented as
56
 *    being the original software.
57
 *
58
 * 3. This notice may not be removed or altered from
59
 *    any source distribution.
60
 */
61
 
62
#include "emcorelib.h"
63
#include "tinf.h"
64
 
65
/* This routine do not check adler32 checksum
66
 * as it is tailored to be used as PNG decompressor
67
 * and PNG has crc32 check of the compressed block
68
 * already
69
 */
70
int tinf_zlib_uncompress(void *dest, unsigned int *destLen,
71
                         const void *source, unsigned int sourceLen)
72
{
73
   unsigned char *src = (unsigned char *)source;
74
   unsigned char *dst = (unsigned char *)dest;
75
   int res;
76
   unsigned char cmf, flg;
77
 
78
   /* -- get header bytes -- */
79
 
80
   cmf = src[8];
81
   flg = src[9];
82
 
83
   /* -- check format -- */
84
 
85
   /* check checksum */
86
   if (((cmf << 8) + flg) % 31) return -1;
87
 
88
   /* check method is deflate */
89
   if ((cmf & 0x0f) != 8) return -2;
90
 
91
   /* check window size is valid */
92
   if ((cmf >> 4) > 7) return -3;
93
 
94
   /* check there is no preset dictionary */
95
   if (flg & 0x20) return -4;
96
 
97
   /* -- inflate -- */
98
 
99
   return tinf_uncompress(dst, destLen, src, sourceLen);
100
}