Announcement

Collapse
No announcement yet.

Which API function to use?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Which API function to use?

    I am working on a project with a framegrabber and finally managed to get a frame on the screen. The problem is that I draw the frame using the DrawPixel function (contained in gfxtools dll). The image is saved in memory at xxxx (the framegrabber software has a function that returns a pointer) and each pixel is 1 byte. Now what is the function to use to display this fast?

    SetDIBitsToDevice? If so, does someone has some good info about this function?

    Any help is welcome (necessary ;-) )

  • #2
    Hi
    If I correctly have understood you ...
    I use something like...
    ---------------------
    VARPIX=VARPTR(PIXX(1).PIXEL(1))- My color data (~10000 x ~10000)
    Hwnd - My window for draw

    ---- It is necessary to fill BI (AS BITMAPINFO)
    for palette : (256 colors)
    PALL - my palette

    FOR J=0 TO 255
    BI.BMICOLORS(J).rgbBlue = pall.pal(1,J)
    BI.BMICOLORS(J).rgbGreen = pall.pal(2,J)
    BI.BMICOLORS(J).rgbRed = pall.pal(3,J)
    NEXT J

    BI.BMIHEADER.BISIZE = 40
    BI.BMIHEADER.BIWIDTH = %X_DL
    BI.BMIHEADER.BIHeight = %Y_DL
    BI.BMIHEADER.BIPLANES = 1
    BI.BMIHEADER.BIBITCOUNT = 8

    ----------------------
    HDC1=GETDC(Hwnd)
    hMemDC1 = CreateCompatibleDC(hDC1)
    ' SetStretchBltMode hdc1,%COLORONCOLOR
    HBMP1=CreateDIBSECTION(HmemDC1,BI,%DIB_RGB_COLORS,LPBIT,0,0)
    Selectobject HMEMDC1,hbmp1


    '------------------------
    ....
    Surpass of the data for drawing

    ! PUSHA
    ! xor edx,edx
    ! MOV EBX,VARPIX ;LARGE DATA>>>>>>>>>>>
    ! ADD EBX,REALXPARAM
    ! ADD EBX,%XPM
    ! MOV EAX,%XP
    ! MUL REALYPARAM
    ! ADD EAX,EBX
    ! MOV EDI,LPBIT ;~ MY =window=<<<<<<<<<<<
    ! MOV EDX,%Y_DL
    XXX2:
    ! MOV CX,124 ;125x1000
    ! MOV ESI,EAX
    ! REP MOVSD
    ! SUB EAX,%XP
    ! DEC EDX
    ! CMP EDX,0
    ! JNZ XXX2
    ! POPA

    BITBLT HDC1,2,2,%X_DL,%Y_DL,HMEMDC1,0,0,%SRCCOPY
    GetClientRect hctl1, Rct
    InvalidateRect hctl1, BYVAL %NULL, %FALSE 'for me !
    UpdateWindow hctl1
    ...

    The attention,
    is necessary to observe rules WM _ PAINT, or use CS _ OWNDC for your window of a conclusion and Clearing of a context.

    My example not absolutely complete, but principle is shown
    (It is pieces of real, working code and very fast)


    V.Shulakov

    ------------------
    Spherical Panorama Inc. Virtual Reality for: Real Estate, Tourism Advertisment.

    Comment


    • #3
      Thierry --

      I'm not sure I understand what you're asking, but here goes...

      The Graphics Tools DrawPixel function only works within the boundaries of the Graphics Tools graphics window, so I assume you're drawing a frame in that area and that you want to "grab" that rectangle and display it somewhere else on the screen.

      (As a side note, I'd recommend using the DrawFocus function instead of DrawPixel. It draws a rectangle that is guaranteed to be visible over any background, and it can be "un-drawn" very easily when you want to get rid of it.)

      As far as "grabbing" the rectangular area, why not just use the Graphics Tools SaveGfxArea function? It can create a standard-format bitmap file that can be displayed outside the graphics window very easily using the API, or it can paste the rectangle to the Windows clipboard.

      If you are intent on using your own "grab" function, it seems to me that the answer to your question depends on what your pointer points to. Did you write the frame-grabbing software or is it a third-party package? If it points to a complete bitmap (with a header, color info, etc.)
      you would use a different technique than if it is "raw" pixel data.

      Hmmm... Maybe I should add "save to memory buffer" to the SaveGfxArea function, to make things like this easier to do? Would that help? I could do that very easily and send you a new DLL later today.

      -- Eric

      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>

      "Not my circus, not my monkeys."

      Comment


      • #4
        I think that my explanation wasn't sufficient...
        Sorry, my brains thinks one thing but my fingers type it a bit different.

        To explain things a bit further here is some small code that I used to get and display a frame in a graphics window using the InitGfx function (gfxtools dll)

        Hope someone can help me out.

        Vladimir, I will look further at your suggestion altough I find it a bit difficult to understand (certainly with the assembler commands involved)

        To Eric, thanks for your help but it seems that we were talking about different things.
        By the way, you really developed a good graphics dll, I am just a bit dissapointed with the performance if I save a graphics area to disk. When I do something similar with Visual Basic (saving the picture in a imagecontrol to disk) it is a lot faster. Suggestions?

        TX


        ' initialize hardware and allocate buffer for 1 frame
        ' FrameArrayPtr contains a pointer to a array of pointers to
        ' the picture buffer. (we only want to get 1 frame so it isn't
        ' really an array

        FrameArrayPtr = el__InitHW (BoardID, 0, 0, 0, 1, 0, 0)

        IF FrameArrayPtr = 0 THEN
        MSGBOX "Hardware initialization failed!"
        ELSE
        ' get first pointer from array of pointers
        FrameArray = @FrameArrayPtr

        ' get 1 frame
        ErrorCode = el__Acquire (BoardID, 0)

        IF ErrorCode = 0 THEN
        WHILE el__TestAcq (BoardID) = 1
        ' wait until acquisition is done...
        WEND

        ' display frame
        FOR y = 0 TO 479
        FOR x = 0 TO 639
        DrawColor = hsw(0, 0, @FrameArray)
        DrawPixel x, y, DrawColor
        INCR FrameArray
        NEXT x
        NEXT y

        END IF
        END IF
        END IF

        END IF


        ------------------

        Comment

        Working...
        X