blob: 7c8fd67917097e20ebf310d0e5f06440d36b89f7 [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
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include "aos/vision/image/image_types.h"
8
9namespace aos {
10namespace vision {
11
12// Returns true if successful false if an error was encountered.
13// Will decompress data into out. Out must be of the right size
14// as determined below.
15bool ProcessJpeg(DataRef data, PixelRef *out);
16
17// Gets the format for the particular jpeg.
18ImageFormat GetFmt(DataRef data);
19
20// Decodes jpeg from data. Will resize if necessary.
21// (Should not be necessary in most normal cases).
22//
23// Consider this the canonical way to decode jpegs if no other
24// choice is given.
25inline bool DecodeJpeg(DataRef data, ImageValue *value) {
26 auto fmt = GetFmt(data);
27 if (!value->fmt().Equals(fmt)) {
28 *value = ImageValue(fmt);
29 }
30 return ProcessJpeg(data, value->data());
31}
32
33} // namespace vision
34} // namespace aos
35
36#endif // _AOS_VISION_IMAGE_JPEGROUTINES_H_