Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.6 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Colspace.cpp 1.7 1998/04/29 22:43:30 tomz Exp $
  2. #define INITGUID
  3. #include "colspace.h"
  4. #include "fourcc.h"
  5. #include "defaults.h"
  6. #include "uuids.h"
  7. BYTE const ColorSpace::BitCount_ [] =
  8. {
  9. // RGB32 RGB24 RGB16 RGB15 YUY2 BTYUV Y8 RGB8 PL_422 PL_411 YUV9 YUV12 VBI UYVY RAW I420
  10. 32, 24, 16, 16, 16, 12, 8, 8, 16, 12, 9, 12, 8, 16, 8, 12
  11. };
  12. BYTE const ColorSpace::YPlaneBitCount_ [] =
  13. {
  14. // RGB32 RGB24 RGB16 RGB15 YUY2 BTYUV Y8 RGB8 PL_422 PL_411 YUV9 YUV12 VBI UYVY RAW I420
  15. 32, 24, 16, 16, 16, 12, 8, 8, 8, 8, 8, 8, 8, 16, 8, 8
  16. };
  17. BYTE const ColorSpace::XRestriction_ [] =
  18. {
  19. 1, 1, 1, 1, 2, 4, 1, 1, 8, 16, 16, 8, 2, 4, 1, 8
  20. };
  21. BYTE const ColorSpace::YRestriction_ [] =
  22. {
  23. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2
  24. };
  25. FOURCC const ColorSpace::FourccArr_ [] =
  26. {
  27. // 32 24 16 15
  28. BI_RGB, BI_RGB, BI_RGB, BI_RGB, FCC_YUY2, FCC_Y41P, FCC_Y8, BI_RGB,
  29. FCC_422, FCC_411, FCC_YVU9, FCC_YV12, FCC_VBI, FCC_UYVY, FCC_RAW, FCC_I420
  30. };
  31. const GUID *ColorSpace::VideoGUIDs [] =
  32. {
  33. &MEDIASUBTYPE_RGB32, &MEDIASUBTYPE_RGB24, &MEDIASUBTYPE_RGB565, &MEDIASUBTYPE_RGB555,
  34. &MEDIASUBTYPE_YUY2, &MEDIASUBTYPE_Y41P, NULL, NULL,
  35. NULL, &MEDIASUBTYPE_Y411, &MEDIASUBTYPE_YVU9, NULL,
  36. NULL, &MEDIASUBTYPE_UYVY, NULL, NULL
  37. };
  38. void DumpGUID(const GUID guid)
  39. {
  40. DebugOut(( 1, "Guid = %08x-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
  41. guid.Data1, guid.Data2, guid.Data3,
  42. guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
  43. guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]
  44. ));
  45. }
  46. /* Constructor: ColorSpace::ColorSpace
  47. * Input: fcc: FOURCC
  48. */
  49. ColorSpace::ColorSpace( FOURCC fcc, int bitCount ) : CurColor_( CF_BelowRange )
  50. {
  51. DebugOut((1, "ColorSpace(%x, %d, ('%c%c%c%c'))\n",
  52. fcc,
  53. bitCount,
  54. fcc & 0xff,
  55. (fcc >> 8) & 0xff,
  56. (fcc >> 16) & 0xff,
  57. (fcc >> 24) & 0xff
  58. ));
  59. switch( fcc ) {
  60. case BI_RGB:
  61. switch ( bitCount ) {
  62. default:
  63. case 8: CurColor_ = CF_RGB8; break;
  64. case 16: CurColor_ = CF_RGB15; break;
  65. case 24: CurColor_ = CF_RGB24; break;
  66. case 32: CurColor_ = CF_RGB32; break;
  67. }
  68. break;
  69. case BI_RLE8:
  70. case BI_RLE4:
  71. case BI_BITFIELDS:
  72. case 0xe436eb7b:// ???
  73. case FCC_YUY2:
  74. case FCC_Y41P:
  75. case FCC_Y8:
  76. case FCC_422:
  77. case FCC_411:
  78. case FCC_YVU9:
  79. case FCC_YV12:
  80. case FCC_VBI:
  81. case FCC_UYVY:
  82. case FCC_RAW:
  83. case FCC_I420:
  84. default:
  85. for ( int fccArrIdx = CF_RGB32; fccArrIdx < CF_AboveRange; fccArrIdx++ )
  86. if ( fcc == FourccArr_ [fccArrIdx] ) {
  87. CurColor_ = (ColFmt)fccArrIdx;
  88. break;
  89. }
  90. break;
  91. }
  92. DebugOut((1, "*** CurColor_ set to %d\n", CurColor_));
  93. }
  94. /* Constructor: ColorSpace::ColorSpace
  95. * Input: guid: const GUID &
  96. */
  97. ColorSpace::ColorSpace( const GUID &guid ) : CurColor_( CF_BelowRange )
  98. {
  99. DebugOut((1, "**************************************\n"));
  100. DebugOut((1, "Looking for the following guid\n"));
  101. DumpGUID(guid);
  102. DebugOut((1, "---\n"));
  103. for ( int idx = CF_RGB32; idx < CF_AboveRange; idx++ ) {
  104. DumpGUID(*VideoGUIDs [idx]);
  105. if ( VideoGUIDs [idx] && IsEqualGUID( guid, *VideoGUIDs [idx] ) ) {
  106. CurColor_ = (ColFmt)idx;
  107. break;
  108. }
  109. }
  110. }
  111. /* Method: ColorSpace::CheckDimentions
  112. * Purpose: This functions checks that the size of a buffer corresponds to the
  113. * restrictions imposed by a color format
  114. * Input: size: reference to SIZE structure
  115. * Output: bool: True or False
  116. */
  117. bool ColorSpace::CheckDimentions( const SIZE &size ) const
  118. {
  119. return bool( CurColor_ > CF_BelowRange && CurColor_ < CF_AboveRange &&
  120. IsDivisible( size.cx, XRestriction_ [CurColor_] ) &&
  121. IsDivisible( size.cy, YRestriction_ [CurColor_] ) );//&&
  122. // size.cx >= MinOutWidth && size.cx <= MaxOutWidth &&
  123. // size.cy >= MinOutHeight && size.cy <= MaxOutHeight );
  124. }
  125. /* Method: ColorSpace::CheckLeftTop
  126. * Purpose: This functions checks that the left top corner of a buffer
  127. * corresponds to the restrictions imposed by a color format
  128. * Input: lt: const reference to MPoint structure
  129. * Output: bool: true or false
  130. */
  131. bool ColorSpace::CheckLeftTop( const MPoint &lt ) const
  132. {
  133. return bool( !( lt.x & 3 ) && !( lt.y & 1 ) );
  134. }