Exemple #1
0
  // createPageString -
  // Create list of pages for search results
  private String createPageString(
      int numberOfItems, int itemsPerPage, int currentPage, String baseUrl) {
    StringBuffer pageString = new StringBuffer();

    // Calculate the total number of pages
    int totalPages = 1;
    if (numberOfItems > itemsPerPage) {
      double pages = Math.ceil(numberOfItems / (double) itemsPerPage);
      totalPages = (int) Math.ceil(pages);
    }

    //
    if (totalPages > 1) {
      for (int i = 1; i <= totalPages; i++) {
        if (i == currentPage) {
          pageString.append(i);
        } else {
          pageString.append("<a href=\"" + baseUrl + i + "\" title=\"" + i + "\">" + i + "</a>");
        }

        if (i != totalPages) pageString.append(" ");
      }
    } else {
      pageString.append("1");
    }

    return pageString.toString();
  }
Exemple #2
0
 byte[] read1bitImage(InputStream in) throws IOException {
   if (fi.compression == FileInfo.LZW)
     throw new IOException("ImageJ cannot open 1-bit LZW compressed TIFFs");
   int scan = (int) Math.ceil(width / 8.0);
   int len = scan * height;
   byte[] buffer = new byte[len];
   byte[] pixels = new byte[nPixels];
   DataInputStream dis = new DataInputStream(in);
   dis.readFully(buffer);
   int value1, value2, offset, index;
   for (int y = 0; y < height; y++) {
     offset = y * scan;
     index = y * width;
     for (int x = 0; x < scan; x++) {
       value1 = buffer[offset + x] & 0xff;
       for (int i = 7; i >= 0; i--) {
         value2 = (value1 & (1 << i)) != 0 ? 255 : 0;
         if (index < pixels.length) pixels[index++] = (byte) value2;
       }
     }
   }
   return pixels;
 }