Go Back   Android Forums > Android Phones > Samsung Transform Ultra > Transform Ultra - All Things Root

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old April 14th, 2012, 10:10 PM   #1 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default Need some help with boot animation creator

Hi guys,

You may have noticed that I'm working on a program to convert an animated GIF to a bootanimation.zip.

I have almost everything working, but I realized something today: My converted PNGs don't work!

I can take an animated GIF and convert it into PNGs via a command line tool, and put them in a zip, and everything works. When I do the same with my tool it creates an almost identical image (slight differences in resize algorithm), but when I package them into a bootanimation.zip and put it on my phone it just shows a black screen on boot.

Here is an example of a working boot animation I made (created with command line utilities):
http://dl.dropbox.com/u/68531860/bootanimation.zip

and here is the same animation NOT working (created with my Java program):
http://dl.dropbox.com/u/68531860/bootanimationJ.zip

Here is my code:
Code:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Iterator;
import javax.imageio.*;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.*;

public class test {

	static BufferedImage background; // background (for optimized GIFs)

	public static void main(String[] args) throws Exception {

		Object input = new File("img.gif");  // or Object input = new FileInputStream("animated.gif");
		ImageInputStream stream = ImageIO.createImageInputStream(input);
		Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
		if (!readers.hasNext())
			throw new RuntimeException("no image reader found");
		ImageReader reader = (ImageReader) readers.next();
		reader.setInput(stream);
		
		int n = reader.getNumImages(true);
		System.out.println("numImages = " + n);

		for (int i = 0; i < n; i++) {

			// get metadata (in order to detect framerate and top/left positioning for each frame)
			IIOImage frame = reader.readAll(i,null);
			IIOMetadata meta = frame.getMetadata();
			IIOMetadataNode imgRootNode = (IIOMetadataNode) meta.getAsTree("javax_imageio_gif_image_1.0");
			
			// get framerate for animation
			if (i == 0) {
				IIOMetadataNode gce = (IIOMetadataNode) imgRootNode.getElementsByTagName("GraphicControlExtension").item(0);
				int delay = Integer.parseInt(gce.getAttribute("delayTime"));
				System.out.println("DELAY: " + delay);
			}

			IIOMetadataNode imgDescr = (IIOMetadataNode) imgRootNode.getElementsByTagName("ImageDescriptor").item(0);
			int offsetX = Integer.parseInt(imgDescr.getAttribute("imageLeftPosition"));  // find offsets for each
			int offsetY = Integer.parseInt(imgDescr.getAttribute("imageTopPosition"));   // frame in the animated GIF

			BufferedImage overlay = reader.read(i);
			if (i == 0) { background = reader.read(i); }

			// combine current and previous frame to create complete frame (in case of optimized GIFs)
			BufferedImage combined = new BufferedImage(background.getWidth(), background.getHeight(), BufferedImage.TYPE_INT_ARGB);

			// paint both images, preserving the alpha channels
			Graphics g = combined.getGraphics();
			g.drawImage(background, 0, 0, null);
			g.drawImage(overlay, offsetX, offsetY, null);			

			// create new directory for images
			if (i == 0) {
				new File("bootanimation/").mkdirs();
			}
			
			// resize frame to fit screen
			int resizeWidth;
			int resizeHeight;
			if (background.getWidth() > background.getHeight()) {
				resizeWidth = 480;
				resizeHeight = 320;	
			}
			else {
				resizeWidth = 320;
				resizeHeight = 480;
			}
			
			// Create new (blank) image of required (scaled) size
			BufferedImage scaledImage = new BufferedImage(resizeWidth, resizeHeight, BufferedImage.TYPE_INT_ARGB);
			// Paint scaled version of image to new image
			Graphics2D graphics2D = scaledImage.createGraphics();
			graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
			RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			graphics2D.drawImage(combined, 0, 0, resizeWidth, resizeHeight, null);
			graphics2D.dispose();
			
			// rotate the image if it's wider than it is tall
			if (scaledImage.getWidth() > scaledImage.getHeight()) {
				ImageIO.write(rotate270(scaledImage), "PNG", new File("bootanimation/img" + String.format("%04d", i) + ".png"));
			}
			else {
				ImageIO.write(scaledImage, "PNG", new File("bootanimation/img" + String.format("%04d", i) + ".png"));
			}
			background = combined; // save our most recently created frame as the background for the next frame (in case of optimized GIFs)
		}
		stream.close();

	}
	
	public static BufferedImage rotate270(BufferedImage img) {
		int width = img.getWidth();
		int height = img.getHeight();
		BufferedImage newImage = new BufferedImage(height, width, img.getType());

		for (int i = 0; i < width; i++)
			for (int j = 0; j < height; j++)
				newImage.setRGB(j, width - 1 - i, img.getRGB(i, j));

		return newImage;
	}
	
}
Please help me figure out what the difference is between my working and non working PNGs!

BLuFeNiX is offline  
Reply With Quote
sponsored links
Old April 14th, 2012, 11:21 PM   #2 (permalink)
Senior Member
 
Loota's Avatar
 
Join Date: Feb 2012
Location: Rockland, NY
Gender: Male
Posts: 739
 
Device(s): Kyocera Hydro Edge
Carrier: Not Provided

Thanks: 219
Thanked 496 Times in 261 Posts
Default

Sorry I'm half asleep and not good with code... are the pngs compressed at all? Is the boot animaTion zip compressed?
__________________
“All is caprice, they love without measure those whom they will soon hate without reason.”—Thomas Sydenham
Loota is offline  
Reply With Quote
Old April 15th, 2012, 12:11 AM   #3 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default

Quote:
Originally Posted by Loota View Post
Sorry I'm half asleep and not good with code... are the pngs compressed at all? Is the boot animaTion zip compressed?
I'm not aware of any PNG compression, but I guess it's possible that the ImageIO.write() method causes this in some way. The zip file is not compressed at all (I do the zipping part myself for testing, and zipped it the same way as the working animation).
BLuFeNiX is offline  
Reply With Quote
Old April 16th, 2012, 01:01 PM   #4 (permalink)
Junior Member
 
Join Date: Nov 2011
Location: RTP, NC
Posts: 38
 
Device(s): Sam Tranform-Ultra, LG Marquee, Sam Vitality, ZTE Score, Archos 70it, Pandigital Novel, Nook
Carrier: Not Provided

Thanks: 9
Thanked 14 Times in 10 Posts
Default

The bit depth on the non working one is 32. Needs to be 24?

Another difference I see is file creation and modified dates embedded at the end of you working images, but not in your non working or other known working ones I looked at so that must not be it. Unless I switched yours around.

Only other thing I can think of is check the permissions of the zip file.
KydDynoMyte is offline  
Last edited by KydDynoMyte; April 16th, 2012 at 03:39 PM.
Reply With Quote
Old April 16th, 2012, 02:10 PM   #5 (permalink)
Senior Member
 
Loota's Avatar
 
Join Date: Feb 2012
Location: Rockland, NY
Gender: Male
Posts: 739
 
Device(s): Kyocera Hydro Edge
Carrier: Not Provided

Thanks: 219
Thanked 496 Times in 261 Posts
Default

Quote:
Originally Posted by KydDynoMyte View Post
The bit depth on the non working one is 32. Needs to be 24?
That could be it... whenever I had a prob loading a image for a bootani I would just copy and paste onto a working boot ani image and resave it.. not that you should have to do that fenix but bit depth could be why it wasn't working and was solved once I copied an image onto a working img
Loota is offline  
Reply With Quote
Old April 16th, 2012, 08:37 PM   #6 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default

Quote:
Originally Posted by KydDynoMyte View Post
The bit depth on the non working one is 32. Needs to be 24?

Another difference I see is file creation and modified dates embedded at the end of you working images, but not in your non working or other known working ones I looked at so that must not be it. Unless I switched yours around.

Only other thing I can think of is check the permissions of the zip file.
Quote:
Originally Posted by Loota View Post
That could be it... whenever I had a prob loading a image for a bootani I would just copy and paste onto a working boot ani image and resave it.. not that you should have to do that fenix but bit depth could be why it wasn't working and was solved once I copied an image onto a working img
I read somewhere that 32bit images are supposed to work, but I will try 24. I know the permissions are okay because I've done numerous "sanity checks" with working animations. Thank you both for the input.
BLuFeNiX is offline  
Reply With Quote
Old April 16th, 2012, 09:22 PM   #7 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default

Quote:
Originally Posted by BLuFeNiX View Post
I read somewhere that 32bit images are supposed to work, but I will try 24. I know the permissions are okay because I've done numerous "sanity checks" with working animations. Thank you both for the input.
Making them 24bit did not fix it.
BLuFeNiX is offline  
Reply With Quote
Old April 16th, 2012, 11:47 PM   #8 (permalink)
Junior Member
 
Join Date: Nov 2011
Location: RTP, NC
Posts: 38
 
Device(s): Sam Tranform-Ultra, LG Marquee, Sam Vitality, ZTE Score, Archos 70it, Pandigital Novel, Nook
Carrier: Not Provided

Thanks: 9
Thanked 14 Times in 10 Posts
Default

Quote:
Originally Posted by BLuFeNiX View Post
Making them 24bit did not fix it.
I think it might be because the one that doesn't work has an alpha channel transparency layer in it.
KydDynoMyte is offline  
Reply With Quote
Old April 17th, 2012, 11:14 AM   #9 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default

Quote:
Originally Posted by KydDynoMyte View Post
I think it might be because the one that doesn't work has an alpha channel transparency layer in it.
32bit means it has an alpha channel, 24bit means no alpha. (8 bits for each color, Red, Green, Blue, and optionally, Alpha) So, removing the alpha did not fix it.

However....

I did get it working! I'll be posting an alpha release either today or tomorrow. All I have left to do is clean up the code, and add the piece that zips the files.
Can't decide if alpha release will have GUI, might wait for beta.

Thank you all for your input.
BLuFeNiX is offline  
Reply With Quote
Old April 17th, 2012, 12:41 PM   #10 (permalink)
Junior Member
 
Join Date: Nov 2011
Location: RTP, NC
Posts: 38
 
Device(s): Sam Tranform-Ultra, LG Marquee, Sam Vitality, ZTE Score, Archos 70it, Pandigital Novel, Nook
Carrier: Not Provided

Thanks: 9
Thanked 14 Times in 10 Posts
Default

Quote:
Originally Posted by BLuFeNiX View Post
32bit means it has an alpha channel, 24bit means no alpha. (8 bits for each color, Red, Green, Blue, and optionally, Alpha) So, removing the alpha did not fix it.

However....

I did get it working! I'll be posting an alpha release either today or tomorrow. All I have left to do is clean up the code, and add the piece that zips the files.
Can't decide if alpha release will have GUI, might wait for beta.

Thank you all for your input.
What fixed it?
KydDynoMyte is offline  
Reply With Quote
sponsored links
Old April 17th, 2012, 01:09 PM   #11 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default

Quote:
Originally Posted by KydDynoMyte View Post
What fixed it?
I ended up having to try about a dozen different libraries for writing out a PNG file. Finally found one that worked: org.apache.xmlgraphics.image.codec.png.PNGImageEnc oder

You'd be surprised how many other libraries just don't write the correct metadata.
BLuFeNiX is offline  
Reply With Quote
Old April 17th, 2012, 04:57 PM   #12 (permalink)
Member
Thread Author (OP)
 
BLuFeNiX's Avatar
 
Join Date: Feb 2012
Posts: 206
 
Device(s):
Carrier: Not Provided

Thanks: 113
Thanked 104 Times in 59 Posts
Default

Quote:
Originally Posted by BLuFeNiX View Post
32bit means it has an alpha channel, 24bit means no alpha. (8 bits for each color, Red, Green, Blue, and optionally, Alpha) So, removing the alpha did not fix it.

However....

I did get it working! I'll be posting an alpha release either today or tomorrow. All I have left to do is clean up the code, and add the piece that zips the files.
Can't decide if alpha release will have GUI, might wait for beta.

Thank you all for your input.
First version released! http://androidforums.com/samsung-transform-ultra/533275-gif2boot-convert-animated-gifs-boot-animations-v0-1a.html
BLuFeNiX is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Phones > Samsung Transform Ultra > Transform Ultra - All Things Root
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:30 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.