From bug-octave-request at bevo dot che dot wisc dot edu Fri Dec 15 11:55:08 2000 Subject: saveimage writes wrong b/w images in some cases From: "John W. Eaton" To: Kai Habel Cc: bug-octave Date: Fri, 15 Dec 2000 11:54:50 -0600 On 7-Aug-2000, Kai Habel wrote: | Bug report for Octave 2.1.31 configured for %OCTAVE_CANONICAL_HOST_TYPE% | | Description: | ----------- | | saveimage writes distorted b/w images in same cases | | Repeat-By: | --------- | | X = [ones(42,22),zeros(42,22)]; | imshow(X,2); | | Fix: | --- | | See patch appended. I have decided to rewrite the black/ white image | section (ppb) for the ppm case. | | ChangeLog: | | 2000-08-08 Kai Habel | | * saveimage.m: fix distortion bug for ppm(pbm) image. Sorry for the long delay. I applied this patch. Thanks! jwe *** /usr/local/share/octave/2.1.31/m/image/saveimage.m Tue Jul 18 10:39:02 2000 | --- ./saveimage.m Mon Aug 7 20:54:23 2000 | *************** | *** 160,166 **** | tagline = sprintf ("# Created by Octave %s, %s", | __OCTAVE_VERSION__, time_string); | | ! if (grey && map_nr == 2 && bw) | | if (map(1) != 0) | map = [0; 1]; | --- 160,166 ---- | tagline = sprintf ("# Created by Octave %s, %s", | __OCTAVE_VERSION__, time_string); | | ! if (grey && bw) | | if (map(1) != 0) | map = [0; 1]; | *************** | *** 168,193 **** | map = [1; 0]; | endif | | ! n_long = rem (img_nc, 8); | ! tmp = zeros (ceil (img_nc/8), img_nr); | | ! for i = 1:img_nr | ! idx = (i-1)*img_nc+1:i*img_nc; | ! if (n_long > 0) | ! img_row = [map(img(idx)); (zeros (8-n_long, 1))]; | ! else | ! img_row = map(img(idx)); | ! endif | ! l_img_row = length (img_row); | ! if (img_nc < 8) | ! for j = 1:8 | ! tmp(:,i) = tmp(:,i) + img_row (j) * 2^(8-j); | ! endfor | ! else | ! for j = 1:8 | ! tmp(:,i) = tmp(:,i) + img_row (j:8:l_img_row) * 2^(8-j); | ! endfor | ! endif | endfor | | fid = fopen (filename, "w"); | --- 168,183 ---- | map = [1; 0]; | endif | | ! k = ceil (img_nr/8); | ! tmp = zeros (k, img_nc); | | ! ## append columns with zeros to original img, that mod(cols,8) = 0 ! | ! bwimg = postpad (reshape (map(img), img_nr, img_nc), k * 8, 0); | ! | ! b = kron (pow2 (7:-1:0)', ones (1, img_nc)); | ! | ! for i = 1:k | ! tmp(i,:) = sum (bwimg(8*(i-1)+1:8*i,:) .* b); | endfor | | fid = fopen (filename, "w"); | | ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------