#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::PNG; use Time::HiRes 'time'; my $mw = MainWindow::->new(); my @common_raw_rgbs; my $png_image = 'pm_11139959_image.png'; my ($W, $H) = (100, 100); { no warnings 'qw'; @common_raw_rgbs = qw{ #ff0000 #ffff00 #009900 #00ffff #0000ff #ff00ff }; } my @raw_rgbs = (@common_raw_rgbs) x int(1 + ($W * $H / (0+@common_raw_rgbs))); my $t0 = time; my $image = $mw->Photo(-format => 'png', -width => $W, -height => $H); my $i = 0; for my $y (0 .. $H - 1) { for my $x (0 .. $W - 1) { $image->put([$raw_rgbs[$i++]], -to => $x, $y, $x + 1, $y + 1); } } $image->write($png_image); my $t1 = time; $mw->Label(-text => 'Image:')->pack(); $mw->Label(-image => $image)->pack(); $mw->Label(-text => 'Time: ' . sprintf '%.6f', $t1 - $t0)->pack(); MainLoop;