When dealing with other (Microsoft) dll's having to flip bitmaps vertically is inevitable. Thankfully the flipping rectangle trick is fast. Still, it does require valuable cpu time. Does anyone know if doing this flipped copy to a displayed canvas will hand over the flipping to the gpu? Ie would the copy to gpu preceed the flip, or vice versa?

Comments

  1. If I recall correctly, vertical flipping is just the question of how you interpret the bitmap and AFAIK that boils down to flipping single flag in bitmap header.

    It has been long time ago... so my memory could be playing tricks on me...

    ReplyDelete
  2. Hard to know the implications of code that we can't see

    ReplyDelete
  3. Dalija Prasnikar I vaguely remember something like that too, but it does not work like that if you copy VCL bitmaps. If you copy a bitmap with a vertical flip, the (scan)lines do indeed change order. But I also know if you copy it to a canvas that happens to be visible, the GPU takes over. I guess the question is at what point that happens. Have to admit I have never quite grasped the (internal) differences between a bitmap, a canvas, and a canvas that happens to be visible.

    ReplyDelete
  4. Mike Versteeg I am talking about interpreting bitmap as whole. Bitmap lines (scanlines) can be organized top to down, and bottom to up. There is flag or something in bitmap header that defines that part. If you have wrong vertical orientation then changing just that header part should suffice. Drawing on canvas and other bitmap operations, take that ordering into account.

    This is also what Delphi does. When you are accessing bitmap scanlines you will always get them in same order, regardless of how they are actually stored in memory.

    But it is hard to say what is your problem, there is not enough info to say for sure.

    ReplyDelete
  5. When dealing with software outside VCL (dll's from Microsoft developers, DirectShow frame buffer) the data is top=down. When dealing with high frame rate high resolution video streams, every microsecond counts. The fastest way to copy such a frame into a VCL bitmap would be to use memcpy. However if you were to draw this bitmap onto a canvas it is upside down. So I use CopyRect with one rectangle upside-down to flip the bitmap. This is an unnecessarily copy costing precious microseconds. As everything external source I deal with has the bitmap upside down I wondered if it would be faster to work with upside-down bitmaps in VCL and only flip them when I need to display them. However for that to have a positive effect it should not require additional CPU time. And then we're back to my original question. If there is some way I can tell a canvas that it should be interpreted upside-down when displayed (i.e. when the GPU grabs it), that should be a definite improvement. (I only would need to remember that all my y-coordinates are mirrored when dealing with the VCL bitmaps.)
    Is that enough info? I always expect others to read my mind..

    ReplyDelete
  6. I'm expect it's possible to create the bitmaps in a way that they won't require further processing. But I can't read your mind, and you don't seem keen to elaborate with any detail.

    ReplyDelete
  7. I really do not know what more details you require? There is nothing more I can think of to clarify my question. However Dalija Prasnikar did point me in the direction and I think I could rephrase my question to:

    "Can I change the orientation of a VCL bitmap to top-bottom?"

    ReplyDelete
  8. Forget it, it's no fun when people only describe what they are doing rather than provide code to make it clear.

    ReplyDelete
  9. David Heffernan How a good programmer can live without telepathy skills? I think, practicing telepathy is so cool and useful!

    ReplyDelete
  10. Mike Versteeg You may also try SetWorldTransform function on the window, that displays final result to the user. But I would personally switch to FMX or GLScene. They bouth can be embeded in VCL application.

    ReplyDelete
  11. Mike Versteeg Yes, you can change bitmap orientation. By flipping the flag in bitmap header. I don't have time to dig up more, but search for bitmapinfoheader

    ReplyDelete
  12. Dalija Prasnikar Thank you for your helpful replies, I'll give that a try.

    ReplyDelete

Post a Comment