mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove trailing spaces
This commit is contained in:
parent
7a99290a14
commit
7a6fbdac2c
@ -93,7 +93,7 @@ static PyObject* get_devices(PyObject *self, PyObject *args) {
|
||||
if (t == NULL) {
|
||||
t = read_string_data(dev, desc.iManufacturer, desc.iProduct, desc.iSerialNumber);
|
||||
if (t == NULL) { Py_DECREF(d); break; }
|
||||
PyDict_SetItem(cache, d, t);
|
||||
PyDict_SetItem(cache, d, t);
|
||||
Py_DECREF(t);
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ initlibusb(void) {
|
||||
|
||||
// We deliberately use the default context. This is the context used by
|
||||
// libmtp and we want to ensure that the busnum/devnum numbers are the same
|
||||
// here and for libmtp.
|
||||
// here and for libmtp.
|
||||
if(libusb_init(NULL) != 0) return;
|
||||
|
||||
Error = PyErr_NewException("libusb.Error", NULL, NULL);
|
||||
|
@ -62,7 +62,7 @@ static void set_bool_property(PyObject *dict, REFPROPERTYKEY key, const char *py
|
||||
HRESULT hr;
|
||||
|
||||
hr = properties->GetBoolValue(key, &ok);
|
||||
if (SUCCEEDED(hr))
|
||||
if (SUCCEEDED(hr))
|
||||
PyDict_SetItemString(dict, pykey, (ok)?Py_True:Py_False);
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ public:
|
||||
|
||||
HRESULT __stdcall OnEnd(REFGUID Context, HRESULT hrStatus) { SetEvent(this->complete); return S_OK; }
|
||||
|
||||
ULONG __stdcall AddRef() { InterlockedIncrement((long*) &self_ref); return self_ref; }
|
||||
ULONG __stdcall AddRef() { InterlockedIncrement((long*) &self_ref); return self_ref; }
|
||||
|
||||
ULONG __stdcall Release() {
|
||||
ULONG refcnt = self_ref - 1;
|
||||
@ -169,8 +169,8 @@ public:
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT __stdcall OnProgress(REFGUID Context, IPortableDeviceValuesCollection* values) {
|
||||
|
||||
HRESULT __stdcall OnProgress(REFGUID Context, IPortableDeviceValuesCollection* values) {
|
||||
DWORD num = 0, i;
|
||||
wchar_t *property = NULL;
|
||||
IPortableDeviceValues *properties = NULL;
|
||||
@ -194,7 +194,7 @@ public:
|
||||
if (obj == NULL) continue;
|
||||
PyDict_SetItem(this->items, temp, obj);
|
||||
Py_DECREF(obj); // We want a borrowed reference to obj
|
||||
}
|
||||
}
|
||||
Py_DECREF(temp);
|
||||
|
||||
set_properties(obj, properties);
|
||||
@ -263,7 +263,7 @@ static bool bulk_get_filesystem(unsigned int level, IPortableDevice *device, IPo
|
||||
if (!ok) {
|
||||
bulk_properties->Cancel(guid_context);
|
||||
pump_waiting_messages();
|
||||
}
|
||||
}
|
||||
end:
|
||||
if (ev != NULL) CloseHandle(ev);
|
||||
if (properties != NULL) properties->Release();
|
||||
@ -306,7 +306,7 @@ static bool find_objects_in(IPortableDeviceContent *content, IPortableDeviceProp
|
||||
if (SUCCEEDED(hr)) {
|
||||
for(i = 0; i < fetched; i++) {
|
||||
pv.pwszVal = child_ids[i];
|
||||
hr2 = object_ids->Add(&pv);
|
||||
hr2 = object_ids->Add(&pv);
|
||||
pv.pwszVal = NULL;
|
||||
if (FAILED(hr2)) { hresult_set_exc("Failed to add child ids to propvariantcollection", hr2); break; }
|
||||
}
|
||||
@ -332,11 +332,11 @@ static PyObject* get_object_properties(IPortableDeviceProperties *devprops, IPor
|
||||
hr = devprops->GetValues(object_id, properties, &values);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (FAILED(hr)) { hresult_set_exc("Failed to get properties for object", hr); goto end; }
|
||||
|
||||
|
||||
ans = Py_BuildValue("{s:N}", "id", wchar_to_unicode(object_id));
|
||||
if (ans == NULL) goto end;
|
||||
set_properties(ans, values);
|
||||
|
||||
|
||||
end:
|
||||
Py_XDECREF(temp);
|
||||
if (values != NULL) values->Release();
|
||||
@ -377,7 +377,7 @@ static bool single_get_filesystem(unsigned int level, IPortableDeviceContent *co
|
||||
ok = true;
|
||||
}
|
||||
} else hresult_set_exc("Failed to get item from IPortableDevicePropVariantCollection", hr);
|
||||
|
||||
|
||||
PropVariantClear(&pv);
|
||||
if (!ok) break;
|
||||
if (recurse != NULL) {
|
||||
@ -391,7 +391,7 @@ end:
|
||||
if (properties != NULL) properties->Release();
|
||||
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
static IPortableDeviceValues* create_object_properties(const wchar_t *parent_id, const wchar_t *name, const GUID content_type, unsigned PY_LONG_LONG size) { // {{{
|
||||
@ -452,7 +452,7 @@ static bool get_files_and_folders(unsigned int level, IPortableDevice *device, I
|
||||
else ok = single_get_filesystem(level, content, object_ids, callback, ans, subfolders);
|
||||
if (!ok) goto end;
|
||||
|
||||
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(subfolders); i++) {
|
||||
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(subfolders); i++) {
|
||||
const wchar_t *child_id = unicode_to_wchar(PyList_GET_ITEM(subfolders, i));
|
||||
if (child_id == NULL) { ok = false; break; }
|
||||
ok = get_files_and_folders(level+1, device, content, bulk_properties, child_id, callback, ans);
|
||||
@ -471,7 +471,7 @@ PyObject* wpd::get_filesystem(IPortableDevice *device, const wchar_t *storage_id
|
||||
|
||||
ans = PyDict_New();
|
||||
if (ans == NULL) return PyErr_NoMemory();
|
||||
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
hr = device->Content(&content);
|
||||
Py_END_ALLOW_THREADS;
|
||||
@ -534,11 +534,11 @@ PyObject* wpd::get_file(IPortableDevice *device, const wchar_t *object_id, PyObj
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
hr = resources->GetStream(object_id, WPD_RESOURCE_DEFAULT, STGM_READ, &bufsize, &stream);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (FAILED(hr)) {
|
||||
if (FAILED(hr)) {
|
||||
if (HRESULT_FROM_WIN32(ERROR_BUSY) == hr) {
|
||||
PyErr_SetString(WPDFileBusy, "Object is in use");
|
||||
} else hresult_set_exc("Failed to create stream interface to read from object", hr);
|
||||
goto end;
|
||||
} else hresult_set_exc("Failed to create stream interface to read from object", hr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
buf = (char *)calloc(bufsize+10, 1);
|
||||
@ -550,8 +550,8 @@ PyObject* wpd::get_file(IPortableDevice *device, const wchar_t *object_id, PyObj
|
||||
hr = stream->Read(buf, bufsize, &bytes_read);
|
||||
Py_END_ALLOW_THREADS;
|
||||
total_read = total_read + bytes_read;
|
||||
if (hr == STG_E_ACCESSDENIED) {
|
||||
PyErr_SetString(PyExc_IOError, "Read access is denied to this object"); break;
|
||||
if (hr == STG_E_ACCESSDENIED) {
|
||||
PyErr_SetString(PyExc_IOError, "Read access is denied to this object"); break;
|
||||
} else if (SUCCEEDED(hr)) {
|
||||
if (bytes_read > 0) {
|
||||
res = PyObject_CallMethod(dest, "write", "s#", buf, bytes_read);
|
||||
@ -561,8 +561,8 @@ PyObject* wpd::get_file(IPortableDevice *device, const wchar_t *object_id, PyObj
|
||||
}
|
||||
} else { hresult_set_exc("Failed to read file from device", hr); break; }
|
||||
|
||||
if (bytes_read == 0) {
|
||||
ok = TRUE;
|
||||
if (bytes_read == 0) {
|
||||
ok = TRUE;
|
||||
Py_XDECREF(PyObject_CallMethod(dest, "flush", NULL));
|
||||
break;
|
||||
}
|
||||
@ -640,7 +640,7 @@ PyObject* wpd::delete_object(IPortableDevice *device, const wchar_t *object_id)
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (FAILED(hr)) { hresult_set_exc("Failed to create propvariantcollection", hr); goto end; }
|
||||
pv.pwszVal = (wchar_t*)object_id;
|
||||
hr = object_ids->Add(&pv);
|
||||
hr = object_ids->Add(&pv);
|
||||
pv.pwszVal = NULL;
|
||||
if (FAILED(hr)) { hresult_set_exc("Failed to add device id to propvariantcollection", hr); goto end; }
|
||||
|
||||
@ -697,11 +697,11 @@ PyObject* wpd::put_file(IPortableDevice *device, const wchar_t *parent_id, const
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
hr = content->CreateObjectWithPropertiesAndData(values, &temp, &bufsize, NULL);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (FAILED(hr)) {
|
||||
if (FAILED(hr)) {
|
||||
if (HRESULT_FROM_WIN32(ERROR_BUSY) == hr) {
|
||||
PyErr_SetString(WPDFileBusy, "Object is in use");
|
||||
} else hresult_set_exc("Failed to create stream interface to write to object", hr);
|
||||
goto end;
|
||||
} else hresult_set_exc("Failed to create stream interface to write to object", hr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
hr = temp->QueryInterface(IID_PPV_ARGS(&dest));
|
||||
|
@ -151,7 +151,7 @@ PyObject* get_storage_info(IPortableDevice *device) { // {{{
|
||||
if (SUCCEEDED(values->GetUnsignedIntegerValue(WPD_STORAGE_ACCESS_CAPABILITY, &access)) && access == WPD_STORAGE_ACCESS_CAPABILITY_READWRITE) desc = Py_True;
|
||||
soid = PyUnicode_FromWideChar(object_ids[i], wcslen(object_ids[i]));
|
||||
if (soid == NULL) { PyErr_NoMemory(); goto end; }
|
||||
so = Py_BuildValue("{s:K, s:K, s:K, s:K, s:O, s:N}",
|
||||
so = Py_BuildValue("{s:K, s:K, s:K, s:K, s:O, s:N}",
|
||||
"capacity", capacity, "capacity_objects", capacity_objects, "free_space", free_space, "free_objects", free_objects, "rw", desc, "id", soid);
|
||||
if (so == NULL) { PyErr_NoMemory(); goto end; }
|
||||
if (SUCCEEDED(values->GetStringValue(WPD_STORAGE_DESCRIPTION, &storage_desc))) {
|
||||
@ -192,7 +192,7 @@ PyObject* get_storage_info(IPortableDevice *device) { // {{{
|
||||
Py_DECREF(so);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < fetched; i ++) { CoTaskMemFree(object_ids[i]); object_ids[i] = NULL;}
|
||||
}// if(SUCCEEDED(hr))
|
||||
}
|
||||
@ -240,12 +240,12 @@ PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropert
|
||||
hr = keys->Add(WPD_DEVICE_TYPE);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (FAILED(hr)) {hresult_set_exc("Failed to add keys to IPortableDeviceKeyCollection", hr); goto end;}
|
||||
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
hr = device->Content(&content);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (FAILED(hr)) {hresult_set_exc("Failed to get IPortableDeviceContent", hr); goto end; }
|
||||
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
hr = content->Properties(&properties);
|
||||
Py_END_ALLOW_THREADS;
|
||||
@ -287,7 +287,7 @@ PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropert
|
||||
|
||||
if (SUCCEEDED(values->GetUnsignedIntegerValue(WPD_DEVICE_TYPE, &ti))) {
|
||||
switch (ti) {
|
||||
case WPD_DEVICE_TYPE_CAMERA:
|
||||
case WPD_DEVICE_TYPE_CAMERA:
|
||||
type = "camera"; break;
|
||||
case WPD_DEVICE_TYPE_MEDIA_PLAYER:
|
||||
type = "media player"; break;
|
||||
@ -357,16 +357,16 @@ PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropert
|
||||
if (storage == NULL) {
|
||||
PyObject *exc_type, *exc_value, *exc_tb;
|
||||
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
|
||||
if (exc_type != NULL && exc_value != NULL) {
|
||||
if (exc_type != NULL && exc_value != NULL) {
|
||||
PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
|
||||
PyDict_SetItemString(ans, "storage_error", exc_value);
|
||||
Py_DECREF(exc_value); exc_value = NULL;
|
||||
PyDict_SetItemString(ans, "storage_error", exc_value);
|
||||
Py_DECREF(exc_value); exc_value = NULL;
|
||||
}
|
||||
Py_XDECREF(exc_type); Py_XDECREF(exc_value); Py_XDECREF(exc_tb);
|
||||
goto end;
|
||||
}
|
||||
PyDict_SetItemString(ans, "storage", storage);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
using namespace wpd;
|
||||
|
||||
PyObject *wpd::hresult_set_exc(const char *msg, HRESULT hr) {
|
||||
PyObject *wpd::hresult_set_exc(const char *msg, HRESULT hr) {
|
||||
PyObject *o = NULL, *mess;
|
||||
LPWSTR desc = NULL;
|
||||
|
||||
@ -55,7 +55,7 @@ int wpd::pump_waiting_messages() {
|
||||
UINT firstMsg = 0, lastMsg = 0;
|
||||
MSG msg;
|
||||
int result = 0;
|
||||
// Read all of the messages in this next loop,
|
||||
// Read all of the messages in this next loop,
|
||||
// removing each message as we read it.
|
||||
while (PeekMessage(&msg, NULL, firstMsg, lastMsg, PM_REMOVE)) {
|
||||
// If it's a quit message, we're out of here.
|
||||
@ -64,7 +64,7 @@ int wpd::pump_waiting_messages() {
|
||||
break;
|
||||
}
|
||||
// Otherwise, dispatch the message.
|
||||
DispatchMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} // End of PeekMessage while loop
|
||||
|
||||
return result;
|
||||
|
@ -49,8 +49,8 @@ wpd_init(PyObject *self, PyObject *args) {
|
||||
|
||||
if (FAILED(hr)) {
|
||||
portable_device_manager = NULL;
|
||||
PyErr_SetString((hr == REGDB_E_CLASSNOTREG) ? NoWPD : WPDError, (hr == REGDB_E_CLASSNOTREG) ?
|
||||
"This computer is not running the Windows Portable Device framework. You may need to install Windows Media Player 11 or newer." :
|
||||
PyErr_SetString((hr == REGDB_E_CLASSNOTREG) ? NoWPD : WPDError, (hr == REGDB_E_CLASSNOTREG) ?
|
||||
"This computer is not running the Windows Portable Device framework. You may need to install Windows Media Player 11 or newer." :
|
||||
"Failed to create the WPD device manager interface");
|
||||
return NULL;
|
||||
}
|
||||
@ -116,7 +116,7 @@ wpd_enumerate_devices(PyObject *self, PyObject *args) {
|
||||
PyTuple_SET_ITEM(ans, i, temp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
hresult_set_exc("Failed to get list of portable devices", hr);
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ initwpd(void) {
|
||||
wpd::DeviceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&wpd::DeviceType) < 0)
|
||||
return;
|
||||
|
||||
|
||||
m = Py_InitModule3("wpd", wpd_methods, "Interface to the WPD windows service.");
|
||||
if (m == NULL) return;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*
|
||||
* Python extension to scan the system for USB devices on OS X machines.
|
||||
* To use
|
||||
* >>> import usbobserver
|
||||
@ -98,7 +98,7 @@ usbobserver_get_iokit_number_property(io_service_t dev, CFStringRef prop) {
|
||||
if (PropRef) {
|
||||
CFNumberGetValue((CFNumberRef)PropRef, kCFNumberLongType, &val);
|
||||
CFRelease(PropRef);
|
||||
}
|
||||
}
|
||||
|
||||
return PyLong_FromLong(val);
|
||||
}
|
||||
@ -106,7 +106,7 @@ usbobserver_get_iokit_number_property(io_service_t dev, CFStringRef prop) {
|
||||
|
||||
static PyObject *
|
||||
usbobserver_get_usb_devices(PyObject *self, PyObject *args) {
|
||||
|
||||
|
||||
CFMutableDictionaryRef matchingDict;
|
||||
kern_return_t kr;
|
||||
PyObject *devices, *device;
|
||||
@ -164,7 +164,7 @@ usbobserver_get_usb_devices(PyObject *self, PyObject *args) {
|
||||
NUKE(vendor); NUKE(product); NUKE(bcd); NUKE(manufacturer);
|
||||
NUKE(productn); NUKE(serial);
|
||||
}
|
||||
|
||||
|
||||
if (iter) IOObjectRelease(iter);
|
||||
|
||||
return devices;
|
||||
@ -184,14 +184,14 @@ usbobserver_get_bsd_path(io_object_t dev) {
|
||||
|
||||
if (!CFStringGetCString(PropRef,
|
||||
cpath + dev_path_length,
|
||||
MAXPATHLEN - dev_path_length,
|
||||
MAXPATHLEN - dev_path_length,
|
||||
kCFStringEncodingUTF8)) return NULL;
|
||||
|
||||
return PyUnicode_DecodeUTF8(cpath, strlen(cpath), "replace");
|
||||
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
static PyObject*
|
||||
usbobserver_find_prop(io_registry_entry_t e, CFStringRef key, int is_string )
|
||||
{
|
||||
char buf[500]; long val = 0;
|
||||
@ -212,7 +212,7 @@ usbobserver_find_prop(io_registry_entry_t e, CFStringRef key, int is_string )
|
||||
|
||||
CFRelease(PropRef);
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
usbobserver_get_usb_drives(PyObject *self, PyObject *args) {
|
||||
@ -289,7 +289,7 @@ usbobserver_get_mounted_filesystems(PyObject *self, PyObject *args) {
|
||||
}
|
||||
num += 10; // In case the number of volumes has increased
|
||||
buf = PyMem_New(fsstat, num);
|
||||
if (buf == NULL) return PyErr_NoMemory();
|
||||
if (buf == NULL) return PyErr_NoMemory();
|
||||
|
||||
num = getfsstat(buf, num*sizeof(fsstat), MNT_NOWAIT);
|
||||
if (num == -1) {
|
||||
@ -458,25 +458,25 @@ end:
|
||||
}
|
||||
|
||||
static PyMethodDef usbobserver_methods[] = {
|
||||
{"get_usb_devices", usbobserver_get_usb_devices, METH_VARARGS,
|
||||
{"get_usb_devices", usbobserver_get_usb_devices, METH_VARARGS,
|
||||
"Get list of connected USB devices. Returns a list of tuples. Each tuple is of the form (vendor_id, product_id, bcd, manufacturer, product, serial number)."
|
||||
},
|
||||
{"get_usb_drives", usbobserver_get_usb_drives, METH_VARARGS,
|
||||
{"get_usb_drives", usbobserver_get_usb_drives, METH_VARARGS,
|
||||
"Get list of mounted drives. Returns a list of tuples, each of the form (name, bsd_path)."
|
||||
},
|
||||
{"get_mounted_filesystems", usbobserver_get_mounted_filesystems, METH_VARARGS,
|
||||
{"get_mounted_filesystems", usbobserver_get_mounted_filesystems, METH_VARARGS,
|
||||
"Get mapping of mounted filesystems. Mapping is from BSD name to mount point."
|
||||
},
|
||||
{"send2trash", usbobserver_send2trash, METH_VARARGS,
|
||||
{"send2trash", usbobserver_send2trash, METH_VARARGS,
|
||||
"send2trash(unicode object) -> Send specified file/dir to trash"
|
||||
},
|
||||
{"user_locale", usbobserver_user_locale, METH_VARARGS,
|
||||
{"user_locale", usbobserver_user_locale, METH_VARARGS,
|
||||
"user_locale() -> The name of the current user's locale or None if an error occurred"
|
||||
},
|
||||
{"date_format", usbobserver_date_fmt, METH_VARARGS,
|
||||
{"date_format", usbobserver_date_fmt, METH_VARARGS,
|
||||
"date_format() -> The (short) date format used by the user's current locale"
|
||||
},
|
||||
{"is_mtp_device", usbobserver_is_mtp, METH_VARARGS,
|
||||
{"is_mtp_device", usbobserver_is_mtp, METH_VARARGS,
|
||||
"is_mtp_device(vendor_id, product_id, bcd, serial) -> Return True if the specified device has an MTP interface"
|
||||
},
|
||||
|
||||
|
@ -52,7 +52,7 @@ cpalmdoc_decompress(PyObject *self, PyObject *args) {
|
||||
input = (Byte *) PyMem_Malloc(sizeof(Byte)*input_len);
|
||||
if (input == NULL) return PyErr_NoMemory();
|
||||
// Map chars to bytes
|
||||
for (j = 0; j < input_len; j++)
|
||||
for (j = 0; j < input_len; j++)
|
||||
input[j] = (_input[j] < 0) ? _input[j]+256 : _input[j];
|
||||
output = (char *)PyMem_Malloc(sizeof(char)*(MAX(BUFFER, 8*input_len)));
|
||||
if (output == NULL) return PyErr_NoMemory();
|
||||
@ -64,7 +64,7 @@ cpalmdoc_decompress(PyObject *self, PyObject *args) {
|
||||
|
||||
else if (c <= 0x7F) // 0, 09-7F = self
|
||||
output[o++] = (char)c;
|
||||
|
||||
|
||||
else if (c >= 0xC0) { // space + ASCII char
|
||||
output[o++] = ' ';
|
||||
output[o++] = c ^ 0x80;
|
||||
@ -72,7 +72,7 @@ cpalmdoc_decompress(PyObject *self, PyObject *args) {
|
||||
else { // 80-BF repeat sequences
|
||||
c = (c << 8) + input[i++];
|
||||
di = (c & 0x3FFF) >> 3;
|
||||
for ( n = (c & 7) + 3; n--; ++o )
|
||||
for ( n = (c & 7) + 3; n--; ++o )
|
||||
output[o] = output[o - di];
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ cpalmdoc_decompress(PyObject *self, PyObject *args) {
|
||||
return ans;
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
cpalmdoc_memcmp( Byte *a, Byte *b, Py_ssize_t len) {
|
||||
Py_ssize_t i;
|
||||
for (i = 0; i < len; i++) if (a[i] != b[i]) return false;
|
||||
@ -92,7 +92,7 @@ cpalmdoc_memcmp( Byte *a, Byte *b, Py_ssize_t len) {
|
||||
static Py_ssize_t
|
||||
cpalmdoc_rfind(Byte *data, Py_ssize_t pos, Py_ssize_t chunk_length) {
|
||||
Py_ssize_t i;
|
||||
for (i = pos - chunk_length; i > -1; i--)
|
||||
for (i = pos - chunk_length; i > -1; i--)
|
||||
if (cpalmdoc_memcmp(data+i, data+pos, chunk_length)) return i;
|
||||
return pos;
|
||||
}
|
||||
@ -105,7 +105,7 @@ cpalmdoc_do_compress(buffer *b, char *output) {
|
||||
Byte c, n;
|
||||
bool found;
|
||||
char *head;
|
||||
buffer temp;
|
||||
buffer temp;
|
||||
head = output;
|
||||
temp.data = (Byte *)PyMem_Malloc(sizeof(Byte)*8); temp.len = 0;
|
||||
if (temp.data == NULL) return 0;
|
||||
@ -167,7 +167,7 @@ cpalmdoc_compress(PyObject *self, PyObject *args) {
|
||||
b.data = (Byte *)PyMem_Malloc(sizeof(Byte)*input_len);
|
||||
if (b.data == NULL) return PyErr_NoMemory();
|
||||
// Map chars to bytes
|
||||
for (j = 0; j < input_len; j++)
|
||||
for (j = 0; j < input_len; j++)
|
||||
b.data[j] = (_input[j] < 0) ? _input[j]+256 : _input[j];
|
||||
b.len = input_len;
|
||||
// Make the output buffer larger than the input as sometimes
|
||||
|
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
* (C) Copyright 2007 Trolltech ASA
|
||||
* (C) Copyright 2007 Trolltech ASA
|
||||
* All rights reserved.
|
||||
**
|
||||
* This is version of the Pictureflow animated image show widget modified by Trolltech ASA.
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
/*
|
||||
ORIGINAL COPYRIGHT HEADER
|
||||
PictureFlow - animated image show widget
|
||||
http://pictureflow.googlecode.com
|
||||
@ -131,134 +131,134 @@ inline PFreal floatToFixed(float val)
|
||||
|
||||
// warning: regenerate the table if IANGLE_MAX and PFREAL_SHIFT are changed!
|
||||
static const PFreal sinTable[IANGLE_MAX] = {
|
||||
3, 9, 15, 21, 28, 34, 40, 47,
|
||||
53, 59, 65, 72, 78, 84, 90, 97,
|
||||
103, 109, 115, 122, 128, 134, 140, 147,
|
||||
153, 159, 165, 171, 178, 184, 190, 196,
|
||||
202, 209, 215, 221, 227, 233, 239, 245,
|
||||
251, 257, 264, 270, 276, 282, 288, 294,
|
||||
300, 306, 312, 318, 324, 330, 336, 342,
|
||||
347, 353, 359, 365, 371, 377, 383, 388,
|
||||
394, 400, 406, 412, 417, 423, 429, 434,
|
||||
440, 446, 451, 457, 463, 468, 474, 479,
|
||||
485, 491, 496, 501, 507, 512, 518, 523,
|
||||
529, 534, 539, 545, 550, 555, 561, 566,
|
||||
571, 576, 581, 587, 592, 597, 602, 607,
|
||||
612, 617, 622, 627, 632, 637, 642, 647,
|
||||
652, 656, 661, 666, 671, 675, 680, 685,
|
||||
690, 694, 699, 703, 708, 712, 717, 721,
|
||||
726, 730, 735, 739, 743, 748, 752, 756,
|
||||
760, 765, 769, 773, 777, 781, 785, 789,
|
||||
793, 797, 801, 805, 809, 813, 816, 820,
|
||||
824, 828, 831, 835, 839, 842, 846, 849,
|
||||
853, 856, 860, 863, 866, 870, 873, 876,
|
||||
879, 883, 886, 889, 892, 895, 898, 901,
|
||||
904, 907, 910, 913, 916, 918, 921, 924,
|
||||
927, 929, 932, 934, 937, 939, 942, 944,
|
||||
947, 949, 951, 954, 956, 958, 960, 963,
|
||||
965, 967, 969, 971, 973, 975, 977, 978,
|
||||
980, 982, 984, 986, 987, 989, 990, 992,
|
||||
994, 995, 997, 998, 999, 1001, 1002, 1003,
|
||||
1004, 1006, 1007, 1008, 1009, 1010, 1011, 1012,
|
||||
1013, 1014, 1015, 1015, 1016, 1017, 1018, 1018,
|
||||
1019, 1019, 1020, 1020, 1021, 1021, 1022, 1022,
|
||||
1022, 1023, 1023, 1023, 1023, 1023, 1023, 1023,
|
||||
1023, 1023, 1023, 1023, 1023, 1023, 1023, 1022,
|
||||
1022, 1022, 1021, 1021, 1020, 1020, 1019, 1019,
|
||||
1018, 1018, 1017, 1016, 1015, 1015, 1014, 1013,
|
||||
1012, 1011, 1010, 1009, 1008, 1007, 1006, 1004,
|
||||
1003, 1002, 1001, 999, 998, 997, 995, 994,
|
||||
992, 990, 989, 987, 986, 984, 982, 980,
|
||||
978, 977, 975, 973, 971, 969, 967, 965,
|
||||
963, 960, 958, 956, 954, 951, 949, 947,
|
||||
944, 942, 939, 937, 934, 932, 929, 927,
|
||||
924, 921, 918, 916, 913, 910, 907, 904,
|
||||
901, 898, 895, 892, 889, 886, 883, 879,
|
||||
876, 873, 870, 866, 863, 860, 856, 853,
|
||||
849, 846, 842, 839, 835, 831, 828, 824,
|
||||
820, 816, 813, 809, 805, 801, 797, 793,
|
||||
789, 785, 781, 777, 773, 769, 765, 760,
|
||||
756, 752, 748, 743, 739, 735, 730, 726,
|
||||
721, 717, 712, 708, 703, 699, 694, 690,
|
||||
685, 680, 675, 671, 666, 661, 656, 652,
|
||||
647, 642, 637, 632, 627, 622, 617, 612,
|
||||
607, 602, 597, 592, 587, 581, 576, 571,
|
||||
566, 561, 555, 550, 545, 539, 534, 529,
|
||||
523, 518, 512, 507, 501, 496, 491, 485,
|
||||
479, 474, 468, 463, 457, 451, 446, 440,
|
||||
434, 429, 423, 417, 412, 406, 400, 394,
|
||||
388, 383, 377, 371, 365, 359, 353, 347,
|
||||
342, 336, 330, 324, 318, 312, 306, 300,
|
||||
294, 288, 282, 276, 270, 264, 257, 251,
|
||||
245, 239, 233, 227, 221, 215, 209, 202,
|
||||
196, 190, 184, 178, 171, 165, 159, 153,
|
||||
147, 140, 134, 128, 122, 115, 109, 103,
|
||||
97, 90, 84, 78, 72, 65, 59, 53,
|
||||
47, 40, 34, 28, 21, 15, 9, 3,
|
||||
-4, -10, -16, -22, -29, -35, -41, -48,
|
||||
-54, -60, -66, -73, -79, -85, -91, -98,
|
||||
-104, -110, -116, -123, -129, -135, -141, -148,
|
||||
-154, -160, -166, -172, -179, -185, -191, -197,
|
||||
-203, -210, -216, -222, -228, -234, -240, -246,
|
||||
-252, -258, -265, -271, -277, -283, -289, -295,
|
||||
-301, -307, -313, -319, -325, -331, -337, -343,
|
||||
-348, -354, -360, -366, -372, -378, -384, -389,
|
||||
-395, -401, -407, -413, -418, -424, -430, -435,
|
||||
-441, -447, -452, -458, -464, -469, -475, -480,
|
||||
-486, -492, -497, -502, -508, -513, -519, -524,
|
||||
-530, -535, -540, -546, -551, -556, -562, -567,
|
||||
-572, -577, -582, -588, -593, -598, -603, -608,
|
||||
-613, -618, -623, -628, -633, -638, -643, -648,
|
||||
-653, -657, -662, -667, -672, -676, -681, -686,
|
||||
-691, -695, -700, -704, -709, -713, -718, -722,
|
||||
-727, -731, -736, -740, -744, -749, -753, -757,
|
||||
-761, -766, -770, -774, -778, -782, -786, -790,
|
||||
-794, -798, -802, -806, -810, -814, -817, -821,
|
||||
-825, -829, -832, -836, -840, -843, -847, -850,
|
||||
-854, -857, -861, -864, -867, -871, -874, -877,
|
||||
-880, -884, -887, -890, -893, -896, -899, -902,
|
||||
-905, -908, -911, -914, -917, -919, -922, -925,
|
||||
-928, -930, -933, -935, -938, -940, -943, -945,
|
||||
-948, -950, -952, -955, -957, -959, -961, -964,
|
||||
-966, -968, -970, -972, -974, -976, -978, -979,
|
||||
-981, -983, -985, -987, -988, -990, -991, -993,
|
||||
-995, -996, -998, -999, -1000, -1002, -1003, -1004,
|
||||
-1005, -1007, -1008, -1009, -1010, -1011, -1012, -1013,
|
||||
-1014, -1015, -1016, -1016, -1017, -1018, -1019, -1019,
|
||||
-1020, -1020, -1021, -1021, -1022, -1022, -1023, -1023,
|
||||
-1023, -1024, -1024, -1024, -1024, -1024, -1024, -1024,
|
||||
-1024, -1024, -1024, -1024, -1024, -1024, -1024, -1023,
|
||||
-1023, -1023, -1022, -1022, -1021, -1021, -1020, -1020,
|
||||
-1019, -1019, -1018, -1017, -1016, -1016, -1015, -1014,
|
||||
-1013, -1012, -1011, -1010, -1009, -1008, -1007, -1005,
|
||||
-1004, -1003, -1002, -1000, -999, -998, -996, -995,
|
||||
-993, -991, -990, -988, -987, -985, -983, -981,
|
||||
-979, -978, -976, -974, -972, -970, -968, -966,
|
||||
-964, -961, -959, -957, -955, -952, -950, -948,
|
||||
-945, -943, -940, -938, -935, -933, -930, -928,
|
||||
-925, -922, -919, -917, -914, -911, -908, -905,
|
||||
-902, -899, -896, -893, -890, -887, -884, -880,
|
||||
-877, -874, -871, -867, -864, -861, -857, -854,
|
||||
-850, -847, -843, -840, -836, -832, -829, -825,
|
||||
-821, -817, -814, -810, -806, -802, -798, -794,
|
||||
-790, -786, -782, -778, -774, -770, -766, -761,
|
||||
-757, -753, -749, -744, -740, -736, -731, -727,
|
||||
-722, -718, -713, -709, -704, -700, -695, -691,
|
||||
-686, -681, -676, -672, -667, -662, -657, -653,
|
||||
-648, -643, -638, -633, -628, -623, -618, -613,
|
||||
-608, -603, -598, -593, -588, -582, -577, -572,
|
||||
-567, -562, -556, -551, -546, -540, -535, -530,
|
||||
-524, -519, -513, -508, -502, -497, -492, -486,
|
||||
-480, -475, -469, -464, -458, -452, -447, -441,
|
||||
-435, -430, -424, -418, -413, -407, -401, -395,
|
||||
-389, -384, -378, -372, -366, -360, -354, -348,
|
||||
-343, -337, -331, -325, -319, -313, -307, -301,
|
||||
-295, -289, -283, -277, -271, -265, -258, -252,
|
||||
-246, -240, -234, -228, -222, -216, -210, -203,
|
||||
-197, -191, -185, -179, -172, -166, -160, -154,
|
||||
-148, -141, -135, -129, -123, -116, -110, -104,
|
||||
-98, -91, -85, -79, -73, -66, -60, -54,
|
||||
-48, -41, -35, -29, -22, -16, -10, -4
|
||||
3, 9, 15, 21, 28, 34, 40, 47,
|
||||
53, 59, 65, 72, 78, 84, 90, 97,
|
||||
103, 109, 115, 122, 128, 134, 140, 147,
|
||||
153, 159, 165, 171, 178, 184, 190, 196,
|
||||
202, 209, 215, 221, 227, 233, 239, 245,
|
||||
251, 257, 264, 270, 276, 282, 288, 294,
|
||||
300, 306, 312, 318, 324, 330, 336, 342,
|
||||
347, 353, 359, 365, 371, 377, 383, 388,
|
||||
394, 400, 406, 412, 417, 423, 429, 434,
|
||||
440, 446, 451, 457, 463, 468, 474, 479,
|
||||
485, 491, 496, 501, 507, 512, 518, 523,
|
||||
529, 534, 539, 545, 550, 555, 561, 566,
|
||||
571, 576, 581, 587, 592, 597, 602, 607,
|
||||
612, 617, 622, 627, 632, 637, 642, 647,
|
||||
652, 656, 661, 666, 671, 675, 680, 685,
|
||||
690, 694, 699, 703, 708, 712, 717, 721,
|
||||
726, 730, 735, 739, 743, 748, 752, 756,
|
||||
760, 765, 769, 773, 777, 781, 785, 789,
|
||||
793, 797, 801, 805, 809, 813, 816, 820,
|
||||
824, 828, 831, 835, 839, 842, 846, 849,
|
||||
853, 856, 860, 863, 866, 870, 873, 876,
|
||||
879, 883, 886, 889, 892, 895, 898, 901,
|
||||
904, 907, 910, 913, 916, 918, 921, 924,
|
||||
927, 929, 932, 934, 937, 939, 942, 944,
|
||||
947, 949, 951, 954, 956, 958, 960, 963,
|
||||
965, 967, 969, 971, 973, 975, 977, 978,
|
||||
980, 982, 984, 986, 987, 989, 990, 992,
|
||||
994, 995, 997, 998, 999, 1001, 1002, 1003,
|
||||
1004, 1006, 1007, 1008, 1009, 1010, 1011, 1012,
|
||||
1013, 1014, 1015, 1015, 1016, 1017, 1018, 1018,
|
||||
1019, 1019, 1020, 1020, 1021, 1021, 1022, 1022,
|
||||
1022, 1023, 1023, 1023, 1023, 1023, 1023, 1023,
|
||||
1023, 1023, 1023, 1023, 1023, 1023, 1023, 1022,
|
||||
1022, 1022, 1021, 1021, 1020, 1020, 1019, 1019,
|
||||
1018, 1018, 1017, 1016, 1015, 1015, 1014, 1013,
|
||||
1012, 1011, 1010, 1009, 1008, 1007, 1006, 1004,
|
||||
1003, 1002, 1001, 999, 998, 997, 995, 994,
|
||||
992, 990, 989, 987, 986, 984, 982, 980,
|
||||
978, 977, 975, 973, 971, 969, 967, 965,
|
||||
963, 960, 958, 956, 954, 951, 949, 947,
|
||||
944, 942, 939, 937, 934, 932, 929, 927,
|
||||
924, 921, 918, 916, 913, 910, 907, 904,
|
||||
901, 898, 895, 892, 889, 886, 883, 879,
|
||||
876, 873, 870, 866, 863, 860, 856, 853,
|
||||
849, 846, 842, 839, 835, 831, 828, 824,
|
||||
820, 816, 813, 809, 805, 801, 797, 793,
|
||||
789, 785, 781, 777, 773, 769, 765, 760,
|
||||
756, 752, 748, 743, 739, 735, 730, 726,
|
||||
721, 717, 712, 708, 703, 699, 694, 690,
|
||||
685, 680, 675, 671, 666, 661, 656, 652,
|
||||
647, 642, 637, 632, 627, 622, 617, 612,
|
||||
607, 602, 597, 592, 587, 581, 576, 571,
|
||||
566, 561, 555, 550, 545, 539, 534, 529,
|
||||
523, 518, 512, 507, 501, 496, 491, 485,
|
||||
479, 474, 468, 463, 457, 451, 446, 440,
|
||||
434, 429, 423, 417, 412, 406, 400, 394,
|
||||
388, 383, 377, 371, 365, 359, 353, 347,
|
||||
342, 336, 330, 324, 318, 312, 306, 300,
|
||||
294, 288, 282, 276, 270, 264, 257, 251,
|
||||
245, 239, 233, 227, 221, 215, 209, 202,
|
||||
196, 190, 184, 178, 171, 165, 159, 153,
|
||||
147, 140, 134, 128, 122, 115, 109, 103,
|
||||
97, 90, 84, 78, 72, 65, 59, 53,
|
||||
47, 40, 34, 28, 21, 15, 9, 3,
|
||||
-4, -10, -16, -22, -29, -35, -41, -48,
|
||||
-54, -60, -66, -73, -79, -85, -91, -98,
|
||||
-104, -110, -116, -123, -129, -135, -141, -148,
|
||||
-154, -160, -166, -172, -179, -185, -191, -197,
|
||||
-203, -210, -216, -222, -228, -234, -240, -246,
|
||||
-252, -258, -265, -271, -277, -283, -289, -295,
|
||||
-301, -307, -313, -319, -325, -331, -337, -343,
|
||||
-348, -354, -360, -366, -372, -378, -384, -389,
|
||||
-395, -401, -407, -413, -418, -424, -430, -435,
|
||||
-441, -447, -452, -458, -464, -469, -475, -480,
|
||||
-486, -492, -497, -502, -508, -513, -519, -524,
|
||||
-530, -535, -540, -546, -551, -556, -562, -567,
|
||||
-572, -577, -582, -588, -593, -598, -603, -608,
|
||||
-613, -618, -623, -628, -633, -638, -643, -648,
|
||||
-653, -657, -662, -667, -672, -676, -681, -686,
|
||||
-691, -695, -700, -704, -709, -713, -718, -722,
|
||||
-727, -731, -736, -740, -744, -749, -753, -757,
|
||||
-761, -766, -770, -774, -778, -782, -786, -790,
|
||||
-794, -798, -802, -806, -810, -814, -817, -821,
|
||||
-825, -829, -832, -836, -840, -843, -847, -850,
|
||||
-854, -857, -861, -864, -867, -871, -874, -877,
|
||||
-880, -884, -887, -890, -893, -896, -899, -902,
|
||||
-905, -908, -911, -914, -917, -919, -922, -925,
|
||||
-928, -930, -933, -935, -938, -940, -943, -945,
|
||||
-948, -950, -952, -955, -957, -959, -961, -964,
|
||||
-966, -968, -970, -972, -974, -976, -978, -979,
|
||||
-981, -983, -985, -987, -988, -990, -991, -993,
|
||||
-995, -996, -998, -999, -1000, -1002, -1003, -1004,
|
||||
-1005, -1007, -1008, -1009, -1010, -1011, -1012, -1013,
|
||||
-1014, -1015, -1016, -1016, -1017, -1018, -1019, -1019,
|
||||
-1020, -1020, -1021, -1021, -1022, -1022, -1023, -1023,
|
||||
-1023, -1024, -1024, -1024, -1024, -1024, -1024, -1024,
|
||||
-1024, -1024, -1024, -1024, -1024, -1024, -1024, -1023,
|
||||
-1023, -1023, -1022, -1022, -1021, -1021, -1020, -1020,
|
||||
-1019, -1019, -1018, -1017, -1016, -1016, -1015, -1014,
|
||||
-1013, -1012, -1011, -1010, -1009, -1008, -1007, -1005,
|
||||
-1004, -1003, -1002, -1000, -999, -998, -996, -995,
|
||||
-993, -991, -990, -988, -987, -985, -983, -981,
|
||||
-979, -978, -976, -974, -972, -970, -968, -966,
|
||||
-964, -961, -959, -957, -955, -952, -950, -948,
|
||||
-945, -943, -940, -938, -935, -933, -930, -928,
|
||||
-925, -922, -919, -917, -914, -911, -908, -905,
|
||||
-902, -899, -896, -893, -890, -887, -884, -880,
|
||||
-877, -874, -871, -867, -864, -861, -857, -854,
|
||||
-850, -847, -843, -840, -836, -832, -829, -825,
|
||||
-821, -817, -814, -810, -806, -802, -798, -794,
|
||||
-790, -786, -782, -778, -774, -770, -766, -761,
|
||||
-757, -753, -749, -744, -740, -736, -731, -727,
|
||||
-722, -718, -713, -709, -704, -700, -695, -691,
|
||||
-686, -681, -676, -672, -667, -662, -657, -653,
|
||||
-648, -643, -638, -633, -628, -623, -618, -613,
|
||||
-608, -603, -598, -593, -588, -582, -577, -572,
|
||||
-567, -562, -556, -551, -546, -540, -535, -530,
|
||||
-524, -519, -513, -508, -502, -497, -492, -486,
|
||||
-480, -475, -469, -464, -458, -452, -447, -441,
|
||||
-435, -430, -424, -418, -413, -407, -401, -395,
|
||||
-389, -384, -378, -372, -366, -360, -354, -348,
|
||||
-343, -337, -331, -325, -319, -313, -307, -301,
|
||||
-295, -289, -283, -277, -271, -265, -258, -252,
|
||||
-246, -240, -234, -228, -222, -216, -210, -203,
|
||||
-197, -191, -185, -179, -172, -166, -160, -154,
|
||||
-148, -141, -135, -129, -123, -116, -110, -104,
|
||||
-98, -91, -85, -79, -73, -66, -60, -54,
|
||||
-48, -41, -35, -29, -22, -16, -10, -4
|
||||
};
|
||||
|
||||
// this is the program the generate the above table
|
||||
@ -302,7 +302,7 @@ inline PFreal fsin(int iangle)
|
||||
while(iangle < 0)
|
||||
iangle += IANGLE_MAX;
|
||||
return sinTable[iangle & IANGLE_MASK];
|
||||
}
|
||||
}
|
||||
|
||||
inline PFreal fcos(int iangle)
|
||||
{
|
||||
@ -375,12 +375,12 @@ public:
|
||||
|
||||
void setImages(FlowImages *images);
|
||||
void dataChanged();
|
||||
|
||||
|
||||
private:
|
||||
PictureFlow* widget;
|
||||
|
||||
|
||||
FlowImages *slideImages;
|
||||
|
||||
|
||||
int slideWidth;
|
||||
int slideHeight;
|
||||
int fontSize;
|
||||
@ -439,7 +439,7 @@ PictureFlowPrivate::PictureFlowPrivate(PictureFlow* w, int queueLength_)
|
||||
triggerTimer.setSingleShot(true);
|
||||
triggerTimer.setInterval(0);
|
||||
QObject::connect(&triggerTimer, SIGNAL(timeout()), widget, SLOT(render()));
|
||||
|
||||
|
||||
recalc(200, 200);
|
||||
resetSlides();
|
||||
}
|
||||
@ -490,7 +490,7 @@ int PictureFlowPrivate::getTarget() const
|
||||
int PictureFlowPrivate::currentSlide() const
|
||||
{
|
||||
return centerIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void PictureFlowPrivate::setCurrentSlide(int index)
|
||||
{
|
||||
@ -619,12 +619,12 @@ static QImage prepareSurface(QImage srcimg, const int w, const int h, bool doRef
|
||||
QRgb color;
|
||||
|
||||
// offscreen buffer: black is sweet
|
||||
QImage result(hs, w, QImage::Format_RGB16);
|
||||
QImage result(hs, w, QImage::Format_RGB16);
|
||||
result.fill(0);
|
||||
|
||||
if (preserveAspectRatio) {
|
||||
QImage temp = srcimg.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
img = QImage(w, h, temp.format());
|
||||
img = QImage(w, h, temp.format());
|
||||
img.fill(0);
|
||||
left = (w - temp.width()) / 2;
|
||||
top = h - temp.height();
|
||||
@ -690,7 +690,7 @@ QImage* PictureFlowPrivate::surface(int slideIndex)
|
||||
QPoint p2(slideWidth*6/10, slideHeight);
|
||||
QLinearGradient linearGrad(p1, p2);
|
||||
linearGrad.setColorAt(0, Qt::black);
|
||||
linearGrad.setColorAt(1, Qt::white);
|
||||
linearGrad.setColorAt(1, Qt::white);
|
||||
painter.setBrush(linearGrad);
|
||||
painter.fillRect(0, 0, slideWidth, slideHeight, QBrush(linearGrad));
|
||||
|
||||
@ -708,7 +708,7 @@ QImage* PictureFlowPrivate::surface(int slideIndex)
|
||||
}
|
||||
|
||||
|
||||
// Schedules rendering the slides. Call this function to avoid immediate
|
||||
// Schedules rendering the slides. Call this function to avoid immediate
|
||||
// render and thus cause less flicker.
|
||||
void PictureFlowPrivate::triggerRender(int after_msecs)
|
||||
{
|
||||
@ -743,7 +743,7 @@ void PictureFlowPrivate::render_text(QPainter *painter, int index) {
|
||||
//printf("top: %d, height: %d\n", brect.top(), brect.height());
|
||||
//
|
||||
painter->drawText(brect, TEXT_FLAGS, caption);
|
||||
|
||||
|
||||
brect2.moveTop(buffer_height - brect2.height());
|
||||
|
||||
painter->save();
|
||||
@ -761,7 +761,7 @@ void PictureFlowPrivate::render()
|
||||
int nright = rightSlides.count();
|
||||
QRect r;
|
||||
|
||||
if (step == 0)
|
||||
if (step == 0)
|
||||
r = renderCenterSlide(centerSlide);
|
||||
else
|
||||
r = renderSlide(centerSlide);
|
||||
@ -777,7 +777,7 @@ void PictureFlowPrivate::render()
|
||||
QRect rs = renderSlide(leftSlides[index], alpha, 0, c1-1);
|
||||
if(!rs.isEmpty())
|
||||
c1 = rs.left();
|
||||
}
|
||||
}
|
||||
for(int index = 0; index < nright-1; index++)
|
||||
{
|
||||
int alpha = (index < nright-2) ? 256 : 128;
|
||||
@ -796,7 +796,7 @@ void PictureFlowPrivate::render()
|
||||
painter.setPen(Qt::white);
|
||||
//painter.setPen(QColor(255,255,255,127));
|
||||
|
||||
if (centerIndex < slideCount() && centerIndex > -1) {
|
||||
if (centerIndex < slideCount() && centerIndex > -1) {
|
||||
render_text(&painter, centerIndex);
|
||||
}
|
||||
|
||||
@ -820,7 +820,7 @@ void PictureFlowPrivate::render()
|
||||
c1 = rs.left();
|
||||
|
||||
alpha = (step > 0) ? 256-fade/2 : 256;
|
||||
}
|
||||
}
|
||||
for(int index = 0; index < nright; index++)
|
||||
{
|
||||
int alpha = (index < nright-2) ? 256 : 128;
|
||||
@ -905,8 +905,8 @@ QRect PictureFlowPrivate::renderSlide(const SlideInfo &slide, int alpha, int col
|
||||
if(!src)
|
||||
return QRect();
|
||||
|
||||
QRect rect(0, 0, 0, 0);
|
||||
|
||||
QRect rect(0, 0, 0, 0);
|
||||
|
||||
int sw = src->height();
|
||||
int sh = src->width();
|
||||
int h = buffer.height();
|
||||
@ -978,10 +978,10 @@ QRect PictureFlowPrivate::renderSlide(const SlideInfo &slide, int alpha, int col
|
||||
}
|
||||
}
|
||||
|
||||
rect.setRight(x);
|
||||
rect.setRight(x);
|
||||
if(!flag)
|
||||
rect.setLeft(x);
|
||||
flag = true;
|
||||
flag = true;
|
||||
|
||||
int y1 = h/2;
|
||||
int y2 = y1+ 1;
|
||||
@ -1006,7 +1006,7 @@ QRect PictureFlowPrivate::renderSlide(const SlideInfo &slide, int alpha, int col
|
||||
y2++;
|
||||
pixel1 -= pixelstep;
|
||||
pixel2 += pixelstep;
|
||||
}
|
||||
}
|
||||
else
|
||||
while((y1 >= 0) && (y2 < h) && (p1 >= 0))
|
||||
{
|
||||
@ -1032,8 +1032,8 @@ QRect PictureFlowPrivate::renderSlide(const SlideInfo &slide, int alpha, int col
|
||||
y2++;
|
||||
pixel1 -= pixelstep;
|
||||
pixel2 += pixelstep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rect.setTop(0);
|
||||
rect.setBottom(h-1);
|
||||
@ -1126,7 +1126,7 @@ void PictureFlowPrivate::updateAnimation()
|
||||
int pos = slideFrame & 0xffff;
|
||||
int neg = 65536 - pos;
|
||||
int tick = (step < 0) ? neg : pos;
|
||||
PFreal ftick = (tick * PFREAL_ONE) >> 16;
|
||||
PFreal ftick = (tick * PFREAL_ONE) >> 16;
|
||||
|
||||
// the leftmost and rightmost slide must fade away
|
||||
fade = pos / 256;
|
||||
@ -1157,7 +1157,7 @@ void PictureFlowPrivate::updateAnimation()
|
||||
step = 0;
|
||||
fade = 256;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < leftSlides.count(); i++)
|
||||
{
|
||||
@ -1188,7 +1188,7 @@ void PictureFlowPrivate::updateAnimation()
|
||||
leftSlides[0].angle = (pos * itilt) >> 16;
|
||||
leftSlides[0].cx = -fmul(offsetX, ftick);
|
||||
leftSlides[0].cy = fmul(offsetY, ftick);
|
||||
}
|
||||
}
|
||||
|
||||
// must change direction ?
|
||||
if(target < index) if(step > 0)
|
||||
@ -1226,7 +1226,7 @@ PictureFlow::PictureFlow(QWidget* parent, int queueLength): QWidget(parent)
|
||||
PictureFlow::~PictureFlow()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QSize PictureFlow::slideSize() const
|
||||
@ -1274,7 +1274,7 @@ void PictureFlow::setShowReflections(bool show) {
|
||||
d->setShowReflections(show);
|
||||
}
|
||||
|
||||
void PictureFlow::setImages(FlowImages *images)
|
||||
void PictureFlow::setImages(FlowImages *images)
|
||||
{
|
||||
d->setImages(images);
|
||||
}
|
||||
@ -1321,7 +1321,7 @@ void PictureFlow::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if(event->modifiers() == Qt::ControlModifier)
|
||||
showSlide(currentSlide()-10);
|
||||
else
|
||||
else
|
||||
showPrevious();
|
||||
event->accept();
|
||||
return;
|
||||
@ -1387,7 +1387,7 @@ void PictureFlow::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
speed = ((qAbs(x-d->previousPos.x())*1000) / d->previousPosTimestamp.elapsed())
|
||||
/ (d->buffer.width() / 10);
|
||||
|
||||
|
||||
if (speed < SPEED_LOWER_THRESHOLD)
|
||||
speed = SPEED_LOWER_THRESHOLD;
|
||||
else if (speed > SPEED_UPPER_LIMIT)
|
||||
@ -1395,19 +1395,19 @@ void PictureFlow::mouseMoveEvent(QMouseEvent* event)
|
||||
else {
|
||||
speed = SPEED_LOWER_THRESHOLD + (speed / 3);
|
||||
// qDebug() << "ACCELERATION ENABLED Speed = " << speed << ", Distance = " << distanceMovedSinceLastEvent;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// qDebug() << "Speed = " << speed;
|
||||
|
||||
// int incr = ((event->pos().x() - d->previousPos.x())/10) * speed;
|
||||
|
||||
|
||||
// qDebug() << "Incremented by " << incr;
|
||||
|
||||
int incr = (distanceMovedSinceLastEvent * speed);
|
||||
|
||||
|
||||
//qDebug() << "(distanceMovedSinceLastEvent * speed) = " << incr;
|
||||
|
||||
if (incr > d->pixelsToMovePerSlide*2) {
|
||||
@ -1438,7 +1438,7 @@ void PictureFlow::mouseMoveEvent(QMouseEvent* event)
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
d->previousPos = event->pos() * device_pixel_ratio();
|
||||
|
@ -35,10 +35,10 @@ void QProgressIndicator::setDisplayedWhenStopped(bool state)
|
||||
update();
|
||||
}
|
||||
|
||||
void QProgressIndicator::setDisplaySize(int size)
|
||||
{
|
||||
m_displaySize = size;
|
||||
update();
|
||||
void QProgressIndicator::setDisplaySize(int size)
|
||||
{
|
||||
m_displaySize = size;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@ -106,10 +106,10 @@ void QProgressIndicator::paintEvent(QPaintEvent * /*event*/)
|
||||
return;
|
||||
|
||||
int width = qMin(this->width(), this->height());
|
||||
|
||||
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
||||
int outerRadius = (width-1)*0.5;
|
||||
int innerRadius = (width-1)*0.5*0.38;
|
||||
|
||||
@ -122,7 +122,7 @@ void QProgressIndicator::paintEvent(QPaintEvent * /*event*/)
|
||||
QColor color = m_color;
|
||||
color.setAlphaF(1.0f - (i/12.0f));
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(color);
|
||||
p.setBrush(color);
|
||||
p.save();
|
||||
p.translate(rect().center());
|
||||
p.rotate(m_angle - i*30.0f);
|
||||
@ -136,7 +136,7 @@ static inline QByteArray detectDesktopEnvironment()
|
||||
const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
|
||||
if (!xdgCurrentDesktop.isEmpty())
|
||||
// See http://standards.freedesktop.org/menu-spec/latest/apb.html
|
||||
return xdgCurrentDesktop.toUpper();
|
||||
return xdgCurrentDesktop.toUpper();
|
||||
|
||||
// Classic fallbacks
|
||||
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))
|
||||
@ -163,7 +163,7 @@ class CalibreStyle: public QProxyStyle {
|
||||
public:
|
||||
CalibreStyle(QStyle *base, QHash<int, QString> icmap) : QProxyStyle(base), icon_map(icmap) {
|
||||
setObjectName(QString("calibre"));
|
||||
desktop_environment = detectDesktopEnvironment();
|
||||
desktop_environment = detectDesktopEnvironment();
|
||||
button_layout = static_cast<QDialogButtonBox::ButtonLayout>(QProxyStyle::styleHint(SH_DialogButtonLayout));
|
||||
if (QLatin1String("GNOME") == desktop_environment || QLatin1String("MATE") == desktop_environment || QLatin1String("UNITY") == desktop_environment || QLatin1String("CINNAMON") == desktop_environment || QLatin1String("X-CINNAMON") == desktop_environment)
|
||||
button_layout = QDialogButtonBox::GnomeLayout;
|
||||
@ -252,12 +252,12 @@ int load_style(QHash<int,QString> icon_map) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
class NoActivateStyle: public QProxyStyle {
|
||||
public:
|
||||
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const {
|
||||
if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick) return 0;
|
||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
class NoActivateStyle: public QProxyStyle {
|
||||
public:
|
||||
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const {
|
||||
if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick) return 0;
|
||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
};
|
||||
|
||||
void set_no_activate_on_click(QWidget *widget) {
|
||||
|
@ -164,15 +164,15 @@ static PyTypeObject html_StateType;
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
// Type-specific fields go here.
|
||||
PyObject *tag_being_defined;
|
||||
PyObject *tags;
|
||||
PyObject *is_bold;
|
||||
PyObject *is_italic;
|
||||
PyObject *tag_being_defined;
|
||||
PyObject *tags;
|
||||
PyObject *is_bold;
|
||||
PyObject *is_italic;
|
||||
PyObject *current_lang;
|
||||
PyObject *parse;
|
||||
PyObject *css_formats;
|
||||
PyObject *sub_parser_state;
|
||||
PyObject *default_lang;
|
||||
PyObject *parse;
|
||||
PyObject *css_formats;
|
||||
PyObject *sub_parser_state;
|
||||
PyObject *default_lang;
|
||||
PyObject *attribute_name;
|
||||
|
||||
} html_State;
|
||||
@ -213,7 +213,7 @@ html_State_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
self->default_lang = NULL;
|
||||
self->attribute_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|OOOOOOOOOO",
|
||||
if (!PyArg_ParseTuple(args, "|OOOOOOOOOO",
|
||||
&(self->tag_being_defined),
|
||||
&(self->tags),
|
||||
&(self->is_bold),
|
||||
@ -401,7 +401,7 @@ static inline long number_to_long(PyObject *number) {
|
||||
static PyObject*
|
||||
html_check_spelling(PyObject *self, PyObject *args) {
|
||||
PyObject *ans = NULL, *temp = NULL, *items = NULL, *text = NULL, *fmt = NULL, *locale = NULL, *sfmt = NULL, *_store_locale = NULL, *t = NULL, *utmp = NULL;
|
||||
long text_len = 0, start = 0, length = 0, ppos = 0;
|
||||
long text_len = 0, start = 0, length = 0, ppos = 0;
|
||||
int store_locale = 0, ok = 0;
|
||||
Py_ssize_t i = 0, j = 0;
|
||||
|
||||
@ -409,7 +409,7 @@ html_check_spelling(PyObject *self, PyObject *args) {
|
||||
store_locale = PyObject_IsTrue(_store_locale);
|
||||
temp = PyObject_GetAttrString(locale, "langcode");
|
||||
if (temp == NULL) goto error;
|
||||
items = PyObject_CallFunctionObjArgs(split, text, temp, NULL);
|
||||
items = PyObject_CallFunctionObjArgs(split, text, temp, NULL);
|
||||
Py_DECREF(temp); temp = NULL;
|
||||
if (items == NULL) goto error;
|
||||
ans = PyTuple_New((2 * PyList_GET_SIZE(items)) + 1);
|
||||
@ -466,7 +466,7 @@ html_check_spelling(PyObject *self, PyObject *args) {
|
||||
error:
|
||||
Py_XDECREF(ans); ans = NULL;
|
||||
end:
|
||||
Py_XDECREF(items); Py_XDECREF(temp);
|
||||
Py_XDECREF(items); Py_XDECREF(temp);
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,10 @@ class GenericUnixServices : public QGenericUnixServices {
|
||||
* Qt will try to query the nativeInterface() without checking if it exists
|
||||
* leading to a segfault. For example, defaultHintStyleFromMatch() queries
|
||||
* the nativeInterface() without checking that it is NULL. See
|
||||
* https://bugreports.qt-project.org/browse/QTBUG-40946
|
||||
* This is no longer strictly neccessary since we implement our own fontconfig database
|
||||
* https://bugreports.qt-project.org/browse/QTBUG-40946
|
||||
* This is no longer strictly neccessary since we implement our own fontconfig database
|
||||
* (a patched version of the Qt fontconfig database). However, it is probably a good idea to
|
||||
* keep it unknown, since the headless QPA is used in contexts where a desktop environment
|
||||
* keep it unknown, since the headless QPA is used in contexts where a desktop environment
|
||||
* does not make sense anyway.
|
||||
*/
|
||||
QByteArray desktopEnvironment() const { return QByteArrayLiteral("UNKNOWN"); }
|
||||
|
@ -61,10 +61,10 @@ static PyObject* create_rsa_keypair(PyObject *self, PyObject *args) {
|
||||
Py_END_ALLOW_THREADS;
|
||||
if (!ret) { set_error("RSA_generate_key_ex"); goto error; }
|
||||
|
||||
ans = PyCapsule_New(KeyPair, NULL, free_rsa_keypair);
|
||||
ans = PyCapsule_New(KeyPair, NULL, free_rsa_keypair);
|
||||
if (ans == NULL) { PyErr_NoMemory(); goto error; }
|
||||
error:
|
||||
if(BigNumber) BN_free(BigNumber);
|
||||
if(BigNumber) BN_free(BigNumber);
|
||||
if (!ans && KeyPair) RSA_free(KeyPair);
|
||||
return ans;
|
||||
}
|
||||
@ -192,7 +192,7 @@ static int certificate_set_serial(X509 *cert)
|
||||
(sno = BN_to_ASN1_INTEGER(bn,sno)) != NULL &&
|
||||
X509_set_serialNumber(cert, sno) == 1)
|
||||
rv = 1;
|
||||
else
|
||||
else
|
||||
set_error("X509_set_serialNumber");
|
||||
BN_free(bn);
|
||||
ASN1_INTEGER_free(sno);
|
||||
@ -270,8 +270,8 @@ static PyObject* create_rsa_cert(PyObject *self, PyObject *args) {
|
||||
ok = 1;
|
||||
|
||||
error:
|
||||
if (!ok) {
|
||||
if (Cert) X509_free(Cert);
|
||||
if (!ok) {
|
||||
if (Cert) X509_free(Cert);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ static PyObject* logfont_to_dict(const ENUMLOGFONTEX *lf, const TEXTMETRIC *tm,
|
||||
full_name = wchar_to_unicode(lf->elfFullName);
|
||||
style = wchar_to_unicode(lf->elfStyle);
|
||||
script = wchar_to_unicode(lf->elfScript);
|
||||
|
||||
|
||||
return Py_BuildValue("{s:N, s:N, s:N, s:N, s:O, s:O, s:O, s:O, s:l}",
|
||||
"name", name,
|
||||
"full_name", full_name,
|
||||
@ -204,7 +204,7 @@ static PyObject* remove_system_font(PyObject *self, PyObject *args) {
|
||||
return Py_BuildValue("O", ok);
|
||||
}
|
||||
|
||||
static
|
||||
static
|
||||
PyMethodDef winfonts_methods[] = {
|
||||
{"enum_font_families", enum_font_families, METH_VARARGS,
|
||||
"enum_font_families()\n\n"
|
||||
|
@ -70,7 +70,7 @@ static unsigned int read_border_row(const QImage &img, const unsigned int width,
|
||||
row = reinterpret_cast<const QRgb*>(img.constScanLine(r));
|
||||
red_average = 0; green_average = 0; blue_average = 0;
|
||||
for (c = 0, pixel = row; c < width; c++, pixel++) {
|
||||
reds[c] = qRed(*pixel) / 255.0; greens[c] = qGreen(*pixel) / 255.0; blues[c] = qBlue(*pixel) / 255.0;
|
||||
reds[c] = qRed(*pixel) / 255.0; greens[c] = qGreen(*pixel) / 255.0; blues[c] = qBlue(*pixel) / 255.0;
|
||||
red_average += reds[c]; green_average += greens[c]; blue_average += blues[c];
|
||||
}
|
||||
red_average /= MAX(1, width); green_average /= MAX(1, width); blue_average /= MAX(1, width);
|
||||
@ -106,7 +106,7 @@ QImage remove_borders(const QImage &image, double fuzz) {
|
||||
if (bottom_border < height - 1) {
|
||||
transpose.rotate(90);
|
||||
timg = img.transformed(transpose);
|
||||
if (timg.isNull()) bad_alloc = true;
|
||||
if (timg.isNull()) bad_alloc = true;
|
||||
else {
|
||||
left_border = read_border_row(timg, height, width, buf, fuzz, true);
|
||||
if (left_border < width - 1) {
|
||||
@ -555,7 +555,7 @@ static inline void hull(const int x_offset, const int y_offset, const int w, con
|
||||
*dest = e; \
|
||||
}
|
||||
|
||||
QImage despeckle(const QImage &image) {
|
||||
QImage despeckle(const QImage &image) {
|
||||
ScopedGILRelease PyGILRelease;
|
||||
int length, x, y, j, i;
|
||||
QRgb *dest;
|
||||
@ -580,7 +580,7 @@ QImage despeckle(const QImage &image) {
|
||||
}
|
||||
// }}}
|
||||
|
||||
// overlay() {{{
|
||||
// overlay() {{{
|
||||
static inline unsigned int BYTE_MUL(unsigned int x, unsigned int a) {
|
||||
quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ffULL) * a;
|
||||
t = (t + ((t >> 8) & 0xff00ff00ff00ffULL) + 0x80008000800080ULL) >> 8;
|
||||
@ -588,7 +588,7 @@ static inline unsigned int BYTE_MUL(unsigned int x, unsigned int a) {
|
||||
return ((unsigned int)(t)) | ((unsigned int)(t >> 24));
|
||||
}
|
||||
|
||||
void overlay(const QImage &image, QImage &canvas, unsigned int left, unsigned int top) {
|
||||
void overlay(const QImage &image, QImage &canvas, unsigned int left, unsigned int top) {
|
||||
ScopedGILRelease PyGILRelease;
|
||||
QImage img(image);
|
||||
unsigned int cw = canvas.width(), ch = canvas.height(), iw = img.width(), ih = img.height(), r, c, right = 0, bottom = 0, height, width, s;
|
||||
@ -618,7 +618,7 @@ void overlay(const QImage &image, QImage &canvas, unsigned int left, unsigned in
|
||||
// Since the canvas has no transparency
|
||||
// the composite pixel is: canvas*(1-alpha) + src * alpha
|
||||
// but src is pre-multiplied, so it is:
|
||||
// canvas*(1-alpha) + src
|
||||
// canvas*(1-alpha) + src
|
||||
s = src[c];
|
||||
if (s >= 0xff000000) dest[left+c] = s;
|
||||
else if (s != 0) dest[left+c] = s + BYTE_MUL(dest[left+c], qAlpha(~s));
|
||||
|
@ -2,7 +2,7 @@
|
||||
* quantize.cpp
|
||||
* Copyright (C) 2016 Kovid Goyal <kovid at kovidgoyal.net>
|
||||
*
|
||||
* octree based image quantization.
|
||||
* octree based image quantization.
|
||||
* See https://www.microsoft.com/msj/archive/S3F1.aspx for a simple to follow
|
||||
* writeup on this algorithm
|
||||
*
|
||||
@ -112,10 +112,10 @@ public:
|
||||
}
|
||||
|
||||
// Adding colors to the tree {{{
|
||||
|
||||
|
||||
inline Node* create_child(const size_t level, const size_t depth, unsigned int *leaf_count, Node **reducible_nodes, Pool<Node> &node_pool) {
|
||||
Node *c = node_pool.checkout();
|
||||
if (level == depth) {
|
||||
if (level == depth) {
|
||||
c->is_leaf = true;
|
||||
(*leaf_count)++;
|
||||
} else {
|
||||
@ -150,12 +150,12 @@ public:
|
||||
// }}}
|
||||
|
||||
// Tree reduction {{{
|
||||
|
||||
|
||||
inline uint64_t total_error() const {
|
||||
Node *child = NULL;
|
||||
uint64_t ans = 0;
|
||||
for (int i = 0; i < MAX_DEPTH; i++) {
|
||||
if ((child = this->children[i]) != NULL)
|
||||
if ((child = this->children[i]) != NULL)
|
||||
ans += child->error_sum.red + child->error_sum.green + child->error_sum.blue;
|
||||
}
|
||||
return ans;
|
||||
@ -215,7 +215,7 @@ public:
|
||||
int i;
|
||||
Node *child;
|
||||
if (this->is_leaf) {
|
||||
color_table[*index] = qRgb(this->avg.red, this->avg.green, this->avg.blue);
|
||||
color_table[*index] = qRgb(this->avg.red, this->avg.green, this->avg.blue);
|
||||
this->index = (*index)++;
|
||||
} else {
|
||||
for (i = 0; i < MAX_DEPTH; i++) {
|
||||
@ -224,7 +224,7 @@ public:
|
||||
child->set_palette_colors(color_table, index, compute_parent_averages);
|
||||
if (compute_parent_averages) {
|
||||
this->pixel_count += child->pixel_count;
|
||||
this->sum.red += child->pixel_count * child->avg.red;
|
||||
this->sum.red += child->pixel_count * child->avg.red;
|
||||
this->sum.green += child->pixel_count * child->avg.green;
|
||||
this->sum.blue += child->pixel_count * child->avg.blue;
|
||||
}
|
||||
@ -372,12 +372,12 @@ QImage quantize(const QImage &image, unsigned int maximum_colors, bool dither, c
|
||||
|
||||
maximum_colors = MAX(2, MIN(MAX_COLORS, maximum_colors));
|
||||
if (img.hasAlphaChannel()) throw std::out_of_range("Cannot quantize image with transparency");
|
||||
if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_Indexed8) {
|
||||
img = img.convertToFormat(QImage::Format_RGB32);
|
||||
if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_Indexed8) {
|
||||
img = img.convertToFormat(QImage::Format_RGB32);
|
||||
if (img.isNull()) throw std::bad_alloc();
|
||||
}
|
||||
}
|
||||
// There can be no more than MAX_LEAVES * 8 nodes. Add 1 in case there is an off by 1 error somewhere.
|
||||
Pool<Node> node_pool((MAX_LEAVES + 1) * 8);
|
||||
Pool<Node> node_pool((MAX_LEAVES + 1) * 8);
|
||||
if (palette.size() > 0) {
|
||||
// Quantizing to fixed palette
|
||||
leaf_count = read_colors(palette, root, depth, reducible_nodes, node_pool);
|
||||
|
@ -18,7 +18,7 @@
|
||||
#define LZ_ONEBUFFER 1
|
||||
#define LAZY 1
|
||||
|
||||
/*
|
||||
/*
|
||||
* Document here
|
||||
*/
|
||||
#include <stdio.h>
|
||||
@ -41,7 +41,7 @@ void lz_init(lz_info *lzi, int wsize, int max_dist,
|
||||
output_match_t output_match,
|
||||
output_literal_t output_literal, void *user_data)
|
||||
{
|
||||
/* the reason for the separate max_dist value is LZX can't reach the
|
||||
/* the reason for the separate max_dist value is LZX can't reach the
|
||||
first three characters in its nominal window. But using a smaller
|
||||
window results in inefficiency when dealing with reset intervals
|
||||
which are the length of the nominal window */
|
||||
@ -55,12 +55,12 @@ void lz_init(lz_info *lzi, int wsize, int max_dist,
|
||||
lzi->min_match = min_match;
|
||||
if (lzi->min_match < 3) lzi->min_match = 3;
|
||||
|
||||
lzi->max_dist = max_dist;
|
||||
lzi->block_buf_size = wsize + lzi->max_dist;
|
||||
lzi->max_dist = max_dist;
|
||||
lzi->block_buf_size = wsize + lzi->max_dist;
|
||||
lzi->block_buf = malloc(lzi->block_buf_size);
|
||||
lzi->block_bufe = lzi->block_buf + lzi->block_buf_size;
|
||||
assert(lzi->block_buf != NULL);
|
||||
|
||||
|
||||
lzi->cur_loc = 0;
|
||||
lzi->block_loc = 0;
|
||||
lzi->chars_in_buf = 0;
|
||||
@ -109,7 +109,7 @@ int tmp_output_match(lz_info *lzi, int match_pos, int match_len)
|
||||
{
|
||||
lz_user_data *lzud = (lz_user_data *)lzi->user_data;
|
||||
int mod_match_loc;
|
||||
|
||||
|
||||
mod_match_loc = match_pos;
|
||||
|
||||
fprintf(lzud->outfile, "(%d, %d)(%d)\n", match_pos, match_len, mod_match_loc);
|
||||
@ -275,13 +275,13 @@ static void lz_analyze_block(lz_info *lzi)
|
||||
#endif
|
||||
}
|
||||
|
||||
void lz_stop_compressing(lz_info *lzi)
|
||||
void lz_stop_compressing(lz_info *lzi)
|
||||
{
|
||||
lzi->stop = 1;
|
||||
/* fprintf(stderr, "Stopping...\n");*/
|
||||
}
|
||||
|
||||
int lz_compress(lz_info *lzi, int nchars)
|
||||
int lz_compress(lz_info *lzi, int nchars)
|
||||
{
|
||||
|
||||
unsigned char *bbp, *bbe;
|
||||
@ -306,7 +306,7 @@ int lz_compress(lz_info *lzi, int nchars)
|
||||
#endif
|
||||
memmove(lzi->block_buf, lzi->block_buf + lzi->chars_in_buf - bytes_to_move,
|
||||
bytes_to_move);
|
||||
|
||||
|
||||
lzi->block_loc = bytes_to_move - residual;
|
||||
lzi->chars_in_buf = bytes_to_move;
|
||||
#ifdef DEBUG_ANALYZE_BLOCK
|
||||
@ -360,7 +360,7 @@ int lz_compress(lz_info *lzi, int nchars)
|
||||
len = 1;
|
||||
/* this is the lazy eval case */
|
||||
}
|
||||
else
|
||||
else
|
||||
#endif
|
||||
if (lzi->output_match(lzi, (*prevp - lzi->block_buf) - lzi->block_loc,
|
||||
len) < 0) {
|
||||
@ -370,7 +370,7 @@ int lz_compress(lz_info *lzi, int nchars)
|
||||
}
|
||||
else
|
||||
len = 1;
|
||||
|
||||
|
||||
if (len < lzi->min_match) {
|
||||
assert(len == 1);
|
||||
lzi->output_literal(lzi, *bbp);
|
||||
|
@ -107,15 +107,15 @@ static int cmp_leaves(const void *in_a, const void *in_b)
|
||||
{
|
||||
const struct h_elem *a = in_a;
|
||||
const struct h_elem *b = in_b;
|
||||
|
||||
|
||||
if (!a->freq && b->freq)
|
||||
return 1;
|
||||
if (a->freq && !b->freq)
|
||||
return -1;
|
||||
|
||||
|
||||
if (a->freq == b->freq)
|
||||
return a->sym - b->sym;
|
||||
|
||||
|
||||
return a->freq - b->freq;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ cmp_pathlengths(const void *in_a, const void *in_b)
|
||||
{
|
||||
const struct h_elem *a = in_a;
|
||||
const struct h_elem *b = in_b;
|
||||
|
||||
|
||||
if (a->pathlength == b->pathlength)
|
||||
#if 0
|
||||
return a->sym - b->sym;
|
||||
@ -136,7 +136,7 @@ cmp_pathlengths(const void *in_a, const void *in_b)
|
||||
}
|
||||
|
||||
/* standard huffman building algorithm */
|
||||
static void
|
||||
static void
|
||||
build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
{
|
||||
h_elem *leaves = malloc(nelem * sizeof(h_elem));
|
||||
@ -180,13 +180,13 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
}
|
||||
assert (!codes_too_long);
|
||||
}
|
||||
|
||||
|
||||
cur_leaf = leaves;
|
||||
next_inode = cur_inode = inodes;
|
||||
|
||||
|
||||
do {
|
||||
f1 = f2 = NULL;
|
||||
if (leaves_left &&
|
||||
if (leaves_left &&
|
||||
((cur_inode == next_inode) ||
|
||||
(cur_leaf->freq <= cur_inode->freq))) {
|
||||
f1 = (ih_elem *)cur_leaf++;
|
||||
@ -195,8 +195,8 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
else if (cur_inode != next_inode) {
|
||||
f1 = cur_inode++;
|
||||
}
|
||||
|
||||
if (leaves_left &&
|
||||
|
||||
if (leaves_left &&
|
||||
((cur_inode == next_inode) ||
|
||||
(cur_leaf->freq <= cur_inode->freq))) {
|
||||
f2 = (ih_elem *)cur_leaf++;
|
||||
@ -205,7 +205,7 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
else if (cur_inode != next_inode) {
|
||||
f2 = cur_inode++;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_HUFFMAN
|
||||
fprintf(stderr, "%d %d\n", f1, f2);
|
||||
#endif
|
||||
@ -231,11 +231,11 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
while (f1 && f2);
|
||||
}
|
||||
while (codes_too_long);
|
||||
|
||||
|
||||
#ifdef DEBUG_HUFFMAN
|
||||
cur_inode = inodes;
|
||||
while (cur_inode < next_inode) {
|
||||
fprintf(stderr, "%d l: %3d%c r: %3d%c freq: %8d\n",
|
||||
fprintf(stderr, "%d l: %3d%c r: %3d%c freq: %8d\n",
|
||||
cur_inode - inodes,
|
||||
(cur_inode->left->sym!=-1)?(((struct h_elem *)cur_inode->left)-leaves):(cur_inode->left-inodes),
|
||||
(cur_inode->left->sym!=-1)?'l':'i',
|
||||
@ -246,7 +246,7 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
cur_inode++;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* now traverse tree depth-first */
|
||||
cur_inode = next_inode - 1;
|
||||
pathlength = 0;
|
||||
@ -262,17 +262,17 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
else {
|
||||
/* mark node */
|
||||
cur_inode->pathlength = pathlength;
|
||||
#if 0
|
||||
#if 0
|
||||
if (cur_inode->right) {
|
||||
/* right node of previously unmarked node is unmarked */
|
||||
cur_inode = cur_inode->right;
|
||||
cur_inode->pathlength = -1;
|
||||
pathlength++;
|
||||
}
|
||||
else
|
||||
else
|
||||
#endif
|
||||
{
|
||||
|
||||
|
||||
/* time to come up. Keep coming up until an unmarked node is reached */
|
||||
/* or the tree is exhausted */
|
||||
do {
|
||||
@ -292,16 +292,16 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
}
|
||||
}
|
||||
while (cur_inode);
|
||||
|
||||
|
||||
#ifdef DEBUG_HUFFMAN
|
||||
cur_inode = inodes;
|
||||
while (cur_inode < next_inode) {
|
||||
fprintf(stderr, "%d l: %3d%c r: %3d%c freq: %8d pathlength %4d\n",
|
||||
fprintf(stderr, "%d l: %3d%c r: %3d%c freq: %8d pathlength %4d\n",
|
||||
cur_inode - inodes,
|
||||
(cur_inode->left->sym!=-1)?(((struct h_elem *)cur_inode->left)-leaves):(cur_inode->left-inodes),
|
||||
(cur_inode->left->sym!=-1)?'l':'i',
|
||||
(cur_inode->right->sym!=-1)?(((struct h_elem *)cur_inode->right)-leaves):(cur_inode->right-inodes),
|
||||
(cur_inode->right->sym!=-1)?'l':'i',
|
||||
(cur_inode->right->sym!=-1)?'l':'i',
|
||||
(cur_inode->freq),
|
||||
(cur_inode->pathlength)
|
||||
);
|
||||
@ -309,11 +309,11 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
}
|
||||
#endif
|
||||
free(inodes);
|
||||
|
||||
|
||||
/* the pathlengths are already in order, so this sorts by symbol */
|
||||
qsort(leaves, nelem, sizeof(h_elem), cmp_pathlengths);
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
Microsoft's second condition on its canonical huffman codes is:
|
||||
|
||||
For each level, starting at the deepest level of the tree and then
|
||||
@ -321,13 +321,13 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
alternative way of stating this constraint is that if any tree node
|
||||
has children then all tree nodes to the left of it with the same path
|
||||
length must also have children.
|
||||
|
||||
|
||||
These 'alternatives' are not equivalent. The latter alternative gives
|
||||
the common canonical code where the longest code is all zeros. The former
|
||||
gives an opposite code where the longest code is all ones. Microsoft uses the
|
||||
former alternative.
|
||||
**/
|
||||
|
||||
|
||||
#if 0
|
||||
pathlength = leaves[0].pathlength;
|
||||
cur_code = 0;
|
||||
@ -355,12 +355,12 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
cur_code++;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG_HUFFMAN
|
||||
for (i = 0; i < nleaves; i++) {
|
||||
char code[18];
|
||||
int j;
|
||||
|
||||
|
||||
cur_code = leaves[i].code;
|
||||
code[leaves[i].pathlength] = 0;
|
||||
for (j = leaves[i].pathlength-1; j >= 0; j--) {
|
||||
@ -387,19 +387,19 @@ build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
|
||||
leaves[1].code = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
memset(tree, 0, nelem * sizeof(huff_entry));
|
||||
for (i = 0; i < nleaves; i++) {
|
||||
tree[leaves[i].sym].codelength = leaves[i].pathlength;
|
||||
tree[leaves[i].sym].code = leaves[i].code;
|
||||
}
|
||||
|
||||
|
||||
free(leaves);
|
||||
}
|
||||
|
||||
|
||||
/* from Stuart Caie's code -- I'm hoping this code is too small to encumber
|
||||
this file. If not, you could rip it out and hard-code the tables */
|
||||
|
||||
|
||||
static void lzx_init_static(void)
|
||||
{
|
||||
int i, j;
|
||||
@ -478,7 +478,7 @@ lzx_get_chars(lz_info *lzi, int n, unsigned char *buf)
|
||||
lzud->left_in_block -= chars_read;
|
||||
#else
|
||||
lzud->left_in_frame -= chars_read % LZX_FRAME_SIZE;
|
||||
if (lzud->left_in_frame < 0)
|
||||
if (lzud->left_in_frame < 0)
|
||||
lzud->left_in_frame += LZX_FRAME_SIZE;
|
||||
#endif
|
||||
if ((chars_read < n) && (lzud->left_in_frame)) {
|
||||
@ -559,7 +559,7 @@ static int find_match_at(lz_info *lzi, int loc, int match_len, int *match_locp)
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
static void check_entropy(lzxc_data *lzud, int main_index)
|
||||
static void check_entropy(lzxc_data *lzud, int main_index)
|
||||
{
|
||||
/* entropy = - sum_alphabet P(x) * log2 P(x) */
|
||||
/* entropy = - sum_alphabet f(x)/N * log2 (f(x)/N) */
|
||||
@ -567,12 +567,12 @@ static void check_entropy(lzxc_data *lzud, int main_index)
|
||||
/* entropy = - 1/N (sum_alphabet f(x) * log2 f(x)) - sum_alphabet f(x) log2 N */
|
||||
/* entropy = - 1/N (sum_alphabet f(x) * log2 f(x)) - log2 N sum_alphabet f(x) */
|
||||
/* entropy = - 1/N (sum_alphabet f(x) * log2 f(x)) - N * log2 N */
|
||||
|
||||
|
||||
/* entropy = - 1/N ((sum_alphabet f(x) * log2 f(x) ) - N * log2 N) */
|
||||
/* entropy = - 1/N ((sum_alphabet f(x) * ln f(x) * 1/ln 2) - N * ln N * 1/ln 2) */
|
||||
/* entropy = 1/(N ln 2) (N * ln N - (sum_alphabet f(x) * ln f(x))) */
|
||||
/* entropy = 1/(N ln 2) (N * ln N + (sum_alphabet -f(x) * ln f(x))) */
|
||||
|
||||
|
||||
/* entropy = 1/(N ln 2) ( sum_alphabet ln N * f(x) + (sum_alphabet -f(x) * ln f(x))) */
|
||||
/* entropy = 1/(N ln 2) ( sum_alphabet ln N * f(x) + (-f(x) * ln f(x))) */
|
||||
/* entropy = -1/(N ln 2) ( sum_alphabet -ln N * f(x) + (f(x) * ln f(x))) */
|
||||
@ -582,14 +582,14 @@ static void check_entropy(lzxc_data *lzud, int main_index)
|
||||
/* entropy = -1/N ( sum_alphabet f(x)(log2 f(x)/N)) */
|
||||
/* entropy = - ( sum_alphabet f(x)/N(log2 f(x)/N)) */
|
||||
/* entropy = - ( sum_alphabet P(x)(log2 P(x))) */
|
||||
|
||||
|
||||
|
||||
double freq;
|
||||
double n_ln_n;
|
||||
double rn_ln2;
|
||||
double cur_ratio;
|
||||
int n;
|
||||
|
||||
|
||||
/* delete old entropy accumulation */
|
||||
if (lzud->main_freq_table[main_index] != 1) {
|
||||
freq = (double)lzud->main_freq_table[main_index]-1;
|
||||
@ -638,7 +638,7 @@ lzx_output_match(lz_info *lzi, int match_pos, int match_len)
|
||||
int i;
|
||||
int pos;
|
||||
for (i = 0; i < match_len; i++) {
|
||||
|
||||
|
||||
#ifdef NONSLIDE
|
||||
pos = match_pos + lzi->block_loc + i;
|
||||
fprintf(stderr, "%c", lzi->block_buf[pos]);
|
||||
@ -701,13 +701,13 @@ lzx_output_match(lz_info *lzi, int match_pos, int match_len)
|
||||
lzud->R0 = -match_pos;
|
||||
|
||||
/* calculate position base using binary search of table; if log2 can be
|
||||
done in hardware, approximation might work;
|
||||
done in hardware, approximation might work;
|
||||
trunc(log2(formatted_offset*formatted_offset)) gets either the proper
|
||||
position slot or the next one, except for slots 0, 1, and 39-49
|
||||
|
||||
Slots 0-1 are handled by the R0-R1 procedures
|
||||
|
||||
Slots 36-49 (formatted_offset >= 262144) can be found by
|
||||
Slots 36-49 (formatted_offset >= 262144) can be found by
|
||||
(formatted_offset/131072) + 34 ==
|
||||
(formatted_offset >> 17) + 34;
|
||||
*/
|
||||
@ -796,7 +796,7 @@ lzx_output_match(lz_info *lzi, int match_pos, int match_len)
|
||||
return 0; /* accept the match */
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
lzx_output_literal(lz_info *lzi, unsigned char ch)
|
||||
{
|
||||
lzxc_data *lzud = (lzxc_data *)lzi->user_data;
|
||||
@ -847,7 +847,7 @@ static void lzx_write_bits(lzxc_data *lzxd, int nbits, uint32_t bits)
|
||||
nbits -= shift_bits;
|
||||
cur_bits = 0;
|
||||
}
|
||||
/* (cur_bits + nbits) < 16. If nbits = 0, we're done.
|
||||
/* (cur_bits + nbits) < 16. If nbits = 0, we're done.
|
||||
otherwise move bits in */
|
||||
shift_bits = nbits;
|
||||
mask_bits = (1U << shift_bits) - 1;
|
||||
@ -893,18 +893,18 @@ lzx_write_compressed_literals(lzxc_data *lzxd, int block_type)
|
||||
/*
|
||||
* 0x80000000 | bit 31 in intelligent bit ordering
|
||||
* (position_slot << 25) | bits 30-25
|
||||
* (position_footer << 8) | bits 8-24
|
||||
* (position_footer << 8) | bits 8-24
|
||||
* (match_len - MIN_MATCH); bits 0-7
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
match_len_m2 = block_code & 0xFF; /* 8 bits */
|
||||
position_footer = (block_code >> 8)& 0x1FFFF; /* 17 bits */
|
||||
position_slot = (block_code >> 25) & 0x3F; /* 6 bits */
|
||||
|
||||
#ifdef DEBUG_MATCHES_2
|
||||
fprintf(stderr, "%08x, %3d %2d %d\n", lzxd->len_uncompressed_input + frame_count, match_len_m2, position_slot, position_footer);
|
||||
#endif
|
||||
#endif
|
||||
if (match_len_m2 < NUM_PRIMARY_LENGTHS) {
|
||||
length_header = match_len_m2;
|
||||
length_footer = 255; /* personal encoding for NULL */
|
||||
@ -955,7 +955,7 @@ lzx_write_compressed_literals(lzxc_data *lzxd, int block_type)
|
||||
lzxd->len_uncompressed_input += frame_count;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
lzx_write_compressed_tree(struct lzxc_data *lzxd,
|
||||
struct huff_entry *tree, uint8_t *prevlengths,
|
||||
int treesize)
|
||||
@ -1011,7 +1011,7 @@ lzx_write_compressed_tree(struct lzxc_data *lzxd,
|
||||
*codep++ = 19;
|
||||
*runp++ = excess;
|
||||
freqs[19]++;
|
||||
/* right, MS lies again. Code is NOT
|
||||
/* right, MS lies again. Code is NOT
|
||||
prev_len + len (mod 17), it's prev_len - len (mod 17)*/
|
||||
*codep = prevlengths[i-cur_run] - last_len;
|
||||
if (*codep > 16) *codep += 17;
|
||||
@ -1078,7 +1078,7 @@ lzx_write_compressed_tree(struct lzxc_data *lzxd,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
lzxc_reset(lzxc_data *lzxd)
|
||||
{
|
||||
lzxd->need_1bit_header = 1;
|
||||
@ -1097,7 +1097,7 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
|
||||
long comp_bits;
|
||||
long comp_bits_ovh;
|
||||
long uncomp_length;
|
||||
|
||||
|
||||
if ((lzxd->block_size != block_size) || (lzxd->block_codes == NULL)) {
|
||||
if (lzxd->block_codes != NULL) free(lzxd->block_codes);
|
||||
lzxd->block_size = block_size;
|
||||
@ -1118,13 +1118,13 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
|
||||
lz_compress(lzxd->lzi, lzxd->left_in_block);
|
||||
if (lzxd->left_in_frame == 0)
|
||||
lzxd->left_in_frame = LZX_FRAME_SIZE;
|
||||
|
||||
if ((lzxd->subdivide<0) || !lzxd->left_in_block ||
|
||||
|
||||
if ((lzxd->subdivide<0) || !lzxd->left_in_block ||
|
||||
(!lz_left_to_process(lzxd->lzi) && lzxd->at_eof(lzxd->in_arg))) {
|
||||
/* now one block is LZ-analyzed. */
|
||||
/* time to write it out */
|
||||
uncomp_length = lzxd->block_size - lzxd->left_in_block - written_sofar;
|
||||
/* uncomp_length will sometimes be 0 when input length is
|
||||
/* uncomp_length will sometimes be 0 when input length is
|
||||
an exact multiple of frame size */
|
||||
if (uncomp_length == 0)
|
||||
continue;
|
||||
@ -1134,7 +1134,7 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
|
||||
#endif
|
||||
lzxd->subdivide = 1;
|
||||
}
|
||||
|
||||
|
||||
if (lzxd->need_1bit_header) {
|
||||
/* one bit Intel preprocessing header */
|
||||
/* always 0 because this implementation doesn't do Intel preprocessing */
|
||||
@ -1169,32 +1169,32 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
|
||||
/* now write out the aligned offset trees if present */
|
||||
if (block_type == LZX_ALIGNED_OFFSET_BLOCK) {
|
||||
for (i = 0; i < LZX_ALIGNED_SIZE; i++) {
|
||||
lzx_write_bits(lzxd, 3, lzxd->aligned_tree[i].codelength);
|
||||
lzx_write_bits(lzxd, 3, lzxd->aligned_tree[i].codelength);
|
||||
}
|
||||
}
|
||||
/* end extra bits */
|
||||
build_huffman_tree(lzxd->main_tree_size, LZX_MAX_CODE_LENGTH,
|
||||
lzxd->main_freq_table, lzxd->main_tree);
|
||||
build_huffman_tree(NUM_SECONDARY_LENGTHS, 16,
|
||||
build_huffman_tree(NUM_SECONDARY_LENGTHS, 16,
|
||||
lzxd->length_freq_table, lzxd->length_tree);
|
||||
|
||||
|
||||
|
||||
/* now write the pre-tree and tree for main 1 */
|
||||
lzx_write_compressed_tree(lzxd, lzxd->main_tree, lzxd->prev_main_treelengths, NUM_CHARS);
|
||||
|
||||
|
||||
/* now write the pre-tree and tree for main 2*/
|
||||
lzx_write_compressed_tree(lzxd, lzxd->main_tree + NUM_CHARS,
|
||||
lzxd->prev_main_treelengths + NUM_CHARS,
|
||||
lzxd->main_tree_size - NUM_CHARS);
|
||||
|
||||
|
||||
/* now write the pre tree and tree for length */
|
||||
lzx_write_compressed_tree(lzxd, lzxd->length_tree, lzxd->prev_length_treelengths,
|
||||
NUM_SECONDARY_LENGTHS);
|
||||
|
||||
|
||||
/* now write literals */
|
||||
lzx_write_compressed_literals(lzxd, block_type);
|
||||
|
||||
|
||||
/* copy treelengths somewhere safe to do delta compression */
|
||||
for (i = 0; i < lzxd->main_tree_size; i++) {
|
||||
lzxd->prev_main_treelengths[i] = lzxd->main_tree[i].codelength;
|
||||
@ -1205,7 +1205,7 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
|
||||
lzxd->main_entropy = 0.0;
|
||||
lzxd->last_ratio = 9999999.0;
|
||||
lzxd->block_codesp = lzxd->block_codes;
|
||||
|
||||
|
||||
memset(lzxd->length_freq_table, 0, NUM_SECONDARY_LENGTHS * sizeof(int));
|
||||
memset(lzxd->main_freq_table, 0, lzxd->main_tree_size * sizeof(int));
|
||||
memset(lzxd->aligned_freq_table, 0, LZX_ALIGNED_SIZE * sizeof(int));
|
||||
@ -1215,7 +1215,7 @@ int lzxc_compress_block(lzxc_data *lzxd, int block_size, int subdivide)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lzxc_init(struct lzxc_data **lzxdp, int wsize_code,
|
||||
int lzxc_init(struct lzxc_data **lzxdp, int wsize_code,
|
||||
lzxc_get_bytes_t get_bytes, void *get_bytes_arg,
|
||||
lzxc_at_eof_t at_eof,
|
||||
lzxc_put_bytes_t put_bytes, void *put_bytes_arg,
|
||||
|
@ -302,7 +302,7 @@ static int lzxd_read_lens(struct lzxd_stream *lzx, unsigned char *lens,
|
||||
int z;
|
||||
|
||||
RESTORE_BITS;
|
||||
|
||||
|
||||
/* read lengths for pretree (20 symbols, lengths stored in fixed 4 bits) */
|
||||
for (x = 0; x < 20; x++) {
|
||||
READ_BITS(y, 4);
|
||||
@ -525,7 +525,7 @@ int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes) {
|
||||
j = 0; READ_BITS(i, 1); if (i) { READ_BITS(i, 16); READ_BITS(j, 16); }
|
||||
lzx->intel_filesize = (i << 16) | j;
|
||||
lzx->header_read = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* calculate size of frame: all frames are 32k except the final frame
|
||||
* which is 32kb or less. this can only be calculated when lzx->length
|
||||
@ -636,7 +636,7 @@ int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes) {
|
||||
match_length += length_footer;
|
||||
}
|
||||
match_length += LZX_MIN_MATCH;
|
||||
|
||||
|
||||
/* get match offset */
|
||||
switch ((match_offset = (main_element >> 3))) {
|
||||
case 0: match_offset = R0; break;
|
||||
@ -654,7 +654,7 @@ int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes) {
|
||||
D(("match ran over window wrap"))
|
||||
return lzx->error = MSPACK_ERR_DECRUNCH;
|
||||
}
|
||||
|
||||
|
||||
/* copy match */
|
||||
rundest = &window[window_posn];
|
||||
i = match_length;
|
||||
@ -817,7 +817,7 @@ int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes) {
|
||||
window_posn - lzx->frame_posn, frame_size))
|
||||
/* Ignored */
|
||||
#if 0
|
||||
return lzx->error = MSPACK_ERR_DECRUNCH;
|
||||
return lzx->error = MSPACK_ERR_DECRUNCH;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ static double process_item(MatchInfo *m, Stack *stack, int32_t *final_positions,
|
||||
// No memoized result, calculate the score
|
||||
for (i = nidx; i < m->needle_len;) {
|
||||
nidx = i;
|
||||
U16_FWD_1(m->needle, i, m->needle_len);// i now points to next char in needle
|
||||
U16_FWD_1(m->needle, i, m->needle_len);// i now points to next char in needle
|
||||
search = searches[nidx];
|
||||
if (search == NULL || m->haystack_len - hidx < m->needle_len - nidx) { score = 0.0; break; }
|
||||
status = U_ZERO_ERROR; // We ignore any errors as we already know that hidx is correct
|
||||
@ -201,20 +201,20 @@ static double process_item(MatchInfo *m, Stack *stack, int32_t *final_positions,
|
||||
status = U_ZERO_ERROR;
|
||||
pos = usearch_next(search, &status);
|
||||
if (pos == USEARCH_DONE) { score = 0.0; break; } // No matches found
|
||||
distance = u_countChar32(m->haystack + last_idx, pos - last_idx);
|
||||
distance = u_countChar32(m->haystack + last_idx, pos - last_idx);
|
||||
if (distance <= 1) score_for_char = m->max_score_per_char;
|
||||
else {
|
||||
U16_GET(m->haystack, 0, pos, m->haystack_len, hc);
|
||||
U16_GET(m->haystack, 0, pos, m->haystack_len, hc);
|
||||
j = pos;
|
||||
U16_PREV(m->haystack, 0, j, lc); // lc is the prev character
|
||||
score_for_char = calc_score_for_char(m, lc, hc, distance);
|
||||
}
|
||||
j = pos;
|
||||
U16_NEXT(m->haystack, j, m->haystack_len, hc);
|
||||
U16_NEXT(m->haystack, j, m->haystack_len, hc);
|
||||
hidx = j;
|
||||
if (m->haystack_len - hidx >= m->needle_len - nidx) stack_push(stack, hidx, nidx, last_idx, score, positions);
|
||||
last_idx = pos;
|
||||
positions[nidx] = pos;
|
||||
last_idx = pos;
|
||||
positions[nidx] = pos;
|
||||
score += score_for_char;
|
||||
} // for(i) iterate over needle
|
||||
mem.score = score; memcpy(mem.positions, positions, sizeof(*positions) * m->needle_len);
|
||||
@ -256,7 +256,7 @@ static void free_searches(UStringSearch **searches, int32_t count) {
|
||||
|
||||
static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UChar *needle, Match *match_results, int32_t *final_positions, int32_t needle_char_len, UCollator *collator, UChar *level1, UChar *level2, UChar *level3) {
|
||||
Stack stack = {0};
|
||||
int32_t i = 0, maxhl = 0;
|
||||
int32_t i = 0, maxhl = 0;
|
||||
int32_t r = 0, *positions = NULL;
|
||||
MatchInfo *matches = NULL;
|
||||
bool ok = FALSE;
|
||||
@ -340,7 +340,7 @@ static void free_matcher(Matcher *self) {
|
||||
if (self->items != NULL) {
|
||||
for (i = 0; i < self->item_count; i++) { nullfree(self->items[i]); }
|
||||
}
|
||||
nullfree(self->items); nullfree(self->item_lengths);
|
||||
nullfree(self->items); nullfree(self->item_lengths);
|
||||
nullfree(self->level1); nullfree(self->level2); nullfree(self->level3);
|
||||
if (self->collator != NULL) ucol_close(self->collator); self->collator = NULL;
|
||||
}
|
||||
@ -361,7 +361,7 @@ Matcher_init(Matcher *self, PyObject *args, PyObject *kwds)
|
||||
UCollator *col = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOOOO", &items, &collator, &level1, &level2, &level3)) return -1;
|
||||
|
||||
|
||||
// Clone the passed in collator (cloning is needed as collators are not thread safe)
|
||||
if (!PyCapsule_CheckExact(collator)) { PyErr_SetString(PyExc_TypeError, "Collator must be a capsule"); return -1; }
|
||||
col = (UCollator*)PyCapsule_GetPointer(collator, NULL);
|
||||
@ -395,7 +395,7 @@ end:
|
||||
return (PyErr_Occurred()) ? -1 : 0;
|
||||
}
|
||||
// Matcher.__init__() }}}
|
||||
|
||||
|
||||
// Matcher.calculate_scores {{{
|
||||
static PyObject *
|
||||
Matcher_calculate_scores(Matcher *self, PyObject *args) {
|
||||
|
@ -34,10 +34,10 @@ static PyObject* monotonic(PyObject *self, PyObject *args) {
|
||||
/* QueryPerformanceCounter() is wildly inaccurate, so we use the more stable
|
||||
* the lower resolution GetTickCount64() (this is what python 3.x uses)
|
||||
* static LARGE_INTEGER frequency = {0}, ts = {0};
|
||||
* static PyObject* monotonic(PyObject *self, PyObject *args) {
|
||||
* static PyObject* monotonic(PyObject *self, PyObject *args) {
|
||||
* if (!QueryPerformanceCounter(&ts)) { PyErr_SetFromWindowsErr(0); return NULL; }
|
||||
* return PyFloat_FromDouble(((double)ts.QuadPart)/frequency.QuadPart);
|
||||
* }
|
||||
* return PyFloat_FromDouble(((double)ts.QuadPart)/frequency.QuadPart);
|
||||
* }
|
||||
*/
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* D3DES (V5.09) -
|
||||
/* D3DES (V5.09) -
|
||||
*
|
||||
* A portable, public domain, version of the Data Encryption Standard.
|
||||
*
|
||||
@ -6,7 +6,7 @@
|
||||
* Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
|
||||
* code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
|
||||
* Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
|
||||
* for humouring me on.
|
||||
* for humouring me on.
|
||||
*
|
||||
* THIS SOFTWARE PLACED IN THE PUBLIC DOMAIN BY THE AUTHOUR
|
||||
* 920825 19:42 EDST
|
||||
@ -14,14 +14,14 @@
|
||||
* Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
|
||||
* (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
|
||||
*/
|
||||
|
||||
|
||||
#include "d3des.h"
|
||||
|
||||
|
||||
static void scrunch(unsigned char *, unsigned long *);
|
||||
static void unscrun(unsigned long *, unsigned char *);
|
||||
static void desfunc(unsigned long *, unsigned long *);
|
||||
static void cookey(unsigned long *);
|
||||
|
||||
|
||||
static unsigned long KnL[32] = { 0L };
|
||||
/*
|
||||
static unsigned long KnR[32] = { 0L };
|
||||
@ -31,10 +31,10 @@ static unsigned char Df_Key[24] = {
|
||||
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
|
||||
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };
|
||||
*/
|
||||
|
||||
|
||||
static unsigned short bytebit[8] = {
|
||||
0200, 0100, 040, 020, 010, 04, 02, 01 };
|
||||
|
||||
|
||||
static unsigned long bigbyte[24] = {
|
||||
0x800000L, 0x400000L, 0x200000L, 0x100000L,
|
||||
0x80000L, 0x40000L, 0x20000L, 0x10000L,
|
||||
@ -42,24 +42,24 @@ static unsigned long bigbyte[24] = {
|
||||
0x800L, 0x400L, 0x200L, 0x100L,
|
||||
0x80L, 0x40L, 0x20L, 0x10L,
|
||||
0x8L, 0x4L, 0x2L, 0x1L };
|
||||
|
||||
|
||||
/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
|
||||
|
||||
|
||||
static unsigned char pc1[56] = {
|
||||
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
|
||||
9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
|
||||
62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
|
||||
13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 };
|
||||
|
||||
|
||||
static unsigned char totrot[16] = {
|
||||
1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
|
||||
|
||||
|
||||
static unsigned char pc2[48] = {
|
||||
13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
|
||||
22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
|
||||
40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
|
||||
43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
|
||||
|
||||
|
||||
void deskey(key, edf) /* Thanks to James Gillogly & Phil Karn! */
|
||||
unsigned char *key;
|
||||
short edf;
|
||||
@ -67,7 +67,7 @@ short edf;
|
||||
int i, j, l, m, n;
|
||||
unsigned char pc1m[56], pcr[56];
|
||||
unsigned long kn[32];
|
||||
|
||||
|
||||
for ( j = 0; j < 56; j++ ) {
|
||||
l = pc1[j];
|
||||
m = l & 07;
|
||||
@ -96,14 +96,14 @@ short edf;
|
||||
cookey(kn);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void cookey(raw1)
|
||||
unsigned long *raw1;
|
||||
{
|
||||
unsigned long *cook, *raw0;
|
||||
unsigned long dough[32];
|
||||
int i;
|
||||
|
||||
|
||||
cook = dough;
|
||||
for( i = 0; i < 16; i++, raw1++ ) {
|
||||
raw0 = raw1++;
|
||||
@ -119,38 +119,38 @@ unsigned long *raw1;
|
||||
usekey(dough);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void cpkey(into)
|
||||
unsigned long *into;
|
||||
{
|
||||
unsigned long *from, *endp;
|
||||
|
||||
|
||||
from = KnL, endp = &KnL[32];
|
||||
while( from < endp ) *into++ = *from++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void usekey(from)
|
||||
unsigned long *from;
|
||||
{
|
||||
unsigned long *to, *endp;
|
||||
|
||||
|
||||
to = KnL, endp = &KnL[32];
|
||||
while( to < endp ) *to++ = *from++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void des(inblock, outblock)
|
||||
unsigned char *inblock, *outblock;
|
||||
{
|
||||
unsigned long work[2];
|
||||
|
||||
|
||||
scrunch(inblock, work);
|
||||
desfunc(work, KnL);
|
||||
unscrun(work, outblock);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void scrunch(outof, into)
|
||||
unsigned char *outof;
|
||||
@ -167,7 +167,7 @@ unsigned long *into;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void unscrun(outof, into)
|
||||
unsigned long *outof;
|
||||
unsigned char *into;
|
||||
@ -184,7 +184,7 @@ unsigned char *into;
|
||||
}
|
||||
|
||||
#include "spr.h"
|
||||
/*
|
||||
/*
|
||||
static unsigned long SP1[64] = {
|
||||
0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
|
||||
0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
|
||||
@ -202,7 +202,7 @@ static unsigned long SP1[64] = {
|
||||
0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
|
||||
0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
|
||||
0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };
|
||||
|
||||
|
||||
static unsigned long SP2[64] = {
|
||||
0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
|
||||
0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
|
||||
@ -220,7 +220,7 @@ static unsigned long SP2[64] = {
|
||||
0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
|
||||
0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
|
||||
0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };
|
||||
|
||||
|
||||
static unsigned long SP3[64] = {
|
||||
0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
|
||||
0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
|
||||
@ -238,7 +238,7 @@ static unsigned long SP3[64] = {
|
||||
0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
|
||||
0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
|
||||
0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };
|
||||
|
||||
|
||||
static unsigned long SP4[64] = {
|
||||
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
|
||||
0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
|
||||
@ -256,7 +256,7 @@ static unsigned long SP4[64] = {
|
||||
0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
|
||||
0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
|
||||
0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };
|
||||
|
||||
|
||||
static unsigned long SP5[64] = {
|
||||
0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
|
||||
0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
|
||||
@ -274,7 +274,7 @@ static unsigned long SP5[64] = {
|
||||
0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
|
||||
0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
|
||||
0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };
|
||||
|
||||
|
||||
static unsigned long SP6[64] = {
|
||||
0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
|
||||
0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
|
||||
@ -292,7 +292,7 @@ static unsigned long SP6[64] = {
|
||||
0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
|
||||
0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
|
||||
0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };
|
||||
|
||||
|
||||
static unsigned long SP7[64] = {
|
||||
0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
|
||||
0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
|
||||
@ -310,7 +310,7 @@ static unsigned long SP7[64] = {
|
||||
0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
|
||||
0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
|
||||
0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };
|
||||
|
||||
|
||||
static unsigned long SP8[64] = {
|
||||
0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
|
||||
0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
|
||||
@ -330,13 +330,13 @@ static unsigned long SP8[64] = {
|
||||
0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static void desfunc(block, keys)
|
||||
unsigned long *block, *keys;
|
||||
{
|
||||
unsigned long fval, work, right, leftt;
|
||||
int round;
|
||||
|
||||
|
||||
leftt = block[0];
|
||||
right = block[1];
|
||||
work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
|
||||
@ -356,7 +356,7 @@ unsigned long *block, *keys;
|
||||
leftt ^= work;
|
||||
right ^= work;
|
||||
leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
|
||||
|
||||
|
||||
for( round = 0; round < 8; round++ ) {
|
||||
work = (right << 28) | (right >> 4);
|
||||
work ^= *keys++;
|
||||
@ -383,7 +383,7 @@ unsigned long *block, *keys;
|
||||
fval |= SP2[(work >> 24) & 0x3fL];
|
||||
right ^= fval;
|
||||
}
|
||||
|
||||
|
||||
right = (right << 31) | (right >> 1);
|
||||
work = (leftt ^ right) & 0xaaaaaaaaL;
|
||||
leftt ^= work;
|
||||
@ -405,15 +405,15 @@ unsigned long *block, *keys;
|
||||
*block = leftt;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#ifdef D2_DES
|
||||
|
||||
|
||||
void des2key(hexkey, mode) /* stomps on Kn3 too */
|
||||
unsigned char *hexkey; /* unsigned char[16] */
|
||||
short mode;
|
||||
{
|
||||
short revmod;
|
||||
|
||||
|
||||
revmod = (mode == EN0) ? DE1 : EN0;
|
||||
deskey(&hexkey[8], revmod);
|
||||
cpkey(KnR);
|
||||
@ -421,12 +421,12 @@ short mode;
|
||||
cpkey(Kn3); /* Kn3 = KnL */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void Ddes(from, into)
|
||||
unsigned char *from, *into; /* unsigned char[8] */
|
||||
{
|
||||
unsigned long work[2];
|
||||
|
||||
|
||||
scrunch(from, work);
|
||||
desfunc(work, KnL);
|
||||
desfunc(work, KnR);
|
||||
@ -434,14 +434,14 @@ unsigned char *from, *into; /* unsigned char[8] */
|
||||
unscrun(work, into);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void D2des(from, into)
|
||||
unsigned char *from; /* unsigned char[16] */
|
||||
unsigned char *into; /* unsigned char[16] */
|
||||
{
|
||||
unsigned long *right, *l1, swap;
|
||||
unsigned long leftt[2], bufR[2];
|
||||
|
||||
|
||||
right = bufR;
|
||||
l1 = &leftt[1];
|
||||
scrunch(from, leftt);
|
||||
@ -462,7 +462,7 @@ unsigned char *into; /* unsigned char[16] */
|
||||
unscrun(right, &into[8]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void makekey(aptr, kptr)
|
||||
char *aptr; /* NULL-terminated */
|
||||
unsigned char *kptr; /* unsigned char[8] */
|
||||
@ -470,7 +470,7 @@ unsigned char *kptr; /* unsigned char[8] */
|
||||
unsigned char *store;
|
||||
int first, i;
|
||||
unsigned long savek[96];
|
||||
|
||||
|
||||
cpDkey(savek);
|
||||
des2key(Df_Key, EN0);
|
||||
for( i = 0; i < 8; i++ ) kptr[i] = Df_Key[i];
|
||||
@ -487,7 +487,7 @@ unsigned char *kptr; /* unsigned char[8] */
|
||||
useDkey(savek);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void make2key(aptr, kptr)
|
||||
char *aptr; /* NULL-terminated */
|
||||
unsigned char *kptr; /* unsigned char[16] */
|
||||
@ -495,7 +495,7 @@ unsigned char *kptr; /* unsigned char[16] */
|
||||
unsigned char *store;
|
||||
int first, i;
|
||||
unsigned long savek[96];
|
||||
|
||||
|
||||
cpDkey(savek);
|
||||
des2key(Df_Key, EN0);
|
||||
for( i = 0; i < 16; i++ ) kptr[i] = Df_Key[i];
|
||||
@ -512,26 +512,26 @@ unsigned char *kptr; /* unsigned char[16] */
|
||||
useDkey(savek);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#ifndef D3_DES /* D2_DES only */
|
||||
|
||||
|
||||
void cp2key(into)
|
||||
unsigned long *into; /* unsigned long[64] */
|
||||
{
|
||||
unsigned long *from, *endp;
|
||||
|
||||
|
||||
cpkey(into);
|
||||
into = &into[32];
|
||||
from = KnR, endp = &KnR[32];
|
||||
while( from < endp ) *into++ = *from++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void use2key(from) /* stomps on Kn3 too */
|
||||
unsigned long *from; /* unsigned long[64] */
|
||||
{
|
||||
unsigned long *to, *endp;
|
||||
|
||||
|
||||
usekey(from);
|
||||
from = &from[32];
|
||||
to = KnR, endp = &KnR[32];
|
||||
@ -539,16 +539,16 @@ unsigned long *from; /* unsigned long[64] */
|
||||
cpkey(Kn3); /* Kn3 = KnL */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#else /* D3_DES too */
|
||||
|
||||
|
||||
void des3key(hexkey, mode)
|
||||
unsigned char *hexkey; /* unsigned char[24] */
|
||||
short mode;
|
||||
{
|
||||
unsigned char *first, *third;
|
||||
short revmod;
|
||||
|
||||
|
||||
if( mode == EN0 ) {
|
||||
revmod = DE1;
|
||||
first = hexkey;
|
||||
@ -566,12 +566,12 @@ short mode;
|
||||
deskey(first, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void cp3key(into)
|
||||
unsigned long *into; /* unsigned long[96] */
|
||||
{
|
||||
unsigned long *from, *endp;
|
||||
|
||||
|
||||
cpkey(into);
|
||||
into = &into[32];
|
||||
from = KnR, endp = &KnR[32];
|
||||
@ -580,12 +580,12 @@ unsigned long *into; /* unsigned long[96] */
|
||||
while( from < endp ) *into++ = *from++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void use3key(from)
|
||||
unsigned long *from; /* unsigned long[96] */
|
||||
{
|
||||
unsigned long *to, *endp;
|
||||
|
||||
|
||||
usekey(from);
|
||||
from = &from[32];
|
||||
to = KnR, endp = &KnR[32];
|
||||
@ -594,15 +594,15 @@ unsigned long *from; /* unsigned long[96] */
|
||||
while( to < endp ) *to++ = *from++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void D3des(unsigned char *, unsigned char *);
|
||||
|
||||
|
||||
static void D3des(from, into) /* amateur theatrics */
|
||||
unsigned char *from; /* unsigned char[24] */
|
||||
unsigned char *into; /* unsigned char[24] */
|
||||
{
|
||||
unsigned long swap, leftt[2], middl[2], right[2];
|
||||
|
||||
|
||||
scrunch(from, leftt);
|
||||
scrunch(&from[8], middl);
|
||||
scrunch(&from[16], right);
|
||||
@ -631,8 +631,8 @@ unsigned char *into; /* unsigned char[24] */
|
||||
unscrun(middl, &into[8]);
|
||||
unscrun(right, &into[16]);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void make3key(aptr, kptr)
|
||||
char *aptr; /* NULL-terminated */
|
||||
unsigned char *kptr; /* unsigned char[24] */
|
||||
@ -640,7 +640,7 @@ unsigned char *kptr; /* unsigned char[24] */
|
||||
unsigned char *store;
|
||||
int first, i;
|
||||
unsigned long savek[96];
|
||||
|
||||
|
||||
cp3key(savek);
|
||||
des3key(Df_Key, EN0);
|
||||
for( i = 0; i < 24; i++ ) kptr[i] = Df_Key[i];
|
||||
@ -657,10 +657,10 @@ unsigned char *kptr; /* unsigned char[24] */
|
||||
use3key(savek);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#endif /* D3_DES */
|
||||
#endif /* D2_DES */
|
||||
|
||||
|
||||
/* Validation sets:
|
||||
*
|
||||
* Single-length key, single-length plaintext -
|
||||
@ -690,4 +690,4 @@ unsigned char *kptr; /* unsigned char[24] */
|
||||
*
|
||||
* d3des V5.09 rwo 9208.04 20:31 Graven Imagery
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
}
|
||||
|
||||
public:
|
||||
OutputDevice(PyObject *file) : tell_func(0), seek_func(0), read_func(0), write_func(0), flush_func(0), written(0) {
|
||||
OutputDevice(PyObject *file) : tell_func(0), seek_func(0), read_func(0), write_func(0), flush_func(0), written(0) {
|
||||
#define GA(f, a) { if((f = PyObject_GetAttrString(file, a)) == NULL) throw pyerr(); }
|
||||
GA(tell_func, "tell");
|
||||
GA(seek_func, "seek");
|
||||
@ -39,7 +39,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
GA(write_func, "write");
|
||||
GA(flush_func, "flush");
|
||||
}
|
||||
~OutputDevice() {
|
||||
~OutputDevice() {
|
||||
NUKE(tell_func); NUKE(seek_func); NUKE(read_func); NUKE(write_func); NUKE(flush_func);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
|
||||
buf = new (std::nothrow) char[lBytes+1];
|
||||
if (buf == NULL) { PyErr_NoMemory(); throw pyerr(); }
|
||||
|
||||
|
||||
// Note: PyOS_vsnprintf produces broken output on windows
|
||||
res = vsnprintf(buf, lBytes, pszFormat, args);
|
||||
|
||||
@ -184,7 +184,7 @@ PyObject* pdf::write_doc(PdfMemDocument *doc, PyObject *f) {
|
||||
} catch(const PdfError & err) {
|
||||
podofo_set_exception(err); return NULL;
|
||||
} catch (...) {
|
||||
if (PyErr_Occurred() == NULL)
|
||||
if (PyErr_Occurred() == NULL)
|
||||
PyErr_SetString(PyExc_Exception, "An unknown error occurred while trying to write the pdf to the file object");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class PyLogMessage : public PdfError::LogMessageCallback {
|
||||
PyLogMessage log_message;
|
||||
|
||||
CALIBRE_MODINIT_FUNC
|
||||
initpodofo(void)
|
||||
initpodofo(void)
|
||||
{
|
||||
PyObject* m;
|
||||
|
||||
|
@ -15,7 +15,7 @@ int main(int argc, char **argv) {
|
||||
cout << endl;
|
||||
cout << "is encrypted: " << doc.GetEncrypted() << endl;
|
||||
PdfString old_title = info->GetTitle();
|
||||
cout << "is hex: " << old_title.IsHex() << endl;
|
||||
cout << "is hex: " << old_title.IsHex() << endl;
|
||||
PdfString new_title(reinterpret_cast<const pdf_utf16be*>("\0z\0z\0z"), 3);
|
||||
cout << "is new unicode: " << new_title.IsUnicode() << endl;
|
||||
info->SetTitle(new_title);
|
||||
|
@ -43,4 +43,3 @@ pdf::podofo_convert_pystring_single_byte(PyObject *py) {
|
||||
if (ans == NULL) PyErr_NoMemory();
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <hunspell.hxx>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject_HEAD
|
||||
Hunspell *handle;
|
||||
char *encoding;
|
||||
} Dictionary;
|
||||
|
@ -362,16 +362,16 @@ zlib_crc32(PyObject *self, PyObject *args)
|
||||
while ((size_t)len > UINT_MAX) {
|
||||
value = crc32(value, buf, UINT_MAX);
|
||||
buf += (size_t) UINT_MAX;
|
||||
len -= (size_t) UINT_MAX;
|
||||
}
|
||||
len -= (size_t) UINT_MAX;
|
||||
}
|
||||
signed_val = crc32(value, buf, (unsigned int)len);
|
||||
Py_END_ALLOW_THREADS
|
||||
} else {
|
||||
signed_val = crc32(value, buf, len);
|
||||
}
|
||||
}
|
||||
if (indata.obj) PyBuffer_Release(&indata);
|
||||
return PyLong_FromUnsignedLong(signed_val & 0xffffffffU);
|
||||
}
|
||||
}
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
{"crc32", zlib_crc32, METH_VARARGS,
|
||||
@ -389,7 +389,7 @@ initzlib2(void) {
|
||||
Comptype.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&Comptype) < 0)
|
||||
return;
|
||||
|
||||
|
||||
m = Py_InitModule3("zlib2", methods,
|
||||
"Implementation of zlib compression with support for the buffer protocol, which is missing in Python2. Code taken from the Python3 zlib module"
|
||||
);
|
||||
@ -422,5 +422,5 @@ initzlib2(void) {
|
||||
if (ZlibError != NULL) {
|
||||
Py_INCREF(ZlibError);
|
||||
PyModule_AddObject(m, "error", ZlibError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2088
src/lzma/LzFind.c
2088
src/lzma/LzFind.c
File diff suppressed because it is too large
Load Diff
@ -1,378 +1,378 @@
|
||||
/* Lzma2Dec.c -- LZMA2 Decoder
|
||||
2015-11-09 : Igor Pavlov : Public domain */
|
||||
|
||||
/* #define SHOW_DEBUG_INFO */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#ifdef SHOW_DEBUG_INFO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "Lzma2Dec.h"
|
||||
|
||||
/*
|
||||
00000000 - EOS
|
||||
00000001 U U - Uncompressed Reset Dic
|
||||
00000010 U U - Uncompressed No Reset
|
||||
100uuuuu U U P P - LZMA no reset
|
||||
101uuuuu U U P P - LZMA reset state
|
||||
110uuuuu U U P P S - LZMA reset state + new prop
|
||||
111uuuuu U U P P S - LZMA reset state + new prop + reset dic
|
||||
|
||||
u, U - Unpack Size
|
||||
P - Pack Size
|
||||
S - Props
|
||||
*/
|
||||
|
||||
#define LZMA2_CONTROL_LZMA (1 << 7)
|
||||
#define LZMA2_CONTROL_COPY_NO_RESET 2
|
||||
#define LZMA2_CONTROL_COPY_RESET_DIC 1
|
||||
#define LZMA2_CONTROL_EOF 0
|
||||
|
||||
#define LZMA2_IS_UNCOMPRESSED_STATE(p) (((p)->control & LZMA2_CONTROL_LZMA) == 0)
|
||||
|
||||
#define LZMA2_GET_LZMA_MODE(p) (((p)->control >> 5) & 3)
|
||||
#define LZMA2_IS_THERE_PROP(mode) ((mode) >= 2)
|
||||
|
||||
#define LZMA2_LCLP_MAX 4
|
||||
#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))
|
||||
|
||||
#ifdef SHOW_DEBUG_INFO
|
||||
#define PRF(x) x
|
||||
#else
|
||||
#define PRF(x)
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA2_STATE_CONTROL,
|
||||
LZMA2_STATE_UNPACK0,
|
||||
LZMA2_STATE_UNPACK1,
|
||||
LZMA2_STATE_PACK0,
|
||||
LZMA2_STATE_PACK1,
|
||||
LZMA2_STATE_PROP,
|
||||
LZMA2_STATE_DATA,
|
||||
LZMA2_STATE_DATA_CONT,
|
||||
LZMA2_STATE_FINISHED,
|
||||
LZMA2_STATE_ERROR
|
||||
} ELzma2State;
|
||||
|
||||
static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
|
||||
{
|
||||
UInt32 dicSize;
|
||||
if (prop > 40)
|
||||
return SZ_ERROR_UNSUPPORTED;
|
||||
dicSize = (prop == 40) ? 0xFFFFFFFF : LZMA2_DIC_SIZE_FROM_PROP(prop);
|
||||
props[0] = (Byte)LZMA2_LCLP_MAX;
|
||||
props[1] = (Byte)(dicSize);
|
||||
props[2] = (Byte)(dicSize >> 8);
|
||||
props[3] = (Byte)(dicSize >> 16);
|
||||
props[4] = (Byte)(dicSize >> 24);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
|
||||
{
|
||||
Byte props[LZMA_PROPS_SIZE];
|
||||
RINOK(Lzma2Dec_GetOldProps(prop, props));
|
||||
return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
|
||||
}
|
||||
|
||||
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
|
||||
{
|
||||
Byte props[LZMA_PROPS_SIZE];
|
||||
RINOK(Lzma2Dec_GetOldProps(prop, props));
|
||||
return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
|
||||
}
|
||||
|
||||
void Lzma2Dec_Init(CLzma2Dec *p)
|
||||
{
|
||||
p->state = LZMA2_STATE_CONTROL;
|
||||
p->needInitDic = True;
|
||||
p->needInitState = True;
|
||||
p->needInitProp = True;
|
||||
LzmaDec_Init(&p->decoder);
|
||||
}
|
||||
|
||||
static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
|
||||
{
|
||||
switch (p->state)
|
||||
{
|
||||
case LZMA2_STATE_CONTROL:
|
||||
p->control = b;
|
||||
PRF(printf("\n %4X ", (unsigned)p->decoder.dicPos));
|
||||
PRF(printf(" %2X", (unsigned)b));
|
||||
if (p->control == 0)
|
||||
return LZMA2_STATE_FINISHED;
|
||||
if (LZMA2_IS_UNCOMPRESSED_STATE(p))
|
||||
{
|
||||
if ((p->control & 0x7F) > 2)
|
||||
return LZMA2_STATE_ERROR;
|
||||
p->unpackSize = 0;
|
||||
}
|
||||
else
|
||||
p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
|
||||
return LZMA2_STATE_UNPACK0;
|
||||
|
||||
case LZMA2_STATE_UNPACK0:
|
||||
p->unpackSize |= (UInt32)b << 8;
|
||||
return LZMA2_STATE_UNPACK1;
|
||||
|
||||
case LZMA2_STATE_UNPACK1:
|
||||
p->unpackSize |= (UInt32)b;
|
||||
p->unpackSize++;
|
||||
PRF(printf(" %8u", (unsigned)p->unpackSize));
|
||||
return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
|
||||
|
||||
case LZMA2_STATE_PACK0:
|
||||
p->packSize = (UInt32)b << 8;
|
||||
return LZMA2_STATE_PACK1;
|
||||
|
||||
case LZMA2_STATE_PACK1:
|
||||
p->packSize |= (UInt32)b;
|
||||
p->packSize++;
|
||||
PRF(printf(" %8u", (unsigned)p->packSize));
|
||||
return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP:
|
||||
(p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
|
||||
|
||||
case LZMA2_STATE_PROP:
|
||||
{
|
||||
unsigned lc, lp;
|
||||
if (b >= (9 * 5 * 5))
|
||||
return LZMA2_STATE_ERROR;
|
||||
lc = b % 9;
|
||||
b /= 9;
|
||||
p->decoder.prop.pb = b / 5;
|
||||
lp = b % 5;
|
||||
if (lc + lp > LZMA2_LCLP_MAX)
|
||||
return LZMA2_STATE_ERROR;
|
||||
p->decoder.prop.lc = lc;
|
||||
p->decoder.prop.lp = lp;
|
||||
p->needInitProp = False;
|
||||
return LZMA2_STATE_DATA;
|
||||
}
|
||||
}
|
||||
return LZMA2_STATE_ERROR;
|
||||
}
|
||||
|
||||
static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size)
|
||||
{
|
||||
memcpy(p->dic + p->dicPos, src, size);
|
||||
p->dicPos += size;
|
||||
if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)
|
||||
p->checkDicSize = p->prop.dicSize;
|
||||
p->processedPos += (UInt32)size;
|
||||
}
|
||||
|
||||
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);
|
||||
|
||||
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
|
||||
{
|
||||
SizeT inSize = *srcLen;
|
||||
*srcLen = 0;
|
||||
*status = LZMA_STATUS_NOT_SPECIFIED;
|
||||
|
||||
while (p->state != LZMA2_STATE_FINISHED)
|
||||
{
|
||||
SizeT dicPos = p->decoder.dicPos;
|
||||
|
||||
if (p->state == LZMA2_STATE_ERROR)
|
||||
return SZ_ERROR_DATA;
|
||||
|
||||
if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
|
||||
{
|
||||
*status = LZMA_STATUS_NOT_FINISHED;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
|
||||
{
|
||||
if (*srcLen == inSize)
|
||||
{
|
||||
*status = LZMA_STATUS_NEEDS_MORE_INPUT;
|
||||
return SZ_OK;
|
||||
}
|
||||
(*srcLen)++;
|
||||
p->state = Lzma2Dec_UpdateState(p, *src++);
|
||||
|
||||
if (dicPos == dicLimit && p->state != LZMA2_STATE_FINISHED)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
SizeT destSizeCur = dicLimit - dicPos;
|
||||
SizeT srcSizeCur = inSize - *srcLen;
|
||||
ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
|
||||
|
||||
if (p->unpackSize <= destSizeCur)
|
||||
{
|
||||
destSizeCur = (SizeT)p->unpackSize;
|
||||
curFinishMode = LZMA_FINISH_END;
|
||||
}
|
||||
|
||||
if (LZMA2_IS_UNCOMPRESSED_STATE(p))
|
||||
{
|
||||
if (*srcLen == inSize)
|
||||
{
|
||||
*status = LZMA_STATUS_NEEDS_MORE_INPUT;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
if (p->state == LZMA2_STATE_DATA)
|
||||
{
|
||||
Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
|
||||
if (initDic)
|
||||
p->needInitProp = p->needInitState = True;
|
||||
else if (p->needInitDic)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
p->needInitDic = False;
|
||||
LzmaDec_InitDicAndState(&p->decoder, initDic, False);
|
||||
}
|
||||
|
||||
if (srcSizeCur > destSizeCur)
|
||||
srcSizeCur = destSizeCur;
|
||||
|
||||
if (srcSizeCur == 0)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
|
||||
LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);
|
||||
|
||||
src += srcSizeCur;
|
||||
*srcLen += srcSizeCur;
|
||||
p->unpackSize -= (UInt32)srcSizeCur;
|
||||
p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
|
||||
}
|
||||
else
|
||||
{
|
||||
SizeT outSizeProcessed;
|
||||
SRes res;
|
||||
|
||||
if (p->state == LZMA2_STATE_DATA)
|
||||
{
|
||||
unsigned mode = LZMA2_GET_LZMA_MODE(p);
|
||||
Bool initDic = (mode == 3);
|
||||
Bool initState = (mode != 0);
|
||||
if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
|
||||
LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
|
||||
p->needInitDic = False;
|
||||
p->needInitState = False;
|
||||
p->state = LZMA2_STATE_DATA_CONT;
|
||||
}
|
||||
|
||||
if (srcSizeCur > p->packSize)
|
||||
srcSizeCur = (SizeT)p->packSize;
|
||||
|
||||
res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
|
||||
|
||||
src += srcSizeCur;
|
||||
*srcLen += srcSizeCur;
|
||||
p->packSize -= (UInt32)srcSizeCur;
|
||||
|
||||
outSizeProcessed = p->decoder.dicPos - dicPos;
|
||||
p->unpackSize -= (UInt32)outSizeProcessed;
|
||||
|
||||
RINOK(res);
|
||||
if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
return res;
|
||||
|
||||
if (srcSizeCur == 0 && outSizeProcessed == 0)
|
||||
{
|
||||
if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
|| p->unpackSize != 0
|
||||
|| p->packSize != 0)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
p->state = LZMA2_STATE_CONTROL;
|
||||
}
|
||||
|
||||
if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
*status = LZMA_STATUS_NOT_FINISHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*status = LZMA_STATUS_FINISHED_WITH_MARK;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
|
||||
{
|
||||
SizeT outSize = *destLen, inSize = *srcLen;
|
||||
*srcLen = *destLen = 0;
|
||||
for (;;)
|
||||
{
|
||||
SizeT srcSizeCur = inSize, outSizeCur, dicPos;
|
||||
ELzmaFinishMode curFinishMode;
|
||||
SRes res;
|
||||
if (p->decoder.dicPos == p->decoder.dicBufSize)
|
||||
p->decoder.dicPos = 0;
|
||||
dicPos = p->decoder.dicPos;
|
||||
if (outSize > p->decoder.dicBufSize - dicPos)
|
||||
{
|
||||
outSizeCur = p->decoder.dicBufSize;
|
||||
curFinishMode = LZMA_FINISH_ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
outSizeCur = dicPos + outSize;
|
||||
curFinishMode = finishMode;
|
||||
}
|
||||
|
||||
res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);
|
||||
src += srcSizeCur;
|
||||
inSize -= srcSizeCur;
|
||||
*srcLen += srcSizeCur;
|
||||
outSizeCur = p->decoder.dicPos - dicPos;
|
||||
memcpy(dest, p->decoder.dic + dicPos, outSizeCur);
|
||||
dest += outSizeCur;
|
||||
outSize -= outSizeCur;
|
||||
*destLen += outSizeCur;
|
||||
if (res != 0)
|
||||
return res;
|
||||
if (outSizeCur == 0 || outSize == 0)
|
||||
return SZ_OK;
|
||||
}
|
||||
}
|
||||
|
||||
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
|
||||
{
|
||||
CLzma2Dec p;
|
||||
SRes res;
|
||||
SizeT outSize = *destLen, inSize = *srcLen;
|
||||
*destLen = *srcLen = 0;
|
||||
*status = LZMA_STATUS_NOT_SPECIFIED;
|
||||
Lzma2Dec_Construct(&p);
|
||||
RINOK(Lzma2Dec_AllocateProbs(&p, prop, alloc));
|
||||
p.decoder.dic = dest;
|
||||
p.decoder.dicBufSize = outSize;
|
||||
Lzma2Dec_Init(&p);
|
||||
*srcLen = inSize;
|
||||
res = Lzma2Dec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
|
||||
*destLen = p.decoder.dicPos;
|
||||
if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
res = SZ_ERROR_INPUT_EOF;
|
||||
Lzma2Dec_FreeProbs(&p, alloc);
|
||||
return res;
|
||||
}
|
||||
/* Lzma2Dec.c -- LZMA2 Decoder
|
||||
2015-11-09 : Igor Pavlov : Public domain */
|
||||
|
||||
/* #define SHOW_DEBUG_INFO */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#ifdef SHOW_DEBUG_INFO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "Lzma2Dec.h"
|
||||
|
||||
/*
|
||||
00000000 - EOS
|
||||
00000001 U U - Uncompressed Reset Dic
|
||||
00000010 U U - Uncompressed No Reset
|
||||
100uuuuu U U P P - LZMA no reset
|
||||
101uuuuu U U P P - LZMA reset state
|
||||
110uuuuu U U P P S - LZMA reset state + new prop
|
||||
111uuuuu U U P P S - LZMA reset state + new prop + reset dic
|
||||
|
||||
u, U - Unpack Size
|
||||
P - Pack Size
|
||||
S - Props
|
||||
*/
|
||||
|
||||
#define LZMA2_CONTROL_LZMA (1 << 7)
|
||||
#define LZMA2_CONTROL_COPY_NO_RESET 2
|
||||
#define LZMA2_CONTROL_COPY_RESET_DIC 1
|
||||
#define LZMA2_CONTROL_EOF 0
|
||||
|
||||
#define LZMA2_IS_UNCOMPRESSED_STATE(p) (((p)->control & LZMA2_CONTROL_LZMA) == 0)
|
||||
|
||||
#define LZMA2_GET_LZMA_MODE(p) (((p)->control >> 5) & 3)
|
||||
#define LZMA2_IS_THERE_PROP(mode) ((mode) >= 2)
|
||||
|
||||
#define LZMA2_LCLP_MAX 4
|
||||
#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))
|
||||
|
||||
#ifdef SHOW_DEBUG_INFO
|
||||
#define PRF(x) x
|
||||
#else
|
||||
#define PRF(x)
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA2_STATE_CONTROL,
|
||||
LZMA2_STATE_UNPACK0,
|
||||
LZMA2_STATE_UNPACK1,
|
||||
LZMA2_STATE_PACK0,
|
||||
LZMA2_STATE_PACK1,
|
||||
LZMA2_STATE_PROP,
|
||||
LZMA2_STATE_DATA,
|
||||
LZMA2_STATE_DATA_CONT,
|
||||
LZMA2_STATE_FINISHED,
|
||||
LZMA2_STATE_ERROR
|
||||
} ELzma2State;
|
||||
|
||||
static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
|
||||
{
|
||||
UInt32 dicSize;
|
||||
if (prop > 40)
|
||||
return SZ_ERROR_UNSUPPORTED;
|
||||
dicSize = (prop == 40) ? 0xFFFFFFFF : LZMA2_DIC_SIZE_FROM_PROP(prop);
|
||||
props[0] = (Byte)LZMA2_LCLP_MAX;
|
||||
props[1] = (Byte)(dicSize);
|
||||
props[2] = (Byte)(dicSize >> 8);
|
||||
props[3] = (Byte)(dicSize >> 16);
|
||||
props[4] = (Byte)(dicSize >> 24);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
|
||||
{
|
||||
Byte props[LZMA_PROPS_SIZE];
|
||||
RINOK(Lzma2Dec_GetOldProps(prop, props));
|
||||
return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
|
||||
}
|
||||
|
||||
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
|
||||
{
|
||||
Byte props[LZMA_PROPS_SIZE];
|
||||
RINOK(Lzma2Dec_GetOldProps(prop, props));
|
||||
return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
|
||||
}
|
||||
|
||||
void Lzma2Dec_Init(CLzma2Dec *p)
|
||||
{
|
||||
p->state = LZMA2_STATE_CONTROL;
|
||||
p->needInitDic = True;
|
||||
p->needInitState = True;
|
||||
p->needInitProp = True;
|
||||
LzmaDec_Init(&p->decoder);
|
||||
}
|
||||
|
||||
static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
|
||||
{
|
||||
switch (p->state)
|
||||
{
|
||||
case LZMA2_STATE_CONTROL:
|
||||
p->control = b;
|
||||
PRF(printf("\n %4X ", (unsigned)p->decoder.dicPos));
|
||||
PRF(printf(" %2X", (unsigned)b));
|
||||
if (p->control == 0)
|
||||
return LZMA2_STATE_FINISHED;
|
||||
if (LZMA2_IS_UNCOMPRESSED_STATE(p))
|
||||
{
|
||||
if ((p->control & 0x7F) > 2)
|
||||
return LZMA2_STATE_ERROR;
|
||||
p->unpackSize = 0;
|
||||
}
|
||||
else
|
||||
p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
|
||||
return LZMA2_STATE_UNPACK0;
|
||||
|
||||
case LZMA2_STATE_UNPACK0:
|
||||
p->unpackSize |= (UInt32)b << 8;
|
||||
return LZMA2_STATE_UNPACK1;
|
||||
|
||||
case LZMA2_STATE_UNPACK1:
|
||||
p->unpackSize |= (UInt32)b;
|
||||
p->unpackSize++;
|
||||
PRF(printf(" %8u", (unsigned)p->unpackSize));
|
||||
return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
|
||||
|
||||
case LZMA2_STATE_PACK0:
|
||||
p->packSize = (UInt32)b << 8;
|
||||
return LZMA2_STATE_PACK1;
|
||||
|
||||
case LZMA2_STATE_PACK1:
|
||||
p->packSize |= (UInt32)b;
|
||||
p->packSize++;
|
||||
PRF(printf(" %8u", (unsigned)p->packSize));
|
||||
return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP:
|
||||
(p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
|
||||
|
||||
case LZMA2_STATE_PROP:
|
||||
{
|
||||
unsigned lc, lp;
|
||||
if (b >= (9 * 5 * 5))
|
||||
return LZMA2_STATE_ERROR;
|
||||
lc = b % 9;
|
||||
b /= 9;
|
||||
p->decoder.prop.pb = b / 5;
|
||||
lp = b % 5;
|
||||
if (lc + lp > LZMA2_LCLP_MAX)
|
||||
return LZMA2_STATE_ERROR;
|
||||
p->decoder.prop.lc = lc;
|
||||
p->decoder.prop.lp = lp;
|
||||
p->needInitProp = False;
|
||||
return LZMA2_STATE_DATA;
|
||||
}
|
||||
}
|
||||
return LZMA2_STATE_ERROR;
|
||||
}
|
||||
|
||||
static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size)
|
||||
{
|
||||
memcpy(p->dic + p->dicPos, src, size);
|
||||
p->dicPos += size;
|
||||
if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)
|
||||
p->checkDicSize = p->prop.dicSize;
|
||||
p->processedPos += (UInt32)size;
|
||||
}
|
||||
|
||||
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);
|
||||
|
||||
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
|
||||
{
|
||||
SizeT inSize = *srcLen;
|
||||
*srcLen = 0;
|
||||
*status = LZMA_STATUS_NOT_SPECIFIED;
|
||||
|
||||
while (p->state != LZMA2_STATE_FINISHED)
|
||||
{
|
||||
SizeT dicPos = p->decoder.dicPos;
|
||||
|
||||
if (p->state == LZMA2_STATE_ERROR)
|
||||
return SZ_ERROR_DATA;
|
||||
|
||||
if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
|
||||
{
|
||||
*status = LZMA_STATUS_NOT_FINISHED;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
|
||||
{
|
||||
if (*srcLen == inSize)
|
||||
{
|
||||
*status = LZMA_STATUS_NEEDS_MORE_INPUT;
|
||||
return SZ_OK;
|
||||
}
|
||||
(*srcLen)++;
|
||||
p->state = Lzma2Dec_UpdateState(p, *src++);
|
||||
|
||||
if (dicPos == dicLimit && p->state != LZMA2_STATE_FINISHED)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
SizeT destSizeCur = dicLimit - dicPos;
|
||||
SizeT srcSizeCur = inSize - *srcLen;
|
||||
ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
|
||||
|
||||
if (p->unpackSize <= destSizeCur)
|
||||
{
|
||||
destSizeCur = (SizeT)p->unpackSize;
|
||||
curFinishMode = LZMA_FINISH_END;
|
||||
}
|
||||
|
||||
if (LZMA2_IS_UNCOMPRESSED_STATE(p))
|
||||
{
|
||||
if (*srcLen == inSize)
|
||||
{
|
||||
*status = LZMA_STATUS_NEEDS_MORE_INPUT;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
if (p->state == LZMA2_STATE_DATA)
|
||||
{
|
||||
Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
|
||||
if (initDic)
|
||||
p->needInitProp = p->needInitState = True;
|
||||
else if (p->needInitDic)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
p->needInitDic = False;
|
||||
LzmaDec_InitDicAndState(&p->decoder, initDic, False);
|
||||
}
|
||||
|
||||
if (srcSizeCur > destSizeCur)
|
||||
srcSizeCur = destSizeCur;
|
||||
|
||||
if (srcSizeCur == 0)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
|
||||
LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);
|
||||
|
||||
src += srcSizeCur;
|
||||
*srcLen += srcSizeCur;
|
||||
p->unpackSize -= (UInt32)srcSizeCur;
|
||||
p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
|
||||
}
|
||||
else
|
||||
{
|
||||
SizeT outSizeProcessed;
|
||||
SRes res;
|
||||
|
||||
if (p->state == LZMA2_STATE_DATA)
|
||||
{
|
||||
unsigned mode = LZMA2_GET_LZMA_MODE(p);
|
||||
Bool initDic = (mode == 3);
|
||||
Bool initState = (mode != 0);
|
||||
if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
|
||||
LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
|
||||
p->needInitDic = False;
|
||||
p->needInitState = False;
|
||||
p->state = LZMA2_STATE_DATA_CONT;
|
||||
}
|
||||
|
||||
if (srcSizeCur > p->packSize)
|
||||
srcSizeCur = (SizeT)p->packSize;
|
||||
|
||||
res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
|
||||
|
||||
src += srcSizeCur;
|
||||
*srcLen += srcSizeCur;
|
||||
p->packSize -= (UInt32)srcSizeCur;
|
||||
|
||||
outSizeProcessed = p->decoder.dicPos - dicPos;
|
||||
p->unpackSize -= (UInt32)outSizeProcessed;
|
||||
|
||||
RINOK(res);
|
||||
if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
return res;
|
||||
|
||||
if (srcSizeCur == 0 && outSizeProcessed == 0)
|
||||
{
|
||||
if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
|| p->unpackSize != 0
|
||||
|| p->packSize != 0)
|
||||
{
|
||||
p->state = LZMA2_STATE_ERROR;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
p->state = LZMA2_STATE_CONTROL;
|
||||
}
|
||||
|
||||
if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
*status = LZMA_STATUS_NOT_FINISHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*status = LZMA_STATUS_FINISHED_WITH_MARK;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
|
||||
{
|
||||
SizeT outSize = *destLen, inSize = *srcLen;
|
||||
*srcLen = *destLen = 0;
|
||||
for (;;)
|
||||
{
|
||||
SizeT srcSizeCur = inSize, outSizeCur, dicPos;
|
||||
ELzmaFinishMode curFinishMode;
|
||||
SRes res;
|
||||
if (p->decoder.dicPos == p->decoder.dicBufSize)
|
||||
p->decoder.dicPos = 0;
|
||||
dicPos = p->decoder.dicPos;
|
||||
if (outSize > p->decoder.dicBufSize - dicPos)
|
||||
{
|
||||
outSizeCur = p->decoder.dicBufSize;
|
||||
curFinishMode = LZMA_FINISH_ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
outSizeCur = dicPos + outSize;
|
||||
curFinishMode = finishMode;
|
||||
}
|
||||
|
||||
res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);
|
||||
src += srcSizeCur;
|
||||
inSize -= srcSizeCur;
|
||||
*srcLen += srcSizeCur;
|
||||
outSizeCur = p->decoder.dicPos - dicPos;
|
||||
memcpy(dest, p->decoder.dic + dicPos, outSizeCur);
|
||||
dest += outSizeCur;
|
||||
outSize -= outSizeCur;
|
||||
*destLen += outSizeCur;
|
||||
if (res != 0)
|
||||
return res;
|
||||
if (outSizeCur == 0 || outSize == 0)
|
||||
return SZ_OK;
|
||||
}
|
||||
}
|
||||
|
||||
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
|
||||
{
|
||||
CLzma2Dec p;
|
||||
SRes res;
|
||||
SizeT outSize = *destLen, inSize = *srcLen;
|
||||
*destLen = *srcLen = 0;
|
||||
*status = LZMA_STATUS_NOT_SPECIFIED;
|
||||
Lzma2Dec_Construct(&p);
|
||||
RINOK(Lzma2Dec_AllocateProbs(&p, prop, alloc));
|
||||
p.decoder.dic = dest;
|
||||
p.decoder.dicBufSize = outSize;
|
||||
Lzma2Dec_Init(&p);
|
||||
*srcLen = inSize;
|
||||
res = Lzma2Dec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
|
||||
*destLen = p.decoder.dicPos;
|
||||
if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
res = SZ_ERROR_INPUT_EOF;
|
||||
Lzma2Dec_FreeProbs(&p, alloc);
|
||||
return res;
|
||||
}
|
||||
|
1040
src/lzma/Lzma2Enc.c
1040
src/lzma/Lzma2Enc.c
File diff suppressed because it is too large
Load Diff
2200
src/lzma/LzmaDec.c
2200
src/lzma/LzmaDec.c
File diff suppressed because it is too large
Load Diff
4702
src/lzma/LzmaEnc.c
4702
src/lzma/LzmaEnc.c
File diff suppressed because it is too large
Load Diff
@ -102,7 +102,7 @@ delta_decode(PyObject *self, PyObject *args) {
|
||||
datalen = PyBytes_GET_SIZE(array);
|
||||
|
||||
for (i = 0; i < datalen; i++) {
|
||||
data[i] += history[(unsigned char)(pos + distance)];
|
||||
data[i] += history[(unsigned char)(pos + distance)];
|
||||
history[pos--] = data[i];
|
||||
}
|
||||
return Py_BuildValue("B", pos);
|
||||
@ -122,7 +122,7 @@ decompress2(PyObject *self, PyObject *args) {
|
||||
ELzmaStatus status = LZMA_STATUS_NOT_FINISHED;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOOBk", &read, &seek, &write, &props, &bufsize)) return NULL;
|
||||
|
||||
|
||||
Lzma2Dec_Construct(&state);
|
||||
res = Lzma2Dec_Allocate(&state, (Byte)props, &allocator);
|
||||
if (res == SZ_ERROR_MEM) { PyErr_NoMemory(); return NULL; }
|
||||
@ -158,7 +158,7 @@ decompress2(PyObject *self, PyObject *args) {
|
||||
if (inbuf_len == 0) { PyErr_SetString(LZMAError, "LZMA2 block was truncated"); goto exit; }
|
||||
memcpy(inbuf, PyBytes_AS_STRING(rres), inbuf_len);
|
||||
Py_DECREF(rres); rres = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
leftover = inbuf_len - inbuf_pos;
|
||||
if (leftover > 0) {
|
||||
@ -232,7 +232,7 @@ decompress(PyObject *self, PyObject *args) {
|
||||
if (inbuf_len == 0) { PyErr_SetString(LZMAError, "LZMA block was truncated"); goto exit; }
|
||||
memcpy(inbuf, PyBytes_AS_STRING(rres), inbuf_len);
|
||||
Py_DECREF(rres); rres = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
leftover = inbuf_len - inbuf_pos;
|
||||
if (leftover > 0) {
|
||||
@ -386,7 +386,7 @@ exit:
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
static PyMethodDef lzma_binding_methods[] = {
|
||||
{"decompress2", decompress2, METH_VARARGS,
|
||||
"Decompress an LZMA2 encoded block, of unknown compressed size (reads till LZMA2 EOS marker)"
|
||||
|
Loading…
x
Reference in New Issue
Block a user