Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8306875

BufferedImage spec needs clarification w.r.t its implementation of the WritableRenderedImage interface

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 21
    • client-libs
    • None
    • 2d
    • behavioral
    • minimal
    • The spec is being updated but not the implementation
    • Java API
    • SE

    Description

      Summary

      Clarify the specification of java.awt.image.BufferedImage with respect to its implementation of the WritableRenderedImage interface.

      Problem

      BufferedImage implements java.awt.image.WritableRenderedImage which has methods relating to which rectangular areas (tiles) of an Image are writable, for updating this, and for adding and removing listeners on tiles. However a BufferedImage inherited this interface in order to implement the super-interface RenderedImage, and a BufferedImage is not tiled - or more precisely is a single tile, always checked out for writing and consequently no-ops many of the methods defined by WritableRenderedImage. However the specification of these methods on BufferedImage is simply copied from the interface and there is no explanation that these methods do nothing.

      Solution

      Update the specification to describe the actual behaviour of BufferedImage.

      Specification

      class java.awt.image.BufferedImage 
      
      
      +   * This method ignores its parameters and does nothing,
      +   * since {@code BufferedImage} is always checked out
      +   * for writing and cannot be made read-only,
      +   * so there can never be events to dispatch.
      +   *
           public void addTileObserver (TileObserver to)
      
      ----
      
      +   * This method ignores the given observer,
      +   * since {@link #addTileObserver(TileObserver)} adds none.
      +   *
           public void removeTileObserver (TileObserver to) 
      
      ----
           /**
            * Returns whether or not a tile is currently checked out for writing.
      +     * The only tile in a {@code BufferedImage} is at (0,0) and it is always
      +     * writable, so calling this method with (0,0) will always return
      +     * {@code true}, and any other coordinate will cause an exception
      +     * to be thrown.
      +     *
            * @param tileX the x index of the tile.
            * @param tileY the y index of the tile.
            * @return {@code true} if the tile specified by the specified
            *          indices is checked out for writing; {@code false}
            *          otherwise.
      -     * @throws ArrayIndexOutOfBoundsException if both
      -     *          {@code tileX} and {@code tileY} are not equal
      +     * @throws IllegalArgumentException if either
      +     *          {@code tileX} or {@code tileY} is not equal
            *          to 0
            */
           public boolean isTileWritable (int tileX, int tileY)
      
      ----
      
      +     * Since a {@code BufferedImage} consists of a single tile,
      +     * and that tile is always checked out for writing,
      +     * this method returns an array of one point.
      +     * Further, the offset shall be consistent with
      +     * {@link #getMinTileX()} and {@link #getMinTileY()},
      +     * which are always (0,0) in {@code BufferedImage}.
      +     * That will always be the coordinates of the single
      +     * returned {@code Point}.
      +     *
           public Point[] getWritableTileIndices()
      
      ----
      
      +   * This method unconditionally returns the
      +   * {@linkplain #getRaster() single tile} without checking
      +   * the passed values. No listeners are notified since the
      +   * returned tile is always checked out for writing.
      
      public WritableRaster getWritableTile (int tileX, int tileY) 
      
      -----
      
      +   * This method immediately returns without checking the passed values.
      +   * No listeners are notified since the {@linkplain #getRaster() single tile}
      +   * is always checked out for writing.
      +   *
           public void releaseWritableTile (int tileX, int tileY)
      
      
      

      Attachments

        Issue Links

          Activity

            People

              prr Philip Race
              prr Philip Race
              Joe Darcy, Philip Race
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: