Skip to content

Commit

Permalink
Move some more declarations to top of block
Browse files Browse the repository at this point in the history
  • Loading branch information
jd20 committed Sep 29, 2017
1 parent e32fb4f commit c9258d6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions _webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static const char* const kErrorMessages[-WEBP_MUX_NOT_ENOUGH_DATA + 1] = {

PyObject* HandleMuxError(WebPMuxError err, char* chunk) {
char message[100];
int message_len;
assert(err <= WEBP_MUX_NOT_FOUND && err >= WEBP_MUX_NOT_ENOUGH_DATA);

// Check for a memory error first
Expand All @@ -44,9 +45,13 @@ PyObject* HandleMuxError(WebPMuxError err, char* chunk) {

// Create the error message
if (chunk == NULL) {
sprintf(message, "could not assemble chunks: %s", kErrorMessages[-err]);
message_len = sprintf_s(message, 100, "could not assemble chunks: %s", kErrorMessages[-err]);
} else {
sprintf(message, "could not set %.4s chunk: %s", chunk, kErrorMessages[-err]);
message_len = sprintf_s(message, 100, "could not set %.4s chunk: %s", chunk, kErrorMessages[-err]);
}
if (message_len < 0) {
PyErr_SetString(PyExc_RuntimeError, "failed to construct error message");
return NULL;
}

// Set the proper error type
Expand Down Expand Up @@ -171,6 +176,7 @@ PyObject* _anim_encoder_add(PyObject* self, PyObject* args)
int lossless;
float quality_factor;
int method;
WebPConfig config;
WebPAnimEncoderObject* encp = (WebPAnimEncoderObject*)self;
WebPAnimEncoder* enc = encp->enc;
WebPPicture* frame = &(encp->frame);
Expand All @@ -188,7 +194,6 @@ PyObject* _anim_encoder_add(PyObject* self, PyObject* args)
}

// Setup config for this frame
WebPConfig config;
if (!WebPConfigInit(&config)) {
PyErr_SetString(PyExc_RuntimeError, "failed to initialize config!");
return NULL;
Expand Down Expand Up @@ -230,6 +235,7 @@ PyObject* _anim_encoder_assemble(PyObject* self, PyObject* args)
Py_ssize_t icc_size;
Py_ssize_t exif_size;
Py_ssize_t xmp_size;
WebPData webp_data;
WebPAnimEncoderObject* encp = (WebPAnimEncoderObject*)self;
WebPAnimEncoder* enc = encp->enc;
WebPMux* mux = NULL;
Expand All @@ -241,7 +247,6 @@ PyObject* _anim_encoder_assemble(PyObject* self, PyObject* args)
}

// Init the output buffer
WebPData webp_data;
WebPDataInit(&webp_data);

// Assemble everything into the output buffer
Expand Down Expand Up @@ -316,19 +321,20 @@ PyObject* _anim_decoder_new(PyObject* self, PyObject* args)
const uint8_t *webp;
Py_ssize_t size;
WebPData webp_src;
char* mode;
WebPDecoderConfig config;
WebPAnimDecoderObject* decp = NULL;
WebPAnimDecoder* dec = NULL;

if (!PyArg_ParseTuple(args, "S", &webp_string)) {
return NULL;
}
PyBytes_AsStringAndSize((PyObject *) webp_string, (char**)&webp, &size);
PyBytes_AsStringAndSize((PyObject *)webp_string, (char**)&webp, &size);
webp_src.bytes = webp;
webp_src.size = size;

// Sniff the mode, since the decoder API doesn't tell us
char* mode = "RGBA";
mode = "RGBA";
if (WebPGetFeatures(webp, size, &config.input) == VP8_STATUS_OK) {
if (!config.input.has_alpha) {
mode = "RGBX";
Expand Down

0 comments on commit c9258d6

Please sign in to comment.