Author: stippi Date: 2010-01-07 02:10:28 +0100 (Thu, 07 Jan 2010) New Revision: 34926 Changeset: http://dev.haiku-os.org/changeset/34926/haiku Modified: haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.cpp haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.h Log: Added utility function colorspace_to_pixfmt(). Modified: haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.cpp =================================================================== --- haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.cpp 2010-01-07 01:08:43 UTC (rev 34925) +++ haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.cpp 2010-01-07 01:10:28 UTC (rev 34926) @@ -16,7 +16,7 @@ #define TRACE(a...) #endif -// this function will try to find the best colorspaces for both the ff-codec and +// this function will try to find the best colorspaces for both the ff-codec and // the Media Kit sides. gfx_convert_func resolve_colorspace(color_space colorSpace, PixelFormat pixelFormat) { @@ -34,7 +34,7 @@ return gfx_conv_yuv410p_rgb32_c; // } } - + if (pixelFormat == PIX_FMT_YUV411P) { // if (cpu.HasMMX()) { // TRACE("resolve_colorspace: gfx_conv_yuv411p_rgb32_mmx\n"); @@ -44,7 +44,7 @@ return gfx_conv_yuv411p_rgb32_c; // } } - + if (pixelFormat == PIX_FMT_YUV420P || pixelFormat == PIX_FMT_YUVJ420P) { if (cpu.HasSSE2()) { TRACE("resolve_colorspace: gfx_conv_yuv420p_rgba32_sse2\n"); @@ -54,7 +54,7 @@ return gfx_conv_YCbCr420p_RGB32_c; } } - + if (pixelFormat == PIX_FMT_YUV422P || pixelFormat == PIX_FMT_YUVJ422P) { if (cpu.HasSSE2()) { return gfx_conv_yuv422p_rgba32_sse2; @@ -95,7 +95,7 @@ return gfx_conv_yuv411p_ycbcr422_c; // } } - + if (pixelFormat == PIX_FMT_YUV420P || pixelFormat == PIX_FMT_YUVJ420P) { // if (cpu.HasMMX()) { // TRACE("resolve_colorspace: gfx_conv_yuv420p_ycbcr422_mmx\n"); @@ -105,7 +105,7 @@ return gfx_conv_yuv420p_ycbcr422_c; // } } - + if (pixelFormat == PIX_FMT_YUYV422) { // if (cpu.HasMMX()) { // TRACE("resolve_colorspace: PIX_FMT_YUV422 => B_YCbCr422: gfx_conv_null_mmx\n"); @@ -115,10 +115,10 @@ return gfx_conv_null_c; // } } - + TRACE("resolve_colorspace: %s => B_YCbCr422: NULL\n", pixfmt_to_string(pixelFormat)); return gfx_conv_null_c; - + default: TRACE("resolve_colorspace: default: NULL !!!\n"); return NULL; @@ -248,19 +248,67 @@ } +PixelFormat +colorspace_to_pixfmt(color_space format) +{ + switch(format) { + default: + case B_NO_COLOR_SPACE: + return PIX_FMT_NONE; + + // NOTE: See pixfmt_to_colorspace() for what these are. + case B_YUV420: + return PIX_FMT_YUV420P; + case B_YUV422: + return PIX_FMT_YUV422P; + case B_RGB24_BIG: + return PIX_FMT_RGB24; + case B_RGB24: + return PIX_FMT_BGR24; + case B_YUV444: + return PIX_FMT_YUV444P; + case B_RGBA32_BIG: + case B_RGB32_BIG: + return PIX_FMT_BGR32; + case B_YUV9: + return PIX_FMT_YUV410P; + case B_YUV12: + return PIX_FMT_YUV411P; + // TODO: YCbCr color spaces! These are not the same as YUV! + case B_RGB16_BIG: + return PIX_FMT_RGB565; + case B_RGB15_BIG: + return PIX_FMT_RGB555; + case B_GRAY8: + return PIX_FMT_GRAY8; + case B_GRAY1: + return PIX_FMT_MONOBLACK; + case B_CMAP8: + return PIX_FMT_PAL8; + case B_RGBA32: + case B_RGB32: + return PIX_FMT_RGB32; + case B_RGB16: + return PIX_FMT_BGR565; + case B_RGB15: + return PIX_FMT_BGR555; + } +} + + #define BEGIN_TAG "\033[31m" #define END_TAG "\033[0m" void dump_ffframe(AVFrame *frame, const char *name) { const char *picttypes[] = {"no pict type", "intra", "predicted", "bidir pre", "s(gmc)-vop"}; - printf(BEGIN_TAG"AVFrame(%s) pts:%-10lld cnum:%-5d dnum:%-5d %s%s, ]\n"END_TAG, - name, - frame->pts, - frame->coded_picture_number, - frame->display_picture_number, -// frame->quality, - frame->key_frame?"keyframe, ":"", + printf(BEGIN_TAG"AVFrame(%s) pts:%-10lld cnum:%-5d dnum:%-5d %s%s, ]\n"END_TAG, + name, + frame->pts, + frame->coded_picture_number, + frame->display_picture_number, +// frame->quality, + frame->key_frame?"keyframe, ":"", picttypes[frame->pict_type]); // printf(BEGIN_TAG"\t\tlinesize[] = {%ld, %ld, %ld, %ld}\n"END_TAG, frame->linesize[0], frame->linesize[1], frame->linesize[2], frame->linesize[3]); } Modified: haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.h =================================================================== --- haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.h 2010-01-07 01:08:43 UTC (rev 34925) +++ haiku/trunk/src/add-ons/media/plugins/ffmpeg/gfx_util.h 2010-01-07 01:10:28 UTC (rev 34926) @@ -30,13 +30,14 @@ // will become: typedef void (*gfx_convert_func) (AVFrame *in, AVFrame *out, int width, int height); -// this function will try to find the best colorspaces for both the ff-codec and +// this function will try to find the best colorspaces for both the ff-codec and // the Media Kit sides. gfx_convert_func resolve_colorspace(color_space cs, PixelFormat pixelFormat); -const char *pixfmt_to_string(int p); +const char *pixfmt_to_string(int format); -color_space pixfmt_to_colorspace(int p); +color_space pixfmt_to_colorspace(int format); +PixelFormat colorspace_to_pixfmt(color_space format); void dump_ffframe(AVFrame *frame, const char *name);