Input::readImageData(boost::shared_ptr<IOChannel> in, FileType type)
{
    std::auto_ptr<GnashImage> im;
    std::auto_ptr<Input> inChannel;

    switch (type) {
#ifdef USE_PNG
        case GNASH_FILETYPE_PNG:
            inChannel = createPngInput(in);
            break;
#endif
#ifdef USE_GIF                
        case GNASH_FILETYPE_GIF:
            inChannel = createGifInput(in);
            break;
#endif
        case GNASH_FILETYPE_JPEG:
            inChannel = JpegInput::create(in);
            break;
        default:
            break;
    }
    
    if (!inChannel.get()) return im;
    
    const size_t height = inChannel->getHeight();
    const size_t width = inChannel->getWidth();

    try {
        switch (inChannel->imageType()) {
            case TYPE_RGB:
                im.reset(new ImageRGB(width, height));
                break;
            case TYPE_RGBA:
                im.reset(new ImageRGBA(width, height));
                break;
            default:
                log_error(_("Invalid image returned"));
                return im;
        }
    }
    catch (std::bad_alloc& e) {
        // This should be caught here because ~JpegInput can also
        // throw an exception on stack unwinding and this confuses
        // remote catchers.
        log_error(_("Out of memory while trying to create %dx%d image"),
                width, height);
        return im;
    }
    

    for (size_t i = 0; i < height; ++i) {
        inChannel->readScanline(scanline(*im, i));
    }

    // The renderers expect RGBA data to be preprocessed. JPEG images are
    // never transparent, but the addition of alpha data stored elsewhere
    // in the SWF is possible; in that case, the processing happens during
    // mergeAlpha().
    if (im->type() == TYPE_RGBA) {
        processAlpha(im->begin(), width * height);
    }
    return im;
}
Input::readImageData(boost::shared_ptr<IOChannel> in, FileType type)
{
    std::auto_ptr<GnashImage> im;
    std::auto_ptr<Input> inChannel;

    switch (type) {
#ifdef USE_PNG
        case GNASH_FILETYPE_PNG:
            inChannel = createPngInput(in);
            break;
#endif
#ifdef USE_GIF                
        case GNASH_FILETYPE_GIF:
            inChannel = createGifInput(in);
            break;
#endif
        case GNASH_FILETYPE_JPEG:
            inChannel = JpegInput::create(in);
            break;
        default:
            break;
    }
    
    if (!inChannel.get()) return im;
    
    const size_t height = inChannel->getHeight();
    const size_t width = inChannel->getWidth();

    try {
        switch (inChannel->imageType()) {
            case TYPE_RGB:
                im.reset(new ImageRGB(width, height));
                break;
            case TYPE_RGBA:
                im.reset(new ImageRGBA(width, height));
                break;
            default:
                log_error(_("Invalid image returned"));
                return im;
        }
    }
    catch (std::bad_alloc& e) {
         
         
         
        log_error(_("Out of memory while trying to create %dx%d image"),
                width, height);
        return im;
    }
    

    for (size_t i = 0; i < height; ++i) {
        inChannel->readScanline(scanline(*im, i));
    }

     
     
     
     
    if (im->type() == TYPE_RGBA) {
        processAlpha(im->begin(), width * height);
    }
    return im;
}