Advertisement
Guest User

Dither ammélioré TO7

a guest
May 1st, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 14.55 KB | None | 0 0
  1. #/bin/perl
  2. # Conversion video en images TO7 avec contraintes:
  3. # 2 couleurs max par bloc de 8 pixels horizontaux.
  4. #
  5. # Samuel DEVULDER, Avril-Mai 2016.
  6. #
  7.  
  8. # parametres
  9. ($W, $H) = (320, 200); # HR
  10. $fps     = 10;
  11. $dither  = "tst2";
  12. $dither  = "vac8";
  13. ($RED,$GRN,$BLU) = (2,4,1);
  14.  
  15. @dither = (
  16. [35, 57, 19, 55,  7, 51,  4, 21],
  17. [29,  6, 41, 27, 37, 17, 59, 45],
  18. [61, 15, 53, 12, 62, 25, 33,  9],
  19. [23, 39, 31, 49,  2, 47, 13, 43],
  20. [ 3, 52,  8, 22, 36, 58, 20, 56],
  21. [38, 18, 60, 46, 30,  5, 42, 28],
  22. [63, 26, 34, 11, 64, 16, 54, 10],
  23. [14, 48,  1, 44, 24, 40, 32, 50]
  24. );
  25.  
  26. # essayer 17*15 -> 256 vals par composantes
  27. @dither = (
  28. [ 224 , 159 ,  49 , 175 ,  18 , 227 ,  97 , 127 , 187 ,  23 , 102 , 169 ,  12 , 137 ,  31 ],
  29. [  89 ,   2 , 235 ,  69 , 131 , 201 ,  28 , 168 ,  79 , 229 , 130 , 212 ,  86 , 239 , 122 ],
  30. [ 217 , 118 , 200 , 100 , 186 ,  56 , 114 , 234 ,  11 , 157 ,  62 ,  30 , 196 ,  50 , 178 ],
  31. [  64 , 149 ,  34 , 162 ,  14 , 253 , 147 ,  66 , 193 ,  96 , 255 , 144 , 104 , 163 ,  21 ],
  32. [ 191 ,  93 , 241 ,  60 , 195 , 107 ,  33 , 211 , 136 ,  45 , 185 ,   3 , 220 ,  75 , 247 ],
  33. [ 135 ,   4 , 205 , 139 ,  87 , 221 , 158 , 101 ,  24 , 223 , 113 ,  59 , 121 , 152 ,  46 ],
  34. [  81 , 173 , 119 ,  29 , 176 ,   1 ,  70 , 242 , 182 ,  76 , 143 , 243 , 180 ,  22 , 198 ],
  35. [ 245 ,  55 , 216 ,  74 , 251 , 125 , 203 ,  40 , 129 ,  13 , 199 ,  36 ,  90 , 226 , 111 ],
  36. [  15 , 148 , 106 , 188 ,  47 ,  94 , 165 ,  78 , 172 , 228 , 103 , 167 , 138 ,  52 , 160 ],
  37. [ 218 ,  44 , 238 ,   8 , 153 , 232 ,  16 , 207 , 109 ,  32 ,  68 , 240 ,   6 , 210 ,  71 ],
  38. [ 181 , 128 ,  85 , 174 , 115 ,  67 , 142 ,  48 , 237 , 154 , 192 , 123 ,  91 , 170 , 112 ],
  39. [  58 , 230 ,  27 , 206 ,  39 , 183 , 222 ,  82 , 134 ,  10 ,  57 , 213 ,  38 , 246 ,  20 ],
  40. [ 197 , 151 , 105 , 141 , 254 ,  99 ,  19 , 202 ,  98 , 249 , 179 , 140 ,  84 , 156 , 120 ],
  41. [  77 ,  41 , 236 ,   7 ,  72 , 133 , 171 ,  42 , 161 ,  65 , 108 ,  17 , 231 ,  53 , 219 ],
  42. [ 146 , 194 ,  92 , 164 , 214 ,  51 , 233 , 110 , 215 ,  26 , 225 , 189 , 126 , 177 ,   5 ],
  43. [ 117 ,  25 , 209 ,  37 , 116 , 190 ,   9 , 145 ,  88 , 166 , 124 ,  73 ,  35 ,  95 , 244 ],
  44. [ 184 ,  80 , 132 , 248 ,  83 , 155 ,  63 , 252 ,  43 , 208 ,  54 , 250 , 150 , 204 ,  61 ]
  45. ) if 0;
  46.  
  47. @dither = (
  48. [  12 ,  14 ,   7 ],
  49. [   9 ,   2 ,   4 ],
  50. [   6 ,  11 ,  15 ],
  51. [  13 ,   8 ,   3 ],
  52. [   1 ,   5 ,  10 ]
  53. ) if 0; # ouais
  54.  
  55. @dither = (
  56. [ 1,7 ,11],
  57. [12, 5,8 ],
  58. [3 ,13, 2],
  59. [14, 6, 9],
  60. [10,15, 4],
  61. ) if 0;
  62.  
  63. @dither = (
  64. [1,4,7],
  65. [5,8,2],
  66. [9,3,6]
  67. ) if 1;
  68.  
  69. @dither = (
  70. [ 1, 8, 4],
  71. [ 7, 6, 3],
  72. [ 5, 2, 9]
  73. ) if 0; #cluster 3x3
  74.  
  75. @dither = (
  76. [   1 , 193 ,  49 , 241 ,  13 , 205 ,  61 , 253 ,   4 , 196 ,  52 , 244 ,  16 , 208 ,  64 , 256 ],
  77. [ 129 ,  65 , 177 , 113 , 141 ,  77 , 189 , 125 , 132 ,  68 , 180 , 116 , 144 ,  80 , 192 , 128 ],
  78. [  33 , 225 ,  17 , 209 ,  45 , 237 ,  29 , 221 ,  36 , 228 ,  20 , 212 ,  48 , 240 ,  32 , 224 ],
  79. [ 161 ,  97 , 145 ,  81 , 173 , 109 , 157 ,  93 , 164 , 100 , 148 ,  84 , 176 , 112 , 160 ,  96 ],
  80. [   9 , 201 ,  57 , 249 ,   5 , 197 ,  53 , 245 ,  12 , 204 ,  60 , 252 ,   8 , 200 ,  56 , 248 ],
  81. [ 137 ,  73 , 185 , 121 , 133 ,  69 , 181 , 117 , 140 ,  76 , 188 , 124 , 136 ,  72 , 184 , 120 ],
  82. [  41 , 233 ,  25 , 217 ,  37 , 229 ,  21 , 213 ,  44 , 236 ,  28 , 220 ,  40 , 232 ,  24 , 216 ],
  83. [ 169 , 105 , 153 ,  89 , 165 , 101 , 149 ,  85 , 172 , 108 , 156 ,  92 , 168 , 104 , 152 ,  88 ],
  84. [   3 , 195 ,  51 , 243 ,  15 , 207 ,  63 , 255 ,   2 , 194 ,  50 , 242 ,  14 , 206 ,  62 , 254 ],
  85. [ 131 ,  67 , 179 , 115 , 143 ,  79 , 191 , 127 , 130 ,  66 , 178 , 114 , 142 ,  78 , 190 , 126 ],
  86. [  35 , 227 ,  19 , 211 ,  47 , 239 ,  31 , 223 ,  34 , 226 ,  18 , 210 ,  46 , 238 ,  30 , 222 ],
  87. [ 163 ,  99 , 147 ,  83 , 175 , 111 , 159 ,  95 , 162 ,  98 , 146 ,  82 , 174 , 110 , 158 ,  94 ],
  88. [  11 , 203 ,  59 , 251 ,   7 , 199 ,  55 , 247 ,  10 , 202 ,  58 , 250 ,   6 , 198 ,  54 , 246 ],
  89. [ 139 ,  75 , 187 , 123 , 135 ,  71 , 183 , 119 , 138 ,  74 , 186 , 122 , 134 ,  70 , 182 , 118 ],
  90. [  43 , 235 ,  27 , 219 ,  39 , 231 ,  23 , 215 ,  42 , 234 ,  26 , 218 ,  38 , 230 ,  22 , 214 ],
  91. [ 171 , 107 , 155 ,  91 , 167 , 103 , 151 ,  87 , 170 , 106 , 154 ,  90 , 166 , 102 , 150 ,  86 ]
  92. ) if 0; # bayer 8x8
  93.  
  94. @dither = (
  95. [ 1, 7,13,19,25,31],
  96. [29,35, 5,11,17,23],
  97. [14,20,26,32, 2, 8],
  98. [ 3, 9,15,21,27,33],
  99. [30,36, 6,12,18,24],
  100. [16,22,28,34, 4,10]
  101. ) if 0;
  102.  
  103. @dither = (
  104. [ 1, 7,13,19,25,31],
  105. [26,32, 2, 8,14,20],
  106. [15,21,27,33, 3, 9],
  107. [ 4,10,16,22,28,34],
  108. [29,35, 5,11,17,23],
  109. [18,24,30,36, 6,12],
  110. ) if 0;
  111.  
  112. @dither = (
  113. [ 7, 13, 11,  4],
  114. [12, 16, 14,  8],
  115. [10, 15,  6,  2],
  116. [ 5,  9,  3,  1]
  117. ) if 1; # TO7
  118.  
  119. @dither = &bayer(@dither);
  120. #   &bayer(&bayer(&bayer(&bayer([1]))));
  121.  
  122. # fichier entree
  123. $file    = $ARGV[0];
  124.  
  125. $out = $file;
  126. $out =~ s/\.[^\.]*$/.gif/;
  127. exit if -e $out;
  128.  
  129. ($x,$y, $aspect_ratio) = (160,100,"16:9");
  130. open(IN, "./ffmpeg -i \"$file\" 2>&1 |");
  131. while(<IN>) {
  132.    if(/, (\d+)x(\d+)/) {
  133.       ($x,$y) = ($1, $2);
  134.       # 4:3
  135.       if(abs($x - 4/3*$y) < abs($x - 16/9*$y)) {
  136.          ($w,$h,$aspect_ratio) = (133,100,"4:3");
  137.       }
  138.    }
  139. }
  140. close(IN);
  141. $h = int(($w=$W)*$y/$x);
  142. $w = int(($h=$H)*$x/$y) if $h>$H;
  143. print $file," : ${x}x${y} ($aspect_ratio) -> ${w}x${h}\n";
  144.  
  145. # dossier temporaire
  146. mkdir "tmp";
  147. open(OUT,"| ./ffmpeg -i - -v 0 -r $fps -s ${w}x${h} -an tmp/img%05d.bmp");
  148. open(IN, "<$file");
  149.  
  150. &init_magick;
  151. $gif = Image::Magick->new(size=>"${w}x${h}");
  152.  
  153. # setup dither
  154. $dy=1+$#dither;
  155. $dx=1+$#{$dither[0]};
  156. for my $y (0..$dy-1) {
  157.     for my $x (0..$dx-1) {
  158.         $dither[$y][$x] /= 1+$dx*$dy;
  159.     }
  160. }  
  161. $cpt = 1; my @c = (0)x8;
  162. binmode(IN);
  163. binmode(OUT);
  164. while(1) {
  165.    $name = sprintf("tmp/img%05d.bmp", $cpt);
  166.    
  167.    $expected_size = $h*(($w*3 + 3)&~3) + 54 if !$expected_size;
  168.    if($expected_size != -s $name) {
  169.       # image pas complete: on continue de nourrir ffmpeg
  170.       my $buf;
  171.       my $read = read(IN,$buf,4096);
  172.       last unless $read;
  173.       syswrite OUT, $buf, $read;
  174.    } else  {
  175.       # image complete!
  176.       print STDERR int($cpt++/$fps),"s\r";
  177.       sleep(5) if ($cpt%1200)==0; # on fait une pause régulière pour ne pas surchauffer le processeur
  178.      
  179.       # lecture de l'image
  180.       my $img = Image::Magick->new();
  181.       $img->Read($name);
  182.       unlink $name;
  183.      
  184.       $img->Set(colorspace=>$LINEAR_SPACE);    
  185.    
  186.       # next if $cpt<293;
  187.      
  188.       # on force la saturation (140%) pour avoir des couleurs plus franches
  189.       #$img->Modulate(saturation=>120);
  190.       #$img->Evaluate(operator=>'Multiply', value=>255/245);
  191.      
  192.       $tmp = Image::Magick->new(size=>"${W}x${H}");
  193.       $tmp->Read("xc:black");
  194.       $tmp->Composite(image=>$img, Operator=>"Over", x=>($W-$w)>>1, y=>($H-$h)>>1);
  195.       undef $img; $img = $tmp;
  196.       my $img2 = $img->Clone();
  197.       $img2->Set(colorspace=>$LINEAR_SPACE eq "RGB" ? "sRGB" : "RGB");
  198.      
  199.       my @px = $img->GetPixels(height=>200, normalize=>"True");
  200.       my @qx = &dither(0,1,@px);
  201.       @px = &dither(1,1,@px);
  202.       $img->OrderedDither("sam,2");
  203.      
  204.       open(PX2IMG,">/tmp/.toto2.pnm");
  205.       print PX2IMG "P6\n320 200\n255\n",pack('C*', @qx),"\n";
  206.       close(PX2IMG);
  207.       $org = Image::Magick->new();
  208.       $org->ReadImage("/tmp/.toto2.pnm");
  209.      
  210.       open(PX2IMG,">/tmp/.toto2.pnm");
  211.       print PX2IMG "P6\n320 200\n255\n",pack('C*', @px),"\n";
  212.       close(PX2IMG);
  213.       $dth = Image::Magick->new();
  214.       $dth->ReadImage("/tmp/.toto2.pnm");
  215.       unlink "/tmp/.toto2.pnm";
  216.      
  217.       $tmp = Image::Magick->new(size=>"641x401");
  218.       $tmp->Read("xc:white");
  219.       $tmp->Composite(image=>$org, Operator=>"Over", x=>0, y=>0);
  220.       $tmp->Composite(image=>$dth, Operator=>"Over", x=>321, y=>0);
  221.       $tmp->Composite(image=>$img, Operator=>"Over", x=>0, y=>201);
  222.       $tmp->Composite(image=>$img2, Operator=>"Over", x=>321, y=>201);
  223.       # $dth->Blur(sigma=>1);
  224.       #$img2->Blur(sigma=>1);
  225.       #$dif = $dth->Compare(image=>$img2, metric=>"rmse");
  226.       # $tmp->Composite(image=>$dth, Operator=>"Over", x=>321, y=>0);
  227.       $img = $tmp;
  228.    
  229.       $img->OrderedDither("o8x8,8");
  230.       $img->Write("toto.png");
  231.      
  232.       # ajout de l'image au gif animé
  233.       $img->Set(dispose=>"None");
  234.       $img->Set(delay=>int(100/$fps));
  235.       push(@$gif, $img);
  236.      
  237.       # pas plus de 3600 imgs (6mins)
  238.       last if $cpt==3600;
  239.    }
  240. }
  241. close(OUT);
  242. unlink(<$ENV{'HOME'}/img*.bmp>);
  243.  
  244. # ecriture du fichier gif
  245. $gif->Set(dispose=>"None");
  246. $gif->Set(Layers=>"optimize-trans");
  247. $gif->Set(delay=>int(100/$fps));
  248. $gif->Write($out);
  249.  
  250.  
  251. sub dither {
  252.     my($withCorrection, $withConstraint, @px) = @_;
  253.     my $i = 0;
  254.     for my $y (0..199) {
  255.         for my $x (0..39) {
  256.             my (@s,@q,%h) = ($i..$i+7); $i+= 8;
  257.             for my $j (@s) {$j*=3;} my $k = $x<<3;
  258.             for my $j (@s) {
  259.                 my $d = $dither[$y%$dy][$k++ %$dx];
  260.                 my $p = ($px[$j]>=$d?2:0) + ($px[$j+1]>=$d?4:0) + ($px[$j+2]>=$d?1:0);
  261.                 push(@q, $p);
  262.                 ++$h{$p};
  263.             }
  264.             my ($c1,$c2);
  265.             my @t = keys %h;
  266.             if($#t==0) {
  267.                 $c1 = $c2 = $t[0];
  268.             } elsif($#t==1) {
  269.                 ($c1, $c2) = (@t);
  270.             } else {
  271.                 @t = keys %cache;%cache = () if $#t>=10000;
  272.                 my $k = join(',', $h{0}, $h{1}, $h{2}, $h{3}, $h{4}, $h{5}, $h{6}, $h{7});
  273.                 my $v = $cache{$k};
  274.                 if(!$v) {
  275.                     ($c1,$c2) = &best_couple(\%h);
  276.                     $cache{$k} = join(',',$c1,$c2);
  277.                 } else {
  278.                     ($c1,$c2) = split(/,/,$v);
  279.                 }
  280.             }
  281.             #print "$k $c1,$c2 $dm : $v\n";
  282.          
  283.             #for my $i (0..7) {print "$i : $col[$i] = $h[$col[$i]]\n";}
  284.             for my $j (@s) {
  285.                 my $q = shift(@q);
  286.                 my $p = $withConstraint ? (($q^$c1)<($q^$c2)?$c1:$c2) : $q;
  287.                 @px[$j..$j+2] = ($p&2?255:0, $p&4?255:0, $p&1?255:0);
  288.                 &diffuse($p, $q, $j, \@px) if $withCorrection && $y<199 && ($p ^= $q);
  289.             }
  290.         }
  291.     }
  292.     return @px;
  293. }
  294.  
  295. sub diffuse {
  296.     # Wolfram-alpha: {x=1/3, a=arcsin(x)+x*sqrt(1-x^2)-2*x^2, b=pi/4-a-x^2, c=a/(a+2*b), d=b/(a+2*b)}
  297.     # --> c = 0.47, b = 0.26
  298.     my($p, $q, $j, $px) = @_;
  299.     # diffusion
  300.     my(@e) = (0,0,0);
  301.     my $e = 0.08; my $f = (1-2*$e)/$e;
  302.     $e[0] = $q&2 ? $e: -$e if $p&2;
  303.     $e[1] = $q&4 ? $e: -$e if $p&4;
  304.     $e[2] = $q&1 ? $e: -$e if $p&1;
  305.     my $r = $j+319*3;
  306.     my $z = $j%960;
  307.     $px->[$r+0] += $e[0] if $z>0;
  308.     $px->[$r+1] += $e[1] if $z>0;
  309.     $px->[$r+2] += $e[2] if $z>0;
  310.     $px->[$r+3] += $e[0]*$f;
  311.     $px->[$r+4] += $e[1]*$f;
  312.     $px->[$r+5] += $e[2]*$f;
  313.     $px->[$r+6] += $e[0] if $z<959;
  314.     $px->[$r+7] += $e[1] if $z<959;
  315.     $px->[$r+8] += $e[2] if $z<959;
  316. }
  317.  
  318. sub best_couple {
  319.     my($h) = @_;
  320.     my $dm = 1000;
  321.     for my $i (0..6) {
  322.         for my $j ($i+1..7) {
  323.             #next if ($i&$j);
  324.             my $d = 0;
  325.             for my $p (keys %$h) {
  326.                 my ($a,$b) = (&dist($p^$i),&dist($p^$j));
  327.                 $d += $h->{$p}*(($a<$b?$a:$b));
  328.                 last if $d>$dm;
  329.             }
  330.             ($dm,$c1,$c2) = ($d,$i,$j) if $d<$dm;
  331.         }
  332.     }
  333.     return ($c1, $c2);
  334. }
  335.  
  336. sub dist {
  337.     my($p) = @_;
  338.     my($r,$g,$b) = (0.299, 0.587, 0.114);
  339.     return ($p&4?$g:0)+($p&2?$r:0)+($p&1?$b:0);
  340. }
  341.  
  342. sub bayer {
  343.     my(@matrix) = @_;
  344.     my $m=$#matrix;
  345.     my $n=$#{$matrix[0]};
  346.     # 0 3
  347.     # 2 1
  348.     my(@m);
  349.     for (0..$m) {
  350.         my $t = [];
  351.         for (0..$n) {push(@$t, 0);}
  352.         push(@m, $t);
  353.     }
  354.    
  355.     for my $j (0..$m) {
  356.         for my $i (0..$n) {
  357.             $m[(1+$m)*0+$j][(1+$n)*0+$i] = 4*$matrix[$j][$i]-3;
  358.             $m[(1+$m)*1+$j][(1+$n)*1+$i] = 4*$matrix[$j][$i]-2;
  359.             $m[(1+$m)*1+$j][(1+$n)*0+$i] = 4*$matrix[$j][$i]-1;
  360.             $m[(1+$m)*0+$j][(1+$n)*1+$i] = 4*$matrix[$j][$i]-0;
  361.         }
  362.     }
  363.     return @m;
  364. }
  365.  
  366. sub init_magick {
  367.    # chargement image-magick la 1ere fois
  368.    my($home) = "tmp";
  369.    $ENV{'HOME'} = $home;
  370.    mkdir($home);
  371.    mkdir("$home/.magick");
  372.    open(THR, ">$home/.magick/thresholds.xml");
  373.    
  374.    my $mx=1+$#dither;
  375.    my $my=1+$#{$dither[0]};
  376.    my $md=$mx*$my+1;
  377.    my $mtx = "<threshold map=\"sam\">\n<description>none</description>\n";
  378.    $mtx .= "<levels width=\"$mx\" height=\"$my\" divisor=\"$md\">\n";
  379.    for my $l (@dither) {for my $x (@$l) {$mtx.=" $x";} $mtx.="\n";}
  380.    $mtx .= " </levels>\n</threshold>\n";  
  381.      
  382.    print THR <<EOF;
  383.       <thresholds>
  384.          $mtx
  385.          <threshold map="2x2">
  386.             <description>2x2 dither matrix</description>
  387.             <levels width="2" height="2" divisor="5">
  388.             1 2
  389.             3 4
  390.             </levels>
  391.          </threshold>
  392.          <threshold map="3x3">
  393.             <description>3x3 dither matrix</description>
  394.             <levels width="3" height="3" divisor="10">
  395.             7 8 2
  396.             6 9 4
  397.             3 5 1
  398.             </levels>
  399.          </threshold>
  400.          <threshold map="5x3">
  401.             <description>5x3 dither matrix</description>
  402.             <levels width="3" height="5" divisor="16">
  403.              3  9  4
  404.              8 14 10  
  405.             13 15 11
  406.              7 12  5
  407.              2  6  1
  408.             </levels>
  409.          </threshold>        
  410.          <threshold map="to7">
  411.             <description>4x4 dither matrix</description>
  412.             <levels width="4" height="4" divisor="17">
  413.              7 13 11  4
  414.             12 16 14  8
  415.             10 15  6  2
  416.              5  9  3  1
  417.             </levels>
  418.          </threshold>        
  419.          <threshold map="tst">
  420.             <description>4x4 dither matrix</description>
  421.             <levels width="4" height="5" divisor="21">
  422. 1 20 13  4
  423. 5 14 16 12
  424. 6 17 19 11
  425. 7 15 18 10
  426. 2  8  9  3
  427.             </levels>
  428.          </threshold>        
  429.  
  430.          <threshold map="tst2">
  431.             <description>4x4 dither matrix</description>
  432.             <levels width="8" height="8" divisor="65">
  433.  1 45 41 13  4 48 44 16
  434. 17 49 61 37 20 52 64 40
  435. 21 53 57 33 24 56 60 36
  436.  5 25 29  9  8 28 32 12
  437.  3 47 43 15  2 46 42 14
  438. 19 51 63 39 18 50 62 38
  439. 23 55 59 35 22 54 58 34
  440.  7 27 31 11  6 26 30 10  
  441.             </levels>
  442.          </threshold>        
  443.  
  444.         <threshold map="vac8">
  445.             <description>void and cluster 65 niveaux</description>
  446.             <levels width="8" height="8" divisor="65">
  447.             35 57 19 55  7 51  4 21
  448.             29  6 41 27 37 17 59 45
  449.             61 15 53 12 62 25 33  9
  450.             23 39 31 49  2 47 13 43
  451.              3 52  8 22 36 58 20 56
  452.             38 18 60 46 30  5 42 28
  453.             63 26 34 11 64 16 54 10
  454.             14 48  1 44 24 40 32 50
  455.             </levels>
  456.          </threshold>
  457.       </thresholds>
  458. EOF
  459.    close(THR);
  460.      
  461.    eval 'use Image::Magick;';
  462.    
  463.    # determination de l'espace RGB lineaire
  464.    my $img = Image::Magick->new(size=>"256x1", depth=>16);
  465.    $img->Read('gradient:black-white');
  466.    $img->Set(colorspace=>'RGB');
  467.    #$img->Set(colorspace=>"Gray") unless $coul;
  468.    my @px1 = $img->GetPixel(x=>128, y=>0);
  469.    $img->Read('gradient:black-white');
  470.    $img->Set(colorspace=>'sRGB');
  471.    #$img->Set(colorspace=>"Gray") unless $coul;
  472.    my @px2 = $img->GetPixel(x=>128, y=>0);
  473.    my $d1 = $px1[0]-0.5; $d1=-$d1 if $d1<0;
  474.    my $d2 = $px2[0]-0.5; $d2=-$d2 if $d2<0;
  475.    $LINEAR_SPACE = $d1>=$d2 ? "RGB" : "sRGB";
  476.    #print $px1[0], "   ",$px2[0],"    $LINEAR_SPACE\n";
  477. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement