tabs -> spaces and removed windows newline
This commit is contained in:
@@ -22,8 +22,7 @@
|
|||||||
* PIL paste if this extension is not found.
|
* PIL paste if this extension is not found.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "overviewer.h"
|
#include "overviewer.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
@@ -502,123 +501,123 @@ resize_half(PyObject *dest, PyObject *src) {
|
|||||||
/* iteration variables */
|
/* iteration variables */
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
/* temp color variables */
|
/* temp color variables */
|
||||||
unsigned int r, g, b, a;
|
unsigned int r, g, b, a;
|
||||||
/* size values for source and destination */
|
/* size values for source and destination */
|
||||||
int src_width, src_height, dest_width, dest_height;
|
int src_width, src_height, dest_width, dest_height;
|
||||||
|
|
||||||
imDest = imaging_python_to_c(dest);
|
imDest = imaging_python_to_c(dest);
|
||||||
imSrc = imaging_python_to_c(src);
|
imSrc = imaging_python_to_c(src);
|
||||||
|
|
||||||
if (!imDest || !imSrc)
|
if (!imDest || !imSrc)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* check the various image modes, make sure they make sense */
|
/* check the various image modes, make sure they make sense */
|
||||||
if (strcmp(imDest->mode, "RGBA") != 0) {
|
if (strcmp(imDest->mode, "RGBA") != 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"given destination image does not have mode \"RGBA\"");
|
"given destination image does not have mode \"RGBA\"");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(imSrc->mode, "RGBA") != 0 && strcmp(imSrc->mode, "RGB") != 0) {
|
if (strcmp(imSrc->mode, "RGBA") != 0 && strcmp(imSrc->mode, "RGB") != 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"given source image does not have mode \"RGBA\" or \"RGB\"");
|
"given source image does not have mode \"RGBA\" or \"RGB\"");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
src_width = imSrc->xsize;
|
src_width = imSrc->xsize;
|
||||||
src_height = imSrc->ysize;
|
src_height = imSrc->ysize;
|
||||||
dest_width = imDest->xsize;
|
dest_width = imDest->xsize;
|
||||||
dest_height = imDest->ysize;
|
dest_height = imDest->ysize;
|
||||||
|
|
||||||
/* make sure destination size is 1/2 src size */
|
/* make sure destination size is 1/2 src size */
|
||||||
if (src_width / 2 != dest_width || src_height / 2 != dest_height) {
|
if (src_width / 2 != dest_width || src_height / 2 != dest_height) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"destination image size is not one-half source image size");
|
"destination image size is not one-half source image size");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set up flags for the src/mask type */
|
/* set up flags for the src/mask type */
|
||||||
src_has_alpha = (imSrc->pixelsize == 4 ? 1 : 0);
|
src_has_alpha = (imSrc->pixelsize == 4 ? 1 : 0);
|
||||||
dest_has_alpha = (imDest->pixelsize == 4 ? 1 : 0);
|
dest_has_alpha = (imDest->pixelsize == 4 ? 1 : 0);
|
||||||
|
|
||||||
/* check that there remains anything to resize */
|
/* check that there remains anything to resize */
|
||||||
if (dest_width <= 0 || dest_height <= 0) {
|
if (dest_width <= 0 || dest_height <= 0) {
|
||||||
/* nothing to do, return */
|
/* nothing to do, return */
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set to fully opaque if source has no alpha channel */
|
/* set to fully opaque if source has no alpha channel */
|
||||||
if(!src_has_alpha)
|
if(!src_has_alpha)
|
||||||
a = 0xFF << 2;
|
a = 0xFF << 2;
|
||||||
|
|
||||||
for (y = 0; y < dest_height; y++) {
|
for (y = 0; y < dest_height; y++) {
|
||||||
|
|
||||||
UINT8 *out = (UINT8 *)imDest->image[y];
|
UINT8 *out = (UINT8 *)imDest->image[y];
|
||||||
UINT8 *in_row1 = (UINT8 *)imSrc->image[y * 2];
|
UINT8 *in_row1 = (UINT8 *)imSrc->image[y * 2];
|
||||||
UINT8 *in_row2 = (UINT8 *)imSrc->image[y * 2 + 1];
|
UINT8 *in_row2 = (UINT8 *)imSrc->image[y * 2 + 1];
|
||||||
|
|
||||||
for (x = 0; x < dest_width; x++) {
|
for (x = 0; x < dest_width; x++) {
|
||||||
|
|
||||||
// read first column
|
// read first column
|
||||||
r = *in_row1;
|
r = *in_row1;
|
||||||
r += *in_row2;
|
r += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
g = *in_row1;
|
g = *in_row1;
|
||||||
g += *in_row2;
|
g += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
b = *in_row1;
|
b = *in_row1;
|
||||||
b += *in_row2;
|
b += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
|
|
||||||
if (src_has_alpha)
|
if (src_has_alpha)
|
||||||
{
|
{
|
||||||
a = *in_row1;
|
a = *in_row1;
|
||||||
a += *in_row2;
|
a += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read second column
|
// read second column
|
||||||
r += *in_row1;
|
r += *in_row1;
|
||||||
r += *in_row2;
|
r += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
g += *in_row1;
|
g += *in_row1;
|
||||||
g += *in_row2;
|
g += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
b += *in_row1;
|
b += *in_row1;
|
||||||
b += *in_row2;
|
b += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
|
|
||||||
if (src_has_alpha)
|
if (src_has_alpha)
|
||||||
{
|
{
|
||||||
a += *in_row1;
|
a += *in_row1;
|
||||||
a += *in_row2;
|
a += *in_row2;
|
||||||
in_row1++;
|
in_row1++;
|
||||||
in_row2++;
|
in_row2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write blended color
|
// write blended color
|
||||||
*out = (UINT8)(r >> 2);
|
*out = (UINT8)(r >> 2);
|
||||||
out++;
|
out++;
|
||||||
*out = (UINT8)(g >> 2);
|
*out = (UINT8)(g >> 2);
|
||||||
out++;
|
out++;
|
||||||
*out = (UINT8)(b >> 2);
|
*out = (UINT8)(b >> 2);
|
||||||
out++;
|
out++;
|
||||||
|
|
||||||
if (dest_has_alpha)
|
if (dest_has_alpha)
|
||||||
{
|
{
|
||||||
*out = (UINT8)(a >> 2);
|
*out = (UINT8)(a >> 2);
|
||||||
out++;
|
out++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,7 +629,7 @@ resize_half_wrap(PyObject *self, PyObject *args)
|
|||||||
PyObject *dest, *src;
|
PyObject *dest, *src;
|
||||||
/* return value: dest image on success */
|
/* return value: dest image on success */
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &dest, &src))
|
if (!PyArg_ParseTuple(args, "OO", &dest, &src))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -640,4 +639,4 @@ resize_half_wrap(PyObject *self, PyObject *args)
|
|||||||
Py_INCREF(dest);
|
Py_INCREF(dest);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user