bugGNU Octave - Bugs: bug #44119, image package: imformats missing...


bug #44119: image package: imformats missing pretty print

Submitted by:  Hartmut <hardy>
Submitted on:  Thu 29 Jan 2015 04:25:37 PM UTC  
Category:  Octave Forge Package Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Wed 06 May 2015 07:55:16 PM UTC, comment #12: 

Sorry, I completely missed it when you uploaded the patch. I think this could have even gone into the 4.0 release if I had seen it before.

Anyway, thank you for the patch, I pushed to the default branch


Carnë Draug <carandraug>
Project Member
Tue 05 May 2015 06:06:16 PM UTC, comment #11: 

Now that the Octave 4.0 release has been switched to stable in the repo, could someone push this changeset (prettyprint for imformats) into the default branch?

Hartmut <hardy>
Wed 04 Feb 2015 09:53:32 PM UTC, comment #10: 

Here is the mercurial changeset (the content is identical to the code directly before this post).

(I wouldn't call this "dead easy", but it was eays enough to use.)

Hartmut <hardy>
Wed 04 Feb 2015 08:51:17 PM UTC, comment #9: 

Here is the code to make a pretty list of the registered image formats, as proposed:

function pretty_print_formats(forms)

  ## Compute the maximal length of the extensions column
  h1 = "Extension";
  ext_seperator = ", ";
  max_ext_length = length (h1);
  for m = 1:length (forms)
    num_ext = length (forms(m).ext);
    length_ext = sum (cellfun (@length, forms(m).ext));
    ext_length = length_ext + (num_ext -1) * length(ext_seperator);
    if ext_length > max_ext_length
      max_ext_length = ext_length;
  h1 = postpad(h1, max_ext_length, " ");

  ## define header names (none should be shorter than 3 characters)
  h2 = "isa";
  h3 = "Info";
  h4 = "Read";
  h5 = "Write";
  h6 = "Alpha";
  h7 = "Description";

  ## print a header
  header = [h1, " | ", h2, " | ", h3, " | ", h4, " | ", h5, " | ", h6, " | ", h7, " "];
  lineunder = [repmat("-", 1, length(h1)), "-+-", repmat("-", 1, length(h2)), "-+-", ...
    repmat("-", 1, length(h3)), "-+-", repmat("-", 1, length(h4)), "-+-", ...
    repmat("-", 1, length(h5)), "-+-", repmat("-", 1, length(h6)), "-+-", ...
    repmat("-", 1, length(h7)), "-"];

  ## print the formats
  # ext (h1)
  for m = 1:length(forms)
    thisline = "";
    num_exts = length(forms(m).ext);
    ext_string = "";
    for n = 1:num_exts
      ext_string = [ext_string, forms(m).ext{n}];
      if n < num_exts
        ext_string = [ext_string, ext_seperator];
    ext_string = postpad(ext_string, length(h1), " ");
    thisline = [thisline, ext_string, " | "];
    # isa (h2)
    if isempty(forms(m).isa)
      thisline = [thisline, postpad(" no", length(h2), " ")];
      thisline = [thisline, postpad("yes", length(h2), " ")];
    thisline = [thisline, " | "];
    # info (h3)
    if isempty(forms(m).info)
    thisline = [thisline, postpad(" no", length(h3), " ")];
      thisline = [thisline, postpad("yes", length(h3), " ")];
    thisline = [thisline, " | "];
    # read (h4)
    if isempty(forms(m).read)
    thisline = [thisline, postpad(" no", length(h4), " ")];
      thisline = [thisline, postpad("yes", length(h4), " ")];
    thisline = [thisline, " | "];
    # write (h5)
    if isempty(forms(m).write)
    thisline = [thisline, postpad(" no", length(h5), " ")];
      thisline = [thisline, postpad("yes", length(h5), " ")];
    thisline = [thisline, " | "];
    # alpha (h6)
    if isempty(forms(m).write)
    thisline = [thisline, postpad(" no", length(h6), " ")];
      thisline = [thisline, postpad("yes", length(h6), " ")];
    thisline = [thisline, " | "];
    # description (h7)
    thisline = [thisline, forms(m).description];
    # print this format line

This function has obviously to be called at the top of imformats.m like this:

% this line used to be
% error ("imformats: pretty print not yet implemented.");

I will attach a screenshot of the resulting output.

I will also try to supply a mercurial changeset. But since I have never done this before, and I'm not a software developer normally, this might take some time. So if you dont' find a changeset here in a couple of weeks, then I have not suceeded with this... In this case, please also feel free to use the above code.

Hartmut <hardy>
Sat 31 Jan 2015 11:02:41 PM UTC, comment #8: 

By the way, could you submit a mercurial changeset? It makes it easier for us to implement and keep attribution to you. It's dead easy to do so (in Linux at least) and you can find the instructions on the manual at https://www.gnu.org/software/octave/doc/interpreter/Basics-of-Generating-a-Changeset.html

Carnë Draug <carandraug>
Project Member
Sat 31 Jan 2015 11:00:19 PM UTC, comment #7: 

I see what you mean about being too large now. Indeed, it is too large and the function names are useless since at least in the case of Octave core they are private.  A more interesting feature would be to have "yes/no" whether there is a writer or reader for each format. Could you implement that?  Something like:

bmp         yes   yes   yes    yes     yes   Microsoft Windows bitmap image
jp2, jpx    yes   yes   yes    yes      no   Joint Ph... you get the idea ;)

About the readability issue due to having a not wide enough screen which causes line breaks, that's dependent on your pager. In my case it is displayed properly via a pager that has "horizontal scroll" (I never changed its configuration though, it's using less on my system).

Carnë Draug <carandraug>
Project Member
Sat 31 Jan 2015 07:21:10 PM UTC, comment #6: 

I have tried to generate a "pretty" and complete list before. I will attach a screenshot of the result. My concern was, that this list is not of much use, because it is so WIDE that it hardly fits onto any screen. And once your terminal window is less wide, you will get linebreaks and it doesn't look pretty at all. (I will attach a screenshot of this as well.)

The reason for this is, that the content of the .isa entry is such a long text string.

Are you sure that such a wide and "pretty" list is useful for anyone? I personally would prefer a less complete, but still readable list like I proposed before.

Just let me know, I could probably provide code for either of them.

Hartmut <hardy>
Sat 31 Jan 2015 06:35:58 PM UTC, comment #5: 

If you type "pkg list" you will see a type of nicely formatted table. The code for this is quite simple, it's the pkg private function installed_packages() which you can see online here:


Can you get something similar for imformats? It doesn't have to be the same as Matlab, just a nice and complete table.

Carnë Draug <carandraug>
Project Member
Fri 30 Jan 2015 09:51:43 PM UTC, comment #4: 

I have had a look what Matlab does on this case (a call to imformats without any input or output arguments). And it outputs a huge text table with all existing information.

If we try to do this (I did) this results in a table that is much wider then usual computer screens, so it is not at all "pretty" any more.

So I would suggest for this case, to only output a simple list of the supported file format extensions.

To achive this, we could substitute todays line 81 of fileformats.m with the following code:

disp('The following file format extensions are currently supported:');
    form = formats;
    for m=1:length(form)
       if(length(form(m).ext) >=2)  % if more then one file format goes onto a line
           for n = 1:length(form(m).ext)-1
               form(m).ext{n} = [form(m).ext{n}, ', ']; % insert commas inbetween them

Hartmut <hardy>
Thu 29 Jan 2015 07:56:23 PM UTC, comment #3: 

The part of imformats that would make a pretty display of the available formats is just Octave code. You are using Octave, which means you can program Octave, which means you should have enough knowledge to do it. Your patch would go here:


Anyway imformats is not really to be used interactive. Its main use is to "register" new formats or modify existing ones.  If you just want to have a list of coders printed with the less amount of typing, you can do:

octave-cli-3.8.2> (imformats).coder
ans = BMP
ans = CUR
ans = GIF
ans = ICO
ans = JBG
ans = JBIG
ans = JP2
ans = JPEG
ans = PBM
ans = PCX
ans = PGM
ans = PNG
ans = PNM
ans = PPM
ans = SUN
ans = TGA
ans = TIFF
ans = XBM
ans = XPM
ans = XWD

Carnë Draug <carandraug>
Project Member
Thu 29 Jan 2015 06:45:45 PM UTC, comment #2: 

You are right, it's just a minor bug or even wish. But this behavior makes the command "imformats" much less useful, because the  (my?) normal use of it would be to only call it without any parameters, and hope to simply get a long list of all supported image formats.

I am sorry, but I don't have the knowledge to supply a patch for this, I don't even quite understand what "pretty print" is. (Wouldn't it be enough to get the same printout from the imformats command as you get it from my variable listing of "F" in the example script? ...)

Hartmut <hardy>
Thu 29 Jan 2015 05:33:03 PM UTC, comment #1: 

It is not incorrect, as the error message says, it was simply not implemented.  pretty print of a struct array was low on my priorities when implemented this.

Could you supply a patch for this?

Carnë Draug <carandraug>
Project Member
Thu 29 Jan 2015 04:25:37 PM UTC, original submission:  

Here is a short script to show what I mean:

pkg load image;
F = imformats;
F          % works fine
imformats  % error

The first way to print the output of imformats works fine. The second way to directly print the output results in the error message "error: imformats: pretty print not yet implemented."

This happens with Octave 3.8.2 and image-2.2.2 under Linux as well as under Windows.

Hartmut <hardy>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #32995:  prettyprintimformats.diff added by hardy (4KiB - text/x-patch)
file #32957:  imformats_wide_list.png added by hardy (153KiB - image/png)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by hardy (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-05-06 carandraug StatusNone => Fixed
        Open/ClosedOpen => Closed
        Release3.8.2 => dev
    2015-02-04 hardy Attached File- => Added prettyprintimformats.diff, #32995
    2015-02-04 hardy Attached File- => Added new_imformats_prettyprint.png, #32994
    2015-01-31 hardy Attached File- => Added imformats_wide_list.png, #32957
        Attached File- => Added imformats_normalwidht=ugly.png, #32958
    2015-01-29 carandraug Severity3 - Normal => 1 - Wish
        Summaryimage package: imformats output (struct array) not displayed properly => image package: imformats missing pretty print

    Back to the top

    Powered by Savane 3.5