diff --git a/sakura_core/Makefile b/sakura_core/Makefile index 374268373d..1b5498732f 100644 --- a/sakura_core/Makefile +++ b/sakura_core/Makefile @@ -46,6 +46,8 @@ LIBS= \ -limagehlp \ -lshlwapi \ -lwinmm \ + -lwindowscodecs \ + -lmsimg32 \ -mwindows \ $(MYLIBS) diff --git a/sakura_core/doc/CEditDoc.cpp b/sakura_core/doc/CEditDoc.cpp index 2a4c4ccdef..39f8e6a85f 100644 --- a/sakura_core/doc/CEditDoc.cpp +++ b/sakura_core/doc/CEditDoc.cpp @@ -45,6 +45,9 @@ #include // Apr. 03, 2003 genta #include #include +#include +#pragma comment(lib, "windowscodecs.lib") +#include #include "doc/CEditDoc.h" #include "doc/logic/CDocLine.h" /// 2002/2/3 aroka #include "doc/layout/CLayout.h" // 2007.08.22 ryoji 追加 @@ -317,61 +320,70 @@ void CEditDoc::SetBackgroundImage() GetInidirOrExedir( &fullPath[0], &path[0] ); path = fullPath; } - const TCHAR* ext = path.GetExt(); - if( 0 != auto_stricmp(ext, _T(".bmp")) ){ - HANDLE hFile = ::CreateFile(path.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); - if( hFile == INVALID_HANDLE_VALUE ){ - return; - } - DWORD fileSize = ::GetFileSize(hFile, NULL); - HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, fileSize); - if( hGlobal == NULL ){ - ::CloseHandle(hFile); - return; - } - DWORD nRead; - BOOL bRead = ::ReadFile(hFile, GlobalLock(hGlobal), fileSize, &nRead, NULL); - ::CloseHandle(hFile); - hFile = NULL; - if( !bRead ){ - ::GlobalFree(hGlobal); - return; - } - ::GlobalUnlock(hGlobal); - { - IPicture* iPicture = NULL; - IStream* iStream = NULL; - //hGlobalの管理を移譲 - if( S_OK != ::CreateStreamOnHGlobal(hGlobal, TRUE, &iStream) ){ - GlobalFree(hGlobal); - }else{ - if( S_OK != ::OleLoadPicture(iStream, fileSize, FALSE, IID_IPicture, (void**)&iPicture) ){ - }else{ - HBITMAP hBitmap = NULL; - short imgType = PICTYPE_NONE; - if( S_OK == iPicture->get_Type(&imgType) && imgType == PICTYPE_BITMAP && - S_OK == iPicture->get_Handle((OLE_HANDLE*)&hBitmap) ){ - m_nBackImgWidth = m_nBackImgHeight = 1; - m_hBackImg = (HBITMAP)::CopyImage(hBitmap, IMAGE_BITMAP, 0, 0, 0); - } - } - } - if( iStream ) iStream->Release(); - if( iPicture ) iPicture->Release(); - } - }else{ - m_hBackImg = (HBITMAP)::LoadImage(NULL, path.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); - } - if( m_hBackImg ){ - BITMAP bmp; - GetObject(m_hBackImg, sizeof(BITMAP), &bmp); - m_nBackImgWidth = bmp.bmWidth; - m_nBackImgHeight = bmp.bmHeight; - if( 0 == m_nBackImgWidth || 0 == m_nBackImgHeight ){ - ::DeleteObject(m_hBackImg); - m_hBackImg = NULL; - } + + using namespace Microsoft::WRL; + ComPtr pIWICFactory; + HRESULT hr; + hr = CoCreateInstance( + CLSID_WICImagingFactory, + NULL, + CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(&pIWICFactory)); + if( FAILED(hr) ) return; + ComPtr pDecoder; + hr = pIWICFactory->CreateDecoderFromFilename( + path.c_str(), + NULL, + GENERIC_READ, + WICDecodeMetadataCacheOnLoad, + &pDecoder); + if( FAILED(hr) ) return; + ComPtr pFrame; + hr = pDecoder->GetFrame(0, &pFrame); + if( FAILED(hr) ) return; + //WICPixelFormatGUID pixelFormat; + //hr = pFrame->GetPixelFormat(&pixelFormat); + //if( FAILED(hr) ) return; + ComPtr pConverter; + pIWICFactory->CreateFormatConverter(&pConverter); + if( FAILED(hr) ) return; + hr = pConverter->Initialize( + pFrame.Get(), + GUID_WICPixelFormat32bppPBGRA, + WICBitmapDitherTypeNone, + NULL, + 0.f, + WICBitmapPaletteTypeCustom); + if( FAILED(hr) ) return; + UINT width, height; + hr = pConverter->GetSize(&width, &height); + if( FAILED(hr) ) return; + BITMAPINFO bminfo = {0}; + BITMAPINFOHEADER& bmih = bminfo.bmiHeader; + bmih.biSize = sizeof(BITMAPINFOHEADER); + bmih.biWidth = (LONG)width; + bmih.biHeight = -(LONG)height; + bmih.biPlanes = 1; + bmih.biBitCount = 32; + bmih.biCompression = BI_RGB; + HDC hdcScreen = GetDC(NULL); + if( !hdcScreen ) return; + void *pvImageBits = NULL; + m_hBackImg = CreateDIBSection(hdcScreen, &bminfo, DIB_RGB_COLORS, &pvImageBits, NULL, 0); + ReleaseDC(NULL, hdcScreen); + if( !m_hBackImg ) return; + UINT lineStride = 4 * width; + hr = pConverter->CopyPixels( + NULL, + lineStride, + lineStride * height, + (BYTE*)pvImageBits); + if( FAILED(hr) ){ + ::DeleteObject(m_hBackImg); + m_hBackImg = NULL; } + m_nBackImgWidth = (int)width; + m_nBackImgHeight = (int)height; } /* 全ビューの初期化:ファイルオープン/クローズ時等に、ビューを初期化する */ diff --git a/sakura_core/typeprop/CPropTypesWindow.cpp b/sakura_core/typeprop/CPropTypesWindow.cpp index a96aab995c..b35faf8d02 100644 --- a/sakura_core/typeprop/CPropTypesWindow.cpp +++ b/sakura_core/typeprop/CPropTypesWindow.cpp @@ -141,7 +141,7 @@ INT_PTR CPropTypesWindow::DispatchEvent( case IDC_BUTTON_BACKIMG_PATH_SEL: { CDlgOpenFile::SelectFile(hwndDlg, GetDlgItem(hwndDlg, IDC_EDIT_BACKIMG_PATH), - _T("*.bmp;*.jpg;*.jpeg"), true, EFITER_NONE ); + _T("*.bmp;*.jpg;*.jpeg;*.png"), true, EFITER_NONE ); } return TRUE; // From Here Sept. 10, 2000 JEPRO diff --git a/sakura_core/view/CEditView_Paint.cpp b/sakura_core/view/CEditView_Paint.cpp index 55680d5061..3d4b671f74 100644 --- a/sakura_core/view/CEditView_Paint.cpp +++ b/sakura_core/view/CEditView_Paint.cpp @@ -26,6 +26,7 @@ #include "StdAfx.h" #include #include +#pragma comment(lib, "Msimg32.lib") #include "view/CEditView_Paint.h" #include "view/CEditView.h" #include "view/CViewFont.h" @@ -198,6 +199,8 @@ void CEditView::DrawBackImage(HDC hdc, RECT& rcPaint, HDC hdcBgImg) #else CTypeSupport cTextType(this,COLORIDX_TEXT); COLORREF colorOld = ::SetBkColor(hdc, cTextType.GetBackColor()); + MyFillRect(hdc, rcPaint); + const CTextArea& area = GetTextArea(); const CEditDoc& doc = *m_pcEditDoc; const STypeConfig& typeConfig = doc.m_cDocType.GetDocumentAttribute(); @@ -279,20 +282,29 @@ void CEditView::DrawBackImage(HDC hdc, RECT& rcPaint, HDC hdcBgImg) CMyRect rcBltAll; rcBltAll.SetLTRB(INT_MAX, INT_MAX, -INT_MAX, -INT_MAX); CMyRect rcImagePosOrg = rcImagePos; + BLENDFUNCTION bf; + bf.BlendOp = AC_SRC_OVER; + bf.BlendFlags = 0; + bf.SourceConstantAlpha = 0xFF; + bf.AlphaFormat = AC_SRC_ALPHA; for(; rcImagePos.top <= nYEnd; ){ for(; rcImagePos.left <= nXEnd; ){ CMyRect rcBlt; if( ::IntersectRect(&rcBlt, &rc, &rcImagePos) ){ - ::BitBlt( + int width = rcBlt.right - rcBlt.left; + int height = rcBlt.bottom - rcBlt.top; + ::AlphaBlend( hdc, rcBlt.left, rcBlt.top, - rcBlt.right - rcBlt.left, - rcBlt.bottom - rcBlt.top, + width, + height, hdcBgImg, rcBlt.left - rcImagePos.left, rcBlt.top - rcImagePos.top, - SRCCOPY + width, + height, + bf ); rcBltAll.left = t_min(rcBltAll.left, rcBlt.left); rcBltAll.top = t_min(rcBltAll.top, rcBlt.top); @@ -336,8 +348,6 @@ void CEditView::DrawBackImage(HDC hdc, RECT& rcPaint, HDC hdcBgImg) if( y3 < y4 ){ rcFill.SetLTRB(x1,y3, x4,y4); MyFillRect(hdc, rcFill); } - }else{ - MyFillRect(hdc, rc); } ::SetBkColor(hdc, colorOld); #endif diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index 61ad2acbc6..1a408f5d5a 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -50,4 +50,4 @@ elseif (MINGW) list (TRANSFORM ALL_O REPLACE "\\.(cpp|rc)$" ".o") target_link_libraries (${project_name} PRIVATE ${ALL_O}) endif () -target_link_libraries (${project_name} PRIVATE winspool ole32 oleaut32 uuid comctl32 imm32 mpr imagehlp shlwapi winmm) +target_link_libraries (${project_name} PRIVATE winspool ole32 oleaut32 uuid comctl32 imm32 mpr imagehlp shlwapi winmm windowscodecs msimg32)