it seems that you are very close to the goal...
I assume that you have implemented the ExternBitmap interface according to the corresponding documentation - which also includes an example.
When you lock the bitmap you will get a XBitmapLock structure containing the address to write your image data (Pixel1) and the size of a single row within the bitmap (Pitch1Y). Are you using this parameters within your decoder?
The size of the allocated bitmap may be larger than the size you have requested when creating the bitmap due to alignment requirments.