Changeset 213:36f5cb12e1a2 for dwt/internal/image/PngEncoder.d
- Timestamp:
- 05/17/08 11:34:28 (8 months ago)
- Files:
-
- dwt/internal/image/PngEncoder.d (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/internal/image/PngEncoder.d
r2 r213 1 /*******************************************************************************1 /******************************************************************************* 2 2 * Copyright (c) 2000, 2006 IBM Corporation and others. 3 3 * All rights reserved. This program and the accompanying materials … … 16 16 import dwt.internal.image.PngDeflater; 17 17 import dwt.dwthelper.ByteArrayOutputStream; 18 import dwt.dwthelper.OutputStream; 18 19 import dwt.DWT; 19 20 import dwt.graphics.ImageData; 20 21 import dwt.graphics.ImageLoader; 21 22 import dwt.graphics.RGB; 23 import dwt.internal.Compatibility; 22 24 import dwt.internal.image.PngChunk; 23 25 … … 237 239 238 240 ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); 241 OutputStream os = Compatibility.newDeflaterOutputStream(baos); 242 if (os is null) os = baos; 239 243 240 244 if (colorType is 3) { 241 245 246 byte[] lineData = new byte[width]; 247 248 for (int y = 0; y < height; y++) { 249 250 int filter = 0; 251 os.write(filter); 252 253 data.getPixels(0, y, width, lineData, 0); 254 255 for (int x = 0; x < lineData.length; x++) { 256 257 os.write(lineData[x]); 258 259 } 260 261 } 262 263 } 264 265 else { 266 242 267 int[] lineData = new int[width]; 243 244 for (int y = 0; y < height; y++) { 245 246 byte filter[] = [0]; 247 baos.write(filter, 0, 1); 248 249 data.getPixels(0, y, width, lineData, 0); 250 251 for (int x = 0; x < lineData.length; x++) { 252 253 baos.write(cast(byte) lineData[x]); 254 255 } 256 257 } 258 259 } 260 261 else { 262 263 int[] lineData = new int[width]; 264 byte[] alphaData = new byte[width]; 268 byte[] alphaData = null; 269 if (colorType is 6) { 270 alphaData = new byte[width]; 271 } 265 272 266 273 int redMask = data.palette.redMask; … … 273 280 for (int y = 0; y < height; y++) { 274 281 275 byte filter[] = [0];276 baos.write(filter, 0, 1);282 int filter = 0; 283 os.write(filter); 277 284 278 285 data.getPixels(0, y, width, lineData, 0); … … 293 300 b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; 294 301 295 byte pixels[] = [cast(byte) r, cast(byte) g, cast(byte) b]; 296 baos.write(pixels, 0, 3); 302 os.write(r); 303 os.write(g); 304 os.write(b); 297 305 298 306 if (colorType is 6) { 299 300 byte alpha[] = [alphaData[x]]; 301 baos.write(alpha, 0, 1); 302 307 os.write(alphaData[x]); 303 308 } 304 309 … … 309 314 } 310 315 311 PngDeflater deflater = new PngDeflater(); 312 byte[] compressed = deflater.deflate(baos.toByteArray()); 316 os.flush(); 317 os.close(); 318 319 byte[] compressed = baos.toByteArray(); 320 if (os is baos) { 321 PngDeflater deflater = new PngDeflater(); 322 compressed = deflater.deflate(compressed); 323 } 313 324 314 325 writeChunk(TAG_IDAT, compressed);
