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.

87 lines
1.7 KiB

  1. #include "precomp.h"
  2. #include "flip.h"
  3. bool FlipImage(LPCODINST lpCompInst, ICCOMPRESS *lpicComp)
  4. {
  5. // at the moment, we only know how to flip UYVY
  6. if (FOURCC_UYVY != lpicComp->lpbiInput->biCompression)
  7. {
  8. return false;
  9. }
  10. if (lpCompInst->bFlip == FALSE)
  11. {
  12. return false;
  13. }
  14. return FlipUYVY(lpCompInst, lpicComp);
  15. }
  16. bool FlipUYVY(LPCODINST lpCompInst, ICCOMPRESS *lpicComp)
  17. {
  18. int nRows, int nCols;
  19. int nIndex;
  20. int nPitch; // row width in bytes;
  21. int nImageSize;
  22. BYTE *pSrc, *pDst; // first and last rows
  23. BYTE *pBuffer=NULL;
  24. LPBITMAPINFOHEADER pBitMapInfo = lpicComp->lpbiInput;
  25. nRows = pBitMapInfo->biHeight;
  26. nCols = pBitMapInfo->biWidth;
  27. nPitch = nCols * 2;
  28. nImageSize = nRows * nPitch;
  29. // allocate the flip buffer if it hasn't already been allcoated
  30. if ((lpCompInst->pFlipBuffer == NULL) || (lpCompInst->dwFlipBufferSize < nImageSize))
  31. {
  32. if (lpCompInst->pFlipBuffer)
  33. {
  34. delete [] lpCompInst->pFlipBuffer;
  35. }
  36. lpCompInst->pFlipBuffer = (void*) (new BYTE [nImageSize]);
  37. if (lpCompInst->pFlipBuffer)
  38. {
  39. lpCompInst->dwFlipBufferSize = nImageSize;
  40. }
  41. else
  42. {
  43. lpCompInst->dwFlipBufferSize = 0;
  44. return false; // out of memory!
  45. }
  46. }
  47. pSrc = (BYTE*)lpicComp->lpInput;
  48. pDst = (BYTE*)(lpCompInst->pFlipBuffer) + (nRows - 1)*nPitch; // bottom of scratch buffer
  49. for (nIndex = 0; nIndex < nRows; nIndex++)
  50. {
  51. CopyMemory(pDst, pSrc, nPitch);
  52. pSrc += nPitch;
  53. pDst = pDst - nPitch;
  54. }
  55. return true;
  56. }
  57. void ReleaseFlipMemory(LPCODINST lpCompInst)
  58. {
  59. if (lpCompInst->pFlipBuffer != NULL)
  60. {
  61. delete [] lpCompInst->pFlipBuffer;
  62. lpCompInst->pFlipBuffer = 0;
  63. lpCompInst->dwFlipBufferSize = 0;
  64. }
  65. }