I'm building a program in Mathematica that generates very simple GIFS that flip between single color squares. It is designed so that the image data is uncompressed, and does not use the LZW compression that most animated GIFs use. I've come across examples of uncompressed GIFs that are not animated, which are just single images, and I've come across very simple animated gifs that change color but they do use LZW. I haven't yet found an example of uncompressed and animated, and that's what I'm trying to do.
So far my program is successful at creating single frame gifs, as well as animated gifs with multiple frames but the animated gifs always come out the same color for each frame, or just some pixels change color, not the whole frame. I am trying to create animated gifs that flips from, for example, a Red Square to a Black Square, on loop.
Below are the block-by-block bytes of a GIF that my program created. I expected this is GIF to be a 2pixel by 2pixel square where the first frame is Red and then second frame is Black. Instead I got two frames of Red.
Header: 47,49,46,38,39,61
Logical Screen Descriptor: 02,00,02,00,f0,00,00
Global Color Table: ff,00,00,00,00,00
Application Extension Block: 21,ff,0b,4e,45,54,53,43,41,50,45,32, 2e,30,03,01,00,00,00
Graphic Extension Control: 21,f9,04,00,88,13,00,00
ImageDescriptor:2c,00,00,00,00,02,00,02,00,00
ImageData Block: 01,03,02,01,01,03,02,01,01,00,
Graphic Extension Control: 21,f9,04,00,88,13,00,00
ImageDescriptor:2c,00,00,00,00,02,00,02,00,00,
ImageData Block:01,03,02,01,01,03,02,01,01,00
Comment Extension: 21,fe,00,00
Trailer: 3B
If you'd like to look at these bytes in a hexeditor, here is the unbroken string of bytes:
47,49,46,38,39,61,02,00,02,00,f0,00,00,ff,00,00,00,00,00,21,ff,0b,4e,45,54,53,43,41,50,45,32,2e,30,03,01,00,00,00,21,f9,04,00,88,13,00,00,2c,00,00,00,00,02,00,02,00,00,01,03,02,01,01,03,02,01,01,00,21,f9,04,00,88,13,00,00,2c,00,00,00,00,02,00,02,00,00,01,03,02,01,01,03,02,01,01,00,21,fe,00,00,3B
My current thinking on what's the problem(s): Is there something wrong the LZW Minimum size (the first byte of the Image Data Block) or with the Clear Code (the third byte of the Image Data Block), because I've found that when I change them to a different value, it can sometimes make a single or double black pixel appear along with a 1-2 red pixels, but I can't figure out a pattern to the bug.
I also wonder if the background color being set to red is giving me a misleading understanding of the bug – are maybe no or very few pixels actually being drawn, but I can't tell because of the background color is the same as the as pixel color?
Here is the program I'm working on in Mathematica – It is partially commented, but I have not completed the comments yet:
https://www.wolframcloud.com/obj/8b483039-494b-476f-844d-a0f39d1d663b
And finally, these are the best resources I've come across that I have been basing my program off of are:
GifLib – What's in a Gif http://giflib.sourceforge.net/whatsinagif/index.html
Gif File Spec
https://www.w3.org/Graphics/GIF/spec-gif89a.txt
Wikipedia
https://en.wikipedia.org/wiki/GIF
In my app, I convert and process images.
from colour to greyscale, then doing operations such as histogram-equalisation, filtering, etc.
that part works fine.
my UIImage display correctly, I also save them to jpeg files and it works.
The only problem is that, although my images are now greyscales, they are still saved as RGB jpegs. that is the red, green and blue value for each pixel are the same but it still waste space to keep the duplicated value, making the file size higher than it could be.
So when i open the image file in photoshop, it is black & white but when I check "Photoshop > Image > Mode", it still says "RGB" instead of "Greyscale".
Anyone know how to tell iOS that the UIImageJPEGRepresentation call should create data with one channel per pixel instead of 4?
Thanks in advance.
You should do an explicit conversion of your image using CGColorSpaceCreateDeviceGray() as color space which is 8 bits per component, 1 channel.
i wonder, how i could figure out if an image has a transparency effect applied. Is there any way in JavaScript or HTML5? I have a Base64-coded image. Is there a way to read out the transparency-information (alpha-channel). For example, if i load a PNG-Image, then convert it to base64, then drop it to html5-canvas, now how can i know if this has transparency-effect activated?
thanx alot
okyo
When you say 'drop it to html5-canvas', I assume you mean using an image element with the 'data:' URI scheme. Also, let's take it as given that you don't want to write javascript code to parse the image files.
You could do something like this pseudo-code:
create 2 off-screen canvases
color one opaque white and the other opaque black
draw the image on both of them
call getImageData on each canvas, using the image bounds
compare the image data
If the image has any transparent or partially-transparent pixels, then presumably the two canvases will end up at least a little different. One exception would be if the image has the transparency feature enabled but is entirely opaque anyway. Another would be if the non-opaque pixels are only very slightly transparent - not enough to alter a white or black background. But this technique would catch images where transparency is noticeable.