cjpeg.h
上传用户:liulu_102
上传日期:2007-01-14
资源大小:193k
文件大小:2k
源码类别:

图片显示

开发平台:

Visual C++

  1. #if !defined(_JPEGCP_)
  2. #define _JPEGCP_
  3. #include <windows.h>
  4. #include <fstream.h>
  5. #define FIXED_1 0x00010000
  6. #define FIXED_half 0x00008000
  7. #define LONG_TO_FIXED(l) ((l)*FIXED_1)
  8. #define FLOAT_TO_FIXED(f) ((long)((f)*FIXED_1))
  9. #define FIXED_TO_SHORT(f) ((short)((f)>>16))
  10. #define FIXED_TO_BYTE(f) ((BYTE)((f)>>16))
  11. #define FIXED_TO_LONG(f) ((f)>>16)
  12. #define JPEGCPERR_NOERROR 0
  13. #define JPEGCPERR_UNKNOWNERROR 1
  14. #define JPEGCPERR_UNSUPPORTEDVERSION 2
  15. #define JPEGCPERR_QTERROR 3
  16. #define JPEGCPERR_FRAMEERROR 4
  17. #define JPEGCPERR_HTERROR 5
  18. #define JPEGCPERR_SOSERROR 6
  19. #define IDCT_FLOAT 0
  20. #define IDCT_INT 1
  21. #define IDCT_MMX 2
  22. typedef struct NODE
  23. { NODE *lNode;
  24. NODE *rNode;
  25. BOOL isLeave;
  26. unsigned char code;
  27. }NODE;
  28. typedef struct
  29. { unsigned char *stream;
  30. UINT bufIdx;
  31. UINT bitIdx;
  32. UINT remain;
  33. }DECODE_PARAM;
  34. class CHuffmanTable
  35. {
  36. private:
  37. NODE root;
  38. private:
  39. public:
  40. CHuffmanTable();
  41. ~CHuffmanTable();
  42. BOOL addNode(UINT len,unsigned char c);
  43. BOOL addNode(NODE* node,UINT len,unsigned char c);
  44. void clear();
  45. void clearNode(NODE* node);
  46. BOOL deCode(DECODE_PARAM* pa,unsigned char *p);
  47. public:
  48. friend class CJpeg;
  49. };
  50. typedef struct
  51. { UINT v,h;
  52. UINT qtID;
  53. }COMPONENT;
  54. typedef struct
  55. { UINT imgWidth,imgHeight;
  56. UINT bufWidth,bufHeight;
  57. int comNum;
  58. BYTE *image[5];
  59. }JPEG_IMAGE_INFO;
  60. class CJpeg
  61. {
  62. //private:
  63. private:
  64. BOOL error;
  65. UINT errorCode;
  66. BOOL opened;
  67. UINT imgWidth,imgHeight;
  68. UINT bufWidth,bufHeight;
  69. UINT numOfCOM;
  70. UINT ri;
  71. UINT qt[4][64];
  72. CHuffmanTable htDC[4];
  73. CHuffmanTable htAC[4];
  74. COMPONENT com[6];
  75. UINT maxH,maxV;
  76. UINT unitNumH,unitNumV;
  77. BYTE *image[5];
  78. void (CJpeg::* pIdctFunc)(short*,BYTE*);
  79. private:
  80. void init();
  81. void idctFloat(short* coef_block,BYTE *output_buf);
  82. void idctInt (short* coef_block,BYTE *output_buf);
  83. void domidct8x8llmW(short *inptr,int*,BYTE* outptr);
  84. void idctMMX(short* coef_block,BYTE *output_buf);
  85. void storeBlock(UINT comID,UINT num,BYTE *block,BYTE *img);
  86. void YCbCrToRGB();
  87. BOOL readQTable(ifstream &ifs);
  88. BOOL readHTable(ifstream &ifs);
  89. BOOL readSOF0(ifstream &ifs);
  90. BOOL readRI(ifstream &ifs);
  91. BOOL readSOS(ifstream &ifs);
  92. public:
  93. CJpeg();
  94. CJpeg(LPCSTR fileName,UINT idctMode);
  95. ~CJpeg();
  96. BOOL operator!();
  97. BOOL open(LPCSTR fileName,UINT idctMode);
  98. void getImageInfo(JPEG_IMAGE_INFO* info);
  99. void close();
  100. UINT getLastError();
  101. public:
  102. };
  103. #endif