aboutsummaryrefslogtreecommitdiffstats
path: root/image.c
AgeCommit message (Collapse)Author
2022-10-19code-style: misc changes (#374)NRK
* ensure static variables comes after non-static ones * remove depreciated DATA32 type * prefer `sizeof(expression)` over `sizeof(Type)`. * silence a -Wsign warning * {gif,webp} loader: use a pointer to reduce code-noise * gif loader: allocate in one place Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/374 Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2022-09-10rename: aa -> anti_aliasNRK
2022-09-10allow disabling anti-aliasing via cli flagNRK
simply running nsxiv with `--anti-alias` will enable anti-aliasing, and running it with `--anti-alias=no` will disable it. the cli flag will overwrite the config.h default. Closes: https://codeberg.org/nsxiv/nsxiv/issues/349
2022-08-16code-style: don't indent switch cases (#358)explosion-mental
The suckless coding style [^0] and the linux coding style [^1] both recommends not indenting switch cases. And it helps out people with lower resolution monitors. [^0]: https://suckless.org/coding_style/ [^1]: https://www.kernel.org/doc/html/v5.10/process/coding-style.html#indentation Co-authored-by: explosion-mental <explosion0mental@gmail.com> Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/358 Reviewed-by: NRK <nrk@disroot.org> Co-authored-by: explosion-mental <explosion-mental@noreply.codeberg.org> Co-committed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-11fix: build failure when _SC_PHYS_PAGES is not definedNRK
_SC_PHYS_PAGES isn't POSIX and might not be defined. in such case, just return back `CACHE_SIZE_FALLBACK`. NOTE: POSIX says the `names` in `sysconf()` are "symbolic constants" not necessarily macros. So we might end up returning the fallback in some cases where `_SC_PHYS_PAGES` *was* available, but not defined as a macro. which is not ideal, but nothing fatal. in practice, this shouldn't be an issue since most systems seems to define them to be macros, i've checked Glibc, Musl, OpenBSD, FreeBSD and Haiku. also add a (useful) comment on `config.h` describing the effect higher cache size has. Closes: https://codeberg.org/nsxiv/nsxiv/issues/354
2022-07-15fix: -Wsign-compare warnings (#336)NRK
mixing signed and unsigned types in comparison can end up having unintended results. for example: if (-1 < 1U) printf("true\n"); else printf("false\n"); previously we silenced these warnings, instead just fix them properly via necessary casting, and in cases where the value cannot be negative (e.g width/height members) make them unsigned. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/336 Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-03fix build failure due to missing <stdio.h> (#337)NRK
the following combination currently fails to build: $ make HAVE_LIBFONTS=0 HAVE_LIBWEBP=1 this is probably because one of the font library was including <stdio.h> Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/337 Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr> Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org> Co-authored-by: NRK <nrk@disroot.org> Co-committed-by: NRK <nrk@disroot.org>
2022-06-28code-style: cleanup includesNRK
* rm unused include <sys/types.h> * move <sys/time.h> to main.c, it's the only file that needs it. * move TV_* macros to main.c * let *.c files explicitly include what they need instead of including them at nsxiv.h
2022-06-25[ci]: slience some clang-tidy warningsNRK
the warnings on r_readdir(), img_load_gif() and strcpy seems to be false positives. the warning about fmt being unused is valid, but not worth fixing with additional #ifdef guards. use `assert` to silence the false positive cases when possible, otherwise use a NOLINT comment with an explanation.
2022-06-25fix: don't use reserved identifiersNRK
identifiers beginning with an underscore is reserved by the C standard.
2022-06-02reduce calls to win-titleNRK
rather than calling the script unconditionally per redraw, we now have a `title_dirty` flag and keep track of when any of the relavent information changes. Co-authored-by: Arthur Williams <taaparthur@gmail.com> Partially fixes: https://github.com/nsxiv/nsxiv/issues/258
2022-04-27code-style: reduce some unnecessary if-elses (#261)N-R-K
also change the condition inside img_frame_animate() to check for positive value rather than comparing against 0.
2022-04-12don't quit if imlib_create_image() fails (#248)N-R-K
...simply print an error msg and try (slower) fallback. also adds a useful comment explaining why we're doing manual blending.
2022-02-26add config.h option for top statusbar (#231)N-R-K
Closes: https://github.com/nsxiv/nsxiv/issues/230 Co-authored-by: mamg22 <45301823+mamg22@users.noreply.github.com>
2022-02-13update copyright yearNRK
2022-01-15Add keybind to scroll to image center (#203)Nick Hanley
There are keybinds for scrolling to the edges of an image but there's no way back to the center. This is particularly annoying while zooming.
2022-01-06fix -Wmaybe-uninitialized warningNRK
2022-01-06fix -Wshadow related warningsNRK
fixes all -Wshadow related warnings (on gcc). this would allow us to use `-Wshadow` in github workflow (https://github.com/nsxiv/nsxiv/pull/195). i've thought about adding `-Wshadow` to our Makefile as well, but decided against it to keep the Makefile CFLAGS barebore/minimal.
2022-01-01fix: jpeg exif orientation on Imlib2 v1.7.5 (#188)N-R-K
since Imlib2 v1.7.5, it is capable of parsing exif data on jpeg files and auto orienting them. this caused nsxiv to rotate the image twice. Closes: https://github.com/nsxiv/nsxiv/issues/187
2022-01-01Allow setting cache size based on memory percentage (#184)MahouShoujoMivutilde
The problem: 1. For the most people imlib2's default 4MiB is unreasonably low; 2. Hardcoding cache size to ~256MiB has performance benefits and doesn't increase RAM usage too much on relatively modern systems; 3. But we can't do that, because that would be detrimental to low spec systems that (apparently) not (?) building nsxiv from source, as been discussed #171 Solution: Calculate cache size based on total memory. Default is set as 3%, which means: * ~245MiB for 8GiB * ~30MiB for 1GiB * and so on CACHE_SIZE_LIMIT (256MiB by default) sets the highest possible value. And in case we cannot determine the total memory (e.g since _SC_PHYS_PAGES isn't POSIX) use CACHE_SIZE_FALLBACK (32MiB by default) instead. Co-authored-by: NRK <nrk@disroot.org>
2021-12-12refactor: move shared code into a functionNRK
2021-12-12img_load_webp: close the file handler and use errnoNRK
2021-12-12img_load_webp: simplify multi-frame allocationNRK
C89 standard specifies: If ptr is a null pointer, the realloc function behaves like the malloc function for the specified size.
2021-12-12img_load_webp: remove unnecessary castingNRK
2021-12-12remove unneeded animated-webp hacksNRK
now that imlib2 (v1.7.5) is able to load the first frame of an animated-webp file, we no longer need the `is_webp` check to bypass imlib2. ref: https://phab.enlightenment.org/T8964
2021-12-09fix: compile error (#182)N-R-K
* fix compile error * use variable instead of macro * Revert "use variable instead of macro" This reverts commit a14ef0b231c50e49906761010a4d4231ce4e3e36. * use local variable instead of macro * Revert "use local variable instead of macro" This reverts commit 7e049d55d94f5c003d90e1a10187356f6a7f54b2.
2021-12-01bring back zoom_levels (#156)N-R-K
this still keeps the shorter zoom logic, but adds back the zoom_levels array so that stay close to sxiv. for users who would like to have the zoom step behavior see: https://github.com/nsxiv/nsxiv/pull/156#issuecomment-975182631
2021-12-01fix crash when zooming out on small images (#178)mamg22
When rendering images, destination image width and height may become zero due to float-to-int conversion after zoom calculation, later crashing when creating an image using those dimensions. This sets a minimum of 1 to both variables. Closes #82
2021-11-26fix: img_load_gif: out-of-bound accessNRK
according to imlib2's gif loader, bg should already be transparent black if bg > cmap->ColorCount
2021-11-26Revert "fix: out-of-bounds access when bg not in color map"NRK
with this patch certain gif images will fail to play. one other problem here is that it suddenly breaks the loop without free-ing data and rows, leading to a memory leak. regardless, this needs to be investigated further. here's an example image where this happens: https://i.postimg.cc/SQf1TJJg/awoo-study.gif This reverts commit cca7834e6718c6ff64da42ed5e9770880a3e8ff6.
2021-11-25allow configuring imlib2's cache size (#171)N-R-K
by default imlib2 uses a 4mb cache, which is quite small. this allows users who have more memory to spare to set a bigger cache size and avoid reloading an already viewed image if it fits into the cache. Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-11-20mark functions and vars as static (#146)N-R-K
the goal here to mark functions and variables not used outside the translation unit as static. main reason for this is cleanliness. however as a side-effect this can help compilers optimize better as it now has guarantee that a certain function won't be called outside of that translation unit. one other side-effect of this is that accessing these vars/function from config.h is now different. if one wants to access a static var/func from different translation unit in config.h, he would have to create a wrapper function under the right ifdef. for static functions one would also need to forward declare it. here's a dummy example of accessing the function `run_key_handler` from config.h under _MAPPINGS_CONFIG ``` static void run_key_handler(const char *, unsigned); bool send_with_ctrl(arg_t key) { run_key_handler(XKeysymToString(key), ControlMask); return false; } ```
2021-10-28code-style: general cleanups (#137)N-R-K
* tns_clean_cache: remove unused function arg * remove malloc casting * improve consistency use sizeof(T) at the end * avoid comparing integers of different signedness * use Window type for embed and parent * remove unnecessary comparisons * remove cpp style comments * improve consistency: remove comma from the end of enumerator list * Removed useless _IMAGE_CONFIG defines * consistency: use the same order as snprintf * Resolve c89 warnings Co-authored-by: uidops <uidops@protonmail.com> Co-authored-by: Arthur Williams <taaparthur@gmail.com>
2021-10-28remove unnecessary animated webp related checkN-R-K
this code snippet was introduced in https://github.com/nsxiv/nsxiv/pull/20/commits/2703809a23bdf3fe426466c7a10f41d747913128 but does not seem to be needed. from what i can tell this is some sort of hack that might've been needed back when we didn't bypass imlib2 when loading webp.
2021-10-28update copyright notice (#139)eylles
2021-10-26fix: memory leak in img_load_webp (#135)N-R-K
if `multi.cap` is >0 that means `multi.frames` has already been malloc-ed. by unconditionally malloc-ing again, we're losing all the old memory. this makes it so we're only malloc-ing (or realloc-ing) when needed.
2021-10-16Revert "Fix in tabbed with alpha patch (#3)" (#121)N-R-K
This reverts commit c7ca547b55e98914264351502e581fe6ae17ae15. cd710f5 fixed the issue with embedding into a parent that has alpha and partially reverted c7ca547 this commit fully reverts c7ca547 , as these changes aren't needed for embedding into an alpha-parent.
2021-10-12Fix behaviour when TrueColor / 24 bit depth is not available (#114)miseran
* Fix regression introduced in c7ca547 which made nsxiv not start in non-TrueColor X server. * Introduce a new fix for embedding into tabbed-alpha. * Fixes a visual glitch from original sxiv when drawing transparent images in 8 bit depth. In 8 bit PseudoColor, `.pixel` is just an index into the 256 defined colors and thus trying to extract rgb bits from it would result in visual glitch. The values `.color.red` on the other hand and so on are always integers between 0 and 0xFFFF representing the color as expected. * Use XColor for win_bg/fg and mrk_fg Co-authored-by: NRK <nrk@disroot.org>
2021-10-11code-style: fix consistency issues all over the codebase (#94)Berke Kocaoğlu
* remove duplicate comment * remove empty tabs and blank lines * move macros and globals ontop * comment to seprate function implementation * fix alignment * switch to *argv[] similar to other suckless code * kill all empty last lines * append comment to endif * reuse existing ARRLEN macro * comment fall through * use while (true) everywhere Co-authored-by: NRK <nrk@disroot.org>
2021-10-09Make statusbar optional (#95)Arthur Williams
libXft and libfontconfig are now optional dependencies which can be disabled via `HAVE_LIBFONTS=0`. Disabling them means disabling the statusbar. This also does not search for freetype2 header if disabled. Co-authored-by: NRK <nrk@disroot.org>
2021-09-25Use zoom steps instead of hard-coding levels (#92)Lu Xu
Co-authored-by: NRK <nrk@disroot.org> Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-09-24Add animated webp support (#20)Sam Whitehead
Co-authored-by: NRK <nrk@disroot.org> Co-authored-by: Stein Gunnar Bakkeby <bakkeby@gmail.com> Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-09-16Rename, Update Docs and Prepare for Release (#9)Berke Kocaoğlu
Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com> Co-authored-by: NRK <nrk@disroot.org> Co-authored-by: Arthur Williams <taaparthur@gmail.com> Co-authored-by: eylles <ed.ylles1997@gmail.com>
2021-09-16Rework the build system (#19)TAAPArthur
* Added simple configure script Added simple script to autodetect if optional dependencies are installed and enable/disable them as needed. Note this solution uses the compiler directly instead of an external program like pkgconfig so it doesn't require any extra dependencies. It is intended to work with any arbitrary compiler; it has been tested with tcc and gcc. There are some "breaking" changes hidden here - HAVE_GIFLIB was renamed to HAVE_LIBGIF to match HAVE_LIBEXIF - Simply typing `make` will no longer try to build with optional dependencies * use implicit RM variable * General clean-up in configure - Use printf instead of echo - Format style * honor env PREFIX, use LDLIBS * Revert "General clean-up in configure" This reverts commit 8683c179dbf273a330f9a224a4d481a7bea42c5f. * honor env LDFLAGS if set * Don't set OPTIONAL_LIBS in configure * make OBJ all caps * follow suckless style build system - remove configure script. - HAVE_LIBGIF and HAVE_LIBEXIF defaults back to 1 - unload several varibales onto config.mk - make version all-caps - add -O2 optimization - use CPPFLAGS for includes and defines * Revert "follow suckless style build system" This reverts commit 8bf75b1f68d72df349edba8d998d4659dd956dd8. * Generate config.mk from make * Inlined configure in Makefile * update docs * cleanups - changes to config.mk should trigger a rebuild - remove potentially confusing variables form Makefile * Use install instead of mkdir/cp/chmod when sensible * fixup! Inlined configure in Makefile * Don't generate config.mk on rm -f *.o sxiv * update docs and cleanups - make config.mk silent - mention editing config.mk in README * fallback to 0 if user edits config.mk in unexpected way * add comment on config.mk * remove invalid comment configure script is removed * slight restructure - make version all caps - restructure variables that users may want to edit to top - use CPPFLAGS for defines - add some comments - remove needless echos since we have verbose output now * add echos back Co-authored-by: NRK <nrk@disroot.org> Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-09-16fix: out-of-bounds access when bg not in color mapwhowillbellthecat
2021-09-16change gamma on -GNRK
Closes: https://github.com/nsxiv/nsxiv/issues/30
2021-09-16Custom bar colors (#10)Guilherme Freire
* set bar and text colors independently * change xresources to Program.class.resource * rename color variables to win/bar_bg/fg * change default bar colors to match window colors
2021-09-16Fix in tabbed with alpha patch (#3)Berke Kocaoğlu
* Fix in tabbed with alpha patch Co-authored-by: Jared Forrest <jared_forrest@mailbox.org>
2021-09-16Implement fill scale modeBerke Kocaoğlu
2019-07-16Use normal win colors in fullscreen modeBert Münnich
Fixes issues #361 and #367