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

✨ Support AVIF image format #385

Merged
merged 10 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
82 changes: 82 additions & 0 deletions .github/actions/setup-dav1d/action.yml
aaronleopold marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Dav1d
description: Compile and install dav1d

runs:
using: composite
steps:
# Linux Section
- name: Install nasm
if: runner.os == 'Linux'
uses: ilammy/setup-nasm@v1

- name: Install Python 3.9
if: runner.os == 'Linux'
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install pip packages
if: runner.os == 'Linux'
run: |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these run clauses need a shell added:

  • bash for linux
  • powershell for windows

pip install -U pip
pip install -U wheel setuptools
pip install -U meson ninja

- name: Build dav1d
if: runner.os == 'Linux'
env:
DAV1D_DIR: dav1d_dir
LIB_PATH: lib/x86_64-linux-gnu
run: |
git clone --branch 1.3.0 --depth 1 https://code.videolan.org/videolan/dav1d.git
cd dav1d
meson build -Dprefix=$HOME/$DAV1D_DIR -Denable_tools=false -Denable_examples=false --buildtype release
ninja -C build
ninja -C build install
echo "PKG_CONFIG_PATH=$HOME/$DAV1D_DIR/$LIB_PATH/pkgconfig" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$HOME/$DAV1D_DIR/$LIB_PATH" >> $GITHUB_ENV

# Windows setup
- name: Install nasm
if: runner.os == 'Windows'
uses: ilammy/setup-nasm@v1

- name: Install Python 3.9
if: runner.os == 'Windows'
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install pip packages
if: runner.os == 'Windows'
run: |
pip install -U pip
pip install -U wheel setuptools
pip install -U meson ninja

- name: Setting up environment
if: runner.os == 'Windows'
shell: bash
run: |
echo "PKG_CONFIG=c:\build\bin\pkg-config.exe" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=C:\build\lib\pkgconfig" >> $GITHUB_ENV
echo "C:\build\bin" >> $GITHUB_PATH

- name: Build pkg-config
if: runner.os == 'Windows'
run: |
git clone --branch meson-glib-subproject --depth 1 https://gitlab.freedesktop.org/tpm/pkg-config.git
cd pkg-config
meson build -Dprefix=C:\build --buildtype release
ninja -C build
ninja -C build install

- name: Build dav1d
if: runner.os == 'Windows'
run: |
git clone --branch 1.3.0 --depth 1 https://code.videolan.org/videolan/dav1d.git
cd dav1d
meson build -Dprefix=C:\build -Denable_tools=false -Denable_examples=false --buildtype release
ninja -C build
ninja -C build install

3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup dav1d
uses: ./.github/actions/setup-dav1d

- name: Setup rust
uses: ./.github/actions/setup-rust

Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ email = { path = "../crates/email" }
epub = { git = "https://github.com/stumpapp/epub-rs", rev = "38e091abe96875952556ab7dec195022d0230e14" }
futures = { workspace = true }
globset = "0.4.14"
image = "0.25.2"
image = {version = "0.25.2", features = ["avif-native"]}
infer = "0.16.0"
itertools = "0.12.1"
prisma-client-rust = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion core/src/filesystem/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use walkdir::WalkDir;

use super::{media::is_accepted_cover_name, ContentType, FileError};

pub const ACCEPTED_IMAGE_EXTENSIONS: [&str; 5] = ["jpg", "png", "jpeg", "webp", "gif"];
pub const ACCEPTED_IMAGE_EXTENSIONS: [&str; 6] =
["jpg", "png", "jpeg", "webp", "avif", "gif"];

pub fn read_entire_file<P: AsRef<Path>>(path: P) -> Result<Vec<u8>, FileError> {
let mut file = File::open(path)?;
Expand Down
7 changes: 7 additions & 0 deletions core/src/filesystem/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum ContentType {
PNG,
JPEG,
WEBP,
AVIF,
GIF,
TXT,
#[default]
Expand Down Expand Up @@ -79,6 +80,7 @@ impl ContentType {
"jpg" => ContentType::JPEG,
"jpeg" => ContentType::JPEG,
"webp" => ContentType::WEBP,
"avif" => ContentType::AVIF,
"gif" => ContentType::GIF,
"txt" => ContentType::TXT,
_ => temporary_content_workarounds(extension),
Expand Down Expand Up @@ -265,6 +267,7 @@ impl ContentType {
ContentType::PNG => "png",
ContentType::JPEG => "jpg",
ContentType::WEBP => "webp",
ContentType::AVIF => "avif",
ContentType::GIF => "gif",
ContentType::TXT => "txt",
ContentType::UNKNOWN => "",
Expand All @@ -291,6 +294,7 @@ impl From<&str> for ContentType {
"image/png" => ContentType::PNG,
"image/jpeg" => ContentType::JPEG,
"image/webp" => ContentType::WEBP,
"image/avif" => ContentType::AVIF,
"image/gif" => ContentType::GIF,
_ => ContentType::UNKNOWN,
}
Expand All @@ -312,6 +316,7 @@ impl std::fmt::Display for ContentType {
ContentType::PNG => write!(f, "image/png"),
ContentType::JPEG => write!(f, "image/jpeg"),
ContentType::WEBP => write!(f, "image/webp"),
ContentType::AVIF => write!(f, "image/avif"),
ContentType::GIF => write!(f, "image/gif"),
ContentType::TXT => write!(f, "text/plain"),
ContentType::UNKNOWN => write!(f, "unknown"),
Expand All @@ -327,6 +332,7 @@ impl From<ImageFormat> for ContentType {
// ImageFormat::JpegXl => ContentType::JPEG,
ImageFormat::Png => ContentType::PNG,
ImageFormat::Webp => ContentType::WEBP,
ImageFormat::Avif => ContentType::AVIF,
}
}
}
Expand All @@ -349,6 +355,7 @@ impl TryFrom<ContentType> for image::ImageFormat {
ContentType::PNG => Ok(image::ImageFormat::Png),
ContentType::JPEG => Ok(image::ImageFormat::Jpeg),
ContentType::WEBP => Ok(image::ImageFormat::WebP),
ContentType::AVIF => Ok(image::ImageFormat::Avif),
ContentType::GIF => Ok(image::ImageFormat::Gif),
ContentType::XHTML => Err(unsupported_error("ContentType::XHTML")),
ContentType::XML => Err(unsupported_error("ContentType::XML")),
Expand Down
Loading
Loading