Thank you everybody for your suggestions.
Things are already done using DIB and pointers, the overall speed is now very good, thus this thread is over.
------------------
Patrice Terrier
mailto

#Compile Exe #Register None #Dim All #Include "win32api.inc" #Resource "gt1.pbr" ' #1 #2 Function MixColor (hWndDst As Long, hWndSrc1 As Long, hWndSrc2 As Long, percent As Long) As Long Register i As Long, j As Long Dim k As Long, p1 As Long, p2 As Long Dim rc As RECT, pWidth As Long, pHeight As Long Dim hWnd(2) As Long, Bm(2) As BITMAP, hTmpBmp(2) As Long, hDC(2) As Long, hTmpDC(2) As Long Dim bmi As BITMAPINFO, pBits0 As Byte Ptr, pBits1 As Byte Ptr, pBits2 As Byte Ptr hWnd(0) = hWndDst: hWnd(1) = hWndSrc1: hWnd(2) = hWndSrc2 For k = 2 To 0 Step -1 hDC(k) = GetDC(hWnd(k)) hTmpDC(k) = CreateCompatibleDC (hDC(k)) If k = 2 Then GetClientRect hWnd(k), rc pWidth = rc.nRight - rc.nLeft pHeight = rc.nBottom - rc.nTop bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader) bmi.bmiHeader.biWidth = pWidth bmi.bmiHeader.biHeight = pHeight bmi.bmiHeader.biPlanes = 1 bmi.bmiHeader.biBitCount = 32 bmi.bmiHeader.biCompression = %BI_RGB End If hTmpBmp(k) = CreateDIBSection(hTmpDC(k), bmi, %DIB_RGB_COLORS, 0, 0, 0) GlobalLock hTmpBmp(k): SelectObject hTmpDC(k), hTmpBmp(k) If k <> 0 Then BitBlt hTmpDC(k), 0, 0, pWidth, pHeight, hDC(k), 0, 0, %SRCCOPY GetObject hTmpBmp(k), SizeOf(bm(k)), bm(k) If k = 0 Then pBits0 = bm(k).bmBits Else _ If k = 1 Then pBits1 = bm(k).bmBits Else pBits2 = bm(k).bmBits p1 = 100 - percent: p2 = percent If k = 0 Then For j = pHeight - 1 To 0 Step - 1 For i = 0 To pWidth - 1 @pBits0[2] = ((p1 * @pBits1[2] + p2 * @pBits2[2])) \ 100 @pBits0[1] = ((p1 * @pBits1[1] + p2 * @pBits2[1])) \ 100 @pBits0[0] = ((p1 * @pBits1[0] + p2 * @pBits2[0])) \ 100 pBits0 = pBits0 + 4: pBits1 = pBits1 + 4: pBits2 = pBits2 + 4 Next Next BitBlt hDC(k), 0, 0, pWidth, pHeight, hTmpDC(k), 0, 0, %SRCCOPY End If Next For k = 0 To 2: ReleaseDC hWnd(k), hDC(k): DeleteDC hTmpDC(k): _ DeleteObject hTmpBmp(k): Next End Function CallBack Function DlgProc Select Case CbMsg Dim t1 As Single, t2 As Single Case %WM_COMMAND If CbCtl = 104 Then t1 = Timer MixColor GetDlgItem(CbHndl, 103), GetDlgItem(CbHndl, 101), _ GetDlgItem(CbHndl, 102), 40 t2 = Timer SetWindowText CbHndl, Format$(1000 * (t2 - t1), "# ms") End If End Select End Function Function PbMain Dim hDlg As Long Dialog New 0, "", , , 420, 400, %WS_CAPTION Or %WS_SYSMENU To hDlg Control Add ImageX, hDlg, 101, "#1", 10, 10, 400, 100 Control Add ImageX, hDlg, 102, "#2", 10, 120, 400, 100 Control Add Label, hDlg, 103, "", 10, 240, 400, 100 Control Add Button, hDlg, 104, "Mix", 10, 360, 400, 15 Dialog Show Modal hDlg Call DlgProc End Function
FUNCTION GetRValue?(BYVAL Colr&) FUNCTION = (Colr& AND &h0000FF&) END FUNCTION FUNCTION GetGValue?(BYVAL Colr&) FUNCTION = (Colr& AND &h00FF00&) \ &h100& END FUNCTION FUNCTION GetBValue?(BYVAL Colr&) FUNCTION = (Colr& AND &hFF0000&) \ &h10000& END FUNCTION
FUNCTION GetRValue?(BYVAL Colr&) FUNCTION = (Colr& AND &H000000FF???) END FUNCTION FUNCTION GetGValue?(BYVAL Colr&) SHIFT RIGHT Colr&, 8 FUNCTION = (Colr& AND &H000000FF???) END FUNCTION FUNCTION GetBValue?(BYVAL Colr&) SHIFT RIGHT Colr&, 16 FUNCTION = (Colr& AND &H000000FF???) END FUNCTION FUNCTION skTransRGB&(BYVAL hDC1&, BYVAL x1&, BYVAL y1&, BYVAL hDC2&, BYVAL x2&, BYVAL y2&, BYVAL Percent&) EXPORT ' Get the color of the first picture and extract the r&,g&,b& values Colr1& = GetPixel(hDC1&, x1&, y1&) r1& = GetRValue(Colr1&) b1& = GetBValue(Colr1&) g1& = GetGValue(Colr1&) ' Get the color of the second picture and extract the r&,g&,b& values Colr2& = GetPixel(hDC2&, x2&, y2&) r2& = GetRValue(Colr2&) b2& = GetBValue(Colr2&) g2& = GetGValue(Colr2&) ' Mix the colors based on the specified percent& to create a new color ' that's a perfect combination of the previous two Complement& = 100 - percent& r& = ((Complement& * r1&) + (percent& * r2&)) \ 100 g& = ((Complement& * g1&) + (percent& * g2&)) \ 100 b& = ((Complement& * b1&) + (percent& * b2&)) \ 100 FUNCTION = RGB(r&, g&, b&) END FUNCTION ' Performs transluscency SUB skTransLusBlt(BYVAL hDC&, _ BYVAL xDest&, BYVAL yDest&, BYVAL nWidth&, BYVAL nHeight&, _ BYVAL hSrcBMP&, _ BYVAL xSrc&, BYVAL ySrc&, _ BYVAL Percent&) EXPORT ' hDC& Destination device context ' xDest&, yDest& Upper-left destination coordinates (pixels) ' nWidth& Width of destination ' nHeight& Height of destination ' hSrcBMP& Handle of the source bitmap ' xSrc&, ySrc& Upper-left source coordinates (pixels) ' Percent& Tansluscency percentage ' ' 32-Bit Transluscency BitBlt Function REGISTER x&, y& hSrcDC& = CreateCompatibleDC(hDC&) CALL SelectObject(hSrcDC&, hSrcBMP&) '*'IF TransColor& < 0 THEN TransColor& = GetPixel(hSrcDC&, 0, 0) ResultDC& = CreateCompatibleDC(hDC&) hResultBmp& = CreateCompatibleBitmap(hDC&, nWidth&, nHeight&) hDestPrevBmp& = SelectObject(ResultDC&, hResultBmp&) CALL BitBlt(ResultDC&, 0, 0, nWidth&, nHeight&, hDC&, xDest&, yDest&, %SRCCOPY) '*'WasPercent& = Percent& FOR x& = xDest& TO nWidth& - 1 FOR y& = yDest& TO nHeight& - 1 '*'IF GetPixel(hSrcDC&, x&, y&) = TransColor& THEN Percent& = 0 PixelColr& = skTransRGB(hDC&, x&, y&, hSrcDC&, x&, y&, Percent&) CALL SetPixel(ResultDC&, x&, y&, PixelColr&) '*'Percent& = WasPercent& NEXT NEXT ' Display transparent bitmap on background. CALL BitBlt(hDC&, xDest&, yDest&, nWidth&, nHeight&, ResultDC&, 0, 0, %SRCCOPY) ' Select original objects back. CALL SelectObject(ResultDC&, hDestPrevBmp&) ' Deallocate system resources. CALL DeleteObject(hResultBmp&) CALL DeleteDC(ResultDC&) CALL DeleteDC(hSrcDC&) END SUB
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: