~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/third_party/libwebp/src/mux/muxi.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 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
 
// Internal header for mux library.
11
 
//
12
 
// Author: Urvang (urvang@google.com)
13
 
 
14
 
#ifndef WEBP_MUX_MUXI_H_
15
 
#define WEBP_MUX_MUXI_H_
16
 
 
17
 
#include <stdlib.h>
18
 
#include "../dec/vp8i.h"
19
 
#include "../dec/vp8li.h"
20
 
#include "../webp/mux.h"
21
 
 
22
 
#ifdef __cplusplus
23
 
extern "C" {
24
 
#endif
25
 
 
26
 
//------------------------------------------------------------------------------
27
 
// Defines and constants.
28
 
 
29
 
#define MUX_MAJ_VERSION 0
30
 
#define MUX_MIN_VERSION 2
31
 
#define MUX_REV_VERSION 1
32
 
 
33
 
// Chunk object.
34
 
typedef struct WebPChunk WebPChunk;
35
 
struct WebPChunk {
36
 
  uint32_t        tag_;
37
 
  int             owner_;  // True if *data_ memory is owned internally.
38
 
                           // VP8X, ANIM, and other internally created chunks
39
 
                           // like ANMF/FRGM are always owned.
40
 
  WebPData        data_;
41
 
  WebPChunk*      next_;
42
 
};
43
 
 
44
 
// MuxImage object. Store a full WebP image (including ANMF/FRGM chunk, ALPH
45
 
// chunk and VP8/VP8L chunk),
46
 
typedef struct WebPMuxImage WebPMuxImage;
47
 
struct WebPMuxImage {
48
 
  WebPChunk*  header_;      // Corresponds to WEBP_CHUNK_ANMF/WEBP_CHUNK_FRGM.
49
 
  WebPChunk*  alpha_;       // Corresponds to WEBP_CHUNK_ALPHA.
50
 
  WebPChunk*  img_;         // Corresponds to WEBP_CHUNK_IMAGE.
51
 
  WebPChunk*  unknown_;     // Corresponds to WEBP_CHUNK_UNKNOWN.
52
 
  int         width_;
53
 
  int         height_;
54
 
  int         has_alpha_;   // Through ALPH chunk or as part of VP8L.
55
 
  int         is_partial_;  // True if only some of the chunks are filled.
56
 
  WebPMuxImage* next_;
57
 
};
58
 
 
59
 
// Main mux object. Stores data chunks.
60
 
struct WebPMux {
61
 
  WebPMuxImage*   images_;
62
 
  WebPChunk*      iccp_;
63
 
  WebPChunk*      exif_;
64
 
  WebPChunk*      xmp_;
65
 
  WebPChunk*      anim_;
66
 
  WebPChunk*      vp8x_;
67
 
 
68
 
  WebPChunk*      unknown_;
69
 
  int             canvas_width_;
70
 
  int             canvas_height_;
71
 
};
72
 
 
73
 
// CHUNK_INDEX enum: used for indexing within 'kChunks' (defined below) only.
74
 
// Note: the reason for having two enums ('WebPChunkId' and 'CHUNK_INDEX') is to
75
 
// allow two different chunks to have the same id (e.g. WebPChunkId
76
 
// 'WEBP_CHUNK_IMAGE' can correspond to CHUNK_INDEX 'IDX_VP8' or 'IDX_VP8L').
77
 
typedef enum {
78
 
  IDX_VP8X = 0,
79
 
  IDX_ICCP,
80
 
  IDX_ANIM,
81
 
  IDX_ANMF,
82
 
  IDX_FRGM,
83
 
  IDX_ALPHA,
84
 
  IDX_VP8,
85
 
  IDX_VP8L,
86
 
  IDX_EXIF,
87
 
  IDX_XMP,
88
 
  IDX_UNKNOWN,
89
 
 
90
 
  IDX_NIL,
91
 
  IDX_LAST_CHUNK
92
 
} CHUNK_INDEX;
93
 
 
94
 
#define NIL_TAG 0x00000000u  // To signal void chunk.
95
 
 
96
 
typedef struct {
97
 
  uint32_t      tag;
98
 
  WebPChunkId   id;
99
 
  uint32_t      size;
100
 
} ChunkInfo;
101
 
 
102
 
extern const ChunkInfo kChunks[IDX_LAST_CHUNK];
103
 
 
104
 
//------------------------------------------------------------------------------
105
 
// Chunk object management.
106
 
 
107
 
// Initialize.
108
 
void ChunkInit(WebPChunk* const chunk);
109
 
 
110
 
// Get chunk index from chunk tag. Returns IDX_UNKNOWN if not found.
111
 
CHUNK_INDEX ChunkGetIndexFromTag(uint32_t tag);
112
 
 
113
 
// Get chunk id from chunk tag. Returns WEBP_CHUNK_UNKNOWN if not found.
114
 
WebPChunkId ChunkGetIdFromTag(uint32_t tag);
115
 
 
116
 
// Convert a fourcc string to a tag.
117
 
uint32_t ChunkGetTagFromFourCC(const char fourcc[4]);
118
 
 
119
 
// Get chunk index from fourcc. Returns IDX_UNKNOWN if given fourcc is unknown.
120
 
CHUNK_INDEX ChunkGetIndexFromFourCC(const char fourcc[4]);
121
 
 
122
 
// Search for nth chunk with given 'tag' in the chunk list.
123
 
// nth = 0 means "last of the list".
124
 
WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag);
125
 
 
126
 
// Fill the chunk with the given data.
127
 
WebPMuxError ChunkAssignData(WebPChunk* chunk, const WebPData* const data,
128
 
                             int copy_data, uint32_t tag);
129
 
 
130
 
// Sets 'chunk' at nth position in the 'chunk_list'.
131
 
// nth = 0 has the special meaning "last of the list".
132
 
// On success ownership is transferred from 'chunk' to the 'chunk_list'.
133
 
WebPMuxError ChunkSetNth(WebPChunk* chunk, WebPChunk** chunk_list,
134
 
                         uint32_t nth);
135
 
 
136
 
// Releases chunk and returns chunk->next_.
137
 
WebPChunk* ChunkRelease(WebPChunk* const chunk);
138
 
 
139
 
// Deletes given chunk & returns chunk->next_.
140
 
WebPChunk* ChunkDelete(WebPChunk* const chunk);
141
 
 
142
 
// Deletes all chunks in the given chunk list.
143
 
void ChunkListDelete(WebPChunk** const chunk_list);
144
 
 
145
 
// Returns size of the chunk including chunk header and padding byte (if any).
146
 
static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) {
147
 
  return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U);
148
 
}
149
 
 
150
 
// Size of a chunk including header and padding.
151
 
static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) {
152
 
  const size_t data_size = chunk->data_.size;
153
 
  assert(data_size < MAX_CHUNK_PAYLOAD);
154
 
  return SizeWithPadding(data_size);
155
 
}
156
 
 
157
 
// Total size of a list of chunks.
158
 
size_t ChunkListDiskSize(const WebPChunk* chunk_list);
159
 
 
160
 
// Write out the given list of chunks into 'dst'.
161
 
uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst);
162
 
 
163
 
//------------------------------------------------------------------------------
164
 
// MuxImage object management.
165
 
 
166
 
// Initialize.
167
 
void MuxImageInit(WebPMuxImage* const wpi);
168
 
 
169
 
// Releases image 'wpi' and returns wpi->next.
170
 
WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi);
171
 
 
172
 
// Delete image 'wpi' and return the next image in the list or NULL.
173
 
// 'wpi' can be NULL.
174
 
WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi);
175
 
 
176
 
// Count number of images matching the given tag id in the 'wpi_list'.
177
 
// If id == WEBP_CHUNK_NIL, all images will be matched.
178
 
int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id);
179
 
 
180
 
// Update width/height/has_alpha info from chunks within wpi.
181
 
// Also remove ALPH chunk if not needed.
182
 
int MuxImageFinalize(WebPMuxImage* const wpi);
183
 
 
184
 
// Check if given ID corresponds to an image related chunk.
185
 
static WEBP_INLINE int IsWPI(WebPChunkId id) {
186
 
  switch (id) {
187
 
    case WEBP_CHUNK_ANMF:
188
 
    case WEBP_CHUNK_FRGM:
189
 
    case WEBP_CHUNK_ALPHA:
190
 
    case WEBP_CHUNK_IMAGE:  return 1;
191
 
    default:        return 0;
192
 
  }
193
 
}
194
 
 
195
 
// Pushes 'wpi' at the end of 'wpi_list'.
196
 
WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list);
197
 
 
198
 
// Delete nth image in the image list.
199
 
WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth);
200
 
 
201
 
// Get nth image in the image list.
202
 
WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth,
203
 
                            WebPMuxImage** wpi);
204
 
 
205
 
// Total size of the given image.
206
 
size_t MuxImageDiskSize(const WebPMuxImage* const wpi);
207
 
 
208
 
// Write out the given image into 'dst'.
209
 
uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst);
210
 
 
211
 
//------------------------------------------------------------------------------
212
 
// Helper methods for mux.
213
 
 
214
 
// Checks if the given image list contains at least one image with alpha.
215
 
int MuxHasAlpha(const WebPMuxImage* images);
216
 
 
217
 
// Write out RIFF header into 'data', given total data size 'size'.
218
 
uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size);
219
 
 
220
 
// Returns the list where chunk with given ID is to be inserted in mux.
221
 
WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id);
222
 
 
223
 
// Validates the given mux object.
224
 
WebPMuxError MuxValidate(const WebPMux* const mux);
225
 
 
226
 
//------------------------------------------------------------------------------
227
 
 
228
 
#ifdef __cplusplus
229
 
}    // extern "C"
230
 
#endif
231
 
 
232
 
#endif  /* WEBP_MUX_MUXI_H_ */