// // (C) CharLS Team 2014, all rights reserved. See the accompanying "License.txt" for licensed use. // #ifndef CHARLS_JPEGMARKERSEGMENT #define CHARLS_JPEGMARKERSEGMENT #include "jpegsegment.h" #include "jpegstreamwriter.h" #include #include #include enum class JpegMarkerCode : uint8_t; class JpegMarkerSegment : public JpegSegment { public: /// /// Creates a JPEG-LS Start Of Frame (SOF-55) segment. /// /// The width of the frame. /// The height of the frame. /// The bits per sample. /// The component count. static std::unique_ptr CreateStartOfFrameSegment(int width, int height, int bitsPerSample, int componentCount); /// /// Creates a JPEG File Interchange (APP1 + jfif) segment. /// /// Parameters to write into the JFIF segment. static std::unique_ptr CreateJpegFileInterchangeFormatSegment(const JfifParameters& params); /// /// Creates a JPEG-LS extended parameters (LSE) segment. /// /// Parameters to write into the JPEG-LS extended segment. static std::unique_ptr CreateJpegLSExtendedParametersSegment(const JlsCustomParameters& params); /// /// Creates a color transformation (APP8) segment. /// /// Parameters to write into the JFIF segment. static std::unique_ptr CreateColorTransformSegment(charls::ColorTransformation transformation); /// /// Creates a JPEG-LS Start Of Scan (SOS) segment. /// /// The component index of the scan segment or the start index if component count > 1. /// The number of components in the scan segment. Can only be > 1 when the components are interleaved. /// The allowed lossy error. 0 means lossless. /// The interleave mode of the components. static std::unique_ptr CreateStartOfScanSegment(int componentIndex, int componentCount, int allowedLossyError, charls::InterleaveMode interleaveMode); JpegMarkerSegment(JpegMarkerCode markerCode, std::vector&& content) : _markerCode(markerCode), _content(content) { } void Serialize(JpegStreamWriter& streamWriter) override { streamWriter.WriteByte(0xFF); streamWriter.WriteByte(static_cast(_markerCode)); streamWriter.WriteWord(static_cast(_content.size() + 2)); streamWriter.WriteBytes(_content); } private: JpegMarkerCode _markerCode; std::vector _content; }; #endif