diff dwt/internal/image/TIFFRandomFileAccess.d @ 34:5123b17c98ef

Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sun, 14 Sep 2008 01:45:57 +0200
parents b903c16b6f48
children
line wrap: on
line diff
--- a/dwt/internal/image/TIFFRandomFileAccess.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/TIFFRandomFileAccess.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,10 +7,15 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.internal.image;
+module dwt.internal.image.TIFFRandomFileAccess;
 
-import java.io.IOException;
+import dwt.internal.image.LEDataInputStream;
+import Math = tango.math.Math;
+import tango.core.Exception;
+import dwt.dwthelper.System;
 
 final class TIFFRandomFileAccess {
 
@@ -24,13 +29,13 @@
 public this(LEDataInputStream stream) {
     inputStream = stream;
     start = current = next = inputStream.getPosition();
-    buffers = new byte[LIST_SIZE][];
+    buffers = new byte[][](LIST_SIZE);
 }
 
 void seek(int pos) {
     if (pos is current) return;
-    if (pos < start) throw new IOException();
-    current = pos;  
+    if (pos < start) throw new IOException( "pos < start" );
+    current = pos;
     if (current > next) {
         int n = current - next;
         /* store required bytes */
@@ -39,7 +44,7 @@
         while (n > 0) {
             if (index >= buffers.length) {
                 byte[][] oldBuffers = buffers;
-                buffers = new byte[Math.max(index + 1, oldBuffers.length + LIST_SIZE)][];
+                buffers = new byte[][]( Math.max(index + 1, oldBuffers.length + LIST_SIZE) );
                 System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length);
             }
             if (buffers[index] is null) buffers[index] = new byte[CHUNK_SIZE];
@@ -60,11 +65,11 @@
     if (nCached > 0) {
         /* Get cached bytes */
         int index = current / CHUNK_SIZE;
-        int offset = current % CHUNK_SIZE;      
+        int offset = current % CHUNK_SIZE;
         while (nCached > 0) {
             int cnt = Math.min(nCached, CHUNK_SIZE - offset);
             System.arraycopy(buffers[index], offset, b, destNext, cnt);
-            nCached -= cnt; 
+            nCached -= cnt;
             destNext += cnt;
             index++;
             offset = 0;
@@ -77,7 +82,7 @@
         while (nMissing > 0) {
             if (index >= buffers.length) {
                 byte[][] oldBuffers = buffers;
-                buffers = new byte[Math.max(index, oldBuffers.length + LIST_SIZE)][];
+                buffers = new byte[][](Math.max(index, oldBuffers.length + LIST_SIZE));
                 System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length);
             }
             if (buffers[index] is null) buffers[index] = new byte[CHUNK_SIZE];