bitmap% performance

66 views
Skip to first unread message

'racket' via users-redirect

unread,
Apr 22, 2020, 4:39:17 PM4/22/20
to us...@racket-lang.org
 
Hi,
I’m writing to the group looking for help with a performance issue. 
I’m coding a gallery like application, using the racket/draw library, but the bitmap% class seems to be pretty slow. The (make-bitmap 4000 3000) operation takes more than 4 seconds on my computer (a macbook pro with a 3.1GHz dual core i5 and 16GB ram). 
What I'd need to do is simply read and resize some jpeg files to display them in a canvas. I could use some external program to resize the photos but I would prefer to work with racket only. The make-platform-bitmap is 20 times faster than the make-bitmap, but I didn’t find a way to draw a jpeg on it.
Do you have any suggestion? 

Thanks,
Andrea 

Simon Schlee

unread,
Apr 23, 2020, 6:47:10 AM4/23/20
to Racket Users
Hi,


Personally I have only used the second constructor that takes a parameter named "in" here:
https://docs.racket-lang.org/draw/bitmap_.html

I didn't notice any performance problems, but my images have much lower resolution.

I resize my images by using the bitmap function which returns a pict, then using scale-to-fit, then using pict->bitmap to convert back to a bitmap.

Hope that is helpful,
otherwise you could provide an example that I can test on my computer, I am on linux.

Good luck!
Simon

Robby Findler

unread,
Apr 23, 2020, 9:49:26 AM4/23/20
to racket, us...@racket-lang.org
I don't know that we can help with the specific call you are reporting a slowdown for (maybe, but I won't address that here as asking other questions first seems worth doing). 

What are you using the bitmap for, exactly? Just to resize the bitmaps? Or as a backing store for drawing into the canvas? Something else?

Robby

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/etPan.5ea0ab6b.35178ff7.17869%40andreagiardina.com.

Robby Findler

unread,
Apr 23, 2020, 9:50:58 AM4/23/20
to racket, us...@racket-lang.org
(My reply to this post bounced on the attempt to send to OP.)

On Wed, Apr 22, 2020 at 3:39 PM 'racket' via users-redirect <us...@plt-scheme.org> wrote:
--

'racket' via users-redirect

unread,
Apr 23, 2020, 11:05:08 AM4/23/20
to us...@racket-lang.org
Hi Robby, thanks for your reply.


What are you using the bitmap for, exactly? Just to resize the bitmaps? Or as a backing store for drawing into the canvas? Something else?

Both of them. 

* I have more than 10K photos in 4000x3000 format that I’d like to download from a webdav server, read exif info, and resize to 960x720 and 320x240

* I should display the thumbnails in a canvas, keeping the system as smooth as possible while scrolling the canvas.

For the first task, if I don’t find any valid alternative, I could use some external tool to resize the images (let’s say libvips or imagemagick) or maybe write some ffi code to use libjpeg. I would prefer this solution over the first one, but I don’t have any experience with ffi coding.


Thanks,

Andrea  

Robby Findler

unread,
Apr 23, 2020, 12:14:09 PM4/23/20
to racket, Racket Users
Thanks! For the first task I think you probably have to use the raw
bitmap% object (since I guess you're using `read-bitmap`). I'm not
sure if there could be some improvement internally so that screen
bitmaps were used to read in the jpegs. Absent an improvement at that
level, I guess I'd just try caching the conversions.

For the second, I guess you are creating very small bitmaps so
probably this particular creation issue isn't affecting that part? If
you really have a lot of them, you could probably implement some
clever pooling that wasn't keeping all of the jpegs in actual bitmap%
objects all the time but was just keeping ones that were likely to be
looked at soon in bitmap% objects.

hth,
Robby
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/etPan.5ea1ae9c.ee2bf71.17869%40andreagiardina.com.

'racket' via users-redirect

unread,
Apr 23, 2020, 2:08:37 PM4/23/20
to Racket list
Hi Sam,
trying your code I get back the following error:

load-file in bitmap%: not available in a canvas-compatible bitmap: (object:quartz-bitmap% ...)


The error I get is expected according to the load-file documentation:

"Loads a bitmap from a file format that read from in, unless the bitmap was produced by make-platform-bitmap, make-screen-bitmap, or make-bitmap in canvas% (in which case an exn:fail:contract exception is raised)"

Which racket version/platform did you use?

Andrea 





On 23 April 2020 at 18:39:08, Sam Tobin-Hochstadt (sa...@cs.indiana.edu(mailto:sa...@cs.indiana.edu)) wrote:

> I'm trying to understand the issue here. You say that you can't use
> `make-platform-bitmap` doesn't work, but this program works for me and
> loads two JPEGs into a platform bitmap.
>
> #lang racket/base
> (require racket/draw racket/class)
> (define b (make-platform-bitmap 1000 1000))
> (define bs (make-bytes 100))
>
> (send b load-file "/home/samth/Dropbox/punge-stuff/diploma.jpeg")
> (send b get-argb-pixels 20 20 5 5 bs)
> (bytes->list bs)
>
> (send b load-file "/usr/share/doc/texlive-doc/dvipdfm/mwicks.jpeg")
> (send b get-argb-pixels 20 20 5 5 bs)
> (bytes->list bs)
> > --
> > You received this message because you are subscribed to the Google Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/etPan.5ea0ab6b.35178ff7.17869%40andreagiardina.com.

'racket' via users-redirect

unread,
Apr 23, 2020, 2:14:23 PM4/23/20
to Racket Users
> Thanks! For the first task I think you probably have to use the raw
> bitmap% object (since I guess you're using `read-bitmap`). 

Hi Robby, I don’t understand how to read a jpeg into a platform-bitmap. Probably I'm missing something in the documentation…  


> For the second, I guess you are creating very small bitmaps so
> probably this particular creation issue isn't affecting that part? If
> you really have a lot of them, you could probably implement some
> clever pooling that wasn't keeping all of the jpegs in actual bitmap%
> objects all the time but was just keeping ones that were likely to be
> looked at soon in bitmap% objects.

Yes, this is exactly what I’m doing. I’m preloading very small bitmaps in memory, display them to give to user a “preview", and then replacing them with a better version.

Andrea


Robby Findler

unread,
Apr 23, 2020, 4:53:36 PM4/23/20
to racket, Racket Users
On Thu, Apr 23, 2020 at 1:14 PM 'racket' via users-redirect
<us...@plt-scheme.org> wrote:
>
> > Thanks! For the first task I think you probably have to use the raw
> > bitmap% object (since I guess you're using `read-bitmap`).
>
> Hi Robby, I don’t understand how to read a jpeg into a platform-bitmap. Probably I'm missing something in the documentation…

Right-- I agree that that isn't supported currently. I don't know how
difficult it would be to support.

Just a random thought: did you try using the read-bitmap method on the
already created bitmap? I don't know if that would be faster (I wanted
to try before posting but I didn't get there). It may be, however,
that the code inside bitmap% would have to be improved.

Robby
Reply all
Reply to author
Forward
0 new messages