mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
create colorspace.h and use it where appropriate
patch by Ian Caulfield: /ian caulfield gmail com/ Originally committed as revision 9716 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
208e63b479
commit
04d2e45f3f
107
libavcodec/colorspace.h
Normal file
107
libavcodec/colorspace.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Colorspace conversion defines
|
||||||
|
* Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
|
||||||
|
*
|
||||||
|
* This file is part of FFmpeg.
|
||||||
|
*
|
||||||
|
* FFmpeg is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FFmpeg is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with FFmpeg; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file colorspace.h
|
||||||
|
* Various defines for YUV<->RGB conversion
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SCALEBITS 10
|
||||||
|
#define ONE_HALF (1 << (SCALEBITS - 1))
|
||||||
|
#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
||||||
|
|
||||||
|
#define YUV_TO_RGB1_CCIR(cb1, cr1)\
|
||||||
|
{\
|
||||||
|
cb = (cb1) - 128;\
|
||||||
|
cr = (cr1) - 128;\
|
||||||
|
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
|
||||||
|
g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
|
||||||
|
ONE_HALF;\
|
||||||
|
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
|
||||||
|
{\
|
||||||
|
y = ((y1) - 16) * FIX(255.0/219.0);\
|
||||||
|
r = cm[(y + r_add) >> SCALEBITS];\
|
||||||
|
g = cm[(y + g_add) >> SCALEBITS];\
|
||||||
|
b = cm[(y + b_add) >> SCALEBITS];\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define YUV_TO_RGB1(cb1, cr1)\
|
||||||
|
{\
|
||||||
|
cb = (cb1) - 128;\
|
||||||
|
cr = (cr1) - 128;\
|
||||||
|
r_add = FIX(1.40200) * cr + ONE_HALF;\
|
||||||
|
g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
|
||||||
|
b_add = FIX(1.77200) * cb + ONE_HALF;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define YUV_TO_RGB2(r, g, b, y1)\
|
||||||
|
{\
|
||||||
|
y = (y1) << SCALEBITS;\
|
||||||
|
r = cm[(y + r_add) >> SCALEBITS];\
|
||||||
|
g = cm[(y + g_add) >> SCALEBITS];\
|
||||||
|
b = cm[(y + b_add) >> SCALEBITS];\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define Y_CCIR_TO_JPEG(y)\
|
||||||
|
cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
|
||||||
|
|
||||||
|
#define Y_JPEG_TO_CCIR(y)\
|
||||||
|
(((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
||||||
|
|
||||||
|
#define C_CCIR_TO_JPEG(y)\
|
||||||
|
cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
|
||||||
|
|
||||||
|
/* NOTE: the clamp is really necessary! */
|
||||||
|
static inline int C_JPEG_TO_CCIR(int y) {
|
||||||
|
y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
|
||||||
|
if (y < 16)
|
||||||
|
y = 16;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define RGB_TO_Y(r, g, b) \
|
||||||
|
((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
|
||||||
|
FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
|
||||||
|
|
||||||
|
#define RGB_TO_U(r1, g1, b1, shift)\
|
||||||
|
(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
|
||||||
|
FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||||
|
|
||||||
|
#define RGB_TO_V(r1, g1, b1, shift)\
|
||||||
|
(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
|
||||||
|
FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||||
|
|
||||||
|
#define RGB_TO_Y_CCIR(r, g, b) \
|
||||||
|
((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
|
||||||
|
FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
||||||
|
|
||||||
|
#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
|
||||||
|
(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
|
||||||
|
FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||||
|
|
||||||
|
#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
|
||||||
|
(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
|
||||||
|
FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||||
|
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
|
#include "colorspace.h"
|
||||||
|
|
||||||
typedef struct DVBSubtitleContext {
|
typedef struct DVBSubtitleContext {
|
||||||
int hide_state;
|
int hide_state;
|
||||||
@ -193,22 +194,6 @@ static void dvb_encode_rle4(uint8_t **pq,
|
|||||||
*pq = q;
|
*pq = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SCALEBITS 10
|
|
||||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
|
||||||
#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
|
||||||
|
|
||||||
#define RGB_TO_Y_CCIR(r, g, b) \
|
|
||||||
((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
|
|
||||||
FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
|
||||||
|
|
||||||
#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
|
|
||||||
(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
|
|
||||||
FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
|
||||||
|
|
||||||
#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
|
|
||||||
(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
|
|
||||||
FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
|
||||||
|
|
||||||
static int encode_dvb_subtitles(DVBSubtitleContext *s,
|
static int encode_dvb_subtitles(DVBSubtitleContext *s,
|
||||||
uint8_t *outbuf, AVSubtitle *h)
|
uint8_t *outbuf, AVSubtitle *h)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "dsputil.h"
|
#include "dsputil.h"
|
||||||
#include "bitstream.h"
|
#include "bitstream.h"
|
||||||
|
#include "colorspace.h"
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
//#define DEBUG_PACKET_CONTENTS
|
//#define DEBUG_PACKET_CONTENTS
|
||||||
@ -894,29 +895,6 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SCALEBITS 10
|
|
||||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
|
||||||
#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
|
||||||
|
|
||||||
#define YUV_TO_RGB1_CCIR(cb1, cr1)\
|
|
||||||
{\
|
|
||||||
cb = (cb1) - 128;\
|
|
||||||
cr = (cr1) - 128;\
|
|
||||||
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
|
|
||||||
g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
|
|
||||||
ONE_HALF;\
|
|
||||||
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
|
|
||||||
{\
|
|
||||||
y = ((y1) - 16) * FIX(255.0/219.0);\
|
|
||||||
r = cm[(y + r_add) >> SCALEBITS];\
|
|
||||||
g = cm[(y + g_add) >> SCALEBITS];\
|
|
||||||
b = cm[(y + b_add) >> SCALEBITS];\
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
|
static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
|
||||||
uint8_t *buf, int buf_size)
|
uint8_t *buf, int buf_size)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "dsputil.h"
|
#include "dsputil.h"
|
||||||
|
#include "colorspace.h"
|
||||||
|
|
||||||
#ifdef HAVE_MMX
|
#ifdef HAVE_MMX
|
||||||
#include "i386/mmx.h"
|
#include "i386/mmx.h"
|
||||||
@ -1158,87 +1159,6 @@ static void yuv420p_to_uyvy422(AVPicture *dst, const AVPicture *src,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SCALEBITS 10
|
|
||||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
|
||||||
#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
|
||||||
|
|
||||||
#define YUV_TO_RGB1_CCIR(cb1, cr1)\
|
|
||||||
{\
|
|
||||||
cb = (cb1) - 128;\
|
|
||||||
cr = (cr1) - 128;\
|
|
||||||
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
|
|
||||||
g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
|
|
||||||
ONE_HALF;\
|
|
||||||
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
|
|
||||||
{\
|
|
||||||
y = ((y1) - 16) * FIX(255.0/219.0);\
|
|
||||||
r = cm[(y + r_add) >> SCALEBITS];\
|
|
||||||
g = cm[(y + g_add) >> SCALEBITS];\
|
|
||||||
b = cm[(y + b_add) >> SCALEBITS];\
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YUV_TO_RGB1(cb1, cr1)\
|
|
||||||
{\
|
|
||||||
cb = (cb1) - 128;\
|
|
||||||
cr = (cr1) - 128;\
|
|
||||||
r_add = FIX(1.40200) * cr + ONE_HALF;\
|
|
||||||
g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
|
|
||||||
b_add = FIX(1.77200) * cb + ONE_HALF;\
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YUV_TO_RGB2(r, g, b, y1)\
|
|
||||||
{\
|
|
||||||
y = (y1) << SCALEBITS;\
|
|
||||||
r = cm[(y + r_add) >> SCALEBITS];\
|
|
||||||
g = cm[(y + g_add) >> SCALEBITS];\
|
|
||||||
b = cm[(y + b_add) >> SCALEBITS];\
|
|
||||||
}
|
|
||||||
|
|
||||||
#define Y_CCIR_TO_JPEG(y)\
|
|
||||||
cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
|
|
||||||
|
|
||||||
#define Y_JPEG_TO_CCIR(y)\
|
|
||||||
(((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
|
||||||
|
|
||||||
#define C_CCIR_TO_JPEG(y)\
|
|
||||||
cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
|
|
||||||
|
|
||||||
/* NOTE: the clamp is really necessary! */
|
|
||||||
static inline int C_JPEG_TO_CCIR(int y) {
|
|
||||||
y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
|
|
||||||
if (y < 16)
|
|
||||||
y = 16;
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define RGB_TO_Y(r, g, b) \
|
|
||||||
((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
|
|
||||||
FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
|
|
||||||
|
|
||||||
#define RGB_TO_U(r1, g1, b1, shift)\
|
|
||||||
(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
|
|
||||||
FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
|
||||||
|
|
||||||
#define RGB_TO_V(r1, g1, b1, shift)\
|
|
||||||
(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
|
|
||||||
FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
|
||||||
|
|
||||||
#define RGB_TO_Y_CCIR(r, g, b) \
|
|
||||||
((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
|
|
||||||
FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
|
||||||
|
|
||||||
#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
|
|
||||||
(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
|
|
||||||
FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
|
||||||
|
|
||||||
#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
|
|
||||||
(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
|
|
||||||
FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
|
||||||
|
|
||||||
static uint8_t y_ccir_to_jpeg[256];
|
static uint8_t y_ccir_to_jpeg[256];
|
||||||
static uint8_t y_jpeg_to_ccir[256];
|
static uint8_t y_jpeg_to_ccir[256];
|
||||||
static uint8_t c_ccir_to_jpeg[256];
|
static uint8_t c_ccir_to_jpeg[256];
|
||||||
@ -2870,4 +2790,3 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef FIX
|
|
||||||
|
Loading…
Reference in New Issue
Block a user