ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/lib/Gtk2/CV.pm
Revision: 1.54
Committed: Fri Aug 26 21:58:02 2022 UTC (21 months ago) by root
Branch: MAIN
CVS Tags: rel-2_0, HEAD
Changes since 1.53: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package Gtk2::CV;
2
3 use common::sense;
4 use Gtk2;
5 use Glib;
6
7 use IO::AIO;
8
9 BEGIN {
10 use XSLoader;
11
12 our $VERSION = '2.0';
13
14 XSLoader::load "Gtk2::CV", $VERSION;
15 }
16
17 magic_buffer ""; # preload magic tables
18
19 our $MPV = $ENV{CV_MPV} || $ENV{CV_MPLAYER} || "mpv";
20
21 our $FAST_TMP = -w "/run/shm" ? "/run/shm"
22 : -w "/dev/shm" ? "/dev/shm"
23 : "/tmp";
24
25 my $aio_source;
26
27 IO::AIO::min_parallel 32;
28 IO::AIO::max_poll_reqs 2;
29
30 # we use a low priority watcher to give GUI interactions as high a priority
31 # as possible.
32 sub enable_aio {
33 $aio_source ||=
34 add_watch Glib::IO IO::AIO::poll_fileno,
35 in => sub {
36 IO::AIO::poll_cb;
37 1
38 },
39 undef,
40 &Glib::G_PRIORITY_LOW;
41 }
42
43 sub disable_aio {
44 remove Glib::Source $aio_source if $aio_source;
45 undef $aio_source;
46 }
47
48 sub flush_aio {
49 enable_aio;
50 IO::AIO::flush;
51 }
52
53 enable_aio;
54
55 sub find_rcfile($) {
56 my $path;
57
58 for (@INC) {
59 $path = "$_/Gtk2/CV/$_[0]";
60 return $path if -r $path;
61 }
62
63 die "FATAL: can't find required file $_[0]\n";
64 }
65
66 sub require_image($) {
67 new_from_file Gtk2::Gdk::Pixbuf find_rcfile "images/$_[0]";
68 }
69
70 sub dealpha_compose($) {
71 return $_[0] unless $_[0]->get_has_alpha;
72
73 Gtk2::CV::dealpha_expose $_[0]->composite_color_simple (
74 $_[0]->get_width, $_[0]->get_height,
75 'nearest', 255, 16, 0xffc0c0c0, 0xff606060,
76 )
77 }
78
79 # TODO: make preferences
80 sub dealpha($) {
81 &dealpha_compose
82 }
83
84 sub load_webp($;$$$) {
85 my ($path, $thumbnail, $iw, $ih) = @_;
86
87 open my $fh, "<:raw", $path
88 or die "$path: $!\n";
89 IO::AIO::mmap my $data, -s $fh, IO::AIO::PROT_READ, IO::AIO::MAP_SHARED, $fh
90 or die "$path: $!\n";
91 decode_webp $data, $thumbnail, $iw, $ih
92 }
93
94 sub load_jxl($;$$$) {
95 my ($path, $thumbnail, $iw, $ih) = @_;
96
97 open my $fh, "<:raw", $path
98 or die "$path: $!\n";
99 IO::AIO::mmap my $data, -s $fh, IO::AIO::PROT_READ, IO::AIO::MAP_SHARED, $fh
100 or die "$path: $!\n";
101 decode_jxl $data, $thumbnail, $iw, $ih
102 }
103
104 sub load_jpeg($;$$$) {
105 my ($path, $thumbnail, $iw, $ih) = @_;
106
107 open my $fh, "<:raw", $path
108 or die "$path: $!\n";
109 IO::AIO::mmap my $data, -s $fh, IO::AIO::PROT_READ, IO::AIO::MAP_SHARED, $fh
110 or die "$path: $!\n";
111 decode_jpeg $data, $thumbnail, $iw, $ih
112 }
113
114 1;
115