Subversion Repositories freemyipod

Rev

Rev 494 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 494 Rev 649
Line 58... Line 58...
58
 * 3. This notice may not be removed or altered from
58
 * 3. This notice may not be removed or altered from
59
 *    any source distribution.
59
 *    any source distribution.
60
 */
60
 */
61
 
61
 
62
 
62
 
63
//#define DEBUG_CONSOLES 2
63
//#define DEBUG_CONSOLES 2
64
//#define DEBUG_PRINT_SOURCE_LINE
64
//#define DEBUG_PRINT_SOURCE_LINE
65
 
65
 
66
 
66
 
67
#include "emcorelib.h"
67
#include "emcorelib.h"
68
#include "tinf.h"
68
#include "tinf.h"
69
 
69
 
70
/* ------------------------------ *
70
/* ------------------------------ *
Line 225... Line 225...
225
   unsigned int bit;
225
   unsigned int bit;
226
//   DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
226
//   DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
227
//          d->bytecount, d->bitcount, d->source);
227
//          d->bytecount, d->bitcount, d->source);
228
 
228
 
229
   /* check if tag is empty */
229
   /* check if tag is empty */
230
   if (!--d->bitcount)
230
   if (!d->bitcount)
231
   {
231
   {
232
       while (!--d->bytecount)
232
       while (!d->bytecount)
233
       {
233
       {
234
           DEBUGF("tinf_getbit: refilling bytes");
234
           DEBUGF("tinf_getbit: refilling bytes");
235
   DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
235
           DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
236
          d->bytecount, d->bitcount, d->source);
236
                  d->bytecount, d->bitcount, d->source);
237
           d->bytecount = (d->source[4] << 24) | (d->source[5] << 16)
237
           d->bytecount = (d->source[4] << 24) | (d->source[5] << 16)
238
                        | (d->source[6] << 8) | d->source[7];
238
                        | (d->source[6] << 8) | d->source[7];
239
           d->source += 12;
239
           d->source += 12;
240
   DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
240
           DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
241
          d->bytecount, d->bitcount, d->source);
241
                  d->bytecount, d->bitcount, d->source);
242
       }
242
       }
243
      /* load next tag */
243
      /* load next tag */
244
      d->tag = *d->source++;
244
      d->tag = *d->source++;
245
      d->bitcount = 8;
245
      d->bitcount = 8;
-
 
246
      d->bytecount--;
246
   }
247
   }
247
 
248
 
248
   /* shift bit out of tag */
249
   /* shift bit out of tag */
249
   bit = d->tag & 1;
250
   bit = d->tag & 1;
250
   d->tag >>= 1;
251
   d->tag >>= 1;
-
 
252
   d->bitcount--;
251
 
253
 
252
//   DEBUGF("tinf_getbit: returning bit %d", bit);
254
//   DEBUGF("tinf_getbit: returning bit %d", bit);
253
   return bit;
255
   return bit;
254
}
256
}
255
 
257
 
Line 477... Line 479...
477
{
479
{
478
    TINF_DATA d;
480
    TINF_DATA d;
479
    int bfinal;
481
    int bfinal;
480
 
482
 
481
    d.source = (const unsigned char *)(source + 10);
483
    d.source = (const unsigned char *)(source + 10);
482
    d.bitcount = 1;
484
    d.bitcount = 0;
483
    d.bytecount = ((d.source[-10] << 24) | (d.source[-9] << 16)
485
    d.bytecount = ((d.source[-10] << 24) | (d.source[-9] << 16)
484
                 | (d.source[-8] << 8) | d.source[-7]) + 1;
486
                 | (d.source[-8] << 8) | d.source[-7]) - 2;
485
 
487
 
486
    d.dest = (unsigned char *)dest;
488
    d.dest = (unsigned char *)dest;
487
    d.destLen = destLen;
489
    d.destLen = destLen;
488
 
490
 
489
    *destLen = 0;
491
    *destLen = 0;
Line 522... Line 524...
522
       }
524
       }
523
 
525
 
524
       if (res) return res;
526
       if (res) return res;
525
 
527
 
526
       if (d.source > (unsigned char *)source + sourceLen)
528
       if (d.source > (unsigned char *)source + sourceLen)
-
 
529
       {
-
 
530
           DEBUGF("tinf_uncompress: Hit end of buffer! (source=0x%08X, len=%d, current=0x%08X)",
-
 
531
                  source, sourceLen, d.source);
527
           return -7;
532
           return -7;
-
 
533
       }
528
    } while (!bfinal);
534
    } while (!bfinal);
529
 
535
 
-
 
536
    d.bytecount -= 4;
-
 
537
   
-
 
538
    if (d.bytecount)
-
 
539
    {
-
 
540
        DEBUGF("tinf_uncompress: %d leftover bytes, %d bits!", d.bytecount, d.bitcount);
-
 
541
        return -8;
-
 
542
    }
-
 
543
 
530
    return 0;
544
    return 0;
531
}
545
}