[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Image Control/Picture object Palette

Leo

11/4/2011 3:01:00 PM

Can someone provide some examples of how to create a custom palette and
then apply it to a picture object. I am trying to mimick the XP boot
screen using the resources in ntoskrnl.exe. The problem is, they don't
have a palette. The palette entries can be found at
http://www.infocellar.com/winxp/customize-startup-....

--
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-sep...


13 Answers

Mike Williams

11/5/2011 10:44:00 PM

0

"Leo" <ttdhead@gmail.com> wrote in message
news:j90unr$dts$1@dont-email.me...
> Can someone provide some examples of how to create a custom palette
> and then apply it to a picture object. I am trying to mimick the XP boot
> screen using the resources in ntoskrnl.exe. The problem is, they don't
> have a palette. The palette entries can be found at
> http://www.infocellar.com/winxp/customize-startup-....

Actually the XP boot screen bitmap is a standard 4 bit (16 colour) bmp,
although its bitmap data section is RLE compressed, and it does have a
colour palette, it's just that all of its 16 x 32 bit palette entries are
set to zero (effectively black). I've never looked at the XP boot screen
bitmap myself before (apart from when XP is loading of course!) but
according to the link you posted the actual palette data is stored elsewhere
in the ntoskrnl.exe file. The palette data itself can be downloaded from the
link as a .pal file, and you can easily get the bitmap itself out of the
ntoskrnl.exe resource using ResHacker or something similar (a link to that
is also at the page to which you posted a link). But I'm sure you know all
that already. So presumably you just need a way to dump palettes into 4 bit
(16 colour) bitmap files? Is that what you want?

Being an old fashioned guy at heart (from my Commodore 64 days!) I usually
shy away from the 'black boxes' of GDI whenever there is an alternative and
fairly simple old fashioned way to do what I need to do, so if I wanted to
insert a custom palette into an existing 16 colour bmp file I would be
inclined to just dump it straight into the file, as raw data. As an example,
in this specific case, if you have the XP boot screen bitmap named as (say)
BitmapXP.bmp and if you have the desired palette file named as (say)
PaletteXP.pal (both of which you can get using the instructions at the link
you posted) then here, below, is a simple way that you can use VB6 to dump
the palette into the bitmap, bearing in mind that the actual palette data in
a .pal file starts at the 25th byte and the palette data of a 16 colour .bmp
file starts at the 55th byte.

Private Sub Command1_Click()
Dim b(1 To 64) As Byte, temp As Byte, n As Long
Open "c:\temp2\PaletteXP.pal" For Binary As 1
Get #1, 25, b()
Close 1
For n = 1 To 60 Step 4
temp = b(n)
b(n) = b(n + 2)
b(n + 2) = temp
Next n
Open "c:\temp2\BitmapXP.bmp" For Binary As 1
Put #1, 55, b()
Close 1
End Sub

The above code should cause the bmp file (originally all solid black) to
look exactly like the WinXP loading screen when you load the resultant
bitmap into MS Paint or whatever. Once you know the above it should be easy
to create your own custom colour palette and dump that into the bitmap. Or
have I completely misunderstood your question (it wouldn't be unusual for
me!).

Mike










Mike Williams

11/6/2011 10:58:00 PM

0


"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:j94e79$1s0$1@dont-email.me...
> . . . . . here, below, is a simple way that you can use VB6 to
> dump the palette into the bitmap . . . [most of code snipped]
> For n = 1 To 60 Step 4 . . . . .

Actually, on second thoughts, that should have been For n = 1 To 61 Step 4,
otherwise it will miss converting the 16th palette entry. That doesn't
matter in this specific case because the 16th palette entry happens to be
pure white (255, 255, 255, 0) and so the converted entry would be the same
as the original entry, and in fact the 640 x 480 XP startup bitmap does not
use the 16th palette entry anyway (it does not use white), but it is worth
noting for future use. Incidentally, I've had a look at the contents of the
ntoskrnl.exe file and it contains four almost identical palettes, all four
exactly the same with the exception that the 16th palette entry is different
in each case, with the other three actually having the flag byte set to
something other than zero in the 16th entry (the flag byte of 16 colour
bitmap palette entries was sometimes used for palette animation, as I
recall, or at least I used to do something similar on other machines many
years ago). I'm not sure at the moment whether those other three raw
palettes refer to other 'blank palette' bitmaps in the resource, or whether
they are used for the same 640 x 480 bitmap on different machine settings,
although I presume the former since the 16th palette entry is not referenced
in the actual bitmap pixel data for the 640 x 480 bitmap. Anyway, I mention
the 'For n = 1 to 61 Step 4' thing purely for reference, just in case you
wish to use a similar method on other palettes for other purposes.

Mike



Leo

11/16/2011 6:07:00 AM

0

Mike Williams pretended :
> "Leo" <ttdhead@gmail.com> wrote in message news:j90unr$dts$1@dont-email.me...
>> Can someone provide some examples of how to create a custom palette
>> and then apply it to a picture object. I am trying to mimick the XP boot
>> screen using the resources in ntoskrnl.exe. The problem is, they don't have
>> a palette. The palette entries can be found at
>> http://www.infocellar.com/winxp/customize-startup-....
>
> Actually the XP boot screen bitmap is a standard 4 bit (16 colour) bmp,
> although its bitmap data section is RLE compressed, and it does have a colour
> palette, it's just that all of its 16 x 32 bit palette entries are set to
> zero (effectively black). I've never looked at the XP boot screen bitmap
> myself before (apart from when XP is loading of course!) but according to the
> link you posted the actual palette data is stored elsewhere in the
> ntoskrnl.exe file. The palette data itself can be downloaded from the link as
> a .pal file, and you can easily get the bitmap itself out of the ntoskrnl.exe
> resource using ResHacker or something similar (a link to that is also at the
> page to which you posted a link). But I'm sure you know all that already. So
> presumably you just need a way to dump palettes into 4 bit (16 colour) bitmap
> files? Is that what you want?
>
> Being an old fashioned guy at heart (from my Commodore 64 days!) I usually
> shy away from the 'black boxes' of GDI whenever there is an alternative and
> fairly simple old fashioned way to do what I need to do, so if I wanted to
> insert a custom palette into an existing 16 colour bmp file I would be
> inclined to just dump it straight into the file, as raw data. As an example,
> in this specific case, if you have the XP boot screen bitmap named as (say)
> BitmapXP.bmp and if you have the desired palette file named as (say)
> PaletteXP.pal (both of which you can get using the instructions at the link
> you posted) then here, below, is a simple way that you can use VB6 to dump
> the palette into the bitmap, bearing in mind that the actual palette data in
> a .pal file starts at the 25th byte and the palette data of a 16 colour .bmp
> file starts at the 55th byte.
>
> Private Sub Command1_Click()
> Dim b(1 To 64) As Byte, temp As Byte, n As Long
> Open "c:\temp2\PaletteXP.pal" For Binary As 1
> Get #1, 25, b()
> Close 1
> For n = 1 To 60 Step 4
> temp = b(n)
> b(n) = b(n + 2)
> b(n + 2) = temp
> Next n
> Open "c:\temp2\BitmapXP.bmp" For Binary As 1
> Put #1, 55, b()
> Close 1
> End Sub
>
> The above code should cause the bmp file (originally all solid black) to look
> exactly like the WinXP loading screen when you load the resultant bitmap into
> MS Paint or whatever. Once you know the above it should be easy to create
> your own custom colour palette and dump that into the bitmap. Or have I
> completely misunderstood your question (it wouldn't be unusual for me!).
>
> Mike

I was hoping to do it with GDI since I have code to load the resource
from the exe as an hBitmap and then convert that into a picture object.

--
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-sep...


Mike Williams

11/18/2011 10:50:00 AM

0

"Leo" <ttdhead@gmail.com> wrote in message
news:j9vjtn$j33$1@dont-email.me...
> Mike Williams pretended :
>> [waffle snipped]
>> Private Sub Command1_Click()
>> Dim b(1 To 64) As Byte, temp As Byte, n As Long
>> Open "c:\temp2\PaletteXP.pal" For Binary As 1
>> Get #1, 25, b()
>> Close 1
>> For n = 1 To 60 Step 4
>> temp = b(n)
>> b(n) = b(n + 2)
>> b(n + 2) = temp
>> Next n
>> Open "c:\temp2\BitmapXP.bmp" For Binary As 1
>> Put #1, 55, b()
>> Close 1
>> End Sub
>
> Thanks Mike. I was hoping to do it with GDI since I have
> code to load the resource from the exe as an hBitmap and
> then convert that into a picture object.

I really don't like the various Palette 'black boxes', partly because I
never use low bpp images that contain palettes and partly because the MS
documentation on Palettes is at best confusing and at worst misleading and
incomplete. I've just written some test code to load a 16 colour image and
I've come across various problems loading 16 colour images to a hBitmap in
the way that I want them to load when the image has all 16 palette entries
set to black (as is the case with the original WinXP startup bmp you appear
to be working with, where XP appears to assign suitable palette entries from
a separate palette depending on circumstances). I think the first thing you
need to do is to check whether in your case you do actually have the handle
of a 16 colour bitmap, and that its pixel data has not been messed about
with by whatever code you are using to get it. Try the following code on the
hBitmap you are working with and check the output in the message box when
you run it. The code should report that hBitmap refers a 16 colour bitmap
and it should return the number of pixels that refer to each of the 16
Palette entries. For the image you appear to be working with you should get
a lot of pixels using Palette(0) and each of the other 15 Palette entries
should be used by the number of pixels that you might reasonably expect that
particular image to use. If you get something different, perhaps all pixels
using either Palette(0) or Palette(1) and perhaps none at all using the
other 14 Palette entries, then you need to look at your existing code which
gets the image. Anyway, paste the following into a VB Form containing a
Command Button and read the notes in the Command Button click event and run
the code when you have done what the note asks for. Post back with full
details of the result that you get. I have not included much error checking
in what is simply just testbed code and I have written it specifically for
16 colour bitmaps, so don't expect miracles :-)

Mike

Option Explicit
Private Declare Function GetObject Lib "gdi32" _
Alias "GetObjectA" (ByVal hObject As Long, _
ByVal nCount As Long, lpObject As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (pDst As Any, _
pSrc As Any, ByVal ByteLen As Long)
Private Declare Function VarPtrArray _
Lib "msvbvm60.dll" Alias "VarPtr" _
(Ptr() As Any) As Long
Private Type BmpHeader4Bit
bfType As String * 2
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biDataSize As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
palette(0 To 15) As Long
End Type
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Type SAFEARRAY1D
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
cElements As Long
lLbound As Long
End Type

Private Sub AnalyzeBitmap(hBmp1 As Long)
Dim sa1 As SAFEARRAY1D, Bmp As BITMAP
Dim pic() As Byte, n As Long
Dim Header As BmpHeader4Bit
GetObject hBmp1, Len(Bmp), Bmp
If Bmp.bmBitsPixel <> 4 Then
MsgBox "This is not a 16 colour bitmap " _
& "(it reports that it is " _
& Bmp.bmBitsPixel & " bpp)"
Exit Sub
End If
' point pic() Byte array to the bitmap bits data
With sa1
.cbElements = 1 ' one byte per element (Byte array)
.cDims = 1 ' one dimension
.lLbound = 0
.cElements = (Bmp.bmHeight * Bmp.bmWidthBytes)
.pvData = Bmp.bmBits ' bitmap bit data
End With
CopyMemory ByVal VarPtrArray(pic), VarPtr(sa1), 4
' check the bits
Dim j As Byte, k As Byte, s1 As String
Dim pal(0 To 15) As Long
For n = LBound(pic) To UBound(pic)
j = (pic(n) And &HF0) \ &H10
k = pic(n) And &HF
pal(j) = pal(j) + 1
pal(k) = pal(k) + 1
Next n
' clear the array to empty
CopyMemory ByVal VarPtrArray(pic), 0&, 4
s1 = "16 colour bitmap (" & Bmp.bmWidth & " x " _
& Bmp.bmHeight & " pixels)" & vbCrLf & vbCrLf
For n = 0 To 15
s1 = s1 & "Palette Entry (" & Format(n) & ") is used by " _
& Format(pal(n)) & " pixels" & vbCrLf
Next n
MsgBox s1
End Sub

Private Sub Command1_Click()
' put here whatever code you are using to get
' your bitmap handle (into a Long called hBitmap
' in this example) and then use the following:
'
AnalyzeBitmap hBitmap
'
End Sub




Leo

11/18/2011 12:17:00 PM

0

Mike Williams explained :
> "Leo" <ttdhead@gmail.com> wrote in message news:j9vjtn$j33$1@dont-email.me...
>> Mike Williams pretended :
>>> [waffle snipped]
>>> Private Sub Command1_Click()
>>> Dim b(1 To 64) As Byte, temp As Byte, n As Long
>>> Open "c:\temp2\PaletteXP.pal" For Binary As 1
>>> Get #1, 25, b()
>>> Close 1
>>> For n = 1 To 60 Step 4
>>> temp = b(n)
>>> b(n) = b(n + 2)
>>> b(n + 2) = temp
>>> Next n
>>> Open "c:\temp2\BitmapXP.bmp" For Binary As 1
>>> Put #1, 55, b()
>>> Close 1
>>> End Sub
>>
>> Thanks Mike. I was hoping to do it with GDI since I have
>> code to load the resource from the exe as an hBitmap and
>> then convert that into a picture object.
>
> I really don't like the various Palette 'black boxes', partly because I never
> use low bpp images that contain palettes and partly because the MS
> documentation on Palettes is at best confusing and at worst misleading and
> incomplete. I've just written some test code to load a 16 colour image and
> I've come across various problems loading 16 colour images to a hBitmap in
> the way that I want them to load when the image has all 16 palette entries
> set to black (as is the case with the original WinXP startup bmp you appear
> to be working with, where XP appears to assign suitable palette entries from
> a separate palette depending on circumstances). I think the first thing you
> need to do is to check whether in your case you do actually have the handle
> of a 16 colour bitmap, and that its pixel data has not been messed about with
> by whatever code you are using to get it. Try the following code on the
> hBitmap you are working with and check the output in the message box when you
> run it. The code should report that hBitmap refers a 16 colour bitmap and it
> should return the number of pixels that refer to each of the 16 Palette
> entries. For the image you appear to be working with you should get a lot of
> pixels using Palette(0) and each of the other 15 Palette entries should be
> used by the number of pixels that you might reasonably expect that particular
> image to use. If you get something different, perhaps all pixels using either
> Palette(0) or Palette(1) and perhaps none at all using the other 14 Palette
> entries, then you need to look at your existing code which gets the image.
> Anyway, paste the following into a VB Form containing a Command Button and
> read the notes in the Command Button click event and run the code when you
> have done what the note asks for. Post back with full details of the result
> that you get. I have not included much error checking in what is simply just
> testbed code and I have written it specifically for 16 colour bitmaps, so
> don't expect miracles :-)
>
> Mike
>
> Option Explicit
> Private Declare Function GetObject Lib "gdi32" _
> Alias "GetObjectA" (ByVal hObject As Long, _
> ByVal nCount As Long, lpObject As Any) As Long
> Private Declare Sub CopyMemory Lib "kernel32" _
> Alias "RtlMoveMemory" (pDst As Any, _
> pSrc As Any, ByVal ByteLen As Long)
> Private Declare Function VarPtrArray _
> Lib "msvbvm60.dll" Alias "VarPtr" _
> (Ptr() As Any) As Long
> Private Type BmpHeader4Bit
> bfType As String * 2
> bfSize As Long
> bfReserved1 As Integer
> bfReserved2 As Integer
> bfOffBits As Long
> biSize As Long
> biWidth As Long
> biHeight As Long
> biPlanes As Integer
> biBitCount As Integer
> biCompression As Long
> biDataSize As Long
> biXPelsPerMeter As Long
> biYPelsPerMeter As Long
> biClrUsed As Long
> biClrImportant As Long
> palette(0 To 15) As Long
> End Type
> Private Type BITMAP
> bmType As Long
> bmWidth As Long
> bmHeight As Long
> bmWidthBytes As Long
> bmPlanes As Integer
> bmBitsPixel As Integer
> bmBits As Long
> End Type
> Private Type SAFEARRAY1D
> cDims As Integer
> fFeatures As Integer
> cbElements As Long
> cLocks As Long
> pvData As Long
> cElements As Long
> lLbound As Long
> End Type
>
> Private Sub AnalyzeBitmap(hBmp1 As Long)
> Dim sa1 As SAFEARRAY1D, Bmp As BITMAP
> Dim pic() As Byte, n As Long
> Dim Header As BmpHeader4Bit
> GetObject hBmp1, Len(Bmp), Bmp
> If Bmp.bmBitsPixel <> 4 Then
> MsgBox "This is not a 16 colour bitmap " _
> & "(it reports that it is " _
> & Bmp.bmBitsPixel & " bpp)"
> Exit Sub
> End If
> ' point pic() Byte array to the bitmap bits data
> With sa1
> .cbElements = 1 ' one byte per element (Byte array)
> .cDims = 1 ' one dimension
> .lLbound = 0
> .cElements = (Bmp.bmHeight * Bmp.bmWidthBytes)
> .pvData = Bmp.bmBits ' bitmap bit data
> End With
> CopyMemory ByVal VarPtrArray(pic), VarPtr(sa1), 4
> ' check the bits
> Dim j As Byte, k As Byte, s1 As String
> Dim pal(0 To 15) As Long
> For n = LBound(pic) To UBound(pic)
> j = (pic(n) And &HF0) \ &H10
> k = pic(n) And &HF
> pal(j) = pal(j) + 1
> pal(k) = pal(k) + 1
> Next n
> ' clear the array to empty
> CopyMemory ByVal VarPtrArray(pic), 0&, 4
> s1 = "16 colour bitmap (" & Bmp.bmWidth & " x " _
> & Bmp.bmHeight & " pixels)" & vbCrLf & vbCrLf
> For n = 0 To 15
> s1 = s1 & "Palette Entry (" & Format(n) & ") is used by " _
> & Format(pal(n)) & " pixels" & vbCrLf
> Next n
> MsgBox s1
> End Sub
>
> Private Sub Command1_Click()
> ' put here whatever code you are using to get
> ' your bitmap handle (into a Long called hBitmap
> ' in this example) and then use the following:
> '
> AnalyzeBitmap hBitmap
> '
> End Sub

I get a Messagebox stating "This is not a 16 colour bitmap (it reports
that it is 16 bpp) My picture box stays black.

--
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-sep...


Mike Williams

11/18/2011 2:04:00 PM

0

"Leo" <ttdhead@gmail.com> wrote in message
news:ja5ib3$9fi$1@dont-email.me...
>
> I get a Messagebox stating "This is not a 16 colour bitmap
> (it reports that it is 16 bpp) My picture box stays black.

Well it looks as though you might have a 16 bpp (65536) bitmap which do not
have a colour palette, whereas as far as I know the XP startup image in
ntoskrnl.exe where you are apparently getting it from is 4 bpp (unless there
are various versions of ntoskrnl). What happens if you use Resource Hacker
to extract the 640 x 480 WinXP startup bitmap from ntoskrnl.exe (which is
likely to appear solid black because of the all black palette it contains)
and if you check its file size. The one I extracted is a RLE compressed 4
bpp 640 x 480 bitmap and its file size if approximately 13KB. Do you get the
same? By the way, is your system running at 16 bit (medium) colour depth?
If so then whatever code you are using to get the bitmap might be creating a
copy of it in the colour depth of the display.

The testbed code I posted does not contain any error checking and it is of
course not foolproof but what happens if you add the following additional
MsgBox line immediately after the "GetObject" line, so that the portion of
the code would look like this:

' . . . . . .
GetObject hBmp, Len(Bmp), Bmp ' this line is already there
MsgBox "Pixel width is " & Bmp.bmWidth & " pixels" & vbCrLf _
& "Data width is " & Bmp.bmWidthBytes & " bytes"

The message box should hopefully tell us a bit more about the bitmap you
have got.

Mike


Leo

11/18/2011 2:39:00 PM

0

Mike Williams used his keyboard to write :
> "Leo" <ttdhead@gmail.com> wrote in message news:ja5ib3$9fi$1@dont-email.me...
>>
>> I get a Messagebox stating "This is not a 16 colour bitmap
>> (it reports that it is 16 bpp) My picture box stays black.
>
> Well it looks as though you might have a 16 bpp (65536) bitmap which do not
> have a colour palette, whereas as far as I know the XP startup image in
> ntoskrnl.exe where you are apparently getting it from is 4 bpp (unless there
> are various versions of ntoskrnl). What happens if you use Resource Hacker to
> extract the 640 x 480 WinXP startup bitmap from ntoskrnl.exe (which is likely
> to appear solid black because of the all black palette it contains) and if
> you check its file size. The one I extracted is a RLE compressed 4 bpp 640 x
> 480 bitmap and its file size if approximately 13KB. Do you get the same? By
> the way, is your system running at 16 bit (medium) colour depth? If so then
> whatever code you are using to get the bitmap might be creating a copy of it
> in the colour depth of the display.
>
> The testbed code I posted does not contain any error checking and it is of
> course not foolproof but what happens if you add the following additional
> MsgBox line immediately after the "GetObject" line, so that the portion of
> the code would look like this:
>
> ' . . . . . .
> GetObject hBmp, Len(Bmp), Bmp ' this line is already there
> MsgBox "Pixel width is " & Bmp.bmWidth & " pixels" & vbCrLf _
> & "Data width is " & Bmp.bmWidthBytes & " bytes"
>
> The message box should hopefully tell us a bit more about the bitmap you have
> got.
>
> Mike

With that extra messagebox I get Pixel width is 640 pixels and Data
width is 1280 bytes. Saving the picture Object using SavePicture
results in a 900 kb bmp. Those results are from under XP Mode with 16
bit settings.

Running under Windows 7 with 32 bit colour pointing at a copy of XP's
ntoskrnl.exe I get Pixel width is 640 pixels and data width is 2560
bytes. I then get This is not a 16 colour bitmap (it reports that is 32
bpp)

--
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-sep...


Mike Williams

11/18/2011 3:18:00 PM

0

"Leo" <ttdhead@gmail.com> wrote in message
news:ja5qm2$ust$1@dont-email.me...

> With that extra messagebox I get Pixel width is
> 640 pixels and Data width is 1280 bytes.

Well it is definitely a 16 bpp (65536 colour) bitmap then (each pixel will
require two bytes). The reason I asked if you were running a 16 bit desktop
was because of my previous suspicion that whatever code you are using to
extract the bitmap from ntoskrnl.exe is making a 16 bpp copy of the original
4 bpp image.

> Saving the picture Object using SavePicture results in
> a 900 kb bmp. Those results are from under XP Mode
> with 16 bit settings.

That'll be a 24 bpp bitmap, which the VB SavePicture method likes to create.

> Running under Windows 7 with 32 bit colour pointing at a copy
> of XP's ntoskrnl.exe I get Pixel width is 640 pixels and data
> width is 2560. I then get This is not a 16 colour bitmap (it reports
> that is 32 bpp).

That's because it is a 32 bpp per pixel bitmap (2560/640 is 4 Bytes per
pixel). So, it definitely looks as though whatever extraction code you are
using is making a copy of the original 4 bit bitmap at whatever screen
colour depth you happen to be running at. This leads me to suspect that your
extraction code (which I have not seen and which you might like to post) is
using the LoadImage API function and that you have failed to include the
LR_CREATEDIBSECTION flag with the other flags you asre using in its last
parameter.

If you include the LR_CREATEDIBSECTION flag then you should find that it
creates a 4 bpp bitmap when it extracts the 4 bpp original from the
ntoskrnl.exe file. When that happens the rest of my code will run reporting
how many pixels in the bitmap use each of the 16 palette entries . . . at
which point you will probably come across another problem (!) which is why I
added code to report the number of pixels per palette entry. Micro$oft's
documentation in that area (as in most other areas!) is flakey at best, but
I can figure out what is happening and why it is happening, which results in
LoadImage clearing all the actual bitmap pixel data nibbles to zero (so you
effectively have no bitmap data at all!) when it comes across a 16 colour
bitmap in which all of the 16 palette entries are set to black (as appears
to be the case here), but I haven't come up with an acceptable solution to
that yet.

Mike





Leo

11/18/2011 3:28:00 PM

0

on 19/11/2011, Mike Williams supposed :
> "Leo" <ttdhead@gmail.com> wrote in message news:ja5qm2$ust$1@dont-email.me...
>
>> With that extra messagebox I get Pixel width is
>> 640 pixels and Data width is 1280 bytes.
>
> Well it is definitely a 16 bpp (65536 colour) bitmap then (each pixel will
> require two bytes). The reason I asked if you were running a 16 bit desktop
> was because of my previous suspicion that whatever code you are using to
> extract the bitmap from ntoskrnl.exe is making a 16 bpp copy of the original
> 4 bpp image.
>
>> Saving the picture Object using SavePicture results in
>> a 900 kb bmp. Those results are from under XP Mode
>> with 16 bit settings.
>
> That'll be a 24 bpp bitmap, which the VB SavePicture method likes to create.
>
>> Running under Windows 7 with 32 bit colour pointing at a copy
>> of XP's ntoskrnl.exe I get Pixel width is 640 pixels and data
>> width is 2560. I then get This is not a 16 colour bitmap (it reports
>> that is 32 bpp).
>
> That's because it is a 32 bpp per pixel bitmap (2560/640 is 4 Bytes per
> pixel). So, it definitely looks as though whatever extraction code you are
> using is making a copy of the original 4 bit bitmap at whatever screen colour
> depth you happen to be running at. This leads me to suspect that your
> extraction code (which I have not seen and which you might like to post) is
> using the LoadImage API function and that you have failed to include the
> LR_CREATEDIBSECTION flag with the other flags you asre using in its last
> parameter.
>
> If you include the LR_CREATEDIBSECTION flag then you should find that it
> creates a 4 bpp bitmap when it extracts the 4 bpp original from the
> ntoskrnl.exe file. When that happens the rest of my code will run reporting
> how many pixels in the bitmap use each of the 16 palette entries . . . at
> which point you will probably come across another problem (!) which is why I
> added code to report the number of pixels per palette entry. Micro$oft's
> documentation in that area (as in most other areas!) is flakey at best, but I
> can figure out what is happening and why it is happening, which results in
> LoadImage clearing all the actual bitmap pixel data nibbles to zero (so you
> effectively have no bitmap data at all!) when it comes across a 16 colour
> bitmap in which all of the 16 palette entries are set to black (as appears to
> be the case here), but I haven't come up with an acceptable solution to that
> yet.
>
> Mike

I am using the code from
http://www.vbaccelerator.com/home/vb/code/Libraries/Resources/Reading_Data_from_Local_or_External_Library_Resources/External_Resources_Demonstration_P...
to extract it from ntoskrnl.exe and turn it into a picture object.

--
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-sep...


Mike Williams

11/18/2011 8:41:00 PM

0

"Leo" <ttdhead@gmail.com> wrote in message
news:ja5ti6$jl2$1@dont-email.me...
>
> I am using the code from
> http://www.vbaccelerator.com/home/vb/code/Libraries/Resources/Reading_Data_from_Local_or_External_Library_Resources/External_Resources_Demonstration_P... >
> to extract it from ntoskrnl.exe and turn it into a picture object.

Well that's typical vbaccelerator code. Extremely useful but quite long
winded and includes everything but the kitchen sink, often making it
difficult to navigate. Anyway, if you have a look at the
GetPictureFromResource function in the module mResource you'll see the
following little block of code:

If IsNumeric(sName) Then
lID = CLng(sName)
hBmp = LoadImageLong(hMod, lID, IMAGE_BITMAP, 0, 0, 0)
Else
hBmp = LoadImageString(hMod, sName, IMAGE_BITMAP, 0, 0, 0)
End If

To make it handle bitmaps at their original colour depth, rather than at the
colour depth of the display, you should change that code so that it is as
follows:

If IsNumeric(sName) Then
lID = CLng(sName)
hBmp = LoadImageLong(hMod, lID, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)
Else
hBmp = LoadImageString(hMod, sName, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION)
End If

You don't need to add the Constant declaration because it is already
declared, but just never used. When you have made that modification you
should find that it successfully extracts your 4 bpp 16 colour bitmap
without changing its colour depth. You can then run my own code (the code I
posted the other day) on the bitmap it creates and it should report the
details of the image, including how many pixel nibbles in the bitmap data
use each of the 16 palette entries . . . and then you will no doubt come
across the other problem I mentioned, where LoadImage effectively erases all
the pixel colour nibbles (sets them all to zero) on a 16 colour 4 bpp bitmap
which has deliberately set to contain a Palette in which all entries are the
same value (zero in this case). If it was a typical 16 colour bitmap which
contained real RGB data in the palette entries then it would be fine, but
not on 16 colour bitmaps which contain zero in all 16 palette entries, such
as the one you are dealing with. That one still needs looking into.

Mike