Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package maim for openSUSE:Factory checked in at 2021-07-15 23:59:01 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/maim (Old) and /work/SRC/openSUSE:Factory/.maim.new.2625 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "maim" Thu Jul 15 23:59:01 2021 rev:6 rq:906139 version:5.7.4 Changes: -------- --- /work/SRC/openSUSE:Factory/maim/maim.changes 2020-09-03 01:08:48.940360217 +0200 +++ /work/SRC/openSUSE:Factory/.maim.new.2625/maim.changes 2021-07-15 23:59:14.998054980 +0200 @@ -1,0 +2,7 @@ +Sat Jul 10 13:35:09 UTC 2021 - Ferdinand Thiessen <[email protected]> + +- Update to 5.7.4 + * Supports webp, and bmp + * Huge speed improvements + +------------------------------------------------------------------- Old: ---- maim-5.6.3.tar.gz New: ---- maim-5.7.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ maim.spec ++++++ --- /var/tmp/diff_new_pack.BwhIQe/_old 2021-07-15 23:59:15.486051054 +0200 +++ /var/tmp/diff_new_pack.BwhIQe/_new 2021-07-15 23:59:15.486051054 +0200 @@ -1,7 +1,7 @@ # # spec file for package maim # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,13 +18,13 @@ # See also http://en.opensuse.org/openSUSE:Specfile_guidelines Name: maim -Version: 5.6.3 +Version: 5.7.4 Release: 0 Summary: Flexible screenshotting utility License: GPL-3.0-or-later Group: Productivity/Graphics/Other URL: https://github.com/naelstrof/maim -Source0: https://github.com/naelstrof/%{name}/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz +Source0: %{url}/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz BuildRequires: cmake >= 3.7 BuildRequires: gcc-c++ BuildRequires: gengetopt @@ -35,6 +35,7 @@ BuildRequires: pkgconfig(icu-uc) BuildRequires: pkgconfig(libjpeg) BuildRequires: pkgconfig(libpng) +BuildRequires: pkgconfig(libwebp) BuildRequires: pkgconfig(xcomposite) BuildRequires: pkgconfig(xfixes) BuildRequires: pkgconfig(xrandr) @@ -50,7 +51,7 @@ %build %cmake -%make_jobs +%cmake_build %install %cmake_install ++++++ maim-5.6.3.tar.gz -> maim-5.7.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/CMakeLists.txt new/maim-5.7.4/CMakeLists.txt --- old/maim-5.6.3/CMakeLists.txt 2020-04-10 23:31:17.000000000 +0200 +++ new/maim-5.7.4/CMakeLists.txt 2021-06-15 04:28:58.000000000 +0200 @@ -1,6 +1,6 @@ cmake_minimum_required( VERSION 3.1.3 ) -project(maim VERSION 5.6.3 LANGUAGES CXX) +project(maim VERSION 5.7.4 LANGUAGES CXX) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") @@ -31,6 +31,7 @@ set( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/modules" ) find_package( PNG REQUIRED ) find_package( JPEG REQUIRED ) +find_package( WebP REQUIRED ) find_package( XRandr REQUIRED ) find_package( XRender REQUIRED ) find_package( XFixes REQUIRED ) @@ -38,6 +39,7 @@ find_package( X11 REQUIRED ) find_package( SLOP REQUIRED ) find_package( Threads REQUIRED ) +find_package( GLM REQUIRED ) set_property(TARGET ${BIN_TARGET} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${BIN_TARGET} PROPERTY CXX_STANDARD 11) @@ -47,12 +49,14 @@ include_directories( ${XRANDR_INCLUDE_DIR} ${X11_INCLUDE_DIR} ${SLOP_INCLUDE_DIR} + ${GLM_INCLUDE_DIR} ${XFIXES_INCLUDE_DIR} ${XCOMPOSITE_INCLUDE_DIR} ${JPEG_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${XRENDER_INCLUDE_DIR} - ${PNG_INCLUDE_DIRS} ) + ${PNG_INCLUDE_DIRS} + ${WEBP_INCLUDE_DIR} ) # Libraries target_link_libraries( ${BIN_TARGET} @@ -64,7 +68,8 @@ ${XRANDR_LIBRARY} ${JPEG_LIBRARIES} ${XRENDER_LIBRARY} - ${SLOP_LIBRARIES} ) + ${SLOP_LIBRARIES} + ${WEBP_LIBRARY} ) if( ${CMAKE_VERSION} VERSION_LESS 3.7 ) message( WARNING "CMake version is below 3.7, CMake version >= 3.7 is required for unicode support." ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/README.md new/maim-5.7.4/README.md --- old/maim-5.6.3/README.md 2020-04-10 23:31:17.000000000 +0200 +++ new/maim-5.7.4/README.md 2021-06-15 04:28:58.000000000 +0200 @@ -2,7 +2,7 @@ maim (Make Image) is a utility that takes screenshots of your desktop. It's meant to overcome shortcomings of scrot and performs better in several ways. ## Features -* Takes screenshots of your desktop, and saves it in png or jpg format. +* Takes screenshots of your desktop, and saves it in png, jpg, or bmp format. * Takes screenshots predetermined regions or windows, useful for automation. * Allows a users to select a region, or window, before taking a screenshot on the fly. @@ -28,10 +28,10 @@ * [FreeBSD: graphics/maim](http://www.freshports.org/graphics/maim/) * [NetBSD: x11/maim](http://pkgsrc.se/x11/maim) * [OpenBSD: graphics/maim](http://openports.se/graphics/maim) -* [CRUX: 6c37/maim](https://github.com/6c37/crux-ports/tree/3.3/maim) +* [CRUX: maim](https://crux.nu/portdb/?a=search&q=maim) * [Gentoo: media-gfx/maim](https://packages.gentoo.org/packages/media-gfx/maim) * [NixOS: maim](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/graphics/maim/default.nix) -* [GNU Guix: maim](https://www.gnu.org/software/guix/packages/#maim) +* [GNU Guix: maim](https://guix.gnu.org/en/packages/maim-5.6.3/) * [Ravenports: maim](http://www.ravenports.com/catalog/bucket_B4/maim/standard/) * [Fedora: maim](https://src.fedoraproject.org/rpms/maim) * Please make a package for maim on your favorite system, and make a pull request to add it to this list. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/maim.1 new/maim-5.7.4/maim.1 --- old/maim-5.6.3/maim.1 2020-04-10 23:31:17.000000000 +0200 +++ new/maim-5.7.4/maim.1 2021-06-15 04:28:58.000000000 +0200 @@ -6,7 +6,7 @@ .SH SYNOPSIS maim [OPTIONS] [FILEPATH] .SH DESCRIPTION -maim (make image) is an utility that takes a screenshot of your desktop, and encodes a png or jpg image of it. By default it outputs the encoded image data directly to standard output. +maim (make image) is an utility that takes a screenshot of your desktop, and encodes a png, jpg, bmp or webp image of it. By default it outputs the encoded image data directly to standard output. .SH OPTIONS .TP .BR \-h ", " \-\-help @@ -19,10 +19,10 @@ Sets the xdisplay to use. .TP .BR \-f ", " \-\-format=\fISTRING\fR -Sets the desired output format, by default maim will attempt to determine the desired output format automatically from the output file. If that fails it defaults to a lossless png format. Currently only supports `png` or `jpg`. +Sets the desired output format, by default maim will attempt to determine the desired output format automatically from the output file. If that fails it defaults to a lossless png format. Currently only supports `png`, `jpg`, `bmp`, and `webp`. .TP .BR \-i ", " \-\-window=\fIWINDOW\fR -Sets the desired window to capture, defaults to the root window. Allows for an integer, hex, or `root` for input. +By default, maim captures the root window. This parameter overrides this and sets the desired window to capture. Allows for an integer, hex, or `root` for input. .TP .BR \-g ", " \-\-geometry=\fIGEOMETRY\fR Sets the region to capture, uses local coordinates from the given window. So -g 10x30-5+0 would represent the rectangle wxh+x+y where w=10, h=30, x=-5, and y=0. x and y are the upper left location of this rectangle. @@ -40,7 +40,7 @@ By default maim super-imposes the cursor onto the image, you can disable that behavior with this flag. .TP .BR \-m ", " \-\-quality -An integer from 1 to 10 that determines the compression quality. 1 is the highest (and lossiest) compression available for the provided format. For example a setting of `1` with png (a lossless format) would increase filesize and decrease decoding time. While a setting of `1` on a jpeg would create a pixel mush. +An integer from 1 to 10 that determines the compression quality. For lossy formats (jpg and webp), lower settings will produce smaller files with lower quality, while higher settings will increase quality at the cost of higher file size. A quality of 10 is lossless for webp. For png, lower settings will compress faster and produce larger files, while higher settings will compress slower, but produce smaller files. No effect on bmp images. .TP .BR \-s ", " \-\-select Enables an interactive selection mode where you may select the desired region or window before a screenshot is captured. Uses the settings below to determine the visuals and settings of slop. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/modules/FindGLM.cmake new/maim-5.7.4/modules/FindGLM.cmake --- old/maim-5.6.3/modules/FindGLM.cmake 1970-01-01 01:00:00.000000000 +0100 +++ new/maim-5.7.4/modules/FindGLM.cmake 2021-06-15 04:28:58.000000000 +0200 @@ -0,0 +1,20 @@ +# - Find GLM +# Find the GLM libraries +# +# This module defines the following variables: +# GLM_FOUND - 1 if GLM_INCLUDE_DIR is found, 0 otherwise +# GLM_INCLUDE_DIR - where to find glm/glm.hpp +# + +find_path( GLM_INCLUDE_DIR + NAMES glm/glm.hpp + PATH_SUFFIXES /usr/include /include + DOC "The GLM include directory" ) + +if( GLM_INCLUDE_DIR ) + set( GLM_FOUND 1 ) +else() + set( GLM_FOUND 0 ) +endif() + +mark_as_advanced( GLM_INCLUDE_DIR ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/modules/FindWebP.cmake new/maim-5.7.4/modules/FindWebP.cmake --- old/maim-5.6.3/modules/FindWebP.cmake 1970-01-01 01:00:00.000000000 +0100 +++ new/maim-5.7.4/modules/FindWebP.cmake 2021-06-15 04:28:58.000000000 +0200 @@ -0,0 +1,25 @@ +# - Find WebP +# Find the WebP libraries +# +# This module defines the following variables: +# WEBP_FOUND - 1 if WEBP_INCLUDE_DIR & WEBP_LIBRARY are found, 0 otherwise +# WEBP_INCLUDE_DIR - where to find webp/encode.h, etc. +# WEBP_LIBRARY - the libwebp library + +find_path( WEBP_INCLUDE_DIR + NAMES webp/encode.h + PATH_SUFFIXES /usr/include /include + DOC "The libwebp include directory" ) + +find_library( WEBP_LIBRARY + NAMES libwebp.so + PATHS /usr/lib /lib + DOC "The libwebp library" ) + +if( WEBP_INCLUDE_DIR AND WEBP_LIBRARY ) + set( WEBP_FOUND 1 ) +else() + set( WEBP_FOUND 0 ) +endif() + +mark_as_advanced( WEBP_INCLUDE_DIR WEBP_LIBRARY ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/src/image.cpp new/maim-5.7.4/src/image.cpp --- old/maim-5.6.3/src/image.cpp 2020-04-10 23:31:17.000000000 +0200 +++ new/maim-5.7.4/src/image.cpp 2021-06-15 04:28:58.000000000 +0200 @@ -204,6 +204,99 @@ delete[] out_buffer; } +void ARGBImage::writeBMP( std::ostream& streamout ) { + int padding = (4 - (width * channels % 4)) % 4; + int rowSize = width * channels + padding; + int imageSize = height * rowSize; + int fileSize = 54 + imageSize; + + unsigned char header [14] = { + 'B', 'M', + (unsigned char)fileSize, (unsigned char)(fileSize >> 8), + (unsigned char)(fileSize >> 16), (unsigned char)(fileSize >> 24), + // Reserved + 0, 0, 0, 0, + // Offset to start of image data + 54, 0, 0, 0, + }; + + unsigned char infoHeader [40] = { + // Size of header + 40, 0, 0, 0, + (unsigned char)width, (unsigned char)(width >> 8), + (unsigned char)(width >> 16), (unsigned char)(width >> 24), + (unsigned char)height, (unsigned char)(height >> 8), + (unsigned char)(height >> 16), (unsigned char)(height >> 24), + // 1 Colour plane + 1, 0, + // 8 bits per channel + (unsigned char)(8 * channels), 0, + // No compression + 0, 0, 0, 0, + // Size of image including padding + (unsigned char)imageSize, (unsigned char)(imageSize >> 8), + (unsigned char)(imageSize >> 16), (unsigned char)(imageSize >> 24), + // 72 DPI for printing as pixels/metre + 0x13, 0x0B, 0, 0, + 0x13, 0x0B, 0, 0, + // 0 Palette colours, 0 important colours + 0, 0, 0, 0, + 0, 0, 0, 0, + }; + + streamout.write( (const char*)header, 14 ); + streamout.write( (const char*)infoHeader, 40 ); + + unsigned char* imageData = new unsigned char[imageSize]; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + // BMP is bottom to top and uses BGR/BGRA + int outOffset = y*rowSize + x*channels; + int inOffset = ((height-y-1)*width + x)*channels; + imageData[outOffset] = data[inOffset + 2]; + imageData[outOffset + 1] = data[inOffset + 1]; + imageData[outOffset + 2] = data[inOffset]; + if (channels == 4) { + imageData[outOffset + 3] = data[inOffset+3]; + } + } + + for (int p = 0; p < padding; p++) { + imageData[y*rowSize + width*channels + p] = 0; + } + } + + streamout.write( (const char*)imageData, imageSize ); + delete[] imageData; +} + +void ARGBImage::writeWEBP( std::ostream& streamout, int quality ) { + // assume 4 channels + if (channels != 4) { + throw new std::runtime_error("WebP tried to save image with more than 4 channels"); + } + + size_t size; + uint8_t* out; + if (quality == 10) { + // encode lossless at highest quality + size = WebPEncodeLosslessRGBA(data, width, height, width * 4, &out); + } + else { + // otherwise, encode lossy + size = WebPEncodeRGBA(data, width, height, width * 4, quality * 10.0f, &out); + } + + if (size == 0) { + throw new std::runtime_error("Failed to encode webp image"); + } + else { + streamout.write((const char*)out, size); + WebPFree(out); + } +} + bool ARGBImage::intersect( XRRCrtcInfo* a, glm::vec4 b ) { if (a->x < b.x + b.z && a->x + a->width > b.x && @@ -239,13 +332,8 @@ } unsigned char* copy = new unsigned char[width*height*channels]; // Zero out our copy - for ( int y = 0; y < height;y++ ) { - for ( int x = 0; x < width;x++ ) { - for ( int c = 0; c < channels;c++ ) { - copy[(y*width+x)*channels+c] = 0; - } - } - } + memset( copy, 0, width*height*channels ); + for ( int i=0;i<physicalMonitors.size();i++ ) { // Make sure we're intersecting XRRCrtcInfo* m = physicalMonitors[i]; @@ -254,11 +342,9 @@ } // Copy over data within the intersecting areas. for ( int y = glm::max(0,m->y-imagey); y<glm::min(height,m->y+m->height-imagey);y++ ) { - for ( int x = glm::max(0,m->x-imagex); x < glm::min(width,m->x+m->width-imagex);x++ ) { - for ( int c = 0; c < channels;c++ ) { - copy[(y*width+x)*channels+c] = data[(y*width+x)*channels+c]; - } - } + int start = (y*width + glm::max(0, m->x-imagex))*channels; + int end = (y*width + glm::min(width,m->x+m->width-imagex))*channels; + memcpy( copy+start, data+start, end-start ); } } x11->freeCRTCS(physicalMonitors); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/src/image.hpp new/maim-5.7.4/src/image.hpp --- old/maim-5.6.3/src/image.hpp 2020-04-10 23:31:17.000000000 +0200 +++ new/maim-5.7.4/src/image.hpp 2021-06-15 04:28:58.000000000 +0200 @@ -21,9 +21,11 @@ #ifndef N_IMAGE_H_ #define N_IMAGE_H_ +#include <cstring> #include <iostream> #include <png.h> #include <jpeglib.h> +#include <webp/encode.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdexcept> @@ -89,6 +91,8 @@ ~ARGBImage(); void writePNG( std::ostream& streamout, int quality ); void writeJPEG( std::ostream& streamout, int quality ); + void writeBMP( std::ostream& streamout ); + void writeWEBP( std::ostream& streamout, int quality ); }; #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/maim-5.6.3/src/main.cpp new/maim-5.7.4/src/main.cpp --- old/maim-5.6.3/src/main.cpp 2020-04-10 23:31:17.000000000 +0200 +++ new/maim-5.7.4/src/main.cpp 2021-06-15 04:28:58.000000000 +0200 @@ -185,8 +185,8 @@ foo->formatGiven = options.count("format") > 0; if ( foo->formatGiven ) { foo->format = options["format"].as<std::string>(); - if ( foo->format != "png" && foo->format != "jpg" && foo->format != "jpeg" ) { - throw new std::invalid_argument("Unknown format type: `" + foo->format + "`, only `png` or `jpg` is allowed." ); + if ( foo->format != "png" && foo->format != "jpg" && foo->format != "jpeg" && foo->format != "bmp" && foo->format != "webp" ) { + throw new std::invalid_argument("Unknown format type: `" + foo->format + "`, only `png`, `jpg`, or `bmp` is allowed." ); } } if ( options.count( "quality" ) > 0 ) { @@ -272,8 +272,8 @@ DESCRIPTION maim (make image) is an utility that takes a screenshot of your desktop, - and encodes a png or jpg image of it. By default it outputs the encoded - image data directly to standard output. + and encodes a png, jpg, bmp or webp image of it. By default it outputs + the encoded image data directly to standard output. OPTIONS -h, --help @@ -289,7 +289,7 @@ Sets the desired output format, by default maim will attempt to determine the desired output format automatically from the output file. If that fails it defaults to a lossless png format. Cur??? - rently only supports `png` or `jpg`. + rently supports `png`, `jpg`, `bmp` and `webp`. -i, --window=INT Sets the desired window to capture, defaults to the root window. @@ -310,11 +310,14 @@ disable that behavior with this flag. -m, --quality - An integer from 1 to 10 that determines the compression quality. 1 - is the highest (and lossiest) compression available for the pro??? - vided format. For example a setting of `1` with png (a lossless - format) would increase filesize and speed up encoding dramatical- - ly. While a setting of `1` on a jpeg would create a pixel mush. + An integer from 1 to 10 that determines the compression quality. + For lossy formats (jpg and webp), lower settings will produce + smaller files with lower quality, while higher settings will inc- + rease quality at the cost of higher file size. A quality of 10 is + lossless for webp. + For png, lower settings will compress faster and produce larger + files, while higher settings will compress slower, but produce + smaller files. No effect on bmp images. -s, --select Enables an interactive selection mode where you may select the @@ -408,14 +411,14 @@ ("h,help", "Print help and exit.") ("v,version", "Print version and exit.") ("x,xdisplay", "Sets the xdisplay to use", cxxopts::value<std::string>()) - ("f,format", "Sets the desired output format, by default maim will attempt to determine the desired output format automatically from the output file. If that fails it defaults to a lossless png format. Currently only supports `png` or `jpg`.", cxxopts::value<std::string>()) + ("f,format", "Sets the desired output format, by default maim will attempt to determine the desired output format automatically from the output file. If that fails it defaults to a lossless png format. Supports `png`, `jpg`, `bmp` and `webp`.", cxxopts::value<std::string>()) ("i,window", "Sets the desired window to capture, defaults to the root window. Allows for an integer, hex, or `root` for input.", cxxopts::value<std::string>()) ("g,geometry", "Sets the region to capture, uses local coordinates from the given window. So -g10x30-5+0 would represent the rectangle wxh+x+y where w=10, h=30, x=-5, and y=0. x and y are the upper left location of this rectangle.", cxxopts::value<std::string>()) ("w,parent", "By default, maim assumes the --geometry values are in respect to the provided --window (or root if not provided). This parameter overrides this behavior by making the geometry be in respect to whatever window you provide to --parent. Allows for an integer, hex, or `root` for input.", cxxopts::value<std::string>()) ("B,capturebackground", "By default, when capturing a window, maim will ignore anything beneath the specified window. This parameter overrides this and also captures elements underneath the window.") ("d,delay", "Sets the time in seconds to wait before taking a screenshot. Prints a simple message to show how many seconds are left before a screenshot is taken. See --quiet for muting this message.", cxxopts::value<float>()->implicit_value("5")) ("u,hidecursor", "By default maim super-imposes the cursor onto the image, you can disable that behavior with this flag.") - ("m,quality", "An integer from 1 to 10 that determines the compression quality. 1 is the highest (and lossiest) compression available for the provided format. For example a setting of `1` with png (a loss??? less format) would increase filesize and decrease decoding time. While a setting of `1` on a jpeg would create a pixel mush.", cxxopts::value<int>()) + ("m,quality", "An integer from 1 to 10 that determines the compression quality. For lossy formats (jpg and webp), lower settings will produce smaller files with lower quality, while higher settings will increase quality at the cost of higher file size. A quality of 10 is lossless for webp. For png, lower settings will compress faster and produce larger files, while higher settings will compress slower, but produce smaller files. No effect on bmp images.", cxxopts::value<int>()) ("s,select", "Enables an interactive selection mode where you may select the desired region or window before a screenshot is captured. Uses the settings below to determine the visuals and settings of slop.") ("b,bordersize", "Sets the selection rectangle's thickness.", cxxopts::value<float>()) ("p,padding", "Sets the padding size for the selection, this can be negative.", cxxopts::value<float>()) @@ -473,8 +476,8 @@ if ( !maimOptions->formatGiven && maimOptions->savepathGiven && maimOptions->savepath.find_last_of(".") != std::string::npos ) { maimOptions->format = maimOptions->savepath.substr(maimOptions->savepath.find_last_of(".")+1); - if ( maimOptions->format != "png" && maimOptions->format != "jpg" && maimOptions->format != "jpeg" ) { - throw new std::invalid_argument("Unknown format type: `" + maimOptions->format + "`, only `png` or `jpg` is allowed." ); + if ( maimOptions->format != "png" && maimOptions->format != "jpg" && maimOptions->format != "jpeg" && maimOptions->format != "bmp" && maimOptions->format != "webp") { + throw new std::invalid_argument("Unknown format type: `" + maimOptions->format + "`, only `png`, `jpg`, `bmp` or `webp` is allowed." ); } } if ( !maimOptions->windowGiven ) { @@ -557,31 +560,37 @@ glm::ivec2 imageloc; // Snapshot the image XImage* image = x11->getImage( selection.id, px, py, selection.w, selection.h, imageloc); - if ( maimOptions->format == "png" ) { - // Convert it to an ARGB format, clipping it to the selection. - ARGBImage convert(image, imageloc, glm::vec4(px, py, selection.w, selection.h), 4, x11 ); - if ( !maimOptions->hideCursor ) { - convert.blendCursor( x11 ); - } - // Mask it if we're taking a picture of root - if ( selection.id == x11->root ) { - convert.mask(x11); - } - // Then output it in the desired format. + + int num_channels; + if ( maimOptions->format == "png" || maimOptions->format == "webp" ) { + // Convert it to an ARGB format, clipping it to the selection + num_channels = 4; + } else { + // Otherwise (jpeg/bmp), convert to RGB, also clipping it to the selection + num_channels = 3; + } + + ARGBImage convert(image, imageloc, glm::vec4(px, py, selection.w, selection.h), num_channels, x11 ); + + if ( !maimOptions->hideCursor ) { + convert.blendCursor( x11 ); + } + // Mask it if we're taking a picture of root + if ( selection.id == x11->root ) { + convert.mask(x11); + } + + // then output it into into the desired format + if (maimOptions->format == "png") { convert.writePNG(*out, maimOptions->quality ); } else if ( maimOptions->format == "jpg" || maimOptions->format == "jpeg" ) { - // Convert it to a RGB format, clipping it to the selection. - ARGBImage convert(image, imageloc, glm::vec4(px, py, selection.w, selection.h), 3, x11 ); - if ( !maimOptions->hideCursor ) { - convert.blendCursor( x11 ); - } - // Mask it if we're taking a picture of root - if ( selection.id == x11->root ) { - convert.mask(x11); - } - // Then output it in the desired format. convert.writeJPEG(*out, maimOptions->quality ); + } else if ( maimOptions->format == "bmp" ) { + convert.writeBMP(*out); + } else if ( maimOptions->format == "webp" ) { + convert.writeWEBP(*out, maimOptions->quality); } + XDestroyImage( image ); if ( maimOptions->savepathGiven ) { @@ -605,6 +614,10 @@ int main( int argc, char** argv ) { try { return app( argc, argv ); + } catch ( const cxxopts::OptionException& e) { + std::cerr << e.what() << std::endl; + std::cerr << "Try \"maim --help\" for more information." << std::endl; + return 1; } catch( std::exception* e ) { std::cerr << "Maim encountered an error:\n" << e->what() << "\n"; return 1;
