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.

73 lines
1.6 KiB

  1. /*==============================================================================
  2. This procedure converts HRAW to DCX in memory.
  3. ASSUMES
  4. 1) Input buffer contains a single scan line.
  5. 2) Output buffer is twice as large as input.
  6. 29-Apr-94 RajeevD Adapted from dcxcodec.dll
  7. ==============================================================================*/
  8. #include <windows.h>
  9. UINT // output data size
  10. DCXEncode
  11. (
  12. LPBYTE lpbIn, // raw input buffer
  13. LPBYTE lpbOut, // dcx output buffer
  14. UINT cbIn // input data size
  15. )
  16. {
  17. UINT cbOut = 0;
  18. BYTE bVal, bRun;
  19. while (cbIn)
  20. {
  21. // Get an input byte.
  22. bVal = *lpbIn++;
  23. cbIn--;
  24. bRun = 1;
  25. // Scan for a run until one of the following occurs:
  26. // (1) There are no more input bytes to be consumed.
  27. // (2) The run length has reached the maximum of 63.
  28. // (3) The first byte does not match the current one.
  29. if (cbIn && bVal == *lpbIn)
  30. {
  31. BYTE cbMax, cbRest;
  32. // Calculate the maximum number of bytes remaining.
  33. cbMax = min (cbIn, 62);
  34. // Scan for a run.
  35. cbRest = 0;
  36. while (bVal == *lpbIn && cbRest < cbMax)
  37. {lpbIn++; cbRest++;}
  38. // Adjust state.
  39. cbIn -= cbRest;
  40. bRun = ++cbRest;
  41. }
  42. // Flip black and white.
  43. bVal = ~bVal;
  44. // Does the value need to be escaped,
  45. // or is there non-trival run of bytes?
  46. if (bVal >= 0xC0 || bRun>1)
  47. {
  48. // Yes, encode the run length.
  49. // (possibly 1 for bVal>=0xC0).
  50. *lpbOut++ = bRun + 0xC0;
  51. cbOut++;
  52. }
  53. // Encode the value.
  54. *lpbOut++ = bVal;
  55. cbOut++;
  56. } // while (cbIn)
  57. return cbOut;
  58. }