CGImage rendering in iOS - ios

I'am decoding a video using ffmpeg, convert it from yuv420 color space to the rgba color space with convert it to a CGImage and render it to the screen. The video plays correctly. With Instruments I see that a third of the CPU cycles are used for another conversion (function is called CGSConvertBGRX8888toRGBA8888) Why is this second color space conversion necessary and why is there no conversion if I load for example a PNG image and draw it the same way?
Code for the CGImage creation:
http://pastebin.com/CqePhPzG
Thanks!

Looks like the byte ordering of the source image doesn't match the destination. Also, I believe X is non-premultiplied alpha whereas A is premultiplied alpha. Try changing the byte ordering settings you pass when creating your image or bitmap image context. HTH.

Related

Very close to building an uncompressed animate GIF from bytes - but it's got a bug I can't detect

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

Is it possible to display processed 14-bit Bayer images on iOS using UIImageView?

I made a project to process Bayer pixels from RAW images on iOS.
I would like to display the processed pixels on the iOS screen, without having to first convert it to 8-bit RGBA (the format for UIImage), which is what UIImageView seems to only accept.
I reviewed CIRAWFilter and the sample RawExposeEmbedded project from Apple, to see how to possibly draw 14-bit data to screen, but the methods they use to render the image to screen involves GLKView and GL functions.
Is this the only known way to render 14-bit RAW processed pixels to an iOS screen or is there an alternative method, such as using CIImage/UIImage with UIImageView?

iOS - Save UIImage as a greyscale JPEG

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.

How to figure out, If an imagefile (base64) has transparency?

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.

Convert apng to gif with sufficiant resolution and color depth

I want to convert some animated PNG (APNG) images to animated GIF. I can successfully convert with a utility I found on the web called apng2gif. Expertly named if I may say. The problem is it does not convert the images with sufficient color depth so the output is a little bit to pixelated and not so smooth relative to the original.
Does anyone know of any other image converters that might convert APNG to GIF with more that 16 bit color depth?
The problem is not with the converter, but with GIF format itself:
http://en.wikipedia.org/wiki/Graphics_Interchange_Format
The format supports up to 8 bits per pixel thus allowing a single image to reference a palette of up to 256 distinct colors.
If you need the GIF to blend better with the background, click on Settings button in apng2gif and then choose the background color you want.

Resources