00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 extern "C" {
00028 #include "libswscale/swscale.h"
00029 }
00030
00031 #include <QMutex>
00032 #include <QMutexLocker>
00033
00034 #include "mythlogging.h"
00035 #include "myth_imgconvert.h"
00036
00037 int myth_sws_img_convert(AVPicture *dst, PixelFormat dst_pix_fmt, AVPicture *src,
00038 PixelFormat pix_fmt, int width, int height)
00039 {
00040 static QMutex ctx_lock;
00041 static struct SwsContext *convert_ctx;
00042
00043 QMutexLocker locker(&ctx_lock);
00044 convert_ctx = sws_getCachedContext(convert_ctx, width, height, pix_fmt,
00045 width, height, dst_pix_fmt,
00046 SWS_FAST_BILINEAR, NULL, NULL, NULL);
00047 if (convert_ctx == NULL) {
00048 LOG(VB_GENERAL, LOG_ERR, "myth_sws_img_convert: Cannot initialize "
00049 "the image conversion context");
00050 return -1;
00051 }
00052
00053 sws_scale(convert_ctx, src->data, src->linesize,
00054 0, height, dst->data, dst->linesize);
00055
00056 return 0;
00057 }