/*static*/ ValuePtr Value::Create(size_t vocabularySize, const std::vector<std::vector<size_t>>& oneHotSequences, const DeviceDescriptor& device, bool readOnly/* = false*/) { NDMaskPtr deviceValueMask = CreateMask(1, oneHotSequences, device); size_t maxSequenceLength = (deviceValueMask == nullptr) ? oneHotSequences[0].size() : deviceValueMask->Shape()[0]; size_t numSequences = oneHotSequences.size(); NDShape sampleShape = { vocabularySize }; NDShape valueDataShape = sampleShape.AppendShape({ maxSequenceLength, numSequences }); size_t numCSCCols = valueDataShape.SubShape(1).TotalSize() + 1; std::vector<SparseIndexType> colStarts(numCSCCols); std::vector<ElementType> nonZeroValues; std::vector<SparseIndexType> rowIndices; for (size_t i = 0; i < numSequences; ++i) { size_t currentSequenceLength = oneHotSequences[i].size(); size_t j = 0; for (; j < currentSequenceLength; ++j) { colStarts[(i * maxSequenceLength) + j] = (SparseIndexType)nonZeroValues.size(); nonZeroValues.push_back(1); rowIndices.push_back((SparseIndexType)(oneHotSequences[i][j])); } for (; j < maxSequenceLength; ++j) colStarts[(i * maxSequenceLength) + j] = (SparseIndexType)(nonZeroValues.size()); } colStarts[numSequences * maxSequenceLength] = (SparseIndexType)(nonZeroValues.size()); NDArrayViewPtr deviceValueData(new NDArrayView(valueDataShape, colStarts.data(), rowIndices.data(), nonZeroValues.data(), nonZeroValues.size(), device, readOnly), [](ReferenceCount* ptr) { delete ptr; }); return ValuePtr(new Value(deviceValueData, deviceValueMask), [](ReferenceCount* ptr) { delete ptr; }); }
/*static*/ ValuePtr Value::Create(const NDShape& sampleShape, const std::vector<std::vector<ElementType>>& sequences, const DeviceDescriptor& device, bool readOnly/* = false*/) { size_t sampleSize = sampleShape.TotalSize(); NDMaskPtr deviceValueMask = CreateMask(sampleSize, sequences, device); size_t maxSequenceLength = (deviceValueMask == nullptr) ? sequences[0].size() : deviceValueMask->Shape()[0]; size_t numSequences = sequences.size(); NDShape valueDataShape = sampleShape.AppendShape({ maxSequenceLength, numSequences }); NDArrayViewPtr valueData(new NDArrayView(AsDataType<ElementType>(), valueDataShape, DeviceDescriptor::CPUDevice()), [](ReferenceCount* ptr) { delete ptr; }); ElementType* dataBuffer = valueData->WritableDataBuffer<ElementType>(); for (size_t i = 0; i < numSequences; ++i) std::copy(sequences[i].data(), sequences[i].data() + sequences[i].size(), dataBuffer + (maxSequenceLength * i * sampleSize)); NDArrayViewPtr deviceValueData; if (device == DeviceDescriptor::CPUDevice()) { if (readOnly) deviceValueData = valueData->Alias(true); else deviceValueData = valueData; } else { deviceValueData = NDArrayViewPtr(new NDArrayView(AsDataType<ElementType>(), valueDataShape, device), [](ReferenceCount* ptr) { delete ptr; }); deviceValueData->CopyFrom(*valueData); if (readOnly) deviceValueData = deviceValueData->Alias(true); } return ValuePtr(new Value(deviceValueData, deviceValueMask), [](ReferenceCount* ptr) { delete ptr; }); }
//--------------------------------------------------------------------------- void TFileMasks::SetStr(const UnicodeString & Str, bool SingleMask) { UnicodeString Backup = FStr; try { FStr = Str; Clear(); intptr_t NextMaskFrom = 1; bool Include = true; while (NextMaskFrom <= Str.Length()) { intptr_t MaskStart = NextMaskFrom; wchar_t NextMaskDelimiter; UnicodeString MaskStr; if (SingleMask) { MaskStr = Str; NextMaskFrom = Str.Length() + 1; NextMaskDelimiter = L'\0'; } else { MaskStr = CopyToChars(Str, NextMaskFrom, AllFileMasksDelimiters, false, &NextMaskDelimiter, true); } intptr_t MaskEnd = NextMaskFrom - 2; TrimEx(MaskStr, MaskStart, MaskEnd); if (!MaskStr.IsEmpty()) { CreateMask(MaskStr, MaskStart, MaskEnd, Include); } if (NextMaskDelimiter == IncludeExcludeFileMasksDelimiter) { if (Include) { Include = false; } else { ThrowError(NextMaskFrom - 1, Str.Length()); } } } } catch(...) { // this does not work correctly if previous mask was set using SetMask. // this should not fail (the mask was validated before), // otherwise we end in an infinite loop SetStr(Backup, false); throw; } }
sf::Uint8* GetMask (const sf::Texture* tex) { sf::Uint8* mask; std::map<const sf::Texture*, sf::Uint8*>::iterator pair = Bitmasks.find(tex); if (pair==Bitmasks.end()) { sf::Image img = tex->copyToImage(); mask = CreateMask (tex, img); } else mask = pair->second; return mask; }
//============================================================================================== // ゲームメイン処理 //============================================================================================== void GameMain(void) { TIMECAPS Caps; timeGetDevCaps(&Caps, sizeof(TIMECAPS)); // 性能取得 timeBeginPeriod(Caps.wPeriodMin); // 設定 HDC hDC_Back = CreateEmptyBMP(hDC_Wnd, pWid, pHei); HDC hDC_Wheel = LoadBMPfromFile(hDC_Wnd, TEXT("wheel.bmp")); HDC hDC_Block = LoadBMPfromResourceSTR(hDC_Wnd, hInst, TEXT("IDB_BLOCKIDB_BLOCK")); HDC hDC_org = LoadBMPfromResourceSTR(hDC_Wnd, hInst, TEXT("IDB_ORG")); HDC hDC_Mask = CreateMask(hDC_org, RGB(0, 0, 0)); HANDLE hfile; DWORD file_size, read_byte; mciSendString(_T("close BGM"), NULL, 0, NULL); // (前回ちゃんと閉じられなかったかも…) mciSendString(_T("open SHOOT!.mid type sequencer alias BGM"), NULL, 0, NULL); // 開く TCHAR BGMStatus[256] = { 0 }; mciSendString(_T("status BGM mode"), BGMStatus, 256, NULL); // 状態の取得 if (lstrcmp(BGMStatus, TEXT("stopped")) == 0) { mciSendString(TEXT("play BGM from 0"), NULL, 0, NULL); // 停止中なら演奏 } Sleep(15000); LPCTSTR Sound = LoadSound(_T("notify.wav")); PlaySound(Sound, NULL, SND_ASYNC | SND_MEMORY); //メインループ while (!EndFlag) { const DWORD StartTime = timeGetTime(); //~ ゲーム処理いろいろ ~ //PatBlt(hDC_Back, 0, 0, pWid, pHei, WHITENESS); BitBlt(hDC_Back, 0, 0, 32, 32, hDC_Wheel, 0, 0, SRCCOPY); BitBlt(hDC_Back, 64, 0, 32, 32, hDC_Block, 0, 0, SRCCOPY); //SpriteBlt(hDC_Back, 32, 0, 32, 32, hDC_org, 0, 0, hDC_Mask); BitBlt(hDC_Wnd, 0, 0, pWid, pHei, hDC_Back, 0, 0, SRCCOPY); const DWORD PassTime = timeGetTime() - StartTime; // 経過時間の計算 (1000 / FPS > PassTime) ? Wait(1000 / FPS - PassTime) : Wait(0); // 待つ。 mciSendString(TEXT("status BGM mode"), BGMStatus, 256, NULL); // 状態の取得 if (lstrcmp(BGMStatus, TEXT("stopped")) == 0) { mciSendString(TEXT("play BGM from 0"), NULL, 0, NULL); // 停止中なら演奏 } FPSCount(&fps); // FPS の計測 } timeEndPeriod(Caps.wPeriodMin); // 後処理 HeapFree(GetProcessHeap(), 0, (LPVOID)Sound); // 解放 DeleteDC(hDC_Wheel); DeleteDC(hDC_Block); }
int main(int argc, char*argv[]) { Mask::Pointer mask = Mask::New(); CreateMask(mask); OutputHelpers::WriteImage(mask.GetPointer(), "mask.png"); UnsignedCharScalarImageType::Pointer image = UnsignedCharScalarImageType::New(); CreateImage(image); OutputHelpers::WriteImage(image.GetPointer(), "image.png"); FloatScalarImageType::Pointer output = FloatScalarImageType::New(); MaskOperations::MaskedLaplacian(image.GetPointer(), mask.GetPointer(), output.GetPointer()); OutputHelpers::WriteImage(output.GetPointer(), "laplacian.mha"); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { Mask::Pointer mask = Mask::New(); CreateMask(mask); itk::Index<2> queryPixel; queryPixel[0] = 5; queryPixel[1] = 5; FloatVector2Type direction; direction[0] = 1; direction[1] = 1; direction.Normalize(); itk::Index<2> pixelAcross = mask->FindPixelAcrossHole(queryPixel, direction); std::cout << "Pixel across: " << pixelAcross << std::endl; //HelpersOutput::WriteImage<Mask>(blurredLuminance, "Test/TestIsophotes.blurred.mha"); return EXIT_SUCCESS; }
BOOL RWindowsImageList::LoadBitmap( LPCTSTR lpszBitmapID, COLORREF crMask ) { if (m_hbmImageList) { DeleteObject() ; } try { HDC hdc = ::GetWindowDC( NULL ) ; BITMAP bm ; // Create the image list bitmap and screen compatible device m_hdcImageList = ::CreateCompatibleDC( hdc ) ; m_hbmImageList = ::LoadBitmap( AfxGetResourceHandle(), lpszBitmapID ) ; ::ReleaseDC( NULL, hdc ) ; if (!m_hdcImageList || !m_hbmImageList) { AfxThrowResourceException( ) ; } // Select the bitmap into the screen compatible dc m_hbmOldImageList = (HBITMAP) ::SelectObject( m_hdcImageList, m_hbmImageList ) ; // Determine the bitmaps dimensions ::GetObject( m_hbmImageList, sizeof( bm ), &bm ) ; try { if (crMask != CLR_DEFAULT) { CreateMask( bm.bmWidth, bm.bmHeight, crMask ) ; } } catch( CResourceException& ) { // Restore the dc so all objects can be deleted ::SelectObject( m_hdcImageList, m_hbmOldImageList ) ; m_hbmOldImageList = NULL ; throw ; } // Save the bitmaps dimensions m_szImage.cx = bm.bmWidth ; m_szImage.cy = bm.bmHeight ; // Save the mask color m_crMask = crMask ; } catch( CResourceException& ) { if (m_hbmImageList) { ::DeleteObject( m_hbmImageList ) ; m_hbmImageList = NULL ; } if (m_hdcImageList) { ::DeleteDC( m_hdcImageList ) ; m_hdcImageList = NULL ; } return FALSE ; } return TRUE ; }
//----------------------------- FUNCTION -------------------------------------* void CTransBmp::DrawTrans(HDC hDC, int x, int y) /*>>>> draw bitmap transparently on given DC I hDC: device context to draw on I x: x/y device coordinates to draw bitmap to I y: Result void <<<<*/ { ASSERT(hDC); if (!m_hbmMask) { CreateMask(hDC); } ASSERT(m_hObject); ASSERT(m_hbmMask); int dx = GetWidth(); int dy = GetHeight(); // Create a memory DC to which to draw. HDC hdcOffScr = ::CreateCompatibleDC(hDC); // Create a bitmap for the off-screen DC that is really // color-compatible with the destination DC. HBITMAP hbmOffScr = ::CreateBitmap(dx, dy, (BYTE)GetDeviceCaps(hDC, PLANES), (BYTE)GetDeviceCaps(hDC, BITSPIXEL), NULL); // Select the buffer bitmap into the off-screen DC. HBITMAP hbmOldOffScr = (HBITMAP)::SelectObject(hdcOffScr, hbmOffScr); // Copy the image of the destination rectangle to the // off-screen buffer DC, so we can play with it. ::BitBlt(hdcOffScr, 0, 0, dx, dy, hDC, x, y, SRCCOPY); // Create a memory DC for the source image. HDC hdcImage = ::CreateCompatibleDC(hDC); HBITMAP hbmOldImage = (HBITMAP)::SelectObject(hdcImage, m_hObject); // Create a memory DC for the mask. HDC hdcMask = ::CreateCompatibleDC(hDC); HBITMAP hbmOldMask = (HBITMAP)::SelectObject(hdcMask, m_hbmMask); // XOR the image with the destination. ::SetBkColor(hdcOffScr, rgbWhite); ::BitBlt(hdcOffScr, 0, 0, dx, dy, hdcImage, 0, 0, DSx); // AND the destination with the mask. ::BitBlt(hdcOffScr, 0, 0, dx, dy, hdcMask, 0, 0, DSa); // XOR the destination with the image again. ::BitBlt(hdcOffScr, 0, 0, dx, dy, hdcImage, 0, 0, DSx); // Copy the resultant image back to the screen DC. ::BitBlt(hDC, x, y, dx, dy, hdcOffScr, 0, 0, SRCCOPY); // Tidy up. ::SelectObject(hdcOffScr, hbmOldOffScr); ::SelectObject(hdcImage, hbmOldImage); ::SelectObject(hdcMask, hbmOldMask); ::DeleteObject(hbmOffScr); ::DeleteDC(hdcOffScr); ::DeleteDC(hdcImage); ::DeleteDC(hdcMask); }
BOOL CFlatToolbar::DrawMonoButton(CDC* pDC, int x, int y, int dx, int dy, int iImage, UINT nStyle) { // interior is black if pressed, white if not if (nStyle & (TBBS_PRESSED | TBBS_CHECKED)) { pDC->FillSolidRect(x, y, dx, dy, RGB(0, 0, 0)); pDC->SetBkColor(RGB(255, 255, 255)); // bkcolor was set by PatB } else { pDC->FillSolidRect(x, y, dx, dy, RGB(0xFF, 0xFF, 0xFF)); } CPoint ptOffset; ptOffset.x = (dx - m_sizeImage.cx - 1) / 2; ptOffset.y = (dy - m_sizeImage.cy) / 2; if ((nStyle & TBBS_PRESSED) || !(nStyle & TBBS_DISABLED)) { // normal image version BitBlt(pDC->m_hDC, x + ptOffset.x, y + ptOffset.y, m_sizeImage.cx, m_sizeImage.cy, hDCGlyphs, iImage * m_sizeImage.cx, 0, (nStyle & (TBBS_PRESSED | TBBS_CHECKED)) ? NOTSRCCOPY : SRCCOPY); if (nStyle & (TBBS_PRESSED | TBBS_CHECKED)) return TRUE; // nothing more to do (rest of style is ignored) } if (nStyle & TBBS_DISABLED) { BitBlt(pDC->m_hDC, x + ptOffset.x, y + ptOffset.y, m_sizeImage.cx, m_sizeImage.cy, hDCGlyphs, iImage * m_sizeImage.cx, 0, SRCCOPY); int ropOld = pDC->SetROP2(R2_MASKNOTPEN); RECT rect; SetRect(&rect, 0, 0, m_sizeImage.cx, m_sizeImage.cy); OffsetRect(&rect, x + ptOffset.x, y + ptOffset.y); AfxFillRect(pDC->m_hDC, &rect, hbrDither); pDC->SetROP2(ropOld); return TRUE; } // if it is checked do the dither brush avoiding the glyph if (nStyle & (TBBS_CHECKED | TBBS_INDETERMINATE)) { HGDIOBJ hbrOld = pDC->SelectObject(hbrDither); if (hbrOld != NULL) { CreateMask(iImage, ptOffset, ~(nStyle & TBBS_INDETERMINATE), nStyle & TBBS_DISABLED); pDC->SetTextColor(0L); // 0 -> 0 pDC->SetBkColor((COLORREF)0x00FFFFFFL); // 1 -> 1 int delta = (nStyle & TBBS_INDETERMINATE) ? 3 : 1; // only draw the dither brush where the mask is 1's CRect rect(0, 0, dx, dy); ::InvertRect(hDCMono, &rect); BitBlt(pDC->m_hDC, x, y, dx, dy, hDCMono, 0, 0, ROP_PSDPxax); pDC->SelectObject(hbrOld); } } return TRUE; }
BOOL CFlatToolbar::DrawButton(CDC* pDC, int x, int y, int iImage, UINT nStyle) { ASSERT_VALID(pDC); int dx = m_sizeButton.cx; int dy = m_sizeButton.cy; if (!globalData.bWin4) { // make the coordinates the interior of the button x += 1; y += 1; dx -= 2; dy -= 2; // border around button pDC->FillSolidRect(x, y-1, dx, 1, globalData.clrWindowFrame); pDC->FillSolidRect(x, y+dy, dx, 1, globalData.clrWindowFrame); pDC->FillSolidRect(x-1, y, 1, dy, globalData.clrWindowFrame); pDC->FillSolidRect(x+dx, y, 1, dy, globalData.clrWindowFrame); } #ifdef _MAC if (m_bMonochrome) return DrawMonoButton(pDC, x, y, dx, dy, iImage, nStyle); #endif // interior grey pDC->FillSolidRect(x, y, dx, dy, globalData.clrBtnFace); // determine offset of bitmap (centered within button) CPoint ptOffset; ptOffset.x = (dx - m_sizeImage.cx - 1) / 2; ptOffset.y = (dy - m_sizeImage.cy) / 2; if (nStyle & (TBBS_PRESSED | TBBS_CHECKED)) { // pressed in or checked pDC->Draw3dRect(x, y, dx, dy, globalData.bWin4 ? globalData.clrWindowFrame : globalData.clrBtnShadow, globalData.bWin4 ? globalData.clrBtnHilite : globalData.clrBtnFace); /* TONYCL: OFFICE97 LOOK AND FEEL if (globalData.bWin4) { pDC->Draw3dRect(x + 1, y + 1, dx - 2, dy - 2, globalData.clrBtnShadow, globalData.clrBtnFace); } */ // for any depressed button, add one to the offsets. ptOffset.x += 1; ptOffset.y += 1; } // TONYCL: START: OFFICE97 LOOK AND FEEL if (nStyle & TBBS_UPSTATE) { pDC->Draw3dRect(x, y, dx, dy, globalData.clrBtnHilite, // MATTGR // clrWindowFrame was icky /*globalData.bWin4 ? globalData.clrWindowFrame : */globalData.clrBtnShadow); } // TONYCL: END: OFFICE97 LOOK AND FEEL if ((nStyle & TBBS_PRESSED) || !(nStyle & TBBS_DISABLED)) { // normal image version BitBlt(pDC->m_hDC, x + ptOffset.x, y + ptOffset.y, m_sizeImage.cx, m_sizeImage.cy, hDCGlyphs, iImage * m_sizeImage.cx, 0, SRCCOPY); if (nStyle & TBBS_PRESSED) return TRUE; // nothing more to do (rest of style is ignored) } if (nStyle & (TBBS_DISABLED | TBBS_INDETERMINATE)) { // disabled or indeterminate version CreateMask(iImage, ptOffset, TRUE, FALSE); pDC->SetTextColor(0L); // 0's in mono -> 0 (for ROP) pDC->SetBkColor((COLORREF)0x00FFFFFFL); // 1's in mono -> 1 if (nStyle & TBBS_DISABLED) { // disabled - draw the hilighted shadow HGDIOBJ hbrOld = pDC->SelectObject(globalData.hbrBtnHilite); if (hbrOld != NULL) { // draw hilight color where we have 0's in the mask BitBlt(pDC->m_hDC, x + 1, y + 1, m_sizeButton.cx - 2, m_sizeButton.cy - 2, hDCMono, 0, 0, ROP_PSDPxax); pDC->SelectObject(hbrOld); } } //BLOCK: always draw the shadow { HGDIOBJ hbrOld = pDC->SelectObject(globalData.hbrBtnShadow); if (hbrOld != NULL) { // draw the shadow color where we have 0's in the mask BitBlt(pDC->m_hDC, x, y, m_sizeButton.cx - 2, m_sizeButton.cy - 2, hDCMono, 0, 0, ROP_PSDPxax); pDC->SelectObject(hbrOld); } } } // if it is checked do the dither brush avoiding the glyph if (nStyle & (TBBS_CHECKED | TBBS_INDETERMINATE)) { HGDIOBJ hbrOld = pDC->SelectObject(hbrDither); if (hbrOld != NULL) { ptOffset.x -= globalData.cxBorder2; ptOffset.y -= globalData.cyBorder2; CreateMask(iImage, ptOffset, ~(nStyle & TBBS_INDETERMINATE), nStyle & TBBS_DISABLED); pDC->SetTextColor(0L); // 0 -> 0 pDC->SetBkColor((COLORREF)0x00FFFFFFL); // 1 -> 1 ASSERT(globalData.cxBorder2 == globalData.cyBorder2); int delta = (nStyle & TBBS_INDETERMINATE) ? globalData.bWin4 ? globalData.cxBorder2*2 : 3 : globalData.cxBorder2*2; // only draw the dither brush where the mask is 1's BitBlt(pDC->m_hDC, x + globalData.cxBorder2, y + globalData.cyBorder2, dx-delta, dy-delta, hDCMono, 0, 0, ROP_DSPDxax); pDC->SelectObject(hbrOld); } } return TRUE; }