This file is indexed.

/usr/share/octave/packages/image-2.2.2/imdither.m is in octave-image 2.2.2-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
## Copyright (C) 2009 Sergey Kirgizov
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img})
## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @
## @var{colors})
## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @
## @var{colors}, @var{dithtype})
## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @
## @var{map})
## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither (@var{img}, @
## @var{map}, @var{colors})
## @deftypefnx {Function File} {[@var{Y}, @var{newmap}] =} imdither(@var{img}, @
## @var{map}, @var{colors}, @var{dithtype})
## Reduce the number a colors of rgb or indexed image.
##
## Note: this requires the ImageMagick "convert" utility.
## get this from www.imagemagick.org if required
## additional documentation of options is available from the
## convert man page.
##
## where
## @var{dithtype} is a value from list:
## 
## @itemize @bullet
## @item "None"
## @item "FloydSteinberg" (default)
## @item "Riemersma"
## @end itemize 
##
## @var{colors} is a maximum number of colors in result map
##
## TODO: Add facility to use already created colormap over "-remap" option
##
## BUGS: This function return a 0-based indexed images 
## when colormap size is lower or equals to 256 like at cmunique code
## @seealso{cmunique}
##
## @end deftypefn

function [Y, newmap] = imdither (im, p1, p2, p3)
  colors="256";
  dithtype="FloydSteinberg";
  if (nargin < 1)
    print_usage;
  endif

  fname = [tmpnam(),".ppm"];
  if (nargin == 1 || isscalar(p1))
                # rgb
    if (nargin >= 2)
      colors=sprintf("%d",p1);
      if (nargin >= 3)
    dithtype=p2;
      endif
    endif
    opts=["-colors ",colors;"-dither ",dithtype];
    imwrite(fname,im(:,:,1),im(:,:,2),im(:,:,3),opts);
    [Y,newmap]=cmunique(imread(fname));
    delete(fname);
  else
    if (nargin <= 1)
      print_usage;
    endif
                # indexed
    if (nargin >= 3)
      colors=sprintf("%d",p2);
      if (nargin >= 4)
    dithtype=p3;
      endif
    endif
    opts=["-colors ",colors;"-dither ",dithtype];
    im (rows(p1)<=256)
    imwrite(fname,im,(p1+1),opts);
    [Y,newmap]=cmunique(imread(fname));
    delete(fname);
  endif
endfunction