Ejemplo n.º 1
0
static int get_image(struct image_info *info, int ds)
{
    unsigned char **p_disp = &disp[ds]; /* short cut */
    LodePNG_Decoder *p_decoder = &decoder;

    info->width = p_decoder->infoPng.width / ds;
    info->height = p_decoder->infoPng.height / ds;
    info->data = p_disp;

    if (*p_disp != NULL)
    {
        /* we still have it */
        return PLUGIN_OK;
    }

    /* assign image buffer */
    if (ds > 1) {
        if (!iv->running_slideshow)
        {
            rb->lcd_putsf(0, 3, "resizing %d*%d", info->width, info->height);
            rb->lcd_update();
        }
        struct bitmap bmp_src, bmp_dst;

        int size = img_mem(ds);

        if (disp_buf + size >= p_decoder->buf + p_decoder->buf_size) {
            /* have to discard the current */
            int i;
            for (i=1; i<=8; i++)
                disp[i] = NULL; /* invalidate all bitmaps */

            /* start again from the beginning of the buffer */
            disp_buf = p_decoder->buf + p_decoder->native_img_size;
        }

        *p_disp = disp_buf;
        disp_buf += size;

        bmp_src.width = p_decoder->infoPng.width;
        bmp_src.height = p_decoder->infoPng.height;
        bmp_src.data = p_decoder->buf;

        bmp_dst.width = info->width;
        bmp_dst.height = info->height;
        bmp_dst.data = *p_disp;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
        rb->cpu_boost(true);
        resize_bitmap(&bmp_src, &bmp_dst);
        rb->cpu_boost(false);
#else
        resize_bitmap(&bmp_src, &bmp_dst);
#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
    } else {
        *p_disp = p_decoder->buf;
    }

    return PLUGIN_OK;
}
Ejemplo n.º 2
0
int get_image(struct image_info *info, int ds)
{
    int w, h; /* used to center output */
    int size; /* decompressed image size */
    long time; /* measured ticks */
    int status;
    struct jpeg* p_jpg = &jpg;
    struct t_disp* p_disp = &disp[ds]; /* short cut */

    info->width = p_jpg->x_size / ds;
    info->height = p_jpg->y_size / ds;
    info->data = p_disp;

    if (p_disp->bitmap[0] != NULL)
    {
        /* we still have it */
        return PLUGIN_OK;
    }

    /* assign image buffer */

    /* physical size needed for decoding */
    size = img_mem(ds);
    if (buf_images_size <= size)
    {   /* have to discard the current */
        int i;
        for (i=1; i<=8; i++)
            disp[i].bitmap[0] = NULL; /* invalidate all bitmaps */
        buf_images = buf_root; /* start again from the beginning of the buffer */
        buf_images_size = root_size;
    }

#ifdef HAVE_LCD_COLOR
    if (p_jpg->blocks > 1) /* colour jpeg */
    {
        int i;

        for (i = 1; i < 3; i++)
        {
            size = (p_jpg->x_phys / ds / p_jpg->subsample_x[i])
                 * (p_jpg->y_phys / ds / p_jpg->subsample_y[i]);
            p_disp->bitmap[i] = buf_images;
            buf_images += size;
            buf_images_size -= size;
        }
        p_disp->csub_x = p_jpg->subsample_x[1];
        p_disp->csub_y = p_jpg->subsample_y[1];
    }
    else
    {
        p_disp->csub_x = p_disp->csub_y = 0;
        p_disp->bitmap[1] = p_disp->bitmap[2] = buf_images;
    }
#endif
    /* size may be less when decoded (if height is not block aligned) */
    size = (p_jpg->x_phys/ds) * (p_jpg->y_size/ds);
    p_disp->bitmap[0] = buf_images;
    buf_images += size;
    buf_images_size -= size;

    if(!running_slideshow)
    {
        rb->snprintf(print, sizeof(print), "decoding %d*%d",
                        info->width, info->height);
        rb->lcd_puts(0, 3, print);
        rb->lcd_update();
    }

    /* update image properties */
    p_disp->stride = p_jpg->x_phys / ds; /* use physical size for stride */

    /* the actual decoding */
    time = *rb->current_tick;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(true);
    status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progress);
    rb->cpu_boost(false);
#else
    status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progress);
#endif
    if (status)
    {
        rb->splashf(HZ, "decode error %d", status);
        return PLUGIN_ERROR;
    }
    time = *rb->current_tick - time;

    if(!running_slideshow)
    {
        rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ);
        rb->lcd_getstringsize(print, &w, &h); /* centered in progress bar */
        rb->lcd_putsxy((LCD_WIDTH - w)/2, LCD_HEIGHT - h, print);
        rb->lcd_update();
    }

    return PLUGIN_OK;
}
Ejemplo n.º 3
0
Archivo: gif.c Proyecto: 4nykey/rockbox
static int get_image(struct image_info *info, int frame, int ds)
{
    unsigned char **p_disp = disp + frame*4 + ds2index(ds);
    struct gif_decoder *p_decoder = &decoder;

    info->width = p_decoder->width / ds;
    info->height = p_decoder->height / ds;
    info->data = p_disp;

    if (*p_disp != NULL)
    {
        /* we still have it */
        return PLUGIN_OK;
    }

    /* assign image buffer */
    if (ds > 1)
    {
        if (!iv->running_slideshow)
        {
            rb->lcd_putsf(0, 3, "resizing %d*%d", info->width, info->height);
            rb->lcd_update();
        }
        struct bitmap bmp_src, bmp_dst;

        /* size of the scalled image */
        int size = img_mem(ds);

        if (disp_buf + size >= p_decoder->mem + p_decoder->mem_size)
        {
            /* have to discard scaled versions */
            for (int i=0; i<p_decoder->frames_count; i++)
            {
                /* leave unscaled pointer allone,
                 * set rest to NULL
                 */
                p_disp = disp + i*4 + 1;
                memset(p_disp, 0, 3*sizeof(unsigned char *));
            }

            /* start again from the beginning of the buffer */
            disp_buf = p_decoder->mem +
                       p_decoder->native_img_size*p_decoder->frames_count +
                       sizeof(unsigned char *)*p_decoder->frames_count*4;
        }

        *p_disp = disp_buf;
        disp_buf += size;

        bmp_src.width = p_decoder->width;
        bmp_src.height = p_decoder->height;
        bmp_src.data = p_decoder->mem + p_decoder->native_img_size*frame;

        bmp_dst.width = info->width;
        bmp_dst.height = info->height;
        bmp_dst.data = *p_disp;

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
        rb->cpu_boost(true);
#endif
        resize_bitmap(&bmp_src, &bmp_dst);

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
        rb->cpu_boost(false);
#endif
    }
    else
    {
        *p_disp = p_decoder->mem + p_decoder->native_img_size*frame;
    }

    return PLUGIN_OK;
}