mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
309c5e261a
commit
12c5ad070b
|
@ -1,19 +1,16 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import warnings
|
from typing import Any # undone
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import assert_deep_equal, assert_image, hopper, skip_unless_feature
|
from .helper import assert_deep_equal, hopper
|
||||||
|
|
||||||
from typing import Any # undone
|
|
||||||
|
|
||||||
pyarrow = pytest.importorskip("pyarrow", reason="PyArrow not installed")
|
pyarrow = pytest.importorskip("pyarrow", reason="PyArrow not installed")
|
||||||
|
|
||||||
TEST_IMAGE_SIZE = (10, 10)
|
TEST_IMAGE_SIZE = (10, 10)
|
||||||
from numbers import Number
|
|
||||||
|
|
||||||
|
|
||||||
def _test_img_equals_pyarray(img: Image.Image, arr: Any, mask) -> None:
|
def _test_img_equals_pyarray(img: Image.Image, arr: Any, mask) -> None:
|
||||||
|
@ -24,19 +21,16 @@ def _test_img_equals_pyarray(img: Image.Image, arr: Any, mask) -> None:
|
||||||
for y in range(0, img.size[1], int(img.size[1] / 10)):
|
for y in range(0, img.size[1], int(img.size[1] / 10)):
|
||||||
if mask:
|
if mask:
|
||||||
for ix, elt in enumerate(mask):
|
for ix, elt in enumerate(mask):
|
||||||
assert px[x,y][ix] == arr[y * img.width + x].as_py()[elt]
|
assert px[x, y][ix] == arr[y * img.width + x].as_py()[elt]
|
||||||
else:
|
else:
|
||||||
assert_deep_equal(px[x, y], arr[y * img.width + x].as_py())
|
assert_deep_equal(px[x, y], arr[y * img.width + x].as_py())
|
||||||
|
|
||||||
|
|
||||||
# really hard to get a non-nullable list type
|
# really hard to get a non-nullable list type
|
||||||
fl_uint8_4_type = pyarrow.field("_",
|
fl_uint8_4_type = pyarrow.field(
|
||||||
pyarrow.list_(
|
"_", pyarrow.list_(pyarrow.field("_", pyarrow.uint8()).with_nullable(False), 4)
|
||||||
pyarrow.field("_",
|
).type
|
||||||
pyarrow.uint8()
|
|
||||||
).with_nullable(False)
|
|
||||||
,4)
|
|
||||||
).type
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode, dtype, mask",
|
"mode, dtype, mask",
|
||||||
|
@ -44,16 +38,16 @@ fl_uint8_4_type = pyarrow.field("_",
|
||||||
("L", pyarrow.uint8(), None),
|
("L", pyarrow.uint8(), None),
|
||||||
("I", pyarrow.int32(), None),
|
("I", pyarrow.int32(), None),
|
||||||
("F", pyarrow.float32(), None),
|
("F", pyarrow.float32(), None),
|
||||||
("LA", fl_uint8_4_type, [0,3]),
|
("LA", fl_uint8_4_type, [0, 3]),
|
||||||
("RGB", fl_uint8_4_type, [0,1,2]),
|
("RGB", fl_uint8_4_type, [0, 1, 2]),
|
||||||
("RGBA", fl_uint8_4_type, None),
|
("RGBA", fl_uint8_4_type, None),
|
||||||
("RGBX", fl_uint8_4_type, None),
|
("RGBX", fl_uint8_4_type, None),
|
||||||
("CMYK", fl_uint8_4_type, None),
|
("CMYK", fl_uint8_4_type, None),
|
||||||
("YCbCr", fl_uint8_4_type, [0,1,2]),
|
("YCbCr", fl_uint8_4_type, [0, 1, 2]),
|
||||||
("HSV", fl_uint8_4_type, [0,1,2]),
|
("HSV", fl_uint8_4_type, [0, 1, 2]),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_to_array(mode: str, dtype: Any, mask: Any ) -> None:
|
def test_to_array(mode: str, dtype: Any, mask: Any) -> None:
|
||||||
img = hopper(mode)
|
img = hopper(mode)
|
||||||
|
|
||||||
# Resize to non-square
|
# Resize to non-square
|
||||||
|
@ -69,35 +63,35 @@ def test_lifetime():
|
||||||
# valgrind shouldn't error out here.
|
# valgrind shouldn't error out here.
|
||||||
# arrays should be accessible after the image is deleted.
|
# arrays should be accessible after the image is deleted.
|
||||||
|
|
||||||
img = hopper('L')
|
img = hopper("L")
|
||||||
|
|
||||||
arr_1 = pyarrow.array(img)
|
arr_1 = pyarrow.array(img)
|
||||||
arr_2 = pyarrow.array(img)
|
arr_2 = pyarrow.array(img)
|
||||||
|
|
||||||
del(img)
|
del img
|
||||||
|
|
||||||
assert arr_1.sum().as_py() > 0
|
assert arr_1.sum().as_py() > 0
|
||||||
del(arr_1)
|
del arr_1
|
||||||
|
|
||||||
assert arr_2.sum().as_py() > 0
|
assert arr_2.sum().as_py() > 0
|
||||||
del(arr_2)
|
del arr_2
|
||||||
|
|
||||||
|
|
||||||
def test_lifetime2():
|
def test_lifetime2():
|
||||||
# valgrind shouldn't error out here.
|
# valgrind shouldn't error out here.
|
||||||
# img should remain after the arrays are collected.
|
# img should remain after the arrays are collected.
|
||||||
|
|
||||||
img = hopper('L')
|
img = hopper("L")
|
||||||
|
|
||||||
arr_1 = pyarrow.array(img)
|
arr_1 = pyarrow.array(img)
|
||||||
arr_2 = pyarrow.array(img)
|
arr_2 = pyarrow.array(img)
|
||||||
|
|
||||||
|
|
||||||
assert arr_1.sum().as_py() > 0
|
assert arr_1.sum().as_py() > 0
|
||||||
del(arr_1)
|
del arr_1
|
||||||
|
|
||||||
assert arr_2.sum().as_py() > 0
|
assert arr_2.sum().as_py() > 0
|
||||||
del(arr_2)
|
del arr_2
|
||||||
|
|
||||||
img2 = img.copy()
|
img2 = img.copy()
|
||||||
px = img2.load()
|
px = img2.load()
|
||||||
assert isinstance(px[0,0], int)
|
assert isinstance(px[0, 0], int)
|
||||||
|
|
|
@ -61,11 +61,11 @@ optional-dependencies.tests = [
|
||||||
"markdown2",
|
"markdown2",
|
||||||
"olefile",
|
"olefile",
|
||||||
"packaging",
|
"packaging",
|
||||||
|
"pyarrow",
|
||||||
"pyroma",
|
"pyroma",
|
||||||
"pytest",
|
"pytest",
|
||||||
"pytest-cov",
|
"pytest-cov",
|
||||||
"pytest-timeout",
|
"pytest-timeout",
|
||||||
"pyarrow",
|
|
||||||
]
|
]
|
||||||
optional-dependencies.typing = [
|
optional-dependencies.typing = [
|
||||||
"typing-extensions; python_version<'3.10'",
|
"typing-extensions; python_version<'3.10'",
|
||||||
|
|
|
@ -744,12 +744,13 @@ class Image:
|
||||||
new["shape"], new["typestr"] = _conv_type_shape(self)
|
new["shape"], new["typestr"] = _conv_type_shape(self)
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
||||||
def __arrow_c_schema__(self) -> object:
|
def __arrow_c_schema__(self) -> object:
|
||||||
self.load()
|
self.load()
|
||||||
return self.im.__arrow_c_schema__()
|
return self.im.__arrow_c_schema__()
|
||||||
|
|
||||||
def __arrow_c_array__(self, requested_schema: object | None = None) -> Tuple[object, object]:
|
def __arrow_c_array__(
|
||||||
|
self, requested_schema: object | None = None
|
||||||
|
) -> Tuple[object, object]:
|
||||||
self.load()
|
self.load()
|
||||||
return (self.im.__arrow_c_schema__(), self.im.__arrow_c_array__())
|
return (self.im.__arrow_c_schema__(), self.im.__arrow_c_array__())
|
||||||
|
|
||||||
|
|
|
@ -228,39 +228,42 @@ PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view) {
|
||||||
/* Arrow HANDLING */
|
/* Arrow HANDLING */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
void ReleaseArrowSchemaPyCapsule(PyObject* capsule) {
|
void
|
||||||
struct ArrowSchema* schema =
|
ReleaseArrowSchemaPyCapsule(PyObject *capsule) {
|
||||||
(struct ArrowSchema*)PyCapsule_GetPointer(capsule, "arrow_schema");
|
struct ArrowSchema *schema =
|
||||||
|
(struct ArrowSchema *)PyCapsule_GetPointer(capsule, "arrow_schema");
|
||||||
if (schema->release != NULL) {
|
if (schema->release != NULL) {
|
||||||
schema->release(schema);
|
schema->release(schema);
|
||||||
}
|
}
|
||||||
free(schema);
|
free(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* ExportArrowSchemaPyCapsule(ImagingObject *self) {
|
PyObject *
|
||||||
struct ArrowSchema* schema =
|
ExportArrowSchemaPyCapsule(ImagingObject *self) {
|
||||||
(struct ArrowSchema*)calloc(1, sizeof(struct ArrowSchema));
|
struct ArrowSchema *schema =
|
||||||
|
(struct ArrowSchema *)calloc(1, sizeof(struct ArrowSchema));
|
||||||
export_imaging_schema(self->image, schema);
|
export_imaging_schema(self->image, schema);
|
||||||
return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule);
|
return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReleaseArrowArrayPyCapsule(PyObject* capsule) {
|
void
|
||||||
struct ArrowArray* array =
|
ReleaseArrowArrayPyCapsule(PyObject *capsule) {
|
||||||
(struct ArrowArray*)PyCapsule_GetPointer(capsule, "arrow_array");
|
struct ArrowArray *array =
|
||||||
|
(struct ArrowArray *)PyCapsule_GetPointer(capsule, "arrow_array");
|
||||||
if (array->release != NULL) {
|
if (array->release != NULL) {
|
||||||
array->release(array);
|
array->release(array);
|
||||||
}
|
}
|
||||||
free(array);
|
free(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* ExportArrowArrayPyCapsule(ImagingObject *self) {
|
PyObject *
|
||||||
struct ArrowArray* array =
|
ExportArrowArrayPyCapsule(ImagingObject *self) {
|
||||||
(struct ArrowArray*)calloc(1, sizeof(struct ArrowArray));
|
struct ArrowArray *array =
|
||||||
|
(struct ArrowArray *)calloc(1, sizeof(struct ArrowArray));
|
||||||
export_imaging_array(self->image, array);
|
export_imaging_array(self->image, array);
|
||||||
return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule);
|
return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* EXCEPTION REROUTING */
|
/* EXCEPTION REROUTING */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
|
@ -9,292 +9,285 @@
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ReleaseExportedSchema(struct ArrowSchema* array) {
|
ReleaseExportedSchema(struct ArrowSchema *array) {
|
||||||
// This should not be called on already released array
|
// This should not be called on already released array
|
||||||
//assert(array->release != NULL);
|
// assert(array->release != NULL);
|
||||||
|
|
||||||
if (!array->release) {
|
if (!array->release) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (array->format) {
|
if (array->format) {
|
||||||
free((void*)array->format);
|
free((void *)array->format);
|
||||||
array->format = NULL;
|
array->format = NULL;
|
||||||
}
|
}
|
||||||
if (array->name) {
|
if (array->name) {
|
||||||
free((void*)array->name);
|
free((void *)array->name);
|
||||||
array->name = NULL;
|
array->name = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
// Release children
|
|
||||||
for (int64_t i = 0; i < array->n_children; ++i) {
|
|
||||||
struct ArrowSchema* child = array->children[i];
|
|
||||||
if (child->release != NULL) {
|
|
||||||
child->release(child);
|
|
||||||
//assert(child->release == NULL);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Release dictionary
|
// Release children
|
||||||
struct ArrowSchema* dict = array->dictionary;
|
for (int64_t i = 0; i < array->n_children; ++i) {
|
||||||
if (dict != NULL && dict->release != NULL) {
|
struct ArrowSchema *child = array->children[i];
|
||||||
dict->release(dict);
|
if (child->release != NULL) {
|
||||||
//assert(dict->release == NULL);
|
child->release(child);
|
||||||
}
|
// assert(child->release == NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO here: release and/or deallocate all data directly owned by
|
// Release dictionary
|
||||||
// the ArrowArray struct, such as the private_data.
|
struct ArrowSchema *dict = array->dictionary;
|
||||||
|
if (dict != NULL && dict->release != NULL) {
|
||||||
|
dict->release(dict);
|
||||||
|
// assert(dict->release == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// Mark array released
|
// TODO here: release and/or deallocate all data directly owned by
|
||||||
array->release = NULL;
|
// the ArrowArray struct, such as the private_data.
|
||||||
|
|
||||||
|
// Mark array released
|
||||||
|
array->release = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
export_named_type(struct ArrowSchema *schema, char *format, char *name) {
|
||||||
|
char *formatp;
|
||||||
|
char *namep;
|
||||||
|
size_t format_len = strlen(format) + 1;
|
||||||
|
size_t name_len = strlen(name) + 1;
|
||||||
|
|
||||||
|
formatp = calloc(format_len, 1);
|
||||||
|
|
||||||
int export_named_type(struct ArrowSchema* schema,
|
if (!formatp) {
|
||||||
char* format,
|
return 1;
|
||||||
char* name) {
|
}
|
||||||
|
|
||||||
char* formatp;
|
namep = calloc(name_len, 1);
|
||||||
char* namep;
|
if (!namep) {
|
||||||
size_t format_len = strlen(format) + 1;
|
free(formatp);
|
||||||
size_t name_len = strlen(name) + 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
formatp = calloc(format_len, 1);
|
strncpy(formatp, format, format_len);
|
||||||
|
strncpy(namep, name, name_len);
|
||||||
|
|
||||||
if (!formatp) {
|
*schema = (struct ArrowSchema){// Type description
|
||||||
return 1;
|
.format = formatp,
|
||||||
}
|
.name = namep,
|
||||||
|
.metadata = NULL,
|
||||||
namep = calloc(name_len, 1);
|
.flags = 0,
|
||||||
if (!namep){
|
.n_children = 0,
|
||||||
free(formatp);
|
.children = NULL,
|
||||||
return 1;
|
.dictionary = NULL,
|
||||||
}
|
// Bookkeeping
|
||||||
|
.release = &ReleaseExportedSchema
|
||||||
strncpy(formatp, format, format_len);
|
};
|
||||||
strncpy(namep, name, name_len);
|
return 0;
|
||||||
|
|
||||||
*schema = (struct ArrowSchema) {
|
|
||||||
// Type description
|
|
||||||
.format = formatp,
|
|
||||||
.name = namep,
|
|
||||||
.metadata = NULL,
|
|
||||||
.flags = 0,
|
|
||||||
.n_children = 0,
|
|
||||||
.children = NULL,
|
|
||||||
.dictionary = NULL,
|
|
||||||
// Bookkeeping
|
|
||||||
.release = &ReleaseExportedSchema
|
|
||||||
};
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int export_imaging_schema(Imaging im, struct ArrowSchema* schema) {
|
int
|
||||||
int retval = 0;
|
export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
|
||||||
|
int retval = 0;
|
||||||
|
|
||||||
if (strcmp(im->arrow_band_format, "") == 0) {
|
if (strcmp(im->arrow_band_format, "") == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (im->bands == 1) {
|
if (im->bands == 1) {
|
||||||
return export_named_type(schema, im->arrow_band_format, im->band_names[0]);
|
return export_named_type(schema, im->arrow_band_format, im->band_names[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = export_named_type(schema, "+w:4", "");
|
retval = export_named_type(schema, "+w:4", "");
|
||||||
if (retval) {
|
if (retval) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
// if it's not 1 band, it's an int32 at the moment. 4 unint8 bands.
|
// if it's not 1 band, it's an int32 at the moment. 4 unint8 bands.
|
||||||
schema->n_children = 1;
|
schema->n_children = 1;
|
||||||
schema->children = calloc(1, sizeof(struct ArrowSchema*));
|
schema->children = calloc(1, sizeof(struct ArrowSchema *));
|
||||||
schema->children[0] = (struct ArrowSchema*)calloc(1, sizeof(struct ArrowSchema));
|
schema->children[0] = (struct ArrowSchema *)calloc(1, sizeof(struct ArrowSchema));
|
||||||
if (export_named_type(schema->children[0], im->arrow_band_format, "pixel")) {
|
if (export_named_type(schema->children[0], im->arrow_band_format, "pixel")) {
|
||||||
free(schema->children[0]);
|
free(schema->children[0]);
|
||||||
schema->release(schema);
|
schema->release(schema);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_simple_type(struct ArrowSchema* schema) {
|
static void
|
||||||
// Mark released
|
release_simple_type(struct ArrowSchema *schema) {
|
||||||
schema->release = NULL;
|
// Mark released
|
||||||
|
schema->release = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void export_uint32_type(struct ArrowSchema* schema) {
|
void
|
||||||
*schema = (struct ArrowSchema) {
|
export_uint32_type(struct ArrowSchema *schema) {
|
||||||
// Type description
|
*schema = (struct ArrowSchema){// Type description
|
||||||
.format = "I",
|
.format = "I",
|
||||||
.name = "",
|
.name = "",
|
||||||
.metadata = NULL,
|
.metadata = NULL,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.n_children = 0,
|
.n_children = 0,
|
||||||
.children = NULL,
|
.children = NULL,
|
||||||
.dictionary = NULL,
|
.dictionary = NULL,
|
||||||
// Bookkeeping
|
// Bookkeeping
|
||||||
.release = &release_simple_type
|
.release = &release_simple_type
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
static void release_uint32_array(struct ArrowArray* array) {
|
release_uint32_array(struct ArrowArray *array) {
|
||||||
//assert(array->n_buffers == 2);
|
// assert(array->n_buffers == 2);
|
||||||
// Free the buffers and the buffers array
|
// Free the buffers and the buffers array
|
||||||
free((void *) array->buffers[1]);
|
free((void *)array->buffers[1]);
|
||||||
free(array->buffers);
|
free(array->buffers);
|
||||||
// Mark released
|
// Mark released
|
||||||
array->release = NULL;
|
array->release = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void export_uint32_array(const uint32_t* data, int64_t nitems,
|
void
|
||||||
struct ArrowArray* array) {
|
export_uint32_array(const uint32_t *data, int64_t nitems, struct ArrowArray *array) {
|
||||||
// Initialize primitive fields
|
// Initialize primitive fields
|
||||||
*array = (struct ArrowArray) {
|
*array = (struct ArrowArray){// Data description
|
||||||
// Data description
|
.length = nitems,
|
||||||
.length = nitems,
|
.offset = 0,
|
||||||
.offset = 0,
|
.null_count = 0,
|
||||||
.null_count = 0,
|
.n_buffers = 2,
|
||||||
.n_buffers = 2,
|
.n_children = 0,
|
||||||
.n_children = 0,
|
.children = NULL,
|
||||||
.children = NULL,
|
.dictionary = NULL,
|
||||||
.dictionary = NULL,
|
// Bookkeeping
|
||||||
// Bookkeeping
|
.release = &release_uint32_array
|
||||||
.release = &release_uint32_array
|
};
|
||||||
};
|
// Allocate list of buffers
|
||||||
// Allocate list of buffers
|
array->buffers = (const void **)malloc(sizeof(void *) * array->n_buffers);
|
||||||
array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
|
// assert(array->buffers != NULL);
|
||||||
//assert(array->buffers != NULL);
|
array->buffers[0] = NULL; // no nulls, null bitmap can be omitted
|
||||||
array->buffers[0] = NULL; // no nulls, null bitmap can be omitted
|
array->buffers[1] = data;
|
||||||
array->buffers[1] = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_const_array(struct ArrowArray* array) {
|
static void
|
||||||
Imaging im = (Imaging)array->private_data;
|
release_const_array(struct ArrowArray *array) {
|
||||||
|
Imaging im = (Imaging)array->private_data;
|
||||||
|
|
||||||
ImagingDelete(im);
|
ImagingDelete(im);
|
||||||
|
|
||||||
//assert(array->n_buffers == 2);
|
// assert(array->n_buffers == 2);
|
||||||
// Free the buffers and the buffers array
|
// Free the buffers and the buffers array
|
||||||
free(array->buffers);
|
free(array->buffers);
|
||||||
// Mark released
|
// Mark released
|
||||||
array->release = NULL;
|
array->release = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
export_single_channel_array(Imaging im, struct ArrowArray *array) {
|
||||||
|
int length = im->xsize * im->ysize;
|
||||||
|
|
||||||
int export_single_channel_array(Imaging im, struct ArrowArray* array){
|
/* undone -- for now, single block images */
|
||||||
int length = im->xsize * im->ysize;
|
// assert (im->block_count = 0 || im->block_count = 1);
|
||||||
|
|
||||||
/* undone -- for now, single block images */
|
if (im->lines_per_block && im->lines_per_block < im->ysize) {
|
||||||
//assert (im->block_count = 0 || im->block_count = 1);
|
length = im->xsize * im->lines_per_block;
|
||||||
|
}
|
||||||
|
|
||||||
if (im->lines_per_block && im->lines_per_block < im->ysize) {
|
im->arrow_borrow++;
|
||||||
length = im->xsize * im->lines_per_block;
|
// Initialize primitive fields
|
||||||
}
|
*array = (struct ArrowArray){// Data description
|
||||||
|
.length = length,
|
||||||
|
.offset = 0,
|
||||||
|
.null_count = 0,
|
||||||
|
.n_buffers = 2,
|
||||||
|
.n_children = 0,
|
||||||
|
.children = NULL,
|
||||||
|
.dictionary = NULL,
|
||||||
|
// Bookkeeping
|
||||||
|
.release = &release_const_array,
|
||||||
|
.private_data = im
|
||||||
|
};
|
||||||
|
|
||||||
im->arrow_borrow++;
|
// Allocate list of buffers
|
||||||
// Initialize primitive fields
|
array->buffers = (const void **)malloc(sizeof(void *) * array->n_buffers);
|
||||||
*array = (struct ArrowArray) {
|
// assert(array->buffers != NULL);
|
||||||
// Data description
|
array->buffers[0] = NULL; // no nulls, null bitmap can be omitted
|
||||||
.length = length,
|
|
||||||
.offset = 0,
|
|
||||||
.null_count = 0,
|
|
||||||
.n_buffers = 2,
|
|
||||||
.n_children = 0,
|
|
||||||
.children = NULL,
|
|
||||||
.dictionary = NULL,
|
|
||||||
// Bookkeeping
|
|
||||||
.release = &release_const_array,
|
|
||||||
.private_data = im
|
|
||||||
};
|
|
||||||
|
|
||||||
// Allocate list of buffers
|
if (im->block) {
|
||||||
array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
|
array->buffers[1] = im->block;
|
||||||
//assert(array->buffers != NULL);
|
} else {
|
||||||
array->buffers[0] = NULL; // no nulls, null bitmap can be omitted
|
array->buffers[1] = im->blocks[0].ptr;
|
||||||
|
}
|
||||||
if (im->block) {
|
return 0;
|
||||||
array->buffers[1] = im->block;
|
|
||||||
} else {
|
|
||||||
array->buffers[1] = im->blocks[0].ptr;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
export_fixed_pixel_array(Imaging im, struct ArrowArray *array) {
|
||||||
|
int length = im->xsize * im->ysize;
|
||||||
|
|
||||||
int export_fixed_pixel_array(Imaging im, struct ArrowArray* array) {
|
/* undone -- for now, single block images */
|
||||||
|
// assert (im->block_count = 0 || im->block_count = 1);
|
||||||
|
|
||||||
int length = im->xsize * im->ysize;
|
if (im->lines_per_block && im->lines_per_block < im->ysize) {
|
||||||
|
length = im->xsize * im->lines_per_block;
|
||||||
|
}
|
||||||
|
|
||||||
/* undone -- for now, single block images */
|
im->arrow_borrow++;
|
||||||
//assert (im->block_count = 0 || im->block_count = 1);
|
// Initialize primitive fields
|
||||||
|
// Fixed length arrays are 1 buffer of validity, and the length in pixels.
|
||||||
|
// Data is in a child array.
|
||||||
|
*array = (struct ArrowArray){// Data description
|
||||||
|
.length = length,
|
||||||
|
.offset = 0,
|
||||||
|
.null_count = 0,
|
||||||
|
.n_buffers = 1,
|
||||||
|
.n_children = 1,
|
||||||
|
.children = NULL,
|
||||||
|
.dictionary = NULL,
|
||||||
|
// Bookkeeping
|
||||||
|
.release = &release_const_array,
|
||||||
|
.private_data = im
|
||||||
|
};
|
||||||
|
|
||||||
if (im->lines_per_block && im->lines_per_block < im->ysize) {
|
// Allocate list of buffers
|
||||||
length = im->xsize * im->lines_per_block;
|
array->buffers = (const void **)calloc(1, sizeof(void *) * array->n_buffers);
|
||||||
}
|
// assert(array->buffers != NULL);
|
||||||
|
array->buffers[0] = NULL; // no nulls, null bitmap can be omitted
|
||||||
|
|
||||||
im->arrow_borrow++;
|
// if it's not 1 band, it's an int32 at the moment. 4 unint8 bands.
|
||||||
// Initialize primitive fields
|
array->n_children = 1;
|
||||||
// Fixed length arrays are 1 buffer of validity, and the length in pixels.
|
array->children = calloc(1, sizeof(struct ArrowArray *));
|
||||||
// Data is in a child array.
|
array->children[0] = (struct ArrowArray *)calloc(1, sizeof(struct ArrowArray));
|
||||||
*array = (struct ArrowArray) {
|
|
||||||
// Data description
|
|
||||||
.length = length,
|
|
||||||
.offset = 0,
|
|
||||||
.null_count = 0,
|
|
||||||
.n_buffers = 1,
|
|
||||||
.n_children = 1,
|
|
||||||
.children = NULL,
|
|
||||||
.dictionary = NULL,
|
|
||||||
// Bookkeeping
|
|
||||||
.release = &release_const_array,
|
|
||||||
.private_data = im
|
|
||||||
};
|
|
||||||
|
|
||||||
// Allocate list of buffers
|
im->arrow_borrow++;
|
||||||
array->buffers = (const void**) calloc(1, sizeof(void*) * array->n_buffers);
|
*array->children[0] = (struct ArrowArray){// Data description
|
||||||
//assert(array->buffers != NULL);
|
.length = length * 4,
|
||||||
array->buffers[0] = NULL; // no nulls, null bitmap can be omitted
|
.offset = 0,
|
||||||
|
.null_count = 0,
|
||||||
|
.n_buffers = 2,
|
||||||
|
.n_children = 0,
|
||||||
|
.children = NULL,
|
||||||
|
.dictionary = NULL,
|
||||||
|
// Bookkeeping
|
||||||
|
.release = &release_const_array,
|
||||||
|
.private_data = im
|
||||||
|
};
|
||||||
|
|
||||||
|
array->children[0]->buffers =
|
||||||
|
(const void **)calloc(2, sizeof(void *) * array->n_buffers);
|
||||||
|
|
||||||
// if it's not 1 band, it's an int32 at the moment. 4 unint8 bands.
|
if (im->block) {
|
||||||
array->n_children = 1;
|
array->children[0]->buffers[1] = im->block;
|
||||||
array->children = calloc(1, sizeof(struct ArrowArray*));
|
} else {
|
||||||
array->children[0] = (struct ArrowArray*)calloc(1, sizeof(struct ArrowArray));
|
array->children[0]->buffers[1] = im->blocks[0].ptr;
|
||||||
|
}
|
||||||
im->arrow_borrow++;
|
return 0;
|
||||||
*array->children[0] = (struct ArrowArray) {
|
|
||||||
// Data description
|
|
||||||
.length = length * 4,
|
|
||||||
.offset = 0,
|
|
||||||
.null_count = 0,
|
|
||||||
.n_buffers = 2,
|
|
||||||
.n_children = 0,
|
|
||||||
.children = NULL,
|
|
||||||
.dictionary = NULL,
|
|
||||||
// Bookkeeping
|
|
||||||
.release = &release_const_array,
|
|
||||||
.private_data = im
|
|
||||||
};
|
|
||||||
|
|
||||||
array->children[0]->buffers = (const void**) calloc(2, sizeof(void*) * array->n_buffers);
|
|
||||||
|
|
||||||
if (im->block) {
|
|
||||||
array->children[0]->buffers[1] = im->block;
|
|
||||||
} else {
|
|
||||||
array->children[0]->buffers[1] = im->blocks[0].ptr;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
export_imaging_array(Imaging im, struct ArrowArray *array) {
|
||||||
|
if (strcmp(im->arrow_band_format, "") == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int export_imaging_array(Imaging im, struct ArrowArray* array) {
|
if (im->bands == 1) {
|
||||||
if (strcmp(im->arrow_band_format, "") == 0) {
|
return export_single_channel_array(im, array);
|
||||||
return 1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (im->bands == 1) {
|
return export_fixed_pixel_array(im, array);
|
||||||
return export_single_channel_array(im, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
return export_fixed_pixel_array(im, array);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,36 +13,36 @@
|
||||||
#define ARROW_FLAG_MAP_KEYS_SORTED 4
|
#define ARROW_FLAG_MAP_KEYS_SORTED 4
|
||||||
|
|
||||||
struct ArrowSchema {
|
struct ArrowSchema {
|
||||||
// Array type description
|
// Array type description
|
||||||
const char* format;
|
const char *format;
|
||||||
const char* name;
|
const char *name;
|
||||||
const char* metadata;
|
const char *metadata;
|
||||||
int64_t flags;
|
int64_t flags;
|
||||||
int64_t n_children;
|
int64_t n_children;
|
||||||
struct ArrowSchema** children;
|
struct ArrowSchema **children;
|
||||||
struct ArrowSchema* dictionary;
|
struct ArrowSchema *dictionary;
|
||||||
|
|
||||||
// Release callback
|
// Release callback
|
||||||
void (*release)(struct ArrowSchema*);
|
void (*release)(struct ArrowSchema *);
|
||||||
// Opaque producer-specific data
|
// Opaque producer-specific data
|
||||||
void* private_data;
|
void *private_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ArrowArray {
|
struct ArrowArray {
|
||||||
// Array data description
|
// Array data description
|
||||||
int64_t length;
|
int64_t length;
|
||||||
int64_t null_count;
|
int64_t null_count;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
int64_t n_buffers;
|
int64_t n_buffers;
|
||||||
int64_t n_children;
|
int64_t n_children;
|
||||||
const void** buffers;
|
const void **buffers;
|
||||||
struct ArrowArray** children;
|
struct ArrowArray **children;
|
||||||
struct ArrowArray* dictionary;
|
struct ArrowArray *dictionary;
|
||||||
|
|
||||||
// Release callback
|
// Release callback
|
||||||
void (*release)(struct ArrowArray*);
|
void (*release)(struct ArrowArray *);
|
||||||
// Opaque producer-specific data
|
// Opaque producer-specific data
|
||||||
void* private_data;
|
void *private_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ARROW_C_DATA_INTERFACE
|
#endif // ARROW_C_DATA_INTERFACE
|
||||||
|
|
|
@ -106,11 +106,11 @@ struct ImagingMemoryInstance {
|
||||||
void (*destroy)(Imaging im);
|
void (*destroy)(Imaging im);
|
||||||
|
|
||||||
/* arrow */
|
/* arrow */
|
||||||
int arrow_borrow; /* Number of arrow arrays that have been allocated */
|
int arrow_borrow; /* Number of arrow arrays that have been allocated */
|
||||||
int blocks_count; /* Number of blocks that have been allocated */
|
int blocks_count; /* Number of blocks that have been allocated */
|
||||||
int lines_per_block; /* Number of lines in a block have been allocated */
|
int lines_per_block; /* Number of lines in a block have been allocated */
|
||||||
|
|
||||||
char band_names[4][3]; /* names of bands, max 2 char + null terminator */
|
char band_names[4][3]; /* names of bands, max 2 char + null terminator */
|
||||||
char arrow_band_format[2]; /* single character + null terminator */
|
char arrow_band_format[2]; /* single character + null terminator */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -713,9 +713,12 @@ _imaging_tell_pyFd(PyObject *fd);
|
||||||
/* Arrow */
|
/* Arrow */
|
||||||
|
|
||||||
#include "Arrow.h"
|
#include "Arrow.h"
|
||||||
extern int export_imaging_array(Imaging im, struct ArrowArray* array);
|
extern int
|
||||||
extern int export_imaging_schema(Imaging im, struct ArrowSchema* schema);
|
export_imaging_array(Imaging im, struct ArrowArray *array);
|
||||||
extern void export_uint32_type(struct ArrowSchema* schema);
|
extern int
|
||||||
|
export_imaging_schema(Imaging im, struct ArrowSchema *schema);
|
||||||
|
extern void
|
||||||
|
export_uint32_type(struct ArrowSchema *schema);
|
||||||
|
|
||||||
/* Errcodes */
|
/* Errcodes */
|
||||||
#define IMAGING_CODEC_END 1
|
#define IMAGING_CODEC_END 1
|
||||||
|
|
|
@ -66,14 +66,14 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
/* 1-bit images */
|
/* 1-bit images */
|
||||||
im->bands = im->pixelsize = 1;
|
im->bands = im->pixelsize = 1;
|
||||||
im->linesize = xsize;
|
im->linesize = xsize;
|
||||||
strcpy(im->band_names[0],"1");
|
strcpy(im->band_names[0], "1");
|
||||||
|
|
||||||
} else if (strcmp(mode, "P") == 0) {
|
} else if (strcmp(mode, "P") == 0) {
|
||||||
/* 8-bit palette mapped images */
|
/* 8-bit palette mapped images */
|
||||||
im->bands = im->pixelsize = 1;
|
im->bands = im->pixelsize = 1;
|
||||||
im->linesize = xsize;
|
im->linesize = xsize;
|
||||||
im->palette = ImagingPaletteNew("RGB");
|
im->palette = ImagingPaletteNew("RGB");
|
||||||
strcpy(im->band_names[0],"P");
|
strcpy(im->band_names[0], "P");
|
||||||
|
|
||||||
} else if (strcmp(mode, "PA") == 0) {
|
} else if (strcmp(mode, "PA") == 0) {
|
||||||
/* 8-bit palette with alpha */
|
/* 8-bit palette with alpha */
|
||||||
|
@ -81,36 +81,36 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->pixelsize = 4; /* store in image32 memory */
|
im->pixelsize = 4; /* store in image32 memory */
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
im->palette = ImagingPaletteNew("RGB");
|
im->palette = ImagingPaletteNew("RGB");
|
||||||
strcpy(im->band_names[0],"P");
|
strcpy(im->band_names[0], "P");
|
||||||
strcpy(im->band_names[1],"X");
|
strcpy(im->band_names[1], "X");
|
||||||
strcpy(im->band_names[2],"X");
|
strcpy(im->band_names[2], "X");
|
||||||
strcpy(im->band_names[3],"A");
|
strcpy(im->band_names[3], "A");
|
||||||
|
|
||||||
} else if (strcmp(mode, "L") == 0) {
|
} else if (strcmp(mode, "L") == 0) {
|
||||||
/* 8-bit grayscale (luminance) images */
|
/* 8-bit grayscale (luminance) images */
|
||||||
im->bands = im->pixelsize = 1;
|
im->bands = im->pixelsize = 1;
|
||||||
im->linesize = xsize;
|
im->linesize = xsize;
|
||||||
strcpy(im->band_names[0],"L");
|
strcpy(im->band_names[0], "L");
|
||||||
|
|
||||||
} else if (strcmp(mode, "LA") == 0) {
|
} else if (strcmp(mode, "LA") == 0) {
|
||||||
/* 8-bit grayscale (luminance) with alpha */
|
/* 8-bit grayscale (luminance) with alpha */
|
||||||
im->bands = 2;
|
im->bands = 2;
|
||||||
im->pixelsize = 4; /* store in image32 memory */
|
im->pixelsize = 4; /* store in image32 memory */
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"L");
|
strcpy(im->band_names[0], "L");
|
||||||
strcpy(im->band_names[1],"X");
|
strcpy(im->band_names[1], "X");
|
||||||
strcpy(im->band_names[2],"X");
|
strcpy(im->band_names[2], "X");
|
||||||
strcpy(im->band_names[3],"A");
|
strcpy(im->band_names[3], "A");
|
||||||
|
|
||||||
} else if (strcmp(mode, "La") == 0) {
|
} else if (strcmp(mode, "La") == 0) {
|
||||||
/* 8-bit grayscale (luminance) with premultiplied alpha */
|
/* 8-bit grayscale (luminance) with premultiplied alpha */
|
||||||
im->bands = 2;
|
im->bands = 2;
|
||||||
im->pixelsize = 4; /* store in image32 memory */
|
im->pixelsize = 4; /* store in image32 memory */
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"L");
|
strcpy(im->band_names[0], "L");
|
||||||
strcpy(im->band_names[1],"X");
|
strcpy(im->band_names[1], "X");
|
||||||
strcpy(im->band_names[2],"X");
|
strcpy(im->band_names[2], "X");
|
||||||
strcpy(im->band_names[3],"a");
|
strcpy(im->band_names[3], "a");
|
||||||
|
|
||||||
} else if (strcmp(mode, "F") == 0) {
|
} else if (strcmp(mode, "F") == 0) {
|
||||||
/* 32-bit floating point images */
|
/* 32-bit floating point images */
|
||||||
|
@ -118,8 +118,8 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->pixelsize = 4;
|
im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
im->type = IMAGING_TYPE_FLOAT32;
|
im->type = IMAGING_TYPE_FLOAT32;
|
||||||
strcpy(im->arrow_band_format , "f");
|
strcpy(im->arrow_band_format, "f");
|
||||||
strcpy(im->band_names[0],"F");
|
strcpy(im->band_names[0], "F");
|
||||||
|
|
||||||
} else if (strcmp(mode, "I") == 0) {
|
} else if (strcmp(mode, "I") == 0) {
|
||||||
/* 32-bit integer images */
|
/* 32-bit integer images */
|
||||||
|
@ -127,8 +127,8 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->pixelsize = 4;
|
im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
im->type = IMAGING_TYPE_INT32;
|
im->type = IMAGING_TYPE_INT32;
|
||||||
strcpy(im->arrow_band_format , "i");
|
strcpy(im->arrow_band_format, "i");
|
||||||
strcpy(im->band_names[0],"I");
|
strcpy(im->band_names[0], "I");
|
||||||
|
|
||||||
} else if (strcmp(mode, "I;16") == 0 || strcmp(mode, "I;16L") == 0 ||
|
} else if (strcmp(mode, "I;16") == 0 || strcmp(mode, "I;16L") == 0 ||
|
||||||
strcmp(mode, "I;16B") == 0 || strcmp(mode, "I;16N") == 0) {
|
strcmp(mode, "I;16B") == 0 || strcmp(mode, "I;16N") == 0) {
|
||||||
|
@ -138,18 +138,18 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->pixelsize = 2;
|
im->pixelsize = 2;
|
||||||
im->linesize = xsize * 2;
|
im->linesize = xsize * 2;
|
||||||
im->type = IMAGING_TYPE_SPECIAL;
|
im->type = IMAGING_TYPE_SPECIAL;
|
||||||
strcpy(im->arrow_band_format , "s");
|
strcpy(im->arrow_band_format, "s");
|
||||||
strcpy(im->band_names[0],"I");
|
strcpy(im->band_names[0], "I");
|
||||||
|
|
||||||
} else if (strcmp(mode, "RGB") == 0) {
|
} else if (strcmp(mode, "RGB") == 0) {
|
||||||
/* 24-bit true colour images */
|
/* 24-bit true colour images */
|
||||||
im->bands = 3;
|
im->bands = 3;
|
||||||
im->pixelsize = 4;
|
im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"R");
|
strcpy(im->band_names[0], "R");
|
||||||
strcpy(im->band_names[1],"G");
|
strcpy(im->band_names[1], "G");
|
||||||
strcpy(im->band_names[2],"B");
|
strcpy(im->band_names[2], "B");
|
||||||
strcpy(im->band_names[3],"X");
|
strcpy(im->band_names[3], "X");
|
||||||
|
|
||||||
} else if (strcmp(mode, "BGR;15") == 0) {
|
} else if (strcmp(mode, "BGR;15") == 0) {
|
||||||
/* EXPERIMENTAL */
|
/* EXPERIMENTAL */
|
||||||
|
@ -159,7 +159,7 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->linesize = (xsize * 2 + 3) & -4;
|
im->linesize = (xsize * 2 + 3) & -4;
|
||||||
im->type = IMAGING_TYPE_SPECIAL;
|
im->type = IMAGING_TYPE_SPECIAL;
|
||||||
/* not allowing arrow due to line length packing */
|
/* not allowing arrow due to line length packing */
|
||||||
strcpy(im->arrow_band_format , "");
|
strcpy(im->arrow_band_format, "");
|
||||||
|
|
||||||
} else if (strcmp(mode, "BGR;16") == 0) {
|
} else if (strcmp(mode, "BGR;16") == 0) {
|
||||||
/* EXPERIMENTAL */
|
/* EXPERIMENTAL */
|
||||||
|
@ -169,7 +169,7 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->linesize = (xsize * 2 + 3) & -4;
|
im->linesize = (xsize * 2 + 3) & -4;
|
||||||
im->type = IMAGING_TYPE_SPECIAL;
|
im->type = IMAGING_TYPE_SPECIAL;
|
||||||
/* not allowing arrow due to line length packing */
|
/* not allowing arrow due to line length packing */
|
||||||
strcpy(im->arrow_band_format , "");
|
strcpy(im->arrow_band_format, "");
|
||||||
|
|
||||||
} else if (strcmp(mode, "BGR;24") == 0) {
|
} else if (strcmp(mode, "BGR;24") == 0) {
|
||||||
/* EXPERIMENTAL */
|
/* EXPERIMENTAL */
|
||||||
|
@ -179,53 +179,53 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->linesize = (xsize * 3 + 3) & -4;
|
im->linesize = (xsize * 3 + 3) & -4;
|
||||||
im->type = IMAGING_TYPE_SPECIAL;
|
im->type = IMAGING_TYPE_SPECIAL;
|
||||||
/* not allowing arrow due to line length packing */
|
/* not allowing arrow due to line length packing */
|
||||||
strcpy(im->arrow_band_format , "");
|
strcpy(im->arrow_band_format, "");
|
||||||
|
|
||||||
} else if (strcmp(mode, "RGBX") == 0) {
|
} else if (strcmp(mode, "RGBX") == 0) {
|
||||||
/* 32-bit true colour images with padding */
|
/* 32-bit true colour images with padding */
|
||||||
im->bands = im->pixelsize = 4;
|
im->bands = im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"R");
|
strcpy(im->band_names[0], "R");
|
||||||
strcpy(im->band_names[1],"G");
|
strcpy(im->band_names[1], "G");
|
||||||
strcpy(im->band_names[2],"B");
|
strcpy(im->band_names[2], "B");
|
||||||
strcpy(im->band_names[3],"X");
|
strcpy(im->band_names[3], "X");
|
||||||
|
|
||||||
} else if (strcmp(mode, "RGBA") == 0) {
|
} else if (strcmp(mode, "RGBA") == 0) {
|
||||||
/* 32-bit true colour images with alpha */
|
/* 32-bit true colour images with alpha */
|
||||||
im->bands = im->pixelsize = 4;
|
im->bands = im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"R");
|
strcpy(im->band_names[0], "R");
|
||||||
strcpy(im->band_names[1],"G");
|
strcpy(im->band_names[1], "G");
|
||||||
strcpy(im->band_names[2],"B");
|
strcpy(im->band_names[2], "B");
|
||||||
strcpy(im->band_names[3],"A");
|
strcpy(im->band_names[3], "A");
|
||||||
|
|
||||||
} else if (strcmp(mode, "RGBa") == 0) {
|
} else if (strcmp(mode, "RGBa") == 0) {
|
||||||
/* 32-bit true colour images with premultiplied alpha */
|
/* 32-bit true colour images with premultiplied alpha */
|
||||||
im->bands = im->pixelsize = 4;
|
im->bands = im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"R");
|
strcpy(im->band_names[0], "R");
|
||||||
strcpy(im->band_names[1],"G");
|
strcpy(im->band_names[1], "G");
|
||||||
strcpy(im->band_names[2],"B");
|
strcpy(im->band_names[2], "B");
|
||||||
strcpy(im->band_names[3],"a");
|
strcpy(im->band_names[3], "a");
|
||||||
|
|
||||||
} else if (strcmp(mode, "CMYK") == 0) {
|
} else if (strcmp(mode, "CMYK") == 0) {
|
||||||
/* 32-bit colour separation */
|
/* 32-bit colour separation */
|
||||||
im->bands = im->pixelsize = 4;
|
im->bands = im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"C");
|
strcpy(im->band_names[0], "C");
|
||||||
strcpy(im->band_names[1],"M");
|
strcpy(im->band_names[1], "M");
|
||||||
strcpy(im->band_names[2],"Y");
|
strcpy(im->band_names[2], "Y");
|
||||||
strcpy(im->band_names[3],"K");
|
strcpy(im->band_names[3], "K");
|
||||||
|
|
||||||
} else if (strcmp(mode, "YCbCr") == 0) {
|
} else if (strcmp(mode, "YCbCr") == 0) {
|
||||||
/* 24-bit video format */
|
/* 24-bit video format */
|
||||||
im->bands = 3;
|
im->bands = 3;
|
||||||
im->pixelsize = 4;
|
im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"Y");
|
strcpy(im->band_names[0], "Y");
|
||||||
strcpy(im->band_names[1],"Cb");
|
strcpy(im->band_names[1], "Cb");
|
||||||
strcpy(im->band_names[2],"Cr");
|
strcpy(im->band_names[2], "Cr");
|
||||||
strcpy(im->band_names[3],"X");
|
strcpy(im->band_names[3], "X");
|
||||||
|
|
||||||
} else if (strcmp(mode, "LAB") == 0) {
|
} else if (strcmp(mode, "LAB") == 0) {
|
||||||
/* 24-bit color, luminance, + 2 color channels */
|
/* 24-bit color, luminance, + 2 color channels */
|
||||||
|
@ -233,10 +233,10 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->bands = 3;
|
im->bands = 3;
|
||||||
im->pixelsize = 4;
|
im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"L");
|
strcpy(im->band_names[0], "L");
|
||||||
strcpy(im->band_names[1],"a");
|
strcpy(im->band_names[1], "a");
|
||||||
strcpy(im->band_names[2],"b");
|
strcpy(im->band_names[2], "b");
|
||||||
strcpy(im->band_names[3],"X");
|
strcpy(im->band_names[3], "X");
|
||||||
|
|
||||||
} else if (strcmp(mode, "HSV") == 0) {
|
} else if (strcmp(mode, "HSV") == 0) {
|
||||||
/* 24-bit color, luminance, + 2 color channels */
|
/* 24-bit color, luminance, + 2 color channels */
|
||||||
|
@ -244,10 +244,10 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
|
||||||
im->bands = 3;
|
im->bands = 3;
|
||||||
im->pixelsize = 4;
|
im->pixelsize = 4;
|
||||||
im->linesize = xsize * 4;
|
im->linesize = xsize * 4;
|
||||||
strcpy(im->band_names[0],"H");
|
strcpy(im->band_names[0], "H");
|
||||||
strcpy(im->band_names[1],"S");
|
strcpy(im->band_names[1], "S");
|
||||||
strcpy(im->band_names[2],"V");
|
strcpy(im->band_names[2], "V");
|
||||||
strcpy(im->band_names[3],"X");
|
strcpy(im->band_names[3], "X");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
free(im);
|
free(im);
|
||||||
|
@ -300,8 +300,8 @@ ImagingDelete(Imaging im) {
|
||||||
|
|
||||||
im->arrow_borrow--;
|
im->arrow_borrow--;
|
||||||
|
|
||||||
if (im->arrow_borrow>0) {
|
if (im->arrow_borrow > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (im->palette) {
|
if (im->palette) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user