This is my first post on the board, so I’m a sort of a newbie at this (…eh, but not entirely.) I’ve searched the archives, but didn’t find anything that resembled this question. OK - I built a program that lets you take a raw feed from a streaming webcam and then decode the file into many seperate .JPG files that make up the larger raw file. My program also lets you see the cam as it’s downloading, so you don’t have to switch back to the page to see it. The way that I currently get the preview image to show up is to read the raw file back to the last 60,000 bytes, then it finds a certain starting point where the JPEG header starts, starts reading from there and stops reading at a certain point n bytes later, where the JPG file ends, then store that data in a seperate file, PreviewFile.jpg, and load that into an image view using the load image command. My question is this - is there any way to take the raw data from the main file from x bytes to n bytes and load that into an image view without having to save out to the temp file? I’ve tried using
set tempImage to read theFile from x to y as picture
close access theFile
set image view "imageView" of window "theWindow" to tempImage
and it doesn’t work. Although, if you write the data from tempImage to another file and open the new file in Preview (or any other app. that can read JPGs), it shows the picture correctly. Do I have to tap into Cocoa to do this, or isn’t there a way possible to make this work? The method I use now is fine for previewing images, but I’m planning on building a non-linear editing/viewing program that can take the RAW file and play it like a QuickTime movie without having to decode it into seperate files first. It would be much better and faster to do it all in memory instead of having to dip the temp. data to the temp file for every frame!
I’m not too familiar with image manipulation at the source code level, but this may get you started. As far as I know, ASStudio has no support for many of the cocoa data methods, including those for handling image data, so you must use ‘call method’ to access the cocoa API directly.
I used a simple ‘read file’ on a test jpeg to get it’s source as a string, and then used the following code to get it into an image view. Hope this is what you’re looking for.
set myImageView to (image view "myImageView" of window "myWindow")
(* Change this so "rawImageData" contains your data as a string *)
set rawImageData to read file myFile as string
call method "displayImageDataString:inImageView:" of class "JBImageView" with parameters {rawImageData, myImageView}
The cocoa subclass file “JBImageView.m” (‘.h’ file not necessary)…
Yes! Thank you!! That snippet did allow me to take the smaller parts of the file and put it in memory! I have noticed a few things though. 1 - I sometimes get an error that the NSWarning nib can’t be loaded while scrubbing - I’m not sure what this is. 2 - I sometimes get “illegal call to JPEG library” errors, but I’m pretty sure that problem lies in my raw file extraction method (the data that the call uses isn’t valid data), which I’ll fix, and 3 - The more I scrub the slider, the more memory the program seems to take up. Is there a way to declare an image, then send it to the image view, and then delete it when it’s done (the next frame is loaded, the old one can be deleted?) With AS itself, it’s easy, but this is an entirely different method to get to the view itself. Is there an easy way to delete the old images, such as
delete image of image view "theImageView"
or
delete contents of image view...
or something similar? Those particular lines doesn’t work. Does it need an equally-Cocoa based script to delete the allocated image?
per a Cocoa tutorial on memory releasing and containing. The method seems to work, as both times I’ve started the program, the memory usage of the program is within 2mb. of the original use. Is this alright, or is there something I’m not seeing with it?