[Ttssh2-commit] [4578] OleLoadPicture() で読み込んだBITMAPをストレッチ(拡大・縮小)できるようにした。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 8月 13日 (土) 17:26:34 JST


Revision: 4578
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4578
Author:   yutakapon
Date:     2011-08-13 17:26:34 +0900 (Sat, 13 Aug 2011)

Log Message:
-----------
OleLoadPicture() で読み込んだBITMAPをストレッチ(拡大・縮小)できるようにした。

Modified Paths:
--------------
    trunk/doc/en/html/about/history.html
    trunk/doc/ja/html/about/history.html
    trunk/teraterm/teraterm/vtdisp.c


-------------- next part --------------
Modified: trunk/doc/en/html/about/history.html
===================================================================
--- trunk/doc/en/html/about/history.html	2011-08-05 01:10:12 UTC (rev 4577)
+++ trunk/doc/en/html/about/history.html	2011-08-13 08:26:34 UTC (rev 4578)
@@ -45,6 +45,7 @@
           <li>added the second argument as the converted string on the strspecial command.</li>
         </ul></li>
       <li>added the "<a href="../macro/command/expandenv.html">expandenv</a>" macro command.</li>
+      <li>Eterm look-feel: The wallpaper file format can support any format other than BMP on Windows Vista or later.</li>
     </ul>
   </li>
 

Modified: trunk/doc/ja/html/about/history.html
===================================================================
--- trunk/doc/ja/html/about/history.html	2011-08-05 01:10:12 UTC (rev 4577)
+++ trunk/doc/ja/html/about/history.html	2011-08-13 08:26:34 UTC (rev 4578)
@@ -45,6 +45,7 @@
           <li>•ÏŠ·‚·‚镶Žš—ñ‚ð strspecial ƒRƒ}ƒ“ƒh‚ɁA‘æ2ˆø”‚Æ‚µ‚ÄŽw’è‚Å‚«‚é‚悤‚É‚µ‚½B</li>
         </ul></li>
       <li>ƒ}ƒNƒƒRƒ}ƒ“ƒh "<a href="../macro/command/expandenv.html">expandenv</a>" ‚ð’ljÁ‚µ‚½B</li>
+      <li>Eterm look-feel: Windows VistaˆÈ~‚É‚¨‚¢‚āA•ÇŽ†‚ªBMPŒ`Ž®ˆÈŠO‚É‚à‘Ήž‚µ‚½B</li>
     </ul>
   </li>
 

Modified: trunk/teraterm/teraterm/vtdisp.c
===================================================================
--- trunk/teraterm/teraterm/vtdisp.c	2011-08-05 01:10:12 UTC (rev 4577)
+++ trunk/teraterm/teraterm/vtdisp.c	2011-08-13 08:26:34 UTC (rev 4578)
@@ -680,54 +680,171 @@
 	return (hBitmap);
 }
 
-void BGPreloadWallpaper(BGSrc *src)
+// üŒ`•âŠ®–@‚É‚æ‚è”äŠr“I‘N–¾‚Ƀrƒbƒgƒ}ƒbƒv‚ðŠg‘åEk¬‚·‚éB
+// Windows 9x/NT‘Ήž
+// cf.http://katahiromz.web.fc2.com/win32/bilinear.html
+static HBITMAP CreateStretched32BppBitmapBilinear(HBITMAP hbm, INT cxNew, INT cyNew)
 {
-  HBITMAP       hbm;
-  WallpaperInfo wi;
-  OSVERSIONINFO osvi;
+    INT ix, iy, x0, y0, x1, y1;
+    DWORD x, y;
+    BITMAP bm;
+    HBITMAP hbmNew;
+    HDC hdc;
+    BITMAPINFO bi;
+    BYTE *pbNewBits, *pbBits, *pbNewLine, *pbLine0, *pbLine1;
+    DWORD wfactor, hfactor;
+    DWORD ex0, ey0, ex1, ey1;
+    DWORD r0, g0, b0, a0, r1, g1, b1, a1;
+    DWORD c00, c01, c10, c11;
+    LONG nWidthBytes, nWidthBytesNew;
+    BOOL fAlpha;
 
-  BGGetWallpaperInfo(&wi);
+    if (GetObject(hbm, sizeof(BITMAP), &bm) == 0)
+        return NULL;
 
-  //•ÇŽ†‚ð“ǂݍž‚Ý
-  //LR_CREATEDIBSECTION ‚ðŽw’è‚·‚é‚Ì‚ªƒRƒc
-  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-  GetVersionEx(&osvi);
-  if (osvi.dwMajorVersion < 6) {
-    if (wi.pattern == BG_STRETCH) {
-      hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,CRTWidth,CRTHeight,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
+    hbmNew = NULL;
+    hdc = CreateCompatibleDC(NULL);
+    if (hdc != NULL)
+    {
+        nWidthBytes = bm.bmWidth * 4;
+        ZeroMemory(&bi, sizeof(BITMAPINFOHEADER));
+        bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+        bi.bmiHeader.biWidth = bm.bmWidth;
+        bi.bmiHeader.biHeight = bm.bmHeight;
+        bi.bmiHeader.biPlanes = 1;
+        bi.bmiHeader.biBitCount = 32;
+        fAlpha = (bm.bmBitsPixel == 32);
+        pbBits = (BYTE *)HeapAlloc(GetProcessHeap(), 0, 
+                                   nWidthBytes * bm.bmHeight);
+        if (pbBits == NULL)
+            return NULL;
+        GetDIBits(hdc, hbm, 0, bm.bmHeight, pbBits, &bi, DIB_RGB_COLORS);
+        bi.bmiHeader.biWidth = cxNew;
+        bi.bmiHeader.biHeight = cyNew;
+        hbmNew = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS,
+                                  (VOID **)&pbNewBits, NULL, 0);
+        if (hbmNew != NULL)
+        {
+            nWidthBytesNew = cxNew * 4;
+            wfactor = (bm.bmWidth << 8) / cxNew;
+            hfactor = (bm.bmHeight << 8) / cyNew;
+            if (!fAlpha)
+                a0 = 255;
+            for(iy = 0; iy < cyNew; iy++)
+            {
+                y = hfactor * iy;
+                y0 = y >> 8;
+                y1 = min(y0 + 1, (INT)bm.bmHeight - 1);
+                ey1 = y & 0xFF;
+                ey0 = 0x100 - ey1;
+                pbNewLine = pbNewBits + iy * nWidthBytesNew;
+                pbLine0 = pbBits + y0 * nWidthBytes;
+                pbLine1 = pbBits + y1 * nWidthBytes;
+                for(ix = 0; ix < cxNew; ix++)
+                {
+                    x = wfactor * ix;
+                    x0 = x >> 8;
+                    x1 = min(x0 + 1, (INT)bm.bmWidth - 1);
+                    ex1 = x & 0xFF;
+                    ex0 = 0x100 - ex1;
+                    c00 = ((LPDWORD)pbLine0)[x0];
+                    c01 = ((LPDWORD)pbLine1)[x0];
+                    c10 = ((LPDWORD)pbLine0)[x1];
+                    c11 = ((LPDWORD)pbLine1)[x1];
+
+                    b0 = ((ex0 * (c00 & 0xFF)) + 
+                          (ex1 * (c10 & 0xFF))) >> 8;
+                    b1 = ((ex0 * (c01 & 0xFF)) + 
+                          (ex1 * (c11 & 0xFF))) >> 8;
+                    g0 = ((ex0 * ((c00 >> 8) & 0xFF)) + 
+                          (ex1 * ((c10 >> 8) & 0xFF))) >> 8;
+                    g1 = ((ex0 * ((c01 >> 8) & 0xFF)) + 
+                          (ex1 * ((c11 >> 8) & 0xFF))) >> 8;
+                    r0 = ((ex0 * ((c00 >> 16) & 0xFF)) + 
+                          (ex1 * ((c10 >> 16) & 0xFF))) >> 8;
+                    r1 = ((ex0 * ((c01 >> 16) & 0xFF)) + 
+                          (ex1 * ((c11 >> 16) & 0xFF))) >> 8;
+                    b0 = (ey0 * b0 + ey1 * b1) >> 8;
+                    g0 = (ey0 * g0 + ey1 * g1) >> 8;
+                    r0 = (ey0 * r0 + ey1 * r1) >> 8;
+
+                    if (fAlpha)
+                    {
+                        a0 = ((ex0 * ((c00 >> 24) & 0xFF)) + 
+                              (ex1 * ((c10 >> 24) & 0xFF))) >> 8;
+                        a1 = ((ex0 * ((c01 >> 24) & 0xFF)) + 
+                              (ex1 * ((c11 >> 24) & 0xFF))) >> 8;
+                        a0 = (ey0 * a0 + ey1 * a1) >> 8;
+                    }
+                    ((LPDWORD)pbNewLine)[ix] = 
+                        MAKELONG(MAKEWORD(b0, g0), MAKEWORD(r0, a0));
+                }
+            }
+        }
+        HeapFree(GetProcessHeap(), 0, pbBits);
+        DeleteDC(hdc);
     }
-    else {
-      hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,        0,       0,LR_LOADFROMFILE);
-    }
-  }
-  else {
-    if (wi.pattern == BG_STRETCH) {
-      hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,CRTWidth,CRTHeight,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
-      // TODO: ‰æ‘œ‚ð‰æ–Ê‚¢‚Á‚Ï‚¢‚ÉŠg‘å‚·‚é‚ɂ́A‚Ç‚¤‚µ‚½‚ç‚æ‚¢‚©H
-    }
-    else {
-      //hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,        0,       0,LR_LOADFROMFILE);
-      hbm = GetBitmapHandle(wi.filename);
-    }
-  }
+    return hbmNew;
+}
 
-  //•ÇŽ†DC‚ðì‚é
-  if(hbm)
-  {
-    BITMAP bm;
+void BGPreloadWallpaper(BGSrc *src)
+{
+//#define DEBUG_XP
+	HBITMAP       hbm;
+	WallpaperInfo wi;
+	OSVERSIONINFO osvi;
 
-    GetObject(hbm,sizeof(bm),&bm);
+	BGGetWallpaperInfo(&wi);
 
-    src->hdc     = CreateBitmapDC(hbm);
-    src->width   = bm.bmWidth;
-    src->height  = bm.bmHeight;
-    src->pattern = wi.pattern;
+#ifdef DEBUG_XP
+	strcpy(wi.filename, "c:\\usr\\ttssh2\\1011_01.jpg");
+#endif
 
-  }else{
-    src->hdc = NULL;
-  }
+	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+	GetVersionEx(&osvi);
+#ifdef DEBUG_XP
+	osvi.dwMajorVersion = 7;
+#endif
+	if (osvi.dwMajorVersion < 6) {
+		//•ÇŽ†‚ð“ǂݍž‚Ý
+		//LR_CREATEDIBSECTION ‚ðŽw’è‚·‚é‚Ì‚ªƒRƒc
+		if (wi.pattern == BG_STRETCH) {
+			hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,CRTWidth,CRTHeight,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
+		}
+		else {
+			hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,        0,       0,LR_LOADFROMFILE);
+		}
+	}
+	else {
+		hbm = GetBitmapHandle(wi.filename);
 
-  src->color = GetSysColor(COLOR_DESKTOP);
+#ifdef DEBUG_XP
+		wi.pattern = BG_STRETCH; 
+#endif
+		if (wi.pattern == BG_STRETCH) {
+			HBITMAP newhbm = CreateStretched32BppBitmapBilinear(hbm, CRTWidth, CRTHeight);
+			DeleteObject(hbm);
+			hbm = newhbm;
+		}
+	}
+
+	//•ÇŽ†DC‚ðì‚é
+	if(hbm)
+	{
+		BITMAP bm;
+
+		GetObject(hbm,sizeof(bm),&bm);
+
+		src->hdc     = CreateBitmapDC(hbm);
+		src->width   = bm.bmWidth;
+		src->height  = bm.bmHeight;
+		src->pattern = wi.pattern;
+
+	}else{
+		src->hdc = NULL;
+	}
+
+	src->color = GetSysColor(COLOR_DESKTOP);
 }
 
 void BGPreloadSrc(BGSrc *src)



Ttssh2-commit メーリングリストの案内
Back to archive index