@@ -52,19 +52,11 @@
Loading
52 52
53 53
  im.quantization
54 54
55 -
This will return a dict with a number of arrays. You can pass this dict
55 +
This will return a dict with a number of lists. You can pass this dict
56 56
directly as the qtables argument when saving a JPEG.
57 57
58 -
The tables format between im.quantization and quantization in presets differ in
59 -
3 ways:
60 -
61 -
1. The base container of the preset is a list with sublists instead of dict.
62 -
   dict[0] -> list[0], dict[1] -> list[1], ...
63 -
2. Each table in a preset is a list instead of an array.
64 -
3. The zigzag order is remove in the preset (needed by libjpeg >= 6a).
65 -
66 -
You can convert the dict format to the preset format with the
67 -
:func:`.JpegImagePlugin.convert_dict_qtables()` function.
58 +
The quantization table format in presets is a list with sublists. These formats
59 +
are interchangeable.
68 60
69 61
Libjpeg ref.:
70 62
https://web.archive.org/web/20120328125543/http://www.jpegcameras.com/libjpeg/libjpeg-3.html

@@ -252,7 +252,7 @@
Loading
252 252
        data = array.array("B" if precision == 1 else "H", s[1:qt_length])
253 253
        if sys.byteorder == "little" and precision > 1:
254 254
            data.byteswap()  # the values are always big-endian
255 -
        self.quantization[v & 15] = data
255 +
        self.quantization[v & 15] = [data[i] for i in zigzag_index]
256 256
        s = s[qt_length:]
257 257
258 258
@@ -585,9 +585,10 @@
Loading
585 585
586 586
587 587
def convert_dict_qtables(qtables):
588 -
    qtables = [qtables[key] for key in range(len(qtables)) if key in qtables]
589 -
    for idx, table in enumerate(qtables):
590 -
        qtables[idx] = [table[i] for i in zigzag_index]
588 +
    warnings.warn(
589 +
        "convert_dict_qtables is deprecated and will be removed in a future"
590 +
        " release. Conversion is no longer needed.",
591 +
        DeprecationWarning)
591 592
    return qtables
592 593
593 594
@@ -668,7 +669,8 @@
Loading
668 669
                qtables = [lines[s : s + 64] for s in range(0, len(lines), 64)]
669 670
        if isinstance(qtables, (tuple, list, dict)):
670 671
            if isinstance(qtables, dict):
671 -
                qtables = convert_dict_qtables(qtables)
672 +
                qtables = [
673 +
                    qtables[key] for key in range(len(qtables)) if key in qtables]
672 674
            elif isinstance(qtables, tuple):
673 675
                qtables = list(qtables)
674 676
            if not (0 < len(qtables) < 5):

@@ -446,7 +446,7 @@
Loading
446 446
                assert len(im.quantization) == n
447 447
                reloaded = self.roundtrip(im, qtables="keep")
448 448
                assert im.quantization == reloaded.quantization
449 -
                assert reloaded.quantization[0].typecode == "B"
449 +
                assert max(reloaded.quantization[0]) <= 255
450 450
451 451
        with Image.open("Tests/images/hopper.jpg") as im:
452 452
            qtables = im.quantization
@@ -458,7 +458,8 @@
Loading
458 458
459 459
            # valid bounds for baseline qtable
460 460
            bounds_qtable = [int(s) for s in ("255 1 " * 32).split(None)]
461 -
            self.roundtrip(im, qtables=[bounds_qtable])
461 +
            im2 = self.roundtrip(im, qtables=[bounds_qtable])
462 +
            assert im2.quantization[0] == bounds_qtable
462 463
463 464
            # values from wizard.txt in jpeg9-a src package.
464 465
            standard_l_qtable = [
@@ -569,6 +570,12 @@
Loading
569 570
            assert max(im2.quantization[0]) <= 255
570 571
            assert max(im2.quantization[1]) <= 255
571 572
573 +
    def test_convert_dict_qtables_deprecation(self):
574 +
        with pytest.warns(DeprecationWarning):
575 +
            qtable = {0: [1, 2, 3, 4]}
576 +
            qtable2 = JpegImagePlugin.convert_dict_qtables(qtable)
577 +
            assert qtable == qtable2
578 +
572 579
    @pytest.mark.skipif(not djpeg_available(), reason="djpeg not available")
573 580
    def test_load_djpeg(self):
574 581
        with Image.open(TEST_FILE) as img:
Files Coverage
Tests 98.13%
src 86.06%
conftest.py 77.78%
Project Totals (328 files) 90.05%
Windows Python 3.7 x64
Build #312739072 -
GHA_Windows
Windows Python 3.6 x64
Build #312739072 -
GHA_Windows
9812.3
TRAVIS_PYTHON_VERSION=3.7
TRAVIS_OS_NAME=linux
TravisCI
Windows Python 3.9 x64
Build #312739072 -
GHA_Windows
Windows Python 3.8 x64
Build #312739072 -
GHA_Windows
Windows Python 3.6 x86
Build #312739072 -
GHA_Windows
Windows Python 3.7 x86
Build #312739072 -
GHA_Windows
ubuntu-latest Python 3.8
Build #312739073 -
GHA_Ubuntu
Windows Python 3.9 x86
Build #312739072 -
GHA_Windows
Windows Python pypy3 x86
Build #312739072 -
GHA_Windows
centos-7-amd64
Build #312739074 -
GHA_Docker
amazon-1-amd64
Build #312739074 -
GHA_Docker
ubuntu-18.04-bionic-amd64
Build #312739074 -
GHA_Docker
centos-6-amd64
Build #312739074 -
GHA_Docker
fedora-32-amd64
Build #312739074 -
GHA_Docker
alpine
Build #312739074 -
GHA_Docker
centos-8-amd64
Build #312739074 -
GHA_Docker
ubuntu-20.04-focal-amd64
Build #312739074 -
GHA_Docker
amazon-2-amd64
Build #312739074 -
GHA_Docker
arch
Build #312739074 -
GHA_Docker
macOS-latest Python 3.8
Build #312739073 -
GHA_macOS
macOS-latest Python 3.6
Build #312739073 -
GHA_macOS
macOS-latest Python 3.7
Build #312739073 -
GHA_macOS
debian-10-buster-x86
Build #312739074 -
GHA_Docker
macOS-latest Python 3.9
Build #312739073 -
GHA_macOS
9812.4
TRAVIS_PYTHON_VERSION=3.8
TRAVIS_OS_NAME=linux
TravisCI
ubuntu-latest Python 3.9
Build #312739073 -
GHA_Ubuntu
ubuntu-latest Python 3.6
Build #312739073 -
GHA_Ubuntu
Windows Python 3.8 x86
Build #312739072 -
GHA_Windows
ubuntu-latest Python 3.7
Build #312739073 -
GHA_Ubuntu
ubuntu-latest Python pypy3
Build #312739073 -
GHA_Ubuntu
macOS-latest Python pypy3
Build #312739073 -
GHA_macOS

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading