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 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 11 | namespace aos::vision { |
Parker Schuh | 44f8692 | 2017-01-03 23:59:50 -0800 | [diff] [blame] | 12 | |
| 13 | // Returns true if successful false if an error was encountered. |
| 14 | // Will decompress data into out. Out must be of the right size |
| 15 | // as determined below. |
| 16 | bool ProcessJpeg(DataRef data, PixelRef *out); |
| 17 | |
| 18 | // Gets the format for the particular jpeg. |
| 19 | ImageFormat GetFmt(DataRef data); |
| 20 | |
| 21 | // Decodes jpeg from data. Will resize if necessary. |
| 22 | // (Should not be necessary in most normal cases). |
| 23 | // |
| 24 | // Consider this the canonical way to decode jpegs if no other |
| 25 | // choice is given. |
| 26 | inline bool DecodeJpeg(DataRef data, ImageValue *value) { |
| 27 | auto fmt = GetFmt(data); |
| 28 | if (!value->fmt().Equals(fmt)) { |
| 29 | *value = ImageValue(fmt); |
| 30 | } |
| 31 | return ProcessJpeg(data, value->data()); |
| 32 | } |
| 33 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 34 | } // namespace aos::vision |
Parker Schuh | 44f8692 | 2017-01-03 23:59:50 -0800 | [diff] [blame] | 35 | |
| 36 | #endif // _AOS_VISION_IMAGE_JPEGROUTINES_H_ |