1 | import java.security.MessageDigest; |
---|
2 | import java.security.NoSuchAlgorithmException; |
---|
3 | |
---|
4 | import loci.common.DataTools; |
---|
5 | import loci.formats.ChannelFiller; |
---|
6 | import loci.formats.ChannelSeparator; |
---|
7 | import loci.formats.FormatTools; |
---|
8 | import loci.formats.IFormatReader; |
---|
9 | import loci.formats.ImageReader; |
---|
10 | import loci.formats.MinMaxCalculator; |
---|
11 | |
---|
12 | |
---|
13 | public class Test |
---|
14 | { |
---|
15 | private static final String TARGET = |
---|
16 | "/home/callan/testimages/lsm/2chZT.lsm"; |
---|
17 | |
---|
18 | public void parse(String id) throws Exception |
---|
19 | { |
---|
20 | IFormatReader reader = new ImageReader(); |
---|
21 | reader = new ChannelFiller(reader); |
---|
22 | reader = new ChannelSeparator(reader); |
---|
23 | reader = new MinMaxCalculator(reader); |
---|
24 | reader.setId(id); |
---|
25 | |
---|
26 | int sizeX = reader.getSizeX(); |
---|
27 | int sizeY = reader.getSizeY(); |
---|
28 | int sizeZ = reader.getSizeZ(); |
---|
29 | int sizeC = reader.getSizeC(); |
---|
30 | int sizeT = reader.getSizeT(); |
---|
31 | int bpp = FormatTools.getBytesPerPixel(reader.getPixelType()); |
---|
32 | int planeSize = sizeX * sizeY * bpp; |
---|
33 | |
---|
34 | byte[] plane = new byte[planeSize]; |
---|
35 | byte[] halfPlane = new byte[planeSize / 2]; |
---|
36 | String planeDigest, halfPlaneDigest; |
---|
37 | for (int i = 0; i < reader.getImageCount(); i++) { |
---|
38 | reader.openBytes(i, plane); |
---|
39 | reader.openBytes(i, halfPlane, 0, 0, sizeX, sizeY / 2); |
---|
40 | planeDigest = md5(plane, 0, planeSize / 2); |
---|
41 | halfPlaneDigest = md5(halfPlane, 0, planeSize / 2); |
---|
42 | if (!planeDigest.equals(halfPlaneDigest)) { |
---|
43 | System.err.println(String.format("MD5:%d %s != %s", |
---|
44 | i, planeDigest, halfPlaneDigest)); |
---|
45 | } |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | /** Calculate the MD5 of a byte array. */ |
---|
50 | public static String md5(byte[] b, int offset, int len) { |
---|
51 | try { |
---|
52 | MessageDigest md = MessageDigest.getInstance("MD5"); |
---|
53 | md.reset(); |
---|
54 | md.update(b, offset, len); |
---|
55 | byte[] digest = md.digest(); |
---|
56 | return DataTools.bytesToHex(digest); |
---|
57 | } |
---|
58 | catch (NoSuchAlgorithmException e) { } |
---|
59 | return null; |
---|
60 | } |
---|
61 | |
---|
62 | public static void main(String[] args) throws Exception |
---|
63 | { |
---|
64 | Test t = new Test(); |
---|
65 | t.parse(TARGET); |
---|
66 | } |
---|
67 | |
---|
68 | } |
---|