home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / goodies / qtreadwritejpeg / qtreadwritejpeg.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.0 KB  |  104 lines

  1. //////////
  2. //
  3. //    File:        QTReadWriteJPEG.h
  4. //
  5. //    Contains:    Sample code for compressing and decompressing JPEG images.
  6. //
  7. //    Written by:    Michael Marinkovich and Guillermo Ortiz
  8. //    Revised by:    Tim Monroe
  9. //                Based heavily on the existing "JPEG Sample" code.
  10. //
  11. //    Copyright:    © 1996-1998 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //    Change History (most recent first):
  14. //
  15. //       <1>         04/27/98    rtm        first file
  16. //       
  17. //////////
  18.  
  19. //////////
  20. //
  21. // header files
  22. //
  23. //////////
  24.  
  25. #include <FixMath.h>
  26. #include <ImageCompression.h>
  27. #include <Movies.h>
  28. #include <QuickTimeComponents.h>
  29. #include <StandardFile.h>
  30.  
  31.  
  32. //////////
  33. //
  34. // constants
  35. //
  36. //////////
  37.  
  38. #define kImageFileCreator        FOUR_CHAR_CODE('ogle')
  39. #define kBufferSize                codecMinimumDataSize        // data unload buffer size
  40.  
  41. #define kSaveImagePrompt        "Save compressed image as:"
  42. #define kSaveImageFileName        "Untitled.jpg"
  43. #define kWindowTitle            "Photo - JPEG"
  44.  
  45. // JFIF (JPEG) markers
  46. enum {
  47.     kSOFMarker                    = 0xC0,                        // start Of Frame N
  48.     kSOFMarker2                    = 0xC2,
  49.     kDHTMarker                    = 0xC4,                        // DHT Marker
  50.     kDACMarker                    = 0xCC,                        // DAC
  51.  
  52.     kRSTOMarker                    = 0xD0,                        // RSTO marker
  53.     kSOIMarker                    = 0xD8,                     // image start marker
  54.     kEOIMarker                    = 0xD9,                        // image end marker
  55.     kSOSMarker                    = 0xDA,                        // SOS marker
  56.     kDQTMarker                    = 0xDB,                        // DQT marker
  57.  
  58.     kAPPOMarker                    = 0xE0,                        // APPO marker
  59.     kCommentMarker                = 0xFE,                        // comment marker
  60.  
  61.     kStartMarker                = 0xFF                        // marker loacted after this byte
  62. };
  63.  
  64.  
  65. //////////
  66. //
  67. // data types
  68. //
  69. //////////
  70.  
  71. // a record to hold info about the JPEG data while we're loading it from disk
  72. struct DLDataRec
  73. {    
  74.     long                        fRefNum;                    // ref number of current file
  75.     long                        fFileLength;            
  76.     Ptr                            fOrigPtr;                    // address of start of buffer
  77.     Ptr                            fEndPtr;                    // address of end of buffer
  78. };
  79. typedef struct DLDataRec DLDataRec;
  80. typedef DLDataRec *DLDataPtr, **DLDataHnd;
  81.  
  82.  
  83. //////////
  84. //
  85. // function prototypes
  86. //
  87. //////////
  88.  
  89. void                            QTJPEG_PromptUserForJPEGFileAndDisplay (void);
  90. OSErr                            QTJPEG_ReadJPEG (FSSpec theFSSpec, CGrafPtr *theGWorld);
  91. OSErr                            QTJPEG_ConvertJPEG (Handle image, CGrafPtr *newWorld);
  92. OSErr                             QTJPEG_ReadJPEGHeader (short theRefNum, ImageDescriptionHandle theDesc, Rect *theRect);
  93. UInt8                            QTJPEG_FindNextMarker (long theRefNum);
  94. OSErr                             QTJPEG_HandleAPPOMarker (UInt8 theMarker, long theRefNum, ImageDescriptionHandle theDesc, Boolean *readingExtension);
  95. OSErr                             QTJPEG_HandleSOFMarker (long theRefNum, ImageDescriptionHandle theDesc, Boolean readingExtension);
  96. void                             QTJPEG_HandleSOSMarker (long theRefNum);
  97. UInt8                              QTJPEG_ReadByte (short theRefNum);
  98. UInt16                             QTJPEG_ReadWord (short theRefNum);
  99. void                             QTJPEG_SkipLength (long theRefNum);
  100. OSErr                             QTJPEG_NewJPEGWorld (GWorldPtr *theWorld, short theDepth, Rect theRect);
  101. OSErr                             QTJPEG_SaveJPEG (GWorldPtr theWorld);
  102. PASCAL_RTN OSErr                 QTJPEG_DataUnloadProc (Ptr theData, long theBytesNeeded, long theRefCon);
  103. PASCAL_RTN OSErr                 QTJPEG_DataLoadingProc (Ptr *theData, long theBytesNeeded, long theRefCon);
  104.