Austin Schuh | 3333ec7 | 2022-12-29 16:21:06 -0800 | [diff] [blame^] | 1 | /* Copyright (C) 2013-2016, The Regents of The University of Michigan. |
| 2 | All rights reserved. |
| 3 | This software was developed in the APRIL Robotics Lab under the |
| 4 | direction of Edwin Olson, ebolson@umich.edu. This software may be |
| 5 | available under alternative licensing terms; contact the address above. |
| 6 | Redistribution and use in source and binary forms, with or without |
| 7 | modification, are permitted provided that the following conditions are met: |
| 8 | 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | list of conditions and the following disclaimer. |
| 10 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | this list of conditions and the following disclaimer in the documentation |
| 12 | and/or other materials provided with the distribution. |
| 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | The views and conclusions contained in the software and documentation are those |
| 24 | of the authors and should not be interpreted as representing official policies, |
| 25 | either expressed or implied, of the Regents of The University of Michigan. |
| 26 | */ |
| 27 | |
| 28 | #pragma once |
| 29 | |
| 30 | #include "image_u8.h" |
| 31 | #include "image_u8x3.h" |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
| 37 | typedef struct pjpeg_component pjpeg_component_t; |
| 38 | struct pjpeg_component |
| 39 | { |
| 40 | // resolution of this component (which is smaller than the |
| 41 | // dimensions of the image if the channel has been sub-sampled.) |
| 42 | uint32_t width, height; |
| 43 | |
| 44 | // number of bytes per row. May be larger than width for alignment |
| 45 | // reasons. |
| 46 | uint32_t stride; |
| 47 | |
| 48 | // data[y*stride + x] |
| 49 | uint8_t *data; |
| 50 | |
| 51 | //////////////////////////////////////////////////////////////// |
| 52 | // These items probably not of great interest to most |
| 53 | // applications. |
| 54 | uint8_t id; // the identifier associated with this component |
| 55 | uint8_t hv; // horiz scale (high 4 bits) / vert scale (low 4 bits) |
| 56 | uint8_t scalex, scaley; // derived from hv above |
| 57 | uint8_t tq; // quantization table index |
| 58 | |
| 59 | // this filled in at the last moment by SOS |
| 60 | uint8_t tda; // which huff tables will we use for DC (high 4 bits) and AC (low 4 bits) |
| 61 | }; |
| 62 | |
| 63 | typedef struct pjpeg pjpeg_t; |
| 64 | struct pjpeg |
| 65 | { |
| 66 | // status of the decode is put here. Non-zero means error. |
| 67 | int error; |
| 68 | |
| 69 | uint32_t width, height; // pixel dimensions |
| 70 | |
| 71 | int ncomponents; |
| 72 | pjpeg_component_t *components; |
| 73 | }; |
| 74 | |
| 75 | enum PJPEG_FLAGS { |
| 76 | PJPEG_STRICT = 1, // Don't try to recover from errors. |
| 77 | PJPEG_MJPEG = 2, // Support JPGs with missing DHT segments. |
| 78 | }; |
| 79 | |
| 80 | enum PJPEG_ERROR { |
| 81 | PJPEG_OKAY = 0, |
| 82 | PJPEG_ERR_FILE, // something wrong reading file |
| 83 | PJPEG_ERR_DQT, // something wrong with DQT marker |
| 84 | PJPEG_ERR_SOF, // something wrong with SOF marker |
| 85 | PJPEG_ERR_DHT, // something wrong with DHT marker |
| 86 | PJPEG_ERR_SOS, // something wrong with SOS marker |
| 87 | PJPEG_ERR_MISSING_DHT, // missing a necessary huffman table |
| 88 | PJPEG_ERR_DRI, // something wrong with DRI marker |
| 89 | PJPEG_ERR_RESET, // didn't get a reset marker where we expected. Corruption? |
| 90 | PJPEG_ERR_EOF, // ran out of bytes while decoding |
| 91 | PJEPG_ERR_UNSUPPORTED, // an unsupported format |
| 92 | }; |
| 93 | |
| 94 | pjpeg_t *pjpeg_create_from_file(const char *path, uint32_t flags, int *error); |
| 95 | pjpeg_t *pjpeg_create_from_buffer(uint8_t *buf, int buflen, uint32_t flags, int *error); |
| 96 | void pjpeg_destroy(pjpeg_t *pj); |
| 97 | |
| 98 | image_u8_t *pjpeg_to_u8_baseline(pjpeg_t *pj); |
| 99 | image_u8x3_t *pjpeg_to_u8x3_baseline(pjpeg_t *pj); |
| 100 | |
| 101 | #ifdef __cplusplus |
| 102 | } |
| 103 | #endif |