port imlib2 vhook to swscaler

Patch by Victor Paesa %wzrlpy A arsystel P com%
Original thread + testcase:
Date: Sep 13, 2006 11:06 PM
Subject: Re: [Ffmpeg-devel] [PATCH] enable libswscale

Originally committed as revision 6648 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Víctor Paesa 2006-10-11 12:08:36 +00:00 committed by Guillaume Poirier
parent 6ab312daa2
commit 67d0436c8d
1 changed files with 41 additions and 16 deletions

View File

@ -46,6 +46,7 @@
*/ */
#include "framehook.h" #include "framehook.h"
#include "swscale.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -59,6 +60,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <Imlib2.h> #include <Imlib2.h>
static int sws_flags = SWS_BICUBIC;
typedef struct { typedef struct {
int dummy; int dummy;
Imlib_Font fn; Imlib_Font fn;
@ -68,6 +71,11 @@ typedef struct {
int x; int x;
int y; int y;
struct _CachedImage *cache; struct _CachedImage *cache;
// This vhook first converts frame to RGB ...
struct SwsContext *toRGB_convert_ctx;
// ... and then converts back frame from RGB to initial format
struct SwsContext *fromRGB_convert_ctx;
} ContextInfo; } ContextInfo;
typedef struct _CachedImage { typedef struct _CachedImage {
@ -87,8 +95,11 @@ void Release(void *ctx)
imlib_free_image(); imlib_free_image();
av_free(ci->cache); av_free(ci->cache);
} }
if (ctx) if (ctx) {
sws_freeContext(ci->toRGB_convert_ctx);
sws_freeContext(ci->fromRGB_convert_ctx);
av_free(ctx); av_free(ctx);
}
} }
int Configure(void **ctxp, int argc, char *argv[]) int Configure(void **ctxp, int argc, char *argv[])
@ -218,15 +229,24 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
data = imlib_image_get_data(); data = imlib_image_get_data();
avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGBA32, width, height); avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGBA32, width, height);
if (pix_fmt != PIX_FMT_RGBA32) {
if (img_convert(&picture1, PIX_FMT_RGBA32, // if we already got a SWS context, let's realloc if is not re-useable
picture, pix_fmt, width, height) < 0) { ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
goto done; width, height, pix_fmt,
} width, height, PIX_FMT_RGBA32,
} else { sws_flags, NULL, NULL, NULL);
img_copy(&picture1, picture, PIX_FMT_RGBA32, width, height); if (ci->toRGB_convert_ctx == NULL) {
av_log(NULL, AV_LOG_ERROR,
"Cannot initialize the toRGB conversion context\n");
exit(1);
} }
// img_convert parameters are 2 first destination, then 4 source
// sws_scale parameters are context, 4 first source, then 2 destination
sws_scale(ci->toRGB_convert_ctx,
picture->data, picture->linesize, 0, height,
picture1.data, picture1.linesize);
imlib_image_set_has_alpha(0); imlib_image_set_has_alpha(0);
{ {
@ -271,15 +291,20 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width,
} }
} }
if (pix_fmt != PIX_FMT_RGBA32) { ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
if (img_convert(picture, pix_fmt, width, height, PIX_FMT_RGBA32,
&picture1, PIX_FMT_RGBA32, width, height) < 0) { width, height, pix_fmt,
} sws_flags, NULL, NULL, NULL);
} else { if (ci->fromRGB_convert_ctx == NULL) {
img_copy(picture, &picture1, PIX_FMT_RGBA32, width, height); av_log(NULL, AV_LOG_ERROR,
"Cannot initialize the fromRGB conversion context\n");
exit(1);
} }
// img_convert parameters are 2 first destination, then 4 source
// sws_scale parameters are context, 4 first source, then 2 destination
sws_scale(ci->fromRGB_convert_ctx,
picture1.data, picture1.linesize, 0, height,
picture->data, picture->linesize);
done:
;
} }