Mercurial > hg > octave-nkf
annotate scripts/image/imfinfo.m @ 12061:9b9aaacf194d release-3-2-x
dlmread: perform tilde expansion to filename argument
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 23 Aug 2009 11:09:17 +0200 |
parents | 74d5c1a4ca96 |
children | 0c42b6b7da24 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2008, 2009 Soren Hauberg <hauberg@gmail.com> |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
2 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
3 ## This file is part of Octave. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
4 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
8 ## your option) any later version. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
9 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
13 ## General Public License for more details. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
14 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
18 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
9143
74d5c1a4ca96
Eliminate 'unbalanced parentheses in @def...' error during texi2pdf.
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
20 ## @deftypefn {Function File} {@var{info} =} imfinfo (@var{filename}) |
74d5c1a4ca96
Eliminate 'unbalanced parentheses in @def...' error during texi2pdf.
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{info} =} imfinfo (@var{url}) |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
22 ## Read image information from a file. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
23 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
24 ## @code{imfinfo} returns a structure containing information about the image |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## stored in the file @var{filename}. The output structure contains the |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
26 ## following fields. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
27 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
28 ## @table @samp |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
29 ## @item Filename |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
30 ## The full name of the image file. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
31 ## @item FileSize |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
32 ## Number of bytes of the image on disk |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
33 ## @item FileModDate |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
34 ## Date of last modification to the file. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
35 ## @item Height |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
36 ## Image height in pixels. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
37 ## @item Width |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
38 ## Image Width in pixels. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
39 ## @item BitDepth |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
40 ## Number of bits per channel per pixel. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
41 ## @item Format |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
42 ## Image format (e.g., @code{"jpeg"}). |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
43 ## @item LongFormat |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
44 ## Long form image format description. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
45 ## @item XResolution |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
46 ## X resolution of the image. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
47 ## @item YResolution |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
48 ## Y resolution of the image. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
49 ## @item TotalColors |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
50 ## Number of unique colors in the image. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
51 ## @item TileName |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
52 ## Tile name. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
53 ## @item AnimationDelay |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
54 ## Time in 1/100ths of a second (0 to 65535) which must expire before displaying |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
55 ## the next image in an animated sequence. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
56 ## @item AnimationIterations |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
57 ## Number of iterations to loop an animation (e.g., Netscape loop extension) for. |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
58 ## @item ByteOrder |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
59 ## Endian option for formats that support it. Is either @code{"little-endian"}, |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
60 ## @code{"big-endian"}, or @code{"undefined"}. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
61 ## @item Gamma |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
62 ## Gamma level of the image. The same color image displayed on two different |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
63 ## workstations may look different due to differences in the display monitor. |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
64 ## @item Matte |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
65 ## @code{true} if the image has transparency. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
66 ## @item ModulusDepth |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
67 ## Image modulus depth (minimum number of bits required to support red/green/blue |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
68 ## components without loss of accuracy). |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
69 ## @item Quality |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
70 ## JPEG/MIFF/PNG compression level. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
71 ## @item QuantizeColors |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
72 ## Preferred number of colors in the image. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
73 ## @item ResolutionUnits |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
74 ## Units of image resolution. Is either @code{"pixels per inch"}, |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
75 ## @code{"pixels per centimeter"}, or @code{"undefined"}. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
76 ## @item ColorType |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
77 ## Image type. Is either @code{"grayscale"}, @code{"indexed"}, @code{"truecolor"}, |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
78 ## or @code{"undefined"}. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
79 ## @item View |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
80 ## FlashPix viewing parameters. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
81 ## @end table |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
82 ## |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
83 ## @seealso{imread, imwrite} |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
84 ## @end deftypefn |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
85 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
86 function info = imfinfo (filename) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
87 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
88 if (nargin < 1) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
89 print_usage (); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
90 endif |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
91 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
92 if (!ischar (filename)) |
8664 | 93 error ("imfinfo: filename must be a string"); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
94 endif |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
95 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
96 filename = tilde_expand (filename); |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
97 |
8152
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
98 delete_file = false; |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
99 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
100 unwind_protect |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
101 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
102 fn = file_in_path (IMAGE_PATH, filename); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
103 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
104 if (isempty (fn)) |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
105 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
106 ## Couldn't find file. See if it's an URL. |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
107 |
8152
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
108 tmp = tmpnam (); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
109 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
110 [fn, status, msg] = urlwrite (filename, tmp); |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
111 |
8152
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
112 if (! status) |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
113 error ("imfinfo: cannot find %s", filename); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
114 endif |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
115 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
116 if (! isempty (fn)) |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
117 delete_file = true; |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
118 endif |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
119 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
120 endif |
8152
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
121 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
122 [statinfo, err, msg] = stat (fn); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
123 if (err != 0) |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
124 error ("imfinfo: error reading '%s': %s", fn, msg); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
125 endif |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
126 |
8152
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
127 time_stamp = strftime ("%e-%b-%Y %H:%M:%S", localtime (statinfo.mtime)); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
128 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
129 info = __magick_finfo__ (fn); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
130 info.FileModDate = time_stamp; |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
131 |
8152
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
132 unwind_protect_cleanup |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
133 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
134 if (delete_file) |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
135 unlink (fn); |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
136 endif |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
137 |
2b48deec1aa2
imfinfo.m: delete temporary files
John W. Eaton <jwe@octave.org>
parents:
8144
diff
changeset
|
138 end_unwind_protect |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
139 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
diff
changeset
|
140 endfunction |