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.

134 lines
3.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 2000.
  3. //
  4. // PixRef.cpp
  5. //
  6. // Direct3D Reference Device - Pixel Buffer Referencing
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. extern int g_DXTBlkSize[];
  12. //-----------------------------------------------------------------------------
  13. //
  14. // PixelAddress - Form character address of locations within buffers using base
  15. // pointer, pitch and type.
  16. //
  17. //-----------------------------------------------------------------------------
  18. //
  19. // common internal version
  20. //
  21. char*
  22. PixelAddress(
  23. int iX, int iY, int iZ, int iSample,
  24. BYTE* pBits, int iYPitch, int iZPitch, int cSamples, RDSurfaceFormat SType )
  25. {
  26. // initialize return value to start of scan line (pitch is always in bytes)
  27. BYTE* pPixAddr = pBits + iY*iYPitch + iZ*iZPitch;
  28. // bump along scan line depending on surface type to point to pixel data
  29. switch ( SType )
  30. {
  31. default:
  32. _ASSERTf(0, ("Unknown RDSurfaceFormat value %08x", SType));
  33. return NULL;
  34. case RD_SF_NULL:
  35. break;
  36. case RD_SF_B8G8R8A8:
  37. case RD_SF_B8G8R8X8:
  38. case RD_SF_U8V8L8X8:
  39. case RD_SF_Z24S8:
  40. case RD_SF_Z24X8:
  41. case RD_SF_S8Z24:
  42. case RD_SF_X8Z24:
  43. case RD_SF_Z24X4S4:
  44. case RD_SF_X4S4Z24:
  45. case RD_SF_Z32S0:
  46. case RD_SF_U8V8W8Q8:
  47. case RD_SF_U10V11W11:
  48. case RD_SF_U16V16:
  49. case RD_SF_R10G10B10A2:
  50. case RD_SF_R8G8B8A8:
  51. case RD_SF_R8G8B8X8:
  52. case RD_SF_R16G16:
  53. case RD_SF_U11V11W10:
  54. case RD_SF_U10V10W10A2:
  55. case RD_SF_U8V8X8A8:
  56. case RD_SF_U8V8X8L8:
  57. pPixAddr += (iX*cSamples*4 + iSample*4);
  58. break;
  59. case RD_SF_B5G6R5:
  60. case RD_SF_B5G5R5X1:
  61. case RD_SF_B5G5R5A1:
  62. case RD_SF_P8A8:
  63. case RD_SF_L8A8:
  64. case RD_SF_U8V8:
  65. case RD_SF_U5V5L6:
  66. case RD_SF_Z16S0:
  67. case RD_SF_Z15S1:
  68. case RD_SF_S1Z15:
  69. case RD_SF_B4G4R4A4:
  70. case RD_SF_B4G4R4X4:
  71. case RD_SF_YUY2:
  72. case RD_SF_UYVY:
  73. case RD_SF_B2G3R3A8:
  74. pPixAddr += (iX*cSamples*2 + iSample*2);
  75. break;
  76. case RD_SF_B8G8R8:
  77. pPixAddr += (iX*cSamples*3 + iSample*3);
  78. break;
  79. case RD_SF_PALETTE8:
  80. case RD_SF_L8:
  81. case RD_SF_A8:
  82. case RD_SF_B2G3R3:
  83. case RD_SF_L4A4:
  84. pPixAddr += (iX*cSamples*1 + iSample*1);
  85. break;
  86. case RD_SF_PALETTE4:
  87. pPixAddr += (iX>>1);
  88. break;
  89. // For the DXT texture formats, obtain the address of the
  90. // block from whih to decompress the texel from
  91. case RD_SF_DXT1:
  92. case RD_SF_DXT2:
  93. case RD_SF_DXT3:
  94. case RD_SF_DXT4:
  95. case RD_SF_DXT5:
  96. pPixAddr = pBits + iZ*iZPitch + (iY >> 2)*iYPitch + (iX>>2) *
  97. g_DXTBlkSize[(int)SType - (int)RD_SF_DXT1];
  98. break;
  99. }
  100. return (char *)pPixAddr;
  101. }
  102. //
  103. // external versions
  104. //
  105. char*
  106. PixelAddress(
  107. int iX, int iY, int iZ,
  108. BYTE* pBits, int iYPitch, int iZPitch, RDSurfaceFormat SType )
  109. {
  110. return PixelAddress( iX, iY, iZ, 0, pBits, iYPitch, iZPitch, 1, SType );
  111. }
  112. char*
  113. PixelAddress(
  114. int iX, int iY, int iZ, int iSample, RDSurface2D* pRT )
  115. {
  116. return PixelAddress( iX, iY, iZ, iSample,
  117. pRT->GetBits(), pRT->GetPitch(), 0 /* pRT->GetSlicePitch() */,
  118. pRT->GetSamples(), pRT->GetSurfaceFormat() );
  119. }
  120. ///////////////////////////////////////////////////////////////////////////////
  121. // end