This is a code which generates the various zoomed versions of an image stored in an SD card and displays it on a Nokia LCD based on the keys pressed on a capacitive touch pad.
Dependencies: FatFileSystem mbed
Fork of Lab3 by
picojpeg/picojpeg.h@0:c546b51ecf0b, 2011-10-11 (annotated)
- Committer:
- XkLi
- Date:
- Tue Oct 11 01:24:18 2011 +0000
- Revision:
- 0:c546b51ecf0b
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
XkLi | 0:c546b51ecf0b | 1 | //------------------------------------------------------------------------------ |
XkLi | 0:c546b51ecf0b | 2 | // picojpeg v1.0 - Public domain, Rich Geldreich <richgel99@gmail.com> |
XkLi | 0:c546b51ecf0b | 3 | //------------------------------------------------------------------------------ |
XkLi | 0:c546b51ecf0b | 4 | #ifndef PICOJPEG_H |
XkLi | 0:c546b51ecf0b | 5 | #define PICOJPEG_H |
XkLi | 0:c546b51ecf0b | 6 | |
XkLi | 0:c546b51ecf0b | 7 | #ifdef __cplusplus |
XkLi | 0:c546b51ecf0b | 8 | extern "C" { |
XkLi | 0:c546b51ecf0b | 9 | #endif |
XkLi | 0:c546b51ecf0b | 10 | |
XkLi | 0:c546b51ecf0b | 11 | // Error codes |
XkLi | 0:c546b51ecf0b | 12 | enum |
XkLi | 0:c546b51ecf0b | 13 | { |
XkLi | 0:c546b51ecf0b | 14 | PJPG_NO_MORE_BLOCKS = 1, |
XkLi | 0:c546b51ecf0b | 15 | PJPG_BAD_DHT_COUNTS, |
XkLi | 0:c546b51ecf0b | 16 | PJPG_BAD_DHT_INDEX, |
XkLi | 0:c546b51ecf0b | 17 | PJPG_BAD_DHT_MARKER, |
XkLi | 0:c546b51ecf0b | 18 | PJPG_BAD_DQT_MARKER, |
XkLi | 0:c546b51ecf0b | 19 | PJPG_BAD_DQT_TABLE, |
XkLi | 0:c546b51ecf0b | 20 | PJPG_BAD_PRECISION, |
XkLi | 0:c546b51ecf0b | 21 | PJPG_BAD_HEIGHT, |
XkLi | 0:c546b51ecf0b | 22 | PJPG_BAD_WIDTH, |
XkLi | 0:c546b51ecf0b | 23 | PJPG_TOO_MANY_COMPONENTS, |
XkLi | 0:c546b51ecf0b | 24 | PJPG_BAD_SOF_LENGTH, |
XkLi | 0:c546b51ecf0b | 25 | PJPG_BAD_VARIABLE_MARKER, |
XkLi | 0:c546b51ecf0b | 26 | PJPG_BAD_DRI_LENGTH, |
XkLi | 0:c546b51ecf0b | 27 | PJPG_BAD_SOS_LENGTH, |
XkLi | 0:c546b51ecf0b | 28 | PJPG_BAD_SOS_COMP_ID, |
XkLi | 0:c546b51ecf0b | 29 | PJPG_W_EXTRA_BYTES_BEFORE_MARKER, |
XkLi | 0:c546b51ecf0b | 30 | PJPG_NO_ARITHMITIC_SUPPORT, |
XkLi | 0:c546b51ecf0b | 31 | PJPG_UNEXPECTED_MARKER, |
XkLi | 0:c546b51ecf0b | 32 | PJPG_NOT_JPEG, |
XkLi | 0:c546b51ecf0b | 33 | PJPG_UNSUPPORTED_MARKER, |
XkLi | 0:c546b51ecf0b | 34 | PJPG_BAD_DQT_LENGTH, |
XkLi | 0:c546b51ecf0b | 35 | PJPG_TOO_MANY_BLOCKS, |
XkLi | 0:c546b51ecf0b | 36 | PJPG_UNDEFINED_QUANT_TABLE, |
XkLi | 0:c546b51ecf0b | 37 | PJPG_UNDEFINED_HUFF_TABLE, |
XkLi | 0:c546b51ecf0b | 38 | PJPG_NOT_SINGLE_SCAN, |
XkLi | 0:c546b51ecf0b | 39 | PJPG_UNSUPPORTED_COLORSPACE, |
XkLi | 0:c546b51ecf0b | 40 | PJPG_UNSUPPORTED_SAMP_FACTORS, |
XkLi | 0:c546b51ecf0b | 41 | PJPG_DECODE_ERROR, |
XkLi | 0:c546b51ecf0b | 42 | PJPG_BAD_RESTART_MARKER, |
XkLi | 0:c546b51ecf0b | 43 | PJPG_ASSERTION_ERROR, |
XkLi | 0:c546b51ecf0b | 44 | PJPG_BAD_SOS_SPECTRAL, |
XkLi | 0:c546b51ecf0b | 45 | PJPG_BAD_SOS_SUCCESSIVE, |
XkLi | 0:c546b51ecf0b | 46 | PJPG_STREAM_READ_ERROR, |
XkLi | 0:c546b51ecf0b | 47 | PJPG_NOTENOUGHMEM, |
XkLi | 0:c546b51ecf0b | 48 | PJPG_UNSUPPORTED_COMP_IDENT, |
XkLi | 0:c546b51ecf0b | 49 | PJPG_UNSUPPORTED_QUANT_TABLE, |
XkLi | 0:c546b51ecf0b | 50 | PJPG_UNSUPPORTED_MODE, |
XkLi | 0:c546b51ecf0b | 51 | }; |
XkLi | 0:c546b51ecf0b | 52 | |
XkLi | 0:c546b51ecf0b | 53 | // Scan types - currently only GRAYSCALE, YH1V1, and YH2V2 are actually supported. |
XkLi | 0:c546b51ecf0b | 54 | typedef enum |
XkLi | 0:c546b51ecf0b | 55 | { |
XkLi | 0:c546b51ecf0b | 56 | PJPG_GRAYSCALE, |
XkLi | 0:c546b51ecf0b | 57 | PJPG_YH1V1, |
XkLi | 0:c546b51ecf0b | 58 | PJPG_YH2V1, |
XkLi | 0:c546b51ecf0b | 59 | PJPG_YH1V2, |
XkLi | 0:c546b51ecf0b | 60 | PJPG_YH2V2 |
XkLi | 0:c546b51ecf0b | 61 | } pjpeg_scan_type_t; |
XkLi | 0:c546b51ecf0b | 62 | |
XkLi | 0:c546b51ecf0b | 63 | typedef struct |
XkLi | 0:c546b51ecf0b | 64 | { |
XkLi | 0:c546b51ecf0b | 65 | // Image resolution |
XkLi | 0:c546b51ecf0b | 66 | int m_width; |
XkLi | 0:c546b51ecf0b | 67 | int m_height; |
XkLi | 0:c546b51ecf0b | 68 | // Number of components (1 or 3) |
XkLi | 0:c546b51ecf0b | 69 | int m_comps; |
XkLi | 0:c546b51ecf0b | 70 | // Total number of minimum coded units (MCU's) per row/col. |
XkLi | 0:c546b51ecf0b | 71 | int m_MCUSPerRow; |
XkLi | 0:c546b51ecf0b | 72 | int m_MCUSPerCol; |
XkLi | 0:c546b51ecf0b | 73 | // Scan type |
XkLi | 0:c546b51ecf0b | 74 | pjpeg_scan_type_t m_scanType; |
XkLi | 0:c546b51ecf0b | 75 | // MCU width/height in pixels |
XkLi | 0:c546b51ecf0b | 76 | int m_MCUWidth; |
XkLi | 0:c546b51ecf0b | 77 | int m_MCUHeight; |
XkLi | 0:c546b51ecf0b | 78 | // Pointers to internal MCU pixel component buffers. |
XkLi | 0:c546b51ecf0b | 79 | // These buffers Will be filled with pixels each time pjpegDecodeMCU() is called successfully. |
XkLi | 0:c546b51ecf0b | 80 | // Each MCU consists of (m_MCUWidth/8)*(m_MCUHeight/8) blocks (currently either 1 for greyscale/no subsampling, or 4 for H2V2 sampling factors), where each block is a contiguous array of 64 (8x8) bytes. |
XkLi | 0:c546b51ecf0b | 81 | // For greyscale images, only the values in m_pMCUBufR are valid. |
XkLi | 0:c546b51ecf0b | 82 | unsigned char *m_pMCUBufR; |
XkLi | 0:c546b51ecf0b | 83 | unsigned char *m_pMCUBufG; |
XkLi | 0:c546b51ecf0b | 84 | unsigned char *m_pMCUBufB; |
XkLi | 0:c546b51ecf0b | 85 | } pjpeg_image_info_t; |
XkLi | 0:c546b51ecf0b | 86 | |
XkLi | 0:c546b51ecf0b | 87 | typedef unsigned char (*pjpeg_need_bytes_callback_t)(unsigned char* pBuf, unsigned char buf_size, unsigned char *pBytes_actually_read, void *pCallback_data); |
XkLi | 0:c546b51ecf0b | 88 | |
XkLi | 0:c546b51ecf0b | 89 | // Initializes the decompressor. Returns 0 on success, or one of the above error codes on failure. |
XkLi | 0:c546b51ecf0b | 90 | // pNeed_bytes_callback will be called to fill the decompressor's internal input buffer. |
XkLi | 0:c546b51ecf0b | 91 | // Not thread safe. |
XkLi | 0:c546b51ecf0b | 92 | unsigned char pjpeg_decode_init(pjpeg_image_info_t *pInfo, pjpeg_need_bytes_callback_t pNeed_bytes_callback, void *pCallback_data); |
XkLi | 0:c546b51ecf0b | 93 | |
XkLi | 0:c546b51ecf0b | 94 | // Decompresses the file's next MCU. Returns 0 on success, PJPG_NO_MORE_BLOCKS if no more blocks are available, or an error code. |
XkLi | 0:c546b51ecf0b | 95 | // Must be called a total of m_MCUSPerRow*m_MCUSPerCol times to completely decompress the image. |
XkLi | 0:c546b51ecf0b | 96 | unsigned char pjpeg_decode_mcu(void); |
XkLi | 0:c546b51ecf0b | 97 | |
XkLi | 0:c546b51ecf0b | 98 | #ifdef __cplusplus |
XkLi | 0:c546b51ecf0b | 99 | } |
XkLi | 0:c546b51ecf0b | 100 | #endif |
XkLi | 0:c546b51ecf0b | 101 | |
XkLi | 0:c546b51ecf0b | 102 | #endif // PICOJPEG_H |