DocumentationOverviewBuilding ASL Documentation Library Wiki Docs Indices Browse Perforce More InfoRelease NotesWiki Site Search License Success Stories Contributors MediaDownloadPerforce Depots SupportASL SourceForge HomeMailing Lists Discussion Forums Report Bugs Suggest Features Contribute to ASL RSSShort-text newsFull-text news File releases Other Adobe ProjectsAdobe AirAdobe GIL Adobe Labs Adobe Media Gallery Adobe XMP Tamarin project (Mozilla Foundation) Other ResourcesBoostRIAForge SGI STL |
dng_stream.h00001 /*****************************************************************************/ 00002 // Copyright 2006-2007 Adobe Systems Incorporated 00003 // All Rights Reserved. 00004 // 00005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 00006 // accordance with the terms of the Adobe license agreement accompanying it. 00007 /*****************************************************************************/ 00008 00009 /* $Id: //mondo/workarea/stern/camera_raw/dng_sdk/source/dng_stream.h#13 $ */ 00010 /* $DateTime: 2007/12/13 23:45:42 $ */ 00011 /* $Change: 405902 $ */ 00012 /* $Author: stern $ */ 00013 00018 /*****************************************************************************/ 00019 00020 #ifndef __dng_stream__ 00021 #define __dng_stream__ 00022 00023 /*****************************************************************************/ 00024 00025 #include "dng_classes.h" 00026 #include "dng_types.h" 00027 #include "dng_memory.h" 00028 #include "dng_rational.h" 00029 #include "dng_utils.h" 00030 00031 /*****************************************************************************/ 00032 00033 // Constants for invalid offset in streams. 00034 00035 const uint64 kDNGStreamInvalidOffset = 0xFFFFFFFFFFFFFFFFLL; 00036 00037 /*****************************************************************************/ 00038 00041 00042 class dng_stream 00043 { 00044 00045 public: 00046 00047 enum 00048 { 00049 00050 kSmallBufferSize = 4 * 1024, 00051 kBigBufferSize = 64 * 1024, 00052 00053 kDefaultBufferSize = kSmallBufferSize 00054 00055 }; 00056 00057 private: 00058 00059 bool fSwapBytes; 00060 00061 bool fHaveLength; 00062 00063 uint64 fLength; 00064 00065 const uint64 fOffsetInOriginalFile; 00066 00067 uint64 fPosition; 00068 00069 dng_memory_data fMemBlock; 00070 00071 uint8 *fBuffer; 00072 00073 uint32 fBufferSize; 00074 00075 uint64 fBufferStart; 00076 uint64 fBufferEnd; 00077 uint64 fBufferLimit; 00078 00079 bool fBufferDirty; 00080 00081 dng_abort_sniffer *fSniffer; 00082 00083 protected: 00084 00085 dng_stream (dng_abort_sniffer *sniffer = NULL, 00086 uint32 bufferSize = kDefaultBufferSize, 00087 uint64 offsetInOriginalFile = kDNGStreamInvalidOffset); 00088 00089 virtual uint64 DoGetLength (); 00090 00091 virtual void DoRead (void *data, 00092 uint32 count, 00093 uint64 offset); 00094 00095 virtual void DoSetLength (uint64 length); 00096 00097 virtual void DoWrite (const void *data, 00098 uint32 count, 00099 uint64 offset); 00100 00101 public: 00102 00108 00109 dng_stream (const void *data, 00110 uint32 count, 00111 uint64 offsetInOriginalFile = kDNGStreamInvalidOffset); 00112 00113 virtual ~dng_stream (); 00114 00117 00118 bool SwapBytes () const 00119 { 00120 return fSwapBytes; 00121 } 00122 00126 00127 void SetSwapBytes (bool swapBytes) 00128 { 00129 fSwapBytes = swapBytes; 00130 } 00131 00134 00135 bool BigEndian () const; 00136 00139 00140 void SetBigEndian (bool bigEndian = true); 00141 00144 00145 bool LittleEndian () const 00146 { 00147 return !BigEndian (); 00148 } 00149 00152 00153 void SetLittleEndian (bool littleEndian = true) 00154 { 00155 SetBigEndian (!littleEndian); 00156 } 00157 00159 00160 uint32 BufferSize () const 00161 { 00162 return fBufferSize; 00163 } 00164 00167 00168 uint64 Length () 00169 { 00170 00171 if (!fHaveLength) 00172 { 00173 00174 fLength = DoGetLength (); 00175 00176 fHaveLength = true; 00177 00178 } 00179 00180 return fLength; 00181 00182 } 00183 00186 00187 uint64 Position () const 00188 { 00189 return fPosition; 00190 } 00191 00196 00197 uint64 PositionInOriginalFile () const; 00198 00202 00203 uint64 OffsetInOriginalFile () const; 00204 00207 00208 const void * Data () const; 00209 00213 00214 dng_memory_block * AsMemoryBlock (dng_memory_allocator &allocator); 00215 00217 00218 void SetReadPosition (uint64 offset); 00219 00222 00223 void Skip (uint64 delta) 00224 { 00225 SetReadPosition (Position () + delta); 00226 } 00227 00234 00235 void Get (void *data, uint32 count); 00236 00238 00239 void SetWritePosition (uint64 offset); 00240 00242 00243 void Flush (); 00244 00247 00248 void SetLength (uint64 length); 00249 00253 00254 void Put (const void *data, uint32 count); 00255 00260 00261 uint8 Get_uint8 () 00262 { 00263 00264 // Fast check to see if in buffer 00265 00266 if (fPosition >= fBufferStart && fPosition < fBufferEnd) 00267 { 00268 00269 return fBuffer [fPosition++ - fBufferStart]; 00270 00271 } 00272 00273 // Not in buffer, let main routine do the work. 00274 00275 uint8 x; 00276 00277 Get (&x, 1); 00278 00279 return x; 00280 00281 } 00282 00285 00286 void Put_uint8 (uint8 x) 00287 { 00288 00289 if (fBufferDirty && 00290 fPosition >= fBufferStart && 00291 fPosition <= fBufferEnd && 00292 fPosition < fBufferLimit) 00293 { 00294 00295 fBuffer [fPosition - fBufferStart] = x; 00296 00297 fPosition++; 00298 00299 if (fBufferEnd < fPosition) 00300 fBufferEnd = fPosition; 00301 00302 fLength = Max_uint64 (Length (), fPosition); 00303 00304 } 00305 00306 else 00307 { 00308 00309 Put (&x, 1); 00310 00311 } 00312 00313 } 00314 00320 00321 uint16 Get_uint16 (); 00322 00326 00327 void Put_uint16 (uint16 x); 00328 00334 00335 uint32 Get_uint32 (); 00336 00340 00341 void Put_uint32 (uint32 x); 00342 00348 00349 uint64 Get_uint64 (); 00350 00354 00355 void Put_uint64 (uint64 x); 00356 00361 00362 int8 Get_int8 () 00363 { 00364 return (int8) Get_uint8 (); 00365 } 00366 00369 00370 void Put_int8 (int8 x) 00371 { 00372 Put_uint8 ((uint8) x); 00373 } 00374 00380 00381 int16 Get_int16 () 00382 { 00383 return (int16) Get_uint16 (); 00384 } 00385 00389 00390 void Put_int16 (int16 x) 00391 { 00392 Put_uint16 ((uint16) x); 00393 } 00394 00400 00401 int32 Get_int32 () 00402 { 00403 return (int32) Get_uint32 (); 00404 } 00405 00409 00410 void Put_int32 (int32 x) 00411 { 00412 Put_uint32 ((uint32) x); 00413 } 00414 00420 00421 int64 Get_int64 () 00422 { 00423 return (int64) Get_uint64 (); 00424 } 00425 00429 00430 void Put_int64 (int64 x) 00431 { 00432 Put_uint64 ((uint64) x); 00433 } 00434 00440 00441 real32 Get_real32 (); 00442 00446 00447 void Put_real32 (real32 x); 00448 00454 00455 real64 Get_real64 (); 00456 00460 00461 void Put_real64 (real64 x); 00462 00471 00472 void Get_CString (char *data, 00473 uint32 maxLength); 00474 00484 00485 void Get_UString (char *data, 00486 uint32 maxLength); 00487 00490 00491 void PutZeros (uint64 count); 00492 00494 00495 void PadAlign2 (); 00496 00498 00499 void PadAlign4 (); 00500 00508 00509 uint32 TagValue_uint32 (uint32 tagType); 00510 00518 00519 int32 TagValue_int32 (uint32 tagType); 00520 00528 00529 dng_urational TagValue_urational (uint32 tagType); 00530 00538 00539 dng_srational TagValue_srational (uint32 tagType); 00540 00548 00549 real64 TagValue_real64 (uint32 tagType); 00550 00553 00554 dng_abort_sniffer * Sniffer () const 00555 { 00556 return fSniffer; 00557 } 00558 00561 00562 void SetSniffer (dng_abort_sniffer *sniffer) 00563 { 00564 fSniffer = sniffer; 00565 } 00566 00570 00571 virtual void CopyToStream (dng_stream &dstStream, 00572 uint64 count); 00573 00576 00577 void DuplicateStream (dng_stream &dstStream); 00578 00579 private: 00580 00581 // Hidden copy constructor and assignment operator. 00582 00583 dng_stream (const dng_stream &stream); 00584 00585 dng_stream & operator= (const dng_stream &stream); 00586 00587 }; 00588 00589 /*****************************************************************************/ 00590 00591 class TempBigEndian 00592 { 00593 00594 private: 00595 00596 dng_stream & fStream; 00597 00598 bool fOldSwap; 00599 00600 public: 00601 00602 TempBigEndian (dng_stream &stream, 00603 bool bigEndian = true); 00604 00605 virtual ~TempBigEndian (); 00606 00607 }; 00608 00609 /*****************************************************************************/ 00610 00611 class TempLittleEndian: public TempBigEndian 00612 { 00613 00614 public: 00615 00616 TempLittleEndian (dng_stream &stream, 00617 bool littleEndian = true) 00618 00619 : TempBigEndian (stream, !littleEndian) 00620 00621 { 00622 } 00623 00624 virtual ~TempLittleEndian () 00625 { 00626 } 00627 00628 }; 00629 00630 /*****************************************************************************/ 00631 00632 class TempStreamSniffer 00633 { 00634 00635 private: 00636 00637 dng_stream & fStream; 00638 00639 dng_abort_sniffer *fOldSniffer; 00640 00641 public: 00642 00643 TempStreamSniffer (dng_stream &stream, 00644 dng_abort_sniffer *sniffer); 00645 00646 virtual ~TempStreamSniffer (); 00647 00648 private: 00649 00650 // Hidden copy constructor and assignment operator. 00651 00652 TempStreamSniffer (const TempStreamSniffer &temp); 00653 00654 TempStreamSniffer & operator= (const TempStreamSniffer &temp); 00655 00656 }; 00657 00658 /*****************************************************************************/ 00659 00660 class PreserveStreamReadPosition 00661 { 00662 00663 private: 00664 00665 dng_stream & fStream; 00666 00667 uint64 fPosition; 00668 00669 public: 00670 00671 PreserveStreamReadPosition (dng_stream &stream) 00672 00673 : fStream (stream) 00674 , fPosition (stream.Position ()) 00675 00676 { 00677 } 00678 00679 ~PreserveStreamReadPosition () 00680 { 00681 fStream.SetReadPosition (fPosition); 00682 } 00683 00684 private: 00685 00686 // Hidden copy constructor and assignment operator. 00687 00688 PreserveStreamReadPosition (const PreserveStreamReadPosition &rhs); 00689 00690 PreserveStreamReadPosition & operator= (const PreserveStreamReadPosition &rhs); 00691 00692 }; 00693 00694 /*****************************************************************************/ 00695 00696 #endif 00697 00698 /*****************************************************************************/ |