blob: 59ad296de676ffb5453521ea409015abe8d63b4b [file] [log] [blame]
Parker Schuh44f86922017-01-03 23:59:50 -08001#ifndef _AOS_VISION_IMAGE_JPEGROUTINES_H_
2#define _AOS_VISION_IMAGE_JPEGROUTINES_H_
3
Parker Schuh44f86922017-01-03 23:59:50 -08004#include <unistd.h>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07005
6#include <cstdio>
7#include <cstdlib>
8
Parker Schuh44f86922017-01-03 23:59:50 -08009#include "aos/vision/image/image_types.h"
10
11namespace aos {
12namespace 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.
17bool ProcessJpeg(DataRef data, PixelRef *out);
18
19// Gets the format for the particular jpeg.
20ImageFormat 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.
27inline 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_