[Newbies] Speed up image loading
felix_do at web.de
Wed Jul 9 09:00:25 UTC 2008
I am trying to write a Photo Manager Application, to learn Morphic and
Squeak. So far I have created a custom Thumbnail morph
"LabeledThumbnail" that is capable of holding a form and a label:
First I create forms like that:
form := (ImageReadWriter
Thumbnails are then derived by (this is an instance method of
LabeledThumbnail, not sure about the >> notation):
thumbnail ifNotNil: [ self removeMorph: thumbnail].
thumbnail _ Thumbnail new.
thumbnail maxWidth:150 minHeight:100.
thumbnail makeThumbnailFromForm: aForm.
self addMorph: thumbnail.
Now I created a new Class "ThumbnailBar", that displays a collection of
ThumbnailBar class>>newFromPhotoCollection: aPhotoCollection
| tmp form |
tmp _ self new.
aPhotoCollection do: [ :entry |
form _ ImageReadWriter formFromFileNamed:
tmp addMorph: (LabeledThumbnail
newFromForm: form withLabel: entry) asMorph
PhotoCollection is a bare list of filenames.
Obviously this is not complete, I want to add scrollbars etc. However,
my current issue is speed. Doing a
col := PhotoCollection newFromDirectory: '/home/felix/DCIM'.
(ThumbnailBar newFromPhotoCollection: col) openInWorld
takes about way too long (minutes range) until the Thumbnail bar shows
up (there are about 200 hi-res jpegs in the collection).
I guess that the most time is spent loading and scaling the images, so
I'll probably cache the thumbs on disk. Another issue is easier and more
intresting to me: I like to reduce the number of Morph objects. E.G. my
"LabeledThumbnail" is a RectangleMorph that owns an ImageMorph and a
StringMorph. I want to get rid of the submorphs and write my own drawing
code. I have already seen how this is done, but am a little afraid of
the redrawing/updating stuff. E.g. this confuses me already:
image := anImage depth = 1
ifTrue: [ColorForm mappingWhiteToTransparentFrom: anImage]
super extent: image extent
Intuitively the "changed" message should be send as the _last_
statement, not the first one. Can anyone explain?
More information about the Beginners