Welcome to mirror list, hosted at ThFree Co, Russian Federation.

File_Bpg.cpp « Image « MediaInfo « MediaInfo « thirdparty « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3d2e5ab04c801ad33bffb45bda2de9d06023e832 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// From http://bellard.org/bpg/bpg_spec.txt
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//---------------------------------------------------------------------------
// Pre-compilation
#include "MediaInfo/PreComp.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Setup.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#if defined(MEDIAINFO_BPG_YES)
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Image/File_Bpg.h"
#include <cmath>
using namespace std;
//---------------------------------------------------------------------------

namespace MediaInfoLib
{

//---------------------------------------------------------------------------
const char* Bpg_ColorSpace(int8u ColorSpace)
{
    switch (ColorSpace)
    {
        case 0:
        case 3:
        case 4: return "YUV";
        case 1: return "RGB";
        case 2: return "YCgCo";
        default: return "";
    }
};

//---------------------------------------------------------------------------
const char* Bpg_colour_primaries(int8u ColorSpace)
{
    switch (ColorSpace)
    {
        case 0: return "BT.601";
        case 3: return "BT.701";
        case 4: return "BT.2020";
        default: return "";
    }
};

//---------------------------------------------------------------------------
const char* Bpg_Pixel_format(int8u PixelFormat)
{
    switch (PixelFormat)
    {
        case 0 : return "Grayscale";
        case 1 :
        case 4 : return "4:2:0";
        case 2 :
        case 5 : return "4:2:2";
        case 3 : return "4:4:4";
        default: return "";
    }

};

//***************************************************************************
// Static stuff
//***************************************************************************

//---------------------------------------------------------------------------
bool File_Bpg::FileHeader_Begin()
{
    //Element_Size
    if (Buffer_Size<4)
        return false; //Must wait for more data

    if (CC4(Buffer) != 0x425047FB) //"BPG"
    {
        Reject("BPG");
        return false;
    }

    //All should be OK...
    return true;
}

//***************************************************************************
// Buffer - Global
//***************************************************************************

//---------------------------------------------------------------------------
void File_Bpg::Read_Buffer_Continue()
{
    //Parsing
    Ztring Version;
    int64u Width, Height;
    int8u  pixelformat, BitsDepth, ColorSpace;
    bool   Alpha1_flag, Alpha2_flag, ReservedZeros, limited_range_flag, ExtensionPresentFlag;
    Element_Begin1("File header");
    Skip_C4(                                                    "Magic"); // File Magic
    BS_Begin();
        Get_S1 (3, pixelformat,                                 "pixel_format"); Param_Info1(Bpg_Pixel_format(pixelformat));
        Get_SB (Alpha1_flag,                                    "Alpha1 Present Flag");
        Get_S1 (4, BitsDepth,                                   "bit_depth_minus_8");

        Get_S1(4, ColorSpace,                                   "color_space"); Param_Info1(Bpg_ColorSpace(ColorSpace)); Param_Info1(Bpg_colour_primaries(ColorSpace));
        Get_SB (ExtensionPresentFlag,                           "Extension Present Flag");
        Get_SB (Alpha2_flag,                                    "Alpha2 Present Flag");
        Get_SB (limited_range_flag,                             "limited_range_flag");
        Get_SB (ReservedZeros,                                  "Reserved");
    BS_End();

    Get_VS(Width,                                               "Picture Width");
    Get_VS(Height,                                              "Picture Height");


    Element_End0();

    FILLING_BEGIN();
        Accept("BPG");

        Stream_Prepare(Stream_Image);
        Fill(Stream_Image, 0, Image_Width, Width);
        Fill(Stream_Image, 0, Image_Height, Height);
        Fill(Stream_Image, 0, Image_Format, __T("BPG"));
        Fill(Stream_Image, 0, Image_ChromaSubsampling, Bpg_Pixel_format(pixelformat));
        Fill(Stream_Image, 0, Image_ColorSpace, Bpg_ColorSpace(ColorSpace));
        Fill(Stream_Image, 0, Image_colour_primaries, Bpg_colour_primaries(ColorSpace));
        Fill(Stream_Image, 0, Image_BitDepth, BitsDepth + 8);
        Fill(Stream_Image, 0, Image_Codec, __T("BPG"));
    FILLING_END();

    Finish("BPG");
}

} //NameSpace

#endif