File: jpegmarkersegment.h

package info (click to toggle)
gdcm 3.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 26,880 kB
  • sloc: cpp: 203,477; ansic: 78,582; xml: 48,129; python: 3,459; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 117
file content (76 lines) | stat: -rw-r--r-- 3,014 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// (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 <vector>
#include <cstdint>
#include <memory>


enum class JpegMarkerCode : uint8_t;


class JpegMarkerSegment : public JpegSegment
{
public:
    /// <summary>
    /// Creates a JPEG-LS Start Of Frame (SOF-55) segment.
    /// </summary>
    /// <param name="width">The width of the frame.</param>
    /// <param name="height">The height of the frame.</param>
    /// <param name="bitsPerSample">The bits per sample.</param>
    /// <param name="componentCount">The component count.</param>
    static std::unique_ptr<JpegMarkerSegment> CreateStartOfFrameSegment(int width, int height, int bitsPerSample, int componentCount);

    /// <summary>
    /// Creates a JPEG File Interchange (APP1 + jfif) segment.
    /// </summary>
    /// <param name="jfif">Parameters to write into the JFIF segment.</param>
    static std::unique_ptr<JpegMarkerSegment> CreateJpegFileInterchangeFormatSegment(const JfifParameters& params);

    /// <summary>
    /// Creates a JPEG-LS extended parameters (LSE) segment.
    /// </summary>
    /// <param name="params">Parameters to write into the JPEG-LS extended segment.</param>
    static std::unique_ptr<JpegMarkerSegment> CreateJpegLSExtendedParametersSegment(const JlsCustomParameters& params);

    /// <summary>
    /// Creates a color transformation (APP8) segment.
    /// </summary>
    /// <param name="jfif">Parameters to write into the JFIF segment.</param>
    static std::unique_ptr<JpegMarkerSegment> CreateColorTransformSegment(charls::ColorTransformation transformation);

    /// <summary>
    /// Creates a JPEG-LS Start Of Scan (SOS) segment.
    /// </summary>
    /// <param name="componentIndex">The component index of the scan segment or the start index if component count > 1.</param>
    /// <param name="componentCount">The number of components in the scan segment. Can only be > 1 when the components are interleaved.</param>
    /// <param name="allowedLossyError">The allowed lossy error. 0 means lossless.</param>
    /// <param name="interleaveMode">The interleave mode of the components.</param>
    static std::unique_ptr<JpegMarkerSegment> CreateStartOfScanSegment(int componentIndex, int componentCount, int allowedLossyError, charls::InterleaveMode interleaveMode);

    JpegMarkerSegment(JpegMarkerCode markerCode, std::vector<uint8_t>&& content) :
        _markerCode(markerCode),
        _content(content)
    {
    }

    void Serialize(JpegStreamWriter& streamWriter) override
    {
        streamWriter.WriteByte(0xFF);
        streamWriter.WriteByte(static_cast<uint8_t>(_markerCode));
        streamWriter.WriteWord(static_cast<uint16_t>(_content.size() + 2));
        streamWriter.WriteBytes(_content);
    }

private:
    JpegMarkerCode _markerCode;
    std::vector<uint8_t> _content;
};

#endif