| 1 |
|
| /* |
| 2 |
|
| * uyvy.c |
| 3 |
|
| * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> |
| 4 |
|
| * Copyright (C) 2003 Regis Duchesne <hpreg@zoy.org> |
| 5 |
|
| * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> |
| 6 |
|
| * |
| 7 |
|
| * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. |
| 8 |
|
| * See http://libmpeg2.sourceforge.net/ for updates. |
| 9 |
|
| * |
| 10 |
|
| * mpeg2dec is free software; you can redistribute it and/or modify |
| 11 |
|
| * it under the terms of the GNU General Public License as published by |
| 12 |
|
| * the Free Software Foundation; either version 2 of the License, or |
| 13 |
|
| * (at your option) any later version. |
| 14 |
|
| * |
| 15 |
|
| * mpeg2dec is distributed in the hope that it will be useful, |
| 16 |
|
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
|
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
|
| * GNU General Public License for more details. |
| 19 |
|
| * |
| 20 |
|
| * You should have received a copy of the GNU General Public License |
| 21 |
|
| * along with this program; if not, write to the Free Software |
| 22 |
|
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
|
| */ |
| 24 |
|
| |
| 25 |
|
| #include "config.h" |
| 26 |
|
| |
| 27 |
|
| #include <inttypes.h> |
| 28 |
|
| |
| 29 |
|
| #include "mpeg2.h" |
| 30 |
|
| #include "mpeg2convert.h" |
| 31 |
|
| |
| 32 |
|
| typedef struct { |
| 33 |
|
| int width; |
| 34 |
|
| int stride; |
| 35 |
|
| int chroma420; |
| 36 |
|
| uint8_t * out; |
| 37 |
|
| } convert_uyvy_t; |
| 38 |
|
| |
| 39 |
0 |
| static void uyvy_start (void * _id, const mpeg2_fbuf_t * fbuf, |
| 40 |
|
| const mpeg2_picture_t * picture, |
| 41 |
|
| const mpeg2_gop_t * gop) |
| 42 |
|
| { |
| 43 |
0 |
| convert_uyvy_t * instance = (convert_uyvy_t *) _id; |
| 44 |
|
| |
| 45 |
0 |
| instance->out = fbuf->buf[0]; |
| 46 |
0 |
| instance->stride = instance->width; |
| 47 |
0 |
▶ | if (picture->nb_fields == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (picture->nb_fields == 1) { |
0 |
0 |
0 |
|
| 48 |
0 |
▶ | if (! (picture->flags & PIC_FLAG_TOP_FIELD_FIRST)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (! (picture->flags & PIC_FLAG_TOP_FIELD_FIRST)) |
0 |
0 |
0 |
|
| 49 |
0 |
| instance->out += 2 * instance->stride; |
| 50 |
0 |
| instance->stride <<= 1; |
| 51 |
|
| } |
| 52 |
0 |
| } |
| 53 |
|
| |
| 54 |
|
| #ifdef WORDS_BIGENDIAN |
| 55 |
|
| #define PACK(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) |
| 56 |
|
| #else |
| 57 |
|
| #define PACK(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a)) |
| 58 |
|
| #endif |
| 59 |
|
| |
| 60 |
0 |
| static void uyvy_copy (void * const _id, uint8_t * const * src, |
| 61 |
|
| const unsigned int v_offset) |
| 62 |
|
| { |
| 63 |
0 |
| const convert_uyvy_t * const id = (convert_uyvy_t *) _id; |
| 64 |
|
| uint8_t * _dst; |
| 65 |
|
| uint8_t * py, * pu, * pv; |
| 66 |
|
| int i, j; |
| 67 |
|
| |
| 68 |
0 |
| _dst = id->out + 2 * id->stride * v_offset; |
| 69 |
0 |
| py = src[0]; pu = src[1]; pv = src[2]; |
| 70 |
|
| |
| 71 |
0 |
| i = 16; |
| 72 |
|
| do { |
| 73 |
0 |
| uint32_t * dst = (uint32_t *) _dst; |
| 74 |
|
| |
| 75 |
0 |
| j = id->width >> 4; |
| 76 |
|
| do { |
| 77 |
0 |
| dst[0] = PACK (pu[0], py[0], pv[0], py[1]); |
| 78 |
0 |
| dst[1] = PACK (pu[1], py[2], pv[1], py[3]); |
| 79 |
0 |
| dst[2] = PACK (pu[2], py[4], pv[2], py[5]); |
| 80 |
0 |
| dst[3] = PACK (pu[3], py[6], pv[3], py[7]); |
| 81 |
0 |
| dst[4] = PACK (pu[4], py[8], pv[4], py[9]); |
| 82 |
0 |
| dst[5] = PACK (pu[5], py[10], pv[5], py[11]); |
| 83 |
0 |
| dst[6] = PACK (pu[6], py[12], pv[6], py[13]); |
| 84 |
0 |
| dst[7] = PACK (pu[7], py[14], pv[7], py[15]); |
| 85 |
0 |
| py += 16; |
| 86 |
0 |
| pu += 8; |
| 87 |
0 |
| pv += 8; |
| 88 |
0 |
| dst += 8; |
| 89 |
0 |
▶ | } while (--j); |
Branch: 1 branch
| Branch | True | False | Total |
| } while (--j); |
0 |
0 |
0 |
|
| 90 |
0 |
| py -= id->width; |
| 91 |
0 |
| pu -= id->width >> 1; |
| 92 |
0 |
| pv -= id->width >> 1; |
| 93 |
0 |
| _dst += 2 * id->stride; |
| 94 |
0 |
| py += id->stride; |
| 95 |
0 |
▶ | if (! (--i & id->chroma420)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! (--i & id->chroma420)) { |
0 |
0 |
0 |
|
| 96 |
0 |
| pu += id->stride >> 1; |
| 97 |
0 |
| pv += id->stride >> 1; |
| 98 |
|
| } |
| 99 |
0 |
▶ | } while (i); |
Branch: 1 branch
| Branch | True | False | Total |
| } while (i); |
0 |
0 |
0 |
|
| 100 |
0 |
| } |
| 101 |
|
| |
| 102 |
0 |
| int mpeg2convert_uyvy (int stage, void * _id, const mpeg2_sequence_t * seq, |
| 103 |
|
| int stride, uint32_t accel, void * arg, |
| 104 |
|
| mpeg2_convert_init_t * result) |
| 105 |
|
| { |
| 106 |
0 |
| convert_uyvy_t * instance = (convert_uyvy_t *) _id; |
| 107 |
|
| |
| 108 |
0 |
▶ | if (seq->chroma_width == seq->width) |
Branch: 1 branch
| Branch | True | False | Total |
| if (seq->chroma_width == seq->width) |
0 |
0 |
0 |
|
| 109 |
0 |
| return 1; |
| 110 |
|
| |
| 111 |
0 |
▶ | if (instance) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (instance) { |
0 |
0 |
0 |
|
| 112 |
0 |
| instance->width = seq->width; |
| 113 |
0 |
| instance->chroma420 = (seq->chroma_height < seq->height); |
| 114 |
0 |
| result->buf_size[0] = seq->width * seq->height * 2; |
| 115 |
0 |
| result->buf_size[1] = result->buf_size[2] = 0; |
| 116 |
0 |
| result->start = uyvy_start; |
| 117 |
0 |
| result->copy = uyvy_copy; |
| 118 |
|
| } else { |
| 119 |
0 |
| result->id_size = sizeof (convert_uyvy_t); |
| 120 |
|
| } |
| 121 |
|
| |
| 122 |
0 |
| return 0; |
| 123 |
|
| } |