Creating Bitmaps from ARGB strings (in actionscript-3)? - actionscript-3

in actionscript 3, what's the fastest way to dump your data (not from a file) into a bitmap for display?
I have it working with setPixels and colored rects but that's way too slow/inefficient.
Is there a way to load in the raw bytes or hijack the loader class to put in custom loader data?
What would be the best/fastest--should I start writing a byte encoder?

You can quickly copy data from a ByteArray into a Bitmap using setPixels(). Even if you need to do some wrangling of your data beforehand, it should be way faster than setting each pixel individually.

Related

How would you convert an image to JSON in Lua?

As you all have probably guessed, I've been trying to make an image parser in a heavily modified and sandboxed version of Lua known as "RBX.Lua" on the kids' gaming platform "ROBLOX".
It is limited and sandboxed heavily to protect from harming the site or engine.
Anyway, is there any way in normal Lua to convert an online image (.png, .jpg, etc) to JSON?
This will probably be closed due to being submissive, and I acknowledge that - I just want to see if there is any way to convert an image into JSON so it returns a JSON table of all the pixel data.
The problem is that you'll have a hard time reconstructing it inside Roblox if you intend to display it. There's no way to give raw image data to GUIs, you'd have to do some trickery and create a frame for every pixel of the image, which isn't very practical.
Otherwise try converting the image data to base64 and then back again. As it'd still be highly compressed you'd have to do the jpg or png decoding in lua. Painful.

Write MATLAB plots as PNG,JPG to a MySQL database

I use MATLAB for calculating and plotting purposes. I want to write a plot as a image file like PNG or JPG into a MySQL database (that I can retreive later for a webbrowser). In other words I want to write a blob to the database that is a PNG or JPG file.
If I search for that I get http://www.mathworks.com/matlabcentral/answers/97768-how-do-i-insert-an-image-or-figure-into-a-database-using-the-database-toolbox-in-matlab but here a matrix of MATLAB is written as an array to a database. That is much bigger than a compressed PNG file and thus does not allow to see subplots and other things and cannot be displayed by a webbrowser.
A workaround would be to write the plot to a file and use MATLAB (or a external script tool based on python or so) to read that file as blob and write it as blob to the database.
Do you know a possibility to write a plot as PNG, JPG directly to a databse without the detour of a file?
I also asked the MATLAB support and they gave me an positive answer. A solution is the figToImStream function of MATLAB compiler toolbox: "Stream out figure as byte array encoded in format specified, creating signed byte array in .png format". The downside is that MATLAB compiler toolbox is quite expensive...

How to access jpeg pixels of bytearray directly in Actionscript 3

I'm trying to:
load a jpeg through FileReference
write the result to a bytearray
extract the pixel data (and nothing else) directly from the bytearray
I've spent many hours looking for an AS3 class that can decode a jpeg object from raw binary data (such as from a bytearray), but to no avail (there is one here but it relies on Alchemy and a SWC, which isn't suitable).
Put simply, once I have the raw data in the byte array, I'm want to know how to discern the pixel data from the rest of the file.
I'm not interested in using the Loader class, or Bitmap's 'getPixels' function.
you will notice that steganography relies on using a png file. The reason that you can't use the jpg file(easily) is that the encoding process removes the reliability of pixel data. Jpg files can be encoded in several ways, including CMYK and RGB but most often YCbCr. Jpg compression relies on Fourier transform, which will eliminate the pixel-level detail. Therefore you will not be able to use the same process on jpg and png,gif,bmp etc.
This is not to say that you cannot do it in a jpg file, but you need to change the approach, or account for loss of data at compressions stage (or save uncompressed).
Well, you could manipulate the compressed data directly to include your message, but you'd have to read up on how you're able to do it without totally corrupting the image.
But if you're thinking to encode the message in the pixels to do a per-pixel diff when decoding your message I'm afraid your assumption (from the comment on Daniel's answer) is wrong.
JPEG compression is lossy - this means that when you put the amended pixel data back into the image file it which will cause all pixel data to be lost (since it needs to be re-encoded.) Instead of pixel data the only information that's saved in the file is how to reassemble an image that appears very similar looking to the original for the human eye, but the pixel data is not the same.
Not even if you decode the image, then save it as a JPEG file, then do the transformation of the original image and finally save this as a second JPEG with the exact same compression settings can you rely on a per-pixel comparison.
However, as I seem to remember that JPEG compresses the image data in 8*8 pixel blocks, you might be able to manipulate and compare the image data on a per-block basis.
extract the pixel data (and nothing else) directly from the bytearray
To do this you need to decode the jpeg first (apart from some eventual metadata, there is nothing else than pixel data in a typical jpeg file), and the way to do that is precisely using Loader.loadBytes and then BitmapData.getPixels. You can probably make your own decoder (like the one you posted), but I don't see any benefit in doing so.
A guy named Thibault Imbert at ByteArray.org adapted the libjpeg library for ActionScript 3. I have not tested this, but other folks seem to like it by the comments at bytearray.org.
http://code.google.com/p/as3-jpeg-decoder/downloads/list

AS3: Saving a sprite to a file and reading it back?

I'm using Actionscript 3 and I need to be able to write a vector graphic sprite to a file and then load it back later. Normally I'd just serialize it in a ByteArray, but apparently you can't serialize a sprite. But it's just data, so there's got to be some way of representing it in a file. I've Googled until my fingers are sore, but I can't seem to turn up anything. Does anyone know how this can be done? Thanks!

How to read target extent from a huge TIFF file by LibTiff.Net library

I have a big tiff file which I don't want to load it into memory one time (That will cause my application takes so many memory), I want to load target part of it one time and show this part in screen.
I am trying to use LibTiff.net library for implement this, but I haven't found a suitable API for it.
Currently I can just load that by calloc a new array (very big!) then call ReadRGBAImageOriented function for load the RGBA value for it.
Do someone have experience on it?
Thanks