ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/CV/lib/Gtk2/CV.pm
Revision: 1.50
Committed: Mon Apr 29 13:11:27 2019 UTC (7 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-1_8
Changes since 1.49: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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