FROM debian:oldstable
RUN if [ ! -f /etc/apt/sources.list ]; then \
        echo "deb http://deb.debian.org/debian oldstable main" > /etc/apt/sources.list && \
        echo "deb http://deb.debian.org/debian-security oldstable-security main" >> /etc/apt/sources.list; \
    fi \
    && apt-get update -qyy \
    && apt-get install -y --no-install-recommends \
        at-spi2-core \
        build-essential \
        desktop-file-utils \
        unzip \
        hicolor-icon-theme \
        git \
        glib-networking \
        intltool \
        libexiv2-dev \
        libgtk-3-dev \
        libcfitsio-dev \
        libfftw3-dev \
        libgsl-dev \
        libgtksourceview-4-dev \
        librsvg2-dev \
        libffms2-dev \
        libtiff-dev \
        libturbojpeg0 \
        libturbojpeg0-dev \
        libheif-dev \
        heif-thumbnailer \
        heif-gdk-pixbuf \
        libpng-dev \
        libavformat-dev \
        libavutil-dev \
        libavcodec-dev \
        libswscale-dev \
        libswresample-dev \
        zstd \
        libzstd-dev \
        libgit2-dev \
        wget \
        libtool \
        libcurl4-gnutls-dev \
        python3 \
        python3-pip \
        python3-venv \
        python3-tk \
        libjson-glib-dev \
        libzstd-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN python3 -m venv /opt/python-env
ENV PATH="/opt/python-env/bin:$PATH"

RUN pip install cmake==3.22.6

RUN git clone https://github.com/LibRaw/LibRaw.git \
    && cd LibRaw \
    && autoreconf -fi \
    && ./configure --disable-examples --disable-static --prefix /usr \
    && make install \
    && cd .. \
    && rm -rf LibRaw \
    && git clone --branch v0.7.0 --single-branch https://github.com/libjxl/libjxl \
    && cd libjxl \
    && ./deps.sh \
    && mkdir -p build && cd build \
    && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. \
    && cmake --build . -- \
    && cmake --build . -- -j$(nproc) \
    && cmake --install . \
    && cd ../.. \
    && rm -rf libjxl

RUN git clone https://github.com/mm2/Little-CMS \
    && cd Little-CMS \
    && git checkout lcms2.14 \
    && ./configure --with-fastfloat --with-threaded --prefix /usr \
    && make install \
    && cd .. \
    && rm -rf Little-CMS

RUN git clone --branch v0.2.12 --single-branch https://gitea.nouspiro.space/nou/libXISF.git \
    && cd libXISF \
    && mkdir -p build && cd build \
    && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. \
    && make install \
    && cd ../.. \
    && rm -rf libXISF

RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.3.zip \
    && unzip opencv.zip && cd opencv-4.5.3 \
    && mkdir -p build && cd build \
    && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \
        -DOPENCV_GENERATE_PKGCONFIG=ON \
        -DBUILD_DOCS=OFF \
        -DBUILD_EXAMPLES=OFF \
        -DBUILD_opencv_apps=OFF \
        -DBUILD_opencv_python2=OFF \
        -DBUILD_opencv_python3=OFF \
        -DBUILD_PERF_TESTS=OFF \
        -DBUILD_SHARED_LIBS=ON \
        -DBUILD_TESTS=OFF \
        -DCMAKE_BUILD_TYPE=RELEASE \
        -DENABLE_PRECOMPILED_HEADERS=OFF \
        -DFORCE_VTK=OFF \
        -DWITH_FFMPEG=OFF \
        -DWITH_GDAL=OFF \
        -DWITH_IPP=OFF \
        -DWITH_OPENEXR=OFF \
        -DWITH_OPENGL=OFF \
        -DWITH_QT=OFF \
        -DWITH_TBB=OFF \
        -DWITH_XINE=OFF \
        -DBUILD_JPEG=ON \
        -DBUILD_TIFF=ON \
        -DBUILD_PNG=ON ..\
    && make install \
    && cd ../.. \
    && rm -rf opencv-4.5.3 opencv.zip

RUN pip install meson==1.9.1 ninja!=1.11.1