commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1391518 - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/ test/data/images/bmp/4/
Date Fri, 28 Sep 2012 16:26:18 GMT
Author: damjan
Date: Fri Sep 28 16:26:17 2012
New Revision: 1391518

URL: http://svn.apache.org/viewvc?rev=1391518&view=rev
Log:
Add some tests for RLE4 and RLE8 compression in BMP files,
implement the missing delta X/Y support,
and generally clean up the RLE compression code.


Added:
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/info.txt   (with props)
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4.bmp   (with props)
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.asm
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.bmp   (with props)
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.asm
    commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.bmp   (with props)
Modified:
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java?rev=1391518&r1=1391517&r2=1391518&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/PixelParserRle.java
Fri Sep 28 16:26:17 2012
@@ -93,46 +93,33 @@ public class PixelParserRle extends Pixe
         int height = bhi.height;
         int x = 0, y = height - 1;
 
-        // bfp.setDebug(true);
-
         boolean done = false;
         while (!done) {
-            // if (count > 100)
-            // return;
-
             int a = 0xff & bfp.readByte("RLE (" + x + "," + y + ") a", is,
                     "BMP: Bad RLE");
-            // baos.write(a);
-            int b = 0xff & bfp.readByte("RLE (" + x + "," + y + ")  b", is,
+            int b = 0xff & bfp.readByte("RLE (" + x + "," + y + ") b", is,
                     "BMP: Bad RLE");
-            // baos.write(b);
 
             if (a == 0) {
                 switch (b) {
                 case 0: {
                     // EOL
-                    // System.out.println("EOL");
                     y--;
                     x = 0;
-                }
                     break;
+                }
                 case 1:
                     // EOF
-                    // System.out.println("xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                     done = true;
                     break;
                 case 2: {
-                    // System.out.println("xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
-                    int c = 0xff & bfp.readByte("RLE c", is, "BMP: Bad RLE");
-                    // baos.write(c);
-                    int d = 0xff & bfp.readByte("RLE d", is, "BMP: Bad RLE");
-                    // baos.write(d);
-
-                }
+                    int deltaX = 0xff & bfp.readByte("RLE deltaX", is, "BMP: Bad RLE");
+                    int deltaY = 0xff & bfp.readByte("RLE deltaY", is, "BMP: Bad RLE");
+                    x += deltaX;
+                    y -= deltaY;
                     break;
+                }
                 default: {
-                    // System.out.println("xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
-
                     int SamplesPerByte = getSamplesPerByte();
                     int size = b / SamplesPerByte;
                     if ((b % SamplesPerByte) > 0) {
@@ -151,7 +138,6 @@ public class PixelParserRle extends Pixe
 
                     int remaining = b;
 
-                    // while(true)
                     for (int i = 0; remaining > 0; i++) {
                     // for (int i = 0; i < bytes.length; i++)
                         int samples[] = convertDataToSamples(0xff & bytes[i]);
@@ -167,19 +153,15 @@ public class PixelParserRle extends Pixe
                         x += written;
                         remaining -= written;
                     }
-                    // baos.write(bytes);
-                }
                     break;
                 }
+                }
             } else {
                 int rgbs[] = convertDataToSamples(b);
 
                 x += processByteOfData(rgbs, a, x, y, width, height,
                         imageBuilder);
-                // x += processByteOfData(b, a, x, y, width, height, bi);
-
             }
         }
-
     }
 }

Added: commons/proper/imaging/trunk/src/test/data/images/bmp/4/info.txt
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/bmp/4/info.txt?rev=1391518&view=auto
==============================================================================
--- commons/proper/imaging/trunk/src/test/data/images/bmp/4/info.txt (added)
+++ commons/proper/imaging/trunk/src/test/data/images/bmp/4/info.txt Fri Sep 28 16:26:17 2012
@@ -0,0 +1,3 @@
+rle4deltaXY.bmp: 4 bit RLE compression with an encoded-mode delta-Y. Added by Damjan Jovanovic.
+rle8deltaXY.bmp: 8 bit RLE compression with an encoded-mode delta-Y. Added by Damjan Jovanovic.
+

Propchange: commons/proper/imaging/trunk/src/test/data/images/bmp/4/info.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4.bmp
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4.bmp?rev=1391518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4.bmp
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.asm
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.asm?rev=1391518&view=auto
==============================================================================
--- commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.asm (added)
+++ commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.asm Fri Sep 28 16:26:17
2012
@@ -0,0 +1,58 @@
+; Licensed to the Apache Software Foundation (ASF) under one
+; or more contributor license agreements.  See the NOTICE file
+; distributed with this work for additional information
+; regarding copyright ownership.  The ASF licenses this file
+; to you under the Apache License, Version 2.0 (the
+; "License"); you may not use this file except in compliance
+; with the License.  You may obtain a copy of the License at
+;
+;    http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing,
+; software distributed under the License is distributed on an
+; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+; KIND, either express or implied.  See the License for the
+; specific language governing permissions and limitations
+; under the License.
+
+
+; Assemblers are the perfect tool for generating
+; custom test images as they let us insert offsets
+; to unknown locations easily and totally
+; customize the file byte-by-byte.
+;
+; To generate a BMP from this, run:
+; nasm -f bin /path/to/this/file.asm -o /path/to/file.bmp
+
+; bitmap file header
+db 'B','M'
+dd $end ; file size
+db 0,0 ; reserved
+db 0,0 ; reserved
+dd $pixels ; offset to pixel array
+
+; bitmap info header
+dd 40 ; header size
+dd 5 ; width
+dd 5 ; height
+dw 1 ; planes
+dw 4 ; bits
+dd 2 ; compression = RLE4
+dd ($end - $pixels) ; raw pixel data size
+dd 0 ; horizontal resolution
+dd 0 ; vertical resolution
+dd 2 ; number of palette entries
+dd 0 ; number of important palette entries
+
+palette:
+db 0,0,0,0 ; blue,green,red,0
+db 0xff,0xff,0xff,0
+
+pixels:
+db 5,0x11 ; 5 ones
+db 0,0 ; eol
+db 0,2,0,3 ;  escape, delta, 0 right, 3 down
+db 5,0x11 ; 5 ones
+db 0,1 ; eof
+
+end:

Added: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.bmp
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.bmp?rev=1391518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle4deltaXY.bmp
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.asm
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.asm?rev=1391518&view=auto
==============================================================================
--- commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.asm (added)
+++ commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.asm Fri Sep 28 16:26:17 2012
@@ -0,0 +1,58 @@
+; Licensed to the Apache Software Foundation (ASF) under one
+; or more contributor license agreements.  See the NOTICE file
+; distributed with this work for additional information
+; regarding copyright ownership.  The ASF licenses this file
+; to you under the Apache License, Version 2.0 (the
+; "License"); you may not use this file except in compliance
+; with the License.  You may obtain a copy of the License at
+;
+;    http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing,
+; software distributed under the License is distributed on an
+; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+; KIND, either express or implied.  See the License for the
+; specific language governing permissions and limitations
+; under the License.
+
+
+; Assemblers are the perfect tool for generating
+; custom test images as they let us insert offsets
+; to unknown locations easily and totally
+; customize the file byte-by-byte.
+;
+; To generate a BMP from this, run:
+; nasm -f bin /path/to/this/file.asm -o /path/to/file.bmp
+
+; bitmap file header
+db 'B','M'
+dd $end ; file size
+db 0,0 ; reserved
+db 0,0 ; reserved
+dd $pixels ; offset to pixel array
+
+; bitmap info header
+dd 40 ; header size
+dd 5 ; width
+dd 5 ; height
+dw 1 ; planes
+dw 8 ; bits
+dd 1 ; compression = RLE8
+dd ($end - $pixels) ; raw pixel data size
+dd 0 ; horizontal resolution
+dd 0 ; vertical resolution
+dd 2 ; number of palette entries
+dd 0 ; number of important palette entries
+
+palette:
+db 0,0,0,0 ; blue,green,red,0
+db 0xff,0xff,0xff,0
+
+pixels:
+db 5,1 ; 5 ones
+db 0,0 ; eol
+db 0,2,0,3 ;  escape, delta, 0 right, 3 down
+db 5,1 ; 5 ones
+db 0,1 ; eof
+
+end:

Added: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.bmp
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.bmp?rev=1391518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/imaging/trunk/src/test/data/images/bmp/4/rle8.bmp
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message