JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
DxMGRView.cpp
Go to the documentation of this file.
1//
2// DxMGRView.cpp : インプリメンテーション ファイル
3//
4
5#include "MFCBase.h"
6#include "DxMGRView.h"
7#include "RwGRDoc.h"
8
9
10#ifdef _DEBUG
11#define new DEBUG_NEW
12#undef THIS_FILE
13static char THIS_FILE[] = __FILE__;
14#endif
15
16
17using namespace jbxl;
18using namespace jbxwl;
19
20
21
23// CDxMGRView
24
25IMPLEMENT_DYNCREATE(CDxMGRView, CExView)
26
27
29{
30 cnstXYRate = true;
31
32 renderRect.left = 0;
33 renderRect.top = 0;
34 renderRect.right = 0;
35 renderRect.bottom = 0;
36
37 cMax = VIEW_8_MAX;
38 cMin = 0;
39
40 vSBntch = 1; // スクロールピッチ
41}
42
43
44//
49
50
51BEGIN_MESSAGE_MAP(CDxMGRView, CDxBaseView)
52 //{{AFX_MSG_MAP(CDxMGRView)
53 //}}AFX_MSG_MAP
54END_MESSAGE_MAP()
55
56
57
58
59// CDxMGRView 描画
60/*
61void CDxMGRView::OnDraw(CDC* pDC)
62{
63 CDocument* pDoc = GetDocument();
64 // TODO: この位置に描画用のコードを追加してください
65}
66*/
67
68
69
70
71// CDxMGRView 診断
72
73#ifdef _DEBUG
78
79//
80void CDxMGRView::Dump(CDumpContext& dc) const
81{
83}
84#endif //_DEBUG
85
86
87
89// CDxMGRView メッセージ ハンドラ
90
91// 現在は カラーについては Planeデータ専用
92// Planeデータで無い場合のカラー処理は処理はまだ実装していない.
93
94//
95// pDoc->cmnHead, pDoc->vMax, pDoc->vMin, pDoc->cMax, pDoc->cMin が必要.
96//
98{
100 if (isNull(cmnHead.grptr)) return;
101
111 //
112 xsize = cmnHead.xsize;
113 ysize = cmnHead.ysize;
114
115 // 表示モード
119 if (viewMode==VIEW_ZDIR) { // Z
120 xsize = cmnHead.xsize;
121 ysize = cmnHead.ysize;
122 zsize = 1;
123 }
124 else {
126 mesg.LoadString(IDS_STR_UNSPT_VWMODE);
127 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
129 return;
130 }
131 }
132
133 else {
134 if (viewMode==VIEW_ZDIR) { // Z
135 xsize = cmnHead.xsize;
136 ysize = cmnHead.ysize;
137 zsize = cmnHead.zsize;
138 }
139 else if (viewMode==VIEW_XDIR) { // X
140 xsize = cmnHead.ysize;
141 ysize = cmnHead.zsize;
142 zsize = cmnHead.xsize;
143 if (ysize<=1) {
145 mesg.LoadString(IDS_STR_INVLD_VWMODE);
146 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
148 return;
149 }
150 }
151 else if (viewMode==VIEW_YDIR) { // Y
152 xsize = cmnHead.xsize;
153 ysize = cmnHead.zsize;
154 zsize = cmnHead.ysize;
155 if (ysize<=1) {
157 mesg.LoadString(IDS_STR_INVLD_VWMODE);
158 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
160 return;
161 }
162
163 }
164 else {
166 mesg.LoadString(IDS_STR_UNKWN_VWMODE);
167 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
169 return;
170 }
171 }
172
173 //
174 cMax = pDoc->cMax;
175 cMin = pDoc->cMin;
176 vMax = pDoc->vMax;
177 vMin = pDoc->vMin;
178
179 //
180 D3DFORMAT format;
181
182 // RGB 8bit/plane
183 // なんで xsize, ysize は偶数なんだっけ!?
185 //xsize = (((xsize*3+3)/4)*4+2)/3;
186 //ysize = (((ysize*3+3)/4)*4+2)/3;
187 viewData.set(xsize, ysize, 1, 24);
188 format = D3DFMT_X8R8G8B8;
189 vMax = cMax = VIEW_8_MAX;
190 vMin = cMin = VIEW_8_MIN;
191 }
192 // ARGB/RGBA 8bit/plane
194 viewData.set(xsize, ysize, 1, 32);
195 format = D3DFMT_A8R8G8B8;
196 vMax = cMax = VIEW_8_MAX;
197 vMin = cMin = VIEW_8_MIN;
198 }
199 // XRGB 8bit/plane
200 else if (colorMode==GRAPH_COLOR_XRGB) {
201 viewData.set(xsize, ysize, 1, 32);
202 format = D3DFMT_X8R8G8B8;
203 vMax = cMax = VIEW_8_MAX;
204 vMin = cMin = VIEW_8_MIN;
205 }
206 // ABGR/BGRA 8bit/plane
208 viewData.set(xsize, ysize, 1, 32);
209 format = D3DFMT_A8R8G8B8;
210 vMax = cMax = VIEW_8_MAX;
211 vMin = cMin = VIEW_8_MIN;
212 }
213 // XBGR 8bit/plane
214 else if (colorMode==GRAPH_COLOR_XBGR) {
215 viewData.set(xsize, ysize, 1, 32);
216 format = D3DFMT_X8R8G8B8;
217 vMax = cMax = VIEW_8_MAX;
218 vMin = cMin = VIEW_8_MIN;
219 }
220 // ARGB16/RGBA16 16bit/plane
222 //xsize += xsize%2;
223 //ysize += ysize%2;
224 viewData.set(xsize, ysize, 1, 16);
225 format = D3DFMT_A4R4G4B4;
226 vMax = cMax = SWORDMAX;
227 vMin = cMin = SWORDMIN;
228 }
229 // RGB16 16bit/plane
230 else if (colorMode==GRAPH_COLOR_RGB16) {
231 //xsize += xsize%2;
232 //ysize += ysize%2;
233 viewData.set(xsize, ysize, 1, 16);
234 format = D3DFMT_R5G6B5;
235 vMax = cMax = SWORDMAX;
236 vMin = cMin = SWORDMIN;
237 }
238 // GRAPH_COLOR_MONO, MONO16 8,16bit/plane (MONO16は MONOに変換されて表示される)
239 else {
240 //xsize = ((xsize+3)/4)*4;
241 //ysize = ((ysize+3)/4)*4;
242 viewData.set(xsize, ysize);
243 format = D3DFMT_R5G6B5;
244 }
245
246 //
249 sizeXYRate = (double)ysize/(double)xsize;
250
251 renderRect.top = 0;
252 renderRect.left = 0;
253 renderRect.right = xsize;
254 renderRect.bottom = ysize;
255 vSBmax = zsize - 1;
256
259
260 //
261 // DX9
262 //
264 if (!rslt) {
266 mesg.LoadString(IDS_STR_FAIL_GET_DX9DEV);
267 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
269 return;
270 }
271
273 if (bufferSize.x<0) {
275 mesg.LoadString(IDS_STR_FAIL_CRT_BAKBUF);
276 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
277 return;
278 }
279
280 HRESULT hr = lpD3DDevice->CreateOffscreenPlainSurface(xsize, ysize, format, D3DPOOL_DEFAULT, &lpSurface, NULL);
281 if (FAILED(hr)) {
283 mesg.LoadString(IDS_STR_FAIL_CRT_SURFACE);
284 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
286 return;
287 }
288
290 if (!hasViewData) {
293 MessageBox(_T("CDxMGRView::OnInitialUpdate():\n\n") + mesg);
295 return;
296 }
297
298 //
299 SetWindowSize(viewData.xsize, viewData.ysize);
300 return;
301}
302
303
305{
306 int point, n;
307 double ca, cb;
308 HRESULT hr;
309
310 if (isNull(viewData.grptr)) {
312 mesg.LoadString(IDS_STR_DLTD_DATA);
313 noti.LoadString(IDS_STR_ERROR);
314 MessageBox(_T("CDxMGRView::SetNewSurface():\n\n") + mesg, noti, MB_OK);
315 return FALSE;
316 }
317
318 //
319 check_endian();
320 MakeSetTitle();
321
322 // コントラスト調整
323 // cMax, cMin: 可変  vMax, vMin:コントラストの上限と下限(固定)
324 if (cMax==cMin) cMax = cMin + 1;
325 ca = ((double)(vMax-vMin))/((double)(cMax-cMin));
326 cb = ((double)(vMin-cMin))/((double)(cMax-cMin));
327
328 // RGB 8bit/plane
330 for (int k=0; k<3; k++) {
331 if (HostEndian==BIG_ENDIAN) n = k;
332 else n = 2 - k;
333 for (int j=0; j<cmnHead.ysize; j++) {
334 for (int i=0; i<cmnHead.xsize; i++) {
335 uByte* ptr = &viewData.point(i, j);
336 point = (int)(cmnHead.point(i, j, k)*ca + VIEW_8_MAX*cb + 0.5);
339 ptr[n] = point;
340 }
341 }
342 }
343
344 int srcpitch = viewData.xsize*3;
346 }
347
348 // BGR 8bit/plane
349 else if (colorMode==GRAPH_COLOR_BGR) {
350 for (int k=0; k<3; k++) {
351 if (HostEndian==BIG_ENDIAN) n = 2 - k;
352 else n = k;
353 for (int j=0; j<cmnHead.ysize; j++) {
354 for (int i=0; i<cmnHead.xsize; i++) {
355 uByte* ptr = &viewData.point(i, j);
356 point = (int)(cmnHead.point(i, j, k)*ca + VIEW_8_MAX*cb + 0.5);
359 ptr[n] = point;
360 }
361 }
362 }
363
364 int srcpitch = viewData.xsize*3;
366 }
367
368 // XRGB/ARGB 8bit/plane
370 for (int k=0; k<4; k++) {
371 if (HostEndian==BIG_ENDIAN) n = k;
372 else n = 3 - k;
373 for (int j=0; j<cmnHead.ysize; j++) {
374 for (int i=0; i<cmnHead.xsize; i++) {
375 uByte* ptr = &viewData.point(i, j);
376 point = (int)(cmnHead.point(i, j, k)*ca + VIEW_8_MAX*cb + 0.5);
379 ptr[n] = point;
380 }
381 }
382 }
383
384 int srcpitch = viewData.xsize*4;
387 }
388 else {
390 }
391 }
392
393 // RGBA 8bit/plane
394 else if (colorMode==GRAPH_COLOR_RGBA) {
395 for (int k=0; k<4; k++) {
396 if (HostEndian==BIG_ENDIAN) n = 3 - k;
397 else n = k;
398 for (int j=0; j<cmnHead.ysize; j++) {
399 for (int i=0; i<cmnHead.xsize; i++) {
400 uByte* ptr = &viewData.point(i, j);
401 point = (int)(cmnHead.point(i, j, k)*ca + VIEW_8_MAX*cb + 0.5);
404 ptr[n] = point;
405 }
406 }
407 }
408
409 int srcpitch = viewData.xsize*4;
411 }
412
413 // XBGR/ABGR 8bit/plane
415 for (int k=0; k<4; k++) {
416 if (HostEndian==BIG_ENDIAN) n = k;
417 else n = 3 - k;
418 for (int j=0; j<cmnHead.ysize; j++) {
419 for (int i=0; i<cmnHead.xsize; i++) {
420 uByte* ptr = &viewData.point(i, j);
421 point = (int)(cmnHead.point(i, j, k)*ca + VIEW_8_MAX*cb + 0.5);
424 ptr[n] = point;
425 }
426 }
427 }
428
429 int srcpitch = viewData.xsize*4;
432 }
433 else {
435 }
436 }
437
438 // BGRA 8bit/plane
439 else if (colorMode==GRAPH_COLOR_BGRA) {
440 for (int k=0; k<4; k++) {
441 if (HostEndian==BIG_ENDIAN) n = 3 - k;
442 else n = k;
443 for (int j=0; j<cmnHead.ysize; j++) {
444 for (int i=0; i<cmnHead.xsize; i++) {
445 uByte* ptr = &viewData.point(i, j);
446 point = (int)(cmnHead.point(i, j, k)*ca + VIEW_8_MAX*cb + 0.5);
449 ptr[n] = point;
450 }
451 }
452 }
453
454 int srcpitch = viewData.xsize*4;
456 }
457
458 // RGB16/ARGB16/RGBA16 16bit/plane
460 uWord* src = NULL;
461 uWord* dst = NULL;
462
463 if (prevSBpos!=vSBpos) {
464 if (viewMode==VIEW_ZDIR) {
465 for (int j=0; j<cmnHead.ysize; j++) {
466 for (int i=0; i<cmnHead.xsize; i++) {
467 src = (uWord*)&cmnHead.point(i, j, vSBpos);
468 dst = (uWord*)&viewData.point(i, j);
469 point = (int)(*src*ca + vMax*cb + 0.5);
470 //point = Min(point, vMax);
471 //point = Max(point, vMin);
472 *dst = point;
473 }
474 }
475 }
476 else if (viewMode==VIEW_XDIR) {
477 for (int j=0; j<cmnHead.zsize; j++) {
478 for (int i=0; i<cmnHead.ysize; i++) {
479 src = (uWord*)&cmnHead.point(vSBpos, i, j);
480 dst = (uWord*)&viewData.point(i, j);
481 point = (int)(*src*ca + vMax*cb + 0.5);
482 //point = Min(point, vMax);
483 //point = Max(point, vMin);
484 *dst = point;
485 }
486 }
487 }
488 else if (viewMode==VIEW_YDIR) {
489 for (int j=0; j<cmnHead.zsize; j++) {
490 for (int i=0; i<cmnHead.xsize; i++) {
491 src = (uWord*)&cmnHead.point(i, cmnHead.ysize-1-vSBpos, j);
492 dst = (uWord*)&viewData.point(i, j);
493 point = (int)(*src*ca + vMax*cb + 0.5);
494 //point = Min(point, vMax);
495 //point = Max(point, vMin);
496 *dst = point;
497 }
498 }
499 }
500 else return FALSE;
501 }
502
503 ntoh_data(viewData.grptr, viewData.lsize, 2);
504 int srcpitch = viewData.xsize*2;
507 }
508 else if (colorMode==GRAPH_COLOR_ARGB16) {
510 }
511 else { // GRAPH_COLOR_RGBA16
512 // R4G4B4A4 -> A4R4G4B4
513 for (int i=0; i<viewData.xsize*viewData.ysize*2; i+=2) {
514 int r = (viewData.grptr[i] &0xf0)>>4;
515 int g = (viewData.grptr[i] &0x0f)<<4;
516 int b = (viewData.grptr[i+1]&0xf0)>>4;
517 int a = (viewData.grptr[i+1]&0x0f)<<4;
518 viewData.grptr[i] = (uByte)(a + r);
519 viewData.grptr[i+1] = (uByte)(g + b);
520 }
522 }
523 }
524
525 // Monochrome 8,16bit/plane cmnHead は8bitに変換済み
527 if (prevSBpos!=vSBpos) {
528 if (viewMode==VIEW_ZDIR) {
529 for (int j=0; j<cmnHead.ysize; j++) {
530 for (int i=0; i<cmnHead.xsize; i++) {
531 point = (int)(cmnHead.point(i, j, vSBpos)*ca + VIEW_8_MAX*cb + 0.5);
533 point = Max(point, 0);
534 viewData.point(i, j) = point;
535 }
536 }
537 }
538 else if (viewMode==VIEW_XDIR) {
539 for (int j=0; j<cmnHead.zsize; j++) {
540 for (int i=0; i<cmnHead.ysize; i++) {
541 point = (int)(cmnHead.point(vSBpos, i, j)*ca + VIEW_8_MAX*cb + 0.5);
543 point = Max(point, 0);
544 viewData.point(i, j) = point;
545 }
546 }
547 }
548 else if (viewMode==VIEW_YDIR) {
549 for (int j=0; j<cmnHead.zsize; j++) {
550 for (int i=0; i<cmnHead.xsize; i++) {
551 point = (int)(cmnHead.point(i, cmnHead.ysize-1-vSBpos, j)*ca + VIEW_8_MAX*cb + 0.5);
553 point = Max(point, 0);
554 viewData.point(i, j) = point;
555 }
556 }
557 }
558 else return FALSE;
559 }
560
561 // GRAPH_COLOR_MONO16 は 8bitに変換されている
562 int srcpitch = viewData.xsize;
564 }
565
566 if (FAILED(hr)) return FALSE;
567
568 return TRUE;
569}
570
571
573{
574 HRESULT hr;
575
576 MakeSetTitle();
577
578 hr = lpD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
579 if (FAILED(hr)) {
581 mesg.LoadString(IDS_STR_FAIL_CLR_WND);
582 MessageBox(_T("CDxMGRView::ExecRender():\n\n") + mesg);
583 return;
584 }
585
587 if (FAILED(hr)) {
589 mesg.LoadString(IDS_STR_FAIL_TRNS_BAKBUF);
590 MessageBox(_T("CDxMGRView::ExecRender():\n\n") + mesg);
591 return;
592 }
593
594 hr = lpD3DDevice->Present(NULL, NULL, NULL, NULL);
595 if (FAILED(hr)) {
597 if (FAILED(hr)) {
600 MessageBox(_T("CDxMGRView::ExecRender():\n\n") + mesg);
601 pFrame->SendMessage(WM_CLOSE);
602 //GetParentFrame()->DestroyWindow();
603 }
604 else ExecRender();
605 }
606}
607
608
610{
612 if (bufferSize.x<0) {
615 MessageBox(_T("CDxMGRView::InitObject():\n\n") + mesg);
616 return;
617 }
618
619 HRESULT hr;
621 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &lpSurface, NULL);
622 }
624 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &lpSurface, NULL);
625 }
626 else if (colorMode==GRAPH_COLOR_XRGB) {
627 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &lpSurface, NULL);
628 }
630 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &lpSurface, NULL);
631 }
632 else if (colorMode==GRAPH_COLOR_XBGR) {
633 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &lpSurface, NULL);
634 }
636 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_A4R4G4B4, D3DPOOL_DEFAULT, &lpSurface, NULL);
637 }
638 else { // GRAPH_COLOR_MONO, MONO16, RGB16
639 hr = lpD3DDevice->CreateOffscreenPlainSurface(viewData.xsize, viewData.ysize, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &lpSurface, NULL);
640 }
641
642 if (FAILED(hr)) {
645 MessageBox(_T("CDxMGRView::InitObject():\n\n") + mesg);
646 return;
647 }
648
650 if (!hasViewData) {
653 MessageBox(_T("CDxMGRView::InitObject():\n\n") + mesg);
654 return;
655 }
656 return;
657}
658
659
661{
663 if (vSBmax>=1) {
665 mesg.LoadString(IDS_STR_IMG_NUM);
666 mesg = _T(" ") + mesg + _T(" %d");
668
670 }
671
672 if (clientRate!=1.0) {
674 szprcnt.Format(_T(" (%d%%)"), (int)(clientRate*100+0.5));
675 Title = Title + szprcnt;
676 }
677 this->SetTitle(Title);
678}
static char THIS_FILE[]
Definition DxMGRView.cpp:13
#define VIEW_8_MAX
Definition ExView.h:39
#define VIEW_XDIR
Definition ExView.h:43
#define VIEW_8_MIN
Definition ExView.h:40
#define VIEW_ZDIR
Definition ExView.h:42
#define VIEW_YDIR
Definition ExView.h:44
LPDIRECT3DDEVICE9 lpD3DDevice
D3DPRESENT_PARAMETERS d3dParam
LPDIRECT3DSURFACE9 lpBackBuffer
BOOL InitDevice(int xsize=0, int ysize=0, CWnd *cwnd=NULL)
LPDIRECT3DSURFACE9 lpSurface
virtual void OnInitialUpdate()
Definition DxMGRView.cpp:97
virtual void ExecRender(void)
virtual void AssertValid() const
Definition DxMGRView.cpp:74
virtual ~CDxMGRView()
Definition DxMGRView.cpp:45
virtual void Dump(CDumpContext &dc) const
Definition DxMGRView.cpp:80
virtual void InitObject(void)
virtual BOOL SetNewSurface(int ovsbpos=0)
ExCmnHead cmnHead
Definition ExDocument.h:53
bool doneErrorMessage
Definition ExFrame.h:51
ExCmnHead cmnHead
Definition ExView.h:73
CString Title
Definition ExView.h:83
BOOL hasViewData
Definition ExView.h:81
ExCmnHead viewData
Definition ExView.h:72
int origYSize
Definition ExView.h:95
CExFrame * pFrame
Definition ExView.h:77
double sizeXYRate
Definition ExView.h:86
int origXSize
Definition ExView.h:94
void SetTitle(LPCTSTR title)
Definition ExView.cpp:348
CExDocument * pDoc
Definition ExView.h:76
virtual void AssertValid() const
Definition ExView.cpp:130
virtual void Dump(CDumpContext &dc) const
Definition ExView.cpp:136
POINT SetWindowSize(int xs, int ys, BOOL first=TRUE)
Definition ExView.cpp:156
double clientRate
Definition ExView.h:87
HRESULT ResetDx9Device(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS *, CDxBaseView *pviw=NULL)
POINT Dx9GetBackBuffer(LPDIRECT3DDEVICE9, LPDIRECT3DSURFACE9 *)
Definition Dx9.cpp:175
CString numbering_name_t(LPCTSTR fmt, int n)
Definition WinTools.cpp:403
#define IDS_STR_IMG_NUM
Definition resource.h:111
#define IDS_STR_DLTD_DATA
Definition resource.h:96
#define IDS_STR_FAIL_RESTR_DX9DEV
Definition resource.h:65
#define IDS_STR_ERROR
Definition resource.h:98
#define IDS_STR_INVLD_VWMODE
Definition resource.h:75
#define IDS_STR_FAIL_GET_DX9DEV
Definition resource.h:59
#define IDS_STR_FAIL_RETRNS_SURFACE
Definition resource.h:70
#define IDS_STR_FAIL_REGET_SURFACE
Definition resource.h:69
#define IDS_STR_FAIL_REGET_BAKBUF
Definition resource.h:68
#define IDS_STR_FAIL_CLR_WND
Definition resource.h:64
#define IDS_STR_FAIL_TRNS_BAKBUF
Definition resource.h:61
#define IDS_STR_FAIL_CRT_SURFACE
Definition resource.h:62
#define IDS_STR_FAIL_CRT_BAKBUF
Definition resource.h:60
#define IDS_STR_UNKWN_VWMODE
Definition resource.h:76
#define IDS_STR_UNSPT_VWMODE
Definition resource.h:74
#define IDS_STR_FAIL_TRNS_SURFACE
Definition resource.h:63