Skip to content

Commit f45f309

Browse files
authored
Add encoding using a buffer and bug fixes (#89)
1 parent 6a99340 commit f45f309

11 files changed

+4726
-1159
lines changed

README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ Encoding of NumPy ndarrays is supported for the following:
4949
* Number of rows/columns: up to 65535
5050
* Number of planes: 1, 3 or 4
5151

52-
5352
### Transfer Syntaxes
5453
| UID | Description |
5554
| --- | --- |
@@ -95,38 +94,38 @@ Lossless encoding of RGB with multiple-component transformation:
9594
```python
9695

9796
import numpy as np
98-
from openjpeg import encode
97+
from openjpeg import encode_array
9998

100-
arr = np.random.randint(low=0, high=65535, size=(100, 100, 3), dtype="uint8")
101-
encode(arr, photometric_interpretation=1) # 1: sRGB
99+
arr = np.random.randint(low=0, high=65536, size=(100, 100, 3), dtype="uint8")
100+
encode_array(arr, photometric_interpretation=1) # 1: sRGB
102101
```
103102

104103
Lossy encoding of a monochrome image using compression ratios:
105104

106105
```python
107106

108107
import numpy as np
109-
from openjpeg import encode
108+
from openjpeg import encode_array
110109

111-
arr = np.random.randint(low=-2**15, high=2**15 - 1, size=(100, 100), dtype="int8")
110+
arr = np.random.randint(low=-2**15, high=2**15, size=(100, 100), dtype="int8")
112111
# You must determine your own values for `compression_ratios`
113112
# as these are for illustration purposes only
114-
encode(arr, compression_ratios=[2, 4, 6])
113+
encode_array(arr, compression_ratios=[5, 2])
115114
```
116115

117116
Lossy encoding of a monochrome image using peak signal-to-noise ratios:
118117

119118
```python
120119

121120
import numpy as np
122-
from openjpeg import encode
121+
from openjpeg import encode_array
123122

124-
arr = np.random.randint(low=-2**15, high=2**15 - 1, size=(100, 100), dtype="int8")
123+
arr = np.random.randint(low=-2**15, high=2**15, size=(100, 100), dtype="int8")
125124
# You must determine your own values for `signal_noise_ratios`
126125
# as these are for illustration purposes only
127-
encode(arr, signal_noise_ratios=[50, 80, 100])
126+
encode_array(arr, signal_noise_ratios=[50, 80, 100])
128127
```
129128

130-
See the docstring for the [encode() function][2] for full details.
129+
See the docstring for the [encode_array() function][2] for full details.
131130

132-
[2]: https://github.com/pydicom/pylibjpeg-openjpeg/blob/main/openjpeg/utils.py#L428
131+
[2]: https://github.com/pydicom/pylibjpeg-openjpeg/blob/main/openjpeg/utils.py#L429

build.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import os
3-
import sys
43
from pathlib import Path
54
import shutil
65
import subprocess

lib/interface/decode.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ extern int Decode(PyObject* fd, unsigned char *out, int codec_format)
562562
}
563563

564564
// Convert colour space (if required)
565+
// Colour space information is only available with JP2
565566
if (
566567
image->color_space != OPJ_CLRSPC_SYCC
567568
&& image->numcomps == 3
@@ -668,7 +669,7 @@ extern int Decode(PyObject* fd, unsigned char *out, int codec_format)
668669
}
669670
}
670671
} else {
671-
// Support for more than 16-bits per component is not implemented
672+
// Support for more than 32-bits per component is not implemented
672673
return_code = 7;
673674
goto failure;
674675
}

0 commit comments

Comments
 (0)