Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
JpegEncoder Class Reference

Reusable IJG compressor and JPEG publisher. More...

#include <jpeg_encoder.h>

Collaboration diagram for JpegEncoder:

Data Structures

struct  Error
struct  Image
 Borrowed view of a JPEG held in this encoder's reusable buffer. More...

Public Member Functions

 JpegEncoder ()
 Create a compressor; throws if the codec cannot be initialized.
 ~JpegEncoder ()
 Release the compressor and invalidate any borrowed JPEG view.
 JpegEncoder (const JpegEncoder &)=delete
 Noncopyable: the compressor stores a pointer to its encoder owner.
JpegEncoder & operator= (const JpegEncoder &)=delete
 Nonassignable: codec and destination state must remain paired.
Image encode (const unsigned char *bgra, int width, int height, int stride, int quality)
 Encode one BGRA image using the configured JPEG quality.

Static Public Member Functions

static void save (const Image &image, const std::filesystem::path &path, const unsigned char *exif=nullptr, std::size_t exifSize=0, bool durable=false)
 Publish encoded JPEG bytes, optionally adding one EXIF APP1 segment.

Static Private Member Functions

static void failure (j_common_ptr codec)
 Save the codec diagnostic and transfer control to recovery.
static void startOutput (j_compress_ptr codec)
 Point the codec at reusable compressed-output storage.
static boolean growOutput (j_compress_ptr codec)
 Grow compressed storage without exceeding the operation limit.
static void finishOutput (j_compress_ptr codec)
 Record the compressed byte count, excluding unused buffer space.

Private Attributes

struct JpegEncoder::Error error_
jpeg_compress_struct compressor_ {}
jpeg_destination_mgr destination_ {}
std::vector< unsigned char > buffer_
std::vector< unsigned char > row_
std::size_t size_ = 0
std::size_t limit_ = 0

Detailed Description

Reusable IJG compressor and JPEG publisher.

Instances are stateful and are not safe for concurrent calls; create one per worker when tiles are encoded in parallel.

Definition at line 49 of file jpeg_encoder.h.

Constructor & Destructor Documentation

◆ JpegEncoder() [1/2]

JpegEncoder::JpegEncoder ( )
inline

Create a compressor; throws if the codec cannot be initialized.

Definition at line 113 of file jpeg_encoder.h.

◆ ~JpegEncoder()

JpegEncoder::~JpegEncoder ( )
inline

Release the compressor and invalidate any borrowed JPEG view.

Definition at line 128 of file jpeg_encoder.h.

◆ JpegEncoder() [2/2]

JpegEncoder::JpegEncoder ( const JpegEncoder & )
delete

Noncopyable: the compressor stores a pointer to its encoder owner.

Member Function Documentation

◆ encode()

Image JpegEncoder::encode ( const unsigned char * bgra,
int width,
int height,
int stride,
int quality )
inline

Encode one BGRA image using the configured JPEG quality.

Parameters
[in]bgraTop-left pixel of the source image.
[in]widthImage width in pixels.
[in]heightImage height in pixels.
[in]strideSource row stride in bytes.
[in]qualityJPEG quality from 1 through 100.
Returns
JPEG bytes borrowed from this encoder; the next encode may replace them.
Exceptions
std::runtime_errorIf dimensions, quality, or codec processing is invalid.

Definition at line 144 of file jpeg_encoder.h.

◆ failure()

void JpegEncoder::failure ( j_common_ptr codec)
inlinestaticprivate

Save the codec diagnostic and transfer control to recovery.

Parameters
codecCompressor carrying the installed error manager.

Convert to a C++ exception at the recovery site, not in this callback.

Definition at line 65 of file jpeg_encoder.h.

◆ finishOutput()

void JpegEncoder::finishOutput ( j_compress_ptr codec)
inlinestaticprivate

Record the compressed byte count, excluding unused buffer space.

Parameters
codecCompressor supplying the remaining destination bytes.

Definition at line 101 of file jpeg_encoder.h.

◆ growOutput()

boolean JpegEncoder::growOutput ( j_compress_ptr codec)
inlinestaticprivate

Grow compressed storage without exceeding the operation limit.

Parameters
codecCompressor that filled its destination span.
Returns
TRUE once more room is available; failures take codec recovery.

Resume writing at the consumed offset after resize, because vector growth can invalidate the codec's previous output pointer.

Definition at line 84 of file jpeg_encoder.h.

◆ operator=()

JpegEncoder & JpegEncoder::operator= ( const JpegEncoder & )
delete

Nonassignable: codec and destination state must remain paired.

◆ save()

void JpegEncoder::save ( const Image & image,
const std::filesystem::path & path,
const unsigned char * exif = nullptr,
std::size_t exifSize = 0,
bool durable = false )
inlinestatic

Publish encoded JPEG bytes, optionally adding one EXIF APP1 segment.

Parameters
[in]imageEncoded JPEG view returned by encode.
[in]pathNew destination path; the caller controls overwrite policy.
[in]exifSerialized EXIF payload, or null when no metadata is added.
[in]exifSizeEXIF payload size in bytes.
[in]durableWhether to use the fsync-backed working-file publisher.
Exceptions
std::runtime_errorIf JPEG framing, EXIF, or file publication fails.

Definition at line 192 of file jpeg_encoder.h.

◆ startOutput()

void JpegEncoder::startOutput ( j_compress_ptr codec)
inlinestaticprivate

Point the codec at reusable compressed-output storage.

Parameters
codecCompressor whose client data identifies the encoder.

Cap the writable span at the current operation limit even when a previous call allocated a larger buffer.

Definition at line 74 of file jpeg_encoder.h.

Field Documentation

◆ buffer_

std::vector<unsigned char> JpegEncoder::buffer_
private

Definition at line 57 of file jpeg_encoder.h.

◆ compressor_

jpeg_compress_struct JpegEncoder::compressor_ {}
private

Definition at line 55 of file jpeg_encoder.h.

◆ destination_

jpeg_destination_mgr JpegEncoder::destination_ {}
private

Definition at line 56 of file jpeg_encoder.h.

◆ error_

struct JpegEncoder::Error JpegEncoder::error_
private

◆ limit_

std::size_t JpegEncoder::limit_ = 0
private

Definition at line 60 of file jpeg_encoder.h.

◆ row_

std::vector<unsigned char> JpegEncoder::row_
private

Definition at line 58 of file jpeg_encoder.h.

◆ size_

std::size_t JpegEncoder::size_ = 0
private

Definition at line 59 of file jpeg_encoder.h.


The documentation for this class was generated from the following file: