| 1 |
#include "Uncompressed.h" |
| 2 |
#include "avm_except.h" |
| 3 |
#include "avifile.h" // IStream |
| 4 |
#include <string.h> |
| 5 |
#include <stdlib.h> // sprintf |
| 6 |
#include <stdio.h> // sprintf |
| 7 |
|
| 8 |
AVM_BEGIN_NAMESPACE; |
| 9 |
|
| 10 |
#define __MODULE__ "Uncompress" |
| 11 |
|
| 12 |
Unc_Decoder::Unc_Decoder(const CodecInfo& info, const BITMAPINFOHEADER& h, int flip) |
| 13 |
:IVideoDecoder(info, h) |
| 14 |
{ |
| 15 |
m_Dest = *m_pFormat; |
| 16 |
|
| 17 |
switch (m_pFormat->biCompression) |
| 18 |
{ |
| 19 |
case IMG_FMT_YUY2: |
| 20 |
m_Dest.SetSpace(IMG_FMT_YUY2); |
| 21 |
m_Cap = CAP_YUY2; |
| 22 |
break; |
| 23 |
case IMG_FMT_YV12: |
| 24 |
m_Dest.SetSpace(IMG_FMT_YV12); |
| 25 |
m_Cap = CAP_YV12; |
| 26 |
break; |
| 27 |
case IMG_FMT_I420: |
| 28 |
m_Dest.SetSpace(IMG_FMT_I420); |
| 29 |
m_Cap = CAP_I420; |
| 30 |
break; |
| 31 |
case IMG_FMT_UYVY: |
| 32 |
m_Dest.SetSpace(IMG_FMT_UYVY); |
| 33 |
m_Cap = CAP_UYVY; |
| 34 |
break; |
| 35 |
case IMG_FMT_Y800: |
| 36 |
m_Dest.SetSpace(IMG_FMT_Y800); |
| 37 |
break; |
| 38 |
case 0: |
| 39 |
case mmioFOURCC('D', 'I', 'B', ' '): |
| 40 |
case mmioFOURCC('R', 'G', 'B', ' '): |
| 41 |
case mmioFOURCC('r', 'a', 'w', ' '): |
| 42 |
if (m_Dest.biBitCount == 16) |
| 43 |
m_Dest.SetBits(15); |
| 44 |
else |
| 45 |
m_Dest.SetBits(m_Dest.biBitCount); |
| 46 |
/* fall through */ |
| 47 |
case 3: |
| 48 |
// image is always stored in bottom-up form |
| 49 |
if (!flip) |
| 50 |
m_Dest.biHeight *= -1; |
| 51 |
m_Cap = CAP_NONE; |
| 52 |
break; |
| 53 |
default: |
| 54 |
char msg[100]; |
| 55 |
sprintf(msg, "unsupported format: 0x%x (%.4s)!", |
| 56 |
m_pFormat->biCompression, (char*)&m_pFormat->biCompression); |
| 57 |
throw FATAL(msg); |
| 58 |
} |
| 59 |
#undef __MODULE__ |
| 60 |
|
| 61 |
|
| 62 |
// 32bit 8bit B 8bit G 8bit R 8bit reserved |
| 63 |
// 24bit 8bit B 8bit G 8bit R |
| 64 |
// 16bit Windows BI_RGB format always means |
| 65 |
// (11 - 15) B (6 - 10) G (1 - 5) R 0 reserved |
| 66 |
|
| 67 |
// Image data is always padded to ensure that each scan line |
| 68 |
// begins on an even byte boundary |
| 69 |
// e.g. - 75 pixels width image has one empty column |
| 70 |
|
| 71 |
/* |
| 72 |
printf("Uncompressed video %dx%d %d %d %d\n", |
| 73 |
m_pFormat->biWidth, m_pFormat->biHeight, |
| 74 |
m_pFormat->biSizeImage, m_pFormat->biWidth * m_pFormat->biHeight, |
| 75 |
m_pFormat->biBitCount); |
| 76 |
*/ |
| 77 |
dest = m_Dest; |
| 78 |
dest.biWidth = (dest.biWidth + 1) & ~1; |
| 79 |
} |
| 80 |
|
| 81 |
Unc_Decoder::~Unc_Decoder() |
| 82 |
{ |
| 83 |
Stop(); |
| 84 |
} |
| 85 |
|
| 86 |
int Unc_Decoder::DecodeFrame(CImage* pImage, const void* src, size_t size, |
| 87 |
int is_keyframe, bool render, CImage** pOut) |
| 88 |
{ |
| 89 |
CImage ci(&dest, (const uint8_t*)src, false); |
| 90 |
//printf("DECODER RGB\n"); dest.Print(); pImage->GetFmt()->Print(); |
| 91 |
pImage->Convert(&ci); |
| 92 |
pImage->SetQuality(1.0); |
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
int Unc_Decoder::SetDestFmt(int bits, fourcc_t csp) |
| 97 |
{ |
| 98 |
if (!CImage::Supported(csp, bits)) |
| 99 |
return -1; |
| 100 |
|
| 101 |
// we allow to set any dest format |
| 102 |
if (bits == 0) |
| 103 |
bits = csp; |
| 104 |
|
| 105 |
switch (bits) |
| 106 |
{ |
| 107 |
case 15: |
| 108 |
case 16: |
| 109 |
case 24: |
| 110 |
case 32: |
| 111 |
m_Dest.SetBits(bits); |
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
m_Dest.SetSpace(bits); |
| 116 |
//printf("SETDESTFMT %d %.4s\n", bits, (char*) &csp); |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
/** |
| 123 |
* |
| 124 |
* E N C O D E R |
| 125 |
* |
| 126 |
*/ |
| 127 |
Unc_Encoder::Unc_Encoder(const CodecInfo& info, fourcc_t compressor, const BITMAPINFOHEADER& header) |
| 128 |
:IVideoEncoder(info), head(header) |
| 129 |
{ |
| 130 |
switch (info.fourcc) |
| 131 |
{ |
| 132 |
case fccYUY2: |
| 133 |
case fccYV12: |
| 134 |
case fccI420: |
| 135 |
case fccUYVY: |
| 136 |
head.SetSpace(info.fourcc); |
| 137 |
break; |
| 138 |
default: |
| 139 |
head.SetBits(info.fourcc); |
| 140 |
head.SetDirection(1); |
| 141 |
} |
| 142 |
chead = head; |
| 143 |
// for YUV - topdown is used - but biHeight in header is positive |
| 144 |
head.biHeight = (int32_t)labs(head.biHeight); |
| 145 |
} |
| 146 |
|
| 147 |
Unc_Encoder::~Unc_Encoder() |
| 148 |
{ |
| 149 |
} |
| 150 |
|
| 151 |
size_t Unc_Encoder::GetOutputSize() const |
| 152 |
{ |
| 153 |
return head.biSizeImage; |
| 154 |
} |
| 155 |
|
| 156 |
const BITMAPINFOHEADER& Unc_Encoder::GetOutputFormat() const |
| 157 |
{ |
| 158 |
return head; |
| 159 |
} |
| 160 |
|
| 161 |
int Unc_Encoder::EncodeFrame(const CImage* src, void* dest, int* is_keyframe, size_t* size, int* lpckid) |
| 162 |
{ |
| 163 |
// FIXME - add check for proper orded!!! |
| 164 |
//printf("FMT from -> to\n"); src->GetFmt()->Print(); chead.Print(); |
| 165 |
CImage ci(&chead, (uint8_t*)dest, false); |
| 166 |
ci.Convert(src); |
| 167 |
if (size) |
| 168 |
*size = head.biSizeImage; |
| 169 |
if (is_keyframe) |
| 170 |
*is_keyframe = IStream::KEYFRAME; |
| 171 |
return 0; |
| 172 |
} |
| 173 |
|
| 174 |
AVM_END_NAMESPACE; |