BBC BASIC
« POINT performance in SDL »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 4:19pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: POINT performance in SDL  (Read 185 times)
MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx POINT performance in SDL
« Thread started on: Sep 2nd, 2017, 9:44pm »

Needing some advice regarding an app I am writing and converting to SDL from BB4W (free). The app does some basic image processing and pixel checking and so makes use of the POINT command which I've been reading (and experiencing) has a performance hit in SDL.

So... I've been thinking that keeping a separate 2D array containing the data for the image contents might be a suitable approach for faster colour lookup and pre & post processing.

I wanted to ask the more knowledgeable people on the forum if there are other ways to get good performance for colour lookup or if there is already a library or other examples around of how to do something similar?


User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
xx Re: POINT performance in SDL
« Reply #1 on: Sep 2nd, 2017, 10:30pm »

Arrays can store pixel information.
If you look at the spider demo program in the Graphics and Games section of this forum, you will see one example.

In this case I would scan a BMP image sketching the info and storing it in a file that can be transferred.

The entire image can then be overlayed and positioned with custom color to your hearts content and transferred to any platform with BBCSDL or BBC4W.
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: POINT performance in SDL
« Reply #2 on: Sep 2nd, 2017, 10:42pm »

on Sep 2nd, 2017, 9:44pm, MarsFS wrote:
I wanted to ask the more knowledgeable people on the forum if there are other ways to get good performance for colour lookup or if there is already a library or other examples around of how to do something similar?

It's unfortunate that 'reading back from the screen' (which affects POINT, TINT, RECTANGLE...TO, VDU 23,7... etc.) is so slow in BBCSDL, particularly compared with BB4W, but it's the price one pays for using GPU-accelerated graphics where the 'bitmap' is not directly visible by the CPU.

When you absolutely have to do it, I don't know of any effective workaround other than what you suggest, i.e. to keep a 'local' copy of what's on the screen (for example in a 2-dimensional array).

If you can describe in more detail what it is you need to do, I may be able to be more specific about the kind of code that you might use. I'm not aware that there is an existing example or library you can look at.

Richard.
User IP Logged

MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: POINT performance in SDL
« Reply #3 on: Sep 4th, 2017, 11:18pm »

Thanks for the feedback, I'm thinking to have a play around with an array and see where that leads me.

The program is an art application that emulates a mode 2 screen (160x256 with 8 cols), the parts I need to currently use point are for a customised fill routine. I also want to implement drawing tools such as transparent and additive brushes that need to read whats already on the canvas and blend / merge / process that information to work out what to overlay onto the existing image.

I've also used POINT to set a highlight on tool icons, now I'm moving to SDL I can probably just use a second bitmap with the highlights drawn in and switch between two images for each tool.




User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: POINT performance in SDL
« Reply #4 on: Sep 5th, 2017, 10:19am »

on Sep 4th, 2017, 11:18pm, MarsFS wrote:
Thanks for the feedback, I'm thinking to have a play around with an array and see where that leads me.

If your situation is that the displayed image is relatively static, one approach would be to copy the entire window (or the relevant part of it) into an array just once and thereafter access the array. Although the initial copy will be relatively slow, subsequently testing individual pixels will be fast:

Code:
      SDL_PIXELFORMAT_ARGB8888 = &16362004
      MODE 8
      GCOL 11
      CIRCLE FILL 640,512,100

      wide% = 640
      high% = 512
      DIM bitmap%(high%-1, wide%-1)
      PROCget_screen_to_array(0, 0, wide%, high%, bitmap%())

      Y% = 256
      FOR X% = 360 TO 380
        PRINT ~bitmap%(Y%,X%)
      NEXT
      END

      DEF PROCget_screen_to_array(X%, Y%, W%, H%, a%())
      LOCAL rect{} : DIM rect{x%, y%, w%, h%}
      rect.x% = X% : rect.y% = Y% : rect.w% = W% : rect.h% = H%
      SYS "SDL_RenderReadPixels", @memhdc%, rect{}, SDL_PIXELFORMAT_ARGB8888, ^a%(0,0), W% * 4
      ENDPROC 

This is how the FILL statement (and related PLOT commands) is implemented in BBCSDL; the entire graphics viewport is read into a memory array, the flood fill is performed in that array, and then the result is blitted back to the screen.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls