This file is indexed.

/usr/share/perl5/Games/PangZero/Graphics.pm is in pangzero 1.4-1.

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
package Games::PangZero::Graphics;

use strict;
use warnings;

use SDL;
use SDL::Surface;
use SDL::Palette;
use SDL::PixelFormat;
use SDL::Video;
use SDL::Event;
use SDL::Events;
use SDL::Color;
use SDL::Config;
use SDL::Cursor;
use SDL::GFX::Rotozoom;
use SDL::Mixer;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
use SDL::Mixer::Music;
use SDL::Mixer::MixChunk;
use SDL::Mixer::MixMusic;
use SDL::Joystick;
use SDL::Mouse;
use SDL::Image;
use SDLx::App;
use SDLx::SFont;

sub LoadSurfaces {
  my ($i, $transparentColor);

  my %balls = qw (
  ball0 Balls-Red128.png ball1 Balls-Red96.png ball2 Balls-Red64.png ball3 Balls-Red32.png ball4 Balls-Red16.png
  xmas Balls-XMAS128.png
  ball4 Balls-Red16.png ball3 Balls-Red32.png
  bouncy2 Balls-Bouncy64.png bouncy3 Balls-Bouncy32.png bouncy4 Balls-Bouncy16.png
  hexa0 Hexa-64.png hexa1 Hexa-32.png hexa2 Hexa-16.png
  blue1 Balls-Water96.png blue2 Balls-Water64.png blue3 Balls-Water32.png blue4 Balls-Water16.png
  frag0 Balls-Fragile128.png frag1 Balls-Fragile96.png frag2 Balls-Fragile64.png frag3 Balls-Fragile32.png frag4 Balls-Fragile16.png
  green1 Balls-SuperClock96.png green2 Balls-SuperClock64.png gold1 Balls-SuperStar96.png gold2 Balls-SuperStar64.png
  death2 Balls-Death64.png
  white2 Balls-Seeker64.png white3 Balls-Seeker32.png
  quake2 Balls-EarthQ64.png quake3 Balls-EarthQ32.png quake4 Balls-EarthQ16.png
  upside0 Balls-Upside128.png upside1 Balls-Upside96.png upside2 Balls-Upside64.png upside3 Balls-Upside32.png upside4 Balls-Upside16.png
  );

  foreach (sort keys %balls) {
    $Games::PangZero::BallSurfaces{$_} = SDL::Image::load("$Games::PangZero::DataDir/$balls{$_}");
    $Games::PangZero::BallSurfaces{$_} = SDL::Video::display_format($Games::PangZero::BallSurfaces{$_});
    $transparentColor = $Games::PangZero::BallSurfaces{$_}->get_pixel(0);
    SDL::Video::set_color_key($Games::PangZero::BallSurfaces{$_}, SDL_SRCCOLORKEY, $transparentColor );
    $Games::PangZero::BallSurfaces{"dark$_"} = SDL::Image::load( "$Games::PangZero::DataDir/$balls{$_}");
    $Games::PangZero::BallSurfaces{"dark$_"} = SDL::Video::display_format($Games::PangZero::BallSurfaces{"dark$_"});
    SDL::Video::set_color_key($Games::PangZero::BallSurfaces{"dark$_"}, SDL_SRCCOLORKEY, $Games::PangZero::BallSurfaces{"dark$_"}->get_pixel(0) );
    SDL::Video::set_alpha($Games::PangZero::BallSurfaces{"dark$_"}, SDL_SRCALPHA, 128);
  }

  $Games::PangZero::BorderSurface          = SDL::Image::load("$Games::PangZero::DataDir/border.png");
  $Games::PangZero::RedBorderSurface       = SDL::Image::load("$Games::PangZero::DataDir/border.png");
  $Games::PangZero::WhiteBorderSurface     = SDL::Image::load("$Games::PangZero::DataDir/border.png");
  $Games::PangZero::BonusSurface           = SDL::Image::load("$Games::PangZero::DataDir/bonus.png");
  $Games::PangZero::LevelIndicatorSurface  = SDL::Image::load("$Games::PangZero::DataDir/level.png");
  $Games::PangZero::LevelIndicatorSurface2 = SDL::Image::load("$Games::PangZero::DataDir/level_empty.png");

  AlterPalette( $Games::PangZero::RedBorderSurface, sub { 1; },
    sub { shift @_; my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_);
    return Games::PangZero::Palette::HsiToRgb( $h - 30, $s, $i * 0.75 + 63); } );
  AlterPalette( $Games::PangZero::WhiteBorderSurface, sub { 1; },
    sub { shift @_; my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_);
    return Games::PangZero::Palette::HsiToRgb( 0, 0, $i*0.25 + 191 ); } );

  MakeGuySurfaces();
}

sub MakeGuySurface {
  my ($player) = @_;
  my ($guySurfaceFile, $guySurface, $whiteGuySurface, $harpoonSurface);

  $guySurfaceFile       = $Games::PangZero::DataDir . '/' . $Games::PangZero::GuyImageFiles[ $player->{imagefileindex} % scalar(@Games::PangZero::GuyImageFiles) ];
  $guySurface           = SDL::Image::load($guySurfaceFile);
  $whiteGuySurface      = SDL::Image::load($guySurfaceFile);
  $harpoonSurface       = SDL::Image::load("$Games::PangZero::DataDir/harpoon.png");
  $player->{hue}        = $Games::PangZero::GuyColors[$player->{colorindex}]->[0];
  $player->{saturation} = $Games::PangZero::GuyColors[$player->{colorindex}]->[1];

  AlterPalette($whiteGuySurface, sub {1;}, sub { return (255, 255, 255); } );
  AlterPalette( $guySurface, sub { $_[3] > $_[2] and $_[3] > $_[1]; },
    sub {
      shift @_;
      my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_);
      return Games::PangZero::Palette::HsiToRgb($player->{hue}, $player->{saturation}, $i); }
  );
  AlterPalette( $harpoonSurface, sub { 1; },
    sub {
      shift @_;
      my ($h, $s, $i) = Games::PangZero::Palette::RgbToHsi(@_);
      return Games::PangZero::Palette::HsiToRgb($player->{hue}, $player->{saturation} * $s / 256, $i); }
  );
  $player->{guySurface}      = $guySurface;
  $player->{whiteGuySurface} = $whiteGuySurface;
  $player->{harpoonSurface}  = $harpoonSurface;
}

sub MakeGuySurfaces {
  foreach my $player (@Games::PangZero::Players) {
    MakeGuySurface($player);
  }

  $Games::PangZero::WhiteHarpoonSurface = SDL::Image::load("$Games::PangZero::DataDir/harpoon.png");
  AlterPalette($Games::PangZero::WhiteHarpoonSurface, sub {1;}, sub { return (255, 255, 255); } );
}

sub AlterPalette {
  my ($surface, $filterSub, $alterSub) = @_;
  my ($r, $g, $b);
  my ($palette, $numColors, $n, $color);

  $palette   = $surface->format->palette();
  $numColors = ($surface->format->BytesPerPixel == 1) ? $palette->ncolors() : -1;
  for ($n = 0; $n < $numColors; $n++) {
    $color       = $palette->color_index($n);
    ($r, $g, $b) = ( $color->r, $color->g, $color->b );

    next unless $filterSub->($n, $r, $g, $b);
    ($r, $g, $b) = $alterSub->($n, $r, $g, $b);
    $r = $g = $b = 4 if ($r == 0 and $g == 0 and $b == 0);

    $color->r($r);
    $color->g($g);
    $color->b($b);
    SDL::Video::set_colors($surface, $n, $color);
  }
  $surface = SDL::Video::display_format($surface);
}

sub RenderBorder {
  my ($borderSurface, $targetSurface) = @_;
  my ($dstrect, $srcrect1, $srcrect2, $xpos, $ypos, $width, $height);

  $width  = $Games::PangZero::ScreenWidth  + 2 * $Games::PangZero::ScreenMargin;
  $height = $Games::PangZero::ScreenHeight + 2 * $Games::PangZero::ScreenMargin;

  # Draw the corners
  $dstrect  = SDL::Rect->new(0, 0, 16, 16);
  $srcrect1 = SDL::Rect->new(0, 0, 16, 16);
  SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect);
  $dstrect->x($width - 16); $srcrect1->x(144);
  SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect);
  $dstrect->y($height - 16); $srcrect1->y(144);
  SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect);
  $dstrect->x(0); $srcrect1->x(0);
  SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect);

  if(SDL::Config->has('SDL_gfx_rotozoom')) {
    # Top border
    my $zoom = SDL::Surface->new(SDL_SWSURFACE(), 128, 16, 32);
    $srcrect1->x(16); $srcrect1->y(0); $srcrect1->w(128); $srcrect1->h(16);
    SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) );
    $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, $Games::PangZero::ScreenWidth / 128, 1, SDL::GFX::Rotozoom::SMOOTHING_OFF());
    $dstrect->x(16); $dstrect->y(0);
    SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect );

    # Left border
    $zoom = SDL::Surface->new(SDL_SWSURFACE(), 16, 128, 32);
    $srcrect1->x(0); $srcrect1->y(16); $srcrect1->h(128); $srcrect1->w(16);
    SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) );
    $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, 1, $Games::PangZero::ScreenHeight / 128, SDL::GFX::Rotozoom::SMOOTHING_OFF());
    $dstrect->x(0); $dstrect->y(16);
    SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect );
  }

  # Draw top and bottom border

  $srcrect1->w(128); $srcrect1->x(16); $srcrect1->y(0);
  $srcrect2 = SDL::Rect->new( 16, 144, 128, 16 );
  for ($xpos = 16; $xpos < $width-16; ) {
    $dstrect->x($xpos);
    $dstrect->y(0);
    SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect);
    $dstrect->y($height - 16);
    SDL::Video::blit_surface($borderSurface, $srcrect2, $targetSurface, $dstrect);
    $xpos += $srcrect1->w();
    $srcrect1->w(16); $srcrect1->x(128);
    $srcrect2->w(16); $srcrect2->x(128);
  }

  # Draw left and right border

  $srcrect1->h(128); $srcrect1->y(16); $srcrect1->x(0);
  $srcrect2->h(128); $srcrect2->y(16); $srcrect2->x(144);
  for ($ypos = 16; $ypos < $height-16; ) {
    $dstrect->x(0);
    $dstrect->y($ypos);
    SDL::Video::blit_surface($borderSurface, $srcrect1, $targetSurface, $dstrect);
    $dstrect->x($width - 16);
    SDL::Video::blit_surface($borderSurface, $srcrect2, $targetSurface, $dstrect);
    $ypos += $srcrect1->h();
    $srcrect1->h(16); $srcrect1->y(128);
    $srcrect2->h(16); $srcrect2->y(128);
  }

  if(SDL::Config->has('SDL_gfx_rotozoom')) {
    # Top border
    my $zoom = SDL::Surface->new(SDL::Video::SDL_SWSURFACE(), 128, 16, 32);
    $srcrect1->x(16); $srcrect1->y(0); $srcrect1->w(128); $srcrect1->h(16);
    SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) );
    $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, $Games::PangZero::ScreenWidth / 128, 1, SDL::GFX::Rotozoom::SMOOTHING_OFF());
    $dstrect->x(16); $dstrect->y(0);
    SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect );

    # Left border
    $zoom = SDL::Surface->new( SDL_SWSURFACE(), 16, 128, 32);
    $srcrect1->x(0); $srcrect1->y(16); $srcrect1->h(128); $srcrect1->w(16);
    SDL::Video::blit_surface($borderSurface, $srcrect1, $zoom, SDL::Rect->new(0, 0, $srcrect1->w, $srcrect1->h) );
    $zoom = SDL::GFX::Rotozoom::zoom_surface($zoom, 1, $Games::PangZero::ScreenHeight / 128, SDL::GFX::Rotozoom::SMOOTHING_OFF());
    $dstrect->x(0); $dstrect->y(16);
    SDL::Video::blit_surface($zoom, SDL::Rect->new(0, 0, $zoom->w, $zoom->h), $targetSurface, $dstrect );
  }
}

sub LoadBackground {
  my $filename = shift;

  SDL::Video::fill_rect($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::PhysicalScreenWidth, $Games::PangZero::PhysicalScreenHeight), SDL::Color->new(0, 0, 0) );
  my $backgroundImage = SDL::Image::load("$Games::PangZero::DataDir/$filename");
  my $dstrect         = SDL::Rect->new($Games::PangZero::ScreenMargin, $Games::PangZero::ScreenMargin, 0, 0);
  my $srcrect         = SDL::Rect->new(0, 0, $Games::PangZero::ScreenWidth, $Games::PangZero::ScreenHeight);
  if ($Games::PangZero::ScreenWidth != $backgroundImage->w() or $Games::PangZero::ScreenHeight != $backgroundImage->h()) {
    if (SDL::Config->has('SDL_gfx_rotozoom')) {
      my $zoomX        = $Games::PangZero::ScreenWidth  / $backgroundImage->w(); # $zoomX = 1.0 if $zoomX < 1.0;
      my $zoomY        = $Games::PangZero::ScreenHeight / $backgroundImage->h(); # $zoomY = 1.0 if $zoomY < 1.0;
      $backgroundImage = SDL::GFX::Rotozoom::zoom_surface($backgroundImage, $zoomX, $zoomY, SDL::GFX::Rotozoom::SMOOTHING_OFF());
    }
  }
  SDL::Video::blit_surface($backgroundImage, $srcrect, $Games::PangZero::Background, $dstrect);

  RenderBorder($Games::PangZero::BorderSurface, $Games::PangZero::Background);
}

sub TextWidth {
  SDLx::SFont::SDL_TEXTWIDTH(@_); # perl-sdl-2.x
}

sub FindVideoMode {
  if ($Games::PangZero::FullScreen < 2) {
    return (800, 600);
  }

  # Find a suitable widescreen mode
  # One native resolution:   1680 x 1050 => 1.6  : 1
  # Which could translate to: 840 x 525  => 1.6  : 1
  # Some adapters have:       848 x 480  => 1.76 : 1
  #                           720 x 480  => 1.5  : 1
  #                           800 x 512  => 1.56 : 1
  # Conclusion: Any resolution where w in [800,900], h > 480 and r in [1.5, 1.8] is good

  my ($modes, $mode, @goodModes, $w, $h, $ratio);
  $modes = SDL::ListModes( 0, SDL_HWSURFACE ); #add back fullscreen
  foreach $mode (@{$modes}) {
    $w     = $mode->w;
    $h     = $mode->h;
    $ratio = $w / $h;
    warn sprintf( "%4d x %4d => %0.3f\n", $w, $h, $ratio );
    next if $w < 800 or $w > 900;
    next if $h < 480;
    next if $ratio < 1.5 or $ratio > 1.8;
    push @goodModes, ( { -w => $w, -h => $h, -score => abs($ratio - 1.6) * 1000 + abs($w - 800) } );
  }
  @goodModes = sort { $a->{-score} <=> $b->{-score} } @goodModes;
  return (800, 600) unless @goodModes;
  foreach $mode (@goodModes) {
    print sprintf( '%d x %d => %0.3f (score %d)', $mode->{-w}, $mode->{-h}, $mode->{-w} / $mode->{-h}, $mode->{-score} ), "\n";
  }
  return ($goodModes[0]->{-w}, $goodModes[0]->{-h});
}

1;