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
// FileBuffer.cpp: implementation of the CFileBuffer class.
//
//////////////////////////////////////////////////////////////////////
 
#include "stdafx.h"
#include "InspectionBuffer.h"
 
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
void CFileBuffer::FillBuffer(CFile &file, int x, int y, int oWidth, int oHeight)
{
    int iData= sizeof(BITMAPFILEHEADER)+ sizeof(BITMAPINFOHEADER)+ 1024;
    for(int i= 0; i< m_Height; i++)
    {
//        fseek(pFile, iData+ x+ (y+ i)*oWidth, SEEK_SET);
//        fread(m_pData+ i*GetDataWidth(), width, 1, pFile);
        file.Seek(iData+ x+ (y+ i)*oWidth, SEEK_SET);
        file.Read(m_pData+ i*GetDataWidth(), m_Width);
    }
}
 
void CFileBuffer::FillBufferReverse(CFile &file, int x, int y, int oWidth, int oHeight)
{
    int iData= sizeof(BITMAPFILEHEADER)+ sizeof(BITMAPINFOHEADER)+ 1024;
 
    int nNewY = oHeight - y - m_Height;
    for(int i= m_Height-1; i>=0 ; i--)
    {
        file.Seek(iData+ x+ (nNewY+ i)*oWidth, SEEK_SET);
        file.Read(m_pData+ (m_Height-1-i)*GetDataWidth(), m_Width);
    }
}
 
void CFileBuffer::FillBufferFromTwoFile(CFile &file1, CFile &file2, int x, int y, int FirstHeight, int SecondHeight, int oWidth, int oHeight)
{
    int iData= sizeof(BITMAPFILEHEADER)+ sizeof(BITMAPINFOHEADER)+ 1024;
    for(int i= 0; i< FirstHeight; i++)
    {
        file1.Seek(iData+ x+ (y+ i)*oWidth, SEEK_SET);
        file1.Read(m_pData+ i*GetDataWidth(), m_Width);
    }
 
    if(SecondHeight>0)
    {
        for(int i= 0; i< SecondHeight; i++)
        {
            file2.Seek(iData+ x+ i*oWidth, SEEK_SET);
            file2.Read(m_pData+ (FirstHeight+i)*GetDataWidth(), m_Width);
        }
    }
}
 
 
void CFileBuffer::SaveBufferToTwoFile(CFile &file1, CFile &file2, int x, int y, int FirstHeight, int SecondHeight, int oWidth, int oHeight)
{
    int iData= sizeof(BITMAPFILEHEADER)+ sizeof(BITMAPINFOHEADER)+ 1024;
    for(int i= 0; i< FirstHeight; i++)
    {
        file1.Seek(iData+ x+ (y+ i)*oWidth, SEEK_SET);
        file1.Write(m_pData+ i*GetDataWidth(), m_Width);
    }
 
    if(SecondHeight>0)
    {
        for(int i= 0; i< SecondHeight; i++)
        {
            file2.Seek(iData+ x+ i*oWidth, SEEK_SET);
            file2.Write(m_pData+ (FirstHeight+i)*GetDataWidth(), m_Width);
        }
    }
}
 
// miniont, 2008-09-04, begin
BITMAPINFOHEADER  CFileBuffer::GetBitmapInfoHeader(CFile &file)
{
    BITMAPINFOHEADER infoHeader;
 
    file.Seek(sizeof(BITMAPFILEHEADER), SEEK_SET);
    file.Read(&infoHeader, sizeof(BITMAPINFOHEADER));
 
    return infoHeader;
}
 
const int CFileBuffer::GetContentWidth(CFile &file)
{
    BITMAPINFOHEADER infoHeader;
    
    file.Seek(sizeof(BITMAPFILEHEADER), SEEK_SET);
    file.Read(&infoHeader, sizeof(BITMAPINFOHEADER));
    
    return infoHeader.biWidth;
}
 
 
const int CFileBuffer::GetContentHeight(CFile &file)
{
    BITMAPINFOHEADER infoHeader;
 
    file.Seek(sizeof(BITMAPFILEHEADER), SEEK_SET);
    file.Read(&infoHeader, sizeof(BITMAPINFOHEADER));
 
    return infoHeader.biHeight;
}
// miniont, 2008-09-04, end