00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022
00023 #include "libavformat/framehook.h"
00024 #include "libswscale/swscale.h"
00025
00026 static int sws_flags = SWS_BICUBIC;
00027
00028 typedef struct {
00029 int dummy;
00030
00031
00032 struct SwsContext *toRGB_convert_ctx;
00033
00034
00035 struct SwsContext *fromRGB_convert_ctx;
00036
00037 } ContextInfo;
00038
00039 void Release(void *ctx)
00040 {
00041 ContextInfo *ci;
00042 ci = (ContextInfo *) ctx;
00043
00044 if (ctx) {
00045 sws_freeContext(ci->toRGB_convert_ctx);
00046 sws_freeContext(ci->fromRGB_convert_ctx);
00047 av_free(ctx);
00048 }
00049 }
00050
00051 int Configure(void **ctxp, int argc, char *argv[])
00052 {
00053 av_log(NULL, AV_LOG_DEBUG, "Called with argc=%d\n", argc);
00054
00055 *ctxp = av_mallocz(sizeof(ContextInfo));
00056 return 0;
00057 }
00058
00059 void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
00060 {
00061 ContextInfo *ci = (ContextInfo *) ctx;
00062 char *buf = 0;
00063 AVPicture picture1;
00064 AVPicture *pict = picture;
00065
00066 (void) ci;
00067
00068 if (pix_fmt != PIX_FMT_RGB24) {
00069 int size;
00070
00071 size = avpicture_get_size(PIX_FMT_RGB24, width, height);
00072 buf = av_malloc(size);
00073
00074 avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
00075
00076
00077 ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
00078 width, height, pix_fmt,
00079 width, height, PIX_FMT_RGB24,
00080 sws_flags, NULL, NULL, NULL);
00081 if (ci->toRGB_convert_ctx == NULL) {
00082 av_log(NULL, AV_LOG_ERROR,
00083 "Cannot initialize the toRGB conversion context\n");
00084 return;
00085 }
00086
00087
00088 sws_scale(ci->toRGB_convert_ctx,
00089 picture->data, picture->linesize, 0, height,
00090 picture1.data, picture1.linesize);
00091
00092 pict = &picture1;
00093 }
00094
00095
00096
00097 if (pix_fmt != PIX_FMT_RGB24) {
00098 ci->fromRGB_convert_ctx = sws_getCachedContext(ci->fromRGB_convert_ctx,
00099 width, height, PIX_FMT_RGB24,
00100 width, height, pix_fmt,
00101 sws_flags, NULL, NULL, NULL);
00102 if (ci->fromRGB_convert_ctx == NULL) {
00103 av_log(NULL, AV_LOG_ERROR,
00104 "Cannot initialize the fromRGB conversion context\n");
00105 return;
00106 }
00107
00108
00109 sws_scale(ci->fromRGB_convert_ctx,
00110 picture1.data, picture1.linesize, 0, height,
00111 picture->data, picture->linesize);
00112 }
00113
00114 av_free(buf);
00115 }
00116