/usr/lib/x86_64-linux-gnu/perl5/5.22/Prima/ImageDialog.pm is in libprima-perl 1.28-1.4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | #
# Copyright (c) 1997-2002 The Protein Laboratory, University of Copenhagen
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Created by Dmitry Karasik <dk@plab.ku.dk>
# $Id: ImageDialog.pm,v 1.18 2008/04/05 18:59:39 dk Exp $
#
package Prima::ImageDialog;
use strict;
use Prima;
use Prima::ImageViewer;
use Prima::ComboBox;
use Prima::Label;
use Prima::FileDialog;
sub filtered_codecs
{
my $codecs = defined($_[0]) ? $_[0] : Prima::Image-> codecs;
return map {
my $n = uc $_-> {fileExtensions}->[0];
my $x = join( ';', map {"*.$_"} @{$_-> {fileExtensions}});
[ "$n - $_->{fileType}" => $x ]
} sort {
$a-> {fileExtensions}->[0] cmp $b-> {fileExtensions}->[0]
} @$codecs;
}
sub filtered_codecs2all
{
my $codecs = defined($_[0]) ? $_[0] : Prima::Image-> codecs;
return join(';', map {"*.$_"} map { @{$_-> {fileExtensions}}} @$codecs)
}
package Prima::ImageOpenDialog;
use vars qw( @ISA);
@ISA = qw( Prima::OpenDialog);
{
my %RNT = (
%{Prima::Dialog-> notification_types()},
HeaderReady => nt::Default,
DataReady => nt::Default,
);
sub notification_types { return \%RNT; }
}
sub profile_default {
my $codecs = [ grep { $_-> {canLoad} } @{Prima::Image-> codecs}];
return {
%{$_[ 0]-> SUPER::profile_default},
preview => 1,
sizeMin => [380,400],
text => 'Open image',
filter => [
['Images' => Prima::ImageDialog::filtered_codecs2all( $codecs)],
['All files' => '*'],
Prima::ImageDialog::filtered_codecs($codecs),
],
}
}
sub init
{
my $self = shift;
$self-> {preview} = 0;
my %profile = $self-> SUPER::init(@_);
my $pk = $self-> insert( ImageViewer =>
origin => [ 524, 120],
name => 'PickHole',
borderWidth=> 1,
alignment => ta::Center,
valignment => ta::Center,
growMode => gm::GrowLoX | gm::GrowLoY,
hScroll => 0,
vScroll => 0,
zoomPrecision => 1000,
);
$pk-> size(($self-> Cancel-> width) x 2); # force square dimension
$self-> insert( ScrollBar =>
origin => [ $pk-> left, $pk-> top + 2],
width => $pk-> width,
selectable => 1,
tabStop => 1,
name => 'FrameSelector',
designScale => undef,
visible => 0,
value => 0,
delegations => ['Change'],
growMode => gm::GrowLoX | gm::GrowLoY,
);
$self-> {Preview} = $self-> insert( CheckBox =>
origin => [ 524, 80],
text => '~Preview',
size => [ 96, 36],
name => 'Preview',
delegations => [qw(Click)],
growMode => gm::GrowLoX | gm::GrowLoY,
);
$self-> insert( Label =>
origin => [ 524, 5],
size => [ 96, 76],
name => 'Info',
text => '',
alignment => ta::Center,
valignment => ta::Top,
wordWrap => 1,
growMode => gm::GrowLoX | gm::GrowHiY,
);
$self-> preview( $profile{preview});
$self-> {frameIndex} = 0;
return %profile;
}
sub update_preview
{
my $self = $_[0];
my $i = $self-> PickHole;
my $j = $self-> Info;
my $s = $self-> FrameSelector;
$i-> image( undef);
$j-> text('');
$s-> hide unless $s-> {block};
$self-> {frameIndex} = 0;
return unless $self-> preview;
my $x = $self-> Files;
$x = $x-> get_items( $x-> focusedItem);
$i-> image( undef);
return unless defined $x;
$x = $self-> directory . $x;
return unless -f $x;
$x = Prima::Icon-> load( $x,
loadExtras => 1,
wantFrames => 1,
iconUnmask => 1,
index => $s-> {block} ? $s-> value : 0,
);
return unless defined $x;
$i-> image( $x);
my @szA = $x-> size;
my @szB = $i-> get_active_area(2);
my $xx = $szB[0]/$szA[0];
my $yy = $szB[1]/$szA[1];
my $codecs = $x-> codecs;
$i-> zoom( $xx < $yy ? $xx : $yy);
my $text = $szA[0].'x'.$szA[1].'x'. ($x-> type & im::BPP) . " bpp ".
$codecs-> [$x-> {extras}-> {codecID}]-> {fileShortType};
$text .= ',grayscale' if $x-> type & im::GrayScale;
if ( $x-> {extras}-> {frames} > 1) {
unless ( $s-> {block}) {
$text .= ",$x->{extras}->{frames} frames";
$s-> {block} = 1;
$s-> set(
visible => 1,
max => $x-> {extras}-> {frames} - 1,
value => 0,
);
$s-> {block} = 0;
} else {
$text .= ",frame ". ($s-> value + 1) . " of $x->{extras}->{frames}";
$self-> {frameIndex} = $s-> value;
}
}
$j-> text( $text);
}
sub preview
{
return $_[0]-> {Preview}-> checked unless $#_;
$_[0]-> {Preview}-> checked( $_[1]);
$_[0]-> update_preview;
}
sub Preview_Click
{
$_[0]-> update_preview;
}
sub Files_SelectItem
{
my ( $self, $lst) = @_;
$self-> SUPER::Files_SelectItem( $lst);
$self-> update_preview if $self-> preview;
}
sub Dir_Change
{
my ( $self, $lst) = @_;
$self-> SUPER::Dir_Change( $lst);
$self-> update_preview if $self-> preview;
}
sub FrameSelector_Change
{
my ( $self, $fs) = @_;
return if $fs-> {block};
my $v = $fs-> value;
$fs-> {block} = 1;
$self-> update_preview;
$fs-> {block} = 0;
}
sub PreviewImage_HeaderReady
{
my ( $self, $image) = @_;
$self-> notify(q(HeaderReady), $image);
}
sub PreviewImage_DataReady
{
my ( $self, $image, $x, $y, $w, $h) = @_;
$self-> notify(q(DataReady), $x, $y, $w, $h);
}
sub load
{
my ( $self, %profile) = @_;
return undef unless defined $self-> execute;
$profile{loadExtras} = 1 unless exists $profile{loadExtras};
$profile{index} = $self-> {frameIndex};
my %im_profile;
if ( $self-> get_notify_sub('HeaderReady') || $self-> get_notify_sub('DataReady')) {
$im_profile{name} = 'PreviewImage';
$im_profile{delegations} = [ $self, qw(HeaderReady DataReady)];
}
my $img = Prima::Image-> new( %im_profile);
my $pv = $profile{progressViewer};
$pv-> watch_load_progress($img) if $pv;
my @r = $img-> load( $self-> fileName, %profile);
$pv-> unwatch_load_progress if $pv;
unless ( defined $r[-1]) {
Prima::MsgBox::message("Error loading " . $self-> fileName . ":$@");
pop @r;
return undef unless scalar @r;
}
return undef, Prima::MsgBox::message( "Empty image") unless scalar @r;
return $r[0] if !wantarray && ( 1 == scalar @r);
return @r;
}
package Prima::ImageSaveDialog;
use vars qw( @ISA);
@ISA = qw( Prima::SaveDialog);
sub profile_default {
my $codecs = [ grep { $_-> {canSave} } @{Prima::Image-> codecs}];
return {
%{$_[ 0]-> SUPER::profile_default},
text => 'Save image',
filter => [ Prima::ImageDialog::filtered_codecs($codecs) ],
image => undef,
filterDialog => 1,
noTestFileCreate => 1,
}
}
sub init
{
my $self = shift;
my %profile = $self-> SUPER::init(@_);
$self-> {ConvertTo} = $self-> insert( ComboBox =>
origin => [ 524, 80],
items => [],
enabled => 0,
name => 'ConvertTo',
style => cs::DropDownList,
size => [ 96, 25],
growMode => gm::GrowLoX,
);
$self-> insert( Label =>
origin => [ 524, 110],
text => '~Convert to:',
size => [ 96, 20],
name => 'ConvertToLabel',
focusLink => $self-> {ConvertTo},
growMode => gm::GrowLoX,
);
$self-> {UseFilter} = $self-> insert( CheckBox =>
origin => [ 524, 20],
text => '~Use filter',
size => [ 96, 36],
name => 'UseFilter',
delegations => [qw(Click)],
growMode => gm::GrowLoX,
);
$self-> {codecFilters} = [];
$self-> {allCodecs} = Prima::Image-> codecs;
$self-> {codecs} = [
sort { $a-> {fileExtensions}->[0] cmp $b-> {fileExtensions}->[0] }
grep { $_-> {canSave}} @{$self-> {allCodecs}}
];
my $codec = $self-> {codecs}-> [$self-> filterIndex];
$self-> image( $profile{image});
$self-> filterDialog( $profile{filterDialog});
$self-> ExtensionsLabel-> text("Sav~e as type ($codec->{fileShortType})");
return %profile;
}
sub on_destroy
{
for ( @{$_[0]-> {codecFilters}}) {
next unless $_;
$_-> destroy;
}
}
sub update_conversion
{
my ( $self, $codec) = @_;
my $i = $self-> {image};
my $x = $self-> {ConvertTo};
my $xl = $self-> ConvertToLabel;
$x-> items([]);
$x-> text('');
$x-> enabled(0);
$xl-> enabled(0);
return unless $i;
my $t = $i-> type;
my @st = @{$codec-> {types}};
return unless @st;
my $max = 0;
my $j = 0;
for ( @st) {
return if $_ == $t;
$max = $j if ( $st[$max] & im::BPP) < ( $_ & im::BPP);
$j++;
}
for ( @st) {
my $x = ( 1 << ( $_ & im::BPP));
$x = '24-bit' if $x == 16777216;
$x .= ' gray' if $_ & im::GrayScale;
$x .= ' colors';
$_ = $x;
}
$x-> items( \@st);
$x-> focusedItem( $max);
$x-> enabled(1);
$xl-> enabled(1);
}
sub Ext_Change
{
my ( $self, $ext) = @_;
$self-> SUPER::Ext_Change( $ext);
my $codec = $self-> {codecs}-> [ $self-> filterIndex];
$self-> ExtensionsLabel-> text("Sav~e as type ($codec->{fileShortType})");
$self-> update_conversion( $codec);
}
sub filterDialog
{
return $_[0]-> {UseFilter}-> checked unless $#_;
$_[0]-> {UseFilter}-> checked( $_[1]);
}
sub image
{
return $_[0]-> {image} unless $#_;
my ( $self, $image) = @_;
$self-> {image} = $image;
if (
$image &&
exists($image-> {extras}) &&
(ref($image-> {extras}) eq 'HASH') &&
defined($image-> {extras}-> {codecID})
) {
my $c = $self-> {allCodecs}-> [$image-> {extras}-> {codecID}];
my $i = 0;
for ( @{$self-> {codecs}}) {
$self-> filterIndex( $i) if $_ == $c;
$i++;
}
$self-> update_conversion( $c);
}
}
sub on_endmodal
{
$_[0]-> image( undef); # just freeing the reference
}
sub save
{
my ( $self, $image, %profile) = @_;
my $ret;
my $dup;
return 0 unless $image;
$dup = $image;
my $extras = $image-> {extras};
$self-> image( $image);
goto EXIT unless defined $self-> execute;
unlink $self-> fileName unless $self-> noTestFileCreate;
$image-> {extras} = { map { $_ => $extras-> {$_} } keys %$extras } ;
my $fi = $self-> filterIndex;
my $codec = $self-> {codecs}-> [ $fi];
# loading filter dialog, if any
if ( $self-> filterDialog) {
unless ( $self-> {codecFilters}-> [ $fi]) {
if (
$image &&
$codec &&
length($codec-> {module}) &&
length( $codec-> {package})
) {
my $x = "use $codec->{module};";
eval $x;
if ($@) {
Prima::MsgBox::message(
"Error invoking $codec->{fileShortType} filter dialog:$@"
);
} else {
$self-> {codecFilters}-> [$fi] =
$codec-> {package}-> save_dialog( $codec);
}
}
}
}
if ( $self-> ConvertTo-> enabled) {
$dup = $image-> dup;
$dup-> type( $codec-> {types}-> [ $self-> ConvertTo-> focusedItem]);
}
# invoking filter dialog
if ( $self-> filterDialog && $self-> {codecFilters}-> [ $fi]) {
my $dlg = $self-> {codecFilters}-> [ $fi];
$dlg-> notify( q(Change), $codec, $dup);
unless ( $dlg-> execute == mb::OK) {
$self-> cancel;
goto EXIT;
}
}
# selecting codec
my $j = 0;
for ( @{$self-> {allCodecs}}) {
$dup-> {extras}-> {codecID} = $j, last if $_ == $codec;
$j++;
}
if ( $dup-> save( $self-> fileName, %profile)) {
$ret = 1;
} else {
Prima::MsgBox::message("Error saving " . $self-> fileName . ":$@");
}
EXIT:
$self-> image( undef);
$image-> {extras} = $extras;
return $ret;
}
1;
__DATA__
=head1 NAME
Prima::ImageDialog - file open and save dialogs.
=head1 DESCRIPTION
The module provides dialogs specially adjusted for image
loading and saving.
=head1 Prima::ImageOpenDialog
Provides a preview feature, allowing the user to view the image file before
loading, and the selection of a frame index for the multi-framed image files.
Instead of C<execute> call, the L<load> method is used to invoke the dialog and
returns the loaded image as a C<Prima::Image> object. The loaded object by
default contains C<{extras}> hash variable set, which contains extra
information returned by the loader. See L<Prima::image-load> for more
information.
=head2 SYNOPSIS
my $dlg = Prima::ImageOpenDialog-> create;
my $img = $dlg-> load;
return unless $img;
print "$_:$img->{extras}->{$_}\n" for sort keys %{$img-> {extras}};
=head2 Proprties
=over
=item preview BOOLEAN
Selects if the preview functionality is active.
The user can switch it on and off interactively.
Default value: 1
=back
=head2 Methods
=over
=item load %PROFILE
Executes the dialog, and, if successful, loads the image file and frame
selected by the user. Returns the loaded image as a C<Prima::Image> object.
PROFILE is a hash, passed to C<Prima::Image::load> method. In particular, it
can be used to disable the default loading of extra information in C<{extras}>
variable, or to specify a non-default loading option. For example,
C<{extras}-E<gt>{className} = 'Prima::Icon'> would return the loaded image as
an icon object. See L<Prima::image-load> for more.
C<load> can report progressive image loading to the caller, and/or to an
instance of C<Prima::ImageViewer>, if desired. If either (or both)
C<onHeaderReady> and C<onDataReady> notifications are specified, these are
called from the respective event handlers of the image being loaded ( see
L<Prima::image-load/"Loading with progress indicator"> for details). If
profile key C<progressViewer> is supplied, its value is treated as a
C<Prima::ImageViewer> instance, and it is used to display image loading
progress. See L<Prima::ImageViewer/watch_load_progress>.
=back
=head2 Events
=over
=item HeaderReady IMAGE
See L<Prima::Image/HeaderReady>.
=item DataReady IMAGE, X, Y, WIDTH, HEIGHT
See L<Prima::Image/DataReady>.
=back
=head1 Prima::ImageSaveDialog
Provides a save dialog where the user can select image format,
the bit depth and other format-specific options. The format-specific
options can be set if a dialog for the file format is provided.
The standard toolkit dialogs reside under in C<Prima::Image> namespace,
in F<Prima/Image> subdirectory. For example, C<Prima::Image::gif> provides
the selection of transparency color, and C<Prima::Image::jpeg> the image
quality control. If the image passed to the L<image> property contains
C<{extras}> variable, the data are read and used as the default values.
In particular, C<{extras}-E<gt>-{codecID}> field, responsible for the
file format, if present, affects the default file format selection.
=head2 SYNOPSIS
my $dlg = Prima::ImageSaveDialog-> create;
return unless $dlg-> save( $image );
print "saved as ", $dlg-> fileName, "\n";
=head2 Properties
=over
=item image IMAGE
Selects the image to be saved. This property is to be used
for the standard invocation of dialog, via C<execute>. It is not
needed when the execution and saving is invoked via L<save> method.
=back
=head2 Methods
=over
=item save IMAGE, %PROFILE
Invokes the dialog, and, if the execution was successful, saves
the IMAGE according to the user selection and PROFILE hash.
PROFILE is not used for the default options, but is passed
directly to C<Prima::Image::save> call, possibly overriding
selection of the user.
Returns 1 in case of success, 0 in case of error.
If the error occurs, the user is notified before the method returns.
=back
=head1 AUTHOR
Dmitry Karasik, E<lt>dmitry@karasik.eu.orgE<gt>.
=head1 SEE ALSO
L<Prima>, L<Prima::Window>, L<Prima::codecs>, L<Prima::image-load>,
L<Prima::Image>, L<Prima::FileDialog>, L<Prima::ImageViewer>, F<examples/iv.pl>.
=cut
|