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.

137 lines
3.1 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * resample.cxx
  8. *
  9. * Abstract:
  10. *
  11. * 1-dimensional image resampling
  12. *
  13. * Revision History:
  14. *
  15. * 01/18/1999 davidx
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #include "precomp.hxx"
  20. VOID
  21. Resample1D(
  22. VOID* src,
  23. INT srccnt,
  24. VOID* dst,
  25. INT dstcnt,
  26. INT pixstride,
  27. double* outpos
  28. )
  29. {
  30. static double* inpos = NULL;
  31. static int inposLen = 0;
  32. // allocate working memory
  33. if (inposLen < dstcnt+2)
  34. {
  35. inposLen = dstcnt+2;
  36. inpos = (double*) realloc(inpos, inposLen*sizeof(double));
  37. if (inpos == NULL)
  38. Error("Out of memory\n");
  39. memset(inpos, 0, inposLen*sizeof(double));
  40. }
  41. // we only deal with 32-bit RGB pixel
  42. if (PIXELSIZE != sizeof(DWORD))
  43. Error("Resample1D can only handle 32bit pixel\n");
  44. DWORD* in = (DWORD*) src;
  45. DWORD* out = (DWORD*) dst;
  46. pixstride /= sizeof(DWORD);
  47. INT u, x;
  48. double accB, intensityB,
  49. accG, intensityG,
  50. accR, intensityR;
  51. double insfac, inseg, outseg;
  52. for (u=x=0; x < dstcnt; x++)
  53. {
  54. while (outpos[u+1] < x)
  55. u++;
  56. inpos[x] = u + (x-outpos[u]) / (outpos[u+1] - outpos[u]);
  57. }
  58. inpos[dstcnt] = srccnt;
  59. inseg = 1.0;
  60. outseg = inpos[1];
  61. insfac = outseg;
  62. accB = accG = accR = 0.0;
  63. for (x=0; x < dstcnt; )
  64. {
  65. DWORD pix0 = in[0];
  66. DWORD pix1;
  67. double rem;
  68. if (inseg == 1.0)
  69. {
  70. intensityB = (BYTE) (pix0 );
  71. intensityG = (BYTE) (pix0 >> 8);
  72. intensityR = (BYTE) (pix0 >> 16);
  73. }
  74. else
  75. {
  76. pix1 = in[pixstride];
  77. rem = 1.0 - inseg;
  78. intensityB = inseg * ((BYTE) (pix0 )) +
  79. rem * ((BYTE) (pix1 ));
  80. intensityG = inseg * ((BYTE) (pix0 >> 8)) +
  81. rem * ((BYTE) (pix1 >> 8));
  82. intensityR = inseg * ((BYTE) (pix0 >> 16)) +
  83. rem * ((BYTE) (pix1 >> 16));
  84. }
  85. if (inseg < outseg)
  86. {
  87. accB += intensityB*inseg;
  88. accG += intensityG*inseg;
  89. accR += intensityR*inseg;
  90. outseg -= inseg;
  91. inseg = 1.0;
  92. in += pixstride;
  93. }
  94. else
  95. {
  96. DWORD r, g, b;
  97. insfac = 1.0 / insfac;
  98. b = (DWORD) ((accB + intensityB*outseg) * insfac);
  99. g = (DWORD) ((accG + intensityG*outseg) * insfac);
  100. r = (DWORD) ((accR + intensityR*outseg) * insfac);
  101. *out = ((b & 0xff) ) |
  102. ((g & 0xff) << 8) |
  103. ((r & 0xff) << 16);
  104. out += pixstride;
  105. x++;
  106. accB = accG = accR = 0.0;
  107. inseg -= outseg;
  108. outseg = insfac = inpos[x+1] - inpos[x];
  109. }
  110. }
  111. }