Results 1 to 12 of 12

Thread: Resolved - 8 bit DIB

  1. #1

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Resolved - 8 bit DIB

    How would I go about using SetDiBits using a 1-d array?

    I tried... but I got a illegal operation and VB crashed.

    Thanks,
    Last edited by DiGiTaIErRoR; Oct 8th, 2003 at 04:59 AM.

  2. #2

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Ok.... this is what I'm going for....

    I have a paletted image(byte data). And what I need to do is process the bytes and generate a picture as fast as possible.

    I would assume that you'd set the device's palette and then somehow insert a 1-D DIB into it.

    Quite a somehow...

  3. #3
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    Tried SetDiBits without success. If you need me to make a 1d version of this I will be happy to do so.

    VB Code:
    1. Private Type RGBQUAD
    2.  Blue  As Byte
    3.  Green As Byte
    4.  Red   As Byte
    5.  Alpha As Byte
    6. End Type
    7.  
    8. Private Type BITMAPINFOHEADER '40 bytes
    9.     biSize As Long
    10.     biWidth As Long
    11.     biHeight As Long
    12.     biPlanes As Integer
    13.     biBitCount As Integer
    14.     biCompression As Long
    15.     biSizeImage As Long
    16.     biXPelsPerMeter As Long
    17.     biYPelsPerMeter As Long
    18.     biClrUsed As Long
    19.     biClrImportant As Long
    20. End Type
    21. Private Type BITMAPINFO
    22.     bmiHeader As BITMAPINFOHEADER
    23.     bmiColors(0 To 255) As RGBQUAD
    24. End Type
    25. Private Const BI_RGB = 0&
    26. Private Const DIB_RGB_COLORS = 0
    27.  
    28. Dim BM_256 As BITMAPINFO
    29.  
    30. Dim Bytes8() As Byte
    31. Dim PadBytes8 As Long
    32.  
    33. Dim X As Long
    34. Dim Y As Long
    35.  
    36. Dim Wide As Integer
    37. Dim High As Integer
    38.  
    39. Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, _
    40.  ByVal X As Long, ByVal Y As Long, _
    41.  ByVal DesW As Long, ByVal DesH As Long, _
    42.  ByVal SrcXOffset As Long, ByVal SrcYOffset As Long, _
    43.  ByVal SrcW As Long, ByVal SrcH As Long, _
    44.   lpBits As Any, lpBitsInfo As BITMAPINFO, _
    45.  ByVal wUsage As Long, ByVal dwRop As Long) As Long
    46.  
    47.  
    48. Private Sub Form_Activate()
    49.  
    50.  ScaleMode = vbPixels
    51.  
    52.  DoEvents
    53.  
    54.  Wide = 250
    55.  High = 200
    56.  
    57.  With BM_256.bmiHeader
    58.   .biBitCount = 8
    59.   .biWidth = Wide
    60.   .biHeight = High
    61.   .biClrImportant = 256
    62.   .biClrUsed = 256
    63.   .biSize = Len(BM_256.bmiHeader)
    64.  
    65.   PadBytes8 = 4 - Wide Mod 4
    66.   If PadBytes8 = 4 Or .biBitCount = 32 Then PadBytes8 = 0
    67.  
    68.   .biSizeImage = (Wide * .biBitCount / 8 + PadBytes8) * High
    69.   .biCompression = BI_RGB
    70.   .biPlanes = 1
    71.  End With
    72.  
    73.  For X = 0 To 255
    74.   BM_256.bmiColors(X).Blue = X
    75.   BM_256.bmiColors(X).Green = X
    76.   BM_256.bmiColors(X).Red = X
    77.  Next
    78.  
    79.  ReDim Bytes8(1 To (Wide + PadBytes8) * BM_256.bmiHeader.biBitCount / 8, 1 To High)
    80.  
    81.  For Y = 1 To High
    82.   For X = 1 To Wide
    83.    Bytes8(X, Y) = 255 * X / Wide
    84.   Next
    85.  Next
    86.  
    87.  If StretchDIBits(Form1.hdc, 0, 0, Wide, High, 0, 0, Wide, High, _
    88.                   Bytes8(1, 1), _
    89.                   BM_256, DIB_RGB_COLORS, vbSrcCopy) = 0 Then
    90.                  
    91.      Caption = "Blit Error!"
    92.  
    93.  End If
    94.  
    95. End Sub

  4. #4

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Thanks.

    This works:

    VB Code:
    1. res = SetDIBits(Form1.hdc, Form1.Image.Handle, 0, 200, Bytes8(1, 1), BM_256, 0)

  5. #5

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    The Y is inverted. Is there anyway to correct that?

    I'd like to be able to copymemory into Bytes8.

    It's the only way I can think of that'll be ultra-fast.

    Is it possible make Bytes8 1-d and forward?

  6. #6
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    "The Y is inverted. Is there anyway to correct that?"

    y=height-y
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  7. #7

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Originally posted by cyborg
    "The Y is inverted. Is there anyway to correct that?"

    y=height-y
    Yea... besides that.

    This needs to be as fast as possible.

  8. #8
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    change:
    VB Code:
    1. For Y = 1 To High
    2.   For X = 1 To Wide
    3.    Bytes8(X, Y) = 255 * X / Wide
    4.   Next
    5.  Next
    to:
    VB Code:
    1. For Y = 1 To High
    2.   For X = 1 To Wide
    3.    Bytes8(X, High - Y) = 255 * X / Wide
    4.   Next
    5.  Next
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  9. #9
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    Here is the 1D version. cyborg I was unable to get SetDiBits working with what you posted

    VB Code:
    1. Private Type RGBQUAD
    2.  Blue  As Byte
    3.  Green As Byte
    4.  Red   As Byte
    5.  Alpha As Byte
    6. End Type
    7.  
    8. Private Type BITMAPINFOHEADER '40 bytes
    9.     biSize As Long
    10.     biWidth As Long
    11.     biHeight As Long
    12.     biPlanes As Integer
    13.     biBitCount As Integer
    14.     biCompression As Long
    15.     biSizeImage As Long
    16.     biXPelsPerMeter As Long
    17.     biYPelsPerMeter As Long
    18.     biClrUsed As Long
    19.     biClrImportant As Long
    20. End Type
    21. Private Type BITMAPINFO
    22.     bmiHeader As BITMAPINFOHEADER
    23.     bmiColors(0 To 255) As RGBQUAD
    24. End Type
    25.  
    26. Private Type SAFEARRAY1D
    27.     cDims As Integer
    28.     fFeatures As Integer
    29.     cbElements As Long
    30.     cLocks As Long
    31.     pvData As Long
    32.     cElements As Long
    33.     lLbound As Long
    34. End Type
    35.  
    36. Private Const BI_RGB& = 0&
    37. Private Const DIB_RGB_COLORS& = 0&
    38.  
    39. Dim BM_256 As BITMAPINFO
    40.  
    41. Dim Bytes8() As Byte
    42. Dim PadBytes8 As Long
    43.  
    44. Dim X As Long
    45. Dim Y As Long
    46.  
    47. Dim Wide As Integer
    48. Dim High As Integer
    49. Dim DrawWidthBytes&
    50. Dim AddDrawWidth&
    51. Dim BufUbound&
    52. Dim TopLeft&
    53. Dim DrawLeft&
    54. Dim DrawRight&
    55.  
    56. Dim Res&
    57.  
    58. Private Declare Function StretchDIBits Lib "gdi32" (ByVal hDC As Long, _
    59.  ByVal X As Long, ByVal Y As Long, _
    60.  ByVal DesW As Long, ByVal DesH As Long, _
    61.  ByVal SrcXOffset As Long, ByVal SrcYOffset As Long, _
    62.  ByVal SrcW As Long, ByVal SrcH As Long, _
    63.   lpBits As Any, lpBitsInfo As BITMAPINFO, _
    64.  ByVal wUsage As Long, ByVal dwRop As Long) As Long
    65.  
    66. Private Sub Form_Activate()
    67.  
    68.  ScaleMode = vbPixels
    69.  
    70.  DoEvents
    71.  
    72.  Wide = 250
    73.  High = 200
    74.  
    75.  With BM_256.bmiHeader
    76.   .biBitCount = 8
    77.   .biWidth = Wide
    78.   .biHeight = High
    79.   .biClrImportant = 256
    80.   .biClrUsed = 256
    81.   .biSize = Len(BM_256.bmiHeader)
    82.  
    83.   PadBytes8 = 4 - Wide Mod 4
    84.   If PadBytes8 = 4 Or .biBitCount = 32 Then PadBytes8 = 0
    85.  
    86.   DrawWidthBytes = Wide * .biBitCount / 8 + PadBytes8
    87.   .biSizeImage = DrawWidthBytes * High
    88.  
    89.   .biCompression = BI_RGB
    90.   .biPlanes = 1
    91.  End With
    92.  
    93.  For X = 0 To 255
    94.   BM_256.bmiColors(X).Blue = X
    95.   BM_256.bmiColors(X).Green = X
    96.   BM_256.bmiColors(X).Red = X
    97.  Next
    98.  
    99.  BufUbound = DrawWidthBytes * High - 1
    100.  
    101.  ReDim Bytes8(BufUbound)
    102.  
    103.  AddDrawWidth = Wide - 1
    104.  TopLeft = DrawWidthBytes * (High - 1)
    105.  
    106.  For Y = 0 To TopLeft Step DrawWidthBytes
    107.   X = 0
    108.   DrawRight = Y + AddDrawWidth
    109.   For Res = Y To DrawRight
    110.    Bytes8(Res) = 255 * X / Wide
    111.    X = X + 1
    112.   Next
    113.  Next
    114.  
    115.  If StretchDIBits(Form1.hDC, 0, 0, Wide, High, 0, 0, Wide, High, _
    116.                   Bytes8(0), _
    117.                   BM_256, DIB_RGB_COLORS, vbSrcCopy) = 0 Then
    118.                  
    119.      Caption = "Blit Error"
    120.  
    121.  End If
    122.  
    123. End Sub

  10. #10

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Originally posted by cyborg
    change:
    VB Code:
    1. For Y = 1 To High
    2.   For X = 1 To Wide
    3.    Bytes8(X, Y) = 255 * X / Wide
    4.   Next
    5.  Next
    to:
    VB Code:
    1. For Y = 1 To High
    2.   For X = 1 To Wide
    3.    Bytes8(X, High - Y) = 255 * X / Wide
    4.   Next
    5.  Next
    Yes, I know. I coded something similar to that. I just want it to not have to calculate the position for optimal speed.

  11. #11
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    try using this:
    StretchDIBits(Form1.hdc, 0, High, Wide, 0, 0, 0, Wide, High, Bytes8(1, 1), BM_256, DIB_RGB_COLORS, vbSrcCopy)


    i've switched the height and y values...so its drawn from high to y instead of from y to high
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  12. #12
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    "ah," cool thank you. I had tried a negative sign in front of the height parameter but that didn't work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width