Parker Schuh | 44f8692 | 2017-01-03 23:59:50 -0800 | [diff] [blame] | 1 | #ifndef _AOS_VISION_IMAGE_JPEGROUTINES_H_ |
| 2 | #define _AOS_VISION_IMAGE_JPEGROUTINES_H_ |
| 3 | |
Parker Schuh | 44f8692 | 2017-01-03 23:59:50 -0800 | [diff] [blame] | 4 | #include <unistd.h> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 5 | |
| 6 | #include <cstdio> |
| 7 | #include <cstdlib> |
| 8 | |
Parker Schuh | 44f8692 | 2017-01-03 23:59:50 -0800 | [diff] [blame] | 9 | #include "aos/vision/image/image_types.h" |
| 10 | |
| 11 | namespace aos { |
| 12 | namespace vision { |
| 13 | |
| 14 | // Returns true if successful false if an error was encountered. |
| 15 | // Will decompress data into out. Out must be of the right size |
| 16 | // as determined below. |
| 17 | bool ProcessJpeg(DataRef data, PixelRef *out); |
| 18 | |
| 19 | // Gets the format for the particular jpeg. |
| 20 | ImageFormat GetFmt(DataRef data); |
| 21 | |
| 22 | // Decodes jpeg from data. Will resize if necessary. |
| 23 | // (Should not be necessary in most normal cases). |
| 24 | // |
| 25 | // Consider this the canonical way to decode jpegs if no other |
| 26 | // choice is given. |
| 27 | inline bool DecodeJpeg(DataRef data, ImageValue *value) { |
| 28 | auto fmt = GetFmt(data); |
| 29 | if (!value->fmt().Equals(fmt)) { |
| 30 | *value = ImageValue(fmt); |
| 31 | } |
| 32 | return ProcessJpeg(data, value->data()); |
| 33 | } |
| 34 | |
| 35 | } // namespace vision |
| 36 | } // namespace aos |
| 37 | |
| 38 | #endif // _AOS_VISION_IMAGE_JPEGROUTINES_H_ |