1 package gov
.nasa
.worldwind
.formats
.nitfs
;
3 import gov
.nasa
.worldwind
.*;
5 Copyright (C) 2001, 2007 United States Government
6 as represented by the Administrator of the
7 National Aeronautics and Space Administration.
12 * @author Lado Garakanidze
13 * @version $Id: Cib2DdsCompress Apr 23, 2007 10:59:01 AM lado
15 class Cib2DdsCompress
extends AbstractRpf2DdsCompress
17 public DDSBlock4x4
compressDxt1Block4x4(NitfsImageBand imageBand
, byte[] pixelCodes
, boolean hasTransparentPixels
)
19 int[] grayPixels
= new int[16];
20 int minColor
= Integer
.MAX_VALUE
;
21 int maxColor
= Integer
.MIN_VALUE
;
23 for(int i
= 0; i
< pixelCodes
.length
; i
++ )
25 grayPixels
[i
] = imageBand
.lookupGray( 0xFF & pixelCodes
[i
]);
26 if(grayPixels
[i
] < minColor
)
27 minColor
= grayPixels
[i
];
28 if(grayPixels
[i
] > maxColor
)
29 maxColor
= grayPixels
[i
];
32 DDSBlock4x4 ddsBlock
= new DDSBlock4x4(
33 (short) DDSConverter
.getPixel565( new Color( maxColor
, maxColor
, maxColor
) ),
34 (short) DDSConverter
.getPixel565( new Color( minColor
, minColor
, minColor
) ),
37 if(maxColor
!= minColor
)
39 int[] ext
= new int[] { maxColor
, minColor
, (2 * maxColor
+ minColor
)/3, (maxColor
+ 2 * minColor
)/3 };
41 for (int i
= 0; i
< grayPixels
.length
; i
++)
43 int closest
= Integer
.MAX_VALUE
;
45 for (int j
= 0; j
< ext
.length
; j
++)
47 int d
= ( ext
[j
] >= grayPixels
[i
] ) ?
(ext
[j
] - grayPixels
[i
]) : (grayPixels
[i
] - ext
[j
]);
54 ddsBlock
.bitmask
|= mask
<< i
* 2;