mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 22:28:22 +01:00
AnimEncoder API: Remove AnimEncoderFrameOptions.
We only need config now, so this struct is not needed. Change-Id: I5139956d13c36ceb4871d52122f248fe70f40c4b
This commit is contained in:
parent
b902c3ea50
commit
5e56bbe09a
@ -271,13 +271,6 @@ void WebPAnimEncoderDelete(WebPAnimEncoder* enc) {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Frame addition.
|
// Frame addition.
|
||||||
|
|
||||||
// Initialize frame options to reasonable defaults.
|
|
||||||
static void DefaultFrameOptions(
|
|
||||||
WebPAnimEncoderFrameOptions* const frame_options) {
|
|
||||||
WebPConfigInit(&frame_options->config);
|
|
||||||
frame_options->config.lossless = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns cached frame at the given 'position'.
|
// Returns cached frame at the given 'position'.
|
||||||
static EncodedFrame* GetFrame(const WebPAnimEncoder* const enc,
|
static EncodedFrame* GetFrame(const WebPAnimEncoder* const enc,
|
||||||
size_t position) {
|
size_t position) {
|
||||||
@ -798,16 +791,16 @@ static void PickBestCandidate(WebPAnimEncoder* const enc,
|
|||||||
// Depending on the configuration, tries different compressions
|
// Depending on the configuration, tries different compressions
|
||||||
// (lossy/lossless), dispose methods, blending methods etc to encode the current
|
// (lossy/lossless), dispose methods, blending methods etc to encode the current
|
||||||
// frame and outputs the best one in 'encoded_frame'.
|
// frame and outputs the best one in 'encoded_frame'.
|
||||||
static WebPEncodingError SetFrame(
|
static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, int duration,
|
||||||
WebPAnimEncoder* const enc, int duration,
|
const WebPConfig* const config,
|
||||||
const WebPAnimEncoderFrameOptions* const frame_options, int is_key_frame,
|
int is_key_frame,
|
||||||
EncodedFrame* const encoded_frame) {
|
EncodedFrame* const encoded_frame) {
|
||||||
int i;
|
int i;
|
||||||
WebPEncodingError error_code = VP8_ENC_OK;
|
WebPEncodingError error_code = VP8_ENC_OK;
|
||||||
const WebPPicture* const curr_canvas = &enc->curr_canvas_copy_;
|
const WebPPicture* const curr_canvas = &enc->curr_canvas_copy_;
|
||||||
const WebPPicture* const prev_canvas = &enc->prev_canvas_;
|
const WebPPicture* const prev_canvas = &enc->prev_canvas_;
|
||||||
Candidate candidates[CANDIDATE_COUNT];
|
Candidate candidates[CANDIDATE_COUNT];
|
||||||
const int is_lossless = frame_options->config.lossless;
|
const int is_lossless = config->lossless;
|
||||||
const int is_first_frame = enc->is_first_frame_;
|
const int is_first_frame = enc->is_first_frame_;
|
||||||
|
|
||||||
int try_dispose_none = 1; // Default.
|
int try_dispose_none = 1; // Default.
|
||||||
@ -826,8 +819,8 @@ static WebPEncodingError SetFrame(
|
|||||||
FrameRect rect_bg;
|
FrameRect rect_bg;
|
||||||
WebPPicture sub_frame_bg;
|
WebPPicture sub_frame_bg;
|
||||||
|
|
||||||
WebPConfig config_ll = frame_options->config;
|
WebPConfig config_ll = *config;
|
||||||
WebPConfig config_lossy = frame_options->config;
|
WebPConfig config_lossy = *config;
|
||||||
config_ll.lossless = 1;
|
config_ll.lossless = 1;
|
||||||
config_lossy.lossless = 0;
|
config_lossy.lossless = 0;
|
||||||
|
|
||||||
@ -903,7 +896,7 @@ static int64_t KeyFramePenalty(const EncodedFrame* const encoded_frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int CacheFrame(WebPAnimEncoder* const enc, int duration,
|
static int CacheFrame(WebPAnimEncoder* const enc, int duration,
|
||||||
const WebPAnimEncoderFrameOptions* const frame_options) {
|
const WebPConfig* const config) {
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
WebPEncodingError error_code = VP8_ENC_OK;
|
WebPEncodingError error_code = VP8_ENC_OK;
|
||||||
const size_t position = enc->count_;
|
const size_t position = enc->count_;
|
||||||
@ -913,7 +906,7 @@ static int CacheFrame(WebPAnimEncoder* const enc, int duration,
|
|||||||
|
|
||||||
if (enc->is_first_frame_) { // Add this as a key-frame.
|
if (enc->is_first_frame_) { // Add this as a key-frame.
|
||||||
error_code =
|
error_code =
|
||||||
SetFrame(enc, duration, frame_options, 1, encoded_frame);
|
SetFrame(enc, duration, config, 1, encoded_frame);
|
||||||
if (error_code != VP8_ENC_OK) {
|
if (error_code != VP8_ENC_OK) {
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
@ -926,7 +919,7 @@ static int CacheFrame(WebPAnimEncoder* const enc, int duration,
|
|||||||
++enc->count_since_key_frame_;
|
++enc->count_since_key_frame_;
|
||||||
if (enc->count_since_key_frame_ <= enc->options_.kmin) {
|
if (enc->count_since_key_frame_ <= enc->options_.kmin) {
|
||||||
// Add this as a frame rectangle.
|
// Add this as a frame rectangle.
|
||||||
error_code = SetFrame(enc, duration, frame_options, 0, encoded_frame);
|
error_code = SetFrame(enc, duration, config, 0, encoded_frame);
|
||||||
if (error_code != VP8_ENC_OK) {
|
if (error_code != VP8_ENC_OK) {
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
@ -937,11 +930,11 @@ static int CacheFrame(WebPAnimEncoder* const enc, int duration,
|
|||||||
int64_t curr_delta;
|
int64_t curr_delta;
|
||||||
|
|
||||||
// Add this as a frame rectangle to enc.
|
// Add this as a frame rectangle to enc.
|
||||||
error_code = SetFrame(enc, duration, frame_options, 0, encoded_frame);
|
error_code = SetFrame(enc, duration, config, 0, encoded_frame);
|
||||||
if (error_code != VP8_ENC_OK) goto End;
|
if (error_code != VP8_ENC_OK) goto End;
|
||||||
|
|
||||||
// Add this as a key-frame to enc, too.
|
// Add this as a key-frame to enc, too.
|
||||||
error_code = SetFrame(enc, duration, frame_options, 1, encoded_frame);
|
error_code = SetFrame(enc, duration, config, 1, encoded_frame);
|
||||||
if (error_code != VP8_ENC_OK) goto End;
|
if (error_code != VP8_ENC_OK) goto End;
|
||||||
|
|
||||||
// Analyze size difference of the two variants.
|
// Analyze size difference of the two variants.
|
||||||
@ -1040,8 +1033,8 @@ static int FlushFrames(WebPAnimEncoder* const enc) {
|
|||||||
#undef KEYFRAME_NONE
|
#undef KEYFRAME_NONE
|
||||||
|
|
||||||
int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int duration,
|
int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int duration,
|
||||||
const WebPAnimEncoderFrameOptions* frame_options) {
|
const WebPConfig* encoder_config) {
|
||||||
WebPAnimEncoderFrameOptions options;
|
WebPConfig config;
|
||||||
if (enc == NULL || frame == NULL) {
|
if (enc == NULL || frame == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1054,17 +1047,18 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int duration,
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (frame_options != NULL) {
|
if (encoder_config != NULL) {
|
||||||
options = *frame_options;
|
config = *encoder_config;
|
||||||
} else {
|
} else {
|
||||||
DefaultFrameOptions(&options);
|
WebPConfigInit(&config);
|
||||||
|
config.lossless = 1;
|
||||||
}
|
}
|
||||||
assert(enc->curr_canvas_ == NULL);
|
assert(enc->curr_canvas_ == NULL);
|
||||||
enc->curr_canvas_ = frame; // Store reference.
|
enc->curr_canvas_ = frame; // Store reference.
|
||||||
assert(enc->curr_canvas_copy_modified_ == 1);
|
assert(enc->curr_canvas_copy_modified_ == 1);
|
||||||
CopyCurrentCanvas(enc);
|
CopyCurrentCanvas(enc);
|
||||||
|
|
||||||
if (!CacheFrame(enc, duration, &options)) {
|
if (!CacheFrame(enc, duration, &config)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!FlushFrames(enc)) {
|
if (!FlushFrames(enc)) {
|
||||||
|
@ -401,7 +401,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* mux,
|
|||||||
/*
|
/*
|
||||||
WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, enc_options);
|
WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, enc_options);
|
||||||
while(<there are more frames>) {
|
while(<there are more frames>) {
|
||||||
WebPAnimEncoderAdd(enc, frame, duration, frame_options);
|
WebPAnimEncoderAdd(enc, frame, duration, config);
|
||||||
}
|
}
|
||||||
WebPAnimEncoderAssemble(enc, webp_data);
|
WebPAnimEncoderAssemble(enc, webp_data);
|
||||||
WebPAnimEncoderDelete(enc);
|
WebPAnimEncoderDelete(enc);
|
||||||
@ -431,15 +431,6 @@ typedef struct {
|
|||||||
uint32_t padding[4]; // Padding for later use.
|
uint32_t padding[4]; // Padding for later use.
|
||||||
} WebPAnimEncoderOptions;
|
} WebPAnimEncoderOptions;
|
||||||
|
|
||||||
// Per-frame options.
|
|
||||||
typedef struct {
|
|
||||||
WebPConfig config; // Core encoding parameters.
|
|
||||||
// TODO(urvang): Add rectangle, dispose and blend method options. After adding
|
|
||||||
// them, we might need to add 'prev_frame_disposed' parameter to
|
|
||||||
// WebPAnimEncoderAdd as well.
|
|
||||||
uint32_t padding[8]; // Padding for later use.
|
|
||||||
} WebPAnimEncoderFrameOptions;
|
|
||||||
|
|
||||||
// Internal, version-checked, entry point.
|
// Internal, version-checked, entry point.
|
||||||
WEBP_EXTERN(WebPAnimEncoder*) WebPAnimEncoderNewInternal(
|
WEBP_EXTERN(WebPAnimEncoder*) WebPAnimEncoderNewInternal(
|
||||||
int, int, const WebPAnimEncoderOptions*, int);
|
int, int, const WebPAnimEncoderOptions*, int);
|
||||||
@ -464,14 +455,14 @@ static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew(
|
|||||||
// enc - (in/out) object to which the frame is to be added.
|
// enc - (in/out) object to which the frame is to be added.
|
||||||
// frame - (in/out) frame data in ARGB or YUVA format.
|
// frame - (in/out) frame data in ARGB or YUVA format.
|
||||||
// duration - (in) frame duration
|
// duration - (in) frame duration
|
||||||
// frame_options - (in) frame options; can be passed NULL to pick
|
// config - (in) encoding options; can be passed NULL to pick
|
||||||
// reasonable defaults.
|
// reasonable defaults.
|
||||||
// Returns:
|
// Returns:
|
||||||
// On error, returns false and frame->error_code is set appropriately.
|
// On error, returns false and frame->error_code is set appropriately.
|
||||||
// Otherwise, returns true.
|
// Otherwise, returns true.
|
||||||
WEBP_EXTERN(int) WebPAnimEncoderAdd(
|
WEBP_EXTERN(int) WebPAnimEncoderAdd(
|
||||||
WebPAnimEncoder* enc, WebPPicture* frame, int duration,
|
WebPAnimEncoder* enc, WebPPicture* frame, int duration,
|
||||||
const WebPAnimEncoderFrameOptions* frame_options);
|
const WebPConfig* config);
|
||||||
|
|
||||||
// Assemble all frames added so far into a WebP bitstream.
|
// Assemble all frames added so far into a WebP bitstream.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
|
Loading…
Reference in New Issue
Block a user