Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Negative height .bmp patch doesn't work on newer .bmp files #5

Closed
DavidGriffith opened this issue Apr 24, 2017 · 2 comments
Closed

Comments

@DavidGriffith
Copy link
Owner

xv-20091212-patrick-keshishian-bmp-negative-height.patch.mime
xv-20091217-patrick-keshishian-bmp-negative-height.patch.mime
xv-20100405-patrick-keshishian-negative-height-sample.bmp.mime

From http://en.wikipedia.org/wiki/BMP_file_format

Uncompressed Windows bitmaps can also be stored from the top row to the bottom, if the image > height value is negative.

The patch works on the 30k test file provided. Here is the header:

00000000   42 4D 68 75  00 00 00 00  00 00 36 00  00 00 28 00  BMhu......6...(.
00000010   00 00 64 00  00 00 9C FF  FF FF 01 00  18 00 00 00  ..d.............
00000020   00 00 32 75  00 00 12 0B  00 00 12 0B  00 00 00 00  ..2u............
00000030   00 00 00 00  00 00 FF FF  FF FF FF FF  FF FF FF FF  ................
00000040   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
00000050   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
00000060   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
00000070   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
00000080   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
00000090   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
000000A0   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
$ file negheight_test_cs3.bmp 
PC bitmap, Windows 3.x format, 100 x -100 x 24

I found another, much smaller, test image at https://issues.apache.org/jira/browse/IMAGING-162. Even with the patch, xv doesn't like it.

Here's the whole file (cannot attach bmp files to Github issues):

begin 644 monochrome-negative-height.bmp
M0DVB`````````((```!L````!````/C___\!``$``````"`````3"P``$PL`
M``(````"````0D=2<P``````````````````````````````````````````
M``````````````````````(```````````````````#___\`````````````
;```````````````0````(````$````"`````
`
end

This is the entire hexdump of the file:

00000000   42 4D A2 00  00 00 00 00  00 00 82 00  00 00 6C 00  BM............l.
00000010   00 00 04 00  00 00 F8 FF  FF FF 01 00  01 00 00 00  ................
00000020   00 00 20 00  00 00 13 0B  00 00 13 0B  00 00 02 00  .. .............
00000030   00 00 02 00  00 00 42 47  52 73 00 00  00 00 00 00  ......BGRs......
00000040   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
00000050   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
00000060   00 00 00 00  00 00 00 00  00 00 02 00  00 00 00 00  ................
00000070   00 00 00 00  00 00 00 00  00 00 FF FF  FF 00 00 00  ................
00000080   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
00000090   00 00 10 00  00 00 20 00  00 00 40 00  00 00 80 00  ...... ...@.....
000000A0   00 00                                               ..
file monochrome-negative-height.bmp
monochrome-negative-height.bmp: PC bitmap, Windows 95/NT4 and newer format, 4 x -8 x 1

So... it appears that the patch is deficient in handling newer-format .bmp files.

Patch was originally applied in 564e566. More work is necessary.

@DavidGriffith
Copy link
Owner Author

DavidGriffith commented Apr 26, 2017

Some discoveries of the progress of the .bmp format:

Given this structure for the header of a .bmp file:

struct bmp_header {
        char  bfType1;          /* The character 'B' */
        char  bfType2;          /* The character 'M' */
        u_short bfReserved1;    /* Unused - must be zero */
        u_short bfReserved2;    /* Unused - must be zero */
        u_int   bfOffBits;      /* Offset to start of pixel data */
        u_int   biSize;         /* Header size */
        ...
}

xv recognizes three possible values for biSize: 12, 40, 64 for WIN_OS2_OLD, WIN_NEW, and OS2_NEW respectively. Any other value indicates the old bitmap format. This is why xv doesn't like the file I got from apache.org. It looks like, to xv, to be an old-format file, but really is a newer one.

@DavidGriffith
Copy link
Owner Author

Updated xvbmp.c to support reading the three newer versions of BMP format. See 60a25db

Three more versions of BMP were introduced since development of xv stopped.
These are for Windows 95 / NT4, Windows 98 / 2000, and Windows NT / 2000.
We still write BMP files in the old Windows 3.x version.
If you need some other version, use ImageMagick.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant