il_rle.h
Upload User: wmy0603
Upload Date: 2022-05-02
Package Size: 1808k
Code Size: 2k
Development Platform:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. //
  3. // ImageLib Sources
  4. // Copyright (C) 2000-2002 by Denton Woods
  5. // Last modified: 05/25/2001 <--Y2K Compliant! =]
  6. //
  7. // Filename: src-IL/include/il_rle.h
  8. //
  9. // Description: Functions for run-length encoding
  10. //
  11. //-----------------------------------------------------------------------------
  12. #ifndef RLE_H
  13. #define RLE_H
  14. #include "il_internal.h"
  15. #define TGA_MAX_RUN 128
  16. #define SGI_MAX_RUN 127
  17. #define BMP_MAX_RUN 127
  18. #ifdef IL_RLE_C
  19. #undef NOINLINE
  20. #undef INLINE
  21. #define INLINE
  22. #endif
  23. #ifndef NOINLINE
  24. INLINE ILuint GetPix(ILubyte *p, ILuint bpp) {
  25. ILuint Pixel;
  26. Pixel = (ILuint)*p++;
  27. while( bpp-- > 1 ) {
  28. Pixel <<= 8;
  29. Pixel |= (ILuint)*p++;
  30. }
  31. return Pixel;
  32. }
  33. INLINE ILint CountDiffPixels(ILubyte *p, ILuint bpp, ILuint pixCnt) {
  34. ILuint pixel;
  35. ILuint nextPixel = 0;
  36. ILint n;
  37. n = 0;
  38. if (pixCnt == 1)
  39. return pixCnt;
  40. pixel = GetPix(p, bpp);
  41. while (pixCnt > 1) {
  42. p += bpp;
  43. nextPixel = GetPix(p, bpp);
  44. if (nextPixel == pixel)
  45. break;
  46. pixel = nextPixel;
  47. ++n;
  48. --pixCnt;
  49. }
  50. if (nextPixel == pixel)
  51. return n;
  52. return n + 1;
  53. }
  54. INLINE ILint CountSamePixels(ILubyte *p, ILuint bpp, ILuint pixCnt) {
  55. ILuint pixel;
  56. ILuint nextPixel;
  57. ILint n;
  58. n = 1;
  59. pixel = GetPix(p, bpp);
  60. pixCnt--;
  61. while (pixCnt > 0) {
  62. p += bpp;
  63. nextPixel = GetPix(p, bpp);
  64. if (nextPixel != pixel)
  65. break;
  66. ++n;
  67. --pixCnt;
  68. }
  69. return n;
  70. }
  71. #endif
  72. ILuint GetPix(ILubyte *p, ILuint bpp);
  73. ILint CountDiffPixels(ILubyte *p, ILuint bpp, ILuint pixCnt);
  74. ILint CountSamePixels(ILubyte *p, ILuint bpp, ILuint pixCnt);
  75. #endif//RLE_H