1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # PharosImagePlugin - an ImagePlugin that can also do pharos related tasks.
|
---|
4 | #
|
---|
5 | # A component of the Greenstone digital library software
|
---|
6 | # from the New Zealand Digital Library Project at the
|
---|
7 | # University of Waikato, New Zealand.
|
---|
8 | #
|
---|
9 | # Copyright (C) 2008 New Zealand Digital Library Project
|
---|
10 | #
|
---|
11 | # This program is free software; you can redistribute it and/or modify
|
---|
12 | # it under the terms of the GNU General Public License as published by
|
---|
13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
14 | # (at your option) any later version.
|
---|
15 | #
|
---|
16 | # This program is distributed in the hope that it will be useful,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | # GNU General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU General Public License
|
---|
22 | # along with this program; if not, write to the Free Software
|
---|
23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | #
|
---|
25 | ###########################################################################
|
---|
26 | package PharosImagePlugin;
|
---|
27 |
|
---|
28 | use ImagePlugin;
|
---|
29 | use PharosImageIndexer;
|
---|
30 |
|
---|
31 | use strict;
|
---|
32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
33 |
|
---|
34 | use gsprintf 'gsprintf';
|
---|
35 |
|
---|
36 | BEGIN {
|
---|
37 | @PharosImagePlugin::ISA = ('ImagePlugin', 'PharosImageIndexer');
|
---|
38 | }
|
---|
39 |
|
---|
40 | my $index_on_list =
|
---|
41 | [ { 'name' => "original",
|
---|
42 | 'desc' => "the original full sized file (will convert to jpg if necessary)" },
|
---|
43 | { 'name' => "screenview",
|
---|
44 | 'desc' => "The screenview sized image (jpg screenview images will be created)" },
|
---|
45 | { 'name' => "thumbnail",
|
---|
46 | 'desc' => "The thumbnail image (jpg thumbnails will be created)" } ];
|
---|
47 |
|
---|
48 |
|
---|
49 | my $arguments = [
|
---|
50 | { 'name' => "disable_pharos_imageis",
|
---|
51 | 'desc' => "Switch off the image similarity indexing",
|
---|
52 | 'type' => "flag",
|
---|
53 | 'reqd' => "no" },
|
---|
54 | { 'name' => "pharos_imageis_index",
|
---|
55 | 'desc' => "Which size image files to index",
|
---|
56 | 'type' => "enum",
|
---|
57 | 'deft' => "thumbnail",
|
---|
58 | 'list' => $index_on_list,
|
---|
59 | 'reqd' => "no"}
|
---|
60 | ];
|
---|
61 |
|
---|
62 | my $options = { 'name' => "PharosImagePlugin",
|
---|
63 | 'desc' => "Image Plugin that also does Pharos Image Similarity Indexing",
|
---|
64 | 'abstract' => "no",
|
---|
65 | 'inherits' => "yes",
|
---|
66 | 'args' => $arguments };
|
---|
67 |
|
---|
68 | sub new {
|
---|
69 | my ($class) = shift (@_);
|
---|
70 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
71 | push(@$pluginlist, $class);
|
---|
72 |
|
---|
73 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
74 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
75 |
|
---|
76 | new PharosImageIndexer($pluginlist, $inputargs, $hashArgOptLists);
|
---|
77 | my $self = new ImagePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
78 |
|
---|
79 | if ($self->{'disable_pharos_imageis'}) {
|
---|
80 | # pharos disabled, don't care about args
|
---|
81 | return bless $self, $class;
|
---|
82 | }
|
---|
83 |
|
---|
84 | # we want imageconverter to store the paths to thumbnails etc so we can use them later.
|
---|
85 | $self->{'store_file_paths'} = 1;
|
---|
86 | # check args
|
---|
87 | if ($self->{'pharos_imageis_index'} eq "thumbnail") {
|
---|
88 | # thumbnails
|
---|
89 | if ($self->{'create_thumbnail'} eq "false") {
|
---|
90 | print STDERR "Pharos Indexing set to index thumbnails, switching on -create_thumbnail\n";
|
---|
91 | $self->{'create_thumbnail'} = "true";
|
---|
92 | }
|
---|
93 | if ($self->{'thumbnailtype'} !~ /^jpe?g$/i) {
|
---|
94 | print STDERR "Pharos Indexing set to index thumbnails, setting thumbnailtype to jpg\n";
|
---|
95 | $self->{'thumbnailtype'} = "jpg";
|
---|
96 | }
|
---|
97 | } elsif ($self->{'pharos_imageis_index'} eq "screenview") {
|
---|
98 | # screenview
|
---|
99 | if ($self->{'create_screenview'} eq "false") {
|
---|
100 | print STDERR "Pharos Indexing set to index screenview, switching on -create_screenview\n";
|
---|
101 | $self->{'create_screenview'} = "true";
|
---|
102 | }
|
---|
103 | if ($self->{'screenviewtype'} !~ /^jpe?g$/i) {
|
---|
104 | print STDERR "Pharos Indexing set to index screenview, setting screenviewtype to jpg\n";
|
---|
105 | $self->{'screenviewtype'} = "jpg";
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | } else {
|
---|
110 | # originals
|
---|
111 | if (!$self->{'converttotype'} || $self->{'converttotype'}!~ /^jpe?g$/i) {
|
---|
112 | print STDERR "Pharos Indexing set to index original images, setting -converttotype to jpg\n";
|
---|
113 | $self->{'converttotype'} = "jpg";
|
---|
114 | }
|
---|
115 |
|
---|
116 | }
|
---|
117 | return bless $self, $class;
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | # needs to be called after BasePlugin init, so that outhandle is set up.
|
---|
122 | sub init {
|
---|
123 | my $self = shift(@_);
|
---|
124 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
125 |
|
---|
126 | $self->SUPER::init(@_);
|
---|
127 | $self->PharosImageIndexer::init() unless $self->{'disable_pharos_imageis'};
|
---|
128 |
|
---|
129 | if (!$self->{'pharos_available'}) {
|
---|
130 | $self->{'disable_pharos_imageis'} = 1; # set this to one so we don't call the functions all the time and get lots of warnings
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | sub remove_all {
|
---|
135 | my $self = shift (@_);
|
---|
136 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
137 |
|
---|
138 | $self->SUPER::remove_all(@_);
|
---|
139 | $self->PharosImageIndexer::remove_all(@_) unless $self->{'disable_pharos_imageis'};
|
---|
140 |
|
---|
141 | }
|
---|
142 |
|
---|
143 | sub remove_one {
|
---|
144 | my $self = shift (@_);
|
---|
145 | my ($file, $oids, $archivedir) = @_;
|
---|
146 | return undef if (!$self->can_process_this_file($file));
|
---|
147 |
|
---|
148 | $self->PharosImageIndexer::remove_one(@_) unless $self->{'disable_pharos_imageis'};
|
---|
149 | return $self->SUPER::remove_one(@_);
|
---|
150 |
|
---|
151 |
|
---|
152 | }
|
---|
153 |
|
---|
154 | sub post_process_doc_obj {
|
---|
155 | my $self = shift (@_);
|
---|
156 | # options??
|
---|
157 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
158 | return if $self->{'disable_pharos_imageis'};
|
---|
159 | if ($self->{'pharos_imageis_index'} eq "thumbnail" && -e $self->{'thumb_file'} ) {
|
---|
160 | print STDERR "indexing thumbnail $self->{'thumb_file'}\n";
|
---|
161 | $self->pharos_index_image($self->{'thumb_file'}, $doc_obj);
|
---|
162 | } elsif ($self->{'pharos_imageis_index'} eq "screenview" && -e $self->{'screen_file'}) {
|
---|
163 | print STDERR "indexing screenview $self->{'screen_file'}\n";
|
---|
164 | $self->pharos_index_image($self->{'screen_file'}, $doc_obj);
|
---|
165 | }
|
---|
166 | elsif (defined $self->{'orig_file'} && -e $self->{'orig_file'}) {
|
---|
167 | print STDERR "indexing converted original $self->{'orig_file'}\n";
|
---|
168 | $self->pharos_index_image($self->{'orig_file'}, $doc_obj);
|
---|
169 | }
|
---|
170 | else {
|
---|
171 | # fall back option, index the original
|
---|
172 | print STDERR "indexing original &util::filename_cat($base_dir, $file)\n";
|
---|
173 | $self->pharos_index_image(&util::filename_cat($base_dir, $file), $doc_obj);
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 |
|
---|
179 | 1;
|
---|