| 1 |
#include "codec_cdzl.h" |
| 2 |
|
| 3 |
#include <stddef.h> |
| 4 |
#include <stdlib.h> |
| 5 |
#include <string.h> |
| 6 |
|
| 7 |
#include "../include/libchdr/cdrom.h" |
| 8 |
|
| 9 |
chd_error cdzl_codec_init(void *codec, uint32_t hunkbytes) |
| 10 |
{ |
| 11 |
chd_error ret; |
| 12 |
cdzl_codec_data* cdzl = (cdzl_codec_data*)codec; |
| 13 |
|
| 14 |
|
| 15 |
if (hunkbytes % CD_FRAME_SIZE != 0) |
| 16 |
return CHDERR_CODEC_ERROR; |
| 17 |
|
| 18 |
cdzl->buffer = (uint8_t*)malloc(sizeof(uint8_t) * hunkbytes); |
| 19 |
if (cdzl->buffer == NULL) |
| 20 |
return CHDERR_OUT_OF_MEMORY; |
| 21 |
|
| 22 |
ret = zlib_codec_init(&cdzl->base_decompressor, (hunkbytes / CD_FRAME_SIZE) * CD_MAX_SECTOR_DATA); |
| 23 |
if (ret != CHDERR_NONE) |
| 24 |
return ret; |
| 25 |
|
| 26 |
#if WANT_SUBCODE |
| 27 |
ret = zlib_codec_init(&cdzl->subcode_decompressor, (hunkbytes / CD_FRAME_SIZE) * CD_MAX_SUBCODE_DATA); |
| 28 |
if (ret != CHDERR_NONE) |
| 29 |
return ret; |
| 30 |
#endif |
| 31 |
|
| 32 |
return CHDERR_NONE; |
| 33 |
} |
| 34 |
|
| 35 |
void cdzl_codec_free(void *codec) |
| 36 |
{ |
| 37 |
cdzl_codec_data* cdzl = (cdzl_codec_data*)codec; |
| 38 |
zlib_codec_free(&cdzl->base_decompressor); |
| 39 |
#if WANT_SUBCODE |
| 40 |
zlib_codec_free(&cdzl->subcode_decompressor); |
| 41 |
#endif |
| 42 |
free(cdzl->buffer); |
| 43 |
} |
| 44 |
|
| 45 |
chd_error cdzl_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) |
| 46 |
{ |
| 47 |
cdzl_codec_data* cdzl = (cdzl_codec_data*)codec; |
| 48 |
|
| 49 |
return cd_codec_decompress(cdzl->buffer, |
| 50 |
&cdzl->base_decompressor, zlib_codec_decompress, |
| 51 |
#if WANT_SUBCODE |
| 52 |
&cdzl->subcode_decompressor, zlib_codec_decompress, |
| 53 |
#else |
| 54 |
NULL, NULL, |
| 55 |
#endif |
| 56 |
src, complen, dest, destlen |
| 57 |
); |
| 58 |
} |