static VideoDecoderStatus decode(VideoDecoder *vdec, Movie *m, Image *p, DemuxedPacket *dp, unsigned int len, unsigned int *used_r) { struct videodecoder_divx *vdm = (struct videodecoder_divx *)vdec->opaque; unsigned char *buf = dp->data; int res; if (len == 0) return VD_NEED_MORE_DATA; *used_r = len; vdm->dec_frame.length = len; vdm->dec_frame.bitstream = buf; vdm->dec_frame.bmp = memory_ptr(image_rendered_image(p)); vdm->dec_frame.render_flag = vdm->to_skip > 0 ? 0 : 1; vdm->dec_frame.stride = 0; pthread_mutex_lock(&vdec->update_mutex); if ((res = decore(vdm->dec_handle, DEC_OPT_FRAME, &vdm->dec_frame, NULL)) != DEC_OK) { if (res == DEC_BAD_FORMAT) { err_message("OPT_FRAME returns DEC_BAD_FORMAT\n"); } else { err_message("OPT_FRAME returns %d\n", res); } pthread_mutex_unlock(&vdec->update_mutex); return VD_ERROR; } m->current_frame++; if (vdm->to_skip > 0) { vdm->to_skip--; pthread_mutex_unlock(&vdec->update_mutex); return VD_OK; } vdec->ts_base = dp->ts_base; vdec->pts = m->current_frame * 1000 / rational_to_double(m->framerate); vdec->to_render++; while (m->status == _PLAY && vdec->to_render > 0) pthread_cond_wait(&vdec->update_cond, &vdec->update_mutex); pthread_mutex_unlock(&vdec->update_mutex); return VD_OK; }
DEFINE_SAVER_PLUGIN_SAVE(p, fp, c, params) { struct jpeg_compress_struct *cinfo = malloc(sizeof(struct jpeg_compress_struct)); struct my_error_mgr jerr; JSAMPROW buffer[1]; /* output row buffer */ int quality, result; debug_message("jpeg: save (%s) (%d, %d) called.\n", image_type_to_string(p->type), image_width(p), image_height(p)); if (cinfo == NULL) return 0; switch (p->type) { case _BITMAP_LSBFirst: case _BITMAP_MSBFirst: case _GRAY_ALPHA: case _INDEX: case _RGB565: case _BGR565: case _RGB555: case _BGR555: case _BGR24: case _RGBA32: case _ABGR32: case _ARGB32: case _BGRA32: show_message("Saving of %s type image is not yet implemented.\n", image_type_to_string(p->type)); return 0; case _GRAY: case _RGB24: break; default: fprintf(stderr, "Unknown image type: %d (maybe bug)\n", p->type); return 0; } cinfo->err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_compress(cinfo); free(cinfo); return 0; } quality = config_get_int(c, "/enfle/plugins/saver/jpeg/quality", &result); if (!result) quality = JPEG_SAVE_DEFAULT_QUALITY; else if (quality < 1 || quality > 100) { show_message("Invalid quality %d: defaults to %d.\n", quality, JPEG_SAVE_DEFAULT_QUALITY); quality = JPEG_SAVE_DEFAULT_QUALITY; } /* Now we can initialize the JPEG decompression object. */ jpeg_create_compress(cinfo); jpeg_stdio_dest(cinfo, fp); cinfo->image_width = image_width(p); cinfo->image_height = image_height(p); if (p->type == _GRAY) { cinfo->input_components = 1; cinfo->in_color_space = JCS_GRAYSCALE; } else { cinfo->input_components = 3; cinfo->in_color_space = JCS_RGB; } jpeg_set_defaults(cinfo); jpeg_set_quality(cinfo, quality, TRUE); jpeg_start_compress(cinfo, TRUE); while (cinfo->next_scanline < cinfo->image_height) { buffer[0] = (JSAMPROW)(memory_ptr(image_image(p)) + image_bpl(p) * cinfo->next_scanline); (void)jpeg_write_scanlines(cinfo, buffer, 1); } (void)jpeg_finish_compress(cinfo); jpeg_destroy_compress(cinfo); free(cinfo); debug_message("jpeg: saved.\n"); return 1; }
/* converts giflib format image into enfle format image */ static int gif_convert(Image *p, GIF_info *g_info, GIF_image *image) { GIF_ct *ct; int i, if_animated; //int transparent_disposal; #if 0 if (image->next != NULL) { if ((p->next = image_create()) == NULL) { image_destroy(p); return 0; } if (!gif_convert(p->next, g_info, image->next)) { image_destroy(p); return 0; } } else p->next = NULL; #endif //swidth = g_info->sd->width; //sheight = g_info->sd->height; image_left(p) = image->id->left; image_top(p) = image->id->top; image_width(p) = image->id->width; image_height(p) = image->id->height; #if 0 if (image_width(p) > swidth || image_height(p) > sheight) { show_message("screen (%dx%d) but image (%dx%d)\n", swidth, sheight, p->width, p->height); swidth = image_width(p); sheight = image_height(p); } #endif p->ncolors = image->id->lct_follows ? 1 << image->id->depth : 1 << g_info->sd->depth; p->type = _INDEX; //p->delay = image->gc->delay ? image->gc->delay : 1; if_animated = g_info->npics > 1 ? 1 : 0; debug_message("GIF: %d pics animation %d\n", g_info->npics, if_animated); #if 0 if (image->gc->transparent) { p->transparent_disposal = if_animated ? _TRANSPARENT : transparent_disposal; p->transparent.index = image->gc->transparent_index; } else p->transparent_disposal = _DONOTHING; p->image_disposal = image->gc->disposal; p->background.index = g_info->sd->back; #endif if (image->id->lct_follows) ct = image->id->lct; else if (g_info->sd->gct_follows) ct = g_info->sd->gct; else { fprintf(stderr, "Null color table..\n"); ct = NULL; } for (i = 0; i < (int)p->ncolors; i++) { p->colormap[i][0] = ct->cell[i]->value[0]; p->colormap[i][1] = ct->cell[i]->value[1]; p->colormap[i][2] = ct->cell[i]->value[2]; } image_bpl(p) = image_width(p); if (!image_image(p)) image_image(p) = memory_create(); if (memory_alloc(image_image(p), image_bpl(p) * image_height(p)) == NULL) return 0; memcpy(memory_ptr(image_image(p)), image->data, image_bpl(p) * image_height(p)); return 1; }