Loading...
Searching...
No Matches
Reusable IJG compressor and JPEG publisher.
More...
#include <jpeg_encoder.h>
|
| struct | Error |
| struct | Image |
| | Borrowed view of a JPEG held in this encoder's reusable buffer. More...
|
|
| | 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 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 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.
|
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.
◆ 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]
Noncopyable: the compressor stores a pointer to its encoder owner.
◆ 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] | bgra | Top-left pixel of the source image. |
| [in] | width | Image width in pixels. |
| [in] | height | Image height in pixels. |
| [in] | stride | Source row stride in bytes. |
| [in] | quality | JPEG quality from 1 through 100. |
- Returns
- JPEG bytes borrowed from this encoder; the next encode may replace them.
- Exceptions
-
| std::runtime_error | If 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
-
| codec | Compressor 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
-
| codec | Compressor 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
-
| codec | Compressor 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=()
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] | image | Encoded JPEG view returned by encode. |
| [in] | path | New destination path; the caller controls overwrite policy. |
| [in] | exif | Serialized EXIF payload, or null when no metadata is added. |
| [in] | exifSize | EXIF payload size in bytes. |
| [in] | durable | Whether to use the fsync-backed working-file publisher. |
- Exceptions
-
| std::runtime_error | If 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
-
| codec | Compressor 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.
◆ buffer_
| std::vector<unsigned char> JpegEncoder::buffer_ |
|
private |
◆ compressor_
| jpeg_compress_struct JpegEncoder::compressor_ {} |
|
private |
◆ destination_
| jpeg_destination_mgr JpegEncoder::destination_ {} |
|
private |
◆ error_
◆ limit_
| std::size_t JpegEncoder::limit_ = 0 |
|
private |
◆ row_
| std::vector<unsigned char> JpegEncoder::row_ |
|
private |
◆ size_
| std::size_t JpegEncoder::size_ = 0 |
|
private |
The documentation for this class was generated from the following file: