|
I really cannot help you with your problem.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
employee information is privileged indeed.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
As there is no information do we assume you are not employed?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
It has to be a candidate for best post ever !!!!
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I guess that you must be posting from The Empty Quarter[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
in vb.net how i get the start and stop time in timer control... that mean if i having two textbox. if named as start and stop. in that i need to click mean the timer to start and click stop maen the timer will stop autimatically... i need a vb.net code for this concept..
|
|
|
|
|
What have you got so far?
My advice is free, and you may get what you paid for.
|
|
|
|
|
Very good!
Make the bugger work, I bet it is a homework problem for college.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
it is a trick question, you can't calculate time. Not even in VB. Tempus fugit.[^]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello everybody,
within an otherwise more simple project I have to deal with something that goes far beyond my knowledge so far. Probably someone of you can help with hints or a snippet?
The goal is to display a picture format which isn't supported from gdi+ on a form. So I already had to go through a lot of advanced stuff with GCHandle etc., but meanwhile I'm far enough that something (coming from the picture file at least) shows on the screen... unfortunately it's only a mixture of colored pixels . Considering the picture specification (if you're interested you find it here[^]) each pixel is represented by a 32-bit word, that is (in my particular case) divided into three 10-bit-integers (RGB) and two padding bits (zero).
With the code below I create an array of 32-bit-integers from the image information in the file, which are supposed to represent the pixels. But how can I access the RGB information? I.e., how would I be able to derive 10-bit-integers from a 32-bit word? Or am I running into a dead-end with the whole concept?
Thanks for any help and advice! Please keep it a bit simple, since for me there seem to be several completely new issues hidden...
Michael
The main code I use is:
Public Sub DisplayImage(ByVal PicFile As FileInfo)
Dim W As UInteger = 200
Dim H As UInteger = 154
Dim stride As UInteger = 4 * W
Dim arrayImage() As UInt32 = MakePixelArray(PicFile)
Dim gch As GCHandle = GCHandle.Alloc(arrayImage, GCHandleType.Pinned)
Dim pBuf As IntPtr = gch.AddrOfPinnedObject
PictureBox1.Width = W
PictureBox1.Height = H
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Image = New Bitmap(W, H, stride, Imaging.PixelFormat.Format32bppRgb, pBuf)
gch.Free()
End Sub
Despite my picture (and the resulting array - see next snippet) is 2048 wide and 1536 high, I still have to set W and H to lower values in order to avoid an AccessViolationExcepiton. But that's another issue...
My actual problem seems to be in the 'MakePixelArray' function, because I can't retrieve the 10-bit-Integers needed for RGB from the DWORD. Here's what I have:
Private Function MakePixelArray(ByVal PicFile As FileInfo) As Array
Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
Dim brh As BinaryReader = New BinaryReader(ft)
ft.Position = 8192
Dim PixelArray(CInt(PicFile.Length - ft.Position) / 4 - 1) As UInteger
For i = 0 To (PixelArray.Length - 1)
Dim buff As UInteger = SwapDWORD(brh.ReadUInt32)
PixelArray(i) = buff
Next i
ft.Close()
brh = Nothing
ft = Nothing
Return PixelArray
End Function Just for completion here's the SwapDWORD function which is needed because the file is written in big endian:
Private Function SwapDWORD(ByVal i As UInt32) As UInt32
Return ((i And &HFF) << 24) + ((i And &HFF00) << 8) + ((i And &HFF0000) >> 8) _
+ ((i >> 24) And &HFF)
End Function
|
|
|
|
|
Something like:
Dim buff As UInteger
buff = &H33388911
Dim Red As UInt32 = (buff And &H3FF)
Dim Green As UInt32 = (buff And &HFFC00) >> 10
Dim Blue As UInt32 = (buff And &H3FF00000) >> 20
This example would give Red = &H111, Green = &H222, Blue = &H333.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi Moreno,
thank you for taking some time. Since I'm a bit clumsy with Hex-stuff I just went and tried your piece of code, replacing the 'buff' value with a UInt32 read from the file (and swapped).
The changed function now considers that the array only consists of 3 Elements (RGB) per pixel instead of 4 (bytes). It now reads like
Private Function MakeRGBArray(ByVal PicFile As FileInfo) As Array
Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
Dim brh As BinaryReader = New BinaryReader(ft)
ft.Position = 8192 ' start with first pixel after the header
' change array dimensions from 4 bytes per pixel to 3 (RGB)
Dim RGBArray(CInt(PicFile.Length - ft.Position) / 4 * 3 - 1) As UInt32
For i = 0 To (RGBArray.Length - 1) Step 3
Dim buff As UInt32 = SwapDWORD(brh.ReadUInt32)
RGBArray(i) = (buff And &H3FF)
RGBArray(i + 1) = (buff And &HFFC00) >> 10
RGBArray(i + 2) = (buff And &H3FF00000) >> 20
Next i
ft.Close()
brh = Nothing
ft = Nothing
Return RGBArray
End Function
To make it short: I can't tell if your idea works, since there's no reasonable result - just a different very bluish pattern. And to be honest: I'm also afraid there's something else wrong with my code, too? As you see in the main function, I also have to use the 'Imaging.PixelFormat.Format32bppRgb' parameter when creating the new bitmap. Changing it results in an ArgumentException
BTW: With your code added, the first pixel returns buff=562758160 (&H218B0210) exactly in the order like it's written in the file (==> Red=528, Green=704, Blue=536)
Do you probably have another hint where I'm trapped in my code salad?
Thank you again,
Michael
|
|
|
|
|
Hi Michael,
Please note that mine was just an example: you should check which is the specific data format in your file: in my example, I gave it for granted that the 1st 10 bit would hold red, then 10 bits for green and finally 10 bits for blue. And no alpha. This might be different from the actual file format you're using.
If you want to share your file and the format, I might be able to help you more.
EDIT: share your code for drawing the picture, if you want - the problem may be there (since you say red, green and blue components seem to be read correctly from the data file).
2+2=5 for very large amounts of 2
(always loved that one hehe!)
modified on Thursday, August 6, 2009 1:53 PM
|
|
|
|
|
Ciao Moreno,
thanks for your support . I've just sent you some stuff to the address at stasnc, hoping that's correct. The code and link to the file specification is also part of my original post.
I'm really looking forward to hearing from you!
Regards
Michael
|
|
|
|
|
Hi Michael,
Getting your stuff just now, I'll have a look at the code and will let you know.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
I had a first look at the stuff, and I sure see one problem, which as you thought is related to the Format24bppRgb format.
This format requires three Byte s for each pixel (red, green, blue), while you provide three UInt32 .
Try to make your RGBArray a Byte array, and you'll probably be done.
I'll have a deeper look anyway, and see if what I said is ok and if there's anything else to fix.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
modified on Friday, August 7, 2009 6:16 AM
|
|
|
|
|
Thanks for looking - I just came home from work and changed what you suggest.
The result is an overflow exception in the lines "RGBArray(i) = (buff And &H3FF)" etc., in which I then try to put a 10-bit value (held in buff which is UInt32, right?) into a single byte (8 bits). How would I correctly downconvert the result of the line into a byte? My silly approach to return 8/10th of course lead to an overflow exception, too...
BTW: I hope you had enough other stuff to do today and didn't drown in all the possibilities to fix
|
|
|
|
|
In order to convert your 10 bits values to 8 bits, you must simply lose the two least significant bits (which is the same as dividing the value by 4):
RGBArray(i) = (buff And &H3FF) >> 2;
RGBArray(i + 1) = (buff And &HFFC00) >> 12;
RGBArray(i + 2) = (buff And &H3FF00000) >> 22;
Try this and you should be doing fine with a Byte array.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hello Michael,
I did not read the whole document about the Cineon File Format, but did a similar research about a image format of a vision mixer's still store (Kahuna) recently. There where the colors also 10 bit (this is common in broadcasting video) but the color was not in RGB but in YUV-format. If you have strange colors, when you are done, start investigating in this direction.
By the way: you should not open your cineon file as a bitmap, but as a byte-array (as suggested), then you could get the three 10-bits out of the 32-bit integer, without GDI+ confuses you. Then alocate a 24-Bit (RGB) Bitmap and use something like setpixel (for testing only, is very slow) to write your converted RGB-values to the bitmap.
To get around the slow setpixel look for articles about manipulating bitmap directly using 'dirty-buffers', but not before you see a picture with the slow method...
Hope to help you find your way, good luck:
Didi
|
|
|
|
|
Thank you, Didi!
I could't open dpx as bitmap anyway, so creating a byte array was my only solution. I had some strong support from Moreno (off-forum) explaining me how to extract the bits in the right way. When allocating 24-Bit RGB Bitmap, as you suggest, a somehow recognizable picture shows up at least...
Here's where we're stuck at the moment. The resulting RGB values make sense in some way (a certain pixel we analyzed e.g. has 132/176/134 while correct RGB values are supposed to be 33/44/33), but the picture shown is completely false colored... a bit like taken by a thermal sensor but heavily green in addition DPX has so many different possibilities to hold a bitmap: it could be YUV, RGB, LIN, LOG and much more... Obviously the Cintel scanner puts 'transfer = 3' (meaning LOG) into the header despite the operators SWEAR it can only be a linear RGB in the data, coz they didn't even install the hardware needed to scan LOG format.
Confusion is resulting about the proper interpretation of the data. Moreno thinks I'll have to take it as a fact that it's LOG data and go compute a LUT. I still wish I could avoid it, believing the operators... because doing that I might have to dig into C++ which scares me a bit - all I want to do is convert a particular source picture, finally, and not analyze all the different kinds of DPX.
Did you probably find a way in your project how to erase that kind of doubts and clearly determine which colorspace and type the dpx is?
Regards
Mick
|
|
|
|
|
Hi Mick,
my project was not DPX, but a internal format of a Vison mixer, but it used also 10 bit...
I looked at google to see, if there is an open source library to read DPX files and found GraphicsMagick[^] probably this could be a solution, there are different bindings including a COM object, that you should be able to use from VB.NET.
Regards: Didi
|
|
|
|
|
Hi Didi,
yeah, I'm trying with the GM Source also - the problem is
a) it's C++ which I'm fully unable to understand and
b) in the needed conversion function it's considering so many details like e.g. all the different formats and colorspaces that even for understanding I have to jump from one function to the other trying to read it --> problem a
Thank you still, and have a nice day
Mick
|
|
|
|
|
Hi Mick,
would not try to go into the sources, just use ImageMagick in VB.NET[^] should be enough.
Regards: Didi
|
|
|
|
|
Hi Didi,
I had played around with that one some time ago (before trying to convert the file data myself) and gave up after a while because I didn't get the source compiled. Now I see they obviously added the DLLs, so probably I'll use it (i.e. try again). At least much more realistic to get a grip on than starting C++ studies and that makes me happy
Thanks for the reminder, anyway!
Have a nice weekend
Mick
|
|
|
|
|
Hi again, Didi!
Stepping through the instructions I managed to build the dll and have the path to the other dll's corrected, so an image is shown in my picturebox. Unfortunately, after approx. 30 seconds, the solution throws an 'OutOfMemoryException' without any additional hint where exactly it would happen. The same effect occurs running the sample solution included with the article, so I figure it happens somewhere in the wrapper dll.
I found a respective question from 2008 in the posts of the article, but it remained unanswered. Did you by any chance solve that problem OR successfully update the wrapper as described with a subsequent version of ImageMagick? It might be an older bug of IM that's been erased for a long time, but despite of many attempts I didn't manage to compile with an updated source.
Thanks for now,
Mick
EDIT: After some experiments I found that this error doesn't happen loading standard size (1920 * 1080) DPX files, only when loading 2k-DPX (2048 * 1536 or 2048 * 1556)!
modified on Sunday, August 16, 2009 4:51 AM
|
|
|
|
|