Generated by Cython 0.27.3
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: encode.c
001: # This file is part of Xpra.
002: # Copyright (C) 2014-2017 Antoine Martin <antoine@devloop.org.uk>
003: # Xpra is released under the terms of the GNU GPL v2, or, at your option, any
004: # later version. See the file COPYING for details.
005:
006: from __future__ import absolute_import
007:
+008: import os
__pyx_t_2 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_2) < 0) __PYX_ERR(0, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
009:
+010: from xpra.log import Logger
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_Logger); __Pyx_GIVEREF(__pyx_n_s_Logger); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Logger); __pyx_t_3 = __Pyx_Import(__pyx_n_s_xpra_log, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Logger); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_Logger, __pyx_t_2) < 0) __PYX_ERR(0, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+011: log = Logger("encoder", "webp")
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_Logger); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_log, __pyx_t_2) < 0) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_tuple__7 = PyTuple_Pack(2, __pyx_n_s_encoder, __pyx_n_s_webp); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7);
012:
013: from xpra.buffers.membuf cimport memalign, object_as_buffer
+014: from xpra.os_util import bytestostr
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_bytestostr); __Pyx_GIVEREF(__pyx_n_s_bytestostr); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_bytestostr); __pyx_t_3 = __Pyx_Import(__pyx_n_s_xpra_os_util, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_bytestostr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_bytestostr, __pyx_t_2) < 0) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
015:
+016: from xpra.util import envbool, envint
__pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_n_s_envbool); __Pyx_GIVEREF(__pyx_n_s_envbool); PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_envbool); __Pyx_INCREF(__pyx_n_s_envint); __Pyx_GIVEREF(__pyx_n_s_envint); PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_envint); __pyx_t_2 = __Pyx_Import(__pyx_n_s_xpra_util, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_envbool); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_envbool, __pyx_t_3) < 0) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_envint); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_envint, __pyx_t_3) < 0) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+017: cdef int LOG_CONFIG = envbool("XPRA_WEBP_LOG_CONFIG", False)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_envbool); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_4xpra_6codecs_4webp_6encode_LOG_CONFIG = __pyx_t_4; /* … */ __pyx_tuple__8 = PyTuple_Pack(2, __pyx_n_s_XPRA_WEBP_LOG_CONFIG, Py_False); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8);
+018: cdef int WEBP_THREADING = envbool("XPRA_WEBP_THREADING", True)
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_envbool); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_4xpra_6codecs_4webp_6encode_WEBP_THREADING = __pyx_t_4; /* … */ __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_XPRA_WEBP_THREADING, Py_True); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__9); __Pyx_GIVEREF(__pyx_tuple__9);
+019: cdef int LOSSLESS_THRESHOLD = envint("XPRA_WEBP_LOSSLESS_THRESHOLD", 75)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_envint); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 19, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_4xpra_6codecs_4webp_6encode_LOSSLESS_THRESHOLD = __pyx_t_4; /* … */ __pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_XPRA_WEBP_LOSSLESS_THRESHOLD, __pyx_int_75); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 19, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10);
+020: assert LOSSLESS_THRESHOLD>=0 and LOSSLESS_THRESHOLD<=100, "invalid lossless threshold: %i" % LOSSLESS_THRESHOLD
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { __pyx_t_6 = ((__pyx_v_4xpra_6codecs_4webp_6encode_LOSSLESS_THRESHOLD >= 0) != 0); if (__pyx_t_6) { } else { __pyx_t_5 = __pyx_t_6; goto __pyx_L2_bool_binop_done; } __pyx_t_6 = ((__pyx_v_4xpra_6codecs_4webp_6encode_LOSSLESS_THRESHOLD <= 0x64) != 0); __pyx_t_5 = __pyx_t_6; __pyx_L2_bool_binop_done:; if (unlikely(!__pyx_t_5)) { __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_4xpra_6codecs_4webp_6encode_LOSSLESS_THRESHOLD); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_invalid_lossless_threshold_i, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 20, __pyx_L1_error) } } #endif
021:
+022: cdef inline int MIN(int a, int b):
static CYTHON_INLINE int __pyx_f_4xpra_6codecs_4webp_6encode_MIN(int __pyx_v_a, int __pyx_v_b) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("MIN", 0); /* … */ /* function exit code */ __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; }
+023: if a<=b:
__pyx_t_1 = ((__pyx_v_a <= __pyx_v_b) != 0); if (__pyx_t_1) { /* … */ }
+024: return a
__pyx_r = __pyx_v_a; goto __pyx_L0;
+025: return b
__pyx_r = __pyx_v_b; goto __pyx_L0;
+026: cdef inline int MAX(int a, int b):
static CYTHON_INLINE int __pyx_f_4xpra_6codecs_4webp_6encode_MAX(int __pyx_v_a, int __pyx_v_b) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("MAX", 0); /* … */ /* function exit code */ __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; }
+027: if a>=b:
__pyx_t_1 = ((__pyx_v_a >= __pyx_v_b) != 0); if (__pyx_t_1) { /* … */ }
+028: return a
__pyx_r = __pyx_v_a; goto __pyx_L0;
+029: return b
__pyx_r = __pyx_v_b; goto __pyx_L0;
030:
031:
032: from libc.stdint cimport uint8_t, uint32_t, uintptr_t
033:
034: cdef extern from "string.h":
035: void * memset ( void * ptr, int value, size_t num )
036:
037: cdef extern from *:
038: ctypedef unsigned long size_t
039:
040: cdef extern from "stdlib.h":
041: void free(void *ptr)
042:
043:
044: DEF WEBP_MAX_DIMENSION = 16383
045:
046: cdef extern from "webp/encode.h":
047:
048: int WebPGetEncoderVersion()
049:
050: ctypedef int WebPImageHint
051: # WebPImageHint:
052: WebPImageHint WEBP_HINT_DEFAULT #default preset
053: WebPImageHint WEBP_HINT_PICTURE #digital picture, like portrait, inner shot
054: WebPImageHint WEBP_HINT_PHOTO #outdoor photograph, with natural lighting
055: WebPImageHint WEBP_HINT_GRAPH #Discrete tone image (graph, map-tile etc).
056:
057: ctypedef int WebPPreset
058: WebPPreset WEBP_PRESET_DEFAULT #default preset.
059: WebPPreset WEBP_PRESET_PICTURE #digital picture, like portrait, inner shot
060: WebPPreset WEBP_PRESET_PHOTO #outdoor photograph, with natural lighting
061: WebPPreset WEBP_PRESET_DRAWING #hand or line drawing, with high-contrast details
062: WebPPreset WEBP_PRESET_ICON #small-sized colorful images
063: WebPPreset WEBP_PRESET_TEXT #text-like
064:
065: ctypedef int WebPEncCSP
066: #chroma sampling
067: WebPEncCSP WEBP_YUV420 #4:2:0
068: WebPEncCSP WEBP_YUV422 #4:2:2
069: WebPEncCSP WEBP_YUV444 #4:4:4
070: WebPEncCSP WEBP_YUV400 #grayscale
071: WebPEncCSP WEBP_CSP_UV_MASK #bit-mask to get the UV sampling factors
072: WebPEncCSP WEBP_YUV420A
073: WebPEncCSP WEBP_YUV422A
074: WebPEncCSP WEBP_YUV444A
075: WebPEncCSP WEBP_YUV400A #grayscale + alpha
076: WebPEncCSP WEBP_CSP_ALPHA_BIT #bit that is set if alpha is present
077:
078: ctypedef int WebPEncodingError
079: WebPEncodingError VP8_ENC_OK
080: WebPEncodingError VP8_ENC_ERROR_OUT_OF_MEMORY
081: WebPEncodingError VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY
082: WebPEncodingError VP8_ENC_ERROR_NULL_PARAMETER
083: WebPEncodingError VP8_ENC_ERROR_INVALID_CONFIGURATION
084: WebPEncodingError VP8_ENC_ERROR_BAD_DIMENSION
085: WebPEncodingError VP8_ENC_ERROR_PARTITION0_OVERFLOW
086: WebPEncodingError VP8_ENC_ERROR_PARTITION_OVERFLOW
087: WebPEncodingError VP8_ENC_ERROR_BAD_WRITE
088: WebPEncodingError VP8_ENC_ERROR_FILE_TOO_BIG
089: WebPEncodingError VP8_ENC_ERROR_USER_ABORT
090: WebPEncodingError VP8_ENC_ERROR_LAST
091:
092: ctypedef struct WebPConfig:
093: int lossless #Lossless encoding (0=lossy(default), 1=lossless).
094: float quality #between 0 (smallest file) and 100 (biggest)
095: int method #quality/speed trade-off (0=fast, 6=slower-better)
096:
097: WebPImageHint image_hint #Hint for image type (lossless only for now).
098:
099: #Parameters related to lossy compression only:
100: int target_size #if non-zero, set the desired target size in bytes.
101: #Takes precedence over the 'compression' parameter.
102: float target_PSNR #if non-zero, specifies the minimal distortion to
103: #try to achieve. Takes precedence over target_size.
104: int segments #maximum number of segments to use, in [1..4]
105: int sns_strength #Spatial Noise Shaping. 0=off, 100=maximum.
106: int filter_strength #range: [0 = off .. 100 = strongest]
107: int filter_sharpness #range: [0 = off .. 7 = least sharp]
108: int filter_type #filtering type: 0 = simple, 1 = strong (only used
109: #if filter_strength > 0 or autofilter > 0)
110: int autofilter #Auto adjust filter's strength [0 = off, 1 = on]
111: int alpha_compression #Algorithm for encoding the alpha plane (0 = none,
112: #1 compressed with WebP lossless). Default is 1.
113: int alpha_filtering #Predictive filtering method for alpha plane.
114: #0: none, 1: fast, 2: best. Default if 1.
115: int alpha_quality #Between 0 (smallest size) and 100 (lossless).
116: #Default is 100.
117: int _pass "pass" #number of entropy-analysis passes (in [1..10]).
118:
119: int show_compressed #if true, export the compressed picture back.
120: #In-loop filtering is not applied.
121: int preprocessing #preprocessing filter (0=none, 1=segment-smooth)
122: int partitions #log2(number of token partitions) in [0..3]. Default
123: #is set to 0 for easier progressive decoding.
124: int partition_limit #quality degradation allowed to fit the 512k limit
125: #on prediction modes coding (0: no degradation,
126: #100: maximum possible degradation).
127: int emulate_jpeg_size #If true, compression parameters will be remapped
128: #to better match the expected output size from
129: #JPEG compression. Generally, the output size will
130: #be similar but the degradation will be lower.
131: int thread_level #If non-zero, try and use multi-threaded encoding.
132: int low_memory #If set, reduce memory usage (but increase CPU use).
133:
134: int near_lossless #Near lossless encoding [0 = max loss .. 100 = off
135: #(default)
136: int exact #if non-zero, preserve the exact RGB values under
137: #transparent area. Otherwise, discard this invisible
138: #RGB information for better compression. The default
139: #value is 0.
140: uint32_t pad[3] #padding for later use
141:
142: ctypedef struct WebPMemoryWriter:
143: uint8_t* mem #final buffer (of size 'max_size', larger than 'size').
144: size_t size #final size
145: size_t max_size #total capacity
146: uint32_t pad[1]
147:
148: ctypedef void *WebPWriterFunction
149: ctypedef void *WebPProgressHook
150: ctypedef void *WebPAuxStats
151:
152: ctypedef struct WebPPicture:
153: # INPUT
154: # Main flag for encoder selecting between ARGB or YUV input.
155: # It is recommended to use ARGB input (*argb, argb_stride) for lossless
156: # compression, and YUV input (*y, *u, *v, etc.) for lossy compression
157: # since these are the respective native colorspace for these formats.
158: int use_argb
159:
160: # YUV input (mostly used for input to lossy compression)
161: WebPEncCSP colorspace #colorspace: should be YUV420 for now (=Y'CbCr).
162: int width, height #dimensions (less or equal to WEBP_MAX_DIMENSION)
163: uint8_t *y
164: uint8_t *u
165: uint8_t *v
166: int y_stride, uv_stride #luma/chroma strides.
167: uint8_t* a #pointer to the alpha plane
168: int a_stride #stride of the alpha plane
169: uint32_t pad1[2] #padding for later use
170:
171: # ARGB input (mostly used for input to lossless compression)
172: uint32_t* argb #Pointer to argb (32 bit) plane.
173: int argb_stride #This is stride in pixels units, not bytes.
174: uint32_t pad2[3] #padding for later use
175:
176: # OUTPUT
177: # Byte-emission hook, to store compressed bytes as they are ready.
178: WebPWriterFunction writer #can be NULL
179: void* custom_ptr #can be used by the writer.
180:
181: # map for extra information (only for lossy compression mode)
182: int extra_info_type #1: intra type, 2: segment, 3: quant
183: #4: intra-16 prediction mode,
184: #5: chroma prediction mode,
185: #6: bit cost, 7: distortion
186: uint8_t* extra_info #if not NULL, points to an array of size
187: # ((width + 15) / 16) * ((height + 15) / 16) that
188: #will be filled with a macroblock map, depending
189: #on extra_info_type.
190:
191: # STATS AND REPORTS
192: # Pointer to side statistics (updated only if not NULL)
193: WebPAuxStats* stats
194:
195: # Error code for the latest error encountered during encoding
196: WebPEncodingError error_code
197:
198: #If not NULL, report progress during encoding.
199: WebPProgressHook progress_hook
200:
201: void* user_data #this field is free to be set to any value and
202: #used during callbacks (like progress-report e.g.).
203:
204: uint32_t pad3[3] #padding for later use
205:
206: # Unused for now: original samples (for non-YUV420 modes)
207: uint8_t *u0
208: uint8_t *v0
209: int uv0_stride
210:
211: uint32_t pad4[7] #padding for later use
212:
213: # PRIVATE FIELDS
214: void* memory_ #row chunk of memory for yuva planes
215: void* memory_argb_ #and for argb too.
216: void* pad5[2] #padding for later use
217:
218: void WebPMemoryWriterInit(WebPMemoryWriter* writer)
219: int WebPMemoryWrite(const uint8_t* data, size_t data_size, const WebPPicture* picture)
220:
221: int WebPConfigInit(WebPConfig* config)
222: int WebPConfigPreset(WebPConfig* config, WebPPreset preset, float quality)
223: int WebPValidateConfig(const WebPConfig* config)
224: int WebPPictureInit(WebPPicture* picture)
225: void WebPPictureFree(WebPPicture* picture)
226:
227: # Colorspace conversion function to import RGB samples.
228: # Previous buffer will be free'd, if any.
229: # *rgb buffer should have a size of at least height * rgb_stride.
230: # Returns false in case of memory error.
231: int WebPPictureImportRGB(WebPPicture* picture, const uint8_t* rgb, int rgb_stride)
232: # Same, but for RGBA buffer.
233: int WebPPictureImportRGBA(WebPPicture* picture, const uint8_t* rgba, int rgba_stride)
234: # Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format
235: # input buffer ignoring the alpha channel. Avoids needing to copy the data
236: # to a temporary 24-bit RGB buffer to import the RGB only.
237: int WebPPictureImportRGBX(WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride)
238:
239: # Variants of the above, but taking BGR(A|X) input.
240: int WebPPictureImportBGR(WebPPicture* picture, const uint8_t* bgr, int bgr_stride)
241: int WebPPictureImportBGRA(WebPPicture* picture, const uint8_t* bgra, int bgra_stride)
242: int WebPPictureImportBGRX(WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride)
243:
244: # Converts picture->argb data to the YUVA format specified by 'colorspace'.
245: # Upon return, picture->use_argb is set to false. The presence of real
246: # non-opaque transparent values is detected, and 'colorspace' will be
247: # adjusted accordingly. Note that this method is lossy.
248: # Returns false in case of error.
249: int WebPPictureARGBToYUVA(WebPPicture* picture, WebPEncCSP colorspace)
250:
251: # Converts picture->yuv to picture->argb and sets picture->use_argb to true.
252: # The input format must be YUV_420 or YUV_420A.
253: # Note that the use of this method is discouraged if one has access to the
254: # raw ARGB samples, since using YUV420 is comparatively lossy. Also, the
255: # conversion from YUV420 to ARGB incurs a small loss too.
256: # Returns false in case of error.
257: int WebPPictureYUVAToARGB(WebPPicture* picture)
258:
259: # Helper function: given a width x height plane of YUV(A) samples
260: # (with stride 'stride'), clean-up the YUV samples under fully transparent
261: # area, to help compressibility (no guarantee, though).
262: void WebPCleanupTransparentArea(WebPPicture* picture)
263:
264: # Scan the picture 'picture' for the presence of non fully opaque alpha values.
265: # Returns true in such case. Otherwise returns false (indicating that the
266: # alpha plane can be ignored altogether e.g.).
267: int WebPPictureHasTransparency(const WebPPicture* picture)
268:
269: # Main encoding call, after config and picture have been initialized.
270: # 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION),
271: # and the 'config' object must be a valid one.
272: # Returns false in case of error, true otherwise.
273: # In case of error, picture->error_code is updated accordingly.
274: # 'picture' can hold the source samples in both YUV(A) or ARGB input, depending
275: # on the value of 'picture->use_argb'. It is highly recommended to use
276: # the former for lossy encoding, and the latter for lossless encoding
277: # (when config.lossless is true). Automatic conversion from one format to
278: # another is provided but they both incur some loss.
279: int WebPEncode(const WebPConfig* config, WebPPicture* picture)
280:
281:
282: ERROR_TO_NAME = {
283: #VP8_ENC_OK
+284: VP8_ENC_ERROR_OUT_OF_MEMORY : "memory error allocating objects",
__pyx_t_2 = __Pyx_PyDict_NewPresized(10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_OUT_OF_MEMORY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_memory_error_allocating_objects) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+285: VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY : "memory error while flushing bits",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 285, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_memory_error_while_flushing_bits) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+286: VP8_ENC_ERROR_NULL_PARAMETER : "a pointer parameter is NULL",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_NULL_PARAMETER); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_a_pointer_parameter_is_NULL) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+287: VP8_ENC_ERROR_INVALID_CONFIGURATION : "configuration is invalid",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_INVALID_CONFIGURATION); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_configuration_is_invalid) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+288: VP8_ENC_ERROR_BAD_DIMENSION : "picture has invalid width/height",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_BAD_DIMENSION); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_picture_has_invalid_width_height) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+289: VP8_ENC_ERROR_PARTITION0_OVERFLOW : "partition is bigger than 512k",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_PARTITION0_OVERFLOW); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 289, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_partition_is_bigger_than_512k) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+290: VP8_ENC_ERROR_PARTITION_OVERFLOW : "partition is bigger than 16M",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_PARTITION_OVERFLOW); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_partition_is_bigger_than_16M) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+291: VP8_ENC_ERROR_BAD_WRITE : "error while flushing bytes",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_BAD_WRITE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 291, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_error_while_flushing_bytes) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+292: VP8_ENC_ERROR_FILE_TOO_BIG : "file is bigger than 4G",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_FILE_TOO_BIG); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 292, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_file_is_bigger_than_4G) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+293: VP8_ENC_ERROR_USER_ABORT : "abort request by user",
__pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(VP8_ENC_ERROR_USER_ABORT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_kp_s_abort_request_by_user) < 0) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_ERROR_TO_NAME, __pyx_t_2) < 0) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
294: }
295:
296: PRESETS = {
+297: WEBP_PRESET_DEFAULT : "default",
__pyx_t_2 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_DEFAULT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_default) < 0) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+298: WEBP_PRESET_PICTURE : "picture",
__pyx_t_3 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_PICTURE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_picture) < 0) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+299: WEBP_PRESET_PHOTO : "photo",
__pyx_t_3 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_PHOTO); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 299, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_photo) < 0) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+300: WEBP_PRESET_DRAWING : "drawing",
__pyx_t_3 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_DRAWING); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 300, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_drawing) < 0) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+301: WEBP_PRESET_ICON : "icon",
__pyx_t_3 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_ICON); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 301, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_icon) < 0) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+302: WEBP_PRESET_TEXT : "text",
__pyx_t_3 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_TEXT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_text) < 0) __PYX_ERR(0, 297, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_PRESETS, __pyx_t_2) < 0) __PYX_ERR(0, 296, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
303: }
+304: PRESET_NAME_TO_CONSTANT = {}
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 304, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_PRESET_NAME_TO_CONSTANT, __pyx_t_2) < 0) __PYX_ERR(0, 304, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+305: for k,v in PRESETS.items():
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_PRESETS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_items); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_7, function); } } if (__pyx_t_3) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 305, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { __pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 305, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_9)) { if (likely(PyList_CheckExact(__pyx_t_7))) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 305, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 305, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } } else { __pyx_t_2 = __pyx_t_9(__pyx_t_7); if (unlikely(!__pyx_t_2)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 305, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_2); } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; #if !CYTHON_COMPILING_IN_PYPY Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 305, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_3 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_10); #else __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; index = 0; __pyx_t_3 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 305, __pyx_L1_error) __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 305, __pyx_L1_error) __pyx_L7_unpacking_done:; } if (PyDict_SetItem(__pyx_d, __pyx_n_s_k, __pyx_t_3) < 0) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_v, __pyx_t_10) < 0) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; /* … */ } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+306: PRESET_NAME_TO_CONSTANT[v] = k
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_k); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_PRESET_NAME_TO_CONSTANT); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (unlikely(PyObject_SetItem(__pyx_t_10, __pyx_t_3, __pyx_t_2) < 0)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
307:
308: IMAGE_HINT = {
+309: WEBP_HINT_DEFAULT : "default",
__pyx_t_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __Pyx_PyInt_From_WebPImageHint(WEBP_HINT_DEFAULT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_7, __pyx_t_2, __pyx_n_s_default) < 0) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+310: WEBP_HINT_PICTURE : "picture",
__pyx_t_2 = __Pyx_PyInt_From_WebPImageHint(WEBP_HINT_PICTURE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_7, __pyx_t_2, __pyx_n_s_picture) < 0) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+311: WEBP_HINT_PHOTO : "photo",
__pyx_t_2 = __Pyx_PyInt_From_WebPImageHint(WEBP_HINT_PHOTO); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 311, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_7, __pyx_t_2, __pyx_n_s_photo) < 0) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+312: WEBP_HINT_GRAPH : "graph",
__pyx_t_2 = __Pyx_PyInt_From_WebPImageHint(WEBP_HINT_GRAPH); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_7, __pyx_t_2, __pyx_n_s_graph) < 0) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_IMAGE_HINT, __pyx_t_7) < 0) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
313: }
+314: HINT_NAME_TO_CONSTANT = {}
__pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (PyDict_SetItem(__pyx_d, __pyx_n_s_HINT_NAME_TO_CONSTANT, __pyx_t_7) < 0) __PYX_ERR(0, 314, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+315: for k,v in IMAGE_HINT.items():
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_IMAGE_HINT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (__pyx_t_2) { __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 315, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { __pyx_t_3 = __pyx_t_7; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 315, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; for (;;) { if (likely(!__pyx_t_9)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 315, __pyx_L1_error) #else __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } else { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 315, __pyx_L1_error) #else __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } } else { __pyx_t_7 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_7)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 315, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_7); } if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { PyObject* sequence = __pyx_t_7; #if !CYTHON_COMPILING_IN_PYPY Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 315, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_2 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_10); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); #endif __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else { Py_ssize_t index = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L10_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L10_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 315, __pyx_L1_error) __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; goto __pyx_L11_unpacking_done; __pyx_L10_unpacking_failed:; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_12 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 315, __pyx_L1_error) __pyx_L11_unpacking_done:; } if (PyDict_SetItem(__pyx_d, __pyx_n_s_k, __pyx_t_2) < 0) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_v, __pyx_t_10) < 0) __PYX_ERR(0, 315, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; /* … */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+316: HINT_NAME_TO_CONSTANT[v] = k
__pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_k); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 316, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_HINT_NAME_TO_CONSTANT); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 316, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_v); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 316, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (unlikely(PyObject_SetItem(__pyx_t_10, __pyx_t_2, __pyx_t_7) < 0)) __PYX_ERR(0, 316, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
317:
+318: cdef WebPImageHint DEFAULT_IMAGE_HINT = HINT_NAME_TO_CONSTANT.get(os.environ.get("XPRA_WEBP_IMAGE_HINT", "graph").lower(), WEBP_HINT_GRAPH)
__pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_HINT_NAME_TO_CONSTANT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_environ); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_get); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_lower); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_10, function); } } if (__pyx_t_11) { __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } else { __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyInt_From_WebPImageHint(WEBP_HINT_GRAPH); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = NULL; __pyx_t_4 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_4 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_7, __pyx_t_10}; __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_7, __pyx_t_10}; __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif { __pyx_t_13 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); if (__pyx_t_11) { __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; } __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_4, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_4, __pyx_t_10); __pyx_t_7 = 0; __pyx_t_10 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_14 = __Pyx_PyInt_As_WebPImageHint(__pyx_t_3); if (unlikely((__pyx_t_14 == ((WebPImageHint)-1)) && PyErr_Occurred())) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_4xpra_6codecs_4webp_6encode_DEFAULT_IMAGE_HINT = __pyx_t_14; /* … */ __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_XPRA_WEBP_IMAGE_HINT, __pyx_n_s_graph); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__11); __Pyx_GIVEREF(__pyx_tuple__11);
+319: cdef WebPPreset DEFAULT_PRESET = PRESET_NAME_TO_CONSTANT.get(os.environ.get("XPRA_WEBP_PRESET", "text").lower(), WEBP_PRESET_TEXT)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_PRESET_NAME_TO_CONSTANT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_environ); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_lower); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_10, function); } } if (__pyx_t_7) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 319, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_TEXT); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_7 = NULL; __pyx_t_4 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_13, function); __pyx_t_4 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_13)) { PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_2, __pyx_t_10}; __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_2, __pyx_t_10}; __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif { __pyx_t_11 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); if (__pyx_t_7) { __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_7); __pyx_t_7 = NULL; } __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_4, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_4, __pyx_t_10); __pyx_t_2 = 0; __pyx_t_10 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_15 = __Pyx_PyInt_As_WebPPreset(__pyx_t_3); if (unlikely((__pyx_t_15 == ((WebPPreset)-1)) && PyErr_Occurred())) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_4xpra_6codecs_4webp_6encode_DEFAULT_PRESET = __pyx_t_15; /* … */ __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_XPRA_WEBP_PRESET, __pyx_n_s_text); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12);
+320: cdef WebPPreset PRESET_SMALL = PRESET_NAME_TO_CONSTANT.get(os.environ.get("XPRA_WEBP_PRESET_SMALL", "icon").lower(), WEBP_PRESET_ICON)
__pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_PRESET_NAME_TO_CONSTANT); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_get); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_environ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_lower); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_10); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_10, function); } } if (__pyx_t_2) { __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 320, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyInt_From_WebPPreset(WEBP_PRESET_ICON); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_2 = NULL; __pyx_t_4 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_11); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_11, function); __pyx_t_4 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_11)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_13, __pyx_t_10}; __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_13, __pyx_t_10}; __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif { __pyx_t_7 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_2) { __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; } __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_4, __pyx_t_13); __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_4, __pyx_t_10); __pyx_t_13 = 0; __pyx_t_10 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_15 = __Pyx_PyInt_As_WebPPreset(__pyx_t_3); if (unlikely((__pyx_t_15 == ((WebPPreset)-1)) && PyErr_Occurred())) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_4xpra_6codecs_4webp_6encode_PRESET_SMALL = __pyx_t_15; /* … */ __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_XPRA_WEBP_PRESET_SMALL, __pyx_n_s_icon); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 320, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__13); __Pyx_GIVEREF(__pyx_tuple__13);
321:
322:
+323: def get_encodings():
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_1get_encodings(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_4webp_6encode_1get_encodings = {"get_encodings", (PyCFunction)__pyx_pw_4xpra_6codecs_4webp_6encode_1get_encodings, METH_NOARGS, 0}; static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_1get_encodings(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_encodings (wrapper)", 0); __pyx_r = __pyx_pf_4xpra_6codecs_4webp_6encode_get_encodings(__pyx_self); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_4webp_6encode_get_encodings(CYTHON_UNUSED PyObject *__pyx_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_encodings", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("xpra.codecs.webp.encode.get_encodings", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_4webp_6encode_1get_encodings, NULL, __pyx_n_s_xpra_codecs_webp_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_encodings, __pyx_t_3) < 0) __PYX_ERR(0, 323, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_xpra_codecs_webp_encode_pyx, __pyx_n_s_get_encodings, 323, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 323, __pyx_L1_error)
+324: return ["webp"]
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 324, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_webp); __Pyx_GIVEREF(__pyx_n_s_webp); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_webp); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
325:
+326: def get_version():
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_3get_version(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_4webp_6encode_3get_version = {"get_version", (PyCFunction)__pyx_pw_4xpra_6codecs_4webp_6encode_3get_version, METH_NOARGS, 0}; static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_3get_version(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_version (wrapper)", 0); __pyx_r = __pyx_pf_4xpra_6codecs_4webp_6encode_2get_version(__pyx_self); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_4webp_6encode_2get_version(CYTHON_UNUSED PyObject *__pyx_self) { int __pyx_v_version; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_version", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("xpra.codecs.webp.encode.get_version", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__15 = PyTuple_Pack(1, __pyx_n_s_version); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 326, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__15); __Pyx_GIVEREF(__pyx_tuple__15); /* … */ __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_4webp_6encode_3get_version, NULL, __pyx_n_s_xpra_codecs_webp_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_version, __pyx_t_3) < 0) __PYX_ERR(0, 326, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_xpra_codecs_webp_encode_pyx, __pyx_n_s_get_version, 326, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 326, __pyx_L1_error)
+327: cdef int version = WebPGetEncoderVersion()
__pyx_v_version = WebPGetEncoderVersion();
+328: log("WebPGetEncoderVersion()=%#x", version)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_version); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; __pyx_t_5 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_5 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_s_WebPGetEncoderVersion_x, __pyx_t_3}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_s_WebPGetEncoderVersion_x, __pyx_t_3}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__pyx_t_4) { __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; } __Pyx_INCREF(__pyx_kp_s_WebPGetEncoderVersion_x); __Pyx_GIVEREF(__pyx_kp_s_WebPGetEncoderVersion_x); PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_kp_s_WebPGetEncoderVersion_x); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+329: return (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_long(((__pyx_v_version >> 16) & 0xff)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_version >> 8) & 0xff)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_v_version & 0xff)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_6); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_6 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
330:
+331: def get_info():
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_5get_info(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_4webp_6encode_5get_info = {"get_info", (PyCFunction)__pyx_pw_4xpra_6codecs_4webp_6encode_5get_info, METH_NOARGS, 0}; static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_5get_info(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_info (wrapper)", 0); __pyx_r = __pyx_pf_4xpra_6codecs_4webp_6encode_4get_info(__pyx_self); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_4webp_6encode_4get_info(CYTHON_UNUSED PyObject *__pyx_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_info", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("xpra.codecs.webp.encode.get_info", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_4webp_6encode_5get_info, NULL, __pyx_n_s_xpra_codecs_webp_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 331, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_info, __pyx_t_3) < 0) __PYX_ERR(0, 331, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_xpra_codecs_webp_encode_pyx, __pyx_n_s_get_info, 331, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 331, __pyx_L1_error)
+332: return {
__Pyx_XDECREF(__pyx_r);
+333: "version" : get_version(),
__pyx_t_1 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_version); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (__pyx_t_4) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_version, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+334: "encodings" : get_encodings(),
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_encodings); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (__pyx_t_4) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_encodings, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+335: "threading" : bool(WEBP_THREADING),
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_4xpra_6codecs_4webp_6encode_WEBP_THREADING); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 335, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyBool_FromLong((!(!__pyx_t_5))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_threading, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+336: "image-hint" : DEFAULT_IMAGE_HINT,
__pyx_t_2 = __Pyx_PyInt_From_WebPImageHint(__pyx_v_4xpra_6codecs_4webp_6encode_DEFAULT_IMAGE_HINT); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 336, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_kp_s_image_hint, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+337: "image-hints" : IMAGE_HINT.values(),
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_IMAGE_HINT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 337, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } if (__pyx_t_3) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_1, __pyx_kp_s_image_hints, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+338: "preset" : DEFAULT_PRESET,
__pyx_t_2 = __Pyx_PyInt_From_WebPPreset(__pyx_v_4xpra_6codecs_4webp_6encode_DEFAULT_PRESET); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_preset, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+339: "preset-small" : PRESET_SMALL,
__pyx_t_2 = __Pyx_PyInt_From_WebPPreset(__pyx_v_4xpra_6codecs_4webp_6encode_PRESET_SMALL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_kp_s_preset_small, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+340: "presets" : PRESETS.values(),
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_PRESETS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 340, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (__pyx_t_4) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_presets, __pyx_t_2) < 0) __PYX_ERR(0, 333, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
341: }
342:
+343: def webp_check(int ret):
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_7webp_check(PyObject *__pyx_self, PyObject *__pyx_arg_ret); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_4webp_6encode_7webp_check = {"webp_check", (PyCFunction)__pyx_pw_4xpra_6codecs_4webp_6encode_7webp_check, METH_O, 0}; static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_7webp_check(PyObject *__pyx_self, PyObject *__pyx_arg_ret) { int __pyx_v_ret; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("webp_check (wrapper)", 0); assert(__pyx_arg_ret); { __pyx_v_ret = __Pyx_PyInt_As_int(__pyx_arg_ret); if (unlikely((__pyx_v_ret == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 343, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("xpra.codecs.webp.encode.webp_check", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4xpra_6codecs_4webp_6encode_6webp_check(__pyx_self, ((int)__pyx_v_ret)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_4webp_6encode_6webp_check(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_ret) { PyObject *__pyx_v_err = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("webp_check", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("xpra.codecs.webp.encode.webp_check", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_err); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__18 = PyTuple_Pack(3, __pyx_n_s_ret, __pyx_n_s_ret, __pyx_n_s_err); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__18); __Pyx_GIVEREF(__pyx_tuple__18); /* … */ __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_4webp_6encode_7webp_check, NULL, __pyx_n_s_xpra_codecs_webp_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_webp_check, __pyx_t_3) < 0) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_xpra_codecs_webp_encode_pyx, __pyx_n_s_webp_check, 343, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 343, __pyx_L1_error)
+344: if ret==0:
__pyx_t_1 = ((__pyx_v_ret == 0) != 0); if (__pyx_t_1) { /* … */ }
+345: return
__Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0;
+346: err = ERROR_TO_NAME.get(ret, ret)
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_ERROR_TO_NAME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; __pyx_t_7 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_7 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5}; __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5}; __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (__pyx_t_6) { __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; } __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_err = __pyx_t_2; __pyx_t_2 = 0;
+347: raise Exception("error: %s" % err)
__pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_error_s, __pyx_v_err); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 347, __pyx_L1_error)
348:
+349: cdef float fclamp(int v):
static float __pyx_f_4xpra_6codecs_4webp_6encode_fclamp(int __pyx_v_v) { float __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fclamp", 0); /* … */ /* function exit code */ __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; }
+350: if v<0:
__pyx_t_1 = ((__pyx_v_v < 0) != 0); if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+351: v = 0
__pyx_v_v = 0;
+352: elif v>100:
__pyx_t_1 = ((__pyx_v_v > 0x64) != 0); if (__pyx_t_1) { /* … */ } __pyx_L3:;
+353: v = 100
__pyx_v_v = 0x64;
+354: return <float> v
__pyx_r = ((float)__pyx_v_v); goto __pyx_L0;
355:
356:
+357: cdef get_config_info(WebPConfig *config):
static PyObject *__pyx_f_4xpra_6codecs_4webp_6encode_get_config_info(WebPConfig *__pyx_v_config) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_config_info", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("xpra.codecs.webp.encode.get_config_info", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+358: return {
__Pyx_XDECREF(__pyx_r);
+359: "lossless" : config.lossless,
__pyx_t_1 = __Pyx_PyDict_NewPresized(22); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->lossless); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_lossless, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+360: "method" : config.method,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->method); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_method, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+361: "image_hint" : IMAGE_HINT.get(config.image_hint, config.image_hint),
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_IMAGE_HINT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyInt_From_WebPImageHint(__pyx_v_config->image_hint); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyInt_From_WebPImageHint(__pyx_v_config->image_hint); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; __pyx_t_7 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_7 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5}; __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5}; __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (__pyx_t_6) { __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; } __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_image_hint_2, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+362: "target_size" : config.target_size,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->target_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_target_size, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+363: "target_PSNR" : config.target_PSNR,
__pyx_t_2 = PyFloat_FromDouble(__pyx_v_config->target_PSNR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_target_PSNR, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+364: "segments" : config.segments,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->segments); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 364, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_segments, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+365: "sns_strength" : config.sns_strength,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->sns_strength); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_sns_strength, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+366: "filter_strength" : config.filter_strength,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->filter_strength); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_filter_strength, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+367: "filter_sharpness" : config.filter_sharpness,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->filter_sharpness); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_filter_sharpness, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+368: "filter_type" : config.filter_type,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->filter_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_filter_type, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+369: "autofilter" : config.autofilter,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->autofilter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_autofilter, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+370: "alpha_compression" : config.alpha_compression,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->alpha_compression); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 370, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_alpha_compression, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+371: "alpha_filtering" : config.alpha_filtering,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->alpha_filtering); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_alpha_filtering, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+372: "alpha_quality" : config.alpha_quality,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->alpha_quality); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_alpha_quality, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+373: "pass" : config._pass,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->pass); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pass, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+374: "show_compressed" : config.show_compressed,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->show_compressed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_show_compressed, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+375: "preprocessing" : config.preprocessing,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->preprocessing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_preprocessing, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+376: "partitions" : config.partitions,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->partitions); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_partitions, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+377: "partition_limit" : config.partition_limit,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->partition_limit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_partition_limit, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+378: "emulate_jpeg_size" : config.emulate_jpeg_size,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->emulate_jpeg_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 378, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_emulate_jpeg_size, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+379: "thread_level" : config.thread_level,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->thread_level); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_thread_level, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+380: "low_memory" : config.low_memory,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config->low_memory); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_low_memory, __pyx_t_2) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
381: }
382:
+383: def compress(image, int quality=50, int speed=50, supports_alpha=False):
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_9compress(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_4webp_6encode_9compress = {"compress", (PyCFunction)__pyx_pw_4xpra_6codecs_4webp_6encode_9compress, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_9compress(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_image = 0; int __pyx_v_quality; int __pyx_v_speed; PyObject *__pyx_v_supports_alpha = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("compress (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_image,&__pyx_n_s_quality,&__pyx_n_s_speed,&__pyx_n_s_supports_alpha,0}; PyObject* values[4] = {0,0,0,0}; values[3] = ((PyObject *)Py_False); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_image)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quality); if (value) { values[1] = value; kw_args--; } } CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_speed); if (value) { values[2] = value; kw_args--; } } CYTHON_FALLTHROUGH; case 3: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_supports_alpha); if (value) { values[3] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "compress") < 0)) __PYX_ERR(0, 383, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_image = values[0]; if (values[1]) { __pyx_v_quality = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_quality == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 383, __pyx_L3_error) } else { __pyx_v_quality = ((int)50); } if (values[2]) { __pyx_v_speed = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_speed == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 383, __pyx_L3_error) } else { __pyx_v_speed = ((int)50); } __pyx_v_supports_alpha = values[3]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("compress", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 383, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("xpra.codecs.webp.encode.compress", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4xpra_6codecs_4webp_6encode_8compress(__pyx_self, __pyx_v_image, __pyx_v_quality, __pyx_v_speed, __pyx_v_supports_alpha); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_4webp_6encode_8compress(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_image, int __pyx_v_quality, int __pyx_v_speed, PyObject *__pyx_v_supports_alpha) { PyObject *__pyx_v_pixel_format = NULL; unsigned int __pyx_v_width; unsigned int __pyx_v_height; unsigned int __pyx_v_stride; unsigned int __pyx_v_Bpp; PyObject *__pyx_v_pixels = NULL; uint8_t *__pyx_v_pic_buf; Py_ssize_t __pyx_v_pic_buf_len; WebPConfig __pyx_v_config; WebPPreset __pyx_v_preset; int __pyx_v_ret; int __pyx_v_size; int __pyx_v_i; int __pyx_v_alpha_int; PyObject *__pyx_v_info = NULL; WebPPicture __pyx_v_pic; WebPMemoryWriter __pyx_v_memory_writer; PyObject *__pyx_v_cdata = NULL; PyObject *__pyx_v_client_options = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("compress", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_12); __Pyx_XDECREF(__pyx_t_13); __Pyx_XDECREF(__pyx_t_14); __Pyx_XDECREF(__pyx_t_15); __Pyx_AddTraceback("xpra.codecs.webp.encode.compress", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_pixel_format); __Pyx_XDECREF(__pyx_v_pixels); __Pyx_XDECREF(__pyx_v_info); __Pyx_XDECREF(__pyx_v_cdata); __Pyx_XDECREF(__pyx_v_client_options); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__20 = PyTuple_Pack(23, __pyx_n_s_image, __pyx_n_s_quality, __pyx_n_s_speed, __pyx_n_s_supports_alpha, __pyx_n_s_pixel_format, __pyx_n_s_width, __pyx_n_s_height, __pyx_n_s_stride, __pyx_n_s_Bpp, __pyx_n_s_pixels, __pyx_n_s_pic_buf, __pyx_n_s_pic_buf_len, __pyx_n_s_config, __pyx_n_s_preset, __pyx_n_s_ret, __pyx_n_s_size, __pyx_n_s_i, __pyx_n_s_alpha_int, __pyx_n_s_info, __pyx_n_s_pic, __pyx_n_s_memory_writer, __pyx_n_s_cdata, __pyx_n_s_client_options); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__20); __Pyx_GIVEREF(__pyx_tuple__20); /* … */ __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_4webp_6encode_9compress, NULL, __pyx_n_s_xpra_codecs_webp_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_compress, __pyx_t_3) < 0) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(4, 0, 23, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_xpra_codecs_webp_encode_pyx, __pyx_n_s_compress, 383, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 383, __pyx_L1_error)
+384: pixel_format = image.get_pixel_format()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_image, __pyx_n_s_get_pixel_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_pixel_format = __pyx_t_1; __pyx_t_1 = 0;
+385: if pixel_format not in ("RGBX", "RGBA", "BGRX", "BGRA"):
__Pyx_INCREF(__pyx_v_pixel_format); __pyx_t_1 = __pyx_v_pixel_format; __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_RGBX, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 385, __pyx_L1_error) if (__pyx_t_5) { } else { __pyx_t_4 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_RGBA, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 385, __pyx_L1_error) if (__pyx_t_5) { } else { __pyx_t_4 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_BGRX, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 385, __pyx_L1_error) if (__pyx_t_5) { } else { __pyx_t_4 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_BGRA, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 385, __pyx_L1_error) __pyx_t_4 = __pyx_t_5; __pyx_L4_bool_binop_done:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { /* … */ }
+386: raise Exception("unsupported pixel format %s" % pixel_format)
__pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_unsupported_pixel_format_s, __pyx_v_pixel_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 386, __pyx_L1_error)
+387: cdef unsigned int width = image.get_width()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_image, __pyx_n_s_get_width); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 387, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 387, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 387, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 387, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_width = __pyx_t_6;
+388: cdef unsigned int height = image.get_height()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_image, __pyx_n_s_get_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 388, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 388, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_height = __pyx_t_6;
+389: cdef unsigned int stride = image.get_rowstride()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_image, __pyx_n_s_get_rowstride); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_stride = __pyx_t_6;
+390: cdef unsigned int Bpp = len(pixel_format)
__pyx_t_7 = PyObject_Length(__pyx_v_pixel_format); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 390, __pyx_L1_error) __pyx_v_Bpp = __pyx_t_7;
+391: pixels = image.get_pixels()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_image, __pyx_n_s_get_pixels); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_pixels = __pyx_t_1; __pyx_t_1 = 0;
392:
393: cdef uint8_t *pic_buf
+394: cdef Py_ssize_t pic_buf_len = 0
__pyx_v_pic_buf_len = 0;
395: cdef WebPConfig config
+396: cdef WebPPreset preset = DEFAULT_PRESET
__pyx_v_preset = __pyx_v_4xpra_6codecs_4webp_6encode_DEFAULT_PRESET;
+397: if width*height<8192:
__pyx_t_5 = (((__pyx_v_width * __pyx_v_height) < 0x2000) != 0); if (__pyx_t_5) { /* … */ }
+398: preset = PRESET_SMALL
__pyx_v_preset = __pyx_v_4xpra_6codecs_4webp_6encode_PRESET_SMALL;
+399: if width>WEBP_MAX_DIMENSION or height>WEBP_MAX_DIMENSION:
__pyx_t_4 = ((__pyx_v_width > 0x3FFF) != 0); if (!__pyx_t_4) { } else { __pyx_t_5 = __pyx_t_4; goto __pyx_L10_bool_binop_done; } __pyx_t_4 = ((__pyx_v_height > 0x3FFF) != 0); __pyx_t_5 = __pyx_t_4; __pyx_L10_bool_binop_done:; if (__pyx_t_5) { /* … */ }
+400: raise Exception("this image is too big for webp: %ix%i" % (width, height))
__pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_width); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_unsigned_int(__pyx_v_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_this_image_is_too_big_for_webp_i, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 400, __pyx_L1_error)
401:
+402: cdef int ret = object_as_buffer(pixels, <const void**> &pic_buf, &pic_buf_len)
__pyx_v_ret = __pyx_f_4xpra_7buffers_6membuf_object_as_buffer(__pyx_v_pixels, ((void const **)(&__pyx_v_pic_buf)), (&__pyx_v_pic_buf_len));
+403: assert ret==0, "failed to get buffer from pixel object: %s (returned %s)" % (type(pixels), ret)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_ret == 0) != 0))) { __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_pixels))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_pixels))); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(__pyx_v_pixels))); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_failed_to_get_buffer_from_pixel, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 403, __pyx_L1_error) } } #endif
+404: log("webp.compress(%s, %i, %i, %s) buf=%#x", image, width, height, supports_alpha, <uintptr_t> pic_buf)
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __Pyx_PyInt_From_unsigned_int(__pyx_v_width); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __Pyx_PyInt_From_unsigned_int(__pyx_v_height); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyInt_FromSize_t(((uintptr_t)__pyx_v_pic_buf)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = NULL; __pyx_t_11 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_11 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[7] = {__pyx_t_10, __pyx_kp_s_webp_compress_s_i_i_s_buf_x, __pyx_v_image, __pyx_t_1, __pyx_t_8, __pyx_v_supports_alpha, __pyx_t_9}; __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 6+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[7] = {__pyx_t_10, __pyx_kp_s_webp_compress_s_i_i_s_buf_x, __pyx_v_image, __pyx_t_1, __pyx_t_8, __pyx_v_supports_alpha, __pyx_t_9}; __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 6+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else #endif { __pyx_t_12 = PyTuple_New(6+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); if (__pyx_t_10) { __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; } __Pyx_INCREF(__pyx_kp_s_webp_compress_s_i_i_s_buf_x); __Pyx_GIVEREF(__pyx_kp_s_webp_compress_s_i_i_s_buf_x); PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_kp_s_webp_compress_s_i_i_s_buf_x); __Pyx_INCREF(__pyx_v_image); __Pyx_GIVEREF(__pyx_v_image); PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_v_image); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_11, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_11, __pyx_t_8); __Pyx_INCREF(__pyx_v_supports_alpha); __Pyx_GIVEREF(__pyx_v_supports_alpha); PyTuple_SET_ITEM(__pyx_t_12, 4+__pyx_t_11, __pyx_v_supports_alpha); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_12, 5+__pyx_t_11, __pyx_t_9); __pyx_t_1 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+405: cdef int size = stride * height
__pyx_v_size = (__pyx_v_stride * __pyx_v_height);
+406: assert pic_buf_len>=size, "pixel buffer is too small: expected at least %s bytes but got %s" % (size, pic_buf_len)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_pic_buf_len >= __pyx_v_size) != 0))) { __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_pic_buf_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_pixel_buffer_is_too_small_expect, __pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(0, 406, __pyx_L1_error) } } #endif
407:
408: cdef int i
+409: cdef int alpha_int = int(supports_alpha and pixel_format.find("A")>=0)
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_supports_alpha); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 409, __pyx_L1_error) if (__pyx_t_5) { } else { __Pyx_INCREF(__pyx_v_supports_alpha); __pyx_t_3 = __pyx_v_supports_alpha; goto __pyx_L12_bool_binop_done; } __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_pixel_format, __pyx_n_s_find); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_12 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_t_12); __pyx_t_3 = __pyx_t_12; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_L12_bool_binop_done:; __pyx_t_12 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_12); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_v_alpha_int = __pyx_t_11; /* … */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_n_s_A); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_);
+410: if alpha_int==0 and Bpp==4:
__pyx_t_4 = ((__pyx_v_alpha_int == 0) != 0); if (__pyx_t_4) { } else { __pyx_t_5 = __pyx_t_4; goto __pyx_L15_bool_binop_done; } __pyx_t_4 = ((__pyx_v_Bpp == 4) != 0); __pyx_t_5 = __pyx_t_4; __pyx_L15_bool_binop_done:; if (__pyx_t_5) { /* … */ }
411: #ensure webp will not decide to encode the alpha channel
412: #(this is stupid: we should be able to pass a flag instead)
+413: i = 3
__pyx_v_i = 3;
+414: while i<size:
while (1) { __pyx_t_5 = ((__pyx_v_i < __pyx_v_size) != 0); if (!__pyx_t_5) break;
+415: pic_buf[i] = 0xff
(__pyx_v_pic_buf[__pyx_v_i]) = 0xff;
+416: i += Bpp
__pyx_v_i = (__pyx_v_i + __pyx_v_Bpp); }
417:
+418: ret = WebPConfigInit(&config)
__pyx_v_ret = WebPConfigInit((&__pyx_v_config));
+419: if not ret:
__pyx_t_5 = ((!(__pyx_v_ret != 0)) != 0); if (__pyx_t_5) { /* … */ }
+420: raise Exception("failed to initialize webp config")
__pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 420, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_Raise(__pyx_t_12, 0, 0, 0); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __PYX_ERR(0, 420, __pyx_L1_error) /* … */ __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_failed_to_initialize_webp_config); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 420, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2);
421:
+422: ret = WebPConfigPreset(&config, preset, fclamp(quality))
__pyx_v_ret = WebPConfigPreset((&__pyx_v_config), __pyx_v_preset, __pyx_f_4xpra_6codecs_4webp_6encode_fclamp(__pyx_v_quality));
+423: if not ret:
__pyx_t_5 = ((!(__pyx_v_ret != 0)) != 0); if (__pyx_t_5) { /* … */ }
+424: raise Exception("failed to set webp preset")
__pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_Raise(__pyx_t_12, 0, 0, 0); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __PYX_ERR(0, 424, __pyx_L1_error) /* … */ __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_failed_to_set_webp_preset); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 424, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3);
425:
426: #tune it:
+427: config.lossless = quality>=LOSSLESS_THRESHOLD
__pyx_v_config.lossless = (__pyx_v_quality >= __pyx_v_4xpra_6codecs_4webp_6encode_LOSSLESS_THRESHOLD);
+428: if config.lossless:
__pyx_t_5 = (__pyx_v_config.lossless != 0); if (__pyx_t_5) { /* … */ goto __pyx_L21; }
429: #not much to gain from setting a high quality here,
430: #the latency will be higher for a negligible compression gain:
+431: config.quality = fclamp(50-speed//2)
__pyx_v_config.quality = __pyx_f_4xpra_6codecs_4webp_6encode_fclamp((50 - __Pyx_div_long(__pyx_v_speed, 2)));
432: else:
+433: config.quality = fclamp(quality)
/*else*/ { __pyx_v_config.quality = __pyx_f_4xpra_6codecs_4webp_6encode_fclamp(__pyx_v_quality); } __pyx_L21:;
434: #"method" takes values from 0 to 6,
435: #but anything higher than 1 is dreadfully slow,
436: #so only use method=1 when speed is already very low
+437: config.method = int(speed<10)
__pyx_v_config.method = ((int)(__pyx_v_speed < 10));
+438: config.alpha_compression = alpha_int
__pyx_v_config.alpha_compression = __pyx_v_alpha_int;
+439: config.alpha_filtering = MAX(0, MIN(2, speed/50)) * alpha_int
__pyx_v_config.alpha_filtering = (__pyx_f_4xpra_6codecs_4webp_6encode_MAX(0, __pyx_f_4xpra_6codecs_4webp_6encode_MIN(2, __Pyx_div_long(__pyx_v_speed, 50))) * __pyx_v_alpha_int);
+440: config.alpha_quality = quality * alpha_int
__pyx_v_config.alpha_quality = (__pyx_v_quality * __pyx_v_alpha_int);
+441: if config.lossless:
__pyx_t_5 = (__pyx_v_config.lossless != 0); if (__pyx_t_5) { /* … */ goto __pyx_L22; }
+442: config.autofilter = 1
__pyx_v_config.autofilter = 1;
443: else:
+444: config.segments = 1
/*else*/ { __pyx_v_config.segments = 1;
+445: config.sns_strength = 0
__pyx_v_config.sns_strength = 0;
+446: config.filter_strength = 0
__pyx_v_config.filter_strength = 0;
+447: config.filter_sharpness = 7-quality//15
__pyx_v_config.filter_sharpness = (7 - __Pyx_div_long(__pyx_v_quality, 15));
+448: config.filter_type = 0
__pyx_v_config.filter_type = 0;
+449: config.autofilter = 0
__pyx_v_config.autofilter = 0; } __pyx_L22:;
+450: config._pass = MAX(1, MIN(10, (100-speed)//10))
__pyx_v_config.pass = __pyx_f_4xpra_6codecs_4webp_6encode_MAX(1, __pyx_f_4xpra_6codecs_4webp_6encode_MIN(10, __Pyx_div_long((0x64 - __pyx_v_speed), 10)));
+451: config.preprocessing = int(speed<50)
__pyx_v_config.preprocessing = ((int)(__pyx_v_speed < 50));
+452: config.image_hint = DEFAULT_IMAGE_HINT
__pyx_v_config.image_hint = __pyx_v_4xpra_6codecs_4webp_6encode_DEFAULT_IMAGE_HINT;
+453: config.thread_level = WEBP_THREADING
__pyx_v_config.thread_level = __pyx_v_4xpra_6codecs_4webp_6encode_WEBP_THREADING;
+454: config.partitions = 3
__pyx_v_config.partitions = 3;
+455: config.partition_limit = MAX(0, MIN(100, 100-quality))
__pyx_v_config.partition_limit = __pyx_f_4xpra_6codecs_4webp_6encode_MAX(0, __pyx_f_4xpra_6codecs_4webp_6encode_MIN(0x64, (0x64 - __pyx_v_quality)));
456:
+457: log("webp.compress config: lossless=%s, quality=%s, method=%s, alpha=%s,%s,%s", config.lossless, config.quality, config.method,
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_config.lossless); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PyFloat_FromDouble(__pyx_v_config.quality); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_config.method); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8);
+458: config.alpha_compression, config.alpha_filtering, config.alpha_quality)
__pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_config.alpha_compression); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 458, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_config.alpha_filtering); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 458, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_config.alpha_quality); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 458, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_14 = NULL; __pyx_t_11 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_14)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_14); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_11 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[8] = {__pyx_t_14, __pyx_kp_s_webp_compress_config_lossless_s, __pyx_t_2, __pyx_t_9, __pyx_t_8, __pyx_t_1, __pyx_t_10, __pyx_t_13}; __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 7+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[8] = {__pyx_t_14, __pyx_kp_s_webp_compress_config_lossless_s, __pyx_t_2, __pyx_t_9, __pyx_t_8, __pyx_t_1, __pyx_t_10, __pyx_t_13}; __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 7+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } else #endif { __pyx_t_15 = PyTuple_New(7+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); if (__pyx_t_14) { __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL; } __Pyx_INCREF(__pyx_kp_s_webp_compress_config_lossless_s); __Pyx_GIVEREF(__pyx_kp_s_webp_compress_config_lossless_s); PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_11, __pyx_kp_s_webp_compress_config_lossless_s); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_11, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 2+__pyx_t_11, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_15, 3+__pyx_t_11, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_15, 4+__pyx_t_11, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_15, 5+__pyx_t_11, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 6+__pyx_t_11, __pyx_t_13); __pyx_t_2 = 0; __pyx_t_9 = 0; __pyx_t_8 = 0; __pyx_t_1 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+459: ret = WebPValidateConfig(&config)
__pyx_v_ret = WebPValidateConfig((&__pyx_v_config));
+460: if not ret:
__pyx_t_5 = ((!(__pyx_v_ret != 0)) != 0); if (__pyx_t_5) { /* … */ }
+461: info = get_config_info(&config)
__pyx_t_12 = __pyx_f_4xpra_6codecs_4webp_6encode_get_config_info((&__pyx_v_config)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_v_info = __pyx_t_12; __pyx_t_12 = 0;
+462: raise Exception("invalid webp configuration: %s" % info)
__pyx_t_12 = __Pyx_PyString_Format(__pyx_kp_s_invalid_webp_configuration_s, __pyx_v_info); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 462, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_12); __pyx_t_12 = 0; __pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_t_3, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_12, 0, 0, 0); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __PYX_ERR(0, 462, __pyx_L1_error)
463:
464: cdef WebPPicture pic
+465: ret = WebPPictureInit(&pic)
__pyx_v_ret = WebPPictureInit((&__pyx_v_pic));
+466: if not ret:
__pyx_t_5 = ((!(__pyx_v_ret != 0)) != 0); if (__pyx_t_5) { /* … */ }
+467: raise Exception("failed to initialise webp picture")
__pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 467, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_Raise(__pyx_t_12, 0, 0, 0); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __PYX_ERR(0, 467, __pyx_L1_error) /* … */ __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_failed_to_initialise_webp_pictur); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 467, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4);
468:
469: #TODO: custom writer that over-allocates memory
470: cdef WebPMemoryWriter memory_writer
+471: WebPMemoryWriterInit(&memory_writer)
WebPMemoryWriterInit((&__pyx_v_memory_writer));
472:
+473: memset(&pic, 0, sizeof(WebPPicture))
memset((&__pyx_v_pic), 0, (sizeof(WebPPicture)));
+474: pic.width = width
__pyx_v_pic.width = __pyx_v_width;
+475: pic.height = height
__pyx_v_pic.height = __pyx_v_height;
+476: pic.use_argb = 1
__pyx_v_pic.use_argb = 1;
+477: pic.argb = <uint32_t*> pic_buf
__pyx_v_pic.argb = ((uint32_t *)__pyx_v_pic_buf);
+478: pic.argb_stride = stride//Bpp
if (unlikely(__pyx_v_Bpp == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); __PYX_ERR(0, 478, __pyx_L1_error) } __pyx_v_pic.argb_stride = (__pyx_v_stride / __pyx_v_Bpp);
+479: pic.writer = <WebPWriterFunction> WebPMemoryWrite
__pyx_v_pic.writer = ((WebPWriterFunction)WebPMemoryWrite);
+480: pic.custom_ptr = <void*> &memory_writer
__pyx_v_pic.custom_ptr = ((void *)(&__pyx_v_memory_writer));
+481: ret = WebPEncode(&config, &pic)
__pyx_v_ret = WebPEncode((&__pyx_v_config), (&__pyx_v_pic));
+482: if not ret:
__pyx_t_5 = ((!(__pyx_v_ret != 0)) != 0); if (__pyx_t_5) { /* … */ }
+483: raise Exception("WebPEncode failed: %s, config=%s" % (ERROR_TO_NAME.get(pic.error_code, pic.error_code), get_config_info(&config)))
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_ERROR_TO_NAME); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyInt_From_WebPEncodingError(__pyx_v_pic.error_code); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_13 = __Pyx_PyInt_From_WebPEncodingError(__pyx_v_pic.error_code); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_10 = NULL; __pyx_t_11 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_15); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_15, function); __pyx_t_11 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_15)) { PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_3, __pyx_t_13}; __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) { PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_3, __pyx_t_13}; __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } else #endif { __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (__pyx_t_10) { __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL; } __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_13); __pyx_t_3 = 0; __pyx_t_13 = 0; __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_1, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; __pyx_t_15 = __pyx_f_4xpra_6codecs_4webp_6encode_get_config_info((&__pyx_v_config)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_15); __pyx_t_12 = 0; __pyx_t_15 = 0; __pyx_t_15 = __Pyx_PyString_Format(__pyx_kp_s_WebPEncode_failed_s_config_s, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_15); __pyx_t_15 = 0; __pyx_t_15 = __Pyx_PyObject_Call(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])), __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_15, 0, 0, 0); __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; __PYX_ERR(0, 483, __pyx_L1_error)
484:
+485: cdata = memory_writer.mem[:memory_writer.size]
__pyx_t_15 = __Pyx_PyBytes_FromStringAndSize(((const char*)__pyx_v_memory_writer.mem) + 0, __pyx_v_memory_writer.size - 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __pyx_v_cdata = ((PyObject*)__pyx_t_15); __pyx_t_15 = 0;
+486: free(memory_writer.mem)
free(__pyx_v_memory_writer.mem);
+487: WebPPictureFree(&pic)
WebPPictureFree((&__pyx_v_pic));
+488: log("webp.compress ratio=%i%%", 100*memory_writer.size//size)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_16 = (0x64 * __pyx_v_memory_writer.size); if (unlikely(__pyx_v_size == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); __PYX_ERR(0, 488, __pyx_L1_error) } __pyx_t_12 = __Pyx_PyInt_FromSize_t((__pyx_t_16 / __pyx_v_size)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_13 = NULL; __pyx_t_11 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_11 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_s_webp_compress_ratio_i, __pyx_t_12}; __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_kp_s_webp_compress_ratio_i, __pyx_t_12}; __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; } else #endif { __pyx_t_3 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__pyx_t_13) { __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); __pyx_t_13 = NULL; } __Pyx_INCREF(__pyx_kp_s_webp_compress_ratio_i); __Pyx_GIVEREF(__pyx_kp_s_webp_compress_ratio_i); PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_11, __pyx_kp_s_webp_compress_ratio_i); __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_11, __pyx_t_12); __pyx_t_12 = 0; __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+489: if LOG_CONFIG>0:
__pyx_t_5 = ((__pyx_v_4xpra_6codecs_4webp_6encode_LOG_CONFIG > 0) != 0); if (__pyx_t_5) { /* … */ }
+490: log("webp.compress used config: %s", get_config_info(&config))
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __pyx_f_4xpra_6codecs_4webp_6encode_get_config_info((&__pyx_v_config)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_12 = NULL; __pyx_t_11 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_12)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_12); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_11 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_s_webp_compress_used_config_s, __pyx_t_3}; __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_kp_s_webp_compress_used_config_s, __pyx_t_3}; __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { __pyx_t_13 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); if (__pyx_t_12) { __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL; } __Pyx_INCREF(__pyx_kp_s_webp_compress_used_config_s); __Pyx_GIVEREF(__pyx_kp_s_webp_compress_used_config_s); PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_11, __pyx_kp_s_webp_compress_used_config_s); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_11, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
491: client_options = {
492: #no need to expose speed
493: #(not used for anything downstream)
494: #"speed" : speed,
+495: "rgb_format" : pixel_format,
__pyx_t_15 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 495, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_rgb_format, __pyx_v_pixel_format) < 0) __PYX_ERR(0, 495, __pyx_L1_error) __pyx_v_client_options = ((PyObject*)__pyx_t_15); __pyx_t_15 = 0;
496: }
+497: if config.lossless:
__pyx_t_5 = (__pyx_v_config.lossless != 0); if (__pyx_t_5) { /* … */ goto __pyx_L27; }
+498: client_options["quality"] = 100
if (unlikely(PyDict_SetItem(__pyx_v_client_options, __pyx_n_s_quality, __pyx_int_100) < 0)) __PYX_ERR(0, 498, __pyx_L1_error)
+499: elif quality>=0 and quality<=100:
__pyx_t_4 = ((__pyx_v_quality >= 0) != 0); if (__pyx_t_4) { } else { __pyx_t_5 = __pyx_t_4; goto __pyx_L28_bool_binop_done; } __pyx_t_4 = ((__pyx_v_quality <= 0x64) != 0); __pyx_t_5 = __pyx_t_4; __pyx_L28_bool_binop_done:; if (__pyx_t_5) { /* … */ } __pyx_L27:;
+500: client_options["quality"] = quality
__pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v_quality); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); if (unlikely(PyDict_SetItem(__pyx_v_client_options, __pyx_n_s_quality, __pyx_t_15) < 0)) __PYX_ERR(0, 500, __pyx_L1_error) __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+501: if alpha_int:
__pyx_t_5 = (__pyx_v_alpha_int != 0); if (__pyx_t_5) { /* … */ }
+502: client_options["has_alpha"] = True
if (unlikely(PyDict_SetItem(__pyx_v_client_options, __pyx_n_s_has_alpha, Py_True) < 0)) __PYX_ERR(0, 502, __pyx_L1_error)
+503: return cdata, client_options
__Pyx_XDECREF(__pyx_r); __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_INCREF(__pyx_v_cdata); __Pyx_GIVEREF(__pyx_v_cdata); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_cdata); __Pyx_INCREF(__pyx_v_client_options); __Pyx_GIVEREF(__pyx_v_client_options); PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_client_options); __pyx_r = __pyx_t_15; __pyx_t_15 = 0; goto __pyx_L0;
504:
505:
+506: def selftest(full=False):
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_11selftest(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6codecs_4webp_6encode_11selftest = {"selftest", (PyCFunction)__pyx_pw_4xpra_6codecs_4webp_6encode_11selftest, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_4xpra_6codecs_4webp_6encode_11selftest(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { CYTHON_UNUSED PyObject *__pyx_v_full = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("selftest (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_full,0}; PyObject* values[1] = {0}; values[0] = ((PyObject *)Py_False); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_full); if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "selftest") < 0)) __PYX_ERR(0, 506, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_full = values[0]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("selftest", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 506, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("xpra.codecs.webp.encode.selftest", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4xpra_6codecs_4webp_6encode_10selftest(__pyx_self, __pyx_v_full); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6codecs_4webp_6encode_10selftest(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_full) { PyObject *__pyx_v_make_test_image = NULL; PyObject *__pyx_v_w = NULL; PyObject *__pyx_v_h = NULL; CYTHON_UNUSED PyObject *__pyx_v_pixels = NULL; PyObject *__pyx_v_has_alpha = NULL; PyObject *__pyx_v_img = NULL; PyObject *__pyx_v_r = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("selftest", 0); /* … */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("xpra.codecs.webp.encode.selftest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_make_test_image); __Pyx_XDECREF(__pyx_v_w); __Pyx_XDECREF(__pyx_v_h); __Pyx_XDECREF(__pyx_v_pixels); __Pyx_XDECREF(__pyx_v_has_alpha); __Pyx_XDECREF(__pyx_v_img); __Pyx_XDECREF(__pyx_v_r); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__22 = PyTuple_Pack(8, __pyx_n_s_full, __pyx_n_s_make_test_image, __pyx_n_s_w, __pyx_n_s_h, __pyx_n_s_pixels, __pyx_n_s_has_alpha, __pyx_n_s_img, __pyx_n_s_r); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 506, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__22); __Pyx_GIVEREF(__pyx_tuple__22); /* … */ __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6codecs_4webp_6encode_11selftest, NULL, __pyx_n_s_xpra_codecs_webp_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_d, __pyx_n_s_selftest, __pyx_t_3) < 0) __PYX_ERR(0, 506, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
507: #fake empty buffer:
+508: from xpra.codecs.codec_checks import make_test_image
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_make_test_image); __Pyx_GIVEREF(__pyx_n_s_make_test_image); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_make_test_image); __pyx_t_2 = __Pyx_Import(__pyx_n_s_xpra_codecs_codec_checks, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_make_test_image); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_1); __pyx_v_make_test_image = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+509: w, h = 24, 16
__pyx_t_2 = __pyx_int_24; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_int_16; __Pyx_INCREF(__pyx_t_1); __pyx_v_w = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_h = __pyx_t_1; __pyx_t_1 = 0;
+510: pixels = bytearray(b"\0" * w*h*4)
__pyx_t_1 = PyNumber_Multiply(__pyx_kp_b__5, __pyx_v_w); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_v_h); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_int_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_pixels = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+511: for has_alpha in (True, False):
__pyx_t_1 = __pyx_tuple__6; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; for (;;) { if (__pyx_t_3 >= 2) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 511, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif __Pyx_XDECREF_SET(__pyx_v_has_alpha, __pyx_t_2); __pyx_t_2 = 0; /* … */ } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_tuple__6 = PyTuple_Pack(2, Py_True, Py_False); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 511, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6);
+512: img = make_test_image("BGR%s" % ["X", "A"][has_alpha], w, h)
__pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_n_s_X); __Pyx_GIVEREF(__pyx_n_s_X); PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_X); __Pyx_INCREF(__pyx_n_s_A); __Pyx_GIVEREF(__pyx_n_s_A); PyList_SET_ITEM(__pyx_t_4, 1, __pyx_n_s_A); __pyx_t_5 = PyObject_GetItem(__pyx_t_4, __pyx_v_has_alpha); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_BGR_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_INCREF(__pyx_v_make_test_image); __pyx_t_5 = __pyx_v_make_test_image; __pyx_t_6 = NULL; __pyx_t_7 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); __pyx_t_7 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_t_4, __pyx_v_w, __pyx_v_h}; __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[4] = {__pyx_t_6, __pyx_t_4, __pyx_v_w, __pyx_v_h}; __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (__pyx_t_6) { __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; } __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_v_w); __Pyx_GIVEREF(__pyx_v_w); PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_w); __Pyx_INCREF(__pyx_v_h); __Pyx_GIVEREF(__pyx_v_h); PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_v_h); __pyx_t_4 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF_SET(__pyx_v_img, __pyx_t_2); __pyx_t_2 = 0;
+513: r = compress(img, quality=50, speed=50, supports_alpha=has_alpha)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_compress); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_img); __Pyx_GIVEREF(__pyx_v_img); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_img); __pyx_t_8 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_quality, __pyx_int_50) < 0) __PYX_ERR(0, 513, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_speed, __pyx_int_50) < 0) __PYX_ERR(0, 513, __pyx_L1_error) if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_supports_alpha, __pyx_v_has_alpha) < 0) __PYX_ERR(0, 513, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_4); __pyx_t_4 = 0;
+514: assert len(r)>0
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { __pyx_t_9 = PyObject_Length(__pyx_v_r); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 514, __pyx_L1_error) if (unlikely(!((__pyx_t_9 > 0) != 0))) { PyErr_SetNone(PyExc_AssertionError); __PYX_ERR(0, 514, __pyx_L1_error) } } #endif
515: #import binascii
516: #print("compressed data(%s)=%s" % (has_alpha, binascii.hexlify(r)))