home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Riza / source / vc_huffyuv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  4.3 KB  |  145 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    A/V interface library
  3. //    Copyright (C) 1998-2008 Avery Lee
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 2 of the License, or
  8. //    (at your option) any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <vd2/system/error.h>
  20. #include <vd2/system/vdalloc.h>
  21. #include <vd2/Kasumi/pixmap.h>
  22. #include <vd2/Kasumi/pixmapops.h>
  23. #include <vd2/Kasumi/pixmaputils.h>
  24. #include <vd2/Riza/bitmap.h>
  25. #include <vd2/Riza/videocodec.h>
  26. #include <vd2/Meia/decode_huffyuv.h>
  27.  
  28. class VDVideoDecompressorHuffyuv : public IVDVideoDecompressor {
  29. public:
  30.     VDVideoDecompressorHuffyuv(uint32 w, uint32 h, uint32 depth, const uint8 *extradata, uint32 extralen);
  31.     ~VDVideoDecompressorHuffyuv();
  32.  
  33.     bool QueryTargetFormat(int format);
  34.     bool QueryTargetFormat(const void *format);
  35.     bool SetTargetFormat(int format);
  36.     bool SetTargetFormat(const void *format);
  37.     int GetTargetFormat() { return mFormat; }
  38.     int GetTargetFormatVariant() { return 0; }
  39.     const uint32 *GetTargetFormatPalette() { return NULL; }
  40.     void Start();
  41.     void Stop();
  42.     void DecompressFrame(void *dst, const void *src, uint32 srcSize, bool keyframe, bool preroll);
  43.     const void *GetRawCodecHandlePtr();
  44.     const wchar_t *GetName();
  45.  
  46. protected:
  47.     int    mFormat;
  48.     int    mWidth;
  49.     int    mHeight;
  50.  
  51.     vdautoptr<IVDVideoDecoderHuffyuv> mpDecoder;
  52. };
  53.  
  54. IVDVideoDecompressor *VDCreateVideoDecompressorHuffyuv(uint32 w, uint32 h, uint32 depth, const uint8 *extradata, uint32 extralen) {
  55.     return new VDVideoDecompressorHuffyuv(w, h, depth, extradata, extralen);
  56. }
  57.  
  58. VDVideoDecompressorHuffyuv::VDVideoDecompressorHuffyuv(uint32 w, uint32 h, uint32 depth, const uint8 *extradata, uint32 extralen)
  59.     : mFormat(0)
  60.     , mWidth(w)
  61.     , mHeight(h)
  62.     , mpDecoder(VDCreateVideoDecoderHuffyuv())
  63. {
  64.     mpDecoder->Init(w, h, depth, extradata, extralen);
  65. }
  66.  
  67. VDVideoDecompressorHuffyuv::~VDVideoDecompressorHuffyuv() {
  68. }
  69.  
  70. bool VDVideoDecompressorHuffyuv::QueryTargetFormat(int format) {
  71.     return format > 0;
  72. }
  73.  
  74. bool VDVideoDecompressorHuffyuv::QueryTargetFormat(const void *format) {
  75.     const VDAVIBitmapInfoHeader& hdr = *(const VDAVIBitmapInfoHeader *)format;
  76.  
  77.     if (hdr.biWidth != mWidth || hdr.biHeight != mHeight)
  78.         return false;
  79.  
  80.     int pxformat = VDBitmapFormatToPixmapFormat(hdr);
  81.  
  82.     return QueryTargetFormat(pxformat);
  83. }
  84.  
  85. bool VDVideoDecompressorHuffyuv::SetTargetFormat(int format) {
  86.     if (!format)
  87.         format = nsVDPixmap::kPixFormat_YUV422_YUYV;
  88.  
  89.     if (QueryTargetFormat(format)) {
  90.         mFormat = format;
  91.         return true;
  92.     }
  93.  
  94.     return false;
  95. }
  96.  
  97. bool VDVideoDecompressorHuffyuv::SetTargetFormat(const void *format) {
  98.     const VDAVIBitmapInfoHeader& hdr = *(const VDAVIBitmapInfoHeader *)format;
  99.  
  100.     if (hdr.biWidth != mWidth || hdr.biHeight != mHeight)
  101.         return false;
  102.  
  103.     int pxformat = VDBitmapFormatToPixmapFormat(hdr);
  104.  
  105.     if (QueryTargetFormat(pxformat)) {
  106.         mFormat = pxformat;
  107.         return true;
  108.     }
  109.  
  110.     return false;
  111. }
  112.  
  113. void VDVideoDecompressorHuffyuv::Start() {
  114.     if (!mFormat)
  115.         throw MyError("Cannot find compatible target format for video decompression.");
  116. }
  117.  
  118. void VDVideoDecompressorHuffyuv::Stop() {
  119. }
  120.  
  121. void VDVideoDecompressorHuffyuv::DecompressFrame(void *dst, const void *src, uint32 srcSize, bool keyframe, bool preroll) {
  122.     if (!mFormat)
  123.         throw MyError("Cannot find compatible target format for video decompression.");
  124.  
  125.     mpDecoder->DecompressFrame(src, srcSize);
  126.  
  127.     // blit time!
  128.  
  129.     VDPixmap pxsrc(mpDecoder->GetFrameBuffer());
  130.  
  131.     VDPixmapLayout dstlayout;
  132.     VDMakeBitmapCompatiblePixmapLayout(dstlayout, mWidth, mHeight, mFormat, 0);
  133.     VDPixmap pxdst(VDPixmapFromLayout(dstlayout, dst));
  134.  
  135.     VDPixmapBlt(pxdst, pxsrc);
  136. }
  137.  
  138. const void *VDVideoDecompressorHuffyuv::GetRawCodecHandlePtr() {
  139.     return NULL;
  140. }
  141.  
  142. const wchar_t *VDVideoDecompressorHuffyuv::GetName() {
  143.     return L"Internal Huffyuv decoder";
  144. }
  145.