117 PyObject *
118 _anim_encoder_new(PyObject *self, PyObject *args) {
119 int width, height;
120 uint32_t bgcolor;
121 int loop_count;
122 int minimize_size;
123 int kmin, kmax;
124 int allow_mixed;
125 int verbose;
126 WebPAnimEncoderOptions enc_options;
127 WebPAnimEncoderObject *encp = NULL;
128 WebPAnimEncoder *enc = NULL;
129
130 if (!PyArg_ParseTuple(
when _PyArg_ParseTuple_SizeT() succeeds
taking False path
131 args,
132 "iiIiiiiii",
133 &width,
134 &height,
135 &bgcolor,
136 &loop_count,
137 &minimize_size,
138 &kmin,
139 &kmax,
140 &allow_mixed,
141 &verbose)) {
142 return NULL;
143 }
144
145 // Setup and configure the encoder's options (these are animation-specific)
146 if (!WebPAnimEncoderOptionsInit(&enc_options)) {
when considering range: -0x80000000 <= value <= -1
taking False path
147 PyErr_SetString(PyExc_RuntimeError, "failed to initialize encoder options");
148 return NULL;
149 }
150 enc_options.anim_params.bgcolor = bgcolor;
151 enc_options.anim_params.loop_count = loop_count;
152 enc_options.minimize_size = minimize_size;
153 enc_options.kmin = kmin;
154 enc_options.kmax = kmax;
155 enc_options.allow_mixed = allow_mixed;
156 enc_options.verbose = verbose;
157
158 // Validate canvas dimensions
159 if (width <= 0 || height <= 0) {
when considering range: 1 <= value <= 0x7fffffff
taking False path
when considering range: 1 <= value <= 0x7fffffff
taking False path
160 PyErr_SetString(PyExc_ValueError, "invalid canvas dimensions");
161 return NULL;
162 }
163
164 // Create a new animation encoder and picture frame
165 encp = PyObject_New(WebPAnimEncoderObject, &WebPAnimEncoder_Type);
when _PyObject_New() succeeds
'*encp' was allocated at: encp = PyObject_New(WebPAnimEncoderObject, &WebPAnimEncoder_Type);
ob_refcnt is now refs: 1 owned
166 if (encp) {
taking True path
167 if (WebPPictureInit(&(encp->frame))) {
when considering range: -0x80000000 <= value <= -1
taking True path
168 enc = WebPAnimEncoderNew(width, height, &enc_options);
169 if (enc) {
when treating unknown struct WebPAnimEncoder * from src/_webp.c:168 as NULL
taking False path
170 encp->enc = enc;
171 return (PyObject *)encp;
172 }
173 WebPPictureFree(&(encp->frame));
174 }
175 PyObject_Del(encp);
176 }
177 PyErr_SetString(PyExc_RuntimeError, "could not create encoder object");
calling PyErr_SetString()
178 return NULL;
179 }