Repository navigation
Expand file tree
/
Copy pathFileAcq.cpp
More file actions
88 lines (74 loc) · 2.68 KB
/
Copy pathFileAcq.cpp
File metadata and controls
88 lines (74 loc) · 2.68 KB
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
/****************************************************************************
* Operator Console - an extensible user interface for the Imatest IT *
* library *
* Copyright (C) 2013 Imatest LLC. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/
#include "FileAcq.h"
FileAcq::FileAcq(void)
{
}
FileAcq::~FileAcq(void)
{
}
///
/// Copies *filepathname to m_filename
///
void FileAcq::Init(const char *filepathname)
{
m_filename = filepathname;
}
///
/// Loads a file first into the CImage object m_image, and then into m_buf inherited from class ImageAcquisition if allocation is successful.
/// @return Returns TRUE if m_buf is successfully allocated, FALSE otherwise
///
bool FileAcq::Open()
{
bool success = false;
int width, height, bytesPerPixel;
HRESULT result;
result = m_image.Load(m_filename);
if (result == S_OK)
{
bytesPerPixel = m_image.GetBPP() / 8;
width = m_image.GetWidth();
height = m_image.GetHeight();
success = ImageAcquisition::Init(width, height, bytesPerPixel);
if (success)
{
// copy the pixels into m_buf:
// create a memory drawing context
//
HDC hdc = m_image.GetDC();
HBITMAP hbitmap = (HBITMAP)m_image;//GetCurrentObject(hdc, OBJ_BITMAP);
BITMAPINFO info;
memset(&info, 0, sizeof(info));
info.bmiHeader.biSize = sizeof(info.bmiHeader);
info.bmiHeader.biWidth = m_width;
info.bmiHeader.biHeight = -m_height; // a negative value means top-down instead of bottom-up
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = 32;
info.bmiHeader.biCompression = BI_RGB;
info.bmiHeader.biSizeImage = 0;
info.bmiHeader.biXPelsPerMeter = 1;
info.bmiHeader.biYPelsPerMeter = 1;
info.bmiHeader.biClrUsed = 0;
info.bmiHeader.biClrImportant = 0;
GetDIBits(hdc, hbitmap, 0, m_height, m_buf, &info, DIB_RGB_COLORS);
m_image.ReleaseDC();
}
}
return success;
}