blob: 4bac976c63789699bdaac106adbb4d8ff07465b1 [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
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080011namespace aos::vision {
Parker Schuh44f86922017-01-03 23:59:50 -080012
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.
16bool ProcessJpeg(DataRef data, PixelRef *out);
17
18// Gets the format for the particular jpeg.
19ImageFormat 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.
26inline 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 Pleinesd99b1ee2024-02-02 20:56:44 -080034} // namespace aos::vision
Parker Schuh44f86922017-01-03 23:59:50 -080035
36#endif // _AOS_VISION_IMAGE_JPEGROUTINES_H_