diff --git a/.hgignore b/.hgignore index fda43040..c7845b77 100644 --- a/.hgignore +++ b/.hgignore @@ -14,7 +14,6 @@ cocoa/*/dg_cocoa.plugin qt/base/*_rc.py qt/base/*_ui.py qt/*/*_ui.py -qt/pe/modules/block/block.c help_se/dupeguru_help help_me/dupeguru_me_help help_pe/dupeguru_pe_help \ No newline at end of file diff --git a/qt/pe/modules/block/block.c b/qt/pe/modules/block/block.c new file mode 100644 index 00000000..44cb97b1 --- /dev/null +++ b/qt/pe/modules/block/block.c @@ -0,0 +1,160 @@ +/* Created By: Virgil Dupras + * Created On: 2010-01-31 + * Copyright 2010 Hardcoded Software (http://www.hardcoded.net) + * + * This software is licensed under the "HS" License as described in the "LICENSE" file, + * which should be included with this package. The terms are also available at + * http://www.hardcoded.net/licenses/hs_license + */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" + +static inline int +max(int a, int b) +{ + return b > a ? b : a; +} + +static inline int +min(int a, int b) +{ + return b < a ? b : a; +} + +static inline PyObject* +getblock(PyObject *image) +{ + int width, height, pixel_count, red, green, blue, bytes_per_line; + PyObject *pi, *pred, *pgreen, *pblue; + PyObject *result; + + red = green = blue = 0; + pi = PyObject_CallMethod(image, "width", NULL); + width = PyInt_AsSsize_t(pi); + Py_DECREF(pi); + pi = PyObject_CallMethod(image, "height", NULL); + height = PyInt_AsSsize_t(pi); + Py_DECREF(pi); + pixel_count = width * height; + if (pixel_count) { + PyObject *sipptr; + char *s; + int i; + + pi = PyObject_CallMethod(image, "bytesPerLine", NULL); + bytes_per_line = PyInt_AsSsize_t(pi); + Py_DECREF(pi); + + sipptr = PyObject_CallMethod(image, "bits", NULL); + pi = PyObject_CallMethod(sipptr, "__int__", NULL); + Py_DECREF(sipptr); + s = (char *)PyInt_AsSsize_t(pi); + Py_DECREF(pi); + /* Qt aligns all its lines on 32bit, which means that if the number of bytes per + * line for image is not divisible by 4, there's going to be crap inserted in "s" + * We have to take this into account when calculating offsets + **/ + for (i=0; i