Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: Test and improve PNG transparency check (f-019) #746

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions se/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ def has_transparency(image: Image_type) -> bool:

if image.mode == "P":
transparent = image.info.get("transparency", -1)
for _, index in image.getcolors():
if index == transparent:
return True
elif image.mode == "RGBA":
if isinstance(transparent, bytes):
for _, index in image.getcolors():
if index >= len(transparent):
return False
if transparent[index] < 255:
return True
else:
for _, index in image.getcolors():
if index == transparent:
return True
elif image.mode in ("LA", "RGBA"):
extrema = image.getextrema()
if extrema[3][0] < 255:
if extrema[-1][0] < 255:
return True

return False
Expand Down
8 changes: 8 additions & 0 deletions tests/lint/filesystem/f-019/golden/f-019-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
f-019 [Error] illustration-1.png `.png` file without transparency. Hint: If an
image doesn’t have transparency, it should be saved as a `.jpg`.
f-019 [Error] illustration-6.png `.png` file without transparency. Hint: If an
image doesn’t have transparency, it should be saved as a `.jpg`.
f-019 [Error] illustration-7.png `.png` file without transparency. Hint: If an
image doesn’t have transparency, it should be saved as a `.jpg`.
f-019 [Error] illustration-8.png `.png` file without transparency. Hint: If an
image doesn’t have transparency, it should be saved as a `.jpg`.
101 changes: 101 additions & 0 deletions tests/lint/filesystem/f-019/in/src/epub/content.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://www.idpf.org/2007/opf" dir="ltr" prefix="se: https://standardebooks.org/vocab/1.0" unique-identifier="uid" version="3.0" xml:lang="en-US">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:identifier id="uid">url:https://standardebooks.org/ebooks/jane-austen/unknown-novel</dc:identifier>
<dc:date>1900-01-01T00:00:00Z</dc:date>
<meta property="dcterms:modified">1900-01-01T00:00:00Z</meta>
<dc:rights>The source text and artwork in this ebook are believed to be in the United States public domain; that is, they are believed to be free of copyright restrictions in the United States. They may still be copyrighted in other countries, so users located outside of the United States must check their local laws before using this ebook. The creators of, and contributors to, this ebook dedicate their contributions to the worldwide public domain via the terms in the [CC0 1.0 Universal Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/).</dc:rights>
<dc:publisher id="publisher">Standard Ebooks</dc:publisher>
<meta property="file-as" refines="#publisher">Standard Ebooks</meta>
<meta property="se:url.homepage" refines="#publisher">https://standardebooks.org</meta>
<meta property="role" refines="#publisher" scheme="marc:relators">bkd</meta>
<meta property="role" refines="#publisher" scheme="marc:relators">mdc</meta>
<meta property="role" refines="#publisher" scheme="marc:relators">pbl</meta>
<dc:contributor id="type-designer">The League of Moveable Type</dc:contributor>
<meta property="file-as" refines="#type-designer">League of Moveable Type, The</meta>
<meta property="se:url.homepage" refines="#type-designer">https://www.theleagueofmoveabletype.com</meta>
<meta property="role" refines="#type-designer" scheme="marc:relators">tyd</meta>
<link href="http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aa" rel="dcterms:conformsTo"/>
<meta property="a11y:certifiedBy">Standard Ebooks</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
<meta property="schema:accessibilityFeature">readingOrder</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilityFeature">tableOfContents</meta>
<meta property="schema:accessibilityFeature">unlocked</meta>
<meta property="schema:accessibilityHazard">none</meta>
<meta property="schema:accessibilitySummary">This publication conforms to WCAG 2.2 Level AA.</meta>
<link href="onix.xml" media-type="application/xml" properties="onix" rel="record"/>
<dc:title id="title">Unknown Novel</dc:title>
<meta property="file-as" refines="#title">Unknown Novel</meta>
<dc:subject id="subject-1">England--Social life and customs--19th century--Fiction</dc:subject>
<dc:subject id="subject-2">Sisters -- Fiction</dc:subject>
<meta property="authority" refines="#subject-1">LCSH</meta>
<meta property="term" refines="#subject-1">sh2008114941</meta>
<meta property="authority" refines="#subject-2">LCSH</meta>
<meta property="term" refines="#subject-2">sh2008111400</meta>
<meta property="se:subject">Fiction</meta>
<dc:description id="description">A short test novel for lint testing.</dc:description>
<meta id="long-description" property="se:long-description" refines="#description">
&lt;p&gt;A short test novel for lint testing.&lt;/p&gt;
</meta>
<dc:language>en-GB</dc:language>
<dc:source>https://www.gutenberg.org/ebooks/161</dc:source>
<dc:source>https://archive.org/details/bub_gb_RtT0OLKFMHsC</dc:source>
<meta property="se:word-count">WORD_COUNT</meta>
<meta property="se:reading-ease.flesch">READING_EASE</meta>
<meta property="se:url.encyclopedia.wikipedia">https://en.wikipedia.org/wiki/Unknown_Jane_Austen_Novel</meta>
<meta property="se:url.vcs.github">https://github.com/standardebooks/jane-austen_unknown-novel</meta>
<dc:creator id="author">Jane Austen</dc:creator>
<meta property="file-as" refines="#author">Austen, Jane</meta>
<meta property="se:url.encyclopedia.wikipedia" refines="#author">https://en.wikipedia.org/wiki/Jane_Austen</meta>
<meta property="se:url.authority.nacoaf" refines="#author">http://id.loc.gov/authorities/names/n79032879</meta>
<meta property="role" refines="#author" scheme="marc:relators">aut</meta>
<dc:contributor id="artist">Georg Friedrich Kersting</dc:contributor>
<meta property="file-as" refines="#artist">Kersting, Georg Friedrich</meta>
<meta property="se:url.encyclopedia.wikipedia" refines="#artist">https://en.wikipedia.org/wiki/Georg_Friedrich_Kersting</meta>
<meta property="se:url.authority.nacoaf" refines="#artist">http://id.loc.gov/authorities/names/n83319941</meta>
<meta property="role" refines="#artist" scheme="marc:relators">art</meta>
<dc:contributor id="transcriber-1">Anonymous</dc:contributor>
<meta property="file-as" refines="#transcriber-1">Anonymous</meta>
<meta property="role" refines="#transcriber-1" scheme="marc:relators">trc</meta>
<dc:contributor id="producer-1">John Doe</dc:contributor>
<meta property="file-as" refines="#producer-1">Doe, John</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">bkp</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">blw</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">cov</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">mrk</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">pfr</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">tyg</meta>
<meta property="role" refines="#producer-1" scheme="marc:relators">wat</meta>
</metadata>
<manifest>
<item href="css/core.css" id="core.css" media-type="text/css"/>
<item href="css/local.css" id="local.css" media-type="text/css"/>
<item href="css/se.css" id="se.css" media-type="text/css"/>
<item href="images/cover.svg" id="cover.svg" media-type="image/svg+xml" properties="cover-image"/>
<item href="images/illustration-1.png" id="illustration-1.png" media-type="image/png"/>
<item href="images/illustration-2.png" id="illustration-2.png" media-type="image/png"/>
<item href="images/illustration-3.png" id="illustration-3.png" media-type="image/png"/>
<item href="images/illustration-4.png" id="illustration-4.png" media-type="image/png"/>
<item href="images/illustration-5.png" id="illustration-5.png" media-type="image/png"/>
<item href="images/illustration-6.png" id="illustration-6.png" media-type="image/png"/>
<item href="images/illustration-7.png" id="illustration-7.png" media-type="image/png"/>
<item href="images/illustration-8.png" id="illustration-8.png" media-type="image/png"/>
<item href="images/logo.svg" id="logo.svg" media-type="image/svg+xml"/>
<item href="images/titlepage.svg" id="titlepage.svg" media-type="image/svg+xml"/>
<item href="text/chapter-1.xhtml" id="chapter-1.xhtml" media-type="application/xhtml+xml"/>
<item href="text/colophon.xhtml" id="colophon.xhtml" media-type="application/xhtml+xml" properties="svg"/>
<item href="text/imprint.xhtml" id="imprint.xhtml" media-type="application/xhtml+xml" properties="svg"/>
<item href="text/titlepage.xhtml" id="titlepage.xhtml" media-type="application/xhtml+xml" properties="svg"/>
<item href="text/uncopyright.xhtml" id="uncopyright.xhtml" media-type="application/xhtml+xml"/>
<item href="toc.xhtml" id="toc.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="titlepage.xhtml"/>
<itemref idref="imprint.xhtml"/>
<itemref idref="chapter-1.xhtml"/>
<itemref idref="colophon.xhtml"/>
<itemref idref="uncopyright.xhtml"/>
</spine>
</package>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions tests/lint/filesystem/f-019/in/src/epub/text/chapter-1.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" epub:prefix="z3998: http://www.daisy.org/z3998/2012/vocab/structure/, se: https://standardebooks.org/vocab/1.0" xml:lang="en-GB">
<head>
<title>I</title>
<link href="../css/core.css" rel="stylesheet" type="text/css"/>
<link href="../css/local.css" rel="stylesheet" type="text/css"/>
</head>
<body epub:type="bodymatter z3998:fiction">
<section id="chapter-1" epub:type="chapter">
<h2 epub:type="ordinal z3998:roman">I</h2>
<p>We can assume that any instance of a point can be construed as a themeless fisherman. Framed in a different way, some picked shakes are thought of simply as crabs. Nowhere is it disputed that a dinner sees a modem as a warming customer. The zeitgeist contends that we can assume that any instance of a kenneth can be construed as an entranced belgian. A rotate is a gaumless debt.</p>
<p><img src="illustration-1.png" alt="Not transparent."/></p>
<p><img src="illustration-2.png" alt="Transparent."/></p>
<p><img src="illustration-3.png" alt="Transparent."/></p>
<p><img src="illustration-4.png" alt="Transparent."/></p>
<p><img src="illustration-5.png" alt="Transparent."/></p>
<p><img src="illustration-6.png" alt="Not transparent."/></p>
<p><img src="illustration-7.png" alt="Not transparent."/></p>
<p><img src="illustration-8.png" alt="Not transparent."/></p>
</section>
</body>
</html>
Loading