(Rect r, InStream is,
ZlibInStream zis,
PixelFormat pf, ModifiablePixelBuffer pb,
PIXEL_T pix_t)
| 152 | } |
| 153 | |
| 154 | private void ZRLE_DECODE(Rect r, InStream is, |
| 155 | ZlibInStream zis, |
| 156 | PixelFormat pf, ModifiablePixelBuffer pb, |
| 157 | PIXEL_T pix_t) |
| 158 | { |
| 159 | int length = is.readU32(); |
| 160 | zis.setUnderlying(is, length); |
| 161 | Rect t = new Rect(); |
| 162 | ByteBuffer buf = ByteBuffer.allocate(64 * 64 * pf.bpp/8); |
| 163 | |
| 164 | for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 64) { |
| 165 | |
| 166 | t.br.y = Math.min(r.br.y, t.tl.y + 64); |
| 167 | |
| 168 | for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 64) { |
| 169 | |
| 170 | t.br.x = Math.min(r.br.x, t.tl.x + 64); |
| 171 | |
| 172 | int mode = zis.readU8(); |
| 173 | boolean rle = (mode & 128) != 0; |
| 174 | int palSize = mode & 127; |
| 175 | ByteBuffer palette = ByteBuffer.allocate(128 * pf.bpp/8); |
| 176 | |
| 177 | for (int i = 0; i < palSize; i++) { |
| 178 | palette.put(READ_PIXEL(zis, pix_t)); |
| 179 | } |
| 180 | palette.flip(); |
| 181 | |
| 182 | if (palSize == 1) { |
| 183 | byte[] pix = new byte[pf.bpp/8]; |
| 184 | palette.get(pix); |
| 185 | pb.fillRect(pf, t, pix); |
| 186 | continue; |
| 187 | } |
| 188 | |
| 189 | if (!rle) { |
| 190 | if (palSize == 0) { |
| 191 | |
| 192 | // raw |
| 193 | switch (pix_t) { |
| 194 | case U24A: |
| 195 | case U24B: |
| 196 | ByteBuffer ptr = buf.duplicate(); |
| 197 | for (int i=0; i < t.area(); i++) { |
| 198 | ptr.put(READ_PIXEL(zis, pix_t)); |
| 199 | } |
| 200 | break; |
| 201 | default: |
| 202 | zis.readBytes(buf.duplicate(), t.area() * (pf.bpp/8)); |
| 203 | } |
| 204 | |
| 205 | } else { |
| 206 | |
| 207 | // packed pixels |
| 208 | int bppp = ((palSize > 16) ? 8 : |
| 209 | ((palSize > 4) ? 4 : ((palSize > 2) ? 2 : 1))); |
| 210 | |
| 211 | ByteBuffer ptr = buf.duplicate(); |
no test coverage detected