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

File_Pcx.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: 29622e645576356f6da2bd11278fd492e3c73ca5 (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
/*  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.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Contributor: Lionel Duchateau, kurtnoise@free.fr
//
// From http://courses.engr.illinois.edu/ece390/books/labmanual/graphics-pcx.html
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

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

//---------------------------------------------------------------------------
#if defined(MEDIAINFO_PCX_YES)
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Image/File_Pcx.h"
//---------------------------------------------------------------------------

namespace MediaInfoLib
{

//***************************************************************************
// Infos
//***************************************************************************

//---------------------------------------------------------------------------
const char* Pcx_VersionInfo(int16u Version)
{
    switch(Version)
    {
        case 0 : return "Paintbrush v2.5";
        case 2 : return "Paintbrush v2.8 with palette information";
        case 3 : return "Paintbrush v2.8 without palette information";
        case 4 : return "Paintbrush/Windows";
        case 5 : return "Paintbrush v3.0+";
        default: return "";
    }
}

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

//---------------------------------------------------------------------------
bool File_Pcx::FileHeader_Begin()
{
    //Element_Size
    if (Buffer_Size<130) //Size of the header
        return false; //Must wait for more data

    if (Buffer[0]!=0x0A
     || Buffer[1]>0x05
     || Buffer[2]!=0x01
     || !(Buffer[3]==1 || Buffer[3]==4 || Buffer[3]==8 || Buffer[3]==24))
    {
        Reject("PCX");
        return false;
    }

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

//***************************************************************************
// File Header Information
//***************************************************************************

//---------------------------------------------------------------------------
void File_Pcx::Read_Buffer_Continue()
{
    //Parsing
    int16u XMin, YMin, XMax, YMax, HorDPI, VertDPI, BytesPerLine, PaletteType, HScrSize, VScrSize;
    int8u Manufacturer, Version, EncodingScheme, BitsPerPixel, ColorPlanes;

    Get_L1 (Manufacturer,                                       "Manufacturer");
    Get_L1 (Version,                                            "Version"); // 0,2,3,4,5
    Get_L1 (EncodingScheme,                                     "EncodingScheme"); // RLE=1
    Get_L1 (BitsPerPixel,                                       "Bits Per Pixel"); // 1,4,8,24
    Get_L2 (XMin,                                               "Left margin of image");
    Get_L2 (YMin,                                               "Upper margin of image");
    Get_L2 (XMax,                                               "Right margin of image");
    Get_L2 (YMax,                                               "Lower margin of image");
    Get_L2 (HorDPI,                                             "Horizontal Resolution");
    Get_L2 (VertDPI,                                            "Vertical Resolution");
    Skip_XX(48,                                                 "Palette");
    Skip_L1(                                                    "Reserved");
    Get_L1 (ColorPlanes,                                        "ColorPlanes");
    Get_L2 (BytesPerLine,                                       "BytesPerLine");
    Get_L2 (PaletteType,                                        "PaletteType");
    Get_L2 (HScrSize,                                           "Horizontal Screen Size");
    Get_L2 (VScrSize,                                           "Vertical Screen Size");
    Skip_XX(56,                                                 "Filler");


    FILLING_BEGIN();
        //Integrity tests
        if (XMax<=XMin
         || YMax<=YMin
         || BytesPerLine<XMax-XMin)
        {
            Reject("PCX");
            return;
        }

        Accept("PCX");
        Stream_Prepare(Stream_Image);
        Fill(Stream_Image, 0, Image_Format, "PCX");
        Fill(Stream_Image, 0, Image_Format_Version, Pcx_VersionInfo(Version));
        Fill(Stream_Image, 0, Image_Width, XMax-XMin);
        Fill(Stream_Image, 0, Image_Height, YMax-YMin);
        Fill(Stream_Image, 0, Image_BitDepth, BitsPerPixel);
        Fill(Stream_Image, 0, "DPI", Ztring::ToZtring(VertDPI) + __T(" x ") + Ztring::ToZtring(HorDPI));
        Finish("PCX");
    FILLING_END();
}


} //NameSpace

#endif