changed call to WinAPI function, it seems like GetKeyState doesn't support Mouse. GetAsyncKeyState does though
changed the word "line offset" to "line stride"
added "pixel stride" to support various data formats
added minimum & maximum values for single component pixel formats to adjust image rendering
added signed integer single component types
applied VisualStyle
@@ -48,3 +48,12 @@ | ||
48 | 48 | #include "fastdelegate.h" |
49 | 49 | #include "PathUtility.h" |
50 | 50 | |
51 | +#if defined _M_IX86 | |
52 | + #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
53 | +#elif defined _M_IA64 | |
54 | + #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
55 | +#elif defined _M_X64 | |
56 | + #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
57 | +#else | |
58 | + #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
59 | +#endif |
@@ -13,20 +13,23 @@ | ||
13 | 13 | |
14 | 14 | #include "Setting.h" |
15 | 15 | |
16 | -struct ColorFormatTypeMapper : public TwoWayMap<CString, DataSetting2D::ColorFormatType> | |
16 | +struct ColorFormatTypeMapper : public TwoWayMap<CString, ColorFormatType> | |
17 | 17 | { |
18 | 18 | ColorFormatTypeMapper() |
19 | 19 | { |
20 | - map(CString("B5G6R5"), DataSetting2D::ColorFormatType_B5G6R5); | |
21 | - map(CString("B8G8R8"), DataSetting2D::ColorFormatType_B8G8R8); | |
22 | - map(CString("B8G8R8A8"), DataSetting2D::ColorFormatType_B8G8R8A8); | |
23 | -// map(CString("16F"), DataSetting2D::ColorFormatType_16F); | |
24 | - map(CString("32F"), DataSetting2D::ColorFormatType_32F); | |
25 | - map(CString("64F"), DataSetting2D::ColorFormatType_64F); | |
26 | - map(CString("1"), DataSetting2D::ColorFormatType_1); | |
27 | - map(CString("8"), DataSetting2D::ColorFormatType_8); | |
28 | - map(CString("16"), DataSetting2D::ColorFormatType_16); | |
29 | - map(CString("32"), DataSetting2D::ColorFormatType_32); | |
20 | + map(CString("B5G6R5"), ColorFormatType_B5G6R5); | |
21 | + map(CString("B8G8R8"), ColorFormatType_B8G8R8); | |
22 | + map(CString("B8G8R8A8"), ColorFormatType_B8G8R8A8); | |
23 | +// map(CString("F16"), ColorFormatType_F16); | |
24 | + map(CString("F32"), ColorFormatType_F32); | |
25 | + map(CString("F64"), ColorFormatType_F64); | |
26 | + map(CString("1"), ColorFormatType_1); | |
27 | + map(CString("U8"), ColorFormatType_U8); | |
28 | + map(CString("U16"), ColorFormatType_U16); | |
29 | + map(CString("U32"), ColorFormatType_U32); | |
30 | + map(CString("S8"), ColorFormatType_S8); | |
31 | + map(CString("S16"), ColorFormatType_S16); | |
32 | + map(CString("S32"), ColorFormatType_S32); | |
30 | 33 | } |
31 | 34 | }; |
32 | 35 |
@@ -49,12 +52,10 @@ | ||
49 | 52 | { |
50 | 53 | DoDataExchange(); |
51 | 54 | |
52 | - for (int i=DataSetting2D::ColorFormatType_Begin; i<=DataSetting2D::ColorFormatType_End; ++i) { | |
53 | - m_wndCmbColorFormat.AddString(colorFormatTypeMapper[(DataSetting2D::ColorFormatType)i]); | |
55 | + for (int i=ColorFormatType_Begin; i<=ColorFormatType_End; ++i) { | |
56 | + m_wndCmbColorFormat.AddString(colorFormatTypeMapper[(ColorFormatType)i]); | |
54 | 57 | } |
55 | - | |
56 | 58 | m_wndRadAddressedLineFirst.Click(); |
57 | - | |
58 | 59 | return 1; // Let the system set the focus |
59 | 60 | } |
60 | 61 |
@@ -71,6 +72,13 @@ | ||
71 | 72 | return 0; |
72 | 73 | } |
73 | 74 | |
75 | +ColorFormatType CSettingDialog_2D::getColorFormat() | |
76 | +{ | |
77 | + CString str; | |
78 | + m_wndCmbColorFormat.GetLBText(m_wndCmbColorFormat.GetCurSel(), str); | |
79 | + return colorFormatTypeMapper[str]; | |
80 | +} | |
81 | + | |
74 | 82 | void CSettingDialog_2D::RetrieveSetting(boost::shared_ptr<IDataSetting>& pSetting) |
75 | 83 | { |
76 | 84 | DataSetting2D* ps = new DataSetting2D; |
@@ -84,9 +92,14 @@ | ||
84 | 92 | }else if (IsDlgButtonChecked(IDC_RAD_ADDRESSEDLINE_LAST) == BST_CHECKED) { |
85 | 93 | ps->addressedLine = DataSetting2D::AddressedLine_Last; |
86 | 94 | } |
87 | - m_wndEdtLineOffset.GetWindowText(ps->lineOffsetFormula, Count(ps->lineOffsetFormula)); | |
88 | - m_wndCmbColorFormat.GetLBText(m_wndCmbColorFormat.GetCurSel(), str); | |
89 | - ps->colorFormat = colorFormatTypeMapper[str]; | |
95 | + ps->colorFormat = getColorFormat(); | |
96 | + | |
97 | + ps->bUsePixelStride = (IsDlgButtonChecked(IDC_CHK_PIXEL_STRIDE) == BST_CHECKED); | |
98 | + m_wndEdtPixelStride.GetWindowText(ps->pixelStrideFormula, Count(ps->pixelStrideFormula)); | |
99 | + ps->bUseLineStride = (IsDlgButtonChecked(IDC_CHK_LINE_STRIDE) == BST_CHECKED); | |
100 | + m_wndEdtLineStride.GetWindowText(ps->lineStrideFormula, Count(ps->lineStrideFormula)); | |
101 | + m_wndEdtMinimum.GetWindowText(ps->minimumFormula, Count(ps->minimumFormula)); | |
102 | + m_wndEdtMaximum.GetWindowText(ps->maximumFormula, Count(ps->maximumFormula)); | |
90 | 103 | } |
91 | 104 | |
92 | 105 | void CSettingDialog_2D::SetSetting(const DataSetting2D& setting) |
@@ -104,7 +117,55 @@ | ||
104 | 117 | CheckDlgButton(IDC_RAD_ADDRESSEDLINE_LAST, BST_CHECKED); |
105 | 118 | break; |
106 | 119 | } |
107 | - m_wndEdtLineOffset.SetWindowTextW(setting.lineOffsetFormula); | |
108 | 120 | m_wndCmbColorFormat.SelectString(-1, colorFormatTypeMapper[setting.colorFormat]); |
121 | + CheckDlgButton(IDC_CHK_PIXEL_STRIDE, setting.bUsePixelStride); | |
122 | + m_wndEdtPixelStride.EnableWindow(setting.bUsePixelStride); | |
123 | + m_wndEdtPixelStride.SetWindowTextW(setting.pixelStrideFormula); | |
124 | + CheckDlgButton(IDC_CHK_LINE_STRIDE, setting.bUseLineStride); | |
125 | + m_wndEdtLineStride.EnableScrollBar(setting.bUseLineStride); | |
126 | + m_wndEdtLineStride.SetWindowTextW(setting.lineStrideFormula); | |
127 | + m_wndEdtMinimum.SetWindowTextW(setting.minimumFormula); | |
128 | + m_wndEdtMaximum.SetWindowTextW(setting.maximumFormula); | |
129 | + setMinMaxEditsEnability(); | |
109 | 130 | } |
110 | 131 | |
132 | +LRESULT CSettingDialog_2D::OnBnClickedChkPixelStride(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) | |
133 | +{ | |
134 | + GetDlgItem(IDC_EDT_PIXEL_STRIDE).EnableWindow(IsDlgButtonChecked(IDC_CHK_PIXEL_STRIDE) == BST_CHECKED); | |
135 | + return 0; | |
136 | +} | |
137 | + | |
138 | +LRESULT CSettingDialog_2D::OnBnClickedChkLineStride(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) | |
139 | +{ | |
140 | + GetDlgItem(IDC_EDT_LINE_STRIDE).EnableWindow(IsDlgButtonChecked(IDC_CHK_LINE_STRIDE) == BST_CHECKED); | |
141 | + return 0; | |
142 | +} | |
143 | + | |
144 | +LRESULT CSettingDialog_2D::OnBnClickedButton4(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) | |
145 | +{ | |
146 | + return 0; | |
147 | +} | |
148 | + | |
149 | +LRESULT CSettingDialog_2D::OnBnClickedButton16(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) | |
150 | +{ | |
151 | + return 0; | |
152 | +} | |
153 | + | |
154 | +LRESULT CSettingDialog_2D::OnBnClickedButton64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) | |
155 | +{ | |
156 | + return 0; | |
157 | +} | |
158 | + | |
159 | +void CSettingDialog_2D::setMinMaxEditsEnability() | |
160 | +{ | |
161 | + ColorFormatType fmt = getColorFormat(); | |
162 | + BOOL enable = (fmt == ColorFormatType_1) ? false : IsSingleComponent(fmt); | |
163 | + m_wndEdtMinimum.EnableWindow(enable); | |
164 | + m_wndEdtMaximum.EnableWindow(enable); | |
165 | +} | |
166 | + | |
167 | +LRESULT CSettingDialog_2D::OnCbnSelchangeCmbColorformat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) | |
168 | +{ | |
169 | + setMinMaxEditsEnability(); | |
170 | + return 0; | |
171 | +} |
@@ -70,6 +70,29 @@ | ||
70 | 70 | int GetAddressOffset() const { return 0; } |
71 | 71 | }; |
72 | 72 | |
73 | +enum ColorFormatType | |
74 | +{ | |
75 | + ColorFormatType_B5G6R5, | |
76 | + ColorFormatType_B8G8R8, | |
77 | + ColorFormatType_B8G8R8A8, | |
78 | +// ColorFormatType_16F, | |
79 | + ColorFormatType_F32, | |
80 | + ColorFormatType_F64, | |
81 | + ColorFormatType_1, | |
82 | + ColorFormatType_U8, | |
83 | + ColorFormatType_U16, | |
84 | + ColorFormatType_U32, | |
85 | + ColorFormatType_S8, | |
86 | + ColorFormatType_S16, | |
87 | + ColorFormatType_S32, | |
88 | + | |
89 | + ColorFormatType_Begin = 0, | |
90 | + ColorFormatType_End = ColorFormatType_S32, | |
91 | +}; | |
92 | + | |
93 | +size_t GetByteSize(ColorFormatType t); | |
94 | +bool IsSingleComponent(ColorFormatType t); | |
95 | + | |
73 | 96 | struct DataSetting2D : public IDataSetting |
74 | 97 | { |
75 | 98 | enum AddressedLine |
@@ -78,28 +101,16 @@ | ||
78 | 101 | AddressedLine_Last, |
79 | 102 | }; |
80 | 103 | |
81 | - enum ColorFormatType | |
82 | - { | |
83 | - ColorFormatType_B5G6R5, | |
84 | - ColorFormatType_B8G8R8, | |
85 | - ColorFormatType_B8G8R8A8, | |
86 | -// ColorFormatType_16F, | |
87 | - ColorFormatType_32F, | |
88 | - ColorFormatType_64F, | |
89 | - ColorFormatType_1, | |
90 | - ColorFormatType_8, | |
91 | - ColorFormatType_16, | |
92 | - ColorFormatType_32, | |
93 | - | |
94 | - ColorFormatType_Begin = 0, | |
95 | - ColorFormatType_End = ColorFormatType_32, | |
96 | - }; | |
97 | - | |
98 | 104 | TCHAR widthFormula[128]; |
99 | 105 | TCHAR heightFormula[128]; |
100 | - TCHAR lineOffsetFormula[128]; | |
106 | + bool bUsePixelStride; | |
107 | + TCHAR pixelStrideFormula[128]; | |
108 | + bool bUseLineStride; | |
109 | + TCHAR lineStrideFormula[128]; | |
101 | 110 | AddressedLine addressedLine; |
102 | 111 | ColorFormatType colorFormat; |
112 | + TCHAR minimumFormula[128]; | |
113 | + TCHAR maximumFormula[128]; | |
103 | 114 | |
104 | 115 | size_t GetTotalBytes() const; |
105 | 116 | int GetAddressOffset() const; |
@@ -10,7 +10,6 @@ | ||
10 | 10 | #define IDD_DLG_1D 202 |
11 | 11 | #define IDD_DLG_2D 203 |
12 | 12 | #define IDD_DLG_TEXT 204 |
13 | -#define IDD_DLG_MEMORY 207 | |
14 | 13 | #define IDD_DLG_PROCESS 207 |
15 | 14 | #define IDD_DLG_FILE 208 |
16 | 15 | #define IDC_RAD_INT 1000 |
@@ -48,6 +47,7 @@ | ||
48 | 47 | #define IDC_TAB_SRC 1027 |
49 | 48 | #define IDC_EDIT1 1043 |
50 | 49 | #define IDC_EDT_WIDTH 1043 |
50 | +#define IDC_EDT_MINIMUM 1044 | |
51 | 51 | #define IDC_COMBO1 1046 |
52 | 52 | #define IDC_CMB_TARGETTYPE 1046 |
53 | 53 | #define IDC_CMB_TYPE 1046 |
@@ -58,10 +58,13 @@ | ||
58 | 58 | #define IDC_EDT_HEIGHT 1048 |
59 | 59 | #define IDC_EDIT3 1049 |
60 | 60 | #define IDC_EDT_LINEOFFSET 1049 |
61 | +#define IDC_EDT_LINE_STRIDE 1049 | |
61 | 62 | #define IDC_RADIO19 1050 |
62 | 63 | #define IDC_RAD_ADDRESSEDLINE_FIRST 1050 |
63 | 64 | #define IDC_EDT_TARGETADDRESS 1051 |
64 | 65 | #define IDC_EDT_TARGETSTRUCTUREADDRESS 1051 |
66 | +#define IDC_EDT_HEIGHT2 1051 | |
67 | +#define IDC_EDT_MAXIMUM 1051 | |
65 | 68 | #define IDC_BTN_READTARGET 1052 |
66 | 69 | #define IDC_BTN_READTARGETSTRUCTURE 1052 |
67 | 70 | #define IDC_COMBO3 1053 |
@@ -75,6 +78,12 @@ | ||
75 | 78 | #define IDC_BTN_PASTE 1057 |
76 | 79 | #define IDC_EDT_BYTES 1057 |
77 | 80 | #define IDC_EDT_FILEPATH 1058 |
81 | +#define IDC_EDT_PIXEL_STRIDE 1059 | |
82 | +#define IDC_BUTTON_16 1061 | |
83 | +#define IDC_BUTTON_4 1062 | |
84 | +#define IDC_BUTTON_64 1063 | |
85 | +#define IDC_CHK_LINE_STRIDE 1064 | |
86 | +#define IDC_CHK_PIXEL_STRIDE 1065 | |
78 | 87 | #define ID_UPDATE 32772 |
79 | 88 | #define ID_VIEW_ALWAYSONTOP 32776 |
80 | 89 | #define ID_ZOOM 32777 |
@@ -92,7 +101,7 @@ | ||
92 | 101 | #ifndef APSTUDIO_READONLY_SYMBOLS |
93 | 102 | #define _APS_NEXT_RESOURCE_VALUE 207 |
94 | 103 | #define _APS_NEXT_COMMAND_VALUE 32789 |
95 | -#define _APS_NEXT_CONTROL_VALUE 1059 | |
104 | +#define _APS_NEXT_CONTROL_VALUE 1065 | |
96 | 105 | #define _APS_NEXT_SYMED_VALUE 101 |
97 | 106 | #endif |
98 | 107 | #endif |
@@ -23,7 +23,11 @@ | ||
23 | 23 | std::string s = ConvertToMString(formula); |
24 | 24 | parser.SetExpr(s.c_str()); |
25 | 25 | } |
26 | - return parser.Eval(); | |
26 | + try { | |
27 | + return parser.Eval(); | |
28 | + }catch (...) { | |
29 | + return 0; | |
30 | + } | |
27 | 31 | } |
28 | 32 | |
29 | 33 | bool ReadProcessData(HANDLE hProcess, LPCVOID pTarget, void* buffer, size_t fetchSize) |
@@ -19,11 +19,6 @@ | ||
19 | 19 | typedef gl::fixed<32, unsigned int> Fixed32; |
20 | 20 | typedef gl::Color4< gl::ColorBGRA<Fixed8> > ColorB8G8R8A8; |
21 | 21 | typedef gl::Color3< gl::ColorBGR<Fixed8> > ColorB8G8R8; |
22 | -typedef gl::Color1<float> Color32F; | |
23 | -typedef gl::Color1<double> Color64F; | |
24 | -typedef gl::Color1<Fixed8> ColorFixed8; | |
25 | -typedef gl::Color1<Fixed16> ColorFixed16; | |
26 | -typedef gl::Color1<Fixed32> ColorFixed32; | |
27 | 22 | |
28 | 23 | #define STATIC_ASSERT(expr) { char dummy[(expr) ? 1 : 0]; } |
29 | 24 |
@@ -45,6 +40,7 @@ | ||
45 | 40 | template <typename T> |
46 | 41 | ColorB8G8R8A8 convert(ColorB5G6R5 from) |
47 | 42 | { |
43 | + STATIC_ASSERT(sizeof(ColorB5G6R5) == 2); | |
48 | 44 | ColorB8G8R8A8 to; |
49 | 45 | to.r.value = from.r << 3; |
50 | 46 | to.g.value = from.g << 2; |
@@ -52,7 +48,16 @@ | ||
52 | 48 | return to; |
53 | 49 | } |
54 | 50 | |
55 | -gl::ColorConverter<ColorB8G8R8A8> colorConverter; | |
51 | +template <typename T> | |
52 | +ColorB8G8R8A8 convert(double from) | |
53 | +{ | |
54 | + ColorB8G8R8A8 to; | |
55 | + uint8_t v = (from * 255.0 + 0.5); | |
56 | + to.r.value = v; | |
57 | + to.g.value = v; | |
58 | + to.b.value = v; | |
59 | + return to; | |
60 | +} | |
56 | 61 | |
57 | 62 | #include "MathUtil.h" |
58 | 63 |
@@ -72,7 +77,14 @@ | ||
72 | 77 | |
73 | 78 | bool CDataView::isMouseClicked() |
74 | 79 | { |
75 | - return GetCapture() == m_hWnd && GetKeyState(GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON) < 0; | |
80 | + HWND hWndCap = GetCapture(); | |
81 | + if (hWndCap == m_hWnd) { | |
82 | + const int chkBtn = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; | |
83 | + SHORT state = GetAsyncKeyState(chkBtn); | |
84 | + bool bClicked = state < 0; | |
85 | + return bClicked; | |
86 | + } | |
87 | + return false; | |
76 | 88 | } |
77 | 89 | |
78 | 90 | CDataView::CDataView() |
@@ -213,51 +225,40 @@ | ||
213 | 225 | int height = EvalFormula(setting.heightFormula); |
214 | 226 | if (height <= 0) |
215 | 227 | return; |
216 | - int lineOffset = EvalFormula(setting.lineOffsetFormula); | |
217 | - if (lineOffset == 0) | |
218 | - return; | |
219 | - | |
228 | + | |
229 | + int pixelStride; | |
230 | + size_t colorFormatPixelSize = GetByteSize(setting.colorFormat); | |
231 | + if (setting.bUsePixelStride) { | |
232 | + pixelStride = EvalFormula(setting.pixelStrideFormula); | |
233 | + if (pixelStride <= 0 || pixelStride < colorFormatPixelSize) { | |
234 | + return; | |
235 | + } | |
236 | + }else { | |
237 | + pixelStride = colorFormatPixelSize; | |
238 | + } | |
239 | + | |
220 | 240 | size_t lineBytes = 0; |
221 | - switch (setting.colorFormat) { | |
222 | - case DataSetting2D::ColorFormatType_B5G6R5: | |
223 | - lineBytes = width * 2; | |
224 | - break; | |
225 | - case DataSetting2D::ColorFormatType_B8G8R8: | |
226 | - lineBytes = width * 3; | |
227 | - break; | |
228 | - case DataSetting2D::ColorFormatType_B8G8R8A8: | |
229 | - case DataSetting2D::ColorFormatType_32F: | |
230 | - lineBytes = width * 4; | |
231 | - break; | |
232 | - case DataSetting2D::ColorFormatType_64F: | |
233 | - lineBytes = width * 8; | |
234 | - break; | |
235 | - case DataSetting2D::ColorFormatType_1: | |
241 | + if (setting.colorFormat == ColorFormatType_1) { | |
236 | 242 | lineBytes = width / 8 + ((width % 8) ? 1 : 0); |
237 | - break; | |
238 | - case DataSetting2D::ColorFormatType_8: | |
239 | - lineBytes = width; | |
240 | - break; | |
241 | - case DataSetting2D::ColorFormatType_16: | |
242 | - lineBytes = width * 2; | |
243 | - break; | |
244 | - case DataSetting2D::ColorFormatType_32: | |
245 | - lineBytes = width * 4; | |
246 | - break; | |
247 | - default: | |
248 | - return; | |
243 | + }else { | |
244 | + lineBytes = width * pixelStride; | |
249 | 245 | } |
250 | - if (abs(lineOffset) < lineBytes) | |
246 | + | |
247 | + int lineStride = setting.bUseLineStride ? EvalFormula(setting.lineStrideFormula) : lineBytes; | |
248 | + if (lineStride == 0) | |
251 | 249 | return; |
252 | - if (abs(lineOffset)*height != dataBytes) | |
250 | + | |
251 | + if (abs(lineStride) < lineBytes) | |
253 | 252 | return; |
253 | + if (abs(lineStride)*height != dataBytes) | |
254 | + return; | |
254 | 255 | |
255 | 256 | const char* pFirstLine = NULL; |
256 | 257 | switch (setting.addressedLine) { |
257 | 258 | case DataSetting2D::AddressedLine_Last: |
258 | 259 | case DataSetting2D::AddressedLine_First: |
259 | - if (lineOffset < 0) { | |
260 | - pFirstLine = pData + -lineOffset * (height - 1); | |
260 | + if (lineStride < 0) { | |
261 | + pFirstLine = pData + -lineStride * (int)(height - 1); | |
261 | 262 | }else { |
262 | 263 | pFirstLine = pData; |
263 | 264 | } |
@@ -277,38 +278,52 @@ | ||
277 | 278 | } |
278 | 279 | m_imgWidth = width; |
279 | 280 | m_imgHeight = height; |
281 | + gl::Buffer2D<ColorB8G8R8A8>& img = *(gl::Buffer2D<ColorB8G8R8A8>*)m_pImage; | |
280 | 282 | |
281 | - STATIC_ASSERT(sizeof(ColorB5G6R5) == 2); | |
282 | - | |
283 | - gl::Buffer2D<ColorB8G8R8A8>& img = *(gl::Buffer2D<ColorB8G8R8A8>*)m_pImage; | |
284 | - switch (setting.colorFormat) { | |
285 | - case DataSetting2D::ColorFormatType_B5G6R5: | |
286 | - gl::BitBlockTransfer(gl::Buffer2D<ColorB5G6R5>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
287 | - break; | |
288 | - case DataSetting2D::ColorFormatType_B8G8R8: | |
289 | - gl::BitBlockTransfer(gl::Buffer2D<ColorB8G8R8>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
290 | - break; | |
291 | - case DataSetting2D::ColorFormatType_B8G8R8A8: | |
292 | - gl::BitBlockTransfer(gl::Buffer2D<ColorB8G8R8A8>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
293 | - break; | |
294 | - case DataSetting2D::ColorFormatType_32F: | |
295 | - gl::BitBlockTransfer(gl::Buffer2D<Color32F>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
296 | - break; | |
297 | - case DataSetting2D::ColorFormatType_64F: | |
298 | - gl::BitBlockTransfer(gl::Buffer2D<Color64F>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
299 | - break; | |
300 | - case DataSetting2D::ColorFormatType_1: | |
301 | - gl::BitBlockTransfer(gl::Buffer2D<bool>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
302 | - break; | |
303 | - case DataSetting2D::ColorFormatType_8: | |
304 | - gl::BitBlockTransfer(gl::Buffer2D<ColorFixed8>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
305 | - break; | |
306 | - case DataSetting2D::ColorFormatType_16: | |
307 | - gl::BitBlockTransfer(gl::Buffer2D<ColorFixed16>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
308 | - break; | |
309 | - case DataSetting2D::ColorFormatType_32: | |
310 | - gl::BitBlockTransfer(gl::Buffer2D<ColorFixed32>(width, height, lineOffset, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
311 | - break; | |
283 | + if (setting.colorFormat != ColorFormatType_1 && IsSingleComponent(setting.colorFormat)) { | |
284 | + gl::ColorConverterMinMax<ColorB8G8R8A8> colorConverter(EvalFormula(setting.minimumFormula), EvalFormula(setting.maximumFormula)); | |
285 | + switch (setting.colorFormat) { | |
286 | + case ColorFormatType_F32: | |
287 | + gl::BitBlockTransfer(gl::Buffer2D<float>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
288 | + break; | |
289 | + case ColorFormatType_F64: | |
290 | + gl::BitBlockTransfer(gl::Buffer2D<double>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
291 | + break; | |
292 | + case ColorFormatType_U8: | |
293 | + gl::BitBlockTransfer(gl::Buffer2D<uint8_t>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
294 | + break; | |
295 | + case ColorFormatType_U16: | |
296 | + gl::BitBlockTransfer(gl::Buffer2D<uint16_t>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
297 | + break; | |
298 | + case ColorFormatType_U32: | |
299 | + gl::BitBlockTransfer(gl::Buffer2D<uint32_t>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
300 | + break; | |
301 | + case ColorFormatType_S8: | |
302 | + gl::BitBlockTransfer(gl::Buffer2D<int8_t>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
303 | + break; | |
304 | + case ColorFormatType_S16: | |
305 | + gl::BitBlockTransfer(gl::Buffer2D<int16_t>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
306 | + break; | |
307 | + case ColorFormatType_S32: | |
308 | + gl::BitBlockTransfer(gl::Buffer2D<int32_t>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
309 | + break; | |
310 | + } | |
311 | + }else { | |
312 | + gl::ColorConverter<ColorB8G8R8A8> colorConverter; | |
313 | + switch (setting.colorFormat) { | |
314 | + case ColorFormatType_1: | |
315 | + gl::BitBlockTransfer(gl::Buffer2D<bool>(width, height, lineStride, (void*)pFirstLine), img, 0,0,0,0,width,height, colorConverter); | |
316 | + break; | |
317 | + case ColorFormatType_B5G6R5: | |
318 | + gl::BitBlockTransfer(gl::Buffer2D<ColorB5G6R5>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
319 | + break; | |
320 | + case ColorFormatType_B8G8R8: | |
321 | + gl::BitBlockTransfer(gl::Buffer2D<ColorB8G8R8>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
322 | + break; | |
323 | + case ColorFormatType_B8G8R8A8: | |
324 | + gl::BitBlockTransfer(gl::Buffer2D<ColorB8G8R8A8>(width, height, lineStride, (void*)pFirstLine), pixelStride, img, 0,0,0,0,width,height, colorConverter); | |
325 | + break; | |
326 | + } | |
312 | 327 | } |
313 | 328 | |
314 | 329 | } |
@@ -563,7 +578,7 @@ | ||
563 | 578 | static |
564 | 579 | bool fetchData( |
565 | 580 | const boost::shared_ptr<SourceSetting>& pSrcSetting, |
566 | - size_t dataLength, int dataAddressOffset, | |
581 | + size_t dataLength, | |
567 | 582 | std::vector<char>& data |
568 | 583 | ) |
569 | 584 | { |
@@ -574,7 +589,6 @@ | ||
574 | 589 | |
575 | 590 | ptrdiff_t addressBase = AddressHexStrToNum(pSrcSetting->addressBaseFormula); |
576 | 591 | ptrdiff_t addressOffset = EvalFormula(pSrcSetting->addressOffsetFormula) * pSrcSetting->addressOffsetMultiplier; |
577 | - addressOffset += dataAddressOffset; | |
578 | 592 | ptrdiff_t address = addressBase + addressOffset; |
579 | 593 | |
580 | 594 | const type_info& ti = typeid(*pSrcSetting); |
@@ -610,7 +624,6 @@ | ||
610 | 624 | fetchData( |
611 | 625 | pSrcSetting, |
612 | 626 | pDataSetting->GetTotalBytes(), |
613 | - pDataSetting->GetAddressOffset(), | |
614 | 627 | m_data |
615 | 628 | ) |
616 | 629 | ) { |
@@ -40,7 +40,8 @@ | ||
40 | 40 | // TODO: need to fix. runs too slow... |
41 | 41 | template <typename ConverterT, typename SrcColorT, typename TargetColorT> |
42 | 42 | void BitBlockTransfer( |
43 | - const Buffer2D<SrcColorT>& src, Buffer2D<TargetColorT>& target, | |
43 | + const Buffer2D<SrcColorT>& src, size_t pixelStride, | |
44 | + Buffer2D<TargetColorT>& target, | |
44 | 45 | int srcX, int srcY, int targetX, int targetY, |
45 | 46 | size_t width, size_t height, |
46 | 47 | ConverterT& converter |
@@ -104,7 +105,8 @@ | ||
104 | 105 | pTarget2 = pTarget; |
105 | 106 | for (size_t x=0; x<width; ++x) { |
106 | 107 | *pTarget2 = converter(*pSrc2); |
107 | - ++pSrc2; | |
108 | + pSrc2 = (const SrcColorT*) (((const char*)pSrc2)+pixelStride); | |
109 | +// ++pSrc2; | |
108 | 110 | ++pTarget2; |
109 | 111 | } |
110 | 112 | OffsetPtr(pSrc, srcLineOffset); |
@@ -47,6 +47,29 @@ | ||
47 | 47 | |
48 | 48 | }; |
49 | 49 | |
50 | +template <typename TargetColorT> | |
51 | +struct ColorConverterMinMax | |
52 | +{ | |
53 | + ColorConverterMinMax(double minimum, double maximum) | |
54 | + : | |
55 | + minimum(minimum), | |
56 | + maximum(maximum), | |
57 | + invRange(1.0 / (maximum - minimum)) | |
58 | + { | |
59 | + } | |
60 | + __forceinline TargetColorT operator () (double from) | |
61 | + { | |
62 | + double nv = (from - minimum) * invRange; | |
63 | + nv = max(0.0, nv); | |
64 | + nv = min(1.0, nv); | |
65 | + return convert<TargetColorT>(nv); | |
66 | + } | |
67 | + | |
68 | + double minimum; | |
69 | + double maximum; | |
70 | + double invRange; | |
71 | +}; | |
72 | + | |
50 | 73 | template <typename NumericT, typename ValueT, size_t tableSize> |
51 | 74 | struct TableLookupHelper |
52 | 75 | { |
@@ -66,23 +66,27 @@ | ||
66 | 66 | |
67 | 67 | size_t DataSetting2D::GetTotalBytes() const |
68 | 68 | { |
69 | + int width = abs(EvalFormula(widthFormula)); | |
69 | 70 | int height = abs(EvalFormula(heightFormula)); |
70 | - int lineOffset = EvalFormula(lineOffsetFormula); | |
71 | - return height * abs(lineOffset); | |
71 | + int lineStride = bUseLineStride ? EvalFormula(lineStrideFormula) : (width * GetByteSize(colorFormat)); | |
72 | + return height * abs(lineStride); | |
72 | 73 | } |
73 | 74 | |
74 | 75 | int DataSetting2D::GetAddressOffset() const |
75 | 76 | { |
76 | - int lineOffset = EvalFormula(lineOffsetFormula); | |
77 | + if (!bUseLineStride) { | |
78 | + return 0; | |
79 | + } | |
80 | + int lineStride = EvalFormula(lineStrideFormula); | |
77 | 81 | int height = EvalFormula(heightFormula); |
78 | 82 | if (addressedLine == AddressedLine_First) { |
79 | - if (lineOffset < 0) { | |
80 | - return lineOffset * (height - 1); | |
83 | + if (lineStride < 0) { | |
84 | + return lineStride * (height - 1); | |
81 | 85 | }else { |
82 | 86 | return 0; |
83 | 87 | } |
84 | 88 | }else { |
85 | - return -1 * lineOffset * (height - 1); | |
89 | + return -1 * lineStride * (height - 1); | |
86 | 90 | } |
87 | 91 | } |
88 | 92 |
@@ -107,3 +111,53 @@ | ||
107 | 111 | addressOffsetMultiplier = 1; |
108 | 112 | } |
109 | 113 | |
114 | +size_t GetByteSize(ColorFormatType t) | |
115 | +{ | |
116 | + switch (t) { | |
117 | + case ColorFormatType_B5G6R5: | |
118 | + return 2; | |
119 | + case ColorFormatType_B8G8R8: | |
120 | + return 3; | |
121 | + case ColorFormatType_B8G8R8A8: | |
122 | + case ColorFormatType_F32: | |
123 | + return 4; | |
124 | + case ColorFormatType_F64: | |
125 | + return 8; | |
126 | + case ColorFormatType_1: | |
127 | + return 0; | |
128 | + break; | |
129 | + case ColorFormatType_U8: | |
130 | + case ColorFormatType_S8: | |
131 | + return 1; | |
132 | + case ColorFormatType_U16: | |
133 | + case ColorFormatType_S16: | |
134 | + return 2; | |
135 | + case ColorFormatType_U32: | |
136 | + case ColorFormatType_S32: | |
137 | + return 4; | |
138 | + default: | |
139 | + return 0; | |
140 | + } | |
141 | +} | |
142 | + | |
143 | +bool IsSingleComponent(ColorFormatType t) | |
144 | +{ | |
145 | + switch (t) { | |
146 | + case ColorFormatType_B5G6R5: | |
147 | + case ColorFormatType_B8G8R8: | |
148 | + case ColorFormatType_B8G8R8A8: | |
149 | + return false; | |
150 | + case ColorFormatType_F32: | |
151 | + case ColorFormatType_F64: | |
152 | + case ColorFormatType_1: | |
153 | + case ColorFormatType_U8: | |
154 | + case ColorFormatType_U16: | |
155 | + case ColorFormatType_U32: | |
156 | + case ColorFormatType_S8: | |
157 | + case ColorFormatType_S16: | |
158 | + case ColorFormatType_S32: | |
159 | + return true; | |
160 | + default: | |
161 | + return false; | |
162 | + } | |
163 | +} | |
\ No newline at end of file |
@@ -20,10 +20,20 @@ | ||
20 | 20 | void RetrieveSetting(boost::shared_ptr<IDataSetting>& pSetting); |
21 | 21 | void SetSetting(const DataSetting2D& setting); |
22 | 22 | |
23 | +private: | |
24 | + enum ColorFormatType getColorFormat(); | |
25 | + void setMinMaxEditsEnability(); | |
26 | + | |
23 | 27 | BEGIN_MSG_MAP(CSettingDialog_2D) |
24 | 28 | MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) |
25 | 29 | COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK) |
26 | 30 | COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel) |
31 | + COMMAND_HANDLER(IDC_BUTTON_4, BN_CLICKED, OnBnClickedButton4) | |
32 | + COMMAND_HANDLER(IDC_BUTTON_16, BN_CLICKED, OnBnClickedButton16) | |
33 | + COMMAND_HANDLER(IDC_BUTTON_64, BN_CLICKED, OnBnClickedButton64) | |
34 | + COMMAND_HANDLER(IDC_CHK_PIXEL_STRIDE, BN_CLICKED, OnBnClickedChkPixelStride) | |
35 | + COMMAND_HANDLER(IDC_CHK_LINE_STRIDE, BN_CLICKED, OnBnClickedChkLineStride) | |
36 | + COMMAND_HANDLER(IDC_CMB_COLORFORMAT, CBN_SELCHANGE, OnCbnSelchangeCmbColorformat) | |
27 | 37 | END_MSG_MAP() |
28 | 38 | |
29 | 39 | BEGIN_DDX_MAP(CSettingDialog_2D) |
@@ -31,17 +41,22 @@ | ||
31 | 41 | DDX_CONTROL_HANDLE(IDC_EDT_HEIGHT, m_wndEdtHeight) |
32 | 42 | DDX_CONTROL_HANDLE(IDC_RAD_ADDRESSEDLINE_FIRST, m_wndRadAddressedLineFirst) |
33 | 43 | DDX_CONTROL_HANDLE(IDC_RAD_ADDRESSEDLINE_LAST, m_wndRadAddressedLineLast) |
34 | - DDX_CONTROL_HANDLE(IDC_EDT_LINEOFFSET, m_wndEdtLineOffset) | |
35 | 44 | DDX_CONTROL_HANDLE(IDC_CMB_COLORFORMAT, m_wndCmbColorFormat) |
45 | + DDX_CONTROL_HANDLE(IDC_EDT_PIXEL_STRIDE, m_wndEdtPixelStride) | |
46 | + DDX_CONTROL_HANDLE(IDC_EDT_LINE_STRIDE, m_wndEdtLineStride) | |
47 | + DDX_CONTROL_HANDLE(IDC_EDT_MINIMUM, m_wndEdtMinimum) | |
48 | + DDX_CONTROL_HANDLE(IDC_EDT_MAXIMUM, m_wndEdtMaximum) | |
36 | 49 | END_DDX_MAP() |
37 | 50 | |
38 | -private: | |
39 | 51 | CEdit m_wndEdtWidth; |
40 | 52 | CEdit m_wndEdtHeight; |
41 | 53 | CButton m_wndRadAddressedLineFirst; |
42 | 54 | CButton m_wndRadAddressedLineLast; |
43 | - CEdit m_wndEdtLineOffset; | |
44 | 55 | CComboBox m_wndCmbColorFormat; |
56 | + CEdit m_wndEdtPixelStride; | |
57 | + CEdit m_wndEdtLineStride; | |
58 | + CEdit m_wndEdtMinimum; | |
59 | + CEdit m_wndEdtMaximum; | |
45 | 60 | |
46 | 61 | // Handler prototypes: |
47 | 62 | // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); |
@@ -50,7 +65,12 @@ | ||
50 | 65 | LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); |
51 | 66 | LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); |
52 | 67 | LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); |
53 | - | |
68 | + LRESULT OnBnClickedChkPixelStride(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); | |
69 | + LRESULT OnBnClickedChkLineStride(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); | |
70 | + LRESULT OnBnClickedButton4(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); | |
71 | + LRESULT OnBnClickedButton16(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); | |
72 | + LRESULT OnBnClickedButton64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); | |
73 | + LRESULT OnCbnSelchangeCmbColorformat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); | |
54 | 74 | }; |
55 | 75 | |
56 | 76 |