1 // Copyright 2012 Google Inc. All Rights Reserved. 2 // 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 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // ----------------------------------------------------------------------------- 9 // 10 // Data-types common to the mux and demux libraries. 11 // 12 // Author: Urvang (urvang (at) google.com) 13 14 #ifndef WEBP_WEBP_MUX_TYPES_H_ 15 #define WEBP_WEBP_MUX_TYPES_H_ 16 17 #include <stdlib.h> // free() 18 #include <string.h> // memset() 19 #include "./types.h" 20 21 #if defined(__cplusplus) || defined(c_plusplus) 22 extern "C" { 23 #endif 24 25 // Note: forward declaring enumerations is not allowed in (strict) C and C++, 26 // the types are left here for reference. 27 // typedef enum WebPFeatureFlags WebPFeatureFlags; 28 // typedef enum WebPMuxAnimDispose WebPMuxAnimDispose; 29 // typedef enum WebPMuxAnimBlend WebPMuxAnimBlend; 30 typedef struct WebPData WebPData; 31 32 // VP8X Feature Flags. 33 typedef enum WebPFeatureFlags { 34 FRAGMENTS_FLAG = 0x00000001, 35 ANIMATION_FLAG = 0x00000002, 36 XMP_FLAG = 0x00000004, 37 EXIF_FLAG = 0x00000008, 38 ALPHA_FLAG = 0x00000010, 39 ICCP_FLAG = 0x00000020 40 } WebPFeatureFlags; 41 42 // Dispose method (animation only). Indicates how the area used by the current 43 // frame is to be treated before rendering the next frame on the canvas. 44 typedef enum WebPMuxAnimDispose { 45 WEBP_MUX_DISPOSE_NONE, // Do not dispose. 46 WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color. 47 } WebPMuxAnimDispose; 48 49 // Blend operation (animation only). Indicates how transparent pixels of the 50 // current frame are blended with those of the previous canvas. 51 typedef enum WebPMuxAnimBlend { 52 WEBP_MUX_BLEND, // Blend. 53 WEBP_MUX_NO_BLEND // Do not blend. 54 } WebPMuxAnimBlend; 55 56 // Data type used to describe 'raw' data, e.g., chunk data 57 // (ICC profile, metadata) and WebP compressed image data. 58 struct WebPData { 59 const uint8_t* bytes; 60 size_t size; 61 }; 62 63 // Initializes the contents of the 'webp_data' object with default values. 64 static WEBP_INLINE void WebPDataInit(WebPData* webp_data) { 65 if (webp_data != NULL) { 66 memset(webp_data, 0, sizeof(*webp_data)); 67 } 68 } 69 70 // Clears the contents of the 'webp_data' object by calling free(). Does not 71 // deallocate the object itself. 72 static WEBP_INLINE void WebPDataClear(WebPData* webp_data) { 73 if (webp_data != NULL) { 74 free((void*)webp_data->bytes); 75 WebPDataInit(webp_data); 76 } 77 } 78 79 // Allocates necessary storage for 'dst' and copies the contents of 'src'. 80 // Returns true on success. 81 static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) { 82 if (src == NULL || dst == NULL) return 0; 83 WebPDataInit(dst); 84 if (src->bytes != NULL && src->size != 0) { 85 dst->bytes = (uint8_t*)malloc(src->size); 86 if (dst->bytes == NULL) return 0; 87 memcpy((void*)dst->bytes, src->bytes, src->size); 88 dst->size = src->size; 89 } 90 return 1; 91 } 92 93 #if defined(__cplusplus) || defined(c_plusplus) 94 } // extern "C" 95 #endif 96 97 #endif /* WEBP_WEBP_MUX_TYPES_H_ */ 98