Merge pull request #8015 from hugovk/pre-commit-clang

Add ClangFormat to pre-commit
This commit is contained in:
Andrew Murray 2024-05-19 16:27:30 +10:00 committed by GitHub
commit 22b64ffcf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 609 additions and 488 deletions

View File

@ -9,6 +9,7 @@ BinPackParameters: false
BreakBeforeBraces: Attach
ColumnLimit: 88
DerivePointerAlignment: false
IndentGotoLabels: false
IndentWidth: 4
Language: Cpp
PointerAlignment: Right

View File

@ -23,6 +23,13 @@ repos:
- id: remove-tabs
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.4
hooks:
- id: clang-format
types: [c]
exclude: ^src/thirdparty/
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:

View File

@ -128,14 +128,7 @@ PyImagingPhotoPut(
block.pixelPtr = (unsigned char *)im->block;
TK_PHOTO_PUT_BLOCK(
interp,
photo,
&block,
0,
0,
block.width,
block.height,
TK_PHOTO_COMPOSITE_SET);
interp, photo, &block, 0, 0, block.width, block.height, TK_PHOTO_COMPOSITE_SET);
return TCL_OK;
}
@ -400,8 +393,8 @@ _func_loader(void *lib) {
return 1;
}
return (
(TK_PHOTO_PUT_BLOCK =
(Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) == NULL);
(TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) ==
NULL);
}
int

View File

@ -533,7 +533,9 @@ getink(PyObject *color, Imaging im, char *ink) {
/* unsigned integer, single layer */
if (rIsInt != 1) {
if (tupleSize != 1) {
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
PyErr_SetString(
PyExc_TypeError,
"color must be int or single-element tuple");
return NULL;
} else if (!PyArg_ParseTuple(color, "L", &r)) {
return NULL;
@ -552,7 +554,9 @@ getink(PyObject *color, Imaging im, char *ink) {
a = 255;
if (im->bands == 2) {
if (tupleSize != 1 && tupleSize != 2) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or two elements");
PyErr_SetString(
PyExc_TypeError,
"color must be int, or tuple of one or two elements");
return NULL;
} else if (!PyArg_ParseTuple(color, "L|i", &r, &a)) {
return NULL;
@ -560,7 +564,10 @@ getink(PyObject *color, Imaging im, char *ink) {
g = b = r;
} else {
if (tupleSize != 3 && tupleSize != 4) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one, three or four elements");
PyErr_SetString(
PyExc_TypeError,
"color must be int, or tuple of one, three or four "
"elements");
return NULL;
} else if (!PyArg_ParseTuple(color, "Lii|i", &r, &g, &b, &a)) {
return NULL;
@ -599,7 +606,9 @@ getink(PyObject *color, Imaging im, char *ink) {
g = (UINT8)(r >> 8);
r = (UINT8)r;
} else if (tupleSize != 3) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or three elements");
PyErr_SetString(
PyExc_TypeError,
"color must be int, or tuple of one or three elements");
return NULL;
} else if (!PyArg_ParseTuple(color, "iiL", &b, &g, &r)) {
return NULL;
@ -1596,8 +1605,10 @@ if (PySequence_Check(op)) { \
value = value * scale + offset;
}
if (image->type == IMAGING_TYPE_SPECIAL) {
image->image8[y][x * 2 + (bigendian ? 1 : 0)] = CLIP8((int)value % 256);
image->image8[y][x * 2 + (bigendian ? 0 : 1)] = CLIP8((int)value >> 8);
image->image8[y][x * 2 + (bigendian ? 1 : 0)] =
CLIP8((int)value % 256);
image->image8[y][x * 2 + (bigendian ? 0 : 1)] =
CLIP8((int)value >> 8);
} else {
image->image8[y][x] = (UINT8)CLIP8(value);
}
@ -1639,8 +1650,7 @@ if (PySequence_Check(op)) { \
for (i = x = y = 0; i < n; i++) {
double value;
set_value_to_item(seq, i);
IMAGING_PIXEL_INT32(image, x, y) =
(INT32)(value * scale + offset);
IMAGING_PIXEL_INT32(image, x, y) = (INT32)(value * scale + offset);
if (++x >= (int)image->xsize) {
x = 0, y++;
}
@ -2785,8 +2795,8 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
glyph = &self->glyphs[text[i]];
if (i == 0 || text[i] != text[i - 1]) {
ImagingDelete(bitmap);
bitmap =
ImagingCrop(self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
bitmap = ImagingCrop(
self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
if (!bitmap) {
goto failed;
}
@ -3315,7 +3325,8 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) {
free(xy);
if (ImagingDrawPolygon(self->image->image, n, ixy, &ink, fill, width, self->blend) < 0) {
if (ImagingDrawPolygon(self->image->image, n, ixy, &ink, fill, width, self->blend) <
0) {
free(ixy);
return NULL;
}
@ -4411,7 +4422,8 @@ setup_module(PyObject *m) {
PyModule_AddObject(m, "HAVE_XCB", have_xcb);
PyObject *pillow_version = PyUnicode_FromString(version);
PyDict_SetItemString(d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
PyDict_SetItemString(
d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
Py_XDECREF(pillow_version);
return 0;

View File

@ -213,11 +213,8 @@ cms_transform_dealloc(CmsTransformObject *self) {
static cmsUInt32Number
findLCMStype(char *PILmode) {
if (
strcmp(PILmode, "RGB") == 0 ||
strcmp(PILmode, "RGBA") == 0 ||
strcmp(PILmode, "RGBX") == 0
) {
if (strcmp(PILmode, "RGB") == 0 || strcmp(PILmode, "RGBA") == 0 ||
strcmp(PILmode, "RGBX") == 0) {
return TYPE_RGBA_8;
}
if (strcmp(PILmode, "RGBA;16B") == 0) {
@ -232,10 +229,7 @@ findLCMStype(char *PILmode) {
if (strcmp(PILmode, "L;16B") == 0) {
return TYPE_GRAY_16_SE;
}
if (
strcmp(PILmode, "YCCA") == 0 ||
strcmp(PILmode, "YCC") == 0
) {
if (strcmp(PILmode, "YCCA") == 0 || strcmp(PILmode, "YCC") == 0) {
return TYPE_YCbCr_8;
}
if (strcmp(PILmode, "LAB") == 0) {
@ -391,7 +385,7 @@ _buildTransform(
iRenderingIntent,
cmsFLAGS);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS;
if (!hTransform) {
PyErr_SetString(PyExc_ValueError, "cannot build transform");
@ -425,7 +419,7 @@ _buildProofTransform(
iProofIntent,
cmsFLAGS);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS;
if (!hTransform) {
PyErr_SetString(PyExc_ValueError, "cannot build proof transform");

View File

@ -490,8 +490,7 @@ text_layout(
size_t count;
#ifdef HAVE_RAQM
if (have_raqm && self->layout_engine == LAYOUT_RAQM) {
count = text_layout_raqm(
string, self, dir, features, lang, glyph_info);
count = text_layout_raqm(string, self, dir, features, lang, glyph_info);
} else
#endif
{
@ -550,7 +549,17 @@ font_getlength(FontObject *self, PyObject *args) {
}
static int
bounding_box_and_anchors(FT_Face face, const char *anchor, int horizontal_dir, GlyphInfo *glyph_info, size_t count, int load_flags, int *width, int *height, int *x_offset, int *y_offset) {
bounding_box_and_anchors(
FT_Face face,
const char *anchor,
int horizontal_dir,
GlyphInfo *glyph_info,
size_t count,
int load_flags,
int *width,
int *height,
int *x_offset,
int *y_offset) {
int position; /* pen position along primary axis, in 26.6 precision */
int advanced; /* pen position along primary axis, in pixels */
int px, py; /* position of current glyph, in pixels */
@ -654,8 +663,7 @@ bounding_box_and_anchors(FT_Face face, const char *anchor, int horizontal_dir, G
break;
case 'm': // middle (ascender + descender) / 2
y_anchor = PIXEL(
(face->size->metrics.ascender +
face->size->metrics.descender) /
(face->size->metrics.ascender + face->size->metrics.descender) /
2);
break;
case 's': // horizontal baseline
@ -758,7 +766,17 @@ font_getsize(FontObject *self, PyObject *args) {
load_flags |= FT_LOAD_COLOR;
}
error = bounding_box_and_anchors(self->face, anchor, horizontal_dir, glyph_info, count, load_flags, &width, &height, &x_offset, &y_offset);
error = bounding_box_and_anchors(
self->face,
anchor,
horizontal_dir,
glyph_info,
count,
load_flags,
&width,
&height,
&x_offset,
&y_offset);
if (glyph_info) {
PyMem_Free(glyph_info);
glyph_info = NULL;
@ -767,12 +785,7 @@ font_getsize(FontObject *self, PyObject *args) {
return NULL;
}
return Py_BuildValue(
"(ii)(ii)",
width,
height,
x_offset,
y_offset);
return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);
}
static PyObject *
@ -869,7 +882,17 @@ font_render(FontObject *self, PyObject *args) {
horizontal_dir = dir && strcmp(dir, "ttb") == 0 ? 0 : 1;
error = bounding_box_and_anchors(self->face, anchor, horizontal_dir, glyph_info, count, load_flags, &width, &height, &x_offset, &y_offset);
error = bounding_box_and_anchors(
self->face,
anchor,
horizontal_dir,
glyph_info,
count,
load_flags,
&width,
&height,
&x_offset,
&y_offset);
if (error) {
PyMem_Del(glyph_info);
return NULL;
@ -1066,17 +1089,26 @@ font_render(FontObject *self, PyObject *args) {
/* paste only if source has data */
if (src_alpha > 0) {
/* unpremultiply BGRa */
int src_red = CLIP8((255 * (int)source[k * 4 + 2]) / src_alpha);
int src_green = CLIP8((255 * (int)source[k * 4 + 1]) / src_alpha);
int src_blue = CLIP8((255 * (int)source[k * 4 + 0]) / src_alpha);
int src_red =
CLIP8((255 * (int)source[k * 4 + 2]) / src_alpha);
int src_green =
CLIP8((255 * (int)source[k * 4 + 1]) / src_alpha);
int src_blue =
CLIP8((255 * (int)source[k * 4 + 0]) / src_alpha);
/* blend required if target has data */
if (target[k * 4 + 3] > 0) {
/* blend RGBA colors */
target[k * 4 + 0] = BLEND(src_alpha, target[k * 4 + 0], src_red, tmp);
target[k * 4 + 1] = BLEND(src_alpha, target[k * 4 + 1], src_green, tmp);
target[k * 4 + 2] = BLEND(src_alpha, target[k * 4 + 2], src_blue, tmp);
target[k * 4 + 3] = CLIP8(src_alpha + MULDIV255(target[k * 4 + 3], (255 - src_alpha), tmp));
target[k * 4 + 0] =
BLEND(src_alpha, target[k * 4 + 0], src_red, tmp);
target[k * 4 + 1] =
BLEND(src_alpha, target[k * 4 + 1], src_green, tmp);
target[k * 4 + 2] =
BLEND(src_alpha, target[k * 4 + 2], src_blue, tmp);
target[k * 4 + 3] = CLIP8(
src_alpha +
MULDIV255(
target[k * 4 + 3], (255 - src_alpha), tmp));
} else {
/* paste unpremultiplied RGBA values */
target[k * 4 + 0] = src_red;
@ -1093,10 +1125,16 @@ font_render(FontObject *self, PyObject *args) {
unsigned int src_alpha = source[k] * convert_scale;
if (src_alpha > 0) {
if (target[k * 4 + 3] > 0) {
target[k * 4 + 0] = BLEND(src_alpha, target[k * 4 + 0], ink[0], tmp);
target[k * 4 + 1] = BLEND(src_alpha, target[k * 4 + 1], ink[1], tmp);
target[k * 4 + 2] = BLEND(src_alpha, target[k * 4 + 2], ink[2], tmp);
target[k * 4 + 3] = CLIP8(src_alpha + MULDIV255(target[k * 4 + 3], (255 - src_alpha), tmp));
target[k * 4 + 0] = BLEND(
src_alpha, target[k * 4 + 0], ink[0], tmp);
target[k * 4 + 1] = BLEND(
src_alpha, target[k * 4 + 1], ink[1], tmp);
target[k * 4 + 2] = BLEND(
src_alpha, target[k * 4 + 2], ink[2], tmp);
target[k * 4 + 3] = CLIP8(
src_alpha +
MULDIV255(
target[k * 4 + 3], (255 - src_alpha), tmp));
} else {
target[k * 4 + 0] = ink[0];
target[k * 4 + 1] = ink[1];
@ -1109,7 +1147,13 @@ font_render(FontObject *self, PyObject *args) {
for (k = x0; k < x1; k++) {
unsigned int src_alpha = source[k] * convert_scale;
if (src_alpha > 0) {
target[k] = target[k] > 0 ? CLIP8(src_alpha + MULDIV255(target[k], (255 - src_alpha), tmp)) : src_alpha;
target[k] =
target[k] > 0
? CLIP8(
src_alpha +
MULDIV255(
target[k], (255 - src_alpha), tmp))
: src_alpha;
}
}
}
@ -1249,7 +1293,8 @@ font_getvaraxes(FontObject *self) {
if (name.name_id == axis.strid) {
axis_name = Py_BuildValue("y#", name.string, name.string_len);
PyDict_SetItemString(list_axis, "name", axis_name ? axis_name : Py_None);
PyDict_SetItemString(
list_axis, "name", axis_name ? axis_name : Py_None);
Py_XDECREF(axis_name);
break;
}

View File

@ -1163,8 +1163,10 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
((JPEGENCODERSTATE *)encoder->state.context)->streamtype = streamtype;
((JPEGENCODERSTATE *)encoder->state.context)->xdpi = xdpi;
((JPEGENCODERSTATE *)encoder->state.context)->ydpi = ydpi;
((JPEGENCODERSTATE *)encoder->state.context)->restart_marker_blocks = restart_marker_blocks;
((JPEGENCODERSTATE *)encoder->state.context)->restart_marker_rows = restart_marker_rows;
((JPEGENCODERSTATE *)encoder->state.context)->restart_marker_blocks =
restart_marker_blocks;
((JPEGENCODERSTATE *)encoder->state.context)->restart_marker_rows =
restart_marker_rows;
((JPEGENCODERSTATE *)encoder->state.context)->comment = comment;
((JPEGENCODERSTATE *)encoder->state.context)->comment_size = comment_size;
((JPEGENCODERSTATE *)encoder->state.context)->extra = extra;
@ -1333,9 +1335,7 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
if (comment && comment_size > 0) {
/* Size is stored as as an uint16, subtract 4 bytes for the header */
if (comment_size >= 65532) {
PyErr_SetString(
PyExc_ValueError,
"JPEG 2000 comment is too long");
PyErr_SetString(PyExc_ValueError, "JPEG 2000 comment is too long");
Py_DECREF(encoder);
return NULL;
}

View File

@ -83,7 +83,6 @@ decode_bc1_color(rgba *dst, const UINT8 *src, int separate_alpha) {
g1 = p[1].g;
b1 = p[1].b;
/* NOTE: BC2 and BC3 reuse BC1 color blocks but always act like c0 > c1 */
if (col.c0 > col.c1 || separate_alpha) {
p[2].r = (2 * r0 + 1 * r1) / 3;
@ -354,8 +353,7 @@ decode_bc7_block(rgba *col, const UINT8 *src) {
}
return;
}
while (!(mode & (1 << bit++)))
;
while (!(mode & (1 << bit++)));
mode = bit - 1;
info = &bc7_modes[mode];
/* color selection bits: {subset}{endpoint} */
@ -826,7 +824,13 @@ put_block(Imaging im, ImagingCodecState state, const char *col, int sz, int C) {
static int
decode_bcn(
Imaging im, ImagingCodecState state, const UINT8 *src, int bytes, int N, int C, char *pixel_format) {
Imaging im,
ImagingCodecState state,
const UINT8 *src,
int bytes,
int N,
int C,
char *pixel_format) {
int ymax = state->ysize + state->yoff;
const UINT8 *ptr = src;
switch (N) {
@ -849,8 +853,7 @@ decode_bcn(
DECODE_LOOP(2, 16, rgba);
DECODE_LOOP(3, 16, rgba);
DECODE_LOOP(4, 8, lum);
case 5:
{
case 5: {
int sign = strcmp(pixel_format, "BC5S") == 0 ? 1 : 0;
while (bytes >= 16) {
rgba col[16];
@ -865,8 +868,7 @@ decode_bcn(
}
break;
}
case 6:
{
case 6: {
int sign = strcmp(pixel_format, "BC6HS") == 0 ? 1 : 0;
while (bytes >= 16) {
rgba col[16];

View File

@ -313,12 +313,12 @@ _gaussian_blur_radius(float radius, int passes) {
}
Imaging
ImagingGaussianBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int passes) {
ImagingGaussianBlur(
Imaging imOut, Imaging imIn, float xradius, float yradius, int passes) {
return ImagingBoxBlur(
imOut,
imIn,
_gaussian_blur_radius(xradius, passes),
_gaussian_blur_radius(yradius, passes),
passes
);
passes);
}

View File

@ -518,8 +518,8 @@ rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) {
/*
* Conversion of RGB + single transparent color either to
* RGBA or LA, where any pixel matching the color will have the alpha channel set to 0, or
* RGBa or La, where any pixel matching the color will have all channels set to 0
* RGBA or LA, where any pixel matching the color will have the alpha channel set to 0,
* or RGBa or La, where any pixel matching the color will have all channels set to 0
*/
static void
@ -1676,7 +1676,8 @@ convert(
return (Imaging)ImagingError_ValueError("conversion not supported");
#else
static char buf[100];
snprintf(buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode);
snprintf(
buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode);
return (Imaging)ImagingError_ValueError(buf);
#endif
}
@ -1720,25 +1721,24 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
return (Imaging)ImagingError_ModeError();
}
if (strcmp(imIn->mode, "RGB") == 0 && (strcmp(mode, "RGBA") == 0 || strcmp(mode, "RGBa") == 0)) {
if (strcmp(imIn->mode, "RGB") == 0 &&
(strcmp(mode, "RGBA") == 0 || strcmp(mode, "RGBa") == 0)) {
convert = rgb2rgba;
if (strcmp(mode, "RGBa") == 0) {
premultiplied = 1;
}
} else if (strcmp(imIn->mode, "RGB") == 0 && (strcmp(mode, "LA") == 0 || strcmp(mode, "La") == 0)) {
} else if (
strcmp(imIn->mode, "RGB") == 0 &&
(strcmp(mode, "LA") == 0 || strcmp(mode, "La") == 0)) {
convert = rgb2la;
source_transparency = 1;
if (strcmp(mode, "La") == 0) {
premultiplied = 1;
}
} else if ((strcmp(imIn->mode, "1") == 0 ||
strcmp(imIn->mode, "I") == 0 ||
strcmp(imIn->mode, "I;16") == 0 ||
strcmp(imIn->mode, "L") == 0
) && (
strcmp(mode, "RGBA") == 0 ||
strcmp(mode, "LA") == 0
)) {
} else if (
(strcmp(imIn->mode, "1") == 0 || strcmp(imIn->mode, "I") == 0 ||
strcmp(imIn->mode, "I;16") == 0 || strcmp(imIn->mode, "L") == 0) &&
(strcmp(mode, "RGBA") == 0 || strcmp(mode, "LA") == 0)) {
if (strcmp(imIn->mode, "1") == 0) {
convert = bit2rgb;
} else if (strcmp(imIn->mode, "I") == 0) {

View File

@ -439,7 +439,14 @@ draw_horizontal_lines(
* Filled polygon draw function using scan line algorithm.
*/
static inline int
polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler hline, int hasAlpha) {
polygon_generic(
Imaging im,
int n,
Edge *e,
int ink,
int eofill,
hline_handler hline,
int hasAlpha) {
Edge **edge_table;
float *xx;
int edge_count = 0;
@ -510,23 +517,38 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
// Check if the two edges join to make a corner
if (((ymin == current->ymin && ymin == other_edge->ymin) ||
(ymin == current->ymax && ymin == other_edge->ymax)) &&
xx[j-1] == (ymin - other_edge->y0) * other_edge->dx + other_edge->x0) {
xx[j - 1] == (ymin - other_edge->y0) * other_edge->dx +
other_edge->x0) {
// Determine points from the edges on the next row
// Or if this is the last row, check the previous row
int offset = ymin == ymax ? -1 : 1;
adjacent_line_x = (ymin + offset - current->y0) * current->dx + current->x0;
adjacent_line_x_other_edge = (ymin + offset - other_edge->y0) * other_edge->dx + other_edge->x0;
adjacent_line_x =
(ymin + offset - current->y0) * current->dx +
current->x0;
adjacent_line_x_other_edge =
(ymin + offset - other_edge->y0) * other_edge->dx +
other_edge->x0;
if (ymin == current->ymax) {
if (current->dx > 0) {
xx[k] = fmax(adjacent_line_x, adjacent_line_x_other_edge) + 1;
xx[k] = fmax(
adjacent_line_x,
adjacent_line_x_other_edge) +
1;
} else {
xx[k] = fmin(adjacent_line_x, adjacent_line_x_other_edge) - 1;
xx[k] = fmin(
adjacent_line_x,
adjacent_line_x_other_edge) -
1;
}
} else {
if (current->dx > 0) {
xx[k] = fmin(adjacent_line_x, adjacent_line_x_other_edge);
xx[k] = fmin(
adjacent_line_x, adjacent_line_x_other_edge);
} else {
xx[k] = fmax(adjacent_line_x, adjacent_line_x_other_edge) + 1;
xx[k] = fmax(
adjacent_line_x,
adjacent_line_x_other_edge) +
1;
}
}
break;
@ -552,7 +574,8 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
int x_start = ROUND_UP(xx[i - 1]);
if (x_pos > x_start) {
// Line would be partway through x_pos, so increase the starting point
// Line would be partway through x_pos, so increase the starting
// point
x_start = x_pos;
if (x_end < x_start) {
// Line would now end before it started
@ -776,7 +799,8 @@ ImagingDrawRectangle(
}
int
ImagingDrawPolygon(Imaging im, int count, int *xy, const void *ink_, int fill, int width, int op) {
ImagingDrawPolygon(
Imaging im, int count, int *xy, const void *ink_, int fill, int width, int op) {
int i, n, x0, y0, x1, y1;
DRAW *draw;
INT32 ink;
@ -826,14 +850,24 @@ ImagingDrawPolygon(Imaging im, int count, int *xy, const void *ink_, int fill, i
/* Outline */
if (width == 1) {
for (i = 0; i < count - 1; i++) {
draw->line(im, xy[i * 2], xy[i * 2 + 1], xy[i * 2 + 2], xy[i * 2 + 3], ink);
draw->line(
im, xy[i * 2], xy[i * 2 + 1], xy[i * 2 + 2], xy[i * 2 + 3], ink);
}
draw->line(im, xy[i * 2], xy[i * 2 + 1], xy[0], xy[1], ink);
} else {
for (i = 0; i < count - 1; i++) {
ImagingDrawWideLine(im, xy[i * 2], xy[i * 2 + 1], xy[i * 2 + 2], xy[i * 2 + 3], ink_, width, op);
ImagingDrawWideLine(
im,
xy[i * 2],
xy[i * 2 + 1],
xy[i * 2 + 2],
xy[i * 2 + 3],
ink_,
width,
op);
}
ImagingDrawWideLine(im, xy[i * 2], xy[i * 2 + 1], xy[0], xy[1], ink_, width, op);
ImagingDrawWideLine(
im, xy[i * 2], xy[i * 2 + 1], xy[0], xy[1], ink_, width, op);
}
}

View File

@ -225,9 +225,8 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float *kernel, float offset) {
void
ImagingFilter5x5(Imaging imOut, Imaging im, const float *kernel, float offset) {
#define KERNEL1x5(in0, x, kernel, d) \
(_i2f(in0[x - d - d]) * (kernel)[0] + \
_i2f(in0[x - d]) * (kernel)[1] + _i2f(in0[x]) * (kernel)[2] + \
_i2f(in0[x + d]) * (kernel)[3] + \
(_i2f(in0[x - d - d]) * (kernel)[0] + _i2f(in0[x - d]) * (kernel)[1] + \
_i2f(in0[x]) * (kernel)[2] + _i2f(in0[x + d]) * (kernel)[3] + \
_i2f(in0[x + d + d]) * (kernel)[4])
int x = 0, y = 0;

View File

@ -231,8 +231,9 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
}
/* Note, have to check Data + size, not just ptr + size) */
if (data + (state->xsize * state->ysize) > ptr + bytes) {
/* not enough data for frame */
/* UNDONE Unclear that we're actually going to leave the buffer at the right place. */
// not enough data for frame
// UNDONE Unclear that we're actually going to leave the buffer at
// the right place.
return ptr - buf; /* bytes consumed */
}
for (y = 0; y < state->ysize; y++) {

View File

@ -58,11 +58,11 @@ ImagingGetBBox(Imaging im, int bbox[4], int alpha_only) {
INT32 mask = 0xffffffff;
if (im->bands == 3) {
((UINT8 *)&mask)[3] = 0;
} else if (alpha_only && (
strcmp(im->mode, "RGBa") == 0 || strcmp(im->mode, "RGBA") == 0 ||
} else if (
alpha_only &&
(strcmp(im->mode, "RGBa") == 0 || strcmp(im->mode, "RGBA") == 0 ||
strcmp(im->mode, "La") == 0 || strcmp(im->mode, "LA") == 0 ||
strcmp(im->mode, "PA") == 0
)) {
strcmp(im->mode, "PA") == 0)) {
#ifdef WORDS_BIGENDIAN
mask = 0x000000ff;
#else

View File

@ -42,20 +42,28 @@ enum { INIT, ENCODE, FINISH };
#define CODE_LIMIT 4096
/* Values of entry_state */
enum { LZW_INITIAL, LZW_TRY_IN1, LZW_TRY_IN2, LZW_TRY_OUT1, LZW_TRY_OUT2,
LZW_FINISHED };
enum {
LZW_INITIAL,
LZW_TRY_IN1,
LZW_TRY_IN2,
LZW_TRY_OUT1,
LZW_TRY_OUT2,
LZW_FINISHED
};
/* Values of control_state */
enum { PUT_HEAD, PUT_INIT_CLEAR, PUT_CLEAR, PUT_LAST_HEAD, PUT_END };
static void glzwe_reset(GIFENCODERSTATE *st) {
static void
glzwe_reset(GIFENCODERSTATE *st) {
st->next_code = st->end_code + 1;
st->max_code = 2 * st->clear_code - 1;
st->code_width = st->bits + 1;
memset(st->codes, 0, sizeof(st->codes));
}
static void glzwe_init(GIFENCODERSTATE *st) {
static void
glzwe_init(GIFENCODERSTATE *st) {
st->clear_code = 1 << st->bits;
st->end_code = st->clear_code + 1;
glzwe_reset(st);
@ -64,11 +72,15 @@ static void glzwe_init(GIFENCODERSTATE *st) {
st->code_buffer = 0;
}
static int glzwe(GIFENCODERSTATE *st, const UINT8 *in_ptr, UINT8 *out_ptr,
UINT32 *in_avail, UINT32 *out_avail,
static int
glzwe(
GIFENCODERSTATE *st,
const UINT8 *in_ptr,
UINT8 *out_ptr,
UINT32 *in_avail,
UINT32 *out_avail,
UINT32 end_of_data) {
switch (st->entry_state) {
case LZW_TRY_IN1:
get_first_byte:
if (!*in_avail) {
@ -100,13 +112,12 @@ encode_loop:
/* This works ONLY with TABLE_SIZE a power of 2. */
st->probe = ((st->head ^ (st->tail << 6)) * 31) & (TABLE_SIZE - 1);
while (st->codes[st->probe]) {
if ((st->codes[st->probe] & 0xFFFFF) ==
((st->head << 8) | st->tail)) {
if ((st->codes[st->probe] & 0xFFFFF) == ((st->head << 8) | st->tail)) {
st->head = st->codes[st->probe] >> 20;
goto encode_loop;
} else {
/* Reprobe decrement must be non-zero and relatively prime to table
* size. So, any odd positive number for power-of-2 size. */
// Reprobe decrement must be non-zero and relatively prime to table
// size. So, any odd positive number for power-of-2 size.
if ((st->probe -= ((st->tail << 2) | 1)) < 0) {
st->probe += TABLE_SIZE;
}
@ -118,8 +129,8 @@ encode_loop:
goto put_code;
insert_code_or_clear: /* jump here after put_code */
if (st->next_code < CODE_LIMIT) {
st->codes[st->probe] = (st->next_code << 20) |
(st->head << 8) | st->tail;
st->codes[st->probe] =
(st->next_code << 20) | (st->head << 8) | st->tail;
if (st->next_code > st->max_code) {
st->max_code = st->max_code * 2 + 1;
st->code_width++;
@ -155,10 +166,9 @@ check_buf_bits:
st->buf_bits_left = 8;
}
/* code bits to pack */
UINT32 n = st->buf_bits_left < st->code_bits_left
? st->buf_bits_left : st->code_bits_left;
st->code_buffer |=
(st->code & ((1 << n) - 1)) << (8 - st->buf_bits_left);
UINT32 n = st->buf_bits_left < st->code_bits_left ? st->buf_bits_left
: st->code_bits_left;
st->code_buffer |= (st->code & ((1 << n) - 1)) << (8 - st->buf_bits_left);
st->code >>= n;
st->buf_bits_left -= n;
st->code_bits_left -= n;
@ -186,7 +196,6 @@ end_of_data:
goto put_code;
flush_code_buffer: /* jump here after put_code */
if (st->buf_bits_left < 8) {
case LZW_TRY_OUT2:
if (!*out_avail) {
st->entry_state = LZW_TRY_OUT2;
@ -278,9 +287,9 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) {
return ptr - buf;
}
sub_block_ptr = ptr;
sub_block_limit = sub_block_ptr +
(256 < buf_limit - sub_block_ptr ?
256 : buf_limit - sub_block_ptr);
sub_block_limit =
sub_block_ptr +
(256 < buf_limit - sub_block_ptr ? 256 : buf_limit - sub_block_ptr);
*ptr++ = 0;
}
@ -302,8 +311,8 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) {
state->shuffle(
state->buffer,
(UINT8 *)im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize
);
state->xoff * im->pixelsize,
state->xsize);
state->x = 0;
/* step forward, according to the interlace settings */
@ -333,8 +342,13 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) {
in_avail = state->xsize - state->x; /* bytes left in line */
out_avail = sub_block_limit - ptr; /* bytes left in sub-block */
r = glzwe(context, &state->buffer[state->x], ptr, &in_avail,
&out_avail, state->state == FINISH);
r = glzwe(
context,
&state->buffer[state->x],
ptr,
&in_avail,
&out_avail,
state->state == FINISH);
out_used = sub_block_limit - ptr - out_avail;
*sub_block_ptr += out_used;
ptr += out_used;

View File

@ -309,7 +309,8 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
extern Imaging
ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
extern Imaging
ImagingGaussianBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int passes);
ImagingGaussianBlur(
Imaging imOut, Imaging imIn, float xradius, float yradius, int passes);
extern Imaging
ImagingGetBand(Imaging im, int band);
extern Imaging
@ -487,7 +488,8 @@ ImagingDrawPieslice(
extern int
ImagingDrawPoint(Imaging im, int x, int y, const void *ink, int op);
extern int
ImagingDrawPolygon(Imaging im, int points, int *xy, const void *ink, int fill, int width, int op);
ImagingDrawPolygon(
Imaging im, int points, int *xy, const void *ink, int fill, int width, int op);
extern int
ImagingDrawRectangle(
Imaging im,

View File

@ -383,8 +383,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state) {
float *pq;
if (len > 0) {
if ((size_t)len >
sizeof(params.tcp_rates) / sizeof(params.tcp_rates[0])) {
if ((size_t)len > sizeof(params.tcp_rates) / sizeof(params.tcp_rates[0])) {
len = sizeof(params.tcp_rates) / sizeof(params.tcp_rates[0]);
}
@ -464,7 +463,8 @@ j2k_encode_entry(Imaging im, ImagingCodecState state) {
}
if (!context->num_resolutions) {
while (tile_width < (1U << (params.numresolution - 1U)) || tile_height < (1U << (params.numresolution - 1U))) {
while (tile_width < (1U << (params.numresolution - 1U)) ||
tile_height < (1U << (params.numresolution - 1U))) {
params.numresolution -= 1;
}
}

View File

@ -305,7 +305,11 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
case 4:
if (context->comment) {
jpeg_write_marker(&context->cinfo, JPEG_COM, (unsigned char *)context->comment, context->comment_size);
jpeg_write_marker(
&context->cinfo,
JPEG_COM,
(unsigned char *)context->comment,
context->comment_size);
}
state->state++;

View File

@ -432,10 +432,9 @@ fill_mask_L(
}
} else {
int alpha_channel = strcmp(imOut->mode, "RGBa") == 0 ||
strcmp(imOut->mode, "RGBA") == 0 ||
strcmp(imOut->mode, "La") == 0 ||
strcmp(imOut->mode, "LA") == 0 ||
int alpha_channel =
strcmp(imOut->mode, "RGBa") == 0 || strcmp(imOut->mode, "RGBA") == 0 ||
strcmp(imOut->mode, "La") == 0 || strcmp(imOut->mode, "LA") == 0 ||
strcmp(imOut->mode, "PA") == 0;
for (y = 0; y < ysize; y++) {
UINT8 *out = (UINT8 *)imOut->image[y + dy] + dx * pixelsize;

View File

@ -260,8 +260,7 @@ mergesort_pixels(PixelList *head, int i) {
return head;
}
for (c = t = head; c && t;
c = c->next[i], t = (t->next[i]) ? t->next[i]->next[i] : NULL)
;
c = c->next[i], t = (t->next[i]) ? t->next[i]->next[i] : NULL);
if (c) {
if (c->prev[i]) {
c->prev[i]->next[i] = NULL;
@ -354,12 +353,10 @@ splitlists(
for (_i = 0; _i < 3; _i++) {
for (_nextCount[_i] = 0, _nextTest = h[_i];
_nextTest && _nextTest->next[_i];
_nextTest = _nextTest->next[_i], _nextCount[_i]++)
;
_nextTest = _nextTest->next[_i], _nextCount[_i]++);
for (_prevCount[_i] = 0, _prevTest = t[_i];
_prevTest && _prevTest->prev[_i];
_prevTest = _prevTest->prev[_i], _prevCount[_i]++)
;
_prevTest = _prevTest->prev[_i], _prevCount[_i]++);
if (_nextTest != t[_i]) {
printf("next-list of axis %d does not end at tail\n", _i);
exit(1);
@ -368,10 +365,8 @@ splitlists(
printf("prev-list of axis %d does not end at head\n", _i);
exit(1);
}
for (; _nextTest && _nextTest->prev[_i]; _nextTest = _nextTest->prev[_i])
;
for (; _prevTest && _prevTest->next[_i]; _prevTest = _prevTest->next[_i])
;
for (; _nextTest && _nextTest->prev[_i]; _nextTest = _nextTest->prev[_i]);
for (; _prevTest && _prevTest->next[_i]; _prevTest = _prevTest->next[_i]);
if (_nextTest != h[_i]) {
printf("next-list of axis %d does not loop back to head\n", _i);
exit(1);
@ -548,22 +543,18 @@ split(BoxNode *node) {
for (_i = 0; _i < 3; _i++) {
for (_nextCount[_i] = 0, _nextTest = node->head[_i];
_nextTest && _nextTest->next[_i];
_nextTest = _nextTest->next[_i], _nextCount[_i]++)
;
_nextTest = _nextTest->next[_i], _nextCount[_i]++);
for (_prevCount[_i] = 0, _prevTest = node->tail[_i];
_prevTest && _prevTest->prev[_i];
_prevTest = _prevTest->prev[_i], _prevCount[_i]++)
;
_prevTest = _prevTest->prev[_i], _prevCount[_i]++);
if (_nextTest != node->tail[_i]) {
printf("next-list of axis %d does not end at tail\n", _i);
}
if (_prevTest != node->head[_i]) {
printf("prev-list of axis %d does not end at head\n", _i);
}
for (; _nextTest && _nextTest->prev[_i]; _nextTest = _nextTest->prev[_i])
;
for (; _prevTest && _prevTest->next[_i]; _prevTest = _prevTest->next[_i])
;
for (; _nextTest && _nextTest->prev[_i]; _nextTest = _nextTest->prev[_i]);
for (; _prevTest && _prevTest->next[_i]; _prevTest = _prevTest->next[_i]);
if (_nextTest != node->head[_i]) {
printf("next-list of axis %d does not loop back to head\n", _i);
}
@ -668,8 +659,7 @@ median_cut(PixelList *hl[3], uint32_t imPixelCount, int nPixels) {
return NULL;
}
for (i = 0; i < 3; i++) {
for (tl[i] = hl[i]; tl[i] && tl[i]->next[i]; tl[i] = tl[i]->next[i])
;
for (tl[i] = hl[i]; tl[i] && tl[i]->next[i]; tl[i] = tl[i]->next[i]);
root->head[i] = hl[i];
root->tail[i] = tl[i];
}
@ -832,16 +822,9 @@ build_distance_tables(
}
for (i = 0; i < nEntries; i++) {
for (j = 0; j < nEntries; j++) {
dwi[j] = (DistanceWithIndex){
&(avgDist[i * nEntries + j]),
j
};
dwi[j] = (DistanceWithIndex){&(avgDist[i * nEntries + j]), j};
}
qsort(
dwi,
nEntries,
sizeof(DistanceWithIndex),
_distance_index_cmp);
qsort(dwi, nEntries, sizeof(DistanceWithIndex), _distance_index_cmp);
for (j = 0; j < nEntries; j++) {
avgDistSortKey[i * nEntries + j] = dwi[j].distance;
}
@ -1452,15 +1435,17 @@ quantize(
hashtable_insert(h2, pixelData[i], bestmatch);
}
if (qp[i] != bestmatch) {
printf ("discrepancy in matching algorithms pixel %d [%d %d] %f %f\n",
i,qp[i],bestmatch,
printf(
"discrepancy in matching algorithms pixel %d [%d %d] %f %f\n",
i,
qp[i],
bestmatch,
sqrt((double)(_SQR(pixelData[i].c.r - p[qp[i]].c.r) +
_SQR(pixelData[i].c.g - p[qp[i]].c.g) +
_SQR(pixelData[i].c.b - p[qp[i]].c.b))),
sqrt((double)(_SQR(pixelData[i].c.r - p[bestmatch].c.r) +
_SQR(pixelData[i].c.g - p[bestmatch].c.g) +
_SQR(pixelData[i].c.b-p[bestmatch].c.b)))
);
_SQR(pixelData[i].c.b - p[bestmatch].c.b))));
}
}
hashtable_free(h2);

View File

@ -113,7 +113,8 @@ expandrow(UINT8 *dest, UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer
}
static int
expandrow2(UINT8 *dest, const UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer) {
expandrow2(
UINT8 *dest, const UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer) {
UINT8 pixel, count;
int x = 0;
@ -197,7 +198,6 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
return -1;
}
/* decoder initialization */
state->count = 0;
state->y = 0;
@ -268,7 +268,6 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
} else if (status == 1) {
goto sgi_finish_decode;
}
}
/* store decompressed data in image */

View File

@ -418,8 +418,7 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) {
}
im->blocks[current_block] = block;
/* Bulletproof code from libc _int_memalign */
aligned_ptr = (char *)(
((size_t) (block.ptr + arena->alignment - 1)) &
aligned_ptr = (char *)(((size_t)(block.ptr + arena->alignment - 1)) &
-((Py_ssize_t)arena->alignment));
}

View File

@ -60,7 +60,11 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) {
dump_state(state);
if (state->loc > state->eof) {
TIFFError("_tiffReadProc", "Invalid Read at loc %" PRIu64 ", eof: %" PRIu64, state->loc, state->eof);
TIFFError(
"_tiffReadProc",
"Invalid Read at loc %" PRIu64 ", eof: %" PRIu64,
state->loc,
state->eof);
return 0;
}
to_read = min(size, min(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
@ -217,7 +221,12 @@ ImagingLibTiffInit(ImagingCodecState state, int fp, uint32_t offset) {
}
int
_pickUnpackers(Imaging im, ImagingCodecState state, TIFF *tiff, uint16_t planarconfig, ImagingShuffler *unpackers) {
_pickUnpackers(
Imaging im,
ImagingCodecState state,
TIFF *tiff,
uint16_t planarconfig,
ImagingShuffler *unpackers) {
// if number of bands is 1, there is no difference with contig case
if (planarconfig == PLANARCONFIG_SEPARATE && im->bands > 1) {
uint16_t bits_per_sample = 8;
@ -232,10 +241,14 @@ _pickUnpackers(Imaging im, ImagingCodecState state, TIFF *tiff, uint16_t planarc
// We'll pick appropriate set of unpackers depending on planar_configuration
// It does not matter if data is RGB(A), CMYK or LUV really,
// we just copy it plane by plane
unpackers[0] = ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "R;16N" : "R", NULL);
unpackers[1] = ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "G;16N" : "G", NULL);
unpackers[2] = ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "B;16N" : "B", NULL);
unpackers[3] = ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "A;16N" : "A", NULL);
unpackers[0] =
ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "R;16N" : "R", NULL);
unpackers[1] =
ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "G;16N" : "G", NULL);
unpackers[2] =
ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "B;16N" : "B", NULL);
unpackers[3] =
ImagingFindUnpacker("RGBA", bits_per_sample == 16 ? "A;16N" : "A", NULL);
return im->bands;
} else {
@ -247,10 +260,10 @@ _pickUnpackers(Imaging im, ImagingCodecState state, TIFF *tiff, uint16_t planarc
int
_decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
// To avoid dealing with YCbCr subsampling and other complications, let libtiff handle it
// Use a TIFFRGBAImage wrapping the tiff image, and let libtiff handle
// all of the conversion. Metadata read from the TIFFRGBAImage could
// be different from the metadata that the base tiff returns.
// To avoid dealing with YCbCr subsampling and other complications, let libtiff
// handle it Use a TIFFRGBAImage wrapping the tiff image, and let libtiff handle all
// of the conversion. Metadata read from the TIFFRGBAImage could be different from
// the metadata that the base tiff returns.
INT32 current_row;
UINT8 *new_data;
@ -259,13 +272,12 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
TIFFRGBAImage img;
char emsg[1024] = "";
// Since using TIFFRGBAImage* functions, we can read whole tiff into rastrr in one call
// Let's select smaller block size. Multiplying image width by (tile length OR rows per strip)
// gives us manageable block size in pixels
// Since using TIFFRGBAImage* functions, we can read whole tiff into rastrr in one
// call Let's select smaller block size. Multiplying image width by (tile length OR
// rows per strip) gives us manageable block size in pixels
if (TIFFIsTiled(tiff)) {
ret = TIFFGetFieldDefaulted(tiff, TIFFTAG_TILELENGTH, &rows_per_block);
}
else {
} else {
ret = TIFFGetFieldDefaulted(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_block);
}
@ -357,7 +369,12 @@ decodergba_err:
}
int
_decodeTile(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, ImagingShuffler *unpackers) {
_decodeTile(
Imaging im,
ImagingCodecState state,
TIFF *tiff,
int planes,
ImagingShuffler *unpackers) {
INT32 x, y, tile_y, current_tile_length, current_tile_width;
UINT32 tile_width, tile_length;
tsize_t tile_bytes_size, row_byte_size;
@ -396,8 +413,8 @@ _decodeTile(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imaging
if (tile_bytes_size > ((tile_length * state->bits / planes + 7) / 8) * tile_width) {
// If the tile size as expected by LibTiff isn't what we're expecting, abort.
// man: TIFFTileSize returns the equivalent size for a tile of data as it would be returned in a
// call to TIFFReadTile ...
// man: TIFFTileSize returns the equivalent size for a tile of data as it
// would be returned in a call to TIFFReadTile ...
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
@ -432,15 +449,20 @@ _decodeTile(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imaging
current_tile_length = min((INT32)tile_length, state->ysize - y);
// iterate over each line in the tile and stuff data into image
for (tile_y = 0; tile_y < current_tile_length; tile_y++) {
TRACE(("Writing tile data at %dx%d using tile_width: %d; \n", tile_y + y, x, current_tile_width));
TRACE(
("Writing tile data at %dx%d using tile_width: %d; \n",
tile_y + y,
x,
current_tile_width));
// UINT8 * bbb = state->buffer + tile_y * row_byte_size;
// TRACE(("chars: %x%x%x%x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3]));
// TRACE(("chars: %x%x%x%x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1],
// ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3]));
shuffler((UINT8*) im->image[tile_y + y] + x * im->pixelsize,
shuffler(
(UINT8 *)im->image[tile_y + y] + x * im->pixelsize,
state->buffer + tile_y * row_byte_size,
current_tile_width
);
current_tile_width);
}
}
}
@ -450,7 +472,12 @@ _decodeTile(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imaging
}
int
_decodeStrip(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, ImagingShuffler *unpackers) {
_decodeStrip(
Imaging im,
ImagingCodecState state,
TIFF *tiff,
int planes,
ImagingShuffler *unpackers) {
INT32 strip_row = 0;
UINT8 *new_data;
UINT32 rows_per_strip;
@ -478,8 +505,8 @@ _decodeStrip(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imagin
unpacker_row_byte_size = (state->xsize * state->bits / planes + 7) / 8;
if (strip_size > (unpacker_row_byte_size * rows_per_strip)) {
// If the strip size as expected by LibTiff isn't what we're expecting, abort.
// man: TIFFStripSize returns the equivalent size for a strip of data as it would be returned in a
// call to TIFFReadEncodedStrip ...
// man: TIFFStripSize returns the equivalent size for a strip of data as it
// would be returned in a call to TIFFReadEncodedStrip ...
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
@ -513,8 +540,13 @@ _decodeStrip(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imagin
int plane;
for (plane = 0; plane < planes; plane++) {
ImagingShuffler shuffler = unpackers[plane];
if (TIFFReadEncodedStrip(tiff, TIFFComputeStrip(tiff, state->y, plane), (tdata_t)state->buffer, strip_size) == -1) {
TRACE(("Decode Error, strip %d\n", TIFFComputeStrip(tiff, state->y, 0)));
if (TIFFReadEncodedStrip(
tiff,
TIFFComputeStrip(tiff, state->y, plane),
(tdata_t)state->buffer,
strip_size) == -1) {
TRACE(
("Decode Error, strip %d\n", TIFFComputeStrip(tiff, state->y, 0)));
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
@ -527,8 +559,9 @@ _decodeStrip(Imaging im, ImagingCodecState state, TIFF *tiff, int planes, Imagin
strip_row++) {
TRACE(("Writing data into line %d ; \n", state->y + strip_row));
// UINT8 * bbb = state->buffer + strip_row * (state->bytes / rows_per_strip);
// TRACE(("chars: %x %x %x %x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3]));
// UINT8 * bbb = state->buffer + strip_row * (state->bytes /
// rows_per_strip); TRACE(("chars: %x %x %x %x\n", ((UINT8 *)bbb)[0],
// ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3]));
shuffler(
(UINT8 *)im->image[state->y + state->yoff + strip_row] +
@ -666,7 +699,6 @@ ImagingLibTiffDecode(
goto decode_err;
}
TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric);
TIFFGetField(tiff, TIFFTAG_COMPRESSION, &compression);
TIFFGetFieldDefaulted(tiff, TIFFTAG_PLANARCONFIG, &planarconfig);
@ -675,16 +707,17 @@ ImagingLibTiffDecode(
// Let LibTiff read them as RGBA
readAsRGBA = photometric == PHOTOMETRIC_YCBCR;
if (readAsRGBA && compression == COMPRESSION_JPEG && planarconfig == PLANARCONFIG_CONTIG) {
// If using new JPEG compression, let libjpeg do RGB conversion for performance reasons
if (readAsRGBA && compression == COMPRESSION_JPEG &&
planarconfig == PLANARCONFIG_CONTIG) {
// If using new JPEG compression, let libjpeg do RGB conversion for performance
// reasons
TIFFSetField(tiff, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
readAsRGBA = 0;
}
if (readAsRGBA) {
_decodeAsRGBA(im, state, tiff);
}
else {
} else {
planes = _pickUnpackers(im, state, tiff, planarconfig, unpackers);
if (planes <= 0) {
goto decode_err;
@ -692,8 +725,7 @@ ImagingLibTiffDecode(
if (TIFFIsTiled(tiff)) {
_decodeTile(im, state, tiff, planes, unpackers);
}
else {
} else {
_decodeStrip(im, state, tiff, planes, unpackers);
}
@ -706,11 +738,11 @@ ImagingLibTiffDecode(
ImagingShuffler shuffle;
INT32 y;
TIFFGetFieldDefaulted(tiff, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo);
TIFFGetFieldDefaulted(
tiff, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo);
if (extrasamples >= 1 &&
(sampleinfo[0] == EXTRASAMPLE_UNSPECIFIED || sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)
) {
if (extrasamples >= 1 && (sampleinfo[0] == EXTRASAMPLE_UNSPECIFIED ||
sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)) {
shuffle = ImagingFindUnpacker("RGBA", "RGBa", NULL);
for (y = state->yoff; y < state->ysize; y++) {

View File

@ -1437,90 +1437,90 @@ band3I(UINT8 *out, const UINT8 *in, int pixels) {
}
static void
band016B(UINT8* out, const UINT8* in, int pixels)
{
band016B(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 0 only, big endian */
for (i = 0; i < pixels; i++) {
out[0] = in[0];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band116B(UINT8* out, const UINT8* in, int pixels)
{
band116B(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 1 only, big endian */
for (i = 0; i < pixels; i++) {
out[1] = in[0];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band216B(UINT8* out, const UINT8* in, int pixels)
{
band216B(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 2 only, big endian */
for (i = 0; i < pixels; i++) {
out[2] = in[0];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band316B(UINT8* out, const UINT8* in, int pixels)
{
band316B(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 3 only, big endian */
for (i = 0; i < pixels; i++) {
out[3] = in[0];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band016L(UINT8* out, const UINT8* in, int pixels)
{
band016L(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 0 only, little endian */
for (i = 0; i < pixels; i++) {
out[0] = in[1];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band116L(UINT8* out, const UINT8* in, int pixels)
{
band116L(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 1 only, little endian */
for (i = 0; i < pixels; i++) {
out[1] = in[1];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band216L(UINT8* out, const UINT8* in, int pixels)
{
band216L(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 2 only, little endian */
for (i = 0; i < pixels; i++) {
out[2] = in[1];
out += 4; in += 2;
out += 4;
in += 2;
}
}
static void
band316L(UINT8* out, const UINT8* in, int pixels)
{
band316L(UINT8 *out, const UINT8 *in, int pixels) {
int i;
/* band 3 only, little endian */
for (i = 0; i < pixels; i++) {
out[3] = in[1];
out += 4; in += 2;
out += 4;
in += 2;
}
}
@ -1687,7 +1687,6 @@ static struct {
{"RGB", "G;16N", 16, band116L},
{"RGB", "B;16N", 16, band216L},
{"RGBA", "R;16N", 16, band016L},
{"RGBA", "G;16N", 16, band116L},
{"RGBA", "B;16N", 16, band216L},