[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.6

Gif to JPEG Conversion with Java1.3

Asked by Wilkhu in Java Programming Language, Graphics

Tags: fastest, gif_mime_type, httpcache

Hi,
I am finding the best and fastest way of converting a GIF Image to JPEG, with the restriction that I am using JDK1.3
I have tried using JAI but at times the images returned are broken. And Black and White images cannot be converted at all. Can someone please please help fix this problem.
Here is the code that doesnt function well.

Also, when this code is loaded on a HP-UX box, it throws a register error stating something is already registered.

****************
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;

import org.apache.log4j.Logger;

import com.sun.media.jai.codec.ByteArraySeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageEncoder;
import com.sun.media.jai.codec.JPEGEncodeParam;
import com.tmobile.wfe.idc.web.cache.CacheItem;
import com.tmobile.wfe.idc.web.cache.HTTPCache;

/**
 * Cache which automatically converts source images into JPEGs.
 * Uses JAI classes to perform the conversion (so needs jai_core.jar and jai_codec.jar).
 */
public class ImageTranscoderCache extends HTTPCache {

      /** Log4j logger. */
      private static Logger log = Logger.getLogger(ImageTranscoderCache.class);

      /** Mime-type for GIF images */
      public static final String GIF_MIME_TYPE = "image/gif";

      /** Mime-type for JPEG images */
      public static final String JPEG_MIME_TYPE = "image/jpeg";
      
      /** Quality setting for JPEG compression. */
      private float jpegQuality;
      
      public ImageTranscoderCache(int expiryMinutes, int maxSize,
            String username, String password, float jpegQuality)
      {
            super(expiryMinutes, maxSize, username, password);
            this.jpegQuality = jpegQuality;
      }
      
      /**
       * Converts GIF images into JPEGs, leaving other types of media unchanged.
       * Uses the HTTPCache superclass's createCacheItem method to actually fetch the
       * contents of the target URL (as a byte[] array), which both simplifies things here,
       * and ensures that any enhancements to that method get used here.
       * TODO Monochrome GIFs don't seem to get work, so left alone.  Fix!
       */
      protected CacheItem createCacheItem(String itemId) throws IOException {
            // Get the source image data
            CacheItem sourceCacheItem = super.createCacheItem(itemId);

            // Return the cached item unchanged if it isn't a GIF (doesn't start with GIF mimetype).
            if (sourceCacheItem.getMime_type().indexOf(GIF_MIME_TYPE) != 0) {
                  log.debug("The MIME Type is: " + sourceCacheItem.getMime_type());
                  log.debug("Not a GIF: " + itemId);
                  return sourceCacheItem;
            }
            
            // Read the source image as a JAI object
            final byte[] sourceData = sourceCacheItem.getData();
            
            if (sourceData == null || sourceData.length == 0) {
                  throw new IOException("No image data read for: " + itemId);
            }
            RenderedOp sourceImage = JAI.create("stream", new ByteArraySeekableStream(sourceData));

            // If monochrome then leave unchanged (since JAI then seems to generate a JPEG that
            // browsers can't understand).
            // TODO Fix this!  Try changing the colour rep?
            if (sourceImage.getColorModel().getPixelSize() == 1) {
                  log.debug("Monochrome, so leaving unchanged");
                  return sourceCacheItem;
            }
            
            // Then convert it to a JPEG
        JPEGEncodeParam encodeParam = new JPEGEncodeParam();
        encodeParam.setQuality(jpegQuality);  // TODO change this to 1.0F high quality!
       
        // Write it to a byte array
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG", outStream, encodeParam);
        encoder.encode(sourceImage);
            outStream.close();      // close actually does nothing, so don't need finally
            
            // And return the converted image
            final byte[] jpegData = outStream.toByteArray();
            log.debug("Converted to JPEG.  Was " + sourceData.length + " bytes, now "
                        + jpegData.length);
            return createCacheItem(itemId, jpegData, JPEG_MIME_TYPE);
      }
}
[+][-]11/11/04 02:16 AM, ID: 12553196Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Java Programming Language, Graphics
Tags: fastest, gif_mime_type, httpcache
Sign Up Now!
Solution Provided By: girionis
Participating Experts: 2
Solution Grade: A
 
[+][-]11/11/04 02:17 AM, ID: 12553198Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 02:28 AM, ID: 12553243Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 02:31 AM, ID: 12553260Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 02:34 AM, ID: 12553270Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 02:35 AM, ID: 12553275Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 02:38 AM, ID: 12553286Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 02:42 AM, ID: 12553299Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 02:49 AM, ID: 12553329Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 02:56 AM, ID: 12553359Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 02:58 AM, ID: 12553370Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 03:01 AM, ID: 12553382Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 03:08 AM, ID: 12553421Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 03:09 AM, ID: 12553424Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 03:14 AM, ID: 12553447Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 03:15 AM, ID: 12553459Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 03:18 AM, ID: 12553478Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 03:33 AM, ID: 12553546Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 03:35 AM, ID: 12553562Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 03:41 AM, ID: 12553597Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/04 03:49 AM, ID: 12553646Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 04:02 AM, ID: 12553726Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/04 04:13 AM, ID: 12553796Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/10/04 01:53 PM, ID: 12796639Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12/11/04 11:05 AM, ID: 12800850Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/14/04 02:23 AM, ID: 12817524Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12/18/04 05:56 AM, ID: 12857125Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89