go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

mux_types.h (3260B)


      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@google.com)
     13 
     14 #ifndef WEBP_WEBP_MUX_TYPES_H_
     15 #define WEBP_WEBP_MUX_TYPES_H_
     16 
     17 #include <string.h>  // memset()
     18 
     19 #include "./types.h"
     20 
     21 #ifdef __cplusplus
     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   ANIMATION_FLAG  = 0x00000002,
     35   XMP_FLAG        = 0x00000004,
     36   EXIF_FLAG       = 0x00000008,
     37   ALPHA_FLAG      = 0x00000010,
     38   ICCP_FLAG       = 0x00000020,
     39 
     40   ALL_VALID_FLAGS = 0x0000003e
     41 } WebPFeatureFlags;
     42 
     43 // Dispose method (animation only). Indicates how the area used by the current
     44 // frame is to be treated before rendering the next frame on the canvas.
     45 typedef enum WebPMuxAnimDispose {
     46   WEBP_MUX_DISPOSE_NONE,       // Do not dispose.
     47   WEBP_MUX_DISPOSE_BACKGROUND  // Dispose to background color.
     48 } WebPMuxAnimDispose;
     49 
     50 // Blend operation (animation only). Indicates how transparent pixels of the
     51 // current frame are blended with those of the previous canvas.
     52 typedef enum WebPMuxAnimBlend {
     53   WEBP_MUX_BLEND,              // Blend.
     54   WEBP_MUX_NO_BLEND            // Do not blend.
     55 } WebPMuxAnimBlend;
     56 
     57 // Data type used to describe 'raw' data, e.g., chunk data
     58 // (ICC profile, metadata) and WebP compressed image data.
     59 // 'bytes' memory must be allocated using WebPMalloc() and such.
     60 struct WebPData {
     61   const uint8_t* bytes;
     62   size_t size;
     63 };
     64 
     65 // Initializes the contents of the 'webp_data' object with default values.
     66 static WEBP_INLINE void WebPDataInit(WebPData* webp_data) {
     67   if (webp_data != NULL) {
     68     memset(webp_data, 0, sizeof(*webp_data));
     69   }
     70 }
     71 
     72 // Clears the contents of the 'webp_data' object by calling WebPFree().
     73 // Does not deallocate the object itself.
     74 static WEBP_INLINE void WebPDataClear(WebPData* webp_data) {
     75   if (webp_data != NULL) {
     76     WebPFree((void*)webp_data->bytes);
     77     WebPDataInit(webp_data);
     78   }
     79 }
     80 
     81 // Allocates necessary storage for 'dst' and copies the contents of 'src'.
     82 // Returns true on success.
     83 WEBP_NODISCARD static WEBP_INLINE int WebPDataCopy(const WebPData* src,
     84                                                    WebPData* dst) {
     85   if (src == NULL || dst == NULL) return 0;
     86   WebPDataInit(dst);
     87   if (src->bytes != NULL && src->size != 0) {
     88     dst->bytes = (uint8_t*)WebPMalloc(src->size);
     89     if (dst->bytes == NULL) return 0;
     90     memcpy((void*)dst->bytes, src->bytes, src->size);
     91     dst->size = src->size;
     92   }
     93   return 1;
     94 }
     95 
     96 #ifdef __cplusplus
     97 }    // extern "C"
     98 #endif
     99 
    100 #endif  // WEBP_WEBP_MUX_TYPES_H_