| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Demux API. | 10 // Demux API. |
| 11 // Enables extraction of image and extended format data from WebP files. | 11 // Enables extraction of image and extended format data from WebP files. |
| 12 | 12 |
| 13 // Code Example: Demuxing WebP data to extract all the frames, ICC profile | 13 // Code Example: Demuxing WebP data to extract all the frames, ICC profile |
| 14 // and EXIF/XMP metadata. | 14 // and EXIF/XMP metadata. |
| 15 // | 15 /* |
| 16 // WebPDemuxer* demux = WebPDemux(&webp_data); | 16 WebPDemuxer* demux = WebPDemux(&webp_data); |
| 17 // | 17 |
| 18 // uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH); | 18 uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH); |
| 19 // uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT); | 19 uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT); |
| 20 // // ... (Get information about the features present in the WebP file). | 20 // ... (Get information about the features present in the WebP file). |
| 21 // uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS); | 21 uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS); |
| 22 // | 22 |
| 23 // // ... (Iterate over all frames). | 23 // ... (Iterate over all frames). |
| 24 // WebPIterator iter; | 24 WebPIterator iter; |
| 25 // if (WebPDemuxGetFrame(demux, 1, &iter)) { | 25 if (WebPDemuxGetFrame(demux, 1, &iter)) { |
| 26 // do { | 26 do { |
| 27 // // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(), | 27 // ... (Consume 'iter'; e.g. Decode 'iter.fragment' with WebPDecode(), |
| 28 // // ... and get other frame properties like width, height, offsets etc. | 28 // ... and get other frame properties like width, height, offsets etc. |
| 29 // // ... see 'struct WebPIterator' below for more info). | 29 // ... see 'struct WebPIterator' below for more info). |
| 30 // } while (WebPDemuxNextFrame(&iter)); | 30 } while (WebPDemuxNextFrame(&iter)); |
| 31 // WebPDemuxReleaseIterator(&iter); | 31 WebPDemuxReleaseIterator(&iter); |
| 32 // } | 32 } |
| 33 // | 33 |
| 34 // // ... (Extract metadata). | 34 // ... (Extract metadata). |
| 35 // WebPChunkIterator chunk_iter; | 35 WebPChunkIterator chunk_iter; |
| 36 // if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter); | 36 if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter); |
| 37 // // ... (Consume the ICC profile in 'chunk_iter.chunk'). | 37 // ... (Consume the ICC profile in 'chunk_iter.chunk'). |
| 38 // WebPDemuxReleaseChunkIterator(&chunk_iter); | 38 WebPDemuxReleaseChunkIterator(&chunk_iter); |
| 39 // if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter); | 39 if (flags & EXIF_FLAG) WebPDemuxGetChunk(demux, "EXIF", 1, &chunk_iter); |
| 40 // // ... (Consume the EXIF metadata in 'chunk_iter.chunk'). | 40 // ... (Consume the EXIF metadata in 'chunk_iter.chunk'). |
| 41 // WebPDemuxReleaseChunkIterator(&chunk_iter); | 41 WebPDemuxReleaseChunkIterator(&chunk_iter); |
| 42 // if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter); | 42 if (flags & XMP_FLAG) WebPDemuxGetChunk(demux, "XMP ", 1, &chunk_iter); |
| 43 // // ... (Consume the XMP metadata in 'chunk_iter.chunk'). | 43 // ... (Consume the XMP metadata in 'chunk_iter.chunk'). |
| 44 // WebPDemuxReleaseChunkIterator(&chunk_iter); | 44 WebPDemuxReleaseChunkIterator(&chunk_iter); |
| 45 // WebPDemuxDelete(demux); | 45 WebPDemuxDelete(demux); |
| 46 */ |
| 46 | 47 |
| 47 #ifndef WEBP_WEBP_DEMUX_H_ | 48 #ifndef WEBP_WEBP_DEMUX_H_ |
| 48 #define WEBP_WEBP_DEMUX_H_ | 49 #define WEBP_WEBP_DEMUX_H_ |
| 49 | 50 |
| 50 #include "./mux_types.h" | 51 #include "./mux_types.h" |
| 51 | 52 |
| 52 #if defined(__cplusplus) || defined(c_plusplus) | 53 #ifdef __cplusplus |
| 53 extern "C" { | 54 extern "C" { |
| 54 #endif | 55 #endif |
| 55 | 56 |
| 56 #define WEBP_DEMUX_ABI_VERSION 0x0101 // MAJOR(8b) + MINOR(8b) | 57 #define WEBP_DEMUX_ABI_VERSION 0x0101 // MAJOR(8b) + MINOR(8b) |
| 57 | 58 |
| 58 // Note: forward declaring enumerations is not allowed in (strict) C and C++, | 59 // Note: forward declaring enumerations is not allowed in (strict) C and C++, |
| 59 // the types are left here for reference. | 60 // the types are left here for reference. |
| 60 // typedef enum WebPDemuxState WebPDemuxState; | 61 // typedef enum WebPDemuxState WebPDemuxState; |
| 61 // typedef enum WebPFormatFeature WebPFormatFeature; | 62 // typedef enum WebPFormatFeature WebPFormatFeature; |
| 62 typedef struct WebPDemuxer WebPDemuxer; | 63 typedef struct WebPDemuxer WebPDemuxer; |
| 63 typedef struct WebPIterator WebPIterator; | 64 typedef struct WebPIterator WebPIterator; |
| 64 typedef struct WebPChunkIterator WebPChunkIterator; | 65 typedef struct WebPChunkIterator WebPChunkIterator; |
| 65 | 66 |
| 66 //------------------------------------------------------------------------------ | 67 //------------------------------------------------------------------------------ |
| 67 | 68 |
| 68 // Returns the version number of the demux library, packed in hexadecimal using | 69 // Returns the version number of the demux library, packed in hexadecimal using |
| 69 // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. | 70 // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. |
| 70 WEBP_EXTERN(int) WebPGetDemuxVersion(void); | 71 WEBP_EXTERN(int) WebPGetDemuxVersion(void); |
| 71 | 72 |
| 72 //------------------------------------------------------------------------------ | 73 //------------------------------------------------------------------------------ |
| 73 // Life of a Demux object | 74 // Life of a Demux object |
| 74 | 75 |
| 75 typedef enum WebPDemuxState { | 76 typedef enum WebPDemuxState { |
| 76 WEBP_DEMUX_PARSING_HEADER, // Not enough data to parse full header. | 77 WEBP_DEMUX_PARSE_ERROR = -1, // An error occurred while parsing. |
| 77 WEBP_DEMUX_PARSED_HEADER, // Header parsing complete, data may be available. | 78 WEBP_DEMUX_PARSING_HEADER = 0, // Not enough data to parse full header. |
| 78 WEBP_DEMUX_DONE // Entire file has been parsed. | 79 WEBP_DEMUX_PARSED_HEADER = 1, // Header parsing complete, |
| 80 // data may be available. |
| 81 WEBP_DEMUX_DONE = 2 // Entire file has been parsed. |
| 79 } WebPDemuxState; | 82 } WebPDemuxState; |
| 80 | 83 |
| 81 // Internal, version-checked, entry point | 84 // Internal, version-checked, entry point |
| 82 WEBP_EXTERN(WebPDemuxer*) WebPDemuxInternal( | 85 WEBP_EXTERN(WebPDemuxer*) WebPDemuxInternal( |
| 83 const WebPData*, int, WebPDemuxState*, int); | 86 const WebPData*, int, WebPDemuxState*, int); |
| 84 | 87 |
| 85 // Parses the full WebP file given by 'data'. | 88 // Parses the full WebP file given by 'data'. |
| 86 // Returns a WebPDemuxer object on successful parse, NULL otherwise. | 89 // Returns a WebPDemuxer object on successful parse, NULL otherwise. |
| 87 static WEBP_INLINE WebPDemuxer* WebPDemux(const WebPData* data) { | 90 static WEBP_INLINE WebPDemuxer* WebPDemux(const WebPData* data) { |
| 88 return WebPDemuxInternal(data, 0, NULL, WEBP_DEMUX_ABI_VERSION); | 91 return WebPDemuxInternal(data, 0, NULL, WEBP_DEMUX_ABI_VERSION); |
| 89 } | 92 } |
| 90 | 93 |
| 91 // Parses the possibly incomplete WebP file given by 'data'. | 94 // Parses the possibly incomplete WebP file given by 'data'. |
| 92 // If 'state' is non-NULL it will be set to indicate the status of the demuxer. | 95 // If 'state' is non-NULL it will be set to indicate the status of the demuxer. |
| 93 // Returns a WebPDemuxer object on successful parse, NULL otherwise. | 96 // Returns NULL in case of error or if there isn't enough data to start parsing; |
| 97 // and a WebPDemuxer object on successful parse. |
| 98 // Note that WebPDemuxer keeps internal pointers to 'data' memory segment. |
| 99 // If this data is volatile, the demuxer object should be deleted (by calling |
| 100 // WebPDemuxDelete()) and WebPDemuxPartial() called again on the new data. |
| 101 // This is usually an inexpensive operation. |
| 94 static WEBP_INLINE WebPDemuxer* WebPDemuxPartial( | 102 static WEBP_INLINE WebPDemuxer* WebPDemuxPartial( |
| 95 const WebPData* data, WebPDemuxState* state) { | 103 const WebPData* data, WebPDemuxState* state) { |
| 96 return WebPDemuxInternal(data, 1, state, WEBP_DEMUX_ABI_VERSION); | 104 return WebPDemuxInternal(data, 1, state, WEBP_DEMUX_ABI_VERSION); |
| 97 } | 105 } |
| 98 | 106 |
| 99 // Frees memory associated with 'dmux'. | 107 // Frees memory associated with 'dmux'. |
| 100 WEBP_EXTERN(void) WebPDemuxDelete(WebPDemuxer* dmux); | 108 WEBP_EXTERN(void) WebPDemuxDelete(WebPDemuxer* dmux); |
| 101 | 109 |
| 102 //------------------------------------------------------------------------------ | 110 //------------------------------------------------------------------------------ |
| 103 // Data/information extraction. | 111 // Data/information extraction. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // 'fragment_num'. | 146 // 'fragment_num'. |
| 139 int has_alpha; // True if the frame or fragment contains transparency. | 147 int has_alpha; // True if the frame or fragment contains transparency. |
| 140 WebPMuxAnimBlend blend_method; // Blend operation for the frame. | 148 WebPMuxAnimBlend blend_method; // Blend operation for the frame. |
| 141 | 149 |
| 142 uint32_t pad[2]; // padding for later use. | 150 uint32_t pad[2]; // padding for later use. |
| 143 void* private_; // for internal use only. | 151 void* private_; // for internal use only. |
| 144 }; | 152 }; |
| 145 | 153 |
| 146 // Retrieves frame 'frame_number' from 'dmux'. | 154 // Retrieves frame 'frame_number' from 'dmux'. |
| 147 // 'iter->fragment' points to the first fragment on return from this function. | 155 // 'iter->fragment' points to the first fragment on return from this function. |
| 148 // Individual fragments may be extracted using WebPDemuxSetFragment(). | 156 // Individual fragments may be extracted using WebPDemuxSelectFragment(). |
| 149 // Setting 'frame_number' equal to 0 will return the last frame of the image. | 157 // Setting 'frame_number' equal to 0 will return the last frame of the image. |
| 150 // Returns false if 'dmux' is NULL or frame 'frame_number' is not present. | 158 // Returns false if 'dmux' is NULL or frame 'frame_number' is not present. |
| 151 // Call WebPDemuxReleaseIterator() when use of the iterator is complete. | 159 // Call WebPDemuxReleaseIterator() when use of the iterator is complete. |
| 152 // NOTE: 'dmux' must persist for the lifetime of 'iter'. | 160 // NOTE: 'dmux' must persist for the lifetime of 'iter'. |
| 153 WEBP_EXTERN(int) WebPDemuxGetFrame( | 161 WEBP_EXTERN(int) WebPDemuxGetFrame( |
| 154 const WebPDemuxer* dmux, int frame_number, WebPIterator* iter); | 162 const WebPDemuxer* dmux, int frame_number, WebPIterator* iter); |
| 155 | 163 |
| 156 // Sets 'iter->fragment' to point to the next ('iter->frame_num' + 1) or | 164 // Sets 'iter->fragment' to point to the next ('iter->frame_num' + 1) or |
| 157 // previous ('iter->frame_num' - 1) frame. These functions do not loop. | 165 // previous ('iter->frame_num' - 1) frame. These functions do not loop. |
| 158 // Returns true on success, false otherwise. | 166 // Returns true on success, false otherwise. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 WEBP_EXTERN(int) WebPDemuxNextChunk(WebPChunkIterator* iter); | 210 WEBP_EXTERN(int) WebPDemuxNextChunk(WebPChunkIterator* iter); |
| 203 WEBP_EXTERN(int) WebPDemuxPrevChunk(WebPChunkIterator* iter); | 211 WEBP_EXTERN(int) WebPDemuxPrevChunk(WebPChunkIterator* iter); |
| 204 | 212 |
| 205 // Releases any memory associated with 'iter'. | 213 // Releases any memory associated with 'iter'. |
| 206 // Must be called before destroying the associated WebPDemuxer with | 214 // Must be called before destroying the associated WebPDemuxer with |
| 207 // WebPDemuxDelete(). | 215 // WebPDemuxDelete(). |
| 208 WEBP_EXTERN(void) WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter); | 216 WEBP_EXTERN(void) WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter); |
| 209 | 217 |
| 210 //------------------------------------------------------------------------------ | 218 //------------------------------------------------------------------------------ |
| 211 | 219 |
| 212 #if defined(__cplusplus) || defined(c_plusplus) | 220 #ifdef __cplusplus |
| 213 } // extern "C" | 221 } // extern "C" |
| 214 #endif | 222 #endif |
| 215 | 223 |
| 216 #endif /* WEBP_WEBP_DEMUX_H_ */ | 224 #endif /* WEBP_WEBP_DEMUX_H_ */ |
| OLD | NEW |