diff options
author | Felipe Heidrich | 2009-06-30 22:00:12 +0000 |
---|---|---|
committer | Felipe Heidrich | 2009-06-30 22:00:12 +0000 |
commit | f664d297f7bb009784868bf3fcf0b3e3bb9a646b (patch) | |
tree | 54012fe4929893eef4891c88cbbf5841272ff433 /bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt | |
parent | bc18a5e014088ce811f09c603b88361094486062 (diff) | |
download | eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.tar.gz eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.tar.xz eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.zip |
*** empty log message ***
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt')
140 files changed, 0 insertions, 34868 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java deleted file mode 100755 index 6d5b5d9d39..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ /dev/null @@ -1,3952 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt; - - -import org.eclipse.swt.internal.*; - -/** - * This class provides access to a small number of SWT system-wide - * methods, and in addition defines the public constants provided - * by SWT. - * <p> - * By defining constants like UP and DOWN in a single class, SWT - * can share common names and concepts at the same time minimizing - * the number of classes, names and constants for the application - * programmer. - * </p><p> - * Note that some of the constants provided by this class represent - * optional, appearance related aspects of widgets which are available - * either only on some window systems, or for a differing set of - * widgets on each window system. These constants are marked - * as <em>HINT</em>s. The set of widgets which support a particular - * <em>HINT</em> may change from release to release, although we typically - * will not withdraw support for a <em>HINT</em> once it is made available. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -/* NOTE: - * Good javadoc coding style is to put the values of static final - * constants in the comments. This reinforces the fact that - * consumers are allowed to rely on the value (and they must - * since the values are compiled inline in their code). We - * can <em>not</em> change the values of these constants between - * releases. - */ -public class SWT { - - /* Widget Event Constants */ - - /** - * The null event type (value is 0). - * - * @since 3.0 - */ - public static final int None = 0; - - /** - * The key down event type (value is 1). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addKeyListener - * @see org.eclipse.swt.widgets.Tracker#addKeyListener - * @see org.eclipse.swt.events.KeyListener#keyPressed - * @see org.eclipse.swt.events.KeyEvent - */ - public static final int KeyDown = 1; - - /** - * The key up event type (value is 2). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addKeyListener - * @see org.eclipse.swt.widgets.Tracker#addKeyListener - * @see org.eclipse.swt.events.KeyListener#keyReleased - * @see org.eclipse.swt.events.KeyEvent - */ - public static final int KeyUp = 2; - - /** - * The mouse down event type (value is 3). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseListener - * @see org.eclipse.swt.events.MouseListener#mouseDown - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseDown = 3; - - /** - * The mouse up event type (value is 4). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseListener - * @see org.eclipse.swt.events.MouseListener#mouseUp - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseUp = 4; - - /** - * The mouse move event type (value is 5). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseMoveListener - * @see org.eclipse.swt.events.MouseMoveListener#mouseMove - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseMove = 5; - - /** - * The mouse enter event type (value is 6). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseTrackListener - * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseEnter = 6; - - /** - * The mouse exit event type (value is 7). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseTrackListener - * @see org.eclipse.swt.events.MouseTrackListener#mouseExit - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseExit = 7; - - /** - * The mouse double click event type (value is 8). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseListener - * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseDoubleClick = 8; - - /** - * The paint event type (value is 9). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addPaintListener - * @see org.eclipse.swt.events.PaintListener#paintControl - * @see org.eclipse.swt.events.PaintEvent - */ - public static final int Paint = 9; - - /** - * The move event type (value is 10). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addControlListener - * @see org.eclipse.swt.widgets.TableColumn#addControlListener - * @see org.eclipse.swt.widgets.Tracker#addControlListener - * @see org.eclipse.swt.widgets.TreeColumn#addControlListener - * @see org.eclipse.swt.events.ControlListener#controlMoved - * @see org.eclipse.swt.events.ControlEvent - */ - public static final int Move = 10; - - /** - * The resize event type (value is 11). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addControlListener - * @see org.eclipse.swt.widgets.TableColumn#addControlListener - * @see org.eclipse.swt.widgets.Tracker#addControlListener - * @see org.eclipse.swt.widgets.TreeColumn#addControlListener - * @see org.eclipse.swt.events.ControlListener#controlResized - * @see org.eclipse.swt.events.ControlEvent - */ - public static final int Resize = 11; - - /** - * The dispose event type (value is 12). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Widget#addDisposeListener - * @see org.eclipse.swt.events.DisposeListener#widgetDisposed - * @see org.eclipse.swt.events.DisposeEvent - */ - public static final int Dispose = 12; - - /** - * The selection event type (value is 13). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Button#addSelectionListener - * @see org.eclipse.swt.widgets.Combo#addSelectionListener - * @see org.eclipse.swt.widgets.CoolItem#addSelectionListener - * @see org.eclipse.swt.widgets.Link#addSelectionListener - * @see org.eclipse.swt.widgets.List#addSelectionListener - * @see org.eclipse.swt.widgets.MenuItem#addSelectionListener - * @see org.eclipse.swt.widgets.Sash#addSelectionListener - * @see org.eclipse.swt.widgets.Scale#addSelectionListener - * @see org.eclipse.swt.widgets.ScrollBar#addSelectionListener - * @see org.eclipse.swt.widgets.Slider#addSelectionListener - * @see org.eclipse.swt.widgets.TabFolder#addSelectionListener - * @see org.eclipse.swt.widgets.Table#addSelectionListener - * @see org.eclipse.swt.widgets.TableColumn#addSelectionListener - * @see org.eclipse.swt.widgets.ToolItem#addSelectionListener - * @see org.eclipse.swt.widgets.TrayItem#addSelectionListener - * @see org.eclipse.swt.widgets.Tree#addSelectionListener - * @see org.eclipse.swt.widgets.TreeColumn#addSelectionListener - * @see org.eclipse.swt.events.SelectionListener#widgetSelected - * @see org.eclipse.swt.events.SelectionEvent - */ - public static final int Selection = 13; - - /** - * The default selection event type (value is 14). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Combo#addSelectionListener - * @see org.eclipse.swt.widgets.List#addSelectionListener - * @see org.eclipse.swt.widgets.Spinner#addSelectionListener - * @see org.eclipse.swt.widgets.Table#addSelectionListener - * @see org.eclipse.swt.widgets.Text#addSelectionListener - * @see org.eclipse.swt.widgets.TrayItem#addSelectionListener - * @see org.eclipse.swt.widgets.Tree#addSelectionListener - * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected - * @see org.eclipse.swt.events.SelectionEvent - */ - public static final int DefaultSelection = 14; - - /** - * The focus in event type (value is 15). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addFocusListener - * @see org.eclipse.swt.events.FocusListener#focusGained - * @see org.eclipse.swt.events.FocusEvent - */ - public static final int FocusIn = 15; - - /** - * The focus out event type (value is 16). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addFocusListener - * @see org.eclipse.swt.events.FocusListener#focusLost - * @see org.eclipse.swt.events.FocusEvent - */ - public static final int FocusOut = 16; - - /** - * The expand event type (value is 17). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Tree#addTreeListener - * @see org.eclipse.swt.events.TreeListener#treeExpanded - * @see org.eclipse.swt.events.TreeEvent - */ - public static final int Expand = 17; - - /** - * The collapse event type (value is 18). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Tree#addTreeListener - * @see org.eclipse.swt.events.TreeListener#treeCollapsed - * @see org.eclipse.swt.events.TreeEvent - */ - public static final int Collapse = 18; - - /** - * The iconify event type (value is 19). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Shell#addShellListener - * @see org.eclipse.swt.events.ShellListener#shellIconified - * @see org.eclipse.swt.events.ShellEvent - */ - public static final int Iconify = 19; - - /** - * The de-iconify event type (value is 20). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Shell#addShellListener - * @see org.eclipse.swt.events.ShellListener#shellDeiconified - * @see org.eclipse.swt.events.ShellEvent - */ - public static final int Deiconify = 20; - - /** - * The close event type (value is 21). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Shell#addShellListener - * @see org.eclipse.swt.events.ShellListener#shellClosed - * @see org.eclipse.swt.events.ShellEvent - */ - public static final int Close = 21; - - /** - * The show event type (value is 22). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Menu#addMenuListener - * @see org.eclipse.swt.events.MenuListener#menuShown - * @see org.eclipse.swt.events.MenuEvent - */ - public static final int Show = 22; - - /** - * The hide event type (value is 23). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Menu#addMenuListener - * @see org.eclipse.swt.events.MenuListener#menuHidden - * @see org.eclipse.swt.events.MenuEvent - */ - public static final int Hide = 23; - - /** - * The modify event type (value is 24). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Combo#addModifyListener - * @see org.eclipse.swt.widgets.Spinner#addModifyListener - * @see org.eclipse.swt.widgets.Text#addModifyListener - * @see org.eclipse.swt.events.ModifyListener#modifyText - * @see org.eclipse.swt.events.ModifyEvent - */ - public static final int Modify = 24; - - /** - * The verify event type (value is 25). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.custom.CCombo#addVerifyListener - * @see org.eclipse.swt.widgets.Combo#addVerifyListener - * @see org.eclipse.swt.custom.StyledText#addVerifyListener - * @see org.eclipse.swt.widgets.Text#addVerifyListener - * @see org.eclipse.swt.events.VerifyListener#verifyText - * @see org.eclipse.swt.events.VerifyEvent - */ - public static final int Verify = 25; - - /** - * The activate event type (value is 26). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Shell#addShellListener - * @see org.eclipse.swt.events.ShellListener#shellActivated - * @see org.eclipse.swt.events.ShellEvent - */ - public static final int Activate = 26; - - /** - * The deactivate event type (value is 27). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Shell#addShellListener - * @see org.eclipse.swt.events.ShellListener#shellDeactivated - * @see org.eclipse.swt.events.ShellEvent - */ - public static final int Deactivate = 27; - - /** - * The help event type (value is 28). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addHelpListener - * @see org.eclipse.swt.widgets.Menu#addHelpListener - * @see org.eclipse.swt.widgets.MenuItem#addHelpListener - * @see org.eclipse.swt.events.HelpListener#helpRequested - * @see org.eclipse.swt.events.HelpEvent - */ - public static final int Help = 28; - - /** - * The drag detect event type (value is 29). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addDragDetectListener - * @see org.eclipse.swt.events.DragDetectListener#dragDetected - * @see org.eclipse.swt.events.DragDetectEvent - * @see org.eclipse.swt.dnd.DragSource - */ - public static final int DragDetect = 29; - - /** - * The arm event type (value is 30). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.MenuItem#addArmListener - * @see org.eclipse.swt.events.ArmListener#widgetArmed - * @see org.eclipse.swt.events.ArmEvent - */ - public static final int Arm = 30; - - /** - * The traverse event type (value is 31). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addTraverseListener - * @see org.eclipse.swt.events.TraverseListener#keyTraversed - * @see org.eclipse.swt.events.TraverseEvent - */ - public static final int Traverse = 31; - - /** - * The mouse hover event type (value is 32). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Control#addMouseTrackListener - * @see org.eclipse.swt.events.MouseTrackListener#mouseHover - * @see org.eclipse.swt.events.MouseEvent - */ - public static final int MouseHover = 32; - - /** - * The hardware key down event type (value is 33). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - */ - public static final int HardKeyDown = 33; - - /** - * The hardware key up event type (value is 34). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - */ - public static final int HardKeyUp = 34; - - /** - * The menu detect event type (value is 35). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @since 3.0 - */ - public static final int MenuDetect = 35; - - /** - * The set data event type (value is 36). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @see org.eclipse.swt.widgets.Table - * @see org.eclipse.swt.widgets.Tree - * - * @since 3.0 - */ - public static final int SetData = 36; - - /** - * The mouse wheel event type (value is 37). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @since 3.1 - */ - public static final int MouseWheel = 37; - - /** - * The settings changed event type (value is 39). - * <p> - * The settings changed event is sent when an operating system - * property, such as a system font or color, has been changed. - * The event occurs after the property has been changed, but - * before any widget is redrawn. Applications that cache operating - * system properties can use this event to update their caches. - * A specific property change can be detected by querying the - * new value of a property and comparing it with the equivalent - * cached value. The operating system automatically redraws and - * lays out all widgets after this event is sent. - * </p> - * - * @see org.eclipse.swt.widgets.Display#addListener - * @see org.eclipse.swt.widgets.Event - * - * @since 3.2 - */ - public static final int Settings = 39; - - /** - * The erase item event type (value is 40). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @since 3.2 - */ - public static final int EraseItem = 40; - - /** - * The measure item event type (value is 41). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @since 3.2 - */ - public static final int MeasureItem = 41; - - /** - * The paint item event type (value is 42). - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @since 3.2 - */ - public static final int PaintItem = 42; - - /** - * The IME composition event type (value is 43). - * <p> - * The IME composition event is sent to allow - * custom text editors to implement in-line - * editing of international text. - * </p> - * - * The detail field indicates the action to be taken: - * <p><ul> - * <li>{@link SWT#COMPOSITION_CHANGED}</li> - * <li>{@link SWT#COMPOSITION_OFFSET}</li> - * <li>{@link SWT#COMPOSITION_SELECTION}</li> - * </ul></p> - * - * @see org.eclipse.swt.widgets.Widget#addListener - * @see org.eclipse.swt.widgets.Display#addFilter - * @see org.eclipse.swt.widgets.Event - * - * @since 3.4 - */ - public static final int ImeComposition = 43; - - /* Event Details */ - - /** - * The IME composition event detail that indicates - * a change in the IME composition. The text field - * of the event is the new composition text. - * The start and end indicate the offsets where the - * composition text should be inserted. - * The styles and ranges are stored in the IME - * object (value is 1). - * - * @see SWT#ImeComposition - * - * @since 3.4 - */ - public static final int COMPOSITION_CHANGED = 1; - - /** - * The IME composition event detail that indicates - * that the IME needs the offset for a given location. - * The x and y fields of the event are used by the - * application to determine the offset. - * - * The index field of the event should be set to the - * text offset at that location. The count field should - * be set to indicate whether the location is closer to - * the leading edge (0) or the trailing edge (1) (value is 2). - * - * @see SWT#ImeComposition - * @see org.eclipse.swt.graphics.TextLayout#getOffset(int, int, int[]) - * - * @since 3.4 - */ - public static final int COMPOSITION_OFFSET = 2; - - /** - * The IME composition event detail that indicates - * that IME needs the selected text and its start - * and end offsets (value is 3). - * - * @see SWT#ImeComposition - * - * @since 3.4 - */ - public static final int COMPOSITION_SELECTION = 3; - - /** - * Indicates that a user-interface component is being dragged, - * for example dragging the thumb of a scroll bar (value is 1). - */ - public static final int DRAG = 1; - - /** - * Event detail field that indicates a user-interface component - * state is selected (value is 1<<1). - * - * @since 3.2 - */ - public static final int SELECTED = 1 << 1; - - /** - * Event detail field that indicates a user-interface component - * state is focused (value is 1<<2). - * - * @since 3.2 - */ - public static final int FOCUSED = 1 << 2; - - /** - * Event detail field that indicates a user-interface component - * draws the background (value is 1<<3). - * - * @since 3.2 - */ - public static final int BACKGROUND = 1 << 3; - - /** - * Event detail field that indicates a user-interface component - * draws the foreground (value is 1<<4). - * - * @since 3.2 - */ - public static final int FOREGROUND = 1 << 4; - - /** - * Event detail field that indicates a user-interface component - * state is hot (value is 1<<5). - * - * @since 3.3 - */ - public static final int HOT = 1 << 5; - - /* This code is intentionally commented */ - //public static final int PRESSED = 1 << 3; - //public static final int ACTIVE = 1 << 4; - //public static final int DISABLED = 1 << 5; - //public static final int HOT = 1 << 6; - //public static final int DEFAULTED = 1 << 7; - - /** - * Traversal event detail field value indicating that no - * traversal action should be taken - * (value is 0). - */ - public static final int TRAVERSE_NONE = 0; - - /** - * Traversal event detail field value indicating that the - * key which designates that a dialog should be cancelled was - * pressed; typically, this is the ESC key - * (value is 1<<1). - */ - public static final int TRAVERSE_ESCAPE = 1 << 1; - - /** - * Traversal event detail field value indicating that the - * key which activates the default button in a dialog was - * pressed; typically, this is the ENTER key - * (value is 1<<2). - */ - public static final int TRAVERSE_RETURN = 1 << 2; - - /** - * Traversal event detail field value indicating that the - * key which designates that focus should be given to the - * previous tab group was pressed; typically, this is the - * SHIFT-TAB key sequence - * (value is 1<<3). - */ - public static final int TRAVERSE_TAB_PREVIOUS = 1 << 3; - - /** - * Traversal event detail field value indicating that the - * key which designates that focus should be given to the - * next tab group was pressed; typically, this is the - * TAB key - * (value is 1<<4). - */ - public static final int TRAVERSE_TAB_NEXT = 1 << 4; - - /** - * Traversal event detail field value indicating that the - * key which designates that focus should be given to the - * previous tab item was pressed; typically, this is either - * the LEFT-ARROW or UP-ARROW keys - * (value is 1<<5). - */ - public static final int TRAVERSE_ARROW_PREVIOUS = 1 << 5; - - /** - * Traversal event detail field value indicating that the - * key which designates that focus should be given to the - * previous tab item was pressed; typically, this is either - * the RIGHT-ARROW or DOWN-ARROW keys - * (value is 1<<6). - */ - public static final int TRAVERSE_ARROW_NEXT = 1 << 6; - - /** - * Traversal event detail field value indicating that a - * mnemonic key sequence was pressed - * (value is 1<<7). - */ - public static final int TRAVERSE_MNEMONIC = 1 << 7; - - /** - * Traversal event detail field value indicating that the - * key which designates that the previous page of a multi-page - * window should be shown was pressed; typically, this - * is the CTRL-PAGEUP key sequence - * (value is 1<<8). - */ - public static final int TRAVERSE_PAGE_PREVIOUS = 1 << 8; - - /** - * Traversal event detail field value indicating that the - * key which designates that the next page of a multi-page - * window should be shown was pressed; typically, this - * is the CTRL-PAGEDOWN key sequence - * (value is 1<<9). - */ - public static final int TRAVERSE_PAGE_NEXT = 1 << 9; - - /** - * A constant known to be zero (0), typically used in operations - * which take bit flags to indicate that "no bits are set". - */ - public static final int NONE = 0; - - /** - * A constant known to be zero (0), used in operations which - * take pointers to indicate a null argument. - */ - public static final int NULL = 0; - - /** - * Indicates that a default should be used (value is -1). - */ - public static final int DEFAULT = -1; - - /** - * Indicates that a property is off (value is 0). - * - * @since 3.1 - */ - public static final int OFF = 0; - - /** - * Indicates that a property is on (value is 1). - * - * @since 3.1 - */ - public static final int ON = 1; - - /** - * Indicates low quality (value is 1). - * - * @since 3.1 - */ - public static final int LOW = 1; - - /** - * Indicates high quality (value is 2). - * - * @since 3.1 - */ - public static final int HIGH = 2; - - /** - * Style constant for menu bar behavior (value is 1<<1). - * <p><b>Used By:</b><ul> - * <li><code>Menu</code></li> - * </ul></p> - */ - public static final int BAR = 1 << 1; - - /** - * Style constant for drop down menu/list behavior (value is 1<<2). - * <br>Note that for <code>DateTime</code> this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Menu</code></li> - * <li><code>ToolItem</code></li> - * <li><code>CoolItem</code></li> - * <li><code>Combo</code></li> - * <li><code>DateTime</code></li> - * </ul></p> - */ - public static final int DROP_DOWN = 1 << 2; - - /** - * Style constant for pop up menu behavior (value is 1<<3). - * <p><b>Used By:</b><ul> - * <li><code>Menu</code></li> - * </ul></p> - */ - public static final int POP_UP = 1 << 3; - - /** - * Style constant for line separator behavior (value is 1<<1). - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>MenuItem</code></li> - * <li><code>ToolItem</code></li> - * </ul></p> - */ - public static final int SEPARATOR = 1 << 1; - - /** - * Style constant for toggle button behavior (value is 1<<1). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * </ul></p> - */ - public static final int TOGGLE = 1 << 1; - - /** - * Style constant for arrow button behavior (value is 1<<2). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * </ul></p> - */ - public static final int ARROW = 1 << 2; - - /** - * Style constant for push button behavior (value is 1<<3). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>MenuItem</code></li> - * <li><code>ToolItem</code></li> - * </ul></p> - */ - public static final int PUSH = 1 << 3; - - /** - * Style constant for radio button behavior (value is 1<<4). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>MenuItem</code></li> - * <li><code>ToolItem</code></li> - * </ul></p> - */ - public static final int RADIO = 1 << 4; - - /** - * Style constant for check box behavior (value is 1<<5). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>MenuItem</code></li> - * <li><code>ToolItem</code></li> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * </ul></p> - */ - public static final int CHECK = 1 << 5; - - /** - * Style constant for cascade behavior (value is 1<<6). - * <p><b>Used By:</b><ul> - * <li><code>MenuItem</code></li> - * </ul></p> - */ - public static final int CASCADE = 1 << 6; - - /** - * Style constant for multi-selection behavior in lists - * and multiple line support on text fields (value is 1<<1). - * <p><b>Used By:</b><ul> - * <li><code>Text</code></li> - * <li><code>List</code></li> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * <li><code>FileDialog</code></li> - * </ul></p> - */ - public static final int MULTI = 1 << 1; - - /** - * Style constant for single selection behavior in lists - * and single line support on text fields (value is 1<<2). - * <p><b>Used By:</b><ul> - * <li><code>Text</code></li> - * <li><code>List</code></li> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * </ul></p> - */ - public static final int SINGLE = 1 << 2; - - /** - * Style constant for read-only behavior (value is 1<<3). - * <p><b>Used By:</b><ul> - * <li><code>Combo</code></li> - * <li><code>Text</code></li> - * </ul></p> - */ - public static final int READ_ONLY = 1 << 3; - - /** - * Style constant for automatic line wrap behavior (value is 1<<6). - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>Text</code></li> - * <li><code>ToolBar</code></li> - * <li><code>Spinner</code></li> - * </ul></p> - */ - public static final int WRAP = 1 << 6; - - /** - * Style constant for search behavior (value is 1<<7). - * <p><b>Used By:</b><ul> - * <li><code>Text</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int SEARCH = 1 << 7; - - /** - * Style constant for simple (not drop down) behavior (value is 1<<6). - * <p><b>Used By:</b><ul> - * <li><code>Combo</code></li> - * </ul></p> - */ - public static final int SIMPLE = 1 << 6; - - /** - * Style constant for password behavior (value is 1<<22). - * <p><b>Used By:</b><ul> - * <li><code>Text</code></li> - * </ul></p> - * - * @since 3.0 - */ - public static final int PASSWORD = 1 << 22; - - /** - * Style constant for shadow in behavior (value is 1<<2). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>Group</code></li> - * </ul></p> - */ - public static final int SHADOW_IN = 1 << 2; - - /** - * Style constant for shadow out behavior (value is 1<<3). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>Group</code></li> - * <li><code>ToolBar</code></li> - * </ul></p> - */ - public static final int SHADOW_OUT = 1 << 3; - - /** - * Style constant for shadow etched in behavior (value is 1<<4). - * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif. - * <p><b>Used By:</b><ul> - * <li><code>Group</code></li> - * </ul></p> - */ - public static final int SHADOW_ETCHED_IN = 1 << 4; - - /** - * Style constant for shadow etched out behavior (value is 1<<6). - * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif. - * <p><b>Used By:</b><ul> - * <li><code>Group</code></li> - * </ul></p> - */ - public static final int SHADOW_ETCHED_OUT = 1 << 6; - - /** - * Style constant for no shadow behavior (value is 1<<5). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>Group</code></li> - * </ul></p> - */ - public static final int SHADOW_NONE = 1 << 5; - - /** - * Style constant for progress bar behavior (value is 1<<1). - * <p><b>Used By:</b><ul> - * <li><code>ProgressBar</code></li> - * </ul></p> - */ - public static final int INDETERMINATE = 1 << 1; - - /** - * Style constant for tool window behavior (value is 1<<2). - * <p> - * A tool window is a window intended to be used as a floating toolbar. - * It typically has a title bar that is shorter than a normal title bar, - * and the window title is typically drawn using a smaller font. - * <br>Note that this is a <em>HINT</em>. - * </p><p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int TOOL = 1 << 2; - - /** - * Style constant to ensure no trimmings are used (value is 1<<3). - * <br>Note that this overrides all other trim styles. - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int NO_TRIM = 1 << 3; - - /** - * Style constant for resize box trim (value is 1<<4). - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * <li><code>Tracker</code></li> - * </ul></p> - */ - public static final int RESIZE = 1 << 4; - - /** - * Style constant for title area trim (value is 1<<5). - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int TITLE = 1 << 5; - - /** - * Style constant for close box trim (value is 1<<6, - * since we do not distinguish between CLOSE style and MENU style). - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int CLOSE = 1 << 6; - - /** - * Style constant for shell menu trim (value is 1<<6, - * since we do not distinguish between CLOSE style and MENU style). - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int MENU = CLOSE; - - /** - * Style constant for minimize box trim (value is 1<<7). - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int MIN = 1 << 7; - - /** - * Style constant for maximize box trim (value is 1<<10). - * <p><b>Used By:</b><ul> - * <li><code>Decorations</code> and subclasses</li> - * </ul></p> - */ - public static final int MAX = 1 << 10; - - /** - * Style constant for horizontal scrollbar behavior (value is 1<<8). - * <p><b>Used By:</b><ul> - * <li><code>Scrollable</code> and subclasses</li> - * </ul></p> - */ - public static final int H_SCROLL = 1 << 8; - - /** - * Style constant for vertical scrollbar behavior (value is 1<<9). - * <p><b>Used By:</b><ul> - * <li><code>Scrollable</code> and subclasses</li> - * </ul></p> - */ - public static final int V_SCROLL = 1 << 9; - - /** - * Style constant for no scrollbar behavior (value is 1<<4). - * <p> - * When neither H_SCROLL or V_SCROLL are specified, controls - * are free to create the default scroll bars for the control. - * Using NO_SCROLL overrides the default and forces the control - * to have no scroll bars. - * - * <b>Used By:</b><ul> - * <li><code>Tree</code></li> - * <li><code>Table</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int NO_SCROLL = 1 << 4; - - /** - * Style constant for bordered behavior (value is 1<<11). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Control</code> and subclasses</li> - * </ul></p> - */ - public static final int BORDER = 1 << 11; - - /** - * Style constant indicating that the window manager should clip - * a widget's children with respect to its viewable area. (value is 1<<12). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Control</code> and subclasses</li> - * </ul></p> - */ - public static final int CLIP_CHILDREN = 1 << 12; - - /** - * Style constant indicating that the window manager should clip - * a widget's siblings with respect to its viewable area. (value is 1<<13). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Control</code> and subclasses</li> - * </ul></p> - */ - public static final int CLIP_SIBLINGS = 1 << 13; - - /** - * Style constant for always on top behavior (value is 1<<14). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Shell</code> and subclasses</li> - * </ul></p> - */ - public static final int ON_TOP = 1 << 14; - - /** - * Style constant for sheet window behavior (value is 1<<28). - * <p> - * A sheet window is a window intended to be used as a temporary modal - * dialog that is attached to a parent window. It is typically used to - * prompt the user before proceeding. The window trim, positioning and - * general look of a sheet window is platform specific. For example, - * on the Macintosh, at the time this documentation was written, the - * window title is not visible. - * <br>Note that this is a <em>HINT</em>. - * </p><p><b>Used By:</b><ul> - * <li><code>Dialog</code> and subclasses</li> - * <li><code>Shell</code> and subclasses</li> - * </ul></p> - * - * @since 3.5 - */ - public static final int SHEET = 1 << 28; - - /** - * Trim style convenience constant for the most common top level shell appearance - * (value is CLOSE|TITLE|MIN|MAX|RESIZE). - * <p><b>Used By:</b><ul> - * <li><code>Shell</code></li> - * </ul></p> - */ - public static final int SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE; - - /** - * Trim style convenience constant for the most common dialog shell appearance - * (value is CLOSE|TITLE|BORDER). - * <p><b>Used By:</b><ul> - * <li><code>Shell</code></li> - * </ul></p> - */ - public static final int DIALOG_TRIM = TITLE | CLOSE | BORDER; - - /** - * Style constant for modeless behavior (value is 0). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Dialog</code></li> - * <li><code>Shell</code></li> - * </ul></p> - */ - public static final int MODELESS = 0; - - /** - * Style constant for primary modal behavior (value is 1<<15). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Dialog</code></li> - * <li><code>Shell</code></li> - * </ul></p> - */ - public static final int PRIMARY_MODAL = 1 << 15; - - /** - * Style constant for application modal behavior (value is 1<<16). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Dialog</code></li> - * <li><code>Shell</code></li> - * </ul></p> - */ - public static final int APPLICATION_MODAL = 1 << 16; - - /** - * Style constant for system modal behavior (value is 1<<17). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Dialog</code></li> - * <li><code>Shell</code></li> - * </ul></p> - */ - public static final int SYSTEM_MODAL = 1 << 17; - - /** - * Style constant for selection hiding behavior when the widget loses focus (value is 1<<15). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Table</code></li> - * </ul></p> - */ - public static final int HIDE_SELECTION = 1 << 15; - - /** - * Style constant for full row selection behavior and - * selection constant indicating that a full line should be - * drawn. (value is 1<<16). - * <br>Note that for some widgets this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * <li><code>StyledText</code></li> - * <li><code>TextLayout</code></li> - * </ul></p> - */ - public static final int FULL_SELECTION = 1 << 16; - - /** - * Style constant for flat appearance. (value is 1<<23). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>ToolBar</code></li> - * </ul></p> - */ - public static final int FLAT = 1 << 23; - - /** - * Style constant for smooth appearance. (value is 1<<16). - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>ProgressBar</code></li> - * <li><code>Sash</code></li> - * </ul></p> - */ - public static final int SMOOTH = 1 << 16; - - /** - * Style constant for no background behavior (value is 1<<18). - * <p> - * By default, before a widget paints, the client area is filled with the current background. - * When this style is specified, the background is not filled, and the application is responsible - * for filling every pixel of the client area. - * This style might be used as an alternative to "double-buffering" in order to reduce flicker. - * This style does not mean "transparent" - widgets that are obscured will not draw through. - * </p><p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * </ul></p> - */ - public static final int NO_BACKGROUND = 1 << 18; - - /** - * Style constant for no focus from the mouse behavior (value is 1<<19). - * <p> - * Normally, when the user clicks on a control, focus is assigned to that - * control, providing the control has no children. Some controls, such as - * tool bars and sashes, don't normally take focus when the mouse is clicked - * or accept focus when assigned from within the program. This style allows - * Composites to implement "no focus" mouse behavior. - * - * <br>Note that this is a <em>HINT</em>. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * </ul></p> - */ - public static final int NO_FOCUS = 1 << 19; - - /** - * Style constant for no redraw on resize behavior (value is 1<<20). - * <p> - * This style stops the entire client area from being invalidated when the size - * of the Canvas changes. Specifically, when the size of the Canvas gets smaller, - * the SWT.Paint event is not sent. When it gets bigger, an SWT.Paint event is - * sent with a GC clipped to only the new areas to be painted. Without this - * style, the entire client area will be repainted. - * - * <br>Note that this is a <em>HINT</em>. - * </p><p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * </ul></p> - */ - public static final int NO_REDRAW_RESIZE = 1 << 20; - - /** - * Style constant for no paint event merging behavior (value is 1<<21). - * - * <br>Note that this is a <em>HINT</em>. - * <p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * </ul></p> - */ - public static final int NO_MERGE_PAINTS = 1 << 21; - - /** - * Style constant for preventing child radio group behavior (value is 1<<22). - * <p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * <li><code>Menu</code></li> - * </ul></p> - */ - public static final int NO_RADIO_GROUP = 1 << 22; - - /** - * Style constant for left to right orientation (value is 1<<25). - * <p> - * When orientation is not explicitly specified, orientation is - * inherited. This means that children will be assigned the - * orientation of their parent. To override this behavior and - * force an orientation for a child, explicitly set the orientation - * of the child when that child is created. - * <br>Note that this is a <em>HINT</em>. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>Control</code></li> - * <li><code>Menu</code></li> - * <li><code>GC</code></li> - * </ul></p> - * - * @since 2.1.2 - */ - public static final int LEFT_TO_RIGHT = 1 << 25; - - /** - * Style constant for right to left orientation (value is 1<<26). - * <p> - * When orientation is not explicitly specified, orientation is - * inherited. This means that children will be assigned the - * orientation of their parent. To override this behavior and - * force an orientation for a child, explicitly set the orientation - * of the child when that child is created. - * <br>Note that this is a <em>HINT</em>. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>Control</code></li> - * <li><code>Menu</code></li> - * <li><code>GC</code></li> - * </ul></p> - * - * @since 2.1.2 - */ - public static final int RIGHT_TO_LEFT = 1 << 26; - - /** - * Style constant to indicate coordinate mirroring (value is 1<<27). - * <p><b>Used By:</b><ul> - * <li><code>Control</code></li> - * <li><code>Menu</code></li> - * </ul></p> - * - * @since 2.1.2 - */ - public static final int MIRRORED = 1 << 27; - - /** - * Style constant to allow embedding (value is 1<<24). - * <p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * </ul></p> - * - * @since 3.0 - */ - public static final int EMBEDDED = 1 << 24; - - /** - * Style constant to allow virtual data (value is 1<<28). - * <p><b>Used By:</b><ul> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * </ul></p> - * - * @since 3.0 - */ - public static final int VIRTUAL = 1 << 28; - - /** - * Style constant to indicate double buffering (value is 1<<29). - * <p><b>Used By:</b><ul> - * <li><code>Control</code></li> - * </ul></p> - * - * @since 3.1 - */ - public static final int DOUBLE_BUFFERED = 1 << 29; - - /** - * Style constant for transparent behavior (value is 1<<30). - * <p> - * By default, before a widget paints, the client area is filled with the current background. - * When this style is specified, the background is not filled and widgets that are obscured - * will draw through. - * </p><p><b>Used By:</b><ul> - * <li><code>Composite</code></li> - * </ul></p> - * - * @since 3.4 - * - * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED - */ - public static final int TRANSPARENT = 1 << 30; - - /** - * Style constant for align up behavior (value is 1<<7, - * since align UP and align TOP are considered the same). - * <p><b>Used By:</b><ul> - * <li><code>Button</code> with <code>ARROW</code> style</li> - * <li><code>Tracker</code></li> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * </ul></p> - */ - public static final int UP = 1 << 7; - - /** - * Style constant to indicate single underline (value is 0). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int UNDERLINE_SINGLE = 0; - - /** - * Style constant to indicate double underline (value is 1). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int UNDERLINE_DOUBLE = 1; - - /** - * Style constant to indicate error underline (value is 2). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int UNDERLINE_ERROR = 2; - - /** - * Style constant to indicate squiggle underline (value is 3). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int UNDERLINE_SQUIGGLE = 3; - - /** - * Style constant to indicate link underline (value is 0). - * <p> - * If the text color or the underline color are not set in the range - * the usage of <code>UNDERLINE_LINK</code> will change these colors - * to the preferred link color of the platform.<br> - * Note that clients that use this style, such as <code>StyledText</code>, - * will include code to track the mouse and change the cursor to the hand - * cursor when mouse is over the link. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.5 - */ - public static final int UNDERLINE_LINK = 4; - - /** - * Style constant to indicate solid border (value is 1). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int BORDER_SOLID = 1; - - /** - * Style constant to indicate dashed border (value is 2). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int BORDER_DASH = 2; - - /** - * Style constant to indicate dotted border (value is 4). - * <p><b>Used By:</b><ul> - * <li><code>TextStyle</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int BORDER_DOT = 4; - - /** - * Style constant for align top behavior (value is 1<<7, - * since align UP and align TOP are considered the same). - * <p><b>Used By:</b><ul> - * <li><code>FormAttachment</code> in a <code>FormLayout</code></li> - * </ul></p> - */ - public static final int TOP = UP; - - /** - * Style constant for align down behavior (value is 1<<10, - * since align DOWN and align BOTTOM are considered the same). - * <p><b>Used By:</b><ul> - * <li><code>Button</code> with <code>ARROW</code> style</li> - * <li><code>Tracker</code></li> - * <li><code>Table</code></li> - * <li><code>Tree</code></li> - * </ul></p> - */ - public static final int DOWN = 1 << 10; - - /** - * Style constant for align bottom behavior (value is 1<<10, - * since align DOWN and align BOTTOM are considered the same). - * <p><b>Used By:</b><ul> - * <li><code>FormAttachment</code> in a <code>FormLayout</code></li> - * </ul></p> - */ - public static final int BOTTOM = DOWN; - - /** - * Style constant for leading alignment (value is 1<<14). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>Label</code></li> - * <li><code>TableColumn</code></li> - * <li><code>Tracker</code></li> - * <li><code>FormAttachment</code> in a <code>FormLayout</code></li> - * </ul></p> - * - * @since 2.1.2 - */ - public static final int LEAD = 1 << 14; - - /** - * Style constant for align left behavior (value is 1<<14). - * This is a synonym for LEAD (value is 1<<14). Newer - * applications should use LEAD instead of LEFT to make code more - * understandable on right-to-left platforms. - */ - public static final int LEFT = LEAD; - - /** - * Style constant for trailing alignment (value is 1<<17). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>Label</code></li> - * <li><code>TableColumn</code></li> - * <li><code>Tracker</code></li> - * <li><code>FormAttachment</code> in a <code>FormLayout</code></li> - * </ul></p> - * - * @since 2.1.2 - */ - public static final int TRAIL = 1 << 17; - - /** - * Style constant for align right behavior (value is 1<<17). - * This is a synonym for TRAIL (value is 1<<17). Newer - * applications should use TRAIL instead of RIGHT to make code more - * understandable on right-to-left platforms. - */ - public static final int RIGHT = TRAIL; - - /** - * Style constant for align center behavior (value is 1<<24). - * <p><b>Used By:</b><ul> - * <li><code>Button</code></li> - * <li><code>Label</code></li> - * <li><code>TableColumn</code></li> - * <li><code>FormAttachment</code> in a <code>FormLayout</code></li> - * </ul></p> - */ - public static final int CENTER = 1 << 24; - - /** - * Style constant for horizontal alignment or orientation behavior (value is 1<<8). - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>ProgressBar</code></li> - * <li><code>Sash</code></li> - * <li><code>Scale</code></li> - * <li><code>ScrollBar</code></li> - * <li><code>Slider</code></li> - * <li><code>ToolBar</code></li> - * <li><code>FillLayout</code> type</li> - * <li><code>RowLayout</code> type</li> - * </ul></p> - */ - public static final int HORIZONTAL = 1 << 8; - - /** - * Style constant for vertical alignment or orientation behavior (value is 1<<9). - * <p><b>Used By:</b><ul> - * <li><code>Label</code></li> - * <li><code>ProgressBar</code></li> - * <li><code>Sash</code></li> - * <li><code>Scale</code></li> - * <li><code>ScrollBar</code></li> - * <li><code>Slider</code></li> - * <li><code>ToolBar</code></li> - * <li><code>CoolBar</code></li> - * <li><code>FillLayout</code> type</li> - * <li><code>RowLayout</code> type</li> - * </ul></p> - */ - public static final int VERTICAL = 1 << 9; - - /** - * Style constant for date display (value is 1<<5). - * <p><b>Used By:</b><ul> - * <li><code>DateTime</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int DATE = 1 << 5; - - /** - * Style constant for time display (value is 1<<7). - * <p><b>Used By:</b><ul> - * <li><code>DateTime</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int TIME = 1 << 7; - - /** - * Style constant for calendar display (value is 1<<10). - * <p><b>Used By:</b><ul> - * <li><code>DateTime</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int CALENDAR = 1 << 10; - - /** - * Style constant for short date/time format (value is 1<<15). - * <p> - * A short date displays the month and year. - * A short time displays hours and minutes. - * <br>Note that this is a <em>HINT</em>. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>DateTime</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int SHORT = 1 << 15; - - /** - * Style constant for medium date/time format (value is 1<<16). - * <p> - * A medium date displays the day, month and year. - * A medium time displays hours, minutes, and seconds. - * <br>Note that this is a <em>HINT</em>. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>DateTime</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int MEDIUM = 1 << 16; - - /** - * Style constant for long date/time format (value is 1<<28). - * <p> - * A long date displays the day, month and year. - * A long time displays hours, minutes, and seconds. - * The day and month names may be displayed. - * <br>Note that this is a <em>HINT</em>. - * </p> - * <p><b>Used By:</b><ul> - * <li><code>DateTime</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int LONG = 1 << 28; - - /** - * Style constant specifying that a Browser should use a Mozilla GRE - * for rendering its content (value is 1<<15). - * <p> - * <p><b>Used By:</b><ul> - * <li><code>Browser</code></li> - * </ul></p> - * - * @since 3.3 - */ - public static final int MOZILLA = 1 << 15; - - /** - * Style constant for balloon behavior (value is 1<<12). - * <p><b>Used By:</b><ul> - * <li><code>ToolTip</code></li> - * </ul></p> - * - * @since 3.2 - */ - public static final int BALLOON = 1 << 12; - - /** - * Style constant for vertical alignment or orientation behavior (value is 1). - * <p><b>Used By:</b><ul> - * <li><code>GridLayout</code> type</li> - * </ul></p> - */ - public static final int BEGINNING = 1; - - /** - * Style constant for vertical alignment or orientation behavior (value is 4). - * <p><b>Used By:</b><ul> - * <li><code>GridLayout</code> type</li> - * </ul></p> - */ - public static final int FILL = 4; - - /** - * Input Method Editor style constant for double byte - * input behavior (value is 1<<1). - */ - public static final int DBCS = 1 << 1; - - /** - * Input Method Editor style constant for alpha - * input behavior (value is 1<<2). - */ - public static final int ALPHA = 1 << 2; - - /** - * Input Method Editor style constant for native - * input behavior (value is 1<<3). - */ - public static final int NATIVE = 1 << 3; - - /** - * Input Method Editor style constant for phonetic - * input behavior (value is 1<<4). - */ - public static final int PHONETIC = 1 << 4; - - /** - * Input Method Editor style constant for romanicized - * input behavior (value is 1<<5). - */ - public static final int ROMAN = 1 << 5; - - /** - * ASCII character convenience constant for the backspace character - * (value is the <code>char</code> '\b'). - */ - public static final char BS = '\b'; - - /** - * ASCII character convenience constant for the carriage return character - * (value is the <code>char</code> '\r'). - */ - public static final char CR = '\r'; - - /** - * ASCII character convenience constant for the delete character - * (value is the <code>char</code> with value 127). - */ - public static final char DEL = 0x7F; - - /** - * ASCII character convenience constant for the escape character - * (value is the <code>char</code> with value 27). - */ - public static final char ESC = 0x1B; - - /** - * ASCII character convenience constant for the line feed character - * (value is the <code>char</code> '\n'). - */ - public static final char LF = '\n'; - - /** - * ASCII character convenience constant for the tab character - * (value is the <code>char</code> '\t'). - * - * @since 2.1 - */ - public static final char TAB = '\t'; - - /** - * keyboard and/or mouse event mask indicating that the ALT key - * was pushed on the keyboard when the event was generated - * (value is 1<<16). - */ - public static final int ALT = 1 << 16; - - /** - * Keyboard and/or mouse event mask indicating that the SHIFT key - * was pushed on the keyboard when the event was generated - * (value is 1<<17). - */ - public static final int SHIFT = 1 << 17; - - /** - * Keyboard and/or mouse event mask indicating that the CTRL key - * was pushed on the keyboard when the event was generated - * (value is 1<<18). - */ - public static final int CTRL = 1 << 18; - - /** - * Keyboard and/or mouse event mask indicating that the CTRL key - * was pushed on the keyboard when the event was generated. This - * is a synonym for CTRL (value is 1<<18). - */ - public static final int CONTROL = CTRL; - - /** - * Keyboard and/or mouse event mask indicating that the COMMAND key - * was pushed on the keyboard when the event was generated - * (value is 1<<22). - * - * @since 2.1 - */ - public static final int COMMAND = 1 << 22; - - /** - * Keyboard and/or mouse event mask indicating all possible - * keyboard modifiers. - * - * To allow for the future, this mask is intended to be used in - * place of code that references each individual keyboard mask. - * For example, the following expression will determine whether - * any modifier is pressed and will continue to work as new modifier - * masks are added. - * - * <code>(stateMask & SWT.MODIFIER_MASK) != 0</code>. - * - * @since 2.1 - */ - public static final int MODIFIER_MASK; - - /** - * Keyboard and/or mouse event mask indicating that mouse button one - * was pushed when the event was generated. (value is 1<<19). - */ - public static final int BUTTON1 = 1 << 19; - - /** - * Keyboard and/or mouse event mask indicating that mouse button two - * was pushed when the event was generated. (value is 1<<20). - */ - public static final int BUTTON2 = 1 << 20; - - /** - * Keyboard and/or mouse event mask indicating that mouse button three - * was pushed when the event was generated. (value is 1<<21). - */ - public static final int BUTTON3 = 1 << 21; - - /** - * Keyboard and/or mouse event mask indicating that mouse button four - * was pushed when the event was generated. (value is 1<<23). - * - * @since 3.1 - */ - public static final int BUTTON4 = 1 << 23; - - /** - * Keyboard and/or mouse event mask indicating that mouse button five - * was pushed when the event was generated. (value is 1<<25). - * - * @since 3.1 - */ - public static final int BUTTON5 = 1 << 25; - - /** - * Keyboard and/or mouse event mask indicating all possible - * mouse buttons. - * - * To allow for the future, this mask is intended to be used - * in place of code that references each individual button mask. - * For example, the following expression will determine whether - * any button is pressed and will continue to work as new button - * masks are added. - * - * <code>(stateMask & SWT.BUTTON_MASK) != 0</code>. - * - * @since 2.1 - */ - public static final int BUTTON_MASK; - - /** - * Keyboard and/or mouse event mask indicating that the MOD1 key - * was pushed on the keyboard when the event was generated. - * - * This is the primary keyboard modifier for the platform. - * - * @since 2.1 - */ - public static final int MOD1; - - /** - * Keyboard and/or mouse event mask indicating that the MOD2 key - * was pushed on the keyboard when the event was generated. - * - * This is the secondary keyboard modifier for the platform. - * - * @since 2.1 - */ - public static final int MOD2; - - /** - * Keyboard and/or mouse event mask indicating that the MOD3 key - * was pushed on the keyboard when the event was generated. - * - * @since 2.1 - */ - public static final int MOD3; - - /** - * Keyboard and/or mouse event mask indicating that the MOD4 key - * was pushed on the keyboard when the event was generated. - * - * @since 2.1 - */ - public static final int MOD4; - - /** - * Constants to indicate line scrolling (value is 1). - * <p><b>Used By:</b><ul> - * <li><code>Control</code></li> - * </ul></p> - * - * @since 3.1 - */ - public static final int SCROLL_LINE = 1; - - /** - * Constants to indicate page scrolling (value is 2). - * <p><b>Used By:</b><ul> - * <li><code>Control</code></li> - * </ul></p> - * - * @since 3.1 - */ - public static final int SCROLL_PAGE = 2; - - /** - * Accelerator constant used to differentiate a key code from a - * unicode character. - * - * If this bit is set, then the key stroke - * portion of an accelerator represents a key code. If this bit - * is not set, then the key stroke portion of an accelerator is - * a unicode character. - * - * The following expression is false: - * - * <code>((SWT.MOD1 | SWT.MOD2 | 'T') & SWT.KEYCODE_BIT) != 0</code>. - * - * The following expression is true: - * - * <code>((SWT.MOD3 | SWT.F2) & SWT.KEYCODE_BIT) != 0</code>. - * - * (value is (1<<24)) - * - * @since 2.1 - */ - public static final int KEYCODE_BIT = (1 << 24); - - /** - * Accelerator constant used to extract the key stroke portion of - * an accelerator. - * - * The key stroke may be a key code or a unicode - * value. If the key stroke is a key code <code>KEYCODE_BIT</code> - * will be set. - * - * @since 2.1 - */ - public static final int KEY_MASK = KEYCODE_BIT + 0xFFFF; - - /** - * Keyboard event constant representing the UP ARROW key - * (value is (1<<24)+1). - */ - public static final int ARROW_UP = KEYCODE_BIT + 1; - - /** - * Keyboard event constant representing the DOWN ARROW key - * (value is (1<<24)+2). - */ - public static final int ARROW_DOWN = KEYCODE_BIT + 2; - - /** - * Keyboard event constant representing the LEFT ARROW key - * (value is (1<<24)+3). - */ - public static final int ARROW_LEFT = KEYCODE_BIT + 3; - - /** - * Keyboard event constant representing the RIGHT ARROW key - * (value is (1<<24)+4). - */ - public static final int ARROW_RIGHT = KEYCODE_BIT + 4; - - /** - * Keyboard event constant representing the PAGE UP key - * (value is (1<<24)+5). - */ - public static final int PAGE_UP = KEYCODE_BIT + 5; - - /** - * Keyboard event constant representing the PAGE DOWN key - * (value is (1<<24)+6). - */ - public static final int PAGE_DOWN = KEYCODE_BIT + 6; - - /** - * Keyboard event constant representing the HOME key - * (value is (1<<24)+7). - */ - public static final int HOME = KEYCODE_BIT + 7; - - /** - * Keyboard event constant representing the END key - * (value is (1<<24)+8). - */ - public static final int END = KEYCODE_BIT + 8; - - /** - * Keyboard event constant representing the INSERT key - * (value is (1<<24)+9). - */ - public static final int INSERT = KEYCODE_BIT + 9; - - /** - * Keyboard event constant representing the F1 key - * (value is (1<<24)+10). - */ - public static final int F1 = KEYCODE_BIT + 10; - - /** - * Keyboard event constant representing the F2 key - * (value is (1<<24)+11). - */ - public static final int F2 = KEYCODE_BIT + 11; - - /** - * Keyboard event constant representing the F3 key - * (value is (1<<24)+12). - */ - public static final int F3 = KEYCODE_BIT + 12; - - /** - * Keyboard event constant representing the F4 key - * (value is (1<<24)+13). - */ - public static final int F4 = KEYCODE_BIT + 13; - - /** - * Keyboard event constant representing the F5 key - * (value is (1<<24)+14). - */ - public static final int F5 = KEYCODE_BIT + 14; - - /** - * Keyboard event constant representing the F6 key - * (value is (1<<24)+15). - */ - public static final int F6 = KEYCODE_BIT + 15; - - /** - * Keyboard event constant representing the F7 key - * (value is (1<<24)+16). - */ - public static final int F7 = KEYCODE_BIT + 16; - - /** - * Keyboard event constant representing the F8 key - * (value is (1<<24)+17). - */ - public static final int F8 = KEYCODE_BIT + 17; - - /** - * Keyboard event constant representing the F9 key - * (value is (1<<24)+18). - */ - public static final int F9 = KEYCODE_BIT + 18; - - /** - * Keyboard event constant representing the F10 key - * (value is (1<<24)+19). - */ - public static final int F10 = KEYCODE_BIT + 19; - - /** - * Keyboard event constant representing the F11 key - * (value is (1<<24)+20). - */ - public static final int F11 = KEYCODE_BIT + 20; - - /** - * Keyboard event constant representing the F12 key - * (value is (1<<24)+21). - */ - public static final int F12 = KEYCODE_BIT + 21; - - /** - * Keyboard event constant representing the F13 key - * (value is (1<<24)+22). - * - * @since 3.0 - */ - public static final int F13 = KEYCODE_BIT + 22; - - /** - * Keyboard event constant representing the F14 key - * (value is (1<<24)+23). - * - * @since 3.0 - */ - public static final int F14 = KEYCODE_BIT + 23; - - /** - * Keyboard event constant representing the F15 key - * (value is (1<<24)+24). - * - * @since 3.0 - */ - public static final int F15 = KEYCODE_BIT + 24; - - /** - * Keyboard event constant representing the numeric key - * pad multiply key (value is (1<<24)+42). - * - * @since 3.0 - */ - public static final int KEYPAD_MULTIPLY = KEYCODE_BIT + 42; - - /** - * Keyboard event constant representing the numeric key - * pad add key (value is (1<<24)+43). - * - * @since 3.0 - */ - public static final int KEYPAD_ADD = KEYCODE_BIT + 43; - - /** - * Keyboard event constant representing the numeric key - * pad subtract key (value is (1<<24)+45). - * - * @since 3.0 - */ - public static final int KEYPAD_SUBTRACT = KEYCODE_BIT + 45; - - /** - * Keyboard event constant representing the numeric key - * pad decimal key (value is (1<<24)+46). - * - * @since 3.0 - */ - public static final int KEYPAD_DECIMAL = KEYCODE_BIT + 46; - - /** - * Keyboard event constant representing the numeric key - * pad divide key (value is (1<<24)+47). - * - * @since 3.0 - */ - public static final int KEYPAD_DIVIDE = KEYCODE_BIT + 47; - - /** - * Keyboard event constant representing the numeric key - * pad zero key (value is (1<<24)+48). - * - * @since 3.0 - */ - public static final int KEYPAD_0 = KEYCODE_BIT + 48; - - /** - * Keyboard event constant representing the numeric key - * pad one key (value is (1<<24)+49). - * - * @since 3.0 - */ - public static final int KEYPAD_1 = KEYCODE_BIT + 49; - - /** - * Keyboard event constant representing the numeric key - * pad two key (value is (1<<24)+50). - * - * @since 3.0 - */ - public static final int KEYPAD_2 = KEYCODE_BIT + 50; - - /** - * Keyboard event constant representing the numeric key - * pad three key (value is (1<<24)+51). - * - * @since 3.0 - */ - public static final int KEYPAD_3 = KEYCODE_BIT + 51; - - /** - * Keyboard event constant representing the numeric key - * pad four key (value is (1<<24)+52). - * - * @since 3.0 - */ - public static final int KEYPAD_4 = KEYCODE_BIT + 52; - - /** - * Keyboard event constant representing the numeric key - * pad five key (value is (1<<24)+53). - * - * @since 3.0 - */ - public static final int KEYPAD_5 = KEYCODE_BIT + 53; - - /** - * Keyboard event constant representing the numeric key - * pad six key (value is (1<<24)+54). - * - * @since 3.0 - */ - public static final int KEYPAD_6 = KEYCODE_BIT + 54; - - /** - * Keyboard event constant representing the numeric key - * pad seven key (value is (1<<24)+55). - * - * @since 3.0 - */ - public static final int KEYPAD_7 = KEYCODE_BIT + 55; - - /** - * Keyboard event constant representing the numeric key - * pad eight key (value is (1<<24)+56). - * - * @since 3.0 - */ - public static final int KEYPAD_8 = KEYCODE_BIT + 56; - - /** - * Keyboard event constant representing the numeric key - * pad nine key (value is (1<<24)+57). - * - * @since 3.0 - */ - public static final int KEYPAD_9 = KEYCODE_BIT + 57; - - /** - * Keyboard event constant representing the numeric key - * pad equal key (value is (1<<24)+61). - * - * @since 3.0 - */ - public static final int KEYPAD_EQUAL = KEYCODE_BIT + 61; - - /** - * Keyboard event constant representing the numeric key - * pad enter key (value is (1<<24)+80). - * - * @since 3.0 - */ - public static final int KEYPAD_CR = KEYCODE_BIT + 80; - - /** - * Keyboard event constant representing the help - * key (value is (1<<24)+81). - * - * NOTE: The HELP key maps to the key labeled "help", - * not "F1". If your keyboard does not have a HELP key, - * you will never see this key press. To listen for - * help on a control, use SWT.Help. - * - * @since 3.0 - * - * @see SWT#Help - */ - public static final int HELP = KEYCODE_BIT + 81; - - /** - * Keyboard event constant representing the caps - * lock key (value is (1<<24)+82). - * - * @since 3.0 - */ - public static final int CAPS_LOCK = KEYCODE_BIT + 82; - - /** - * Keyboard event constant representing the num - * lock key (value is (1<<24)+83). - * - * @since 3.0 - */ - public static final int NUM_LOCK = KEYCODE_BIT + 83; - - /** - * Keyboard event constant representing the scroll - * lock key (value is (1<<24)+84). - * - * @since 3.0 - */ - public static final int SCROLL_LOCK = KEYCODE_BIT + 84; - - /** - * Keyboard event constant representing the pause - * key (value is (1<<24)+85). - * - * @since 3.0 - */ - public static final int PAUSE = KEYCODE_BIT + 85; - - /** - * Keyboard event constant representing the break - * key (value is (1<<24)+86). - * - * @since 3.0 - */ - public static final int BREAK = KEYCODE_BIT + 86; - - /** - * Keyboard event constant representing the print screen - * key (value is (1<<24)+87). - * - * @since 3.0 - */ - public static final int PRINT_SCREEN = KEYCODE_BIT + 87; - - /** - * The <code>MessageBox</code> style constant for error icon - * behavior (value is 1). - */ - public static final int ICON_ERROR = 1; - - /** - * The <code>MessageBox</code> style constant for information icon - * behavior (value is 1<<1). - */ - public static final int ICON_INFORMATION = 1 << 1; - - /** - * The <code>MessageBox</code> style constant for question icon - * behavior (value is 1<<2). - */ - public static final int ICON_QUESTION = 1 << 2; - - /** - * The <code>MessageBox</code> style constant for warning icon - * behavior (value is 1<<3). - */ - public static final int ICON_WARNING = 1 << 3; - - /** - * The <code>MessageBox</code> style constant for "working" icon - * behavior (value is 1<<4). - */ - public static final int ICON_WORKING = 1 << 4; - - /** - * The style constant for "search" icon. This style constant is - * used with <code>Text</code> in combination with <code>SWT.SEARCH - * </code> (value is 1<<9). - * <br>Note that this is a <em>HINT</em>. - * - * <p><b>Used By:</b><ul> - * <li><code>Text</code></li> - * </ul></p> - * - * @see #SEARCH - * @see #ICON_CANCEL - * - * @since 3.5 - */ - public static final int ICON_SEARCH = 1 << 9; - - /** - * The style constant for "cancel" icon. This style constant is - * used with <code>Text</code> in combination with <code>SWT.SEARCH - * </code> (value is 1<<8). - * <br>Note that this is a <em>HINT</em>. - * - * <p><b>Used By:</b><ul> - * <li><code>Text</code></li> - * </ul></p> - * - * @see #SEARCH - * @see #ICON_SEARCH - * - * @since 3.5 - */ - public static final int ICON_CANCEL = 1 << 8; - - - /** - * The <code>MessageBox</code> style constant for an OK button; - * valid combinations are OK, OK|CANCEL - * (value is 1<<5). - */ - public static final int OK = 1 << 5; - - /** - * The <code>MessageBox</code> style constant for YES button; - * valid combinations are YES|NO, YES|NO|CANCEL - * (value is 1<<6). - */ - public static final int YES = 1 << 6; - - /** - * The <code>MessageBox</code> style constant for NO button; - * valid combinations are YES|NO, YES|NO|CANCEL - * (value is 1<<7). - */ - public static final int NO = 1 << 7; - - /** - * The <code>MessageBox</code> style constant for a CANCEL button; - * valid combinations are OK|CANCEL, YES|NO|CANCEL, RETRY|CANCEL - * (value is 1<<8). - * - * <p><b>Used By:</b><ul> - * <li><code>MessageBox</code></li> - * </ul></p> - */ - public static final int CANCEL = 1 << 8; - - /** - * The <code>MessageBox</code> style constant for an ABORT button; - * the only valid combination is ABORT|RETRY|IGNORE - * (value is 1<<9). - */ - public static final int ABORT = 1 << 9; - - /** - * The <code>MessageBox</code> style constant for a RETRY button; - * valid combinations are ABORT|RETRY|IGNORE, RETRY|CANCEL - * (value is 1<<10). - */ - public static final int RETRY = 1 << 10; - - /** - * The <code>MessageBox</code> style constant for an IGNORE button; - * the only valid combination is ABORT|RETRY|IGNORE - * (value is 1<<11). - */ - public static final int IGNORE = 1 << 11; - - /** - * The <code>FileDialog</code> style constant for open file dialog behavior - * (value is 1<<12). - */ - public static final int OPEN = 1 << 12; - - /** - * The <code>FileDialog</code> style constant for save file dialog behavior - * (value is 1<<13). - */ - public static final int SAVE = 1 << 13; - - /** - * The <code>Composite</code> constant to indicate that - * an attribute (such as background) is not inherited - * by the children (value is 0). - * - * @since 3.2 - */ - public static final int INHERIT_NONE = 0; - - /** - * The <code>Composite</code> constant to indicate that - * an attribute (such as background) is inherited by - * children who choose this value as their "default" - * (value is 1). For example, a label child will - * typically choose to inherit the background color - * of a composite while a list or table will not. - * - * @since 3.2 - */ - public static final int INHERIT_DEFAULT = 1; - - /** - * The <code>Composite</code> constant to indicate that - * an attribute (such as background) is inherited by - * all children. - * - * @since 3.2 - */ - public static final int INHERIT_FORCE = 2; - - /** - * Default color white (value is 1). - */ - public static final int COLOR_WHITE = 1; - - /** - * Default color black (value is 2). - */ - public static final int COLOR_BLACK = 2; - - /** - * Default color red (value is 3). - */ - public static final int COLOR_RED = 3; - - /** - * Default color dark red (value is 4). - */ - public static final int COLOR_DARK_RED = 4; - - /** - * Default color green (value is 5). - */ - public static final int COLOR_GREEN = 5; - - /** - * Default color dark green (value is 6). - */ - public static final int COLOR_DARK_GREEN = 6; - - /** - * Default color yellow (value is 7). - */ - public static final int COLOR_YELLOW = 7; - - /** - * Default color dark yellow (value is 8). - */ - public static final int COLOR_DARK_YELLOW = 8; - - /** - * Default color blue (value is 9). - */ - public static final int COLOR_BLUE = 9; - - /** - * Default color dark blue (value is 10). - */ - public static final int COLOR_DARK_BLUE = 10; - - /** - * Default color magenta (value is 11). - */ - public static final int COLOR_MAGENTA = 11; - - /** - * Default color dark magenta (value is 12). - */ - public static final int COLOR_DARK_MAGENTA = 12; - - /** - * Default color cyan (value is 13). - */ - public static final int COLOR_CYAN = 13; - - /** - * Default color dark cyan (value is 14). - */ - public static final int COLOR_DARK_CYAN = 14; - - /** - * Default color gray (value is 15). - */ - public static final int COLOR_GRAY = 15; - - /** - * Default color dark gray (value is 16). - */ - public static final int COLOR_DARK_GRAY = 16; - - /* - * System Colors - * - * Dealing with system colors is an area where there are - * many platform differences. On some platforms, system - * colors can change dynamically while the program is - * running. On other platforms, system colors can be - * changed for all instances of a particular widget. - * Therefore, the only truly portable method to obtain - * a widget color query is to query the color from an - * instance of the widget. - * - * It is expected that the list of supported colors - * will grow over time. - */ - - /** - * System color used to paint dark shadow areas (value is 17). - */ - public static final int COLOR_WIDGET_DARK_SHADOW = 17; - - /** - * System color used to paint normal shadow areas (value is 18). - */ - public static final int COLOR_WIDGET_NORMAL_SHADOW = 18; - - /** - * System color used to paint light shadow areas (value is 19). - */ - public static final int COLOR_WIDGET_LIGHT_SHADOW = 19; - - /** - * System color used to paint highlight shadow areas (value is 20). - */ - public static final int COLOR_WIDGET_HIGHLIGHT_SHADOW = 20; - - /** - * System color used to paint foreground areas (value is 21). - */ - public static final int COLOR_WIDGET_FOREGROUND = 21; - - /** - * System color used to paint background areas (value is 22). - */ - public static final int COLOR_WIDGET_BACKGROUND = 22; - - /** - * System color used to paint border areas (value is 23). - */ - public static final int COLOR_WIDGET_BORDER = 23; - - /** - * System color used to paint list foreground areas (value is 24). - */ - public static final int COLOR_LIST_FOREGROUND = 24; - - /** - * System color used to paint list background areas (value is 25). - */ - public static final int COLOR_LIST_BACKGROUND = 25; - - /** - * System color used to paint list selection background areas (value is 26). - */ - public static final int COLOR_LIST_SELECTION = 26; - - /** - * System color used to paint list selected text (value is 27). - */ - public static final int COLOR_LIST_SELECTION_TEXT = 27; - - /** - * System color used to paint tooltip text (value is 28). - */ - public static final int COLOR_INFO_FOREGROUND = 28; - - /** - * System color used to paint tooltip background areas (value is 29). - */ - public static final int COLOR_INFO_BACKGROUND = 29; - - /** - * System color used to paint title text (value is 30). - */ - public static final int COLOR_TITLE_FOREGROUND = 30; - - /** - * System color used to paint title background areas (value is 31). - */ - public static final int COLOR_TITLE_BACKGROUND = 31; - - /** - * System color used to paint title background gradient (value is 32). - */ - public static final int COLOR_TITLE_BACKGROUND_GRADIENT = 32; - - /** - * System color used to paint inactive title text (value is 33). - */ - public static final int COLOR_TITLE_INACTIVE_FOREGROUND = 33; - - /** - * System color used to paint inactive title background areas (value is 34). - */ - public static final int COLOR_TITLE_INACTIVE_BACKGROUND = 34; - - /** - * System color used to paint inactive title background gradient (value is 35). - */ - public static final int COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = 35; - - /** - * Draw constant indicating whether the drawing operation - * should fill the background (value is 1<<0). - */ - public static final int DRAW_TRANSPARENT = 1 << 0; - - /** - * Draw constant indicating whether the string drawing operation - * should handle line-delimiters (value is 1<<1). - */ - public static final int DRAW_DELIMITER = 1 << 1; - - /** - * Draw constant indicating whether the string drawing operation - * should expand TAB characters (value is 1<<2). - */ - public static final int DRAW_TAB = 1 << 2; - - /** - * Draw constant indicating whether the string drawing operation - * should handle mnemonics (value is 1<<3). - */ - public static final int DRAW_MNEMONIC = 1 << 3; - - - /** - * Selection constant indicating that a line delimiter should be - * drawn (value is 1<<17). - * - * <p><b>Used By:</b><ul> - * <li><code>TextLayout</code></li> - * </ul></p> - * - * @see #FULL_SELECTION - * @see #LAST_LINE_SELECTION - * - * @since 3.3 - */ - public static final int DELIMITER_SELECTION = 1 << 17; - - /** - * Selection constant indicating that the last line is selected - * to the end and should be drawn using either a line delimiter - * or full line selection (value is 1<<20). - * - * <p><b>Used By:</b><ul> - * <li><code>TextLayout</code></li> - * </ul></p> - * - * @see #DELIMITER_SELECTION - * @see #FULL_SELECTION - * - * @since 3.3 - */ - public static final int LAST_LINE_SELECTION = 1 << 20; - - /** - * SWT error constant indicating that no error number was specified - * (value is 1). - */ - public static final int ERROR_UNSPECIFIED = 1; - - /** - * SWT error constant indicating that no more handles for an - * operating system resource are available - * (value is 2). - */ - public static final int ERROR_NO_HANDLES = 2; - - /** - * SWT error constant indicating that no more callback resources are available - * (value is 3). - */ - public static final int ERROR_NO_MORE_CALLBACKS = 3; - - /** - * SWT error constant indicating that a null argument was passed in - * (value is 4). - */ - public static final int ERROR_NULL_ARGUMENT = 4; - - /** - * SWT error constant indicating that an invalid argument was passed in - * (value is 5). - */ - public static final int ERROR_INVALID_ARGUMENT = 5; - - /** - * SWT error constant indicating that a value was found to be - * outside the allowable range - * (value is 6). - */ - public static final int ERROR_INVALID_RANGE = 6; - - /** - * SWT error constant indicating that a value which can not be - * zero was found to be - * (value is 7). - */ - public static final int ERROR_CANNOT_BE_ZERO = 7; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to provide the value of an item - * (value is 8). - */ - public static final int ERROR_CANNOT_GET_ITEM = 8; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to provide the selection - * (value is 9). - */ - public static final int ERROR_CANNOT_GET_SELECTION = 9; - - /** - * SWT error constant indicating that the matrix is not invertible - * (value is 10). - * - * @since 3.1 - */ - public static final int ERROR_CANNOT_INVERT_MATRIX = 10; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to provide the height of an item - * (value is 11). - */ - public static final int ERROR_CANNOT_GET_ITEM_HEIGHT = 11; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to provide the text of a widget - * (value is 12). - */ - public static final int ERROR_CANNOT_GET_TEXT = 12; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to set the text of a widget - * (value is 13). - */ - public static final int ERROR_CANNOT_SET_TEXT = 13; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to add an item - * (value is 14). - */ - public static final int ERROR_ITEM_NOT_ADDED = 14; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to remove an item - * (value is 15). - */ - public static final int ERROR_ITEM_NOT_REMOVED = 15; - - /** - * SWT error constant indicating that the graphics library - * is not available - * (value is 16). - */ - public static final int ERROR_NO_GRAPHICS_LIBRARY = 16; - - /** - * SWT error constant indicating that a particular feature has - * not been implemented on this platform - * (value is 20). - */ - public static final int ERROR_NOT_IMPLEMENTED = 20; - - /** - * SWT error constant indicating that a menu which needed - * to have the drop down style had some other style instead - * (value is 21). - */ - public static final int ERROR_MENU_NOT_DROP_DOWN = 21; - - /** - * SWT error constant indicating that an attempt was made to - * invoke an SWT operation which can only be executed by the - * user-interface thread from some other thread - * (value is 22). - */ - public static final int ERROR_THREAD_INVALID_ACCESS = 22; - - /** - * SWT error constant indicating that an attempt was made to - * invoke an SWT operation using a widget which had already - * been disposed - * (value is 24). - */ - public static final int ERROR_WIDGET_DISPOSED = 24; - - /** - * SWT error constant indicating that a menu item which needed - * to have the cascade style had some other style instead - * (value is 27). - */ - public static final int ERROR_MENUITEM_NOT_CASCADE = 27; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to set the selection of a widget - * (value is 28). - */ - public static final int ERROR_CANNOT_SET_SELECTION = 28; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to set the menu - * (value is 29). - */ - public static final int ERROR_CANNOT_SET_MENU = 29; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to set the enabled state - * (value is 30). - */ - public static final int ERROR_CANNOT_SET_ENABLED = 30; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to provide enabled/disabled state information - * (value is 31). - */ - public static final int ERROR_CANNOT_GET_ENABLED = 31; - - /** - * SWT error constant indicating that a provided widget can - * not be used as a parent in the current operation - * (value is 32). - */ - public static final int ERROR_INVALID_PARENT = 32; - - /** - * SWT error constant indicating that a menu which needed - * to have the menu bar style had some other style instead - * (value is 33). - */ - public static final int ERROR_MENU_NOT_BAR = 33; - - /** - * SWT error constant indicating that the underlying operating - * system was unable to provide count information - * (value is 36). - */ - public static final int ERROR_CANNOT_GET_COUNT = 36; - - /** - * SWT error constant indicating that a menu which needed - * to have the pop up menu style had some other style instead - * (value is 37). - */ - public static final int ERROR_MENU_NOT_POP_UP = 37; - - /** - * SWT error constant indicating that a graphics operation - * was attempted with an image of an unsupported depth - * (value is 38). - */ - public static final int ERROR_UNSUPPORTED_DEPTH = 38; - - /** - * SWT error constant indicating that an input/output operation - * failed during the execution of an SWT operation - * (value is 39). - */ - public static final int ERROR_IO = 39; - - /** - * SWT error constant indicating that a graphics operation - * was attempted with an image having an invalid format - * (value is 40). - */ - public static final int ERROR_INVALID_IMAGE = 40; - - /** - * SWT error constant indicating that a graphics operation - * was attempted with an image having a valid but unsupported - * format - * (value is 42). - */ - public static final int ERROR_UNSUPPORTED_FORMAT = 42; - - /** - * SWT error constant indicating that an attempt was made - * to subclass an SWT widget class without implementing the - * <code>checkSubclass()</code> method - * (value is 43). - * - * For additional information see the comment in - * <code>Widget.checkSubclass()</code>. - * - * @see org.eclipse.swt.widgets.Widget#checkSubclass - */ - public static final int ERROR_INVALID_SUBCLASS = 43; - - /** - * SWT error constant indicating that an attempt was made to - * invoke an SWT operation using a graphics object which had - * already been disposed - * (value is 44). - */ - public static final int ERROR_GRAPHIC_DISPOSED = 44; - - /** - * SWT error constant indicating that an attempt was made to - * invoke an SWT operation using a device which had already - * been disposed - * (value is 45). - */ - public static final int ERROR_DEVICE_DISPOSED = 45; - - /** - * SWT error constant indicating that an exception happened - * when executing a runnable - * (value is 46). - */ - public static final int ERROR_FAILED_EXEC = 46; - - /** - * SWT error constant indicating that an unsatisfied link - * error occurred while attempting to load a library - * (value is 47). - * - * @since 3.1 - */ - public static final int ERROR_FAILED_LOAD_LIBRARY = 47; - - /** - * SWT error constant indicating that a font is not valid - * (value is 48). - * - * @since 3.1 - */ - public static final int ERROR_INVALID_FONT = 48; - - /** - * SWT error constant indicating that an attempt was made to - * use an BrowserFunction object which had already been disposed - * (value is 49). - * - * @since 3.5 - */ - public static final int ERROR_FUNCTION_DISPOSED = 49; - - /** - * SWT error constant indicating that an exception happened - * when evaluating a javascript expression - * (value is 50). - * - * @since 3.5 - */ - public static final int ERROR_FAILED_EVALUATE = 50; - - /** - * SWT error constant indicating that an invalid value was returned - * (value is 51). - * - * @since 3.5 - */ - public static final int ERROR_INVALID_RETURN_VALUE = 51; - - /** - * Constant indicating that an image or operation is of type bitmap (value is 0). - */ - public static final int BITMAP = 0; - - /** - * Constant indicating that an image or operation is of type icon (value is 1). - */ - public static final int ICON = 1; - - /** - * The <code>Image</code> constructor argument indicating that - * the new image should be a copy of the image provided as - * an argument (value is 0). - */ - public static final int IMAGE_COPY = 0; - - /** - * The <code>Image</code> constructor argument indicating that - * the new image should have the appearance of a "disabled" - * (using the platform's rules for how this should look) - * copy of the image provided as an argument (value is 1). - */ - public static final int IMAGE_DISABLE = 1; - - /** - * The <code>Image</code> constructor argument indicating that - * the new image should have the appearance of a "gray scaled" - * copy of the image provided as an argument (value is 2). - */ - public static final int IMAGE_GRAY = 2; - - /** - * Constant to indicate an error state (value is 1). - * <p><b>Used By:</b><ul> - * <li><code>ProgressBar</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int ERROR = 1; - - /** - * Constant to a indicate a paused state (value is 4). - * <p><b>Used By:</b><ul> - * <li><code>ProgressBar</code></li> - * </ul></p> - * - * @since 3.4 - */ - public static final int PAUSED = 1 << 2; - - /** - * The font style constant indicating a normal weight, non-italic font - * (value is 0). This constant is also used with <code>ProgressBar</code> - * to indicate a normal state. - * <p><b>Used By:</b><ul> - * <li><code>ProgressBar</code></li> - * </ul></p> - */ - public static final int NORMAL = 0; - - /** - * The font style constant indicating a bold weight font - * (value is 1<<0). - */ - public static final int BOLD = 1 << 0; - - /** - * The font style constant indicating an italic font - * (value is 1<<1). - */ - public static final int ITALIC = 1 << 1; - - /** - * System arrow cursor (value is 0). - */ - public static final int CURSOR_ARROW = 0; - - /** - * System wait cursor (value is 1). - */ - public static final int CURSOR_WAIT = 1; - - /** - * System cross hair cursor (value is 2). - */ - public static final int CURSOR_CROSS = 2; - - /** - * System app startup cursor (value is 3). - */ - public static final int CURSOR_APPSTARTING = 3; - - /** - * System help cursor (value is 4). - */ - public static final int CURSOR_HELP = 4; - - /** - * System resize all directions cursor (value is 5). - */ - public static final int CURSOR_SIZEALL = 5; - - /** - * System resize north-east-south-west cursor (value is 6). - */ - public static final int CURSOR_SIZENESW = 6; - - /** - * System resize north-south cursor (value is 7). - */ - public static final int CURSOR_SIZENS = 7; - - /** - * System resize north-west-south-east cursor (value is 8). - */ - public static final int CURSOR_SIZENWSE = 8; - - /** - * System resize west-east cursor (value is 9). - */ - public static final int CURSOR_SIZEWE = 9; - - /** - * System resize north cursor (value is 10). - */ - public static final int CURSOR_SIZEN = 10; - - /** - * System resize south cursor (value is 11). - */ - public static final int CURSOR_SIZES = 11; - - /** - * System resize east cursor (value is 12). - */ - public static final int CURSOR_SIZEE = 12; - - /** - * System resize west cursor (value is 13). - */ - public static final int CURSOR_SIZEW = 13; - - /** - * System resize north-east cursor (value is 14). - */ - public static final int CURSOR_SIZENE = 14; - - /** - * System resize south-east cursor (value is 15). - */ - public static final int CURSOR_SIZESE = 15; - - /** - * System resize south-west cursor (value is 16). - */ - public static final int CURSOR_SIZESW = 16; - - /** - * System resize north-west cursor (value is 17). - */ - public static final int CURSOR_SIZENW = 17; - - /** - * System up arrow cursor (value is 18). - */ - public static final int CURSOR_UPARROW = 18; - - /** - * System i-beam cursor (value is 19). - */ - public static final int CURSOR_IBEAM = 19; - - /** - * System "not allowed" cursor (value is 20). - */ - public static final int CURSOR_NO = 20; - - /** - * System hand cursor (value is 21). - */ - public static final int CURSOR_HAND = 21; - - /** - * Line drawing style for flat end caps (value is 1). - * - * @see org.eclipse.swt.graphics.GC#setLineCap(int) - * @see org.eclipse.swt.graphics.GC#getLineCap() - * - * @since 3.1 - */ - public static final int CAP_FLAT = 1; - - /** - * Line drawing style for rounded end caps (value is 2). - * - * @see org.eclipse.swt.graphics.GC#setLineCap(int) - * @see org.eclipse.swt.graphics.GC#getLineCap() - * - * @since 3.1 - */ - public static final int CAP_ROUND = 2; - - /** - * Line drawing style for square end caps (value is 3). - * - * @see org.eclipse.swt.graphics.GC#setLineCap(int) - * @see org.eclipse.swt.graphics.GC#getLineCap() - * - * @since 3.1 - */ - public static final int CAP_SQUARE = 3; - - /** - * Line drawing style for miter joins (value is 1). - * - * @see org.eclipse.swt.graphics.GC#setLineJoin(int) - * @see org.eclipse.swt.graphics.GC#getLineJoin() - * - * @since 3.1 - */ - public static final int JOIN_MITER = 1; - - /** - * Line drawing style for rounded joins (value is 2). - * - * @see org.eclipse.swt.graphics.GC#setLineJoin(int) - * @see org.eclipse.swt.graphics.GC#getLineJoin() - * - * @since 3.1 - */ - public static final int JOIN_ROUND = 2; - - /** - * Line drawing style for bevel joins (value is 3). - * - * @see org.eclipse.swt.graphics.GC#setLineJoin(int) - * @see org.eclipse.swt.graphics.GC#getLineJoin() - * - * @since 3.1 - */ - public static final int JOIN_BEVEL = 3; - - /** - * Line drawing style for solid lines (value is 1). - */ - public static final int LINE_SOLID = 1; - - /** - * Line drawing style for dashed lines (value is 2). - */ - public static final int LINE_DASH = 2; - - /** - * Line drawing style for dotted lines (value is 3). - */ - public static final int LINE_DOT = 3; - - /** - * Line drawing style for alternating dash-dot lines (value is 4). - */ - public static final int LINE_DASHDOT = 4; - - /** - * Line drawing style for dash-dot-dot lines (value is 5). - */ - public static final int LINE_DASHDOTDOT = 5; - - /** - * Line drawing style for custom dashed lines (value is 6). - * - * @see org.eclipse.swt.graphics.GC#setLineDash(int[]) - * @see org.eclipse.swt.graphics.GC#getLineDash() - * - * @since 3.1 - */ - public static final int LINE_CUSTOM = 6; - - /** - * Path constant that represents a "move to" operation (value is 1). - * - * @since 3.1 - */ - public static final int PATH_MOVE_TO = 1; - - /** - * Path constant that represents a "line to" operation (value is 2). - * - * @since 3.1 - */ - public static final int PATH_LINE_TO = 2; - - /** - * Path constant that represents a "quadratic curve to" operation (value is 3). - * - * @since 3.1 - */ - public static final int PATH_QUAD_TO = 3; - - /** - * Path constant that represents a "cubic curve to" operation (value is 4). - * - * @since 3.1 - */ - public static final int PATH_CUBIC_TO = 4; - - /** - * Path constant that represents a "close" operation (value is 5). - * - * @since 3.1 - */ - public static final int PATH_CLOSE = 5; - - /** - * Even odd rule for filling operations (value is 1). - * - * @since 3.1 - */ - public static final int FILL_EVEN_ODD = 1; - - /** - * Winding rule for filling operations (value is 2). - * - * @since 3.1 - */ - public static final int FILL_WINDING = 2; - - /** - * Image format constant indicating an unknown image type (value is -1). - */ - public static final int IMAGE_UNDEFINED = -1; - - /** - * Image format constant indicating a Windows BMP format image (value is 0). - */ - public static final int IMAGE_BMP = 0; - - /** - * Image format constant indicating a run-length encoded - * Windows BMP format image (value is 1). - */ - public static final int IMAGE_BMP_RLE = 1; - - /** - * Image format constant indicating a GIF format image (value is 2). - */ - public static final int IMAGE_GIF = 2; - - /** - * Image format constant indicating a ICO format image (value is 3). - */ - public static final int IMAGE_ICO = 3; - - /** - * Image format constant indicating a JPEG format image (value is 4). - */ - public static final int IMAGE_JPEG = 4; - - /** - * Image format constant indicating a PNG format image (value is 5). - */ - public static final int IMAGE_PNG = 5; - - /** - * Image format constant indicating a TIFF format image (value is 6). - */ - public static final int IMAGE_TIFF = 6; - - /** - * Image format constant indicating an OS/2 BMP format image (value is 7). - */ - public static final int IMAGE_OS2_BMP = 7; - - /** - * GIF image disposal method constants indicating that the - * disposal method is unspecified (value is 0). - */ - public static final int DM_UNSPECIFIED = 0x0; - - /** - * GIF image disposal method constants indicating that the - * disposal method is to do nothing; that is, to leave the - * previous image in place (value is 1). - */ - public static final int DM_FILL_NONE = 0x1; - - /** - * GIF image disposal method constants indicating that the - * the previous images should be covered with the background - * color before displaying the next image (value is 2). - */ - public static final int DM_FILL_BACKGROUND = 0x2; - - /** - * GIF image disposal method constants indicating that the - * disposal method is to restore the previous picture - * (value is 3). - */ - public static final int DM_FILL_PREVIOUS = 0x3; - - /** - * Image transparency constant indicating that the image - * contains no transparency information (value is 0). - */ - public static final int TRANSPARENCY_NONE = 0x0; - - /** - * Image transparency constant indicating that the image - * contains alpha transparency information (value is 1<<0). - */ - public static final int TRANSPARENCY_ALPHA = 1 << 0; - - /** - * Image transparency constant indicating that the image - * contains a transparency mask (value is 1<<1). - */ - public static final int TRANSPARENCY_MASK = 1 << 1; - - /** - * Image transparency constant indicating that the image - * contains a transparent pixel (value is 1<<2). - */ - public static final int TRANSPARENCY_PIXEL = 1 << 2; - - /** - * The character movement type (value is 1<<0). - * This constant is used to move a text offset over a character. - * - * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int) - * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int) - * - * @since 3.0 - */ - public static final int MOVEMENT_CHAR = 1 << 0; - - /** - * The cluster movement type (value is 1<<1). - * This constant is used to move a text offset over a cluster. - * A cluster groups one or more characters. A cluster is - * undivisible, this means that a caret offset can not be placed in the - * middle of a cluster. - * - * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int) - * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int) - * - * @since 3.0 - */ - public static final int MOVEMENT_CLUSTER = 1 << 1; - - /** - * The word movement type (value is 1<<2). - * This constant is used to move a text offset over a word. - * The behavior of this constant depends on the platform and on the - * direction of the movement. For example, on Windows the stop is - * always at the start of the word. On GTK and Mac the stop is at the end - * of the word if the direction is next and at the start of the word if the - * direction is previous. - * - * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int) - * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int) - * - * @since 3.0 - */ - public static final int MOVEMENT_WORD = 1 << 2; - - /** - * The word end movement type (value is 1<<3). - * This constant is used to move a text offset to the next or previous - * word end. The behavior of this constant does not depend on the platform. - * - * - * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int) - * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int) - * - * @since 3.3 - */ - public static final int MOVEMENT_WORD_END = 1 << 3; - - /** - * The word start movement type (value is 1<<4). - * This constant is used to move a text offset to the next or previous - * word start. The behavior of this constant does not depend on the platform. - * - * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int) - * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int) - * - * @since 3.3 - */ - public static final int MOVEMENT_WORD_START = 1 << 4; - - -/** - * Answers a concise, human readable description of the error code. - * - * @param code the SWT error code. - * @return a description of the error code. - * - * @see SWT - */ -static String findErrorText (int code) { - switch (code) { - case ERROR_UNSPECIFIED: return "Unspecified error"; //$NON-NLS-1$ - case ERROR_NO_HANDLES: return "No more handles"; //$NON-NLS-1$ - case ERROR_NO_MORE_CALLBACKS: return "No more callbacks"; //$NON-NLS-1$ - case ERROR_NULL_ARGUMENT: return "Argument cannot be null"; //$NON-NLS-1$ - case ERROR_INVALID_ARGUMENT: return "Argument not valid"; //$NON-NLS-1$ - case ERROR_INVALID_RETURN_VALUE: return "Return value not valid"; //$NON-NLS-1$ - case ERROR_INVALID_RANGE: return "Index out of bounds"; //$NON-NLS-1$ - case ERROR_CANNOT_BE_ZERO: return "Argument cannot be zero"; //$NON-NLS-1$ - case ERROR_CANNOT_GET_ITEM: return "Cannot get item"; //$NON-NLS-1$ - case ERROR_CANNOT_GET_SELECTION: return "Cannot get selection"; //$NON-NLS-1$ - case ERROR_CANNOT_GET_ITEM_HEIGHT: return "Cannot get item height"; //$NON-NLS-1$ - case ERROR_CANNOT_GET_TEXT: return "Cannot get text"; //$NON-NLS-1$ - case ERROR_CANNOT_SET_TEXT: return "Cannot set text"; //$NON-NLS-1$ - case ERROR_ITEM_NOT_ADDED: return "Item not added"; //$NON-NLS-1$ - case ERROR_ITEM_NOT_REMOVED: return "Item not removed"; //$NON-NLS-1$ - case ERROR_NOT_IMPLEMENTED: return "Not implemented"; //$NON-NLS-1$ - case ERROR_MENU_NOT_DROP_DOWN: return "Menu must be a drop down"; //$NON-NLS-1$ - case ERROR_THREAD_INVALID_ACCESS: return "Invalid thread access"; //$NON-NLS-1$ - case ERROR_WIDGET_DISPOSED: return "Widget is disposed"; //$NON-NLS-1$ - case ERROR_MENUITEM_NOT_CASCADE: return "Menu item is not a CASCADE"; //$NON-NLS-1$ - case ERROR_CANNOT_SET_SELECTION: return "Cannot set selection"; //$NON-NLS-1$ - case ERROR_CANNOT_SET_MENU: return "Cannot set menu"; //$NON-NLS-1$ - case ERROR_CANNOT_SET_ENABLED: return "Cannot set the enabled state"; //$NON-NLS-1$ - case ERROR_CANNOT_GET_ENABLED: return "Cannot get the enabled state"; //$NON-NLS-1$ - case ERROR_INVALID_PARENT: return "Widget has the wrong parent"; //$NON-NLS-1$ - case ERROR_MENU_NOT_BAR: return "Menu is not a BAR"; //$NON-NLS-1$ - case ERROR_CANNOT_GET_COUNT: return "Cannot get count"; //$NON-NLS-1$ - case ERROR_MENU_NOT_POP_UP: return "Menu is not a POP_UP"; //$NON-NLS-1$ - case ERROR_UNSUPPORTED_DEPTH: return "Unsupported color depth"; //$NON-NLS-1$ - case ERROR_IO: return "i/o error"; //$NON-NLS-1$ - case ERROR_INVALID_IMAGE: return "Invalid image"; //$NON-NLS-1$ - case ERROR_UNSUPPORTED_FORMAT: return "Unsupported or unrecognized format"; //$NON-NLS-1$ - case ERROR_INVALID_SUBCLASS: return "Subclassing not allowed"; //$NON-NLS-1$ - case ERROR_GRAPHIC_DISPOSED: return "Graphic is disposed"; //$NON-NLS-1$ - case ERROR_DEVICE_DISPOSED: return "Device is disposed"; //$NON-NLS-1$ - case ERROR_FUNCTION_DISPOSED: return "BrowserFunction is disposed"; //$NON-NLS-1$ - case ERROR_FAILED_EXEC: return "Failed to execute runnable"; //$NON-NLS-1$ - case ERROR_FAILED_EVALUATE: return "Failed to evaluate javascript expression"; //$NON-NLS-1$ - case ERROR_FAILED_LOAD_LIBRARY: return "Unable to load library"; //$NON-NLS-1$ - case ERROR_CANNOT_INVERT_MATRIX: return "Cannot invert matrix"; //$NON-NLS-1$ - case ERROR_NO_GRAPHICS_LIBRARY: return "Unable to load graphics library"; //$NON-NLS-1$ - case ERROR_INVALID_FONT: return "Font not valid"; //$NON-NLS-1$ - } - return "Unknown error"; //$NON-NLS-1$ -} - -/** - * Returns the NLS'ed message for the given argument. - * - * @param key the key to look up - * @return the message for the given key - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the key is null</li> - * </ul> - */ -public static String getMessage(String key) { - return Compatibility.getMessage(key); -} - -/** - * Returns the SWT platform name. - * Examples: "win32", "motif", "gtk", "photon", "carbon", "cocoa", "wpf" - * - * @return the SWT platform name - */ -public static String getPlatform () { - return Platform.PLATFORM; -} - -/** - * Returns the SWT version number as an integer. - * Example: "SWT051" == 51 - * - * @return the SWT version number - */ -public static int getVersion () { - return Library.SWT_VERSION; -} - -/** - * Throws an appropriate exception based on the passed in error code. - * - * @param code the SWT error code - */ -public static void error (int code) { - error (code, null); -} - -/** - * Throws an appropriate exception based on the passed in error code. - * The <code>throwable</code> argument should be either null, or the - * throwable which caused SWT to throw an exception. - * <p> - * In SWT, errors are reported by throwing one of three exceptions: - * <dl> - * <dd>java.lang.IllegalArgumentException</dd> - * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt> - * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd> - * <dt>thrown whenever a recoverable error happens internally in SWT</dt> - * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd> - * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt> - * </dl> - * This method provides the logic which maps between error codes - * and one of the above exceptions. - * </p> - * - * @param code the SWT error code. - * @param throwable the exception which caused the error to occur. - * - * @see SWTError - * @see SWTException - * @see IllegalArgumentException - */ -public static void error (int code, Throwable throwable) { - error (code, throwable, null); -} - -/** - * Throws an appropriate exception based on the passed in error code. - * The <code>throwable</code> argument should be either null, or the - * throwable which caused SWT to throw an exception. - * <p> - * In SWT, errors are reported by throwing one of three exceptions: - * <dl> - * <dd>java.lang.IllegalArgumentException</dd> - * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt> - * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd> - * <dt>thrown whenever a recoverable error happens internally in SWT</dt> - * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd> - * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt> - * </dl> - * This method provides the logic which maps between error codes - * and one of the above exceptions. - * </p> - * - * @param code the SWT error code. - * @param throwable the exception which caused the error to occur. - * @param detail more information about error. - * - * @see SWTError - * @see SWTException - * @see IllegalArgumentException - * - * @since 3.0 - */ -public static void error (int code, Throwable throwable, String detail) { - - /* - * This code prevents the creation of "chains" of SWTErrors and - * SWTExceptions which in turn contain other SWTErrors and - * SWTExceptions as their throwable. This can occur when low level - * code throws an exception past a point where a higher layer is - * being "safe" and catching all exceptions. (Note that, this is - * _a_bad_thing_ which we always try to avoid.) - * - * On the theory that the low level code is closest to the - * original problem, we simply re-throw the original exception here. - * - * NOTE: Exceptions thrown in syncExec and asyncExec must be - * wrapped. - */ - if (code != SWT.ERROR_FAILED_EXEC) { - if (throwable instanceof SWTError) throw (SWTError) throwable; - if (throwable instanceof SWTException) throw (SWTException) throwable; - } - - String message = findErrorText (code); - if (detail != null) message += detail; - switch (code) { - - /* Illegal Arguments (non-fatal) */ - case ERROR_NULL_ARGUMENT: - case ERROR_CANNOT_BE_ZERO: - case ERROR_INVALID_ARGUMENT: - case ERROR_MENU_NOT_BAR: - case ERROR_MENU_NOT_DROP_DOWN: - case ERROR_MENU_NOT_POP_UP: - case ERROR_MENUITEM_NOT_CASCADE: - case ERROR_INVALID_PARENT: - case ERROR_INVALID_RANGE: { - throw new IllegalArgumentException (message); - } - - /* SWT Exceptions (non-fatal) */ - case ERROR_INVALID_SUBCLASS: - case ERROR_THREAD_INVALID_ACCESS: - case ERROR_WIDGET_DISPOSED: - case ERROR_GRAPHIC_DISPOSED: - case ERROR_DEVICE_DISPOSED: - case ERROR_FUNCTION_DISPOSED: - case ERROR_INVALID_IMAGE: - case ERROR_UNSUPPORTED_DEPTH: - case ERROR_UNSUPPORTED_FORMAT: - case ERROR_FAILED_EXEC: - case ERROR_FAILED_EVALUATE: - case ERROR_CANNOT_INVERT_MATRIX: - case ERROR_NO_GRAPHICS_LIBRARY: - case ERROR_INVALID_RETURN_VALUE: - case ERROR_IO: { - SWTException exception = new SWTException (code, message); - exception.throwable = throwable; - throw exception; - } - - /* Operation System Errors (fatal, may occur only on some platforms) */ - case ERROR_CANNOT_GET_COUNT: - case ERROR_CANNOT_GET_ENABLED: - case ERROR_CANNOT_GET_ITEM: - case ERROR_CANNOT_GET_ITEM_HEIGHT: - case ERROR_CANNOT_GET_SELECTION: - case ERROR_CANNOT_GET_TEXT: - case ERROR_CANNOT_SET_ENABLED: - case ERROR_CANNOT_SET_MENU: - case ERROR_CANNOT_SET_SELECTION: - case ERROR_CANNOT_SET_TEXT: - case ERROR_ITEM_NOT_ADDED: - case ERROR_ITEM_NOT_REMOVED: - case ERROR_NO_HANDLES: - //FALL THROUGH - - /* SWT Errors (fatal, may occur only on some platforms) */ - case ERROR_FAILED_LOAD_LIBRARY: - case ERROR_NO_MORE_CALLBACKS: - case ERROR_NOT_IMPLEMENTED: - case ERROR_UNSPECIFIED: { - SWTError error = new SWTError (code, message); - error.throwable = throwable; - throw error; - } - } - - /* Unknown/Undefined Error */ - SWTError error = new SWTError (code, message); - error.throwable = throwable; - throw error; -} - -static { - /* - * These values represent bit masks that may need to - * expand in the future. Therefore they are not initialized - * in the declaration to stop the compiler from inlining. - */ - BUTTON_MASK = BUTTON1 | BUTTON2 | BUTTON3 | BUTTON4 | BUTTON5; - MODIFIER_MASK = ALT | SHIFT | CTRL | COMMAND; - - /* - * These values can be different on different platforms. - * Therefore they are not initialized in the declaration - * to stop the compiler from inlining. - */ - String platform = getPlatform (); - if ("carbon".equals (platform) || "cocoa".equals (platform)) { //$NON-NLS-1$ //$NON-NLS-2$ - MOD1 = COMMAND; - MOD2 = SHIFT; - MOD3 = ALT; - MOD4 = CONTROL; - } else { - MOD1 = CONTROL; - MOD2 = SHIFT; - MOD3 = ALT; - MOD4 = 0; - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java deleted file mode 100755 index 6a2341db66..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt; - -import org.eclipse.swt.internal.*; - -/** - * This error is thrown whenever an unrecoverable error - * occurs internally in SWT. The message text and error code - * provide a further description of the problem. The exception - * has a <code>throwable</code> field which holds the underlying - * throwable that caused the problem (if this information is - * available (i.e. it may be null)). - * <p> - * SWTErrors are thrown when something fails internally which - * either leaves SWT in an unknown state (eg. the o/s call to - * remove an item from a list returns an error code) or when SWT - * is left in a known-to-be-unrecoverable state (eg. it runs out - * of callback resources). SWTErrors should not occur in typical - * programs, although "high reliability" applications should - * still catch them. - * </p><p> - * This class also provides support methods used by SWT to match - * error codes to the appropriate exception class (SWTError, - * SWTException, or IllegalArgumentException) and to provide - * human readable strings for SWT error codes. - * </p> - * - * @see SWTException - * @see SWT#error(int) - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class SWTError extends Error { - /** - * The SWT error code, one of SWT.ERROR_*. - */ - public int code; - - /** - * The underlying throwable that caused the problem, - * or null if this information is not available. - */ - public Throwable throwable; - - static final long serialVersionUID = 3833467327105808433L; - -/** - * Constructs a new instance of this class with its - * stack trace filled in. The error code is set to an - * unspecified value. - */ -public SWTError () { - this (SWT.ERROR_UNSPECIFIED); -} - -/** - * Constructs a new instance of this class with its - * stack trace and message filled in. The error code is - * set to an unspecified value. Specifying <code>null</code> - * as the message is equivalent to specifying an empty string. - * - * @param message the detail message for the exception - */ -public SWTError (String message) { - this (SWT.ERROR_UNSPECIFIED, message); -} - -/** - * Constructs a new instance of this class with its - * stack trace and error code filled in. - * - * @param code the SWT error code - */ -public SWTError (int code) { - this (code, SWT.findErrorText (code)); -} - -/** - * Constructs a new instance of this class with its - * stack trace, error code and message filled in. - * Specifying <code>null</code> as the message is - * equivalent to specifying an empty string. - * - * @param code the SWT error code - * @param message the detail message for the exception - */ -public SWTError (int code, String message) { - super (message); - this.code = code; -} - -/** - * Returns the underlying throwable that caused the problem, - * or null if this information is not available. - * <p> - * NOTE: This method overrides Throwable.getCause() that was - * added to JDK1.4. It is necessary to override this method - * in order for inherited printStackTrace() methods to work. - * </p> - * @return the underlying throwable - * - * @since 3.1 - */ -public Throwable getCause() { - return throwable; -} - -/** - * Returns the string describing this SWTError object. - * <p> - * It is combined with the message string of the Throwable - * which caused this SWTError (if this information is available). - * </p> - * @return the error message string of this SWTError object - */ -public String getMessage () { - if (throwable == null) return super.getMessage (); - return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$ -} - -/** - * Outputs a printable representation of this error's - * stack trace on the standard error stream. - * <p> - * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) - * are not provided in order to maintain compatibility with CLDC. - * </p> - */ -public void printStackTrace () { - super.printStackTrace (); - if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable != null) { - System.err.println ("*** Stack trace of contained error ***"); //$NON-NLS-1$ - throwable.printStackTrace (); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java deleted file mode 100755 index c139457ff5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt; - -import org.eclipse.swt.internal.*; - -/** - * This runtime exception is thrown whenever a recoverable error - * occurs internally in SWT. The message text and error code - * provide a further description of the problem. The exception - * has a <code>throwable</code> field which holds the underlying - * exception that caused the problem (if this information is - * available (i.e. it may be null)). - * <p> - * SWTExceptions are thrown when something fails internally, - * but SWT is left in a known stable state (eg. a widget call - * was made from a non-u/i thread, or there is failure while - * reading an Image because the source file was corrupt). - * </p> - * - * @see SWTError - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class SWTException extends RuntimeException { - /** - * The SWT error code, one of SWT.ERROR_*. - */ - public int code; - - /** - * The underlying throwable that caused the problem, - * or null if this information is not available. - */ - public Throwable throwable; - - static final long serialVersionUID = 3257282552304842547L; - -/** - * Constructs a new instance of this class with its - * stack trace filled in. The error code is set to an - * unspecified value. - */ -public SWTException () { - this (SWT.ERROR_UNSPECIFIED); -} - -/** - * Constructs a new instance of this class with its - * stack trace and message filled in. The error code is - * set to an unspecified value. Specifying <code>null</code> - * as the message is equivalent to specifying an empty string. - * - * @param message the detail message for the exception - */ -public SWTException (String message) { - this (SWT.ERROR_UNSPECIFIED, message); -} - -/** - * Constructs a new instance of this class with its - * stack trace and error code filled in. - * - * @param code the SWT error code - */ -public SWTException (int code) { - this (code, SWT.findErrorText (code)); -} - -/** - * Constructs a new instance of this class with its - * stack trace, error code and message filled in. - * Specifying <code>null</code> as the message is - * equivalent to specifying an empty string. - * - * @param code the SWT error code - * @param message the detail message for the exception - */ -public SWTException (int code, String message) { - super (message); - this.code = code; -} - -/** - * Returns the underlying throwable that caused the problem, - * or null if this information is not available. - * <p> - * NOTE: This method overrides Throwable.getCause() that was - * added to JDK1.4. It is necessary to override this method - * in order for inherited printStackTrace() methods to work. - * </p> - * @return the underlying throwable - * - * @since 3.1 - */ -public Throwable getCause() { - return throwable; -} - -/** - * Returns the string describing this SWTException object. - * <p> - * It is combined with the message string of the Throwable - * which caused this SWTException (if this information is available). - * </p> - * @return the error message string of this SWTException object - */ -public String getMessage () { - if (throwable == null) return super.getMessage (); - return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$ -} - -/** - * Outputs a printable representation of this exception's - * stack trace on the standard error stream. - * <p> - * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) - * are not provided in order to maintain compatibility with CLDC. - * </p> - */ -public void printStackTrace () { - super.printStackTrace (); - if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable != null) { - System.err.println ("*** Stack trace of contained exception ***"); //$NON-NLS-1$ - throwable.printStackTrace (); - } -} - -} - - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java deleted file mode 100755 index 5b6f9826a1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * a widget such as a menu item being armed. - * - * @see ArmListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class ArmEvent extends TypedEvent { - - static final long serialVersionUID = 3258126964249212217L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public ArmEvent(Event e) { - super(e); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java deleted file mode 100755 index 23e983afc7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the event that is generated when a widget, - * such as a menu item, is armed. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a widget using the - * <code>addArmListener</code> method and removed using - * the <code>removeArmListener</code> method. When the - * widget is armed, the widgetArmed method will be invoked. - * </p> - * - * @see ArmEvent - */ -public interface ArmListener extends SWTEventListener { - -/** - * Sent when a widget is armed, or 'about to be selected'. - * - * @param e an event containing information about the arm - */ -public void widgetArmed(ArmEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java deleted file mode 100755 index 10f273b09f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>ControlListener</code> interface. - * <p> - * Classes that wish to deal with <code>ControlEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see ControlListener - * @see ControlEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class ControlAdapter implements ControlListener { - -/** - * Sent when the location (x, y) of a control changes relative - * to its parent (or relative to the display, for <code>Shell</code>s). - * The default behavior is to do nothing. - * - * @param e an event containing information about the move - */ -public void controlMoved(ControlEvent e) { -} - -/** - * Sent when the size (width, height) of a control changes. - * The default behavior is to do nothing. - * - * @param e an event containing information about the resize - */ -public void controlResized(ControlEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java deleted file mode 100755 index 3513ef31c2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * controls being moved or resized. - * - * @see ControlListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class ControlEvent extends TypedEvent { - - static final long serialVersionUID = 3258132436155119161L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public ControlEvent(Event e) { - super(e); -} - -} - - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java deleted file mode 100755 index 4895ec1946..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated by moving - * and resizing controls. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addControlListener</code> method and removed using - * the <code>removeControlListener</code> method. When a - * control is moved or resized, the appropriate method will - * be invoked. - * </p> - * - * @see ControlAdapter - * @see ControlEvent - */ -public interface ControlListener extends SWTEventListener { - -/** - * Sent when the location (x, y) of a control changes relative - * to its parent (or relative to the display, for <code>Shell</code>s). - * - * @param e an event containing information about the move - */ -public void controlMoved(ControlEvent e); - -/** - * Sent when the size (width, height) of a control changes. - * - * @param e an event containing information about the resize - */ -public void controlResized(ControlEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java deleted file mode 100755 index 04dbdd9639..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * widgets being disposed. - * - * @see DisposeListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class DisposeEvent extends TypedEvent { - - static final long serialVersionUID = 3257566187633521206L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public DisposeEvent(Event e) { - super(e); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java deleted file mode 100755 index 980f0b30ae..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the event that is generated when a widget - * is disposed. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a widget using the - * <code>addDisposeListener</code> method and removed using - * the <code>removeDisposeListener</code> method. When a - * widget is disposed, the widgetDisposed method will - * be invoked. - * </p> - * - * @see DisposeEvent - */ -public interface DisposeListener extends SWTEventListener { - -/** - * Sent when the widget is disposed. - * - * @param e an event containing information about the dispose - */ -public void widgetDisposed(DisposeEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java deleted file mode 100644 index a10148d87d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * a drag gesture. - * - * @see DragDetectListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.3 - */ - -public final class DragDetectEvent extends MouseEvent { - - private static final long serialVersionUID = -7229172519733647232L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public DragDetectEvent(Event e) { - super(e); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java deleted file mode 100644 index 805747da3b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated when a drag - * gesture is detected. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addDragDetectListener</code> method and removed using - * the <code>removeDragDetectListener</code> method. When the - * drag is detected, the drageDetected method will be invoked. - * </p> - * - * @see DragDetectEvent - * - * @since 3.3 - */ -public interface DragDetectListener extends SWTEventListener { - -/** - * Sent when a drag gesture is detected. - * - * @param e an event containing information about the drag - */ -public void dragDetected(DragDetectEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java deleted file mode 100644 index 6d9751368c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>ExpandListener</code> interface. - * <p> - * Classes that wish to deal with <code>ExpandEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see ExpandListener - * @see ExpandEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.2 - */ -public abstract class ExpandAdapter implements ExpandListener { - -/** - * Sent when an item is collapsed. - * The default behavior is to do nothing. - * - * @param e an event containing information about the operation - */ -public void itemCollapsed(ExpandEvent e) { -} - -/** - * Sent when an item is expanded. - * The default behavior is to do nothing. - * - * @param e an event containing information about the operation - */ -public void itemExpanded(ExpandEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java deleted file mode 100644 index 439de1702d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class are sent as a result of - * <code>ExpandItem</code>s being expanded or collapsed. - * - * @see ExpandListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.2 - */ - -public class ExpandEvent extends SelectionEvent { - - static final long serialVersionUID = 3976735856884987356L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public ExpandEvent(Event e) { - super(e); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java deleted file mode 100644 index 4991d97a2f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the expanding and collapsing of <code>ExpandItem</code>s. - * - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a <code>ExpandBar</code> - * control using the <code>addExpandListener</code> method and - * removed using the <code>removeExpandListener</code> method. - * When a item of the <code>ExpandBar</code> is expanded or - * collapsed, the appropriate method will be invoked. - * </p> - * - * @see ExpandAdapter - * @see ExpandEvent - * - * @since 3.2 - */ -public interface ExpandListener extends SWTEventListener { - -/** - * Sent when an item is collapsed. - * - * @param e an event containing information about the operation - */ -public void itemCollapsed(ExpandEvent e); - -/** - * Sent when an item is expanded. - * - * @param e an event containing information about the operation - */ -public void itemExpanded(ExpandEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java deleted file mode 100755 index eab687e12d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>FocusListener</code> interface. - * <p> - * Classes that wish to deal with <code>FocusEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see FocusListener - * @see FocusEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class FocusAdapter implements FocusListener { - -/** - * Sent when a control gets focus. - * The default behavior is to do nothing. - * - * @param e an event containing information about the focus change - */ -public void focusGained(FocusEvent e) { -} - -/** - * Sent when a control loses focus. - * The default behavior is to do nothing. - * - * @param e an event containing information about the focus change - */ -public void focusLost(FocusEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java deleted file mode 100755 index a703db7cfe..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * widgets gaining and losing focus. - * - * @see FocusListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class FocusEvent extends TypedEvent { - - static final long serialVersionUID = 3258134643684227381L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public FocusEvent(Event e) { - super(e); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java deleted file mode 100755 index 9aa3097d0a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated as controls - * gain and lose focus. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addFocusListener</code> method and removed using - * the <code>removeFocusListener</code> method. When a - * control gains or loses focus, the appropriate method - * will be invoked. - * </p> - * - * @see FocusAdapter - * @see FocusEvent - */ -public interface FocusListener extends SWTEventListener { - -/** - * Sent when a control gets focus. - * - * @param e an event containing information about the focus change - */ -public void focusGained(FocusEvent e); - -/** - * Sent when a control loses focus. - * - * @param e an event containing information about the focus change - */ -public void focusLost(FocusEvent e); -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java deleted file mode 100755 index fd38eba361..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * help being requested for a widget. - * - * @see HelpListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class HelpEvent extends TypedEvent { - - static final long serialVersionUID = 3257001038606251315L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public HelpEvent(Event e) { - super(e); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java deleted file mode 100755 index 9437c093ea..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the event that is generated when help is - * requested for a control, typically when the user presses F1. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addHelpListener</code> method and removed using - * the <code>removeHelpListener</code> method. When help - * is requested for a control, the helpRequested method - * will be invoked. - * </p> - * - * @see HelpEvent - */ -public interface HelpListener extends SWTEventListener { - -/** - * Sent when help is requested for a control, typically - * when the user presses F1. - * - * @param e an event containing information about the help - */ -public void helpRequested(HelpEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java deleted file mode 100755 index dca53cc517..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>KeyListener</code> interface. - * <p> - * Classes that wish to deal with <code>KeyEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see KeyListener - * @see KeyEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class KeyAdapter implements KeyListener { - -/** - * Sent when a key is pressed on the system keyboard. - * The default behavior is to do nothing. - * - * @param e an event containing information about the key press - */ -public void keyPressed(KeyEvent e) { -} - -/** - * Sent when a key is released on the system keyboard. - * The default behavior is to do nothing. - * - * @param e an event containing information about the key release - */ -public void keyReleased(KeyEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java deleted file mode 100755 index 7a3a1d77db..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * keys being pressed and released on the keyboard. - * <p> - * When a key listener is added to a control, the control - * will take part in widget traversal. By default, all - * traversal keys (such as the tab key and so on) are - * delivered to the control. In order for a control to take - * part in traversal, it should listen for traversal events. - * Otherwise, the user can traverse into a control but not - * out. Note that native controls such as table and tree - * implement key traversal in the operating system. It is - * not necessary to add traversal listeners for these controls, - * unless you want to override the default traversal. - * </p> - * - * @see KeyListener - * @see TraverseListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class KeyEvent extends TypedEvent { - - /** - * the character represented by the key that was typed. - * This is the final character that results after all modifiers have been - * applied. For example, when the user types Ctrl+A, the character value - * is 0x01. It is important that applications do not attempt to modify the - * character value based on a stateMask (such as SWT.CTRL) or the resulting - * character will not be correct. - */ - public char character; - - /** - * the key code of the key that was typed, - * as defined by the key code constants in class <code>SWT</code>. - * When the character field of the event is ambiguous, this field - * contains the unicode value of the original character. For example, - * typing Ctrl+M or Return both result in the character '\r' but the - * keyCode field will also contain '\r' when Return was typed. - * - * @see org.eclipse.swt.SWT - */ - public int keyCode; - - /** - * the state of the keyboard modifier keys at the time - * the event was generated, as defined by the key code - * constants in class <code>SWT</code>. - * - * @see org.eclipse.swt.SWT - */ - public int stateMask; - - /** - * A flag indicating whether the operation should be allowed. - * Setting this field to <code>false</code> will cancel the operation. - */ - public boolean doit; - - static final long serialVersionUID = 3256442491011412789L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public KeyEvent(Event e) { - super(e); - this.character = e.character; - this.keyCode = e.keyCode; - this.stateMask = e.stateMask; - this.doit = e.doit; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " character='" + ((character == 0) ? "\\0" : "" + character) + "'" - + " keyCode=" + keyCode - + " stateMask=" + stateMask - + " doit=" + doit - + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java deleted file mode 100755 index 6107f8370e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated as keys - * are pressed on the system keyboard. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addKeyListener</code> method and removed using - * the <code>removeKeyListener</code> method. When a - * key is pressed or released, the appropriate method will - * be invoked. - * </p> - * - * @see KeyAdapter - * @see KeyEvent - */ -public interface KeyListener extends SWTEventListener { - -/** - * Sent when a key is pressed on the system keyboard. - * - * @param e an event containing information about the key press - */ -public void keyPressed(KeyEvent e); - -/** - * Sent when a key is released on the system keyboard. - * - * @param e an event containing information about the key release - */ -public void keyReleased(KeyEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java deleted file mode 100755 index 6bd3c6e5df..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>MenuListener</code> interface. - * <p> - * Classes that wish to deal with <code>MenuEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see MenuListener - * @see MenuEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class MenuAdapter implements MenuListener { - -/** - * Sent when a menu is hidden. - * The default behavior is to do nothing. - * - * @param e an event containing information about the menu operation - */ -public void menuHidden(MenuEvent e) { -} - -/** - * Sent when a menu is shown. - * The default behavior is to do nothing. - * - * @param e an event containing information about the menu operation - */ -public void menuShown(MenuEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java deleted file mode 100644 index 8f36c30d39..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent whenever the platform- - * specific trigger for showing a context menu is detected. - * - * @see MenuDetectListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.3 - */ - -public final class MenuDetectEvent extends TypedEvent { - - /** - * the display-relative x coordinate of the pointer - * at the time the context menu trigger occurred - */ - public int x; - - /** - * the display-relative y coordinate of the pointer - * at the time the context menu trigger occurred - */ - public int y; - - /** - * A flag indicating whether the operation should be allowed. - * Setting this field to <code>false</code> will cancel the operation. - */ - public boolean doit; - - private static final long serialVersionUID = -3061660596590828941L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public MenuDetectEvent(Event e) { - super(e); - this.x = e.x; - this.y = e.y; - this.doit = e.doit; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " x=" + x - + " y=" + y - + " doit=" + doit - + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java deleted file mode 100644 index 1d6769cca7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated when the - * platform-specific trigger for showing a context menu is - * detected. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control or TrayItem - * using the <code>addMenuDetectListener</code> method and - * removed using the <code>removeMenuDetectListener</code> method. - * When the context menu trigger occurs, the - * <code>menuDetected</code> method will be invoked. - * </p> - * - * @see MenuDetectEvent - * - * @since 3.3 - */ -public interface MenuDetectListener extends SWTEventListener { - -/** - * Sent when the platform-dependent trigger for showing a menu item is detected. - * - * @param e an event containing information about the menu detect - */ -public void menuDetected (MenuDetectEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java deleted file mode 100755 index 4697a9df42..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * menus being shown and hidden. - * - * @see MenuListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class MenuEvent extends TypedEvent { - - static final long serialVersionUID = 3258132440332383025L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public MenuEvent(Event e) { - super(e); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java deleted file mode 100755 index 0c74780ce9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the hiding and showing of menus. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a menu using the - * <code>addMenuListener</code> method and removed using - * the <code>removeMenuListener</code> method. When the - * menu is hidden or shown, the appropriate method will - * be invoked. - * </p> - * - * @see MenuAdapter - * @see MenuEvent - */ -public interface MenuListener extends SWTEventListener { - -/** - * Sent when a menu is hidden. - * - * @param e an event containing information about the menu operation - */ -public void menuHidden(MenuEvent e); - -/** - * Sent when a menu is shown. - * - * @param e an event containing information about the menu operation - */ -public void menuShown(MenuEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java deleted file mode 100755 index 36642cfdd5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * text being modified. - * - * @see ModifyListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class ModifyEvent extends TypedEvent { - - static final long serialVersionUID = 3258129146227011891L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public ModifyEvent(Event e) { - super(e); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java deleted file mode 100755 index 614b13ad5a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the events that are generated when text - * is modified. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a text widget using the - * <code>addModifyListener</code> method and removed using - * the <code>removeModifyListener</code> method. When the - * text is modified, the modifyText method will be invoked. - * </p> - * - * @see ModifyEvent - */ -public interface ModifyListener extends SWTEventListener { - -/** - * Sent when the text is modified. - * - * @param e an event containing information about the modify - */ -public void modifyText(ModifyEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java deleted file mode 100755 index 1ae1c4821f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>MouseListener</code> interface. - * <p> - * Classes that wish to deal with <code>MouseEvent</code>s - * which occur as mouse buttons are pressed and released can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see MouseListener - * @see MouseEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class MouseAdapter implements MouseListener { - -/** - * Sent when a mouse button is pressed twice within the - * (operating system specified) double click period. - * The default behavior is to do nothing. - * - * @param e an event containing information about the mouse double click - * - * @see org.eclipse.swt.widgets.Display#getDoubleClickTime() - */ -public void mouseDoubleClick(MouseEvent e) { -} - -/** - * Sent when a mouse button is pressed. - * The default behavior is to do nothing. - * - * @param e an event containing information about the mouse button press - */ -public void mouseDown(MouseEvent e) { -} - -/** - * Sent when a mouse button is released. - * The default behavior is to do nothing. - * - * @param e an event containing information about the mouse button release - */ -public void mouseUp(MouseEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java deleted file mode 100755 index 19da7695a8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent whenever mouse - * related actions occur. This includes mouse buttons - * being pressed and released, the mouse pointer being - * moved and the mouse pointer crossing widget boundaries. - * <p> - * Note: The <code>button</code> field is an integer that - * represents the mouse button number. This is not the same - * as the <code>SWT</code> mask constants <code>BUTTONx</code>. - * </p> - * - * @see MouseListener - * @see MouseMoveListener - * @see MouseTrackListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class MouseEvent extends TypedEvent { - - /** - * the button that was pressed or released; 1 for the - * first button, 2 for the second button, and 3 for the - * third button, etc. - */ - public int button; - - /** - * the state of the keyboard modifier keys and mouse masks - * at the time the event was generated. - */ - public int stateMask; - - /** - * the widget-relative, x coordinate of the pointer - * at the time the mouse button was pressed or released - */ - public int x; - - /** - * the widget-relative, y coordinate of the pointer - * at the time the mouse button was pressed or released - */ - public int y; - - /** - * the number times the mouse has been clicked, as defined - * by the operating system; 1 for the first click, 2 for the - * second click and so on. - * - * @since 3.3 - */ - public int count; - - static final long serialVersionUID = 3257288037011566898L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public MouseEvent(Event e) { - super(e); - this.x = e.x; - this.y = e.y; - this.button = e.button; - this.stateMask = e.stateMask; - this.count = e.count; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " button=" + button - + " stateMask=" + stateMask - + " x=" + x - + " y=" + y - + " count=" + count - + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java deleted file mode 100755 index 8ee2158624..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated as mouse buttons - * are pressed. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addMouseListener</code> method and removed using - * the <code>removeMouseListener</code> method. When a - * mouse button is pressed or released, the appropriate method - * will be invoked. - * </p> - * - * @see MouseAdapter - * @see MouseEvent - */ -public interface MouseListener extends SWTEventListener { - -/** - * Sent when a mouse button is pressed twice within the - * (operating system specified) double click period. - * - * @param e an event containing information about the mouse double click - * - * @see org.eclipse.swt.widgets.Display#getDoubleClickTime() - */ -public void mouseDoubleClick(MouseEvent e); - -/** - * Sent when a mouse button is pressed. - * - * @param e an event containing information about the mouse button press - */ -public void mouseDown(MouseEvent e); - -/** - * Sent when a mouse button is released. - * - * @param e an event containing information about the mouse button release - */ -public void mouseUp(MouseEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java deleted file mode 100755 index cc4e00f1a7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the events that are generated as the mouse - * pointer moves. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addMouseMoveListener</code> method and removed using - * the <code>removeMouseMoveListener</code> method. As the - * mouse moves, the mouseMove method will be invoked. - * </p> - * - * @see MouseEvent - */ -public interface MouseMoveListener extends SWTEventListener { - -/** - * Sent when the mouse moves. - * - * @param e an event containing information about the mouse move - */ -public void mouseMove(MouseEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java deleted file mode 100755 index d5ba0ef8bf..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>MouseTrackListener</code> interface. - * <p> - * Classes that wish to deal with <code>MouseEvent</code>s which - * occur as the mouse pointer passes (or hovers) over controls can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see MouseTrackListener - * @see MouseEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class MouseTrackAdapter implements MouseTrackListener { - -/** - * Sent when the mouse pointer passes into the area of - * the screen covered by a control. - * The default behavior is to do nothing. - * - * @param e an event containing information about the mouse enter - */ -public void mouseEnter(MouseEvent e) { -} - -/** - * Sent when the mouse pointer passes out of the area of - * the screen covered by a control. - * The default behavior is to do nothing. - * - * @param e an event containing information about the mouse exit - */ -public void mouseExit(MouseEvent e) { -} - -/** - * Sent when the mouse pointer hovers (that is, stops moving - * for an (operating system specified) period of time) over - * a control. - * The default behavior is to do nothing. - * - * @param e an event containing information about the hover - */ -public void mouseHover(MouseEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java deleted file mode 100755 index 9b01407c7d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated as the mouse - * pointer passes (or hovers) over controls. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addMouseTrackListener</code> method and removed using - * the <code>removeMouseTrackListener</code> method. When the - * mouse pointer passes into or out of the area of the screen - * covered by a control or pauses while over a control, the - * appropriate method will be invoked. - * </p> - * - * @see MouseTrackAdapter - * @see MouseEvent - */ -public interface MouseTrackListener extends SWTEventListener { - -/** - * Sent when the mouse pointer passes into the area of - * the screen covered by a control. - * - * @param e an event containing information about the mouse enter - */ -public void mouseEnter(MouseEvent e); - -/** - * Sent when the mouse pointer passes out of the area of - * the screen covered by a control. - * - * @param e an event containing information about the mouse exit - */ -public void mouseExit(MouseEvent e); - -/** - * Sent when the mouse pointer hovers (that is, stops moving - * for an (operating system specified) period of time) over - * a control. - * - * @param e an event containing information about the hover - */ -public void mouseHover(MouseEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java deleted file mode 100644 index 74d50b1676..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the event that is generated as the mouse - * wheel is scrolled. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addMouseWheelListener</code> method and removed using - * the <code>removeMouseWheelListener</code> method. When the - * mouse wheel is scrolled the <code>mouseScrolled</code> method - * will be invoked. - * </p> - * - * @see MouseEvent - * - * @since 3.3 - */ -public interface MouseWheelListener extends SWTEventListener { - -/** - * Sent when the mouse wheel is scrolled. - * - * @param e an event containing information about the mouse wheel action - */ -public void mouseScrolled (MouseEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java deleted file mode 100755 index e7c4443ff1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.graphics.GC; - -/** - * Instances of this class are sent as a result of - * visible areas of controls requiring re-painting. - * - * @see PaintListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class PaintEvent extends TypedEvent { - - /** - * the graphics context to use when painting - * that is configured to use the colors, font and - * damaged region of the control. It is valid - * only during the paint and must not be disposed - */ - public GC gc; - - /** - * the x offset of the bounding rectangle of the - * region that requires painting - */ - public int x; - - /** - * the y offset of the bounding rectangle of the - * region that requires painting - */ - public int y; - - /** - * the width of the bounding rectangle of the - * region that requires painting - */ - public int width; - - /** - * the height of the bounding rectangle of the - * region that requires painting - */ - public int height; - - /** - * the number of following paint events which - * are pending which may always be zero on - * some platforms - */ - public int count; - - static final long serialVersionUID = 3256446919205992497L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public PaintEvent(Event e) { - super(e); - this.gc = e.gc; - this.x = e.x; - this.y = e.y; - this.width = e.width; - this.height = e.height; - this.count = e.count; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " gc=" + gc - + " x=" + x - + " y=" + y - + " width=" + width - + " height=" + height - + " count=" + count - + "}"; -} -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java deleted file mode 100755 index 7a047c82ea..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated when the - * control needs to be painted. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addPaintListener</code> method and removed using - * the <code>removePaintListener</code> method. When a - * paint event occurs, the paintControl method will be - * invoked. - * </p> - * - * @see PaintEvent - */ -public interface PaintListener extends SWTEventListener { - -/** - * Sent when a paint event occurs for the control. - * - * @param e an event containing information about the paint - */ -public void paintControl(PaintEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java deleted file mode 100755 index be1fe9fdc0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>SelectionListener</code> interface. - * <p> - * Classes that wish to deal with <code>SelectionEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see SelectionListener - * @see SelectionEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class SelectionAdapter implements SelectionListener { - -/** - * Sent when selection occurs in the control. - * The default behavior is to do nothing. - * - * @param e an event containing information about the selection - */ -public void widgetSelected(SelectionEvent e) { -} - -/** - * Sent when default selection occurs in the control. - * The default behavior is to do nothing. - * - * @param e an event containing information about the default selection - */ -public void widgetDefaultSelected(SelectionEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java deleted file mode 100755 index 7f6a77eb2d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class are sent as a result of - * widgets being selected. - * <p> - * Note: The fields that are filled in depend on the widget. - * </p> - * - * @see SelectionListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class SelectionEvent extends TypedEvent { - - /** - * The item that was selected. - */ - public Widget item; - - /** - * Extra detail information about the selection, depending on the widget. - * - * <p><b>Sash</b><ul> - * <li>{@link org.eclipse.swt.SWT#DRAG}</li> - * </ul></p><p><b>ScrollBar and Slider</b><ul> - * <li>{@link org.eclipse.swt.SWT#DRAG}</li> - * <li>{@link org.eclipse.swt.SWT#HOME}</li> - * <li>{@link org.eclipse.swt.SWT#END}</li> - * <li>{@link org.eclipse.swt.SWT#ARROW_DOWN}</li> - * <li>{@link org.eclipse.swt.SWT#ARROW_UP}</li> - * <li>{@link org.eclipse.swt.SWT#PAGE_DOWN}</li> - * <li>{@link org.eclipse.swt.SWT#PAGE_UP}</li> - * </ul></p><p><b>Table and Tree</b><ul> - * <li>{@link org.eclipse.swt.SWT#CHECK}</li> - * </ul></p><p><b>Text</b><ul> - * <li>{@link org.eclipse.swt.SWT#CANCEL}</li> - * </ul></p><p><b>CoolItem and ToolItem</b><ul> - * <li>{@link org.eclipse.swt.SWT#ARROW}</li> - * </ul></p> - */ - public int detail; - - /** - * The x location of the selected area. - */ - public int x; - - /** - * The y location of selected area. - */ - public int y; - - /** - * The width of selected area. - */ - public int width; - - /** - * The height of selected area. - */ - public int height; - - /** - * The state of the keyboard modifier keys at the time - * the event was generated. - */ - public int stateMask; - - /** - * The text of the hyperlink that was selected. - * This will be either the text of the hyperlink or the value of its HREF, - * if one was specified. - * - * @see org.eclipse.swt.widgets.Link#setText(String) - * @since 3.1 - */ - public String text; - - /** - * A flag indicating whether the operation should be allowed. - * Setting this field to <code>false</code> will cancel the - * operation, depending on the widget. - */ - public boolean doit; - - static final long serialVersionUID = 3976735856884987953L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public SelectionEvent(Event e) { - super(e); - this.item = e.item; - this.x = e.x; - this.y = e.y; - this.width = e.width; - this.height = e.height; - this.detail = e.detail; - this.stateMask = e.stateMask; - this.text = e.text; - this.doit = e.doit; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " item=" + item - + " detail=" + detail - + " x=" + x - + " y=" + y - + " width=" + width - + " height=" + height - + " stateMask=" + stateMask - + " text=" + text - + " doit=" + doit - + "}"; -} -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java deleted file mode 100755 index 32938d3f07..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the events that are generated when selection - * occurs in a control. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addSelectionListener</code> method and removed using - * the <code>removeSelectionListener</code> method. When - * selection occurs in a control the appropriate method - * will be invoked. - * </p> - * - * @see SelectionAdapter - * @see SelectionEvent - */ -public interface SelectionListener extends SWTEventListener { - -/** - * Sent when selection occurs in the control. - * <p> - * For example, selection occurs in a List when the user selects - * an item or items with the keyboard or mouse. On some platforms, - * the event occurs when a mouse button or key is pressed. On others, - * it happens when the mouse or key is released. The exact key or - * mouse gesture that causes this event is platform specific. - * </p> - * - * @param e an event containing information about the selection - */ -public void widgetSelected(SelectionEvent e); - -/** - * Sent when default selection occurs in the control. - * <p> - * For example, on some platforms default selection occurs in a List - * when the user double-clicks an item or types return in a Text. - * On some platforms, the event occurs when a mouse button or key is - * pressed. On others, it happens when the mouse or key is released. - * The exact key or mouse gesture that causes this event is platform - * specific. - * </p> - * - * @param e an event containing information about the default selection - */ -public void widgetDefaultSelected(SelectionEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java deleted file mode 100755 index 39e7d188f1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>ShellListener</code> interface. - * <p> - * Classes that wish to deal with <code>ShellEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see ShellListener - * @see ShellEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class ShellAdapter implements ShellListener { - -/** - * Sent when a shell becomes the active window. - * The default behavior is to do nothing. - * - * @param e an event containing information about the activation - */ -public void shellActivated(ShellEvent e) { -} - -/** - * Sent when a shell is closed. - * The default behavior is to do nothing. - * - * @param e an event containing information about the close - */ -public void shellClosed(ShellEvent e) { -} - -/** - * Sent when a shell stops being the active window. - * The default behavior is to do nothing. - * - * @param e an event containing information about the deactivation - */ -public void shellDeactivated(ShellEvent e) { -} - -/** - * Sent when a shell is un-minimized. - * The default behavior is to do nothing. - * - * @param e an event containing information about the un-minimization - */ -public void shellDeiconified(ShellEvent e) { -} - -/** - * Sent when a shell is minimized. - * The default behavior is to do nothing. - * - * @param e an event containing information about the minimization - */ -public void shellIconified(ShellEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java deleted file mode 100755 index 736cca3f14..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * operations being performed on shells. - * - * @see ShellListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class ShellEvent extends TypedEvent { - - /** - * A flag indicating whether the operation should be allowed. - * Setting this field to <code>false</code> will cancel the operation. - */ - public boolean doit; - - static final long serialVersionUID = 3257569490479888441L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public ShellEvent(Event e) { - super(e); - this.doit = e.doit; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " doit=" + doit - + "}"; -} -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java deleted file mode 100755 index 36cd8a146a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with changes in state of <code>Shell</code>s. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a shell using the - * <code>addShellListener</code> method and removed using - * the <code>removeShellListener</code> method. When the - * state of the shell changes, the appropriate method will - * be invoked. - * </p> - * - * @see ShellAdapter - * @see ShellEvent - */ -public interface ShellListener extends SWTEventListener { - -/** - * Sent when a shell becomes the active window. - * - * @param e an event containing information about the activation - */ -public void shellActivated(ShellEvent e); - -/** - * Sent when a shell is closed. - * - * @param e an event containing information about the close - */ -public void shellClosed(ShellEvent e); - -/** - * Sent when a shell stops being the active window. - * - * @param e an event containing information about the deactivation - */ -public void shellDeactivated(ShellEvent e); - -/** - * Sent when a shell is un-minimized. - * - * @param e an event containing information about the un-minimization - */ -public void shellDeiconified(ShellEvent e); - -/** - * Sent when a shell is minimized. - * - * @param e an event containing information about the minimization - */ -public void shellIconified(ShellEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java deleted file mode 100755 index f50e42ab2a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class are sent as a result of - * widget traversal actions. - * <p> - * The traversal event allows fine control over keyboard traversal - * in a control both to implement traversal and override the default - * traversal behavior defined by the system. This is achieved using - * two fields, <code>detail</code> and <code>doit</code>. - * </p><p> - * When a control is traversed, a traverse event is sent. The detail - * describes the type of traversal and the doit field indicates the default - * behavior of the system. For example, when a right arrow key is pressed - * in a text control, the detail field is <code>TRAVERSE_ARROW_NEXT</code> - * and the doit field is <code>false</code>, indicating that the system - * will not traverse to the next tab item and the arrow key will be - * delivered to the text control. If the same key is pressed in a radio - * button, the doit field will be <code>true</code>, indicating that - * traversal is to proceed to the next tab item, possibly another radio - * button in the group and that the arrow key is not to be delivered - * to the radio button. - * </p><p> - * How can the traversal event be used to implement traversal? - * When a tab key is pressed in a canvas, the detail field will be - * <code>TRAVERSE_TAB_NEXT</code> and the doit field will be - * <code>false</code>. The default behavior of the system is to - * provide no traversal for canvas controls. This means that by - * default in a canvas, a key listener will see every key that the - * user types, including traversal keys. To understand why this - * is so, it is important to understand that only the widget implementor - * can decide which traversal is appropriate for the widget. Returning - * to the <code>TRAVERSE_TAB_NEXT</code> example, a text widget implemented - * by a canvas would typically want to use the tab key to insert a - * tab character into the widget. A list widget implementation, on the - * other hand, would like the system default traversal behavior. Using - * only the doit flag, both implementations are possible. The text widget - * implementor sets doit to <code>false</code>, ensuring that the system - * will not traverse and that the tab key will be delivered to key listeners. - * The list widget implementor sets doit to <code>true</code>, indicating - * that the system should perform tab traversal and that the key should not - * be delivered to the list widget. - * </p><p> - * How can the traversal event be used to override system traversal? - * When the return key is pressed in a single line text control, the - * detail field is <code>TRAVERSE_RETURN</code> and the doit field - * is <code>true</code>. This means that the return key will be processed - * by the default button, not the text widget. If the text widget has - * a default selection listener, it will not run because the return key - * will be processed by the default button. Imagine that the text control - * is being used as an in-place editor and return is used to dispose the - * widget. Setting doit to <code>false</code> will stop the system from - * activating the default button but the key will be delivered to the text - * control, running the key and selection listeners for the text. How - * can <code>TRAVERSE_RETURN</code> be implemented so that the default button - * will not be activated and the text widget will not see the return key? - * This is achieved by setting doit to <code>true</code>, and the detail - * to <code>TRAVERSE_NONE</code>. - * </p><p> - * Note: A widget implementor will typically implement traversal using - * only the doit flag to either enable or disable system traversal. - * </p> - * - * @see TraverseListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class TraverseEvent extends KeyEvent { - - /** - * The traversal type. - * <p><ul> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_NONE}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_ESCAPE}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_RETURN}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_TAB_NEXT}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_TAB_PREVIOUS}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_ARROW_NEXT}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_ARROW_PREVIOUS}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_MNEMONIC}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_PAGE_NEXT}</li> - * <li>{@link org.eclipse.swt.SWT#TRAVERSE_PAGE_PREVIOUS}</li> - * </ul></p> - * - * Setting this field will change the type of traversal. - * For example, setting the detail to <code>TRAVERSE_NONE</code> - * causes no traversal action to be taken. - * - * When used in conjunction with the <code>doit</code> field, the - * traversal detail field can be useful when overriding the default - * traversal mechanism for a control. For example, setting the doit - * field to <code>false</code> will cancel the operation and allow - * the traversal key stroke to be delivered to the control. Setting - * the doit field to <code>true</code> indicates that the traversal - * described by the detail field is to be performed. - */ - public int detail; - - static final long serialVersionUID = 3257565105301239349L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public TraverseEvent(Event e) { - super(e); - this.detail = e.detail; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " detail=" + detail - + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java deleted file mode 100755 index 2d1d4b3261..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the events that are generated when a - * traverse event occurs in a control. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a control using the - * <code>addTraverseListener</code> method and removed using - * the <code>removeTraverseListener</code> method. When a - * traverse event occurs in a control, the keyTraversed method - * will be invoked. - * </p> - * - * @see TraverseEvent - */ -public interface TraverseListener extends SWTEventListener { - -/** - * Sent when a traverse event occurs in a control. - * <p> - * A traverse event occurs when the user presses a traversal - * key. Traversal keys are typically tab and arrow keys, along - * with certain other keys on some platforms. Traversal key - * constants beginning with <code>TRAVERSE_</code> are defined - * in the <code>SWT</code> class. - * </p> - * - * @param e an event containing information about the traverse - */ -public void keyTraversed(TraverseEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java deleted file mode 100755 index c7dacb892b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -/** - * This adapter class provides default implementations for the - * methods described by the <code>TreeListener</code> interface. - * <p> - * Classes that wish to deal with <code>TreeEvent</code>s can - * extend this class and override only the methods which they are - * interested in. - * </p> - * - * @see TreeListener - * @see TreeEvent - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class TreeAdapter implements TreeListener { - -/** - * Sent when a tree branch is collapsed. - * The default behavior is to do nothing. - * - * @param e an event containing information about the tree operation - */ -public void treeCollapsed(TreeEvent e) { -} - -/** - * Sent when a tree branch is expanded. - * The default behavior is to do nothing. - * - * @param e an event containing information about the tree operation - */ -public void treeExpanded(TreeEvent e) { -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java deleted file mode 100755 index 1a3dbc547d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * trees being expanded and collapsed. - * - * @see TreeListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class TreeEvent extends SelectionEvent { - - static final long serialVersionUID = 3257282548009677109L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public TreeEvent(Event e) { - super(e); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java deleted file mode 100755 index 9e45cc2630..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the expanding and collapsing of tree - * branches. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a tree control using the - * <code>addTreeListener</code> method and removed using - * the <code>removeTreeListener</code> method. When a branch - * of the tree is expanded or collapsed, the appropriate method - * will be invoked. - * </p> - * - * @see TreeAdapter - * @see TreeEvent - */ -public interface TreeListener extends SWTEventListener { - -/** - * Sent when a tree branch is collapsed. - * - * @param e an event containing information about the tree operation - */ -public void treeCollapsed(TreeEvent e); - -/** - * Sent when a tree branch is expanded. - * - * @param e an event containing information about the tree operation - */ -public void treeExpanded(TreeEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java deleted file mode 100755 index 1f2f8676f7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.internal.SWTEventObject; - -/** - * This is the super class for all typed event classes provided - * by SWT. Typed events contain particular information which is - * applicable to the event occurrence. - * - * @see org.eclipse.swt.widgets.Event - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public class TypedEvent extends SWTEventObject { - - /** - * the display where the event occurred - * - * @since 2.0 - */ - public Display display; - - /** - * the widget that issued the event - */ - public Widget widget; - - /** - * the time that the event occurred. - * - * NOTE: This field is an unsigned integer and should - * be AND'ed with 0xFFFFFFFFL so that it can be treated - * as a signed long. - */ - public int time; - - /** - * a field for application use - */ - public Object data; - - static final long serialVersionUID = 3257285846578377524L; - -/** - * Constructs a new instance of this class. - * - * @param object the object that fired the event - */ -public TypedEvent(Object object) { - super(object); -} - -/** - * Constructs a new instance of this class based on the - * information in the argument. - * - * @param e the low level event to initialize the receiver with - */ -public TypedEvent(Event e) { - super(e.widget); - this.display = e.display; - this.widget = e.widget; - this.time = e.time; - this.data = e.data; -} - -/** - * Returns the name of the event. This is the name of - * the class without the package name. - * - * @return the name of the event - */ -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - return getName () - + "{" + widget - + " time=" + time - + " data=" + data - + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java deleted file mode 100755 index 527aaba7e6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.widgets.Event; - -/** - * Instances of this class are sent as a result of - * widgets handling keyboard events - * - * @see VerifyListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class VerifyEvent extends KeyEvent { - - /** - * the range of text being modified. - * Setting these fields has no effect. - */ - public int start, end; - - /** - * the new text that will be inserted. - * Setting this field will change the text that is about to - * be inserted or deleted. - */ - public String text; - - static final long serialVersionUID = 3257003246269577014L; - -/** - * Constructs a new instance of this class based on the - * information in the given untyped event. - * - * @param e the untyped event containing the information - */ -public VerifyEvent(Event e) { - super(e); - this.start = e.start; - this.end = e.end; - this.text = e.text; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - String string = super.toString (); - return string.substring (0, string.length() - 1) // remove trailing '}' - + " start=" + start - + " end=" + end - + " text=" + text - + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java deleted file mode 100755 index 653e203387..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.events; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide a method - * that deals with the events that are generated when text - * is about to be modified. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to a text control using the - * <code>addVerifyListener</code> method and removed using - * the <code>removeVerifyListener</code> method. When the - * text is about to be modified, the verifyText method - * will be invoked. - * </p> - * - * @see VerifyEvent - */ -public interface VerifyListener extends SWTEventListener { - -/** - * Sent when the text is about to be modified. - * <p> - * A verify event occurs after the user has done something - * to modify the text (typically typed a key), but before - * the text is modified. The doit field in the verify event - * indicates whether or not to modify the text. - * </p> - * - * @param e an event containing information about the verify - */ -public void verifyText(VerifyEvent e); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html deleted file mode 100755 index b6325f9463..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html +++ /dev/null @@ -1,23 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -SWT typed listener support. -<h2> -Package Specification</h2> -This package provides the typed events and listener interfaces and, -where appropriate, matching adapter classes which make up the -"high level" <em>typed listener</em> support provided by SWT. -<p> -For contrast, see also the <em>untyped listener</em> support provided -by class <code>org.eclipse.swt.widgets.Event</code> and interface -<code>org.eclipse.swt.widgets.Listener</code>, and the -<code>addListener</code> and <code>removeListener</code> methods in -class <code>org.eclipse.swt.widgets.Widget</code>. -</p> -</body> -</html> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java deleted file mode 100755 index 2d909d1c0f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -/** - * Implementers of <code>Drawable</code> can have a graphics context (GC) - * created for them, and then they can be drawn on by sending messages to - * their associated GC. SWT images, and device objects such as the Display - * device and the Printer device, are drawables. - * <p> - * <b>IMPORTANT:</b> This interface is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It should never be - * referenced from application code. - * </p> - * - * @see Device - * @see Image - * @see GC - */ -public interface Drawable { - -/** - * Invokes platform specific functionality to allocate a new GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Drawable</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param data the platform specific GC data - * @return the platform specific GC handle - */ - -public int /*long*/ internal_new_GC (GCData data); - -/** - * Invokes platform specific functionality to dispose a GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Drawable</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param handle the platform specific GC handle - * @param data the platform specific GC data - */ -public void internal_dispose_GC (int /*long*/ handle, GCData data); - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java deleted file mode 100644 index ccc0c386b5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.*; - -/** - * Instances of this class represent glyph metrics. - * <p> - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - * </p> - * <p> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * </p> - * - * @see TextStyle - * @see TextLayout - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.2 - */ -public final class GlyphMetrics { - - /** - * the ascent of the GlyphMetrics - */ - public int ascent; - - /** - * the descent of the GlyphMetrics - */ - public int descent; - - /** - * the width of the GlyphMetrics - */ - public int width; - -/** - * Constructs an instance of this class with the given - * ascent, descent and width values. - * - * @param ascent the GlyphMetrics ascent - * @param descent the GlyphMetrics descent - * @param width the GlyphMetrics width - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the ascent, descent or width argument is negative</li> - * </ul> - */ -public GlyphMetrics(int ascent, int descent, int width) { - if (ascent < 0 || descent < 0 || width < 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - this.ascent = ascent; - this.descent = descent; - this.width = width; -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode() - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof GlyphMetrics)) return false; - GlyphMetrics metrics = (GlyphMetrics)object; - return metrics.ascent == ascent && metrics.descent == descent && metrics.width == width; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ -public int hashCode () { - return ascent ^ descent ^ width; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the <code>GlyphMetrics</code> - */ -public String toString () { - return "GlyphMetrics {" + ascent + ", " + descent + ", " + width + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java deleted file mode 100755 index 24c7f646b8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java +++ /dev/null @@ -1,3673 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import java.io.*; -import org.eclipse.swt.*; -import org.eclipse.swt.internal.CloneableCompatibility; - -/** - * Instances of this class are device-independent descriptions - * of images. They are typically used as an intermediate format - * between loading from or writing to streams and creating an - * <code>Image</code>. - * <p> - * Note that the public fields <code>x</code>, <code>y</code>, - * <code>disposalMethod</code> and <code>delayTime</code> are - * typically only used when the image is in a set of images used - * for animation. - * </p> - * - * @see Image - * @see ImageLoader - * @see <a href="http://www.eclipse.org/swt/snippets/#image">ImageData snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ImageAnalyzer</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class ImageData implements CloneableCompatibility { - - /** - * The width of the image, in pixels. - */ - public int width; - - /** - * The height of the image, in pixels. - */ - public int height; - - /** - * The color depth of the image, in bits per pixel. - * <p> - * Note that a depth of 8 or less does not necessarily - * mean that the image is palette indexed, or - * conversely that a depth greater than 8 means that - * the image is direct color. Check the associated - * PaletteData's isDirect field for such determinations. - */ - public int depth; - - /** - * The scanline padding. - * <p> - * If one scanline of the image is not a multiple of - * this number, it will be padded with zeros until it is. - * </p> - */ - public int scanlinePad; - - /** - * The number of bytes per scanline. - * <p> - * This is a multiple of the scanline padding. - * </p> - */ - public int bytesPerLine; - - /** - * The pixel data of the image. - * <p> - * Note that for 16 bit depth images the pixel data is stored - * in least significant byte order; however, for 24bit and - * 32bit depth images the pixel data is stored in most - * significant byte order. - * </p> - */ - public byte[] data; - - /** - * The color table for the image. - */ - public PaletteData palette; - - /** - * The transparent pixel. - * <p> - * Pixels with this value are transparent. - * </p><p> - * The default is -1 which means 'no transparent pixel'. - * </p> - */ - public int transparentPixel; - - /** - * An icon-specific field containing the data from the icon mask. - * <p> - * This is a 1 bit bitmap stored with the most significant - * bit first. The number of bytes per scanline is - * '((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad'. - * </p><p> - * The default is null which means 'no transparency mask'. - * </p> - */ - public byte[] maskData; - - /** - * An icon-specific field containing the scanline pad of the mask. - * <p> - * If one scanline of the transparency mask is not a - * multiple of this number, it will be padded with zeros until - * it is. - * </p> - */ - public int maskPad; - - /** - * The alpha data of the image. - * <p> - * Every pixel can have an <em>alpha blending</em> value that - * varies from 0, meaning fully transparent, to 255 meaning - * fully opaque. The number of bytes per scanline is - * 'width'. - * </p> - */ - public byte[] alphaData; - - /** - * The global alpha value to be used for every pixel. - * <p> - * If this value is set, the <code>alphaData</code> field - * is ignored and when the image is rendered each pixel - * will be blended with the background an amount - * proportional to this value. - * </p><p> - * The default is -1 which means 'no global alpha value' - * </p> - */ - public int alpha; - - /** - * The type of file from which the image was read. - * - * It is expressed as one of the following values: - * <dl> - * <dt><code>IMAGE_BMP</code></dt> - * <dd>Windows BMP file format, no compression</dd> - * <dt><code>IMAGE_BMP_RLE</code></dt> - * <dd>Windows BMP file format, RLE compression if appropriate</dd> - * <dt><code>IMAGE_GIF</code></dt> - * <dd>GIF file format</dd> - * <dt><code>IMAGE_ICO</code></dt> - * <dd>Windows ICO file format</dd> - * <dt><code>IMAGE_JPEG</code></dt> - * <dd>JPEG file format</dd> - * <dt><code>IMAGE_PNG</code></dt> - * <dd>PNG file format</dd> - * </dl> - */ - public int type; - - /** - * The x coordinate of the top left corner of the image - * within the logical screen (this field corresponds to - * the GIF89a Image Left Position value). - */ - public int x; - - /** - * The y coordinate of the top left corner of the image - * within the logical screen (this field corresponds to - * the GIF89a Image Top Position value). - */ - public int y; - - /** - * A description of how to dispose of the current image - * before displaying the next. - * - * It is expressed as one of the following values: - * <dl> - * <dt><code>DM_UNSPECIFIED</code></dt> - * <dd>disposal method not specified</dd> - * <dt><code>DM_FILL_NONE</code></dt> - * <dd>do nothing - leave the image in place</dd> - * <dt><code>DM_FILL_BACKGROUND</code></dt> - * <dd>fill with the background color</dd> - * <dt><code>DM_FILL_PREVIOUS</code></dt> - * <dd>restore the previous picture</dd> - * </dl> - * (this field corresponds to the GIF89a Disposal Method value) - */ - public int disposalMethod; - - /** - * The time to delay before displaying the next image - * in an animation (this field corresponds to the GIF89a - * Delay Time value). - */ - public int delayTime; - - /** - * Arbitrary channel width data to 8-bit conversion table. - */ - static final byte[][] ANY_TO_EIGHT = new byte[9][]; - static { - for (int b = 0; b < 9; ++b) { - byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b]; - if (b == 0) continue; - int inc = 0; - for (int bit = 0x10000; (bit >>= b) != 0;) inc |= bit; - for (int v = 0, p = 0; v < 0x10000; v+= inc) data[p++] = (byte)(v >> 8); - } - } - static final byte[] ONE_TO_ONE_MAPPING = ANY_TO_EIGHT[8]; - - /** - * Scaled 8x8 Bayer dither matrix. - */ - static final int[][] DITHER_MATRIX = { - { 0xfc0000, 0x7c0000, 0xdc0000, 0x5c0000, 0xf40000, 0x740000, 0xd40000, 0x540000 }, - { 0x3c0000, 0xbc0000, 0x1c0000, 0x9c0000, 0x340000, 0xb40000, 0x140000, 0x940000 }, - { 0xcc0000, 0x4c0000, 0xec0000, 0x6c0000, 0xc40000, 0x440000, 0xe40000, 0x640000 }, - { 0x0c0000, 0x8c0000, 0x2c0000, 0xac0000, 0x040000, 0x840000, 0x240000, 0xa40000 }, - { 0xf00000, 0x700000, 0xd00000, 0x500000, 0xf80000, 0x780000, 0xd80000, 0x580000 }, - { 0x300000, 0xb00000, 0x100000, 0x900000, 0x380000, 0xb80000, 0x180000, 0x980000 }, - { 0xc00000, 0x400000, 0xe00000, 0x600000, 0xc80000, 0x480000, 0xe80000, 0x680000 }, - { 0x000000, 0x800000, 0x200000, 0xa00000, 0x080000, 0x880000, 0x280000, 0xa80000 } - }; - -/** - * Constructs a new, empty ImageData with the given width, height, - * depth and palette. The data will be initialized to an (all zero) - * array of the appropriate size. - * - * @param width the width of the image - * @param height the height of the image - * @param depth the depth of the image - * @param palette the palette of the image (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the width or height is zero or negative, or if the depth is not - * one of 1, 2, 4, 8, 16, 24 or 32</li> - * <li>ERROR_NULL_ARGUMENT - if the palette is null</li> - * </ul> - */ -public ImageData(int width, int height, int depth, PaletteData palette) { - this(width, height, depth, palette, - 4, null, 0, null, - null, -1, -1, SWT.IMAGE_UNDEFINED, - 0, 0, 0, 0); -} - -/** - * Constructs a new, empty ImageData with the given width, height, - * depth, palette, scanlinePad and data. - * - * @param width the width of the image - * @param height the height of the image - * @param depth the depth of the image - * @param palette the palette of the image - * @param scanlinePad the padding of each line, in bytes - * @param data the data of the image - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the width or height is zero or negative, or if the depth is not - * one of 1, 2, 4, 8, 16, 24 or 32, or the data array is too small to contain the image data</li> - * <li>ERROR_NULL_ARGUMENT - if the palette or data is null</li> - * <li>ERROR_CANNOT_BE_ZERO - if the scanlinePad is zero</li> - * </ul> - */ -public ImageData(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data) { - this(width, height, depth, palette, - scanlinePad, checkData(data), 0, null, - null, -1, -1, SWT.IMAGE_UNDEFINED, - 0, 0, 0, 0); -} - -/** - * Constructs an <code>ImageData</code> loaded from the specified - * input stream. Throws an error if an error occurs while loading - * the image, or if the image has an unsupported type. Application - * code is still responsible for closing the input stream. - * <p> - * This constructor is provided for convenience when loading a single - * image only. If the stream contains multiple images, only the first - * one will be loaded. To load multiple images, use - * <code>ImageLoader.load()</code>. - * </p><p> - * This constructor may be used to load a resource as follows: - * </p> - * <pre> - * static ImageData loadImageData (Class clazz, String string) { - * InputStream stream = clazz.getResourceAsStream (string); - * if (stream == null) return null; - * ImageData imageData = null; - * try { - * imageData = new ImageData (stream); - * } catch (SWTException ex) { - * } finally { - * try { - * stream.close (); - * } catch (IOException ex) {} - * } - * return imageData; - * } - * </pre> - * - * @param stream the input stream to load the image from (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> - * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> - * </ul> - * - * @see ImageLoader#load(InputStream) - */ -public ImageData(InputStream stream) { - ImageData[] data = ImageDataLoader.load(stream); - if (data.length < 1) SWT.error(SWT.ERROR_INVALID_IMAGE); - ImageData i = data[0]; - setAllFields( - i.width, - i.height, - i.depth, - i.scanlinePad, - i.bytesPerLine, - i.data, - i.palette, - i.transparentPixel, - i.maskData, - i.maskPad, - i.alphaData, - i.alpha, - i.type, - i.x, - i.y, - i.disposalMethod, - i.delayTime); -} - -/** - * Constructs an <code>ImageData</code> loaded from a file with the - * specified name. Throws an error if an error occurs loading the - * image, or if the image has an unsupported type. - * <p> - * This constructor is provided for convenience when loading a single - * image only. If the file contains multiple images, only the first - * one will be loaded. To load multiple images, use - * <code>ImageLoader.load()</code>. - * </p> - * - * @param filename the name of the file to load the image from (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the file name is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while reading from the file</li> - * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li> - * </ul> - */ -public ImageData(String filename) { - ImageData[] data = ImageDataLoader.load(filename); - if (data.length < 1) SWT.error(SWT.ERROR_INVALID_IMAGE); - ImageData i = data[0]; - setAllFields( - i.width, - i.height, - i.depth, - i.scanlinePad, - i.bytesPerLine, - i.data, - i.palette, - i.transparentPixel, - i.maskData, - i.maskPad, - i.alphaData, - i.alpha, - i.type, - i.x, - i.y, - i.disposalMethod, - i.delayTime); -} - -/** - * Prevents uninitialized instances from being created outside the package. - */ -ImageData() { -} - -/** - * Constructs an image data by giving values for all non-computable fields. - * <p> - * This method is for internal use, and is not described further. - * </p> - */ -ImageData( - int width, int height, int depth, PaletteData palette, - int scanlinePad, byte[] data, int maskPad, byte[] maskData, - byte[] alphaData, int alpha, int transparentPixel, int type, - int x, int y, int disposalMethod, int delayTime) -{ - - if (palette == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (!(depth == 1 || depth == 2 || depth == 4 || depth == 8 - || depth == 16 || depth == 24 || depth == 32)) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - if (width <= 0 || height <= 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - if (scanlinePad == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO); - - int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1)) - / scanlinePad * scanlinePad; - - /* - * When the image is being loaded from a PNG, we need to use the theoretical minimum - * number of bytes per line to check whether there is enough data, because the actual - * number of bytes per line is calculated based on the given depth, which may be larger - * than the actual depth of the PNG. - */ - int minBytesPerLine = type == SWT.IMAGE_PNG ? ((((width + 7) / 8) + 3) / 4) * 4 : bytesPerLine; - if (data != null && data.length < minBytesPerLine * height) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - setAllFields( - width, - height, - depth, - scanlinePad, - bytesPerLine, - data != null ? data : new byte[bytesPerLine * height], - palette, - transparentPixel, - maskData, - maskPad, - alphaData, - alpha, - type, - x, - y, - disposalMethod, - delayTime); -} - -/** - * Initializes all fields in the receiver. This method must be called - * by all public constructors to ensure that all fields are initialized - * for a new ImageData object. If a new field is added to the class, - * then it must be added to this method. - * <p> - * This method is for internal use, and is not described further. - * </p> - */ -void setAllFields(int width, int height, int depth, int scanlinePad, - int bytesPerLine, byte[] data, PaletteData palette, int transparentPixel, - byte[] maskData, int maskPad, byte[] alphaData, int alpha, - int type, int x, int y, int disposalMethod, int delayTime) { - - this.width = width; - this.height = height; - this.depth = depth; - this.scanlinePad = scanlinePad; - this.bytesPerLine = bytesPerLine; - this.data = data; - this.palette = palette; - this.transparentPixel = transparentPixel; - this.maskData = maskData; - this.maskPad = maskPad; - this.alphaData = alphaData; - this.alpha = alpha; - this.type = type; - this.x = x; - this.y = y; - this.disposalMethod = disposalMethod; - this.delayTime = delayTime; -} - -/** - * Invokes internal SWT functionality to create a new instance of - * this class. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>ImageData</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is subject - * to change without notice, and should never be called from - * application code. - * </p> - * <p> - * This method is for internal use, and is not described further. - * </p> - */ -public static ImageData internal_new( - int width, int height, int depth, PaletteData palette, - int scanlinePad, byte[] data, int maskPad, byte[] maskData, - byte[] alphaData, int alpha, int transparentPixel, int type, - int x, int y, int disposalMethod, int delayTime) -{ - return new ImageData( - width, height, depth, palette, scanlinePad, data, maskPad, maskData, - alphaData, alpha, transparentPixel, type, x, y, disposalMethod, delayTime); -} - -ImageData colorMaskImage(int pixel) { - ImageData mask = new ImageData(width, height, 1, bwPalette(), - 2, null, 0, null, null, -1, -1, SWT.IMAGE_UNDEFINED, - 0, 0, 0, 0); - int[] row = new int[width]; - for (int y = 0; y < height; y++) { - getPixels(0, y, width, row, 0); - for (int i = 0; i < width; i++) { - if (pixel != -1 && row[i] == pixel) { - row[i] = 0; - } else { - row[i] = 1; - } - } - mask.setPixels(0, y, width, row, 0); - } - return mask; -} - -static byte[] checkData(byte [] data) { - if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return data; -} - -/** - * Returns a new instance of the same class as the receiver, - * whose slots have been filled in with <em>copies</em> of - * the values in the slots of the receiver. That is, the - * returned object is a <em>deep copy</em> of the receiver. - * - * @return a copy of the receiver. - */ -public Object clone() { - byte[] cloneData = new byte[data.length]; - System.arraycopy(data, 0, cloneData, 0, data.length); - byte[] cloneMaskData = null; - if (maskData != null) { - cloneMaskData = new byte[maskData.length]; - System.arraycopy(maskData, 0, cloneMaskData, 0, maskData.length); - } - byte[] cloneAlphaData = null; - if (alphaData != null) { - cloneAlphaData = new byte[alphaData.length]; - System.arraycopy(alphaData, 0, cloneAlphaData, 0, alphaData.length); - } - return new ImageData( - width, - height, - depth, - palette, - scanlinePad, - cloneData, - maskPad, - cloneMaskData, - cloneAlphaData, - alpha, - transparentPixel, - type, - x, - y, - disposalMethod, - delayTime); -} - -/** - * Returns the alpha value at offset <code>x</code> in - * scanline <code>y</code> in the receiver's alpha data. - * The alpha value is between 0 (transparent) and - * 255 (opaque). - * - * @param x the x coordinate of the pixel to get the alpha value of - * @param y the y coordinate of the pixel to get the alpha value of - * @return the alpha value at the given coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if either argument is out of range</li> - * </ul> - */ -public int getAlpha(int x, int y) { - if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - - if (alphaData == null) return 255; - return alphaData[y * width + x] & 0xFF; -} - -/** - * Returns <code>getWidth</code> alpha values starting at offset - * <code>x</code> in scanline <code>y</code> in the receiver's alpha - * data starting at <code>startIndex</code>. The alpha values - * are unsigned, between <code>(byte)0</code> (transparent) and - * <code>(byte)255</code> (opaque). - * - * @param x the x position of the pixel to begin getting alpha values - * @param y the y position of the pixel to begin getting alpha values - * @param getWidth the width of the data to get - * @param alphas the buffer in which to put the alpha values - * @param startIndex the offset into the image to begin getting alpha values - * - * @exception IndexOutOfBoundsException if getWidth is too large - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if pixels is null</li> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li> - * </ul> - */ -public void getAlphas(int x, int y, int getWidth, byte[] alphas, int startIndex) { - if (alphas == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (getWidth == 0) return; - - if (alphaData == null) { - int endIndex = startIndex + getWidth; - for (int i = startIndex; i < endIndex; i++) { - alphas[i] = (byte)255; - } - return; - } - // may throw an IndexOutOfBoundsException - System.arraycopy(alphaData, y * width + x, alphas, startIndex, getWidth); -} - -/** - * Returns the pixel value at offset <code>x</code> in - * scanline <code>y</code> in the receiver's data. - * - * @param x the x position of the pixel to get - * @param y the y position of the pixel to get - * @return the pixel at the given coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if either argument is out of bounds</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li> - * </ul> - */ -public int getPixel(int x, int y) { - if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int index; - int theByte; - int mask; - switch (depth) { - case 32: - index = (y * bytesPerLine) + (x * 4); - return ((data[index] & 0xFF) << 24) + ((data[index+1] & 0xFF) << 16) + - ((data[index+2] & 0xFF) << 8) + (data[index+3] & 0xFF); - case 24: - index = (y * bytesPerLine) + (x * 3); - return ((data[index] & 0xFF) << 16) + ((data[index+1] & 0xFF) << 8) + - (data[index+2] & 0xFF); - case 16: - index = (y * bytesPerLine) + (x * 2); - return ((data[index+1] & 0xFF) << 8) + (data[index] & 0xFF); - case 8: - index = (y * bytesPerLine) + x ; - return data[index] & 0xFF; - case 4: - index = (y * bytesPerLine) + (x >> 1); - theByte = data[index] & 0xFF; - if ((x & 0x1) == 0) { - return theByte >> 4; - } else { - return theByte & 0x0F; - } - case 2: - index = (y * bytesPerLine) + (x >> 2); - theByte = data[index] & 0xFF; - int offset = 3 - (x % 4); - mask = 3 << (offset * 2); - return (theByte & mask) >> (offset * 2); - case 1: - index = (y * bytesPerLine) + (x >> 3); - theByte = data[index] & 0xFF; - mask = 1 << (7 - (x & 0x7)); - if ((theByte & mask) == 0) { - return 0; - } else { - return 1; - } - } - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - return 0; -} - -/** - * Returns <code>getWidth</code> pixel values starting at offset - * <code>x</code> in scanline <code>y</code> in the receiver's - * data starting at <code>startIndex</code>. - * - * @param x the x position of the first pixel to get - * @param y the y position of the first pixel to get - * @param getWidth the width of the data to get - * @param pixels the buffer in which to put the pixels - * @param startIndex the offset into the byte array to begin storing pixels - * - * @exception IndexOutOfBoundsException if getWidth is too large - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if pixels is null</li> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4 or 8 - * (For higher depths, use the int[] version of this method.)</li> - * </ul> - */ -public void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex) { - if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (getWidth == 0) return; - int index; - int theByte; - int mask = 0; - int n = getWidth; - int i = startIndex; - int srcX = x, srcY = y; - switch (depth) { - case 8: - index = (y * bytesPerLine) + x; - for (int j = 0; j < getWidth; j++) { - pixels[i] = data[index]; - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - return; - case 4: - index = (y * bytesPerLine) + (x >> 1); - if ((x & 0x1) == 1) { - theByte = data[index] & 0xFF; - pixels[i] = (byte)(theByte & 0x0F); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - while (n > 1) { - theByte = data[index] & 0xFF; - pixels[i] = (byte)(theByte >> 4); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - pixels[i] = (byte)(theByte & 0x0F); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - } - if (n > 0) { - theByte = data[index] & 0xFF; - pixels[i] = (byte)(theByte >> 4); - } - return; - case 2: - index = (y * bytesPerLine) + (x >> 2); - theByte = data[index] & 0xFF; - int offset; - while (n > 0) { - offset = 3 - (srcX % 4); - mask = 3 << (offset * 2); - pixels[i] = (byte)((theByte & mask) >> (offset * 2)); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - if (n > 0) theByte = data[index] & 0xFF; - srcX = 0; - } else { - if (offset == 0) { - index++; - theByte = data[index] & 0xFF; - } - } - } - return; - case 1: - index = (y * bytesPerLine) + (x >> 3); - theByte = data[index] & 0xFF; - while (n > 0) { - mask = 1 << (7 - (srcX & 0x7)); - if ((theByte & mask) == 0) { - pixels[i] = 0; - } else { - pixels[i] = 1; - } - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - if (n > 0) theByte = data[index] & 0xFF; - srcX = 0; - } else { - if (mask == 1) { - index++; - if (n > 0) theByte = data[index] & 0xFF; - } - } - } - return; - } - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); -} - -/** - * Returns <code>getWidth</code> pixel values starting at offset - * <code>x</code> in scanline <code>y</code> in the receiver's - * data starting at <code>startIndex</code>. - * - * @param x the x position of the first pixel to get - * @param y the y position of the first pixel to get - * @param getWidth the width of the data to get - * @param pixels the buffer in which to put the pixels - * @param startIndex the offset into the buffer to begin storing pixels - * - * @exception IndexOutOfBoundsException if getWidth is too large - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if pixels is null</li> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li> - * </ul> - */ -public void getPixels(int x, int y, int getWidth, int[] pixels, int startIndex) { - if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (getWidth == 0) return; - int index; - int theByte; - int mask; - int n = getWidth; - int i = startIndex; - int srcX = x, srcY = y; - switch (depth) { - case 32: - index = (y * bytesPerLine) + (x * 4); - i = startIndex; - for (int j = 0; j < getWidth; j++) { - pixels[i] = ((data[index] & 0xFF) << 24) | ((data[index+1] & 0xFF) << 16) - | ((data[index+2] & 0xFF) << 8) | (data[index+3] & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index += 4; - } - } - return; - case 24: - index = (y * bytesPerLine) + (x * 3); - for (int j = 0; j < getWidth; j++) { - pixels[i] = ((data[index] & 0xFF) << 16) | ((data[index+1] & 0xFF) << 8) - | (data[index+2] & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index += 3; - } - } - return; - case 16: - index = (y * bytesPerLine) + (x * 2); - for (int j = 0; j < getWidth; j++) { - pixels[i] = ((data[index+1] & 0xFF) << 8) + (data[index] & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index += 2; - } - } - return; - case 8: - index = (y * bytesPerLine) + x; - for (int j = 0; j < getWidth; j++) { - pixels[i] = data[index] & 0xFF; - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - return; - case 4: - index = (y * bytesPerLine) + (x >> 1); - if ((x & 0x1) == 1) { - theByte = data[index] & 0xFF; - pixels[i] = theByte & 0x0F; - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - while (n > 1) { - theByte = data[index] & 0xFF; - pixels[i] = theByte >> 4; - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - pixels[i] = theByte & 0x0F; - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - } - if (n > 0) { - theByte = data[index] & 0xFF; - pixels[i] = theByte >> 4; - } - return; - case 2: - index = (y * bytesPerLine) + (x >> 2); - theByte = data[index] & 0xFF; - int offset; - while (n > 0) { - offset = 3 - (srcX % 4); - mask = 3 << (offset * 2); - pixels[i] = (byte)((theByte & mask) >> (offset * 2)); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - if (n > 0) theByte = data[index] & 0xFF; - srcX = 0; - } else { - if (offset == 0) { - index++; - theByte = data[index] & 0xFF; - } - } - } - return; - case 1: - index = (y * bytesPerLine) + (x >> 3); - theByte = data[index] & 0xFF; - while (n > 0) { - mask = 1 << (7 - (srcX & 0x7)); - if ((theByte & mask) == 0) { - pixels[i] = 0; - } else { - pixels[i] = 1; - } - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - if (n > 0) theByte = data[index] & 0xFF; - srcX = 0; - } else { - if (mask == 1) { - index++; - if (n > 0) theByte = data[index] & 0xFF; - } - } - } - return; - } - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); -} - -/** - * Returns an array of <code>RGB</code>s which comprise the - * indexed color table of the receiver, or null if the receiver - * has a direct color model. - * - * @return the RGB values for the image or null if direct color - * - * @see PaletteData#getRGBs() - */ -public RGB[] getRGBs() { - return palette.getRGBs(); -} - -/** - * Returns an <code>ImageData</code> which specifies the - * transparency mask information for the receiver. If the - * receiver has no transparency or is not an icon, returns - * an opaque mask. - * - * @return the transparency mask - */ -public ImageData getTransparencyMask() { - if (getTransparencyType() == SWT.TRANSPARENCY_MASK) { - return new ImageData(width, height, 1, bwPalette(), maskPad, maskData); - } else { - return colorMaskImage(transparentPixel); - } -} - -/** - * Returns the image transparency type, which will be one of - * <code>SWT.TRANSPARENCY_NONE</code>, <code>SWT.TRANSPARENCY_MASK</code>, - * <code>SWT.TRANSPARENCY_PIXEL</code> or <code>SWT.TRANSPARENCY_ALPHA</code>. - * - * @return the receiver's transparency type - */ -public int getTransparencyType() { - if (maskData != null) return SWT.TRANSPARENCY_MASK; - if (transparentPixel != -1) return SWT.TRANSPARENCY_PIXEL; - if (alphaData != null) return SWT.TRANSPARENCY_ALPHA; - return SWT.TRANSPARENCY_NONE; -} - -/** - * Returns the byte order of the receiver. - * - * @return MSB_FIRST or LSB_FIRST - */ -int getByteOrder() { - return depth != 16 ? MSB_FIRST : LSB_FIRST; -} - -/** - * Returns a copy of the receiver which has been stretched or - * shrunk to the specified size. If either the width or height - * is negative, the resulting image will be inverted in the - * associated axis. - * - * @param width the width of the new ImageData - * @param height the height of the new ImageData - * @return a scaled copy of the image - */ -public ImageData scaledTo(int width, int height) { - /* Create a destination image with no data */ - final boolean flipX = (width < 0); - if (flipX) width = - width; - final boolean flipY = (height < 0); - if (flipY) height = - height; - - ImageData dest = new ImageData( - width, height, depth, palette, - scanlinePad, null, 0, null, - null, -1, transparentPixel, type, - x, y, disposalMethod, delayTime); - - /* Scale the image contents */ - if (palette.isDirect) blit(BLIT_SRC, - this.data, this.depth, this.bytesPerLine, this.getByteOrder(), 0, 0, this.width, this.height, 0, 0, 0, - ALPHA_OPAQUE, null, 0, 0, 0, - dest.data, dest.depth, dest.bytesPerLine, dest.getByteOrder(), 0, 0, dest.width, dest.height, 0, 0, 0, - flipX, flipY); - else blit(BLIT_SRC, - this.data, this.depth, this.bytesPerLine, this.getByteOrder(), 0, 0, this.width, this.height, null, null, null, - ALPHA_OPAQUE, null, 0, 0, 0, - dest.data, dest.depth, dest.bytesPerLine, dest.getByteOrder(), 0, 0, dest.width, dest.height, null, null, null, - flipX, flipY); - - /* Scale the image mask or alpha */ - if (maskData != null) { - dest.maskPad = this.maskPad; - int destBpl = (dest.width + 7) / 8; - destBpl = (destBpl + (dest.maskPad - 1)) / dest.maskPad * dest.maskPad; - dest.maskData = new byte[destBpl * dest.height]; - int srcBpl = (this.width + 7) / 8; - srcBpl = (srcBpl + (this.maskPad - 1)) / this.maskPad * this.maskPad; - blit(BLIT_SRC, - this.maskData, 1, srcBpl, MSB_FIRST, 0, 0, this.width, this.height, null, null, null, - ALPHA_OPAQUE, null, 0, 0, 0, - dest.maskData, 1, destBpl, MSB_FIRST, 0, 0, dest.width, dest.height, null, null, null, - flipX, flipY); - } else if (alpha != -1) { - dest.alpha = this.alpha; - } else if (alphaData != null) { - dest.alphaData = new byte[dest.width * dest.height]; - blit(BLIT_SRC, - this.alphaData, 8, this.width, MSB_FIRST, 0, 0, this.width, this.height, null, null, null, - ALPHA_OPAQUE, null, 0, 0, 0, - dest.alphaData, 8, dest.width, MSB_FIRST, 0, 0, dest.width, dest.height, null, null, null, - flipX, flipY); - } - return dest; -} - -/** - * Sets the alpha value at offset <code>x</code> in - * scanline <code>y</code> in the receiver's alpha data. - * The alpha value must be between 0 (transparent) - * and 255 (opaque). - * - * @param x the x coordinate of the alpha value to set - * @param y the y coordinate of the alpha value to set - * @param alpha the value to set the alpha to - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * </ul> - */ -public void setAlpha(int x, int y, int alpha) { - if (x >= width || y >= height || x < 0 || y < 0 || alpha < 0 || alpha > 255) - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - - if (alphaData == null) alphaData = new byte[width * height]; - alphaData[y * width + x] = (byte)alpha; -} - -/** - * Sets the alpha values starting at offset <code>x</code> in - * scanline <code>y</code> in the receiver's alpha data to the - * values from the array <code>alphas</code> starting at - * <code>startIndex</code>. The alpha values must be between - * <code>(byte)0</code> (transparent) and <code>(byte)255</code> (opaque) - * - * @param x the x coordinate of the pixel to being setting the alpha values - * @param y the y coordinate of the pixel to being setting the alpha values - * @param putWidth the width of the alpha values to set - * @param alphas the alpha values to set - * @param startIndex the index at which to begin setting - * - * @exception IndexOutOfBoundsException if putWidth is too large - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if pixels is null</li> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li> - * </ul> - */ -public void setAlphas(int x, int y, int putWidth, byte[] alphas, int startIndex) { - if (alphas == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (putWidth == 0) return; - - if (alphaData == null) alphaData = new byte[width * height]; - // may throw an IndexOutOfBoundsException - System.arraycopy(alphas, startIndex, alphaData, y * width + x, putWidth); -} - -/** - * Sets the pixel value at offset <code>x</code> in - * scanline <code>y</code> in the receiver's data. - * - * @param x the x coordinate of the pixel to set - * @param y the y coordinate of the pixel to set - * @param pixelValue the value to set the pixel to - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li> - * </ul> - */ -public void setPixel(int x, int y, int pixelValue) { - if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int index; - byte theByte; - int mask; - switch (depth) { - case 32: - index = (y * bytesPerLine) + (x * 4); - data[index] = (byte)((pixelValue >> 24) & 0xFF); - data[index + 1] = (byte)((pixelValue >> 16) & 0xFF); - data[index + 2] = (byte)((pixelValue >> 8) & 0xFF); - data[index + 3] = (byte)(pixelValue & 0xFF); - return; - case 24: - index = (y * bytesPerLine) + (x * 3); - data[index] = (byte)((pixelValue >> 16) & 0xFF); - data[index + 1] = (byte)((pixelValue >> 8) & 0xFF); - data[index + 2] = (byte)(pixelValue & 0xFF); - return; - case 16: - index = (y * bytesPerLine) + (x * 2); - data[index + 1] = (byte)((pixelValue >> 8) & 0xFF); - data[index] = (byte)(pixelValue & 0xFF); - return; - case 8: - index = (y * bytesPerLine) + x ; - data[index] = (byte)(pixelValue & 0xFF); - return; - case 4: - index = (y * bytesPerLine) + (x >> 1); - if ((x & 0x1) == 0) { - data[index] = (byte)((data[index] & 0x0F) | ((pixelValue & 0x0F) << 4)); - } else { - data[index] = (byte)((data[index] & 0xF0) | (pixelValue & 0x0F)); - } - return; - case 2: - index = (y * bytesPerLine) + (x >> 2); - theByte = data[index]; - int offset = 3 - (x % 4); - mask = 0xFF ^ (3 << (offset * 2)); - data[index] = (byte)((data[index] & mask) | (pixelValue << (offset * 2))); - return; - case 1: - index = (y * bytesPerLine) + (x >> 3); - theByte = data[index]; - mask = 1 << (7 - (x & 0x7)); - if ((pixelValue & 0x1) == 1) { - data[index] = (byte)(theByte | mask); - } else { - data[index] = (byte)(theByte & (mask ^ -1)); - } - return; - } - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); -} - -/** - * Sets the pixel values starting at offset <code>x</code> in - * scanline <code>y</code> in the receiver's data to the - * values from the array <code>pixels</code> starting at - * <code>startIndex</code>. - * - * @param x the x position of the pixel to set - * @param y the y position of the pixel to set - * @param putWidth the width of the pixels to set - * @param pixels the pixels to set - * @param startIndex the index at which to begin setting - * - * @exception IndexOutOfBoundsException if putWidth is too large - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if pixels is null</li> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8 - * (For higher depths, use the int[] version of this method.)</li> - * </ul> - */ -public void setPixels(int x, int y, int putWidth, byte[] pixels, int startIndex) { - if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (putWidth == 0) return; - int index; - int theByte; - int mask; - int n = putWidth; - int i = startIndex; - int srcX = x, srcY = y; - switch (depth) { - case 8: - index = (y * bytesPerLine) + x; - for (int j = 0; j < putWidth; j++) { - data[index] = (byte)(pixels[i] & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - return; - case 4: - index = (y * bytesPerLine) + (x >> 1); - boolean high = (x & 0x1) == 0; - while (n > 0) { - theByte = pixels[i] & 0x0F; - if (high) { - data[index] = (byte)((data[index] & 0x0F) | (theByte << 4)); - } else { - data[index] = (byte)((data[index] & 0xF0) | theByte); - } - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - high = true; - srcX = 0; - } else { - if (!high) index++; - high = !high; - } - } - return; - case 2: - byte [] masks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F }; - index = (y * bytesPerLine) + (x >> 2); - int offset = 3 - (x % 4); - while (n > 0) { - theByte = pixels[i] & 0x3; - data[index] = (byte)((data[index] & masks[offset]) | (theByte << (offset * 2))); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - offset = 0; - srcX = 0; - } else { - if (offset == 0) { - index++; - offset = 3; - } else { - offset--; - } - } - } - return; - case 1: - index = (y * bytesPerLine) + (x >> 3); - while (n > 0) { - mask = 1 << (7 - (srcX & 0x7)); - if ((pixels[i] & 0x1) == 1) { - data[index] = (byte)((data[index] & 0xFF) | mask); - } else { - data[index] = (byte)((data[index] & 0xFF) & (mask ^ -1)); - } - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - if (mask == 1) { - index++; - } - } - } - return; - } - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); -} - -/** - * Sets the pixel values starting at offset <code>x</code> in - * scanline <code>y</code> in the receiver's data to the - * values from the array <code>pixels</code> starting at - * <code>startIndex</code>. - * - * @param x the x position of the pixel to set - * @param y the y position of the pixel to set - * @param putWidth the width of the pixels to set - * @param pixels the pixels to set - * @param startIndex the index at which to begin setting - * - * @exception IndexOutOfBoundsException if putWidth is too large - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if pixels is null</li> - * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li> - * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li> - * </ul> - */ -public void setPixels(int x, int y, int putWidth, int[] pixels, int startIndex) { - if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (putWidth == 0) return; - int index; - int theByte; - int mask; - int n = putWidth; - int i = startIndex; - int pixel; - int srcX = x, srcY = y; - switch (depth) { - case 32: - index = (y * bytesPerLine) + (x * 4); - for (int j = 0; j < putWidth; j++) { - pixel = pixels[i]; - data[index] = (byte)((pixel >> 24) & 0xFF); - data[index + 1] = (byte)((pixel >> 16) & 0xFF); - data[index + 2] = (byte)((pixel >> 8) & 0xFF); - data[index + 3] = (byte)(pixel & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index += 4; - } - } - return; - case 24: - index = (y * bytesPerLine) + (x * 3); - for (int j = 0; j < putWidth; j++) { - pixel = pixels[i]; - data[index] = (byte)((pixel >> 16) & 0xFF); - data[index + 1] = (byte)((pixel >> 8) & 0xFF); - data[index + 2] = (byte)(pixel & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index += 3; - } - } - return; - case 16: - index = (y * bytesPerLine) + (x * 2); - for (int j = 0; j < putWidth; j++) { - pixel = pixels[i]; - data[index] = (byte)(pixel & 0xFF); - data[index + 1] = (byte)((pixel >> 8) & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index += 2; - } - } - return; - case 8: - index = (y * bytesPerLine) + x; - for (int j = 0; j < putWidth; j++) { - data[index] = (byte)(pixels[i] & 0xFF); - i++; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - index++; - } - } - return; - case 4: - index = (y * bytesPerLine) + (x >> 1); - boolean high = (x & 0x1) == 0; - while (n > 0) { - theByte = pixels[i] & 0x0F; - if (high) { - data[index] = (byte)((data[index] & 0x0F) | (theByte << 4)); - } else { - data[index] = (byte)((data[index] & 0xF0) | theByte); - } - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - high = true; - srcX = 0; - } else { - if (!high) index++; - high = !high; - } - } - return; - case 2: - byte [] masks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F }; - index = (y * bytesPerLine) + (x >> 2); - int offset = 3 - (x % 4); - while (n > 0) { - theByte = pixels[i] & 0x3; - data[index] = (byte)((data[index] & masks[offset]) | (theByte << (offset * 2))); - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - offset = 3; - srcX = 0; - } else { - if (offset == 0) { - index++; - offset = 3; - } else { - offset--; - } - } - } - return; - case 1: - index = (y * bytesPerLine) + (x >> 3); - while (n > 0) { - mask = 1 << (7 - (srcX & 0x7)); - if ((pixels[i] & 0x1) == 1) { - data[index] = (byte)((data[index] & 0xFF) | mask); - } else { - data[index] = (byte)((data[index] & 0xFF) & (mask ^ -1)); - } - i++; - n--; - srcX++; - if (srcX >= width) { - srcY++; - index = srcY * bytesPerLine; - srcX = 0; - } else { - if (mask == 1) { - index++; - } - } - } - return; - } - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); -} - -/** - * Returns a palette with 2 colors: black & white. - */ -static PaletteData bwPalette() { - return new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255, 255, 255)}); -} - -/** - * Gets the offset of the most significant bit for - * the given mask. - */ -static int getMSBOffset(int mask) { - for (int i = 31; i >= 0; i--) { - if (((mask >> i) & 0x1) != 0) return i + 1; - } - return 0; -} - -/** - * Finds the closest match. - */ -static int closestMatch(int depth, byte red, byte green, byte blue, int redMask, int greenMask, int blueMask, byte[] reds, byte[] greens, byte[] blues) { - if (depth > 8) { - int rshift = 32 - getMSBOffset(redMask); - int gshift = 32 - getMSBOffset(greenMask); - int bshift = 32 - getMSBOffset(blueMask); - return (((red << 24) >>> rshift) & redMask) | - (((green << 24) >>> gshift) & greenMask) | - (((blue << 24) >>> bshift) & blueMask); - } - int r, g, b; - int minDistance = 0x7fffffff; - int nearestPixel = 0; - int n = reds.length; - for (int j = 0; j < n; j++) { - r = (reds[j] & 0xFF) - (red & 0xFF); - g = (greens[j] & 0xFF) - (green & 0xFF); - b = (blues[j] & 0xFF) - (blue & 0xFF); - int distance = r*r + g*g + b*b; - if (distance < minDistance) { - nearestPixel = j; - if (distance == 0) break; - minDistance = distance; - } - } - return nearestPixel; -} - -static final ImageData convertMask(ImageData mask) { - if (mask.depth == 1) return mask; - PaletteData palette = new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255,255,255)}); - ImageData newMask = new ImageData(mask.width, mask.height, 1, palette); - /* Find index of black in mask palette */ - int blackIndex = 0; - RGB[] rgbs = mask.getRGBs(); - if (rgbs != null) { - while (blackIndex < rgbs.length) { - if (rgbs[blackIndex].equals(palette.colors[0])) break; - blackIndex++; - } - } - int[] pixels = new int[mask.width]; - for (int y = 0; y < mask.height; y++) { - mask.getPixels(0, y, mask.width, pixels, 0); - for (int i = 0; i < pixels.length; i++) { - if (pixels[i] == blackIndex) { - pixels[i] = 0; - } else { - pixels[i] = 1; - } - } - newMask.setPixels(0, y, mask.width, pixels, 0); - } - return newMask; -} - -static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) { - if (pad == newPad) return data; - int stride = (width * depth + 7) / 8; - int bpl = (stride + (pad - 1)) / pad * pad; - int newBpl = (stride + (newPad - 1)) / newPad * newPad; - byte[] newData = new byte[height * newBpl]; - int srcIndex = 0, destIndex = 0; - for (int y = 0; y < height; y++) { - System.arraycopy(data, srcIndex, newData, destIndex, stride); - srcIndex += bpl; - destIndex += newBpl; - } - return newData; -} - -/** - * Blit operation bits to be OR'ed together to specify the desired operation. - */ -static final int - BLIT_SRC = 1, // copy source directly, else applies logic operations - BLIT_ALPHA = 2, // enable alpha blending - BLIT_DITHER = 4; // enable dithering in low color modes - -/** - * Alpha mode, values 0 - 255 specify global alpha level - */ -static final int - ALPHA_OPAQUE = 255, // Fully opaque (ignores any alpha data) - ALPHA_TRANSPARENT = 0, // Fully transparent (ignores any alpha data) - ALPHA_CHANNEL_SEPARATE = -1, // Use alpha channel from separate alphaData - ALPHA_CHANNEL_SOURCE = -2, // Use alpha channel embedded in sourceData - ALPHA_MASK_UNPACKED = -3, // Use transparency mask formed by bytes in alphaData (non-zero is opaque) - ALPHA_MASK_PACKED = -4, // Use transparency mask formed by packed bits in alphaData - ALPHA_MASK_INDEX = -5, // Consider source palette indices transparent if in alphaData array - ALPHA_MASK_RGB = -6; // Consider source RGBs transparent if in RGB888 format alphaData array - -/** - * Byte and bit order constants. - */ -static final int LSB_FIRST = 0; -static final int MSB_FIRST = 1; - -/** - * Data types (internal) - */ -private static final int - // direct / true color formats with arbitrary masks & shifts - TYPE_GENERIC_8 = 0, - TYPE_GENERIC_16_MSB = 1, - TYPE_GENERIC_16_LSB = 2, - TYPE_GENERIC_24 = 3, - TYPE_GENERIC_32_MSB = 4, - TYPE_GENERIC_32_LSB = 5, - // palette indexed color formats - TYPE_INDEX_8 = 6, - TYPE_INDEX_4 = 7, - TYPE_INDEX_2 = 8, - TYPE_INDEX_1_MSB = 9, - TYPE_INDEX_1_LSB = 10; - -/** - * Blits a direct palette image into a direct palette image. - * <p> - * Note: When the source and destination depth, order and masks - * are pairwise equal and the blitter operation is BLIT_SRC, - * the masks are ignored. Hence when not changing the image - * data format, 0 may be specified for the masks. - * </p> - * - * @param op the blitter operation: a combination of BLIT_xxx flags - * (see BLIT_xxx constants) - * @param srcData the source byte array containing image data - * @param srcDepth the source depth: one of 8, 16, 24, 32 - * @param srcStride the source number of bytes per line - * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if srcDepth is not 16 or 32 - * @param srcX the top-left x-coord of the source blit region - * @param srcY the top-left y-coord of the source blit region - * @param srcWidth the width of the source blit region - * @param srcHeight the height of the source blit region - * @param srcRedMask the source red channel mask - * @param srcGreenMask the source green channel mask - * @param srcBlueMask the source blue channel mask - * @param alphaMode the alpha blending or mask mode, may be - * an integer 0-255 for global alpha; ignored if BLIT_ALPHA - * not specified in the blitter operations - * (see ALPHA_MODE_xxx constants) - * @param alphaData the alpha blending or mask data, varies depending - * on the value of alphaMode and sometimes ignored - * @param alphaStride the alpha data number of bytes per line - * @param alphaX the top-left x-coord of the alpha blit region - * @param alphaY the top-left y-coord of the alpha blit region - * @param destData the destination byte array containing image data - * @param destDepth the destination depth: one of 8, 16, 24, 32 - * @param destStride the destination number of bytes per line - * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if destDepth is not 16 or 32 - * @param destX the top-left x-coord of the destination blit region - * @param destY the top-left y-coord of the destination blit region - * @param destWidth the width of the destination blit region - * @param destHeight the height of the destination blit region - * @param destRedMask the destination red channel mask - * @param destGreenMask the destination green channel mask - * @param destBlueMask the destination blue channel mask - * @param flipX if true the resulting image is flipped along the vertical axis - * @param flipY if true the resulting image is flipped along the horizontal axis - */ -static void blit(int op, - byte[] srcData, int srcDepth, int srcStride, int srcOrder, - int srcX, int srcY, int srcWidth, int srcHeight, - int srcRedMask, int srcGreenMask, int srcBlueMask, - int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, - byte[] destData, int destDepth, int destStride, int destOrder, - int destX, int destY, int destWidth, int destHeight, - int destRedMask, int destGreenMask, int destBlueMask, - boolean flipX, boolean flipY) { - if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return; - - // these should be supplied as params later - final int srcAlphaMask = 0, destAlphaMask = 0; - - /*** Prepare scaling data ***/ - final int dwm1 = destWidth - 1; - final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; - final int dhm1 = destHeight - 1; - final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; - - /*** Prepare source-related data ***/ - final int sbpp, stype; - switch (srcDepth) { - case 8: - sbpp = 1; - stype = TYPE_GENERIC_8; - break; - case 16: - sbpp = 2; - stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB; - break; - case 24: - sbpp = 3; - stype = TYPE_GENERIC_24; - break; - case 32: - sbpp = 4; - stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int spr = srcY * srcStride + srcX * sbpp; - - /*** Prepare destination-related data ***/ - final int dbpp, dtype; - switch (destDepth) { - case 8: - dbpp = 1; - dtype = TYPE_GENERIC_8; - break; - case 16: - dbpp = 2; - dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB; - break; - case 24: - dbpp = 3; - dtype = TYPE_GENERIC_24; - break; - case 32: - dbpp = 4; - dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid destination type"); - return; - } - int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX) * dbpp; - final int dprxi = (flipX) ? -dbpp : dbpp; - final int dpryi = (flipY) ? -destStride : destStride; - - /*** Prepare special processing data ***/ - int apr; - if ((op & BLIT_ALPHA) != 0) { - switch (alphaMode) { - case ALPHA_MASK_UNPACKED: - case ALPHA_CHANNEL_SEPARATE: - if (alphaData == null) alphaMode = 0x10000; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_PACKED: - if (alphaData == null) alphaMode = 0x10000; - alphaStride <<= 3; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_INDEX: - //throw new IllegalArgumentException("Invalid alpha type"); - return; - case ALPHA_MASK_RGB: - if (alphaData == null) alphaMode = 0x10000; - apr = 0; - break; - default: - alphaMode = (alphaMode << 16) / 255; // prescale - case ALPHA_CHANNEL_SOURCE: - apr = 0; - break; - } - } else { - alphaMode = 0x10000; - apr = 0; - } - - /*** Blit ***/ - int dp = dpr; - int sp = spr; - if ((alphaMode == 0x10000) && (stype == dtype) && - (srcRedMask == destRedMask) && (srcGreenMask == destGreenMask) && - (srcBlueMask == destBlueMask) && (srcAlphaMask == destAlphaMask)) { - /*** Fast blit (straight copy) ***/ - switch (sbpp) { - case 1: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - sp += (sfx >>> 16); - } - } - break; - case 2: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - destData[dp + 1] = srcData[sp + 1]; - sp += (sfx >>> 16) * 2; - } - } - break; - case 3: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - destData[dp + 1] = srcData[sp + 1]; - destData[dp + 2] = srcData[sp + 2]; - sp += (sfx >>> 16) * 3; - } - } - break; - case 4: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp]; - destData[dp + 1] = srcData[sp + 1]; - destData[dp + 2] = srcData[sp + 2]; - destData[dp + 3] = srcData[sp + 3]; - sp += (sfx >>> 16) * 4; - } - } - break; - } - return; - } - /*Fast 32 to 32 blit */ - if (alphaMode == 0x10000 && stype == TYPE_GENERIC_32_MSB && dtype == TYPE_GENERIC_32_MSB) { - if (srcRedMask == 0xFF00 && srcGreenMask == 0xff0000 && srcBlueMask == 0xff000000 && destRedMask == 0xFF0000 && destGreenMask == 0xff00 && destBlueMask == 0xff) { - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = srcData[sp + 3]; - destData[dp + 1] = srcData[sp + 2]; - destData[dp + 2] = srcData[sp + 1]; - destData[dp + 3] = srcData[sp]; - sp += (sfx >>> 16) * 4; - } - } - return; - } - } - /*Fast 24 to 32 blit */ - if (alphaMode == 0x10000 && stype == TYPE_GENERIC_24 && dtype == TYPE_GENERIC_32_MSB) { - if (srcRedMask == 0xFF && srcGreenMask == 0xff00 && srcBlueMask == 0xff0000 && destRedMask == 0xFF0000 && destGreenMask == 0xff00 && destBlueMask == 0xff) { - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = 0; - destData[dp + 1] = srcData[sp + 2]; - destData[dp + 2] = srcData[sp + 1]; - destData[dp + 3] = srcData[sp]; - sp += (sfx >>> 16) * 3; - } - } - return; - } - } - - /*** Comprehensive blit (apply transformations) ***/ - final int srcRedShift = getChannelShift(srcRedMask); - final byte[] srcReds = ANY_TO_EIGHT[getChannelWidth(srcRedMask, srcRedShift)]; - final int srcGreenShift = getChannelShift(srcGreenMask); - final byte[] srcGreens = ANY_TO_EIGHT[getChannelWidth(srcGreenMask, srcGreenShift)]; - final int srcBlueShift = getChannelShift(srcBlueMask); - final byte[] srcBlues = ANY_TO_EIGHT[getChannelWidth(srcBlueMask, srcBlueShift)]; - final int srcAlphaShift = getChannelShift(srcAlphaMask); - final byte[] srcAlphas = ANY_TO_EIGHT[getChannelWidth(srcAlphaMask, srcAlphaShift)]; - - final int destRedShift = getChannelShift(destRedMask); - final int destRedWidth = getChannelWidth(destRedMask, destRedShift); - final byte[] destReds = ANY_TO_EIGHT[destRedWidth]; - final int destRedPreShift = 8 - destRedWidth; - final int destGreenShift = getChannelShift(destGreenMask); - final int destGreenWidth = getChannelWidth(destGreenMask, destGreenShift); - final byte[] destGreens = ANY_TO_EIGHT[destGreenWidth]; - final int destGreenPreShift = 8 - destGreenWidth; - final int destBlueShift = getChannelShift(destBlueMask); - final int destBlueWidth = getChannelWidth(destBlueMask, destBlueShift); - final byte[] destBlues = ANY_TO_EIGHT[destBlueWidth]; - final int destBluePreShift = 8 - destBlueWidth; - final int destAlphaShift = getChannelShift(destAlphaMask); - final int destAlphaWidth = getChannelWidth(destAlphaMask, destAlphaShift); - final byte[] destAlphas = ANY_TO_EIGHT[destAlphaWidth]; - final int destAlphaPreShift = 8 - destAlphaWidth; - - int ap = apr, alpha = alphaMode; - int r = 0, g = 0, b = 0, a = 0; - int rq = 0, gq = 0, bq = 0, aq = 0; - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, - sp = spr += (sfy >>> 16) * srcStride, - ap = apr += (sfy >>> 16) * alphaStride, - sfy = (sfy & 0xffff) + sfyi, - dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, - dp += dprxi, - sfx = (sfx & 0xffff) + sfxi) { - /*** READ NEXT PIXEL ***/ - switch (stype) { - case TYPE_GENERIC_8: { - final int data = srcData[sp] & 0xff; - sp += (sfx >>> 16); - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_MSB: { - final int data = ((srcData[sp] & 0xff) << 8) | (srcData[sp + 1] & 0xff); - sp += (sfx >>> 16) * 2; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_LSB: { - final int data = ((srcData[sp + 1] & 0xff) << 8) | (srcData[sp] & 0xff); - sp += (sfx >>> 16) * 2; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_24: { - final int data = (( ((srcData[sp] & 0xff) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp + 2] & 0xff); - sp += (sfx >>> 16) * 3; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_MSB: { - final int data = (( (( ((srcData[sp] & 0xff) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp + 2] & 0xff)) << 8) | - (srcData[sp + 3] & 0xff); - sp += (sfx >>> 16) * 4; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_LSB: { - final int data = (( (( ((srcData[sp + 3] & 0xff) << 8) | - (srcData[sp + 2] & 0xff)) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp] & 0xff); - sp += (sfx >>> 16) * 4; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - } - - /*** DO SPECIAL PROCESSING IF REQUIRED ***/ - switch (alphaMode) { - case ALPHA_CHANNEL_SEPARATE: - alpha = ((alphaData[ap] & 0xff) << 16) / 255; - ap += (sfx >> 16); - break; - case ALPHA_CHANNEL_SOURCE: - alpha = (a << 16) / 255; - break; - case ALPHA_MASK_UNPACKED: - alpha = (alphaData[ap] != 0) ? 0x10000 : 0; - ap += (sfx >> 16); - break; - case ALPHA_MASK_PACKED: - alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000; - ap += (sfx >> 16); - break; - case ALPHA_MASK_RGB: - alpha = 0x10000; - for (int i = 0; i < alphaData.length; i += 3) { - if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) { - alpha = 0x0000; - break; - } - } - break; - } - if (alpha != 0x10000) { - if (alpha == 0x0000) continue; - switch (dtype) { - case TYPE_GENERIC_8: { - final int data = destData[dp] & 0xff; - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_MSB: { - final int data = ((destData[dp] & 0xff) << 8) | (destData[dp + 1] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_LSB: { - final int data = ((destData[dp + 1] & 0xff) << 8) | (destData[dp] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_24: { - final int data = (( ((destData[dp] & 0xff) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp + 2] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_MSB: { - final int data = (( (( ((destData[dp] & 0xff) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp + 2] & 0xff)) << 8) | - (destData[dp + 3] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_LSB: { - final int data = (( (( ((destData[dp + 3] & 0xff) << 8) | - (destData[dp + 2] & 0xff)) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - } - // Perform alpha blending - a = aq + ((a - aq) * alpha >> 16); - r = rq + ((r - rq) * alpha >> 16); - g = gq + ((g - gq) * alpha >> 16); - b = bq + ((b - bq) * alpha >> 16); - } - - /*** WRITE NEXT PIXEL ***/ - final int data = - (r >>> destRedPreShift << destRedShift) | - (g >>> destGreenPreShift << destGreenShift) | - (b >>> destBluePreShift << destBlueShift) | - (a >>> destAlphaPreShift << destAlphaShift); - switch (dtype) { - case TYPE_GENERIC_8: { - destData[dp] = (byte) data; - } break; - case TYPE_GENERIC_16_MSB: { - destData[dp] = (byte) (data >>> 8); - destData[dp + 1] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_16_LSB: { - destData[dp] = (byte) (data & 0xff); - destData[dp + 1] = (byte) (data >>> 8); - } break; - case TYPE_GENERIC_24: { - destData[dp] = (byte) (data >>> 16); - destData[dp + 1] = (byte) (data >>> 8); - destData[dp + 2] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_32_MSB: { - destData[dp] = (byte) (data >>> 24); - destData[dp + 1] = (byte) (data >>> 16); - destData[dp + 2] = (byte) (data >>> 8); - destData[dp + 3] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_32_LSB: { - destData[dp] = (byte) (data & 0xff); - destData[dp + 1] = (byte) (data >>> 8); - destData[dp + 2] = (byte) (data >>> 16); - destData[dp + 3] = (byte) (data >>> 24); - } break; - } - } - } -} - -/** - * Blits an index palette image into an index palette image. - * <p> - * Note: The source and destination red, green, and blue - * arrays may be null if no alpha blending or dither is to be - * performed. - * </p> - * - * @param op the blitter operation: a combination of BLIT_xxx flags - * (see BLIT_xxx constants) - * @param srcData the source byte array containing image data - * @param srcDepth the source depth: one of 1, 2, 4, 8 - * @param srcStride the source number of bytes per line - * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if srcDepth is not 1 - * @param srcX the top-left x-coord of the source blit region - * @param srcY the top-left y-coord of the source blit region - * @param srcWidth the width of the source blit region - * @param srcHeight the height of the source blit region - * @param srcReds the source palette red component intensities - * @param srcGreens the source palette green component intensities - * @param srcBlues the source palette blue component intensities - * @param alphaMode the alpha blending or mask mode, may be - * an integer 0-255 for global alpha; ignored if BLIT_ALPHA - * not specified in the blitter operations - * (see ALPHA_MODE_xxx constants) - * @param alphaData the alpha blending or mask data, varies depending - * on the value of alphaMode and sometimes ignored - * @param alphaStride the alpha data number of bytes per line - * @param alphaX the top-left x-coord of the alpha blit region - * @param alphaY the top-left y-coord of the alpha blit region - * @param destData the destination byte array containing image data - * @param destDepth the destination depth: one of 1, 2, 4, 8 - * @param destStride the destination number of bytes per line - * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if destDepth is not 1 - * @param destX the top-left x-coord of the destination blit region - * @param destY the top-left y-coord of the destination blit region - * @param destWidth the width of the destination blit region - * @param destHeight the height of the destination blit region - * @param destReds the destination palette red component intensities - * @param destGreens the destination palette green component intensities - * @param destBlues the destination palette blue component intensities - * @param flipX if true the resulting image is flipped along the vertical axis - * @param flipY if true the resulting image is flipped along the horizontal axis - */ -static void blit(int op, - byte[] srcData, int srcDepth, int srcStride, int srcOrder, - int srcX, int srcY, int srcWidth, int srcHeight, - byte[] srcReds, byte[] srcGreens, byte[] srcBlues, - int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, - byte[] destData, int destDepth, int destStride, int destOrder, - int destX, int destY, int destWidth, int destHeight, - byte[] destReds, byte[] destGreens, byte[] destBlues, - boolean flipX, boolean flipY) { - if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return; - - /*** Prepare scaling data ***/ - final int dwm1 = destWidth - 1; - final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; - final int dhm1 = destHeight - 1; - final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; - - /*** Prepare source-related data ***/ - final int stype; - switch (srcDepth) { - case 8: - stype = TYPE_INDEX_8; - break; - case 4: - srcStride <<= 1; - stype = TYPE_INDEX_4; - break; - case 2: - srcStride <<= 2; - stype = TYPE_INDEX_2; - break; - case 1: - srcStride <<= 3; - stype = (srcOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int spr = srcY * srcStride + srcX; - - /*** Prepare destination-related data ***/ - final int dtype; - switch (destDepth) { - case 8: - dtype = TYPE_INDEX_8; - break; - case 4: - destStride <<= 1; - dtype = TYPE_INDEX_4; - break; - case 2: - destStride <<= 2; - dtype = TYPE_INDEX_2; - break; - case 1: - destStride <<= 3; - dtype = (destOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX); - final int dprxi = (flipX) ? -1 : 1; - final int dpryi = (flipY) ? -destStride : destStride; - - /*** Prepare special processing data ***/ - int apr; - if ((op & BLIT_ALPHA) != 0) { - switch (alphaMode) { - case ALPHA_MASK_UNPACKED: - case ALPHA_CHANNEL_SEPARATE: - if (alphaData == null) alphaMode = 0x10000; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_PACKED: - if (alphaData == null) alphaMode = 0x10000; - alphaStride <<= 3; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_INDEX: - case ALPHA_MASK_RGB: - if (alphaData == null) alphaMode = 0x10000; - apr = 0; - break; - default: - alphaMode = (alphaMode << 16) / 255; // prescale - case ALPHA_CHANNEL_SOURCE: - apr = 0; - break; - } - } else { - alphaMode = 0x10000; - apr = 0; - } - final boolean ditherEnabled = (op & BLIT_DITHER) != 0; - - /*** Blit ***/ - int dp = dpr; - int sp = spr; - int ap = apr; - int destPaletteSize = 1 << destDepth; - if ((destReds != null) && (destReds.length < destPaletteSize)) destPaletteSize = destReds.length; - byte[] paletteMapping = null; - boolean isExactPaletteMapping = true; - switch (alphaMode) { - case 0x10000: - /*** If the palettes and formats are equivalent use a one-to-one mapping ***/ - if ((stype == dtype) && - (srcReds == destReds) && (srcGreens == destGreens) && (srcBlues == destBlues)) { - paletteMapping = ONE_TO_ONE_MAPPING; - break; - /*** If palettes have not been supplied, supply a suitable mapping ***/ - } else if ((srcReds == null) || (destReds == null)) { - if (srcDepth <= destDepth) { - paletteMapping = ONE_TO_ONE_MAPPING; - } else { - paletteMapping = new byte[1 << srcDepth]; - int mask = (0xff << destDepth) >>> 8; - for (int i = 0; i < paletteMapping.length; ++i) paletteMapping[i] = (byte)(i & mask); - } - break; - } - case ALPHA_MASK_UNPACKED: - case ALPHA_MASK_PACKED: - case ALPHA_MASK_INDEX: - case ALPHA_MASK_RGB: - /*** Generate a palette mapping ***/ - int srcPaletteSize = 1 << srcDepth; - paletteMapping = new byte[srcPaletteSize]; - if ((srcReds != null) && (srcReds.length < srcPaletteSize)) srcPaletteSize = srcReds.length; - for (int i = 0, r, g, b, index; i < srcPaletteSize; ++i) { - r = srcReds[i] & 0xff; - g = srcGreens[i] & 0xff; - b = srcBlues[i] & 0xff; - index = 0; - int minDistance = 0x7fffffff; - for (int j = 0, dr, dg, db, distance; j < destPaletteSize; ++j) { - dr = (destReds[j] & 0xff) - r; - dg = (destGreens[j] & 0xff) - g; - db = (destBlues[j] & 0xff) - b; - distance = dr * dr + dg * dg + db * db; - if (distance < minDistance) { - index = j; - if (distance == 0) break; - minDistance = distance; - } - } - paletteMapping[i] = (byte)index; - if (minDistance != 0) isExactPaletteMapping = false; - } - break; - } - if ((paletteMapping != null) && (isExactPaletteMapping || ! ditherEnabled)) { - if ((stype == dtype) && (alphaMode == 0x10000)) { - /*** Fast blit (copy w/ mapping) ***/ - switch (stype) { - case TYPE_INDEX_8: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - destData[dp] = paletteMapping[srcData[sp] & 0xff]; - sp += (sfx >>> 16); - } - } - break; - case TYPE_INDEX_4: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - final int v; - if ((sp & 1) != 0) v = paletteMapping[srcData[sp >> 1] & 0x0f]; - else v = (srcData[sp >> 1] >>> 4) & 0x0f; - sp += (sfx >>> 16); - if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | v); - else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (v << 4)); - } - } - break; - case TYPE_INDEX_2: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - final int index = paletteMapping[(srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03]; - sp += (sfx >>> 16); - final int shift = 6 - (dp & 3) * 2; - destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift)); - } - } - break; - case TYPE_INDEX_1_MSB: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - final int index = paletteMapping[(srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01]; - sp += (sfx >>> 16); - final int shift = 7 - (dp & 7); - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); - } - } - break; - case TYPE_INDEX_1_LSB: - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { - final int index = paletteMapping[(srcData[sp >> 3] >>> (sp & 7)) & 0x01]; - sp += (sfx >>> 16); - final int shift = dp & 7; - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); - } - } - break; - } - } else { - /*** Convert between indexed modes using mapping and mask ***/ - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, - sp = spr += (sfy >>> 16) * srcStride, - sfy = (sfy & 0xffff) + sfyi, - dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, - dp += dprxi, - sfx = (sfx & 0xffff) + sfxi) { - int index; - /*** READ NEXT PIXEL ***/ - switch (stype) { - case TYPE_INDEX_8: - index = srcData[sp] & 0xff; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_4: - if ((sp & 1) != 0) index = srcData[sp >> 1] & 0x0f; - else index = (srcData[sp >> 1] >>> 4) & 0x0f; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_2: - index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_1_MSB: - index = (srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_1_LSB: - index = (srcData[sp >> 3] >>> (sp & 7)) & 0x01; - sp += (sfx >>> 16); - break; - default: - return; - } - /*** APPLY MASK ***/ - switch (alphaMode) { - case ALPHA_MASK_UNPACKED: { - final byte mask = alphaData[ap]; - ap += (sfx >> 16); - if (mask == 0) continue; - } break; - case ALPHA_MASK_PACKED: { - final int mask = alphaData[ap >> 3] & (1 << (ap & 7)); - ap += (sfx >> 16); - if (mask == 0) continue; - } break; - case ALPHA_MASK_INDEX: { - int i = 0; - while (i < alphaData.length) { - if (index == (alphaData[i] & 0xff)) break; - } - if (i < alphaData.length) continue; - } break; - case ALPHA_MASK_RGB: { - final byte r = srcReds[index], g = srcGreens[index], b = srcBlues[index]; - int i = 0; - while (i < alphaData.length) { - if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) break; - i += 3; - } - if (i < alphaData.length) continue; - } break; - } - index = paletteMapping[index] & 0xff; - - /*** WRITE NEXT PIXEL ***/ - switch (dtype) { - case TYPE_INDEX_8: - destData[dp] = (byte) index; - break; - case TYPE_INDEX_4: - if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | index); - else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (index << 4)); - break; - case TYPE_INDEX_2: { - final int shift = 6 - (dp & 3) * 2; - destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift)); - } break; - case TYPE_INDEX_1_MSB: { - final int shift = 7 - (dp & 7); - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); - } break; - case TYPE_INDEX_1_LSB: { - final int shift = dp & 7; - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); - } break; - } - } - } - } - return; - } - - /*** Comprehensive blit (apply transformations) ***/ - int alpha = alphaMode; - int index = 0; - int indexq = 0; - int lastindex = 0, lastr = -1, lastg = -1, lastb = -1; - final int[] rerr, gerr, berr; - if (ditherEnabled) { - rerr = new int[destWidth + 2]; - gerr = new int[destWidth + 2]; - berr = new int[destWidth + 2]; - } else { - rerr = null; gerr = null; berr = null; - } - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, - sp = spr += (sfy >>> 16) * srcStride, - ap = apr += (sfy >>> 16) * alphaStride, - sfy = (sfy & 0xffff) + sfyi, - dp = dpr += dpryi) { - int lrerr = 0, lgerr = 0, lberr = 0; - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, - dp += dprxi, - sfx = (sfx & 0xffff) + sfxi) { - /*** READ NEXT PIXEL ***/ - switch (stype) { - case TYPE_INDEX_8: - index = srcData[sp] & 0xff; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_4: - if ((sp & 1) != 0) index = srcData[sp >> 1] & 0x0f; - else index = (srcData[sp >> 1] >>> 4) & 0x0f; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_2: - index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_1_MSB: - index = (srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_1_LSB: - index = (srcData[sp >> 3] >>> (sp & 7)) & 0x01; - sp += (sfx >>> 16); - break; - } - - /*** DO SPECIAL PROCESSING IF REQUIRED ***/ - int r = srcReds[index] & 0xff, g = srcGreens[index] & 0xff, b = srcBlues[index] & 0xff; - switch (alphaMode) { - case ALPHA_CHANNEL_SEPARATE: - alpha = ((alphaData[ap] & 0xff) << 16) / 255; - ap += (sfx >> 16); - break; - case ALPHA_MASK_UNPACKED: - alpha = (alphaData[ap] != 0) ? 0x10000 : 0; - ap += (sfx >> 16); - break; - case ALPHA_MASK_PACKED: - alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000; - ap += (sfx >> 16); - break; - case ALPHA_MASK_INDEX: { // could speed up using binary search if we sorted the indices - int i = 0; - while (i < alphaData.length) { - if (index == (alphaData[i] & 0xff)) break; - } - if (i < alphaData.length) continue; - } break; - case ALPHA_MASK_RGB: { - int i = 0; - while (i < alphaData.length) { - if ((r == (alphaData[i] & 0xff)) && - (g == (alphaData[i + 1] & 0xff)) && - (b == (alphaData[i + 2] & 0xff))) break; - i += 3; - } - if (i < alphaData.length) continue; - } break; - } - if (alpha != 0x10000) { - if (alpha == 0x0000) continue; - switch (dtype) { - case TYPE_INDEX_8: - indexq = destData[dp] & 0xff; - break; - case TYPE_INDEX_4: - if ((dp & 1) != 0) indexq = destData[dp >> 1] & 0x0f; - else indexq = (destData[dp >> 1] >>> 4) & 0x0f; - break; - case TYPE_INDEX_2: - indexq = (destData[dp >> 2] >>> (6 - (dp & 3) * 2)) & 0x03; - break; - case TYPE_INDEX_1_MSB: - indexq = (destData[dp >> 3] >>> (7 - (dp & 7))) & 0x01; - break; - case TYPE_INDEX_1_LSB: - indexq = (destData[dp >> 3] >>> (dp & 7)) & 0x01; - break; - } - // Perform alpha blending - final int rq = destReds[indexq] & 0xff; - final int gq = destGreens[indexq] & 0xff; - final int bq = destBlues[indexq] & 0xff; - r = rq + ((r - rq) * alpha >> 16); - g = gq + ((g - gq) * alpha >> 16); - b = bq + ((b - bq) * alpha >> 16); - } - - /*** MAP COLOR TO THE PALETTE ***/ - if (ditherEnabled) { - // Floyd-Steinberg error diffusion - r += rerr[dx] >> 4; - if (r < 0) r = 0; else if (r > 255) r = 255; - g += gerr[dx] >> 4; - if (g < 0) g = 0; else if (g > 255) g = 255; - b += berr[dx] >> 4; - if (b < 0) b = 0; else if (b > 255) b = 255; - rerr[dx] = lrerr; - gerr[dx] = lgerr; - berr[dx] = lberr; - } - if (r != lastr || g != lastg || b != lastb) { - // moving the variable declarations out seems to make the JDK JIT happier... - for (int j = 0, dr, dg, db, distance, minDistance = 0x7fffffff; j < destPaletteSize; ++j) { - dr = (destReds[j] & 0xff) - r; - dg = (destGreens[j] & 0xff) - g; - db = (destBlues[j] & 0xff) - b; - distance = dr * dr + dg * dg + db * db; - if (distance < minDistance) { - lastindex = j; - if (distance == 0) break; - minDistance = distance; - } - } - lastr = r; lastg = g; lastb = b; - } - if (ditherEnabled) { - // Floyd-Steinberg error diffusion, cont'd... - final int dxm1 = dx - 1, dxp1 = dx + 1; - int acc; - rerr[dxp1] += acc = (lrerr = r - (destReds[lastindex] & 0xff)) + lrerr + lrerr; - rerr[dx] += acc += lrerr + lrerr; - rerr[dxm1] += acc + lrerr + lrerr; - gerr[dxp1] += acc = (lgerr = g - (destGreens[lastindex] & 0xff)) + lgerr + lgerr; - gerr[dx] += acc += lgerr + lgerr; - gerr[dxm1] += acc + lgerr + lgerr; - berr[dxp1] += acc = (lberr = b - (destBlues[lastindex] & 0xff)) + lberr + lberr; - berr[dx] += acc += lberr + lberr; - berr[dxm1] += acc + lberr + lberr; - } - - /*** WRITE NEXT PIXEL ***/ - switch (dtype) { - case TYPE_INDEX_8: - destData[dp] = (byte) lastindex; - break; - case TYPE_INDEX_4: - if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | lastindex); - else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4)); - break; - case TYPE_INDEX_2: { - final int shift = 6 - (dp & 3) * 2; - destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift)); - } break; - case TYPE_INDEX_1_MSB: { - final int shift = 7 - (dp & 7); - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); - } break; - case TYPE_INDEX_1_LSB: { - final int shift = dp & 7; - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); - } break; - } - } - } -} - -/** - * Blits an index palette image into a direct palette image. - * <p> - * Note: The source and destination masks and palettes must - * always be fully specified. - * </p> - * - * @param op the blitter operation: a combination of BLIT_xxx flags - * (see BLIT_xxx constants) - * @param srcData the source byte array containing image data - * @param srcDepth the source depth: one of 1, 2, 4, 8 - * @param srcStride the source number of bytes per line - * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if srcDepth is not 1 - * @param srcX the top-left x-coord of the source blit region - * @param srcY the top-left y-coord of the source blit region - * @param srcWidth the width of the source blit region - * @param srcHeight the height of the source blit region - * @param srcReds the source palette red component intensities - * @param srcGreens the source palette green component intensities - * @param srcBlues the source palette blue component intensities - * @param alphaMode the alpha blending or mask mode, may be - * an integer 0-255 for global alpha; ignored if BLIT_ALPHA - * not specified in the blitter operations - * (see ALPHA_MODE_xxx constants) - * @param alphaData the alpha blending or mask data, varies depending - * on the value of alphaMode and sometimes ignored - * @param alphaStride the alpha data number of bytes per line - * @param alphaX the top-left x-coord of the alpha blit region - * @param alphaY the top-left y-coord of the alpha blit region - * @param destData the destination byte array containing image data - * @param destDepth the destination depth: one of 8, 16, 24, 32 - * @param destStride the destination number of bytes per line - * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if destDepth is not 16 or 32 - * @param destX the top-left x-coord of the destination blit region - * @param destY the top-left y-coord of the destination blit region - * @param destWidth the width of the destination blit region - * @param destHeight the height of the destination blit region - * @param destRedMask the destination red channel mask - * @param destGreenMask the destination green channel mask - * @param destBlueMask the destination blue channel mask - * @param flipX if true the resulting image is flipped along the vertical axis - * @param flipY if true the resulting image is flipped along the horizontal axis - */ -static void blit(int op, - byte[] srcData, int srcDepth, int srcStride, int srcOrder, - int srcX, int srcY, int srcWidth, int srcHeight, - byte[] srcReds, byte[] srcGreens, byte[] srcBlues, - int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, - byte[] destData, int destDepth, int destStride, int destOrder, - int destX, int destY, int destWidth, int destHeight, - int destRedMask, int destGreenMask, int destBlueMask, - boolean flipX, boolean flipY) { - if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return; - - /*** Fast blit (straight copy) ***/ - if (srcX == 0 && srcY == 0 && destX == 0 && destY == 0 && destWidth == srcWidth && destHeight == srcHeight) { - if (destDepth == 24 && srcDepth == 8 && (op & BLIT_ALPHA) == 0 && destRedMask == 0xFF0000 && destGreenMask == 0xFF00 && destBlueMask == 0xFF) { - for (int y = 0, sp = 0, dp = 0, spad = srcStride - srcWidth, dpad = destStride - (destWidth * 3); y < destHeight; y++, sp += spad, dp += dpad) { - for (int x = 0; x < destWidth; x++) { - int index = srcData[sp++] & 0xff; - destData[dp++] = srcReds[index]; - destData[dp++] = srcGreens[index]; - destData[dp++] = srcBlues[index]; - } - } - return; - } - if (destDepth == 32 && destOrder == MSB_FIRST && srcDepth == 8 && (op & BLIT_ALPHA) == 0 && destRedMask == 0xFF0000 && destGreenMask == 0xFF00 && destBlueMask == 0xFF) { - for (int y = 0, sp = 0, dp = 0, spad = srcStride - srcWidth, dpad = destStride - (destWidth * 4); y < destHeight; y++, sp += spad, dp += dpad) { - for (int x = 0; x < destWidth; x++) { - int index = srcData[sp++] & 0xff; - dp++; - destData[dp++] = srcReds[index]; - destData[dp++] = srcGreens[index]; - destData[dp++] = srcBlues[index]; - } - } - return; - } - } - // these should be supplied as params later - final int destAlphaMask = 0; - - /*** Prepare scaling data ***/ - final int dwm1 = destWidth - 1; - final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; - final int dhm1 = destHeight - 1; - final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; - - /*** Prepare source-related data ***/ - final int stype; - switch (srcDepth) { - case 8: - stype = TYPE_INDEX_8; - break; - case 4: - srcStride <<= 1; - stype = TYPE_INDEX_4; - break; - case 2: - srcStride <<= 2; - stype = TYPE_INDEX_2; - break; - case 1: - srcStride <<= 3; - stype = (srcOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int spr = srcY * srcStride + srcX; - - /*** Prepare destination-related data ***/ - final int dbpp, dtype; - switch (destDepth) { - case 8: - dbpp = 1; - dtype = TYPE_GENERIC_8; - break; - case 16: - dbpp = 2; - dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB; - break; - case 24: - dbpp = 3; - dtype = TYPE_GENERIC_24; - break; - case 32: - dbpp = 4; - dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid destination type"); - return; - } - int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX) * dbpp; - final int dprxi = (flipX) ? -dbpp : dbpp; - final int dpryi = (flipY) ? -destStride : destStride; - - /*** Prepare special processing data ***/ - int apr; - if ((op & BLIT_ALPHA) != 0) { - switch (alphaMode) { - case ALPHA_MASK_UNPACKED: - case ALPHA_CHANNEL_SEPARATE: - if (alphaData == null) alphaMode = 0x10000; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_PACKED: - if (alphaData == null) alphaMode = 0x10000; - alphaStride <<= 3; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_INDEX: - case ALPHA_MASK_RGB: - if (alphaData == null) alphaMode = 0x10000; - apr = 0; - break; - default: - alphaMode = (alphaMode << 16) / 255; // prescale - case ALPHA_CHANNEL_SOURCE: - apr = 0; - break; - } - } else { - alphaMode = 0x10000; - apr = 0; - } - - /*** Comprehensive blit (apply transformations) ***/ - final int destRedShift = getChannelShift(destRedMask); - final int destRedWidth = getChannelWidth(destRedMask, destRedShift); - final byte[] destReds = ANY_TO_EIGHT[destRedWidth]; - final int destRedPreShift = 8 - destRedWidth; - final int destGreenShift = getChannelShift(destGreenMask); - final int destGreenWidth = getChannelWidth(destGreenMask, destGreenShift); - final byte[] destGreens = ANY_TO_EIGHT[destGreenWidth]; - final int destGreenPreShift = 8 - destGreenWidth; - final int destBlueShift = getChannelShift(destBlueMask); - final int destBlueWidth = getChannelWidth(destBlueMask, destBlueShift); - final byte[] destBlues = ANY_TO_EIGHT[destBlueWidth]; - final int destBluePreShift = 8 - destBlueWidth; - final int destAlphaShift = getChannelShift(destAlphaMask); - final int destAlphaWidth = getChannelWidth(destAlphaMask, destAlphaShift); - final byte[] destAlphas = ANY_TO_EIGHT[destAlphaWidth]; - final int destAlphaPreShift = 8 - destAlphaWidth; - - int dp = dpr; - int sp = spr; - int ap = apr, alpha = alphaMode; - int r = 0, g = 0, b = 0, a = 0, index = 0; - int rq = 0, gq = 0, bq = 0, aq = 0; - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, - sp = spr += (sfy >>> 16) * srcStride, - ap = apr += (sfy >>> 16) * alphaStride, - sfy = (sfy & 0xffff) + sfyi, - dp = dpr += dpryi) { - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, - dp += dprxi, - sfx = (sfx & 0xffff) + sfxi) { - /*** READ NEXT PIXEL ***/ - switch (stype) { - case TYPE_INDEX_8: - index = srcData[sp] & 0xff; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_4: - if ((sp & 1) != 0) index = srcData[sp >> 1] & 0x0f; - else index = (srcData[sp >> 1] >>> 4) & 0x0f; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_2: - index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_1_MSB: - index = (srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01; - sp += (sfx >>> 16); - break; - case TYPE_INDEX_1_LSB: - index = (srcData[sp >> 3] >>> (sp & 7)) & 0x01; - sp += (sfx >>> 16); - break; - } - - /*** DO SPECIAL PROCESSING IF REQUIRED ***/ - r = srcReds[index] & 0xff; - g = srcGreens[index] & 0xff; - b = srcBlues[index] & 0xff; - switch (alphaMode) { - case ALPHA_CHANNEL_SEPARATE: - alpha = ((alphaData[ap] & 0xff) << 16) / 255; - ap += (sfx >> 16); - break; - case ALPHA_MASK_UNPACKED: - alpha = (alphaData[ap] != 0) ? 0x10000 : 0; - ap += (sfx >> 16); - break; - case ALPHA_MASK_PACKED: - alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000; - ap += (sfx >> 16); - break; - case ALPHA_MASK_INDEX: { // could speed up using binary search if we sorted the indices - int i = 0; - while (i < alphaData.length) { - if (index == (alphaData[i] & 0xff)) break; - } - if (i < alphaData.length) continue; - } break; - case ALPHA_MASK_RGB: { - int i = 0; - while (i < alphaData.length) { - if ((r == (alphaData[i] & 0xff)) && - (g == (alphaData[i + 1] & 0xff)) && - (b == (alphaData[i + 2] & 0xff))) break; - i += 3; - } - if (i < alphaData.length) continue; - } break; - } - if (alpha != 0x10000) { - if (alpha == 0x0000) continue; - switch (dtype) { - case TYPE_GENERIC_8: { - final int data = destData[dp] & 0xff; - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_MSB: { - final int data = ((destData[dp] & 0xff) << 8) | (destData[dp + 1] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_LSB: { - final int data = ((destData[dp + 1] & 0xff) << 8) | (destData[dp] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_24: { - final int data = (( ((destData[dp] & 0xff) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp + 2] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_MSB: { - final int data = (( (( ((destData[dp] & 0xff) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp + 2] & 0xff)) << 8) | - (destData[dp + 3] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_LSB: { - final int data = (( (( ((destData[dp + 3] & 0xff) << 8) | - (destData[dp + 2] & 0xff)) << 8) | - (destData[dp + 1] & 0xff)) << 8) | - (destData[dp] & 0xff); - rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff; - gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff; - bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff; - aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff; - } break; - } - // Perform alpha blending - a = aq + ((a - aq) * alpha >> 16); - r = rq + ((r - rq) * alpha >> 16); - g = gq + ((g - gq) * alpha >> 16); - b = bq + ((b - bq) * alpha >> 16); - } - - /*** WRITE NEXT PIXEL ***/ - final int data = - (r >>> destRedPreShift << destRedShift) | - (g >>> destGreenPreShift << destGreenShift) | - (b >>> destBluePreShift << destBlueShift) | - (a >>> destAlphaPreShift << destAlphaShift); - switch (dtype) { - case TYPE_GENERIC_8: { - destData[dp] = (byte) data; - } break; - case TYPE_GENERIC_16_MSB: { - destData[dp] = (byte) (data >>> 8); - destData[dp + 1] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_16_LSB: { - destData[dp] = (byte) (data & 0xff); - destData[dp + 1] = (byte) (data >>> 8); - } break; - case TYPE_GENERIC_24: { - destData[dp] = (byte) (data >>> 16); - destData[dp + 1] = (byte) (data >>> 8); - destData[dp + 2] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_32_MSB: { - destData[dp] = (byte) (data >>> 24); - destData[dp + 1] = (byte) (data >>> 16); - destData[dp + 2] = (byte) (data >>> 8); - destData[dp + 3] = (byte) (data & 0xff); - } break; - case TYPE_GENERIC_32_LSB: { - destData[dp] = (byte) (data & 0xff); - destData[dp + 1] = (byte) (data >>> 8); - destData[dp + 2] = (byte) (data >>> 16); - destData[dp + 3] = (byte) (data >>> 24); - } break; - } - } - } -} - -/** - * Blits a direct palette image into an index palette image. - * <p> - * Note: The source and destination masks and palettes must - * always be fully specified. - * </p> - * - * @param op the blitter operation: a combination of BLIT_xxx flags - * (see BLIT_xxx constants) - * @param srcData the source byte array containing image data - * @param srcDepth the source depth: one of 8, 16, 24, 32 - * @param srcStride the source number of bytes per line - * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if srcDepth is not 16 or 32 - * @param srcX the top-left x-coord of the source blit region - * @param srcY the top-left y-coord of the source blit region - * @param srcWidth the width of the source blit region - * @param srcHeight the height of the source blit region - * @param srcRedMask the source red channel mask - * @param srcGreenMask the source green channel mask - * @param srcBlueMask the source blue channel mask - * @param alphaMode the alpha blending or mask mode, may be - * an integer 0-255 for global alpha; ignored if BLIT_ALPHA - * not specified in the blitter operations - * (see ALPHA_MODE_xxx constants) - * @param alphaData the alpha blending or mask data, varies depending - * on the value of alphaMode and sometimes ignored - * @param alphaStride the alpha data number of bytes per line - * @param alphaX the top-left x-coord of the alpha blit region - * @param alphaY the top-left y-coord of the alpha blit region - * @param destData the destination byte array containing image data - * @param destDepth the destination depth: one of 1, 2, 4, 8 - * @param destStride the destination number of bytes per line - * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST; - * ignored if destDepth is not 1 - * @param destX the top-left x-coord of the destination blit region - * @param destY the top-left y-coord of the destination blit region - * @param destWidth the width of the destination blit region - * @param destHeight the height of the destination blit region - * @param destReds the destination palette red component intensities - * @param destGreens the destination palette green component intensities - * @param destBlues the destination palette blue component intensities - * @param flipX if true the resulting image is flipped along the vertical axis - * @param flipY if true the resulting image is flipped along the horizontal axis - */ -static void blit(int op, - byte[] srcData, int srcDepth, int srcStride, int srcOrder, - int srcX, int srcY, int srcWidth, int srcHeight, - int srcRedMask, int srcGreenMask, int srcBlueMask, - int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, - byte[] destData, int destDepth, int destStride, int destOrder, - int destX, int destY, int destWidth, int destHeight, - byte[] destReds, byte[] destGreens, byte[] destBlues, - boolean flipX, boolean flipY) { - if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return; - - // these should be supplied as params later - final int srcAlphaMask = 0; - - /*** Prepare scaling data ***/ - final int dwm1 = destWidth - 1; - final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; - final int dhm1 = destHeight - 1; - final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; - - /*** Prepare source-related data ***/ - final int sbpp, stype; - switch (srcDepth) { - case 8: - sbpp = 1; - stype = TYPE_GENERIC_8; - break; - case 16: - sbpp = 2; - stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB; - break; - case 24: - sbpp = 3; - stype = TYPE_GENERIC_24; - break; - case 32: - sbpp = 4; - stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int spr = srcY * srcStride + srcX * sbpp; - - /*** Prepare destination-related data ***/ - final int dtype; - switch (destDepth) { - case 8: - dtype = TYPE_INDEX_8; - break; - case 4: - destStride <<= 1; - dtype = TYPE_INDEX_4; - break; - case 2: - destStride <<= 2; - dtype = TYPE_INDEX_2; - break; - case 1: - destStride <<= 3; - dtype = (destOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB; - break; - default: - //throw new IllegalArgumentException("Invalid source type"); - return; - } - int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX); - final int dprxi = (flipX) ? -1 : 1; - final int dpryi = (flipY) ? -destStride : destStride; - - /*** Prepare special processing data ***/ - int apr; - if ((op & BLIT_ALPHA) != 0) { - switch (alphaMode) { - case ALPHA_MASK_UNPACKED: - case ALPHA_CHANNEL_SEPARATE: - if (alphaData == null) alphaMode = 0x10000; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_PACKED: - if (alphaData == null) alphaMode = 0x10000; - alphaStride <<= 3; - apr = alphaY * alphaStride + alphaX; - break; - case ALPHA_MASK_INDEX: - //throw new IllegalArgumentException("Invalid alpha type"); - return; - case ALPHA_MASK_RGB: - if (alphaData == null) alphaMode = 0x10000; - apr = 0; - break; - default: - alphaMode = (alphaMode << 16) / 255; // prescale - case ALPHA_CHANNEL_SOURCE: - apr = 0; - break; - } - } else { - alphaMode = 0x10000; - apr = 0; - } - final boolean ditherEnabled = (op & BLIT_DITHER) != 0; - - /*** Comprehensive blit (apply transformations) ***/ - final int srcRedShift = getChannelShift(srcRedMask); - final byte[] srcReds = ANY_TO_EIGHT[getChannelWidth(srcRedMask, srcRedShift)]; - final int srcGreenShift = getChannelShift(srcGreenMask); - final byte[] srcGreens = ANY_TO_EIGHT[getChannelWidth(srcGreenMask, srcGreenShift)]; - final int srcBlueShift = getChannelShift(srcBlueMask); - final byte[] srcBlues = ANY_TO_EIGHT[getChannelWidth(srcBlueMask, srcBlueShift)]; - final int srcAlphaShift = getChannelShift(srcAlphaMask); - final byte[] srcAlphas = ANY_TO_EIGHT[getChannelWidth(srcAlphaMask, srcAlphaShift)]; - - int dp = dpr; - int sp = spr; - int ap = apr, alpha = alphaMode; - int r = 0, g = 0, b = 0, a = 0; - int indexq = 0; - int lastindex = 0, lastr = -1, lastg = -1, lastb = -1; - final int[] rerr, gerr, berr; - int destPaletteSize = 1 << destDepth; - if ((destReds != null) && (destReds.length < destPaletteSize)) destPaletteSize = destReds.length; - if (ditherEnabled) { - rerr = new int[destWidth + 2]; - gerr = new int[destWidth + 2]; - berr = new int[destWidth + 2]; - } else { - rerr = null; gerr = null; berr = null; - } - for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, - sp = spr += (sfy >>> 16) * srcStride, - ap = apr += (sfy >>> 16) * alphaStride, - sfy = (sfy & 0xffff) + sfyi, - dp = dpr += dpryi) { - int lrerr = 0, lgerr = 0, lberr = 0; - for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, - dp += dprxi, - sfx = (sfx & 0xffff) + sfxi) { - /*** READ NEXT PIXEL ***/ - switch (stype) { - case TYPE_GENERIC_8: { - final int data = srcData[sp] & 0xff; - sp += (sfx >>> 16); - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_MSB: { - final int data = ((srcData[sp] & 0xff) << 8) | (srcData[sp + 1] & 0xff); - sp += (sfx >>> 16) * 2; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_16_LSB: { - final int data = ((srcData[sp + 1] & 0xff) << 8) | (srcData[sp] & 0xff); - sp += (sfx >>> 16) * 2; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_24: { - final int data = (( ((srcData[sp] & 0xff) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp + 2] & 0xff); - sp += (sfx >>> 16) * 3; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_MSB: { - final int data = (( (( ((srcData[sp] & 0xff) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp + 2] & 0xff)) << 8) | - (srcData[sp + 3] & 0xff); - sp += (sfx >>> 16) * 4; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - case TYPE_GENERIC_32_LSB: { - final int data = (( (( ((srcData[sp + 3] & 0xff) << 8) | - (srcData[sp + 2] & 0xff)) << 8) | - (srcData[sp + 1] & 0xff)) << 8) | - (srcData[sp] & 0xff); - sp += (sfx >>> 16) * 4; - r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff; - g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff; - b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff; - a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff; - } break; - } - - /*** DO SPECIAL PROCESSING IF REQUIRED ***/ - switch (alphaMode) { - case ALPHA_CHANNEL_SEPARATE: - alpha = ((alphaData[ap] & 0xff) << 16) / 255; - ap += (sfx >> 16); - break; - case ALPHA_CHANNEL_SOURCE: - alpha = (a << 16) / 255; - break; - case ALPHA_MASK_UNPACKED: - alpha = (alphaData[ap] != 0) ? 0x10000 : 0; - ap += (sfx >> 16); - break; - case ALPHA_MASK_PACKED: - alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000; - ap += (sfx >> 16); - break; - case ALPHA_MASK_RGB: - alpha = 0x10000; - for (int i = 0; i < alphaData.length; i += 3) { - if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) { - alpha = 0x0000; - break; - } - } - break; - } - if (alpha != 0x10000) { - if (alpha == 0x0000) continue; - switch (dtype) { - case TYPE_INDEX_8: - indexq = destData[dp] & 0xff; - break; - case TYPE_INDEX_4: - if ((dp & 1) != 0) indexq = destData[dp >> 1] & 0x0f; - else indexq = (destData[dp >> 1] >>> 4) & 0x0f; - break; - case TYPE_INDEX_2: - indexq = (destData[dp >> 2] >>> (6 - (dp & 3) * 2)) & 0x03; - break; - case TYPE_INDEX_1_MSB: - indexq = (destData[dp >> 3] >>> (7 - (dp & 7))) & 0x01; - break; - case TYPE_INDEX_1_LSB: - indexq = (destData[dp >> 3] >>> (dp & 7)) & 0x01; - break; - } - // Perform alpha blending - final int rq = destReds[indexq] & 0xff; - final int gq = destGreens[indexq] & 0xff; - final int bq = destBlues[indexq] & 0xff; - r = rq + ((r - rq) * alpha >> 16); - g = gq + ((g - gq) * alpha >> 16); - b = bq + ((b - bq) * alpha >> 16); - } - - /*** MAP COLOR TO THE PALETTE ***/ - if (ditherEnabled) { - // Floyd-Steinberg error diffusion - r += rerr[dx] >> 4; - if (r < 0) r = 0; else if (r > 255) r = 255; - g += gerr[dx] >> 4; - if (g < 0) g = 0; else if (g > 255) g = 255; - b += berr[dx] >> 4; - if (b < 0) b = 0; else if (b > 255) b = 255; - rerr[dx] = lrerr; - gerr[dx] = lgerr; - berr[dx] = lberr; - } - if (r != lastr || g != lastg || b != lastb) { - // moving the variable declarations out seems to make the JDK JIT happier... - for (int j = 0, dr, dg, db, distance, minDistance = 0x7fffffff; j < destPaletteSize; ++j) { - dr = (destReds[j] & 0xff) - r; - dg = (destGreens[j] & 0xff) - g; - db = (destBlues[j] & 0xff) - b; - distance = dr * dr + dg * dg + db * db; - if (distance < minDistance) { - lastindex = j; - if (distance == 0) break; - minDistance = distance; - } - } - lastr = r; lastg = g; lastb = b; - } - if (ditherEnabled) { - // Floyd-Steinberg error diffusion, cont'd... - final int dxm1 = dx - 1, dxp1 = dx + 1; - int acc; - rerr[dxp1] += acc = (lrerr = r - (destReds[lastindex] & 0xff)) + lrerr + lrerr; - rerr[dx] += acc += lrerr + lrerr; - rerr[dxm1] += acc + lrerr + lrerr; - gerr[dxp1] += acc = (lgerr = g - (destGreens[lastindex] & 0xff)) + lgerr + lgerr; - gerr[dx] += acc += lgerr + lgerr; - gerr[dxm1] += acc + lgerr + lgerr; - berr[dxp1] += acc = (lberr = b - (destBlues[lastindex] & 0xff)) + lberr + lberr; - berr[dx] += acc += lberr + lberr; - berr[dxm1] += acc + lberr + lberr; - } - - /*** WRITE NEXT PIXEL ***/ - switch (dtype) { - case TYPE_INDEX_8: - destData[dp] = (byte) lastindex; - break; - case TYPE_INDEX_4: - if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | lastindex); - else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4)); - break; - case TYPE_INDEX_2: { - final int shift = 6 - (dp & 3) * 2; - destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift)); - } break; - case TYPE_INDEX_1_MSB: { - final int shift = 7 - (dp & 7); - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); - } break; - case TYPE_INDEX_1_LSB: { - final int shift = dp & 7; - destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); - } break; - } - } - } -} - -/** - * Computes the required channel shift from a mask. - */ -static int getChannelShift(int mask) { - if (mask == 0) return 0; - int i; - for (i = 0; ((mask & 1) == 0) && (i < 32); ++i) { - mask >>>= 1; - } - return i; -} - -/** - * Computes the required channel width (depth) from a mask. - */ -static int getChannelWidth(int mask, int shift) { - if (mask == 0) return 0; - int i; - mask >>>= shift; - for (i = shift; ((mask & 1) != 0) && (i < 32); ++i) { - mask >>>= 1; - } - return i - shift; -} - -/** - * Extracts a field from packed RGB data given a mask for that field. - */ -static byte getChannelField(int data, int mask) { - final int shift = getChannelShift(mask); - return ANY_TO_EIGHT[getChannelWidth(mask, shift)][(data & mask) >>> shift]; -} - -/** - * Creates an ImageData containing one band's worth of a gradient filled - * block. If <code>vertical</code> is true, the band must be tiled - * horizontally to fill a region, otherwise it must be tiled vertically. - * - * @param width the width of the region to be filled - * @param height the height of the region to be filled - * @param vertical if true sweeps from top to bottom, else - * sweeps from left to right - * @param fromRGB the color to start with - * @param toRGB the color to end with - * @param redBits the number of significant red bits, 0 for palette modes - * @param greenBits the number of significant green bits, 0 for palette modes - * @param blueBits the number of significant blue bits, 0 for palette modes - * @return the new ImageData - */ -static ImageData createGradientBand( - int width, int height, boolean vertical, - RGB fromRGB, RGB toRGB, - int redBits, int greenBits, int blueBits) { - /* Gradients are drawn as tiled bands */ - final int bandWidth, bandHeight, bitmapDepth; - final byte[] bitmapData; - final PaletteData paletteData; - /* Select an algorithm depending on the depth of the screen */ - if (redBits != 0 && greenBits != 0 && blueBits != 0) { - paletteData = new PaletteData(0x0000ff00, 0x00ff0000, 0xff000000); - bitmapDepth = 32; - if (redBits >= 8 && greenBits >= 8 && blueBits >= 8) { - /* Precise color */ - final int steps; - if (vertical) { - bandWidth = 1; - bandHeight = height; - steps = bandHeight > 1 ? bandHeight - 1 : 1; - } else { - bandWidth = width; - bandHeight = 1; - steps = bandWidth > 1 ? bandWidth - 1 : 1; - } - final int bytesPerLine = bandWidth * 4; - bitmapData = new byte[bandHeight * bytesPerLine]; - buildPreciseGradientChannel(fromRGB.blue, toRGB.blue, steps, bandWidth, bandHeight, vertical, bitmapData, 0, bytesPerLine); - buildPreciseGradientChannel(fromRGB.green, toRGB.green, steps, bandWidth, bandHeight, vertical, bitmapData, 1, bytesPerLine); - buildPreciseGradientChannel(fromRGB.red, toRGB.red, steps, bandWidth, bandHeight, vertical, bitmapData, 2, bytesPerLine); - } else { - /* Dithered color */ - final int steps; - if (vertical) { - bandWidth = (width < 8) ? width : 8; - bandHeight = height; - steps = bandHeight > 1 ? bandHeight - 1 : 1; - } else { - bandWidth = width; - bandHeight = (height < 8) ? height : 8; - steps = bandWidth > 1 ? bandWidth - 1 : 1; - } - final int bytesPerLine = bandWidth * 4; - bitmapData = new byte[bandHeight * bytesPerLine]; - buildDitheredGradientChannel(fromRGB.blue, toRGB.blue, steps, bandWidth, bandHeight, vertical, bitmapData, 0, bytesPerLine, blueBits); - buildDitheredGradientChannel(fromRGB.green, toRGB.green, steps, bandWidth, bandHeight, vertical, bitmapData, 1, bytesPerLine, greenBits); - buildDitheredGradientChannel(fromRGB.red, toRGB.red, steps, bandWidth, bandHeight, vertical, bitmapData, 2, bytesPerLine, redBits); - } - } else { - /* Dithered two tone */ - paletteData = new PaletteData(new RGB[] { fromRGB, toRGB }); - bitmapDepth = 8; - final int blendi; - if (vertical) { - bandWidth = (width < 8) ? width : 8; - bandHeight = height; - blendi = (bandHeight > 1) ? 0x1040000 / (bandHeight - 1) + 1 : 1; - } else { - bandWidth = width; - bandHeight = (height < 8) ? height : 8; - blendi = (bandWidth > 1) ? 0x1040000 / (bandWidth - 1) + 1 : 1; - } - final int bytesPerLine = (bandWidth + 3) & -4; - bitmapData = new byte[bandHeight * bytesPerLine]; - if (vertical) { - for (int dy = 0, blend = 0, dp = 0; dy < bandHeight; - ++dy, blend += blendi, dp += bytesPerLine) { - for (int dx = 0; dx < bandWidth; ++dx) { - bitmapData[dp + dx] = (blend + DITHER_MATRIX[dy & 7][dx]) < - 0x1000000 ? (byte)0 : (byte)1; - } - } - } else { - for (int dx = 0, blend = 0; dx < bandWidth; ++dx, blend += blendi) { - for (int dy = 0, dptr = dx; dy < bandHeight; ++dy, dptr += bytesPerLine) { - bitmapData[dptr] = (blend + DITHER_MATRIX[dy][dx & 7]) < - 0x1000000 ? (byte)0 : (byte)1; - } - } - } - } - return new ImageData(bandWidth, bandHeight, bitmapDepth, paletteData, 4, bitmapData); -} - -/* - * Fill in gradated values for a color channel - */ -static final void buildPreciseGradientChannel(int from, int to, int steps, - int bandWidth, int bandHeight, boolean vertical, - byte[] bitmapData, int dp, int bytesPerLine) { - int val = from << 16; - final int inc = ((to << 16) - val) / steps + 1; - if (vertical) { - for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) { - bitmapData[dp] = (byte)(val >>> 16); - val += inc; - } - } else { - for (int dx = 0; dx < bandWidth; ++dx, dp += 4) { - bitmapData[dp] = (byte)(val >>> 16); - val += inc; - } - } -} - -/* - * Fill in dithered gradated values for a color channel - */ -static final void buildDitheredGradientChannel(int from, int to, int steps, - int bandWidth, int bandHeight, boolean vertical, - byte[] bitmapData, int dp, int bytesPerLine, int bits) { - final int mask = 0xff00 >>> bits; - int val = from << 16; - final int inc = ((to << 16) - val) / steps + 1; - if (vertical) { - for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) { - for (int dx = 0, dptr = dp; dx < bandWidth; ++dx, dptr += 4) { - final int thresh = DITHER_MATRIX[dy & 7][dx] >>> bits; - int temp = val + thresh; - if (temp > 0xffffff) bitmapData[dptr] = -1; - else bitmapData[dptr] = (byte)((temp >>> 16) & mask); - } - val += inc; - } - } else { - for (int dx = 0; dx < bandWidth; ++dx, dp += 4) { - for (int dy = 0, dptr = dp; dy < bandHeight; ++dy, dptr += bytesPerLine) { - final int thresh = DITHER_MATRIX[dy][dx & 7] >>> bits; - int temp = val + thresh; - if (temp > 0xffffff) bitmapData[dptr] = -1; - else bitmapData[dptr] = (byte)((temp >>> 16) & mask); - } - val += inc; - } - } -} - -/** - * Renders a gradient onto a GC. - * <p> - * This is a GC helper. - * </p> - * - * @param gc the GC to render the gradient onto - * @param device the device the GC belongs to - * @param x the top-left x coordinate of the region to be filled - * @param y the top-left y coordinate of the region to be filled - * @param width the width of the region to be filled - * @param height the height of the region to be filled - * @param vertical if true sweeps from top to bottom, else - * sweeps from left to right - * @param fromRGB the color to start with - * @param toRGB the color to end with - * @param redBits the number of significant red bits, 0 for palette modes - * @param greenBits the number of significant green bits, 0 for palette modes - * @param blueBits the number of significant blue bits, 0 for palette modes - */ -static void fillGradientRectangle(GC gc, Device device, - int x, int y, int width, int height, boolean vertical, - RGB fromRGB, RGB toRGB, - int redBits, int greenBits, int blueBits) { - /* Create the bitmap and tile it */ - ImageData band = createGradientBand(width, height, vertical, - fromRGB, toRGB, redBits, greenBits, blueBits); - Image image = new Image(device, band); - if ((band.width == 1) || (band.height == 1)) { - gc.drawImage(image, 0, 0, band.width, band.height, x, y, width, height); - } else { - if (vertical) { - for (int dx = 0; dx < width; dx += band.width) { - int blitWidth = width - dx; - if (blitWidth > band.width) blitWidth = band.width; - gc.drawImage(image, 0, 0, blitWidth, band.height, dx + x, y, blitWidth, band.height); - } - } else { - for (int dy = 0; dy < height; dy += band.height) { - int blitHeight = height - dy; - if (blitHeight > band.height) blitHeight = band.height; - gc.drawImage(image, 0, 0, band.width, blitHeight, x, dy + y, band.width, blitHeight); - } - } - } - image.dispose(); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java deleted file mode 100644 index b0aa89772c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import java.io.*; - -/** - * Internal class that separates ImageData from ImageLoader - * to allow removal of ImageLoader from the toolkit. - */ -class ImageDataLoader { - - public static ImageData[] load(InputStream stream) { - return new ImageLoader().load(stream); - } - - public static ImageData[] load(String filename) { - return new ImageLoader().load(filename); - } - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java deleted file mode 100755 index 0feebe2873..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import java.io.*; -import java.util.Vector; -import org.eclipse.swt.*; -import org.eclipse.swt.internal.Compatibility; -import org.eclipse.swt.internal.image.*; - -/** - * Instances of this class are used to load images from, - * and save images to, a file or stream. - * <p> - * Currently supported image formats are: - * </p><ul> - * <li>BMP (Windows or OS/2 Bitmap)</li> - * <li>ICO (Windows Icon)</li> - * <li>JPEG</li> - * <li>GIF</li> - * <li>PNG</li> - * <li>TIFF</li> - * </ul> - * <code>ImageLoaders</code> can be used to: - * <ul> - * <li>load/save single images in all formats</li> - * <li>load/save multiple images (GIF/ICO/TIFF)</li> - * <li>load/save animated GIF images</li> - * <li>load interlaced GIF/PNG images</li> - * <li>load progressive JPEG images</li> - * </ul> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ImageAnalyzer</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class ImageLoader { - - /** - * the array of ImageData objects in this ImageLoader. - * This array is read in when the load method is called, - * and it is written out when the save method is called - */ - public ImageData[] data; - - /** - * the width of the logical screen on which the images - * reside, in pixels (this corresponds to the GIF89a - * Logical Screen Width value) - */ - public int logicalScreenWidth; - - /** - * the height of the logical screen on which the images - * reside, in pixels (this corresponds to the GIF89a - * Logical Screen Height value) - */ - public int logicalScreenHeight; - - /** - * the background pixel for the logical screen (this - * corresponds to the GIF89a Background Color Index value). - * The default is -1 which means 'unspecified background' - * - */ - public int backgroundPixel; - - /** - * the number of times to repeat the display of a sequence - * of animated images (this corresponds to the commonly-used - * GIF application extension for "NETSCAPE 2.0 01"). - * The default is 1. A value of 0 means 'display repeatedly' - */ - public int repeatCount; - - /* - * the set of ImageLoader event listeners, created on demand - */ - Vector imageLoaderListeners; - -/** - * Construct a new empty ImageLoader. - */ -public ImageLoader() { - reset(); -} - -/** - * Resets the fields of the ImageLoader, except for the - * <code>imageLoaderListeners</code> field. - */ -void reset() { - data = null; - logicalScreenWidth = 0; - logicalScreenHeight = 0; - backgroundPixel = -1; - repeatCount = 1; -} - -/** - * Loads an array of <code>ImageData</code> objects from the - * specified input stream. Throws an error if either an error - * occurs while loading the images, or if the images are not - * of a supported type. Returns the loaded image data array. - * - * @param stream the input stream to load the images from - * @return an array of <code>ImageData</code> objects loaded from the specified input stream - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> - * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> - * </ul> - */ -public ImageData[] load(InputStream stream) { - if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - reset(); - data = FileFormat.load(stream, this); - return data; -} - -/** - * Loads an array of <code>ImageData</code> objects from the - * file with the specified name. Throws an error if either - * an error occurs while loading the images, or if the images are - * not of a supported type. Returns the loaded image data array. - * - * @param filename the name of the file to load the images from - * @return an array of <code>ImageData</code> objects loaded from the specified file - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the file name is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while reading from the file</li> - * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li> - * </ul> - */ -public ImageData[] load(String filename) { - if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - InputStream stream = null; - try { - stream = Compatibility.newFileInputStream(filename); - return load(stream); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } finally { - try { - if (stream != null) stream.close(); - } catch (IOException e) { - // Ignore error - } - } - return null; -} - -/** - * Saves the image data in this ImageLoader to the specified stream. - * The format parameter can have one of the following values: - * <dl> - * <dt><code>IMAGE_BMP</code></dt> - * <dd>Windows BMP file format, no compression</dd> - * <dt><code>IMAGE_BMP_RLE</code></dt> - * <dd>Windows BMP file format, RLE compression if appropriate</dd> - * <dt><code>IMAGE_GIF</code></dt> - * <dd>GIF file format</dd> - * <dt><code>IMAGE_ICO</code></dt> - * <dd>Windows ICO file format</dd> - * <dt><code>IMAGE_JPEG</code></dt> - * <dd>JPEG file format</dd> - * <dt><code>IMAGE_PNG</code></dt> - * <dd>PNG file format</dd> - * </dl> - * - * @param stream the output stream to write the images to - * @param format the format to write the images in - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while writing to the stream</li> - * <li>ERROR_INVALID_IMAGE - if the image data contains invalid data</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format</li> - * </ul> - */ -public void save(OutputStream stream, int format) { - if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - FileFormat.save(stream, format, this); -} - -/** - * Saves the image data in this ImageLoader to a file with the specified name. - * The format parameter can have one of the following values: - * <dl> - * <dt><code>IMAGE_BMP</code></dt> - * <dd>Windows BMP file format, no compression</dd> - * <dt><code>IMAGE_BMP_RLE</code></dt> - * <dd>Windows BMP file format, RLE compression if appropriate</dd> - * <dt><code>IMAGE_GIF</code></dt> - * <dd>GIF file format</dd> - * <dt><code>IMAGE_ICO</code></dt> - * <dd>Windows ICO file format</dd> - * <dt><code>IMAGE_JPEG</code></dt> - * <dd>JPEG file format</dd> - * <dt><code>IMAGE_PNG</code></dt> - * <dd>PNG file format</dd> - * </dl> - * - * @param filename the name of the file to write the images to - * @param format the format to write the images in - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the file name is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while writing to the file</li> - * <li>ERROR_INVALID_IMAGE - if the image data contains invalid data</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format</li> - * </ul> - */ -public void save(String filename, int format) { - if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - OutputStream stream = null; - try { - stream = Compatibility.newFileOutputStream(filename); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - save(stream, format); - try { - stream.close(); - } catch (IOException e) { - } -} - -/** - * Adds the listener to the collection of listeners who will be - * notified when image data is either partially or completely loaded. - * <p> - * An ImageLoaderListener should be added before invoking - * one of the receiver's load methods. The listener's - * <code>imageDataLoaded</code> method is called when image - * data has been partially loaded, as is supported by interlaced - * GIF/PNG or progressive JPEG images. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * - * @see ImageLoaderListener - * @see ImageLoaderEvent - */ -public void addImageLoaderListener(ImageLoaderListener listener) { - if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - if (imageLoaderListeners == null) { - imageLoaderListeners = new Vector(); - } - imageLoaderListeners.addElement(listener); -} - -/** - * Removes the listener from the collection of listeners who will be - * notified when image data is either partially or completely loaded. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * - * @see #addImageLoaderListener(ImageLoaderListener) - */ -public void removeImageLoaderListener(ImageLoaderListener listener) { - if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - if (imageLoaderListeners == null) return; - imageLoaderListeners.removeElement(listener); -} - -/** - * Returns <code>true</code> if the receiver has image loader - * listeners, and <code>false</code> otherwise. - * - * @return <code>true</code> if there are <code>ImageLoaderListener</code>s, and <code>false</code> otherwise - * - * @see #addImageLoaderListener(ImageLoaderListener) - * @see #removeImageLoaderListener(ImageLoaderListener) - */ -public boolean hasListeners() { - return imageLoaderListeners != null && imageLoaderListeners.size() > 0; -} - -/** - * Notifies all image loader listeners that an image loader event - * has occurred. Pass the specified event object to each listener. - * - * @param event the <code>ImageLoaderEvent</code> to send to each <code>ImageLoaderListener</code> - */ -public void notifyListeners(ImageLoaderEvent event) { - if (!hasListeners()) return; - int size = imageLoaderListeners.size(); - for (int i = 0; i < size; i++) { - ImageLoaderListener listener = (ImageLoaderListener) imageLoaderListeners.elementAt(i); - listener.imageDataLoaded(event); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java deleted file mode 100755 index d365596052..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.internal.SWTEventObject; - -/** - * Instances of this class are sent as a result of the incremental - * loading of image data. - * <p> - * <b>Notes:</b> - * </p><ul> - * <li>The number of events which will be sent when loading images - * is not constant. It varies by image type, and for JPEG images it - * varies from image to image.</li> - * <li>For image sources which contain multiple images, the - * <code>endOfImage</code> flag in the event will be set to true - * after each individual image is loaded.</li> - * </ul> - * - * @see ImageLoader - * @see ImageLoaderListener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class ImageLoaderEvent extends SWTEventObject { - - /** - * if the <code>endOfImage</code> flag is false, then this is a - * partially complete copy of the current <code>ImageData</code>, - * otherwise this is a completely loaded <code>ImageData</code> - */ - public ImageData imageData; - - /** - * the zero-based count of image data increments -- this is - * equivalent to the number of events that have been generated - * while loading a particular image - */ - public int incrementCount; - - /** - * If this flag is true, then the current image data has been - * completely loaded, otherwise the image data is only partially - * loaded, and further ImageLoader events will occur unless an - * exception is thrown - */ - public boolean endOfImage; - - static final long serialVersionUID = 3257284738325558065L; - -/** - * Constructs a new instance of this class given the event source and - * the values to store in its fields. - * - * @param source the ImageLoader that was loading when the event occurred - * @param imageData the image data for the event - * @param incrementCount the image data increment for the event - * @param endOfImage the end of image flag for the event - */ -public ImageLoaderEvent(ImageLoader source, ImageData imageData, int incrementCount, boolean endOfImage) { - super(source); - this.imageData = imageData; - this.incrementCount = incrementCount; - this.endOfImage = endOfImage; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString () { - return "ImageLoaderEvent {source=" + source + " imageData=" + imageData + " incrementCount=" + incrementCount + " endOfImage=" + endOfImage + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java deleted file mode 100755 index 631779fc0a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Classes which implement this interface provide methods - * that deal with the incremental loading of image data. - * <p> - * After creating an instance of a class that implements - * this interface it can be added to an image loader using the - * <code>addImageLoaderListener</code> method and removed using - * the <code>removeImageLoaderListener</code> method. When - * image data is either partially or completely loaded, this - * method will be invoked. - * </p> - * - * @see ImageLoader - * @see ImageLoaderEvent - */ - -public interface ImageLoaderListener extends SWTEventListener { - -/** - * Sent when image data is either partially or completely loaded. - * <p> - * The timing of when this method is called varies depending on - * the format of the image being loaded. - * </p> - * - * @param e an event containing information about the image loading operation - */ -public void imageDataLoaded(ImageLoaderEvent e); - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java deleted file mode 100644 index 6d02341579..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.*; - -/** - * <code>LineAttributes</code> defines a set of line attributes that - * can be modified in a GC. - * <p> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * </p> - * - * @see GC#getLineAttributes() - * @see GC#setLineAttributes(LineAttributes) - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.3 - */ -public class LineAttributes { - - /** - * The line width. - */ - public float width; - - /** - * The line style. - * - * @see org.eclipse.swt.SWT#LINE_CUSTOM - * @see org.eclipse.swt.SWT#LINE_DASH - * @see org.eclipse.swt.SWT#LINE_DASHDOT - * @see org.eclipse.swt.SWT#LINE_DASHDOTDOT - * @see org.eclipse.swt.SWT#LINE_DOT - * @see org.eclipse.swt.SWT#LINE_SOLID - */ - public int style; - - /** - * The line cap style. - * - * @see org.eclipse.swt.SWT#CAP_FLAT - * @see org.eclipse.swt.SWT#CAP_ROUND - * @see org.eclipse.swt.SWT#CAP_SQUARE - */ - public int cap; - - /** - * The line join style. - * - * @see org.eclipse.swt.SWT#JOIN_BEVEL - * @see org.eclipse.swt.SWT#JOIN_MITER - * @see org.eclipse.swt.SWT#JOIN_ROUND - */ - public int join; - - /** - * The line dash style for SWT.LINE_CUSTOM. - */ - public float[] dash; - - /** - * The line dash style offset for SWT.LINE_CUSTOM. - */ - public float dashOffset; - - /** - * The line miter limit. - */ - public float miterLimit; - -/** - * Create a new line attributes with the specified line width. - * - * @param width the line width - */ -public LineAttributes(float width) { - this(width, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_SOLID, null, 0, 10); -} - -/** - * Create a new line attributes with the specified line cap, join and width. - * - * @param width the line width - * @param cap the line cap style - * @param join the line join style - */ -public LineAttributes(float width, int cap, int join) { - this(width, cap, join, SWT.LINE_SOLID, null, 0, 10); -} - -/** - * Create a new line attributes with the specified arguments. - * - * @param width the line width - * @param cap the line cap style - * @param join the line join style - * @param style the line style - * @param dash the line dash style - * @param dashOffset the line dash style offset - * @param miterLimit the line miter limit - */ -public LineAttributes(float width, int cap, int join, int style, float[] dash, float dashOffset, float miterLimit) { - this.width = width; - this.cap = cap; - this.join = join; - this.style = style; - this.dash = dash; - this.dashOffset = dashOffset; - this.miterLimit = miterLimit; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java deleted file mode 100755 index c73a01fa9c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.*; - -/** - * Instances of this class describe the color data used by an image. - * <p> - * Depending on the depth of the image, the PaletteData can take one - * of two forms, indicated by the isDirect field: - * </p> - * <dl> - * <dt> - * <em>isDirect is false</em> - * </dt> - * <dd> - * If isDirect is <code>false</code>, this palette is an indexed - * palette which maps pixel values to RGBs. The actual RGB values - * may be retrieved by using the getRGBs() method. - * </dd> - * <dt> - * <em>isDirect is true</em> - * </dt> - * <dd> - * If isDirect is <code>true</code>, this palette is a direct color - * palette. Instead of containing RGB values, it contains red, - * green and blue mask and shift information which indicates how - * the color components may be extracted from a given pixel. - * This means that the RGB value is actually encoded in the pixel value. - * <p> - * In this case, the shift data is the number of bits required to shift - * the RGB value to the left in order to align the high bit of the - * corresponding mask with the high bit of the first byte. This number - * may be negative, so care must be taken when shifting. For example, - * with a red mask of 0xFF0000, the red shift would be -16. With a red - * mask of 0x1F, the red shift would be 3. - * </p> - * </dd> - * </dl> - * - * @see Image - * @see RGB - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class PaletteData { - - /** - * true if the receiver is a direct palette, - * and false otherwise - */ - public boolean isDirect; - - /** - * the RGB values for an indexed palette, where the - * indices of the array correspond to pixel values - */ - public RGB[] colors; - - /** - * the red mask for a direct palette - */ - public int redMask; - - /** - * the green mask for a direct palette - */ - public int greenMask; - - /** - * the blue mask for a direct palette - */ - public int blueMask; - - /** - * the red shift for a direct palette - */ - public int redShift; - - /** - * the green shift for a direct palette - */ - public int greenShift; - - /** - * the blue shift for a direct palette - */ - public int blueShift; - -/** - * Constructs a new indexed palette given an array of RGB values. - * - * @param colors the array of <code>RGB</code>s for the palette - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - */ -public PaletteData(RGB[] colors) { - if (colors == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - this.colors = colors; - this.isDirect = false; -} - -/** - * Constructs a new direct palette given the red, green and blue masks. - * - * @param redMask the red mask - * @param greenMask the green mask - * @param blueMask the blue mask - */ -public PaletteData(int redMask, int greenMask, int blueMask) { - this.redMask = redMask; - this.greenMask = greenMask; - this.blueMask = blueMask; - this.isDirect = true; - this.redShift = shiftForMask(redMask); - this.greenShift = shiftForMask(greenMask); - this.blueShift = shiftForMask(blueMask); -} - -/** - * Returns the pixel value corresponding to the given <code>RGB</code>. - * - * @param rgb the RGB to get the pixel value for - * @return the pixel value for the given RGB - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the RGB is not found in the palette</li> - * </ul> - */ -public int getPixel(RGB rgb) { - if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (isDirect) { - int pixel = 0; - pixel |= (redShift < 0 ? rgb.red << -redShift : rgb.red >>> redShift) & redMask; - pixel |= (greenShift < 0 ? rgb.green << -greenShift : rgb.green >>> greenShift) & greenMask; - pixel |= (blueShift < 0 ? rgb.blue << -blueShift : rgb.blue >>> blueShift) & blueMask; - return pixel; - } else { - for (int i = 0; i < colors.length; i++) { - if (colors[i].equals(rgb)) return i; - } - /* The RGB did not exist in the palette */ - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return 0; - } -} - -/** - * Returns an <code>RGB</code> corresponding to the given pixel value. - * - * @param pixel the pixel to get the RGB value for - * @return the RGB value for the given pixel - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the pixel does not exist in the palette</li> - * </ul> - */ -public RGB getRGB(int pixel) { - if (isDirect) { - int r = pixel & redMask; - r = (redShift < 0) ? r >>> -redShift : r << redShift; - int g = pixel & greenMask; - g = (greenShift < 0) ? g >>> -greenShift : g << greenShift; - int b = pixel & blueMask; - b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; - return new RGB(r, g, b); - } else { - if (pixel < 0 || pixel >= colors.length) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - return colors[pixel]; - } -} - -/** - * Returns all the RGB values in the receiver if it is an - * indexed palette, or null if it is a direct palette. - * - * @return the <code>RGB</code>s for the receiver or null - */ -public RGB[] getRGBs() { - return colors; -} - -/** - * Computes the shift value for a given mask. - * - * @param mask the mask to compute the shift for - * @return the shift amount - * - * @see PaletteData - */ -int shiftForMask(int mask) { - for (int i = 31; i >= 0; i--) { - if (((mask >> i) & 0x1) != 0) return 7 - i; - } - return 32; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java deleted file mode 100644 index 8702dcfbe2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -/** - * Instances of this class describe device-independent paths. - * - * @see Path - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.1 - */ -public final class PathData { - - /** - * The type of each point. - */ - public byte[] types; - - /** - * The points of a path. - */ - public float[] points; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java deleted file mode 100755 index 3d3f9cbc5d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.internal.SerializableCompatibility; - -/** - * Instances of this class represent places on the (x, y) - * coordinate plane. - * <p> - * The coordinate space for rectangles and points is considered - * to have increasing values downward and to the right from its - * origin making this the normal, computer graphics oriented notion - * of (x, y) coordinates rather than the strict mathematical one. - * </p> - * <p> - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - * </p> - * <p> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * </p> - * - * @see Rectangle - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class Point implements SerializableCompatibility { - - /** - * the x coordinate of the point - */ - public int x; - - /** - * the y coordinate of the point - */ - public int y; - - static final long serialVersionUID = 3257002163938146354L; - -/** - * Constructs a new point with the given x and y coordinates. - * - * @param x the x coordinate of the new point - * @param y the y coordinate of the new point - */ -public Point (int x, int y) { - this.x = x; - this.y = y; -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode() - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Point)) return false; - Point p = (Point)object; - return (p.x == this.x) && (p.y == this.y); -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ -public int hashCode () { - return x ^ y; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the point - */ -public String toString () { - return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java deleted file mode 100755 index e7a5630bbd..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.internal.SerializableCompatibility; -import org.eclipse.swt.*; - -/** - * Instances of this class are descriptions of colors in - * terms of the primary additive color model (red, green and - * blue). A color may be described in terms of the relative - * intensities of these three primary colors. The brightness - * of each color is specified by a value in the range 0 to 255, - * where 0 indicates no color (blackness) and 255 indicates - * maximum intensity. - * <p> - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - * </p> - * <p> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * </p> - * - * @see Color - * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class RGB implements SerializableCompatibility { - - /** - * the red component of the RGB - */ - public int red; - - /** - * the green component of the RGB - */ - public int green; - - /** - * the blue component of the RGB - */ - public int blue; - - static final long serialVersionUID = 3258415023461249074L; - -/** - * Constructs an instance of this class with the given - * red, green and blue values. - * - * @param red the red component of the new instance - * @param green the green component of the new instance - * @param blue the blue component of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> - * </ul> - */ -public RGB(int red, int green, int blue) { - if ((red > 255) || (red < 0) || - (green > 255) || (green < 0) || - (blue > 255) || (blue < 0)) - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - this.red = red; - this.green = green; - this.blue = blue; -} - -/** -* Constructs an instance of this class with the given -* hue, saturation, and brightness. -* -* @param hue the hue value for the HSB color (from 0 to 360) -* @param saturation the saturation value for the HSB color (from 0 to 1) -* @param brightness the brightness value for the HSB color (from 0 to 1) -* -* @exception IllegalArgumentException <ul> -* <li>ERROR_INVALID_ARGUMENT - if the hue is not between 0 and 360 or -* the saturation or brightness is not between 0 and 1</li> -* </ul> -* -* @since 3.2 -*/ -public RGB(float hue, float saturation, float brightness) { - if (hue < 0 || hue > 360 || saturation < 0 || saturation > 1 || - brightness < 0 || brightness > 1) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - float r, g, b; - if (saturation == 0) { - r = g = b = brightness; - } else { - if (hue == 360) hue = 0; - hue /= 60; - int i = (int)hue; - float f = hue - i; - float p = brightness * (1 - saturation); - float q = brightness * (1 - saturation * f); - float t = brightness * (1 - saturation * (1 - f)); - switch(i) { - case 0: - r = brightness; - g = t; - b = p; - break; - case 1: - r = q; - g = brightness; - b = p; - break; - case 2: - r = p; - g = brightness; - b = t; - break; - case 3: - r = p; - g = q; - b = brightness; - break; - case 4: - r = t; - g = p; - b = brightness; - break; - case 5: - default: - r = brightness; - g = p; - b = q; - break; - } - } - red = (int)(r * 255 + 0.5); - green = (int)(g * 255 + 0.5); - blue = (int)(b * 255 + 0.5); -} - -/** - * Returns the hue, saturation, and brightness of the color. - * - * @return color space values in float format (hue, saturation, brightness) - * - * @since 3.2 - */ -public float[] getHSB() { - float r = red / 255f; - float g = green / 255f; - float b = blue / 255f; - float max = Math.max(Math.max(r, g), b); - float min = Math.min(Math.min(r, g), b); - float delta = max - min; - float hue = 0; - float brightness = max; - float saturation = max == 0 ? 0 : (max - min) / max; - if (delta != 0) { - if (r == max) { - hue = (g - b) / delta; - } else { - if (g == max) { - hue = 2 + (b - r) / delta; - } else { - hue = 4 + (r - g) / delta; - } - } - hue *= 60; - if (hue < 0) hue += 360; - } - return new float[] {hue, saturation, brightness}; -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode() - */ -public boolean equals(Object object) { - if (object == this) return true; - if (!(object instanceof RGB)) return false; - RGB rgb = (RGB)object; - return (rgb.red == this.red) && (rgb.green == this.green) && (rgb.blue == this.blue); -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ -public int hashCode() { - return (blue << 16) | (green << 8) | red; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the <code>RGB</code> - */ -public String toString() { - return "RGB {" + red + ", " + green + ", " + blue + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java deleted file mode 100755 index c09e15f454..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.internal.SerializableCompatibility; -import org.eclipse.swt.*; - -/** - * Instances of this class represent rectangular areas in an - * (x, y) coordinate system. The top left corner of the rectangle - * is specified by its x and y values, and the extent of the - * rectangle is specified by its width and height. - * <p> - * The coordinate space for rectangles and points is considered - * to have increasing values downward and to the right from its - * origin making this the normal, computer graphics oriented notion - * of (x, y) coordinates rather than the strict mathematical one. - * </p> - * <p> - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - * </p> - * <p> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * </p> - * - * @see Point - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public final class Rectangle implements SerializableCompatibility { - - /** - * the x coordinate of the rectangle - */ - public int x; - - /** - * the y coordinate of the rectangle - */ - public int y; - - /** - * the width of the rectangle - */ - public int width; - - /** - * the height of the rectangle - */ - public int height; - - static final long serialVersionUID = 3256439218279428914L; - -/** - * Construct a new instance of this class given the - * x, y, width and height values. - * - * @param x the x coordinate of the origin of the rectangle - * @param y the y coordinate of the origin of the rectangle - * @param width the width of the rectangle - * @param height the height of the rectangle - */ -public Rectangle (int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; -} - -/** - * Destructively replaces the x, y, width and height values - * in the receiver with ones which represent the union of the - * rectangles specified by the receiver and the given rectangle. - * <p> - * The union of two rectangles is the smallest single rectangle - * that completely covers both of the areas covered by the two - * given rectangles. - * </p> - * - * @param rect the rectangle to merge with the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - */ -public void add (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int left = x < rect.x ? x : rect.x; - int top = y < rect.y ? y : rect.y; - int lhs = x + width; - int rhs = rect.x + rect.width; - int right = lhs > rhs ? lhs : rhs; - lhs = y + height; - rhs = rect.y + rect.height; - int bottom = lhs > rhs ? lhs : rhs; - x = left; y = top; width = right - left; height = bottom - top; -} - -/** - * Returns <code>true</code> if the point specified by the - * arguments is inside the area specified by the receiver, - * and <code>false</code> otherwise. - * - * @param x the x coordinate of the point to test for containment - * @param y the y coordinate of the point to test for containment - * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise - */ -public boolean contains (int x, int y) { - return (x >= this.x) && (y >= this.y) && x < (this.x + width) && y < (this.y + height); -} - -/** - * Returns <code>true</code> if the given point is inside the - * area specified by the receiver, and <code>false</code> - * otherwise. - * - * @param pt the point to test for containment - * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - */ -public boolean contains (Point pt) { - if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return contains(pt.x, pt.y); -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode() - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Rectangle)) return false; - Rectangle r = (Rectangle)object; - return (r.x == this.x) && (r.y == this.y) && (r.width == this.width) && (r.height == this.height); -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ -public int hashCode () { - return x ^ y ^ width ^ height; -} - -/** - * Destructively replaces the x, y, width and height values - * in the receiver with ones which represent the intersection of the - * rectangles specified by the receiver and the given rectangle. - * - * @param rect the rectangle to intersect with the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * - * since 3.0 - */ -public void intersect (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (this == rect) return; - int left = x > rect.x ? x : rect.x; - int top = y > rect.y ? y : rect.y; - int lhs = x + width; - int rhs = rect.x + rect.width; - int right = lhs < rhs ? lhs : rhs; - lhs = y + height; - rhs = rect.y + rect.height; - int bottom = lhs < rhs ? lhs : rhs; - x = right < left ? 0 : left; - y = bottom < top ? 0 : top; - width = right < left ? 0 : right - left; - height = bottom < top ? 0 : bottom - top; -} - -/** - * Returns a new rectangle which represents the intersection - * of the receiver and the given rectangle. - * <p> - * The intersection of two rectangles is the rectangle that - * covers the area which is contained within both rectangles. - * </p> - * - * @param rect the rectangle to intersect with the receiver - * @return the intersection of the receiver and the argument - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - */ -public Rectangle intersection (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (this == rect) return new Rectangle (x, y, width, height); - int left = x > rect.x ? x : rect.x; - int top = y > rect.y ? y : rect.y; - int lhs = x + width; - int rhs = rect.x + rect.width; - int right = lhs < rhs ? lhs : rhs; - lhs = y + height; - rhs = rect.y + rect.height; - int bottom = lhs < rhs ? lhs : rhs; - return new Rectangle ( - right < left ? 0 : left, - bottom < top ? 0 : top, - right < left ? 0 : right - left, - bottom < top ? 0 : bottom - top); -} - -/** - * Returns <code>true</code> if the rectangle described by the - * arguments intersects with the receiver and <code>false</code> - * otherwise. - * <p> - * Two rectangles intersect if the area of the rectangle - * representing their intersection is not empty. - * </p> - * - * @param x the x coordinate of the origin of the rectangle - * @param y the y coordinate of the origin of the rectangle - * @param width the width of the rectangle - * @param height the height of the rectangle - * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * - * @see #intersection(Rectangle) - * @see #isEmpty() - * - * @since 3.0 - */ -public boolean intersects (int x, int y, int width, int height) { - return (x < this.x + this.width) && (y < this.y + this.height) && - (x + width > this.x) && (y + height > this.y); -} - -/** - * Returns <code>true</code> if the given rectangle intersects - * with the receiver and <code>false</code> otherwise. - * <p> - * Two rectangles intersect if the area of the rectangle - * representing their intersection is not empty. - * </p> - * - * @param rect the rectangle to test for intersection - * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * - * @see #intersection(Rectangle) - * @see #isEmpty() - */ -public boolean intersects (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return rect == this || intersects (rect.x, rect.y, rect.width, rect.height); -} - -/** - * Returns <code>true</code> if the receiver does not cover any - * area in the (x, y) coordinate plane, and <code>false</code> if - * the receiver does cover some area in the plane. - * <p> - * A rectangle is considered to <em>cover area</em> in the - * (x, y) coordinate plane if both its width and height are - * non-zero. - * </p> - * - * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise - */ -public boolean isEmpty () { - return (width <= 0) || (height <= 0); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the rectangle - */ -public String toString () { - return "Rectangle {" + x + ", " + y + ", " + width + ", " + height + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ -} - -/** - * Returns a new rectangle which represents the union of - * the receiver and the given rectangle. - * <p> - * The union of two rectangles is the smallest single rectangle - * that completely covers both of the areas covered by the two - * given rectangles. - * </p> - * - * @param rect the rectangle to perform union with - * @return the union of the receiver and the argument - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * - * @see #add(Rectangle) - */ -public Rectangle union (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int left = x < rect.x ? x : rect.x; - int top = y < rect.y ? y : rect.y; - int lhs = x + width; - int rhs = rect.x + rect.width; - int right = lhs > rhs ? lhs : rhs; - lhs = y + height; - rhs = rect.y + rect.height; - int bottom = lhs > rhs ? lhs : rhs; - return new Rectangle (left, top, right - left, bottom - top); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java deleted file mode 100644 index 82c45043b9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.*; - -/** - * This class is the abstract superclass of all graphics resource objects. - * Resources created by the application must be disposed. - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. However, it has not been marked - * final to allow those outside of the SWT development team to implement - * patched versions of the class in order to get around specific - * limitations in advance of when those limitations can be addressed - * by the team. Any class built using subclassing to access the internals - * of this class will likely fail to compile or run between releases and - * may be strongly platform specific. Subclassing should not be attempted - * without an intimate and detailed understanding of the workings of the - * hierarchy. No support is provided for user-written classes which are - * implemented as subclasses of this class. - * </p> - * - * @see #dispose - * @see #isDisposed - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.1 - */ -public abstract class Resource { - - /** - * the device where this resource was created - */ - Device device; - -public Resource() { -} - -Resource(Device device) { - if (device == null) device = Device.getDevice(); - if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - this.device = device; -} - -void destroy() { -} - -/** - * Disposes of the operating system resources associated with - * this resource. Applications must dispose of all resources - * which they allocate. - */ -public void dispose() { - if (device == null) return; - if (device.isDisposed()) return; - destroy(); - if (device.tracking) device.dispose_Object(this); - device = null; -} - -/** - * Returns the <code>Device</code> where this resource was - * created. - * - * @return <code>Device</code> the device of the receiver - * - * @since 3.2 - */ -public Device getDevice() { - Device device = this.device; - if (device == null || isDisposed ()) SWT.error (SWT.ERROR_GRAPHIC_DISPOSED); - return device; -} - -void init() { - if (device.tracking) device.new_Object(this); -} - -/** - * Returns <code>true</code> if the resource has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the resource. - * When a resource has been disposed, it is an error to - * invoke any other method using the resource. - * - * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise - */ -public abstract boolean isDisposed(); - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java deleted file mode 100644 index 6b7b1cd9a9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java +++ /dev/null @@ -1,395 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.*; - -/** - * <code>TextStyle</code> defines a set of styles that can be applied - * to a range of text. - * <p> - * The hashCode() method in this class uses the values of the public - * fields to compute the hash value. When storing instances of the - * class in hashed collections, do not modify these fields after the - * object has been inserted. - * </p> - * <p> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * </p> - * - * @see TextLayout - * @see Font - * @see Color - * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.0 - */ -public class TextStyle { - - /** - * the font of the style - */ - public Font font; - - /** - * the foreground of the style - */ - public Color foreground; - - /** - * the background of the style - */ - public Color background; - - /** - * the underline flag of the style. The default underline - * style is <code>SWT.UNDERLINE_SINGLE</code>. - * - * - * @since 3.1 - */ - public boolean underline; - - /** - * the underline color of the style - * - * @since 3.4 - */ - public Color underlineColor; - - /** - * the underline style. This style is ignored when - * <code>underline</code> is false. - * <p> - * This value should be one of <code>SWT.UNDERLINE_SINGLE</code>, - * <code>SWT.UNDERLINE_DOUBLE</code>, <code>SWT.UNDERLINE_ERROR</code>, - * or <code>SWT.UNDERLINE_SQUIGGLE</code>. - * </p> - * - * @see SWT#UNDERLINE_SINGLE - * @see SWT#UNDERLINE_DOUBLE - * @see SWT#UNDERLINE_ERROR - * @see SWT#UNDERLINE_SQUIGGLE - * @see SWT#UNDERLINE_LINK - * - * @since 3.4 - */ - public int underlineStyle; - - /** - * the strikeout flag of the style - * - * @since 3.1 - */ - public boolean strikeout; - - /** - * the strikeout color of the style - * - * @since 3.4 - */ - public Color strikeoutColor; - - /** - * the border style. The default border style is <code>SWT.NONE</code>. - * <p> - * This value should be one of <code>SWT.BORDER_SOLID</code>, - * <code>SWT.BORDER_DASH</code>,<code>SWT.BORDER_DOT</code> or - * <code>SWT.NONE</code>. - * </p> - * - * @see SWT#BORDER_SOLID - * @see SWT#BORDER_DASH - * @see SWT#BORDER_DOT - * @see SWT#NONE - * - * @since 3.4 - */ - public int borderStyle; - - /** - * the border color of the style - * - * @since 3.4 - */ - public Color borderColor; - - /** - * the GlyphMetrics of the style - * - * @since 3.2 - */ - public GlyphMetrics metrics; - - /** - * the baseline rise of the style. - * - * @since 3.2 - */ - public int rise; - - - /** - * the data. An user data field. It can be used to hold the HREF when the range - * is used as a link or the embed object when the range is used with <code>GlyphMetrics</code>. - * <p> - * - * @since 3.5 - */ - public Object data; - - -/** - * Create an empty text style. - * - * @since 3.4 - */ -public TextStyle () { -} - -/** - * Create a new text style with the specified font, foreground - * and background. - * - * @param font the font of the style, <code>null</code> if none - * @param foreground the foreground color of the style, <code>null</code> if none - * @param background the background color of the style, <code>null</code> if none - */ -public TextStyle (Font font, Color foreground, Color background) { - if (font != null && font.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - if (foreground != null && foreground.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - if (background != null && background.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - this.font = font; - this.foreground = foreground; - this.background = background; -} - - -/** - * Create a new text style from an existing text style. - * - * @param style the style to copy - * - * @since 3.4 - */ -public TextStyle (TextStyle style) { - if (style == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - font = style.font; - foreground = style.foreground; - background = style.background; - underline = style.underline; - underlineColor = style.underlineColor; - underlineStyle = style.underlineStyle; - strikeout = style.strikeout; - strikeoutColor = style.strikeoutColor; - borderStyle = style.borderStyle; - borderColor = style.borderColor; - metrics = style.metrics; - rise = style.rise; - data = style.data; -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode() - */ -public boolean equals(Object object) { - if (object == this) return true; - if (object == null) return false; - if (!(object instanceof TextStyle)) return false; - TextStyle style = (TextStyle)object; - if (foreground != null) { - if (!foreground.equals(style.foreground)) return false; - } else if (style.foreground != null) return false; - if (background != null) { - if (!background.equals(style.background)) return false; - } else if (style.background != null) return false; - if (font != null) { - if (!font.equals(style.font)) return false; - } else if (style.font != null) return false; - if (metrics != null || style.metrics != null) return false; - if (underline != style.underline) return false; - if (underlineStyle != style.underlineStyle) return false; - if (borderStyle != style.borderStyle) return false; - if (strikeout != style.strikeout) return false; - if (rise != style.rise) return false; - if (underlineColor != null) { - if (!underlineColor.equals(style.underlineColor)) return false; - } else if (style.underlineColor != null) return false; - if (strikeoutColor != null) { - if (!strikeoutColor.equals(style.strikeoutColor)) return false; - } else if (style.strikeoutColor != null) return false; - if (underlineStyle != style.underlineStyle) return false; - if (borderColor != null) { - if (!borderColor.equals(style.borderColor)) return false; - } else if (style.borderColor != null) return false; - if (data != null) { - if (!data.equals(style.data)) return false; - } else if (style.data != null) return false; - return true; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ -public int hashCode() { - int hash = 0; - if (foreground != null) hash ^= foreground.hashCode(); - if (background != null) hash ^= background.hashCode(); - if (font != null) hash ^= font.hashCode(); - if (metrics != null) hash ^= metrics.hashCode(); - if (underline) hash ^= hash; - if (strikeout) hash ^= hash; - hash ^= rise; - if (underlineColor != null) hash ^= underlineColor.hashCode(); - if (strikeoutColor != null) hash ^= strikeoutColor.hashCode(); - if (borderColor != null) hash ^= borderColor.hashCode(); - hash ^= underlineStyle; - return hash; -} - -boolean isAdherentBorder(TextStyle style) { - if (this == style) return true; - if (style == null) return false; - if (borderStyle != style.borderStyle) return false; - if (borderColor != null) { - if (!borderColor.equals(style.borderColor)) return false; - } else { - if (style.borderColor != null) return false; - if (foreground != null) { - if (!foreground.equals(style.foreground)) return false; - } else if (style.foreground != null) return false; - } - return true; -} - -boolean isAdherentUnderline(TextStyle style) { - if (this == style) return true; - if (style == null) return false; - if (underline != style.underline) return false; - if (underlineStyle != style.underlineStyle) return false; - if (underlineColor != null) { - if (!underlineColor.equals(style.underlineColor)) return false; - } else { - if (style.underlineColor != null) return false; - if (foreground != null) { - if (!foreground.equals(style.foreground)) return false; - } else if (style.foreground != null) return false; - } - return true; -} - -boolean isAdherentStrikeout(TextStyle style) { - if (this == style) return true; - if (style == null) return false; - if (strikeout != style.strikeout) return false; - if (strikeoutColor != null) { - if (!strikeoutColor.equals(style.strikeoutColor)) return false; - } else { - if (style.strikeoutColor != null) return false; - if (foreground != null) { - if (!foreground.equals(style.foreground)) return false; - } else if (style.foreground != null) return false; - } - return true; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the <code>TextStyle</code> - */ -public String toString () { - StringBuffer buffer = new StringBuffer("TextStyle {"); //$NON-NLS-1$ - int startLength = buffer.length(); - if (font != null) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("font="); //$NON-NLS-1$ - buffer.append(font); - } - if (foreground != null) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("foreground="); //$NON-NLS-1$ - buffer.append(foreground); - } - if (background != null) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("background="); //$NON-NLS-1$ - buffer.append(background); - } - if (underline) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("underline="); //$NON-NLS-1$ - switch (underlineStyle) { - case SWT.UNDERLINE_SINGLE: buffer.append("single"); break; //$NON-NLS-1$ - case SWT.UNDERLINE_DOUBLE: buffer.append("double"); break; //$NON-NLS-1$ - case SWT.UNDERLINE_SQUIGGLE: buffer.append("squiggle"); break; //$NON-NLS-1$ - case SWT.UNDERLINE_ERROR: buffer.append("error"); break; //$NON-NLS-1$ - case SWT.UNDERLINE_LINK: buffer.append("link"); break; //$NON-NLS-1$ - } - if (underlineColor != null) { - buffer.append(", underlineColor="); //$NON-NLS-1$ - buffer.append(underlineColor); - } - } - if (strikeout) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("striked out"); //$NON-NLS-1$ - if (strikeoutColor != null) { - buffer.append(", strikeoutColor="); //$NON-NLS-1$ - buffer.append(strikeoutColor); - } - } - if (borderStyle != SWT.NONE) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("border="); //$NON-NLS-1$ - switch (borderStyle) { - case SWT.BORDER_SOLID: buffer.append("solid"); break; //$NON-NLS-1$ - case SWT.BORDER_DOT: buffer.append("dot"); break; //$NON-NLS-1$ - case SWT.BORDER_DASH: buffer.append("dash"); break; //$NON-NLS-1$ - } - if (borderColor != null) { - buffer.append(", borderColor="); //$NON-NLS-1$ - buffer.append(borderColor); - } - } - if (rise != 0) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("rise="); //$NON-NLS-1$ - buffer.append(rise); - } - if (metrics != null) { - if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$ - buffer.append("metrics="); //$NON-NLS-1$ - buffer.append(metrics); - } - buffer.append("}"); //$NON-NLS-1$ - return buffer.toString(); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html deleted file mode 100755 index d71267ad85..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html +++ /dev/null @@ -1,18 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -SWT graphics classes. -<h2> -Package Specification</h2> -This package provides the classes which implement points, rectangles, -regions, colors, cursors, fonts, graphics contexts (that is, <code>GC</code>s) -where most of the primitive drawing operations are implemented, and -images including both the code for displaying them and the public API for -loading/saving them. -</body> -</html> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java deleted file mode 100755 index ce73d17e0e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal; - - -/** - * Instances of this class represent entry points into Java - * which can be invoked from operating system level callback - * routines. - * <p> - * IMPORTANT: A callback is only valid when invoked on the - * thread which created it. The results are undefined (and - * typically bad) when a callback is passed out to the - * operating system (or other code) in such a way that the - * callback is called from a different thread. - */ - -public class Callback { - - Object object; - String method, signature; - int argCount; - int /*long*/ address, errorResult; - boolean isStatic, isArrayBased; - - static final String PTR_SIGNATURE = C.PTR_SIZEOF == 4 ? "I" : "J"; //$NON-NLS-1$ //$NON-NLS-2$ - static final String SIGNATURE_0 = getSignature(0); - static final String SIGNATURE_1 = getSignature(1); - static final String SIGNATURE_2 = getSignature(2); - static final String SIGNATURE_3 = getSignature(3); - static final String SIGNATURE_4 = getSignature(4); - static final String SIGNATURE_N = "(["+PTR_SIGNATURE+")"+PTR_SIGNATURE; //$NON-NLS-1$ //$NON-NLS-2$ - -/** - * Constructs a new instance of this class given an object - * to send the message to, a string naming the method to - * invoke and an argument count. Note that, if the object - * is an instance of <code>Class</code> it is assumed that - * the method is a static method on that class. - * - * @param object the object to send the message to - * @param method the name of the method to invoke - * @param argCount the number of arguments that the method takes - */ -public Callback (Object object, String method, int argCount) { - this (object, method, argCount, false); -} - -/** - * Constructs a new instance of this class given an object - * to send the message to, a string naming the method to - * invoke, an argument count and a flag indicating whether - * or not the arguments will be passed in an array. Note - * that, if the object is an instance of <code>Class</code> - * it is assumed that the method is a static method on that - * class. - * - * @param object the object to send the message to - * @param method the name of the method to invoke - * @param argCount the number of arguments that the method takes - * @param isArrayBased <code>true</code> if the arguments should be passed in an array and false otherwise - */ -public Callback (Object object, String method, int argCount, boolean isArrayBased) { - this (object, method, argCount, isArrayBased, 0); -} - -/** - * Constructs a new instance of this class given an object - * to send the message to, a string naming the method to - * invoke, an argument count, a flag indicating whether - * or not the arguments will be passed in an array and a value - * to return when an exception happens. Note that, if - * the object is an instance of <code>Class</code> - * it is assumed that the method is a static method on that - * class. - * - * @param object the object to send the message to - * @param method the name of the method to invoke - * @param argCount the number of arguments that the method takes - * @param isArrayBased <code>true</code> if the arguments should be passed in an array and false otherwise - * @param errorResult the return value if the java code throws an exception - */ -public Callback (Object object, String method, int argCount, boolean isArrayBased, int /*long*/ errorResult) { - - /* Set the callback fields */ - this.object = object; - this.method = method; - this.argCount = argCount; - this.isStatic = object instanceof Class; - this.isArrayBased = isArrayBased; - this.errorResult = errorResult; - - /* Inline the common cases */ - if (isArrayBased) { - signature = SIGNATURE_N; - } else { - switch (argCount) { - case 0: signature = SIGNATURE_0; break; //$NON-NLS-1$ - case 1: signature = SIGNATURE_1; break; //$NON-NLS-1$ - case 2: signature = SIGNATURE_2; break; //$NON-NLS-1$ - case 3: signature = SIGNATURE_3; break; //$NON-NLS-1$ - case 4: signature = SIGNATURE_4; break; //$NON-NLS-1$ - default: - signature = getSignature(argCount); - } - } - - /* Bind the address */ - address = bind (this, object, method, signature, argCount, isStatic, isArrayBased, errorResult); -} - -/** - * Allocates the native level resources associated with the - * callback. This method is only invoked from within the - * constructor for the argument. - * - * @param callback the callback to bind - * @param object the callback's object - * @param method the callback's method - * @param signature the callback's method signature - * @param argCount the callback's method argument count - * @param isStatic whether the callback's method is static - * @param isArrayBased whether the callback's method is array based - * @param errorResult the callback's error result - */ -static native synchronized int /*long*/ bind (Callback callback, Object object, String method, String signature, int argCount, boolean isStatic, boolean isArrayBased, int /*long*/ errorResult); - -/** - * Releases the native level resources associated with the callback, - * and removes all references between the callback and - * other objects. This helps to prevent (bad) application code - * from accidentally holding onto extraneous garbage. - */ -public void dispose () { - if (object == null) return; - unbind (this); - object = method = signature = null; - address = 0; -} - -/** - * Returns the address of a block of machine code which will - * invoke the callback represented by the receiver. - * - * @return the callback address - */ -public int /*long*/ getAddress () { - return address; -} - -/** - * Returns the SWT platform name. - * - * @return the platform name of the currently running SWT - */ -public static native String getPlatform (); - -/** - * Returns the number of times the system has been recursively entered - * through a callback. - * <p> - * Note: This should not be called by application code. - * </p> - * - * @return the entry count - * - * @since 2.1 - */ -public static native int getEntryCount (); - -static String getSignature(int argCount) { - String signature = "("; //$NON-NLS-1$ - for (int i = 0; i < argCount; i++) signature += PTR_SIGNATURE; - signature += ")" + PTR_SIGNATURE; //$NON-NLS-1$ - return signature; -} - -/** - * Indicates whether or not callbacks which are triggered at the - * native level should cause the messages described by the matching - * <code>Callback</code> objects to be invoked. This method is used - * to safely shut down SWT when it is run within environments - * which can generate spurious events. - * <p> - * Note: This should not be called by application code. - * </p> - * - * @param enable true if callbacks should be invoked - */ -public static final native synchronized void setEnabled (boolean enable); - -/** - * Returns whether or not callbacks which are triggered at the - * native level should cause the messages described by the matching - * <code>Callback</code> objects to be invoked. This method is used - * to safely shut down SWT when it is run within environments - * which can generate spurious events. - * <p> - * Note: This should not be called by application code. - * </p> - * - * @return true if callbacks should not be invoked - */ -public static final native synchronized boolean getEnabled (); - -/** - * This might be called directly from native code in environments - * which can generate spurious events. Check before removing it. - * - * @deprecated - * - * @param ignore true if callbacks should not be invoked - */ -static final void ignoreCallbacks (boolean ignore) { - setEnabled (!ignore); -} - -/** - * Immediately wipes out all native level state associated - * with <em>all</em> callbacks. - * <p> - * <b>WARNING:</b> This operation is <em>extremely</em> dangerous, - * and should never be performed by application code. - * </p> - */ -public static final native synchronized void reset (); - -/** - * Releases the native level resources associated with the callback. - * - * @see #dispose - */ -static final native synchronized void unbind (Callback callback); - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java deleted file mode 100755 index 074b038bb5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import java.io.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Abstract factory class for loading/unloading images from files or streams - * in various image file formats. - * - */ -public abstract class FileFormat { - static final String FORMAT_PACKAGE = "org.eclipse.swt.internal.image"; //$NON-NLS-1$ - static final String FORMAT_SUFFIX = "FileFormat"; //$NON-NLS-1$ - static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG", "PNG", "TIFF", "OS2BMP"}; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$//$NON-NLS-7$//$NON-NLS-8$ - - LEDataInputStream inputStream; - LEDataOutputStream outputStream; - ImageLoader loader; - int compression; - -/** - * Return whether or not the specified input stream - * represents a supported file format. - */ -abstract boolean isFileFormat(LEDataInputStream stream); - -abstract ImageData[] loadFromByteStream(); - -/** - * Read the specified input stream, and return the - * device independent image array represented by the stream. - */ -public ImageData[] loadFromStream(LEDataInputStream stream) { - try { - inputStream = stream; - return loadFromByteStream(); - } catch (Exception e) { - if (e instanceof IOException) { - SWT.error(SWT.ERROR_IO, e); - } else { - SWT.error(SWT.ERROR_INVALID_IMAGE, e); - } - return null; - } -} - -/** - * Read the specified input stream using the specified loader, and - * return the device independent image array represented by the stream. - */ -public static ImageData[] load(InputStream is, ImageLoader loader) { - FileFormat fileFormat = null; - LEDataInputStream stream = new LEDataInputStream(is); - boolean isSupported = false; - for (int i = 1; i < FORMATS.length; i++) { - if (FORMATS[i] != null) { - try { - Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[i] + FORMAT_SUFFIX); - fileFormat = (FileFormat) clazz.newInstance(); - if (fileFormat.isFileFormat(stream)) { - isSupported = true; - break; - } - } catch (ClassNotFoundException e) { - FORMATS[i] = null; - } catch (Exception e) { - } - } - } - if (!isSupported) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - fileFormat.loader = loader; - return fileFormat.loadFromStream(stream); -} - -/** - * Write the device independent image array stored in the specified loader - * to the specified output stream using the specified file format. - */ -public static void save(OutputStream os, int format, ImageLoader loader) { - if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - - LEDataOutputStream stream = new LEDataOutputStream(os); - FileFormat fileFormat = null; - try { - Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX); - fileFormat = (FileFormat) clazz.newInstance(); - } catch (Exception e) { - SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - } - if (format == SWT.IMAGE_BMP_RLE) { - switch (loader.data[0].depth) { - case 8: fileFormat.compression = 1; break; - case 4: fileFormat.compression = 2; break; - } - } - fileFormat.unloadIntoStream(loader, stream); -} - -abstract void unloadIntoByteStream(ImageLoader loader); - -/** - * Write the device independent image array stored in the specified loader - * to the specified output stream. - */ -public void unloadIntoStream(ImageLoader loader, LEDataOutputStream stream) { - try { - outputStream = stream; - unloadIntoByteStream(loader); - outputStream.flush(); - } catch (Exception e) { - try {outputStream.flush();} catch (Exception f) {} - SWT.error(SWT.ERROR_IO, e); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java deleted file mode 100755 index 583e7c0e99..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java +++ /dev/null @@ -1,612 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -public final class GIFFileFormat extends FileFormat { - String signature; - int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth; - int disposalMethod = 0; - int delayTime = 0; - int transparentPixel = -1; - int repeatCount = 1; - - static final int GIF_APPLICATION_EXTENSION_BLOCK_ID = 0xFF; - static final int GIF_GRAPHICS_CONTROL_BLOCK_ID = 0xF9; - static final int GIF_PLAIN_TEXT_BLOCK_ID = 0x01; - static final int GIF_COMMENT_BLOCK_ID = 0xFE; - static final int GIF_EXTENSION_BLOCK_ID = 0x21; - static final int GIF_IMAGE_BLOCK_ID = 0x2C; - static final int GIF_TRAILER_ID = 0x3B; - static final byte [] GIF89a = new byte[] { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a' }; - static final byte [] NETSCAPE2_0 = new byte[] { (byte)'N', (byte)'E', (byte)'T', (byte)'S', (byte)'C', (byte)'A', (byte)'P', (byte)'E', (byte)'2', (byte)'.', (byte)'0' }; - - /** - * Answer a palette containing numGrays - * shades of gray, ranging from black to white. - */ - static PaletteData grayRamp(int numGrays) { - int n = numGrays - 1; - RGB[] colors = new RGB[numGrays]; - for (int i = 0; i < numGrays; i++) { - int intensity = (byte)((i * 3) * 256 / n); - colors[i] = new RGB(intensity, intensity, intensity); - } - return new PaletteData(colors); - } - - boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] signature = new byte[3]; - stream.read(signature); - stream.unread(signature); - return signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F'; - } catch (Exception e) { - return false; - } - } - - /** - * Load the GIF image(s) stored in the input stream. - * Return an array of ImageData representing the image(s). - */ - ImageData[] loadFromByteStream() { - byte[] signature = new byte[3]; - byte[] versionBytes = new byte[3]; - byte[] block = new byte[7]; - try { - inputStream.read(signature); - if (!(signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F')) - SWT.error(SWT.ERROR_INVALID_IMAGE); - - inputStream.read(versionBytes); - - inputStream.read(block); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - screenWidth = (block[0] & 0xFF) | ((block[1] & 0xFF) << 8); - loader.logicalScreenWidth = screenWidth; - screenHeight = (block[2] & 0xFF) | ((block[3] & 0xFF) << 8); - loader.logicalScreenHeight = screenHeight; - byte bitField = block[4]; - backgroundPixel = block[5] & 0xFF; - //aspect = block[6] & 0xFF; - bitsPerPixel = ((bitField >> 4) & 0x07) + 1; - defaultDepth = (bitField & 0x7) + 1; - PaletteData palette = null; - if ((bitField & 0x80) != 0) { - // Global palette. - //sorted = (bitField & 0x8) != 0; - palette = readPalette(1 << defaultDepth); - } else { - // No global palette. - //sorted = false; - backgroundPixel = -1; - defaultDepth = bitsPerPixel; - } - loader.backgroundPixel = backgroundPixel; - - getExtensions(); - int id = readID(); - ImageData[] images = new ImageData[0]; - while (id == GIF_IMAGE_BLOCK_ID) { - ImageData image = readImageBlock(palette); - if (loader.hasListeners()) { - loader.notifyListeners(new ImageLoaderEvent(loader, image, 3, true)); - } - ImageData[] oldImages = images; - images = new ImageData[oldImages.length + 1]; - System.arraycopy(oldImages, 0, images, 0, oldImages.length); - images[images.length - 1] = image; - try { - /* Read the 0-byte terminator at the end of the image. */ - id = inputStream.read(); - if (id > 0) { - /* We read the terminator earlier. */ - inputStream.unread(new byte[] {(byte)id}); - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - getExtensions(); - id = readID(); - } - return images; - } - - /** - * Read and return the next block or extension identifier from the file. - */ - int readID() { - try { - return inputStream.read(); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return -1; - } - - /** - * Read extensions until an image descriptor appears. - * In the future, if we care about the extensions, they - * should be properly grouped with the image data before - * which they appeared. Right now, the interesting parts - * of some extensions are kept, but the rest is discarded. - * Throw an error if an error occurs. - */ - void getExtensions() { - int id = readID(); - while (id != GIF_IMAGE_BLOCK_ID && id != GIF_TRAILER_ID && id > 0) { - if (id == GIF_EXTENSION_BLOCK_ID) { - readExtension(); - } else { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - id = readID(); - } - if (id == GIF_IMAGE_BLOCK_ID || id == GIF_TRAILER_ID) { - try { - inputStream.unread(new byte[] {(byte)id}); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - } - - /** - * Read a control extension. - * Return the extension block data. - */ - byte[] readExtension() { - int extensionID = readID(); - if (extensionID == GIF_COMMENT_BLOCK_ID) - return readCommentExtension(); - if (extensionID == GIF_PLAIN_TEXT_BLOCK_ID) - return readPlainTextExtension(); - if (extensionID == GIF_GRAPHICS_CONTROL_BLOCK_ID) - return readGraphicsControlExtension(); - if (extensionID == GIF_APPLICATION_EXTENSION_BLOCK_ID) - return readApplicationExtension(); - // Otherwise, we don't recognize the block. If the - // field size is correct, we can just skip over - // the block contents. - try { - int extSize = inputStream.read(); - if (extSize < 0) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - byte[] ext = new byte[extSize]; - inputStream.read(ext, 0, extSize); - return ext; - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - return null; - } - } - - /** - * We have just read the Comment extension identifier - * from the input stream. Read in the rest of the comment - * and return it. GIF comment blocks are variable size. - */ - byte[] readCommentExtension() { - try { - byte[] comment = new byte[0]; - byte[] block = new byte[255]; - int size = inputStream.read(); - while ((size > 0) && (inputStream.read(block, 0, size) != -1)) { - byte[] oldComment = comment; - comment = new byte[oldComment.length + size]; - System.arraycopy(oldComment, 0, comment, 0, oldComment.length); - System.arraycopy(block, 0, comment, oldComment.length, size); - size = inputStream.read(); - } - return comment; - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - return null; - } - } - - /** - * We have just read the PlainText extension identifier - * from the input stream. Read in the plain text info and text, - * and return the text. GIF plain text blocks are variable size. - */ - byte[] readPlainTextExtension() { - try { - // Read size of block = 0x0C. - inputStream.read(); - // Read the text information (x, y, width, height, colors). - byte[] info = new byte[12]; - inputStream.read(info); - // Read the text. - byte[] text = new byte[0]; - byte[] block = new byte[255]; - int size = inputStream.read(); - while ((size > 0) && (inputStream.read(block, 0, size) != -1)) { - byte[] oldText = text; - text = new byte[oldText.length + size]; - System.arraycopy(oldText, 0, text, 0, oldText.length); - System.arraycopy(block, 0, text, oldText.length, size); - size = inputStream.read(); - } - return text; - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - return null; - } - } - - /** - * We have just read the GraphicsControl extension identifier - * from the input stream. Read in the control information, store - * it, and return it. - */ - byte[] readGraphicsControlExtension() { - try { - // Read size of block = 0x04. - inputStream.read(); - // Read the control block. - byte[] controlBlock = new byte[4]; - inputStream.read(controlBlock); - byte bitField = controlBlock[0]; - // Store the user input field. - //userInput = (bitField & 0x02) != 0; - // Store the disposal method. - disposalMethod = (bitField >> 2) & 0x07; - // Store the delay time. - delayTime = (controlBlock[1] & 0xFF) | ((controlBlock[2] & 0xFF) << 8); - // Store the transparent color. - if ((bitField & 0x01) != 0) { - transparentPixel = controlBlock[3] & 0xFF; - } else { - transparentPixel = -1; - } - // Read block terminator. - inputStream.read(); - return controlBlock; - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - return null; - } - } - - /** - * We have just read the Application extension identifier - * from the input stream. Read in the rest of the extension, - * look for and store 'number of repeats', and return the data. - */ - byte[] readApplicationExtension() { - try { - // Read block data. - int blockSize = inputStream.read(); - byte[] blockData = new byte[blockSize]; - inputStream.read(blockData); - // Read application data. - byte[] data = new byte[0]; - byte[] block = new byte[255]; - int size = inputStream.read(); - while ((size > 0) && (inputStream.read(block, 0, size) != -1)) { - byte[] oldData = data; - data = new byte[oldData.length + size]; - System.arraycopy(oldData, 0, data, 0, oldData.length); - System.arraycopy(block, 0, data, oldData.length, size); - size = inputStream.read(); - } - // Look for the NETSCAPE 'repeat count' field for an animated GIF. - boolean netscape = - blockSize > 7 && - blockData[0] == 'N' && - blockData[1] == 'E' && - blockData[2] == 'T' && - blockData[3] == 'S' && - blockData[4] == 'C' && - blockData[5] == 'A' && - blockData[6] == 'P' && - blockData[7] == 'E'; - boolean authentic = - blockSize > 10 && - blockData[8] == '2' && - blockData[9] == '.' && - blockData[10] == '0'; - if (netscape && authentic && data[0] == 01) { //$NON-NLS-1$ //$NON-NLS-2$ - repeatCount = (data[1] & 0xFF) | ((data[2] & 0xFF) << 8); - loader.repeatCount = repeatCount; - } - return data; - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - return null; - } - } - - /** - * Return a DeviceIndependentImage representing the - * image block at the current position in the input stream. - * Throw an error if an error occurs. - */ - ImageData readImageBlock(PaletteData defaultPalette) { - int depth; - PaletteData palette; - byte[] block = new byte[9]; - try { - inputStream.read(block); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - int left = (block[0] & 0xFF) | ((block[1] & 0xFF) << 8); - int top = (block[2] & 0xFF) | ((block[3] & 0xFF) << 8); - int width = (block[4] & 0xFF) | ((block[5] & 0xFF) << 8); - int height = (block[6] & 0xFF) | ((block[7] & 0xFF) << 8); - byte bitField = block[8]; - boolean interlaced = (bitField & 0x40) != 0; - //boolean sorted = (bitField & 0x20) != 0; - if ((bitField & 0x80) != 0) { - // Local palette. - depth = (bitField & 0x7) + 1; - palette = readPalette(1 << depth); - } else { - // No local palette. - depth = defaultDepth; - palette = defaultPalette; - } - /* Work around: Ignore the case where a GIF specifies an - * invalid index for the transparent pixel that is larger - * than the number of entries in the palette. */ - if (transparentPixel > 1 << depth) { - transparentPixel = -1; - } - // Promote depth to next highest supported value. - if (!(depth == 1 || depth == 4 || depth == 8)) { - if (depth < 4) - depth = 4; - else - depth = 8; - } - if (palette == null) { - palette = grayRamp(1 << depth); - } - int initialCodeSize = -1; - try { - initialCodeSize = inputStream.read(); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - if (initialCodeSize < 0) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - ImageData image = ImageData.internal_new( - width, - height, - depth, - palette, - 4, - null, - 0, - null, - null, - -1, - transparentPixel, - SWT.IMAGE_GIF, - left, - top, - disposalMethod, - delayTime); - LZWCodec codec = new LZWCodec(); - codec.decode(inputStream, loader, image, interlaced, initialCodeSize); - return image; - } - - /** - * Read a palette from the input stream. - */ - PaletteData readPalette(int numColors) { - byte[] bytes = new byte[numColors * 3]; - try { - if (inputStream.read(bytes) != bytes.length) - SWT.error(SWT.ERROR_INVALID_IMAGE); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - RGB[] colors = new RGB[numColors]; - for (int i = 0; i < numColors; i++) - colors[i] = new RGB(bytes[i*3] & 0xFF, - bytes[i*3+1] & 0xFF, bytes[i*3+2] & 0xFF); - return new PaletteData(colors); - } - - void unloadIntoByteStream(ImageLoader loader) { - - /* Step 1: Acquire GIF parameters. */ - ImageData[] data = loader.data; - int frameCount = data.length; - boolean multi = frameCount > 1; - ImageData firstImage = data[0]; - int logicalScreenWidth = multi ? loader.logicalScreenWidth : firstImage.width; - int logicalScreenHeight = multi ? loader.logicalScreenHeight : firstImage.height; - int backgroundPixel = loader.backgroundPixel; - int depth = firstImage.depth; - PaletteData palette = firstImage.palette; - RGB[] colors = palette.getRGBs(); - short globalTable = 1; - - /* Step 2: Check for validity and global/local color map. */ - if (!(depth == 1 || depth == 4 || depth == 8)) { - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - } - for (int i=0; i<frameCount; i++) { - if (data[i].palette.isDirect) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - if (multi) { - if (!(data[i].height <= logicalScreenHeight && data[i].width <= logicalScreenWidth && data[i].depth == depth)) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - if (globalTable == 1) { - RGB rgbs[] = data[i].palette.getRGBs(); - if (rgbs.length != colors.length) { - globalTable = 0; - } else { - for (int j=0; j<colors.length; j++) { - if (!(rgbs[j].red == colors[j].red && - rgbs[j].green == colors[j].green && - rgbs[j].blue == colors[j].blue)) - globalTable = 0; - } - } - } - } - } - - try { - /* Step 3: Write the GIF89a Header and Logical Screen Descriptor. */ - outputStream.write(GIF89a); - int bitField = globalTable*128 + (depth-1)*16 + depth-1; - outputStream.writeShort((short)logicalScreenWidth); - outputStream.writeShort((short)logicalScreenHeight); - outputStream.write(bitField); - outputStream.write(backgroundPixel); - outputStream.write(0); // Aspect ratio is 1:1 - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - - /* Step 4: Write Global Color Table if applicable. */ - if (globalTable == 1) { - writePalette(palette, depth); - } - - /* Step 5: Write Application Extension if applicable. */ - if (multi) { - int repeatCount = loader.repeatCount; - try { - outputStream.write(GIF_EXTENSION_BLOCK_ID); - outputStream.write(GIF_APPLICATION_EXTENSION_BLOCK_ID); - outputStream.write(NETSCAPE2_0.length); - outputStream.write(NETSCAPE2_0); - outputStream.write(3); // Three bytes follow - outputStream.write(1); // Extension type - outputStream.writeShort((short) repeatCount); - outputStream.write(0); // Block terminator - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - for (int frame=0; frame<frameCount; frame++) { - - /* Step 6: Write Graphics Control Block for each frame if applicable. */ - if (multi || data[frame].transparentPixel != -1) { - writeGraphicsControlBlock(data[frame]); - } - - /* Step 7: Write Image Header for each frame. */ - int x = data[frame].x; - int y = data[frame].y; - int width = data[frame].width; - int height = data[frame].height; - try { - outputStream.write(GIF_IMAGE_BLOCK_ID); - byte[] block = new byte[9]; - block[0] = (byte)(x & 0xFF); - block[1] = (byte)((x >> 8) & 0xFF); - block[2] = (byte)(y & 0xFF); - block[3] = (byte)((y >> 8) & 0xFF); - block[4] = (byte)(width & 0xFF); - block[5] = (byte)((width >> 8) & 0xFF); - block[6] = (byte)(height & 0xFF); - block[7] = (byte)((height >> 8) & 0xFF); - block[8] = (byte)(globalTable == 0 ? (depth-1) | 0x80 : 0x00); - outputStream.write(block); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - - /* Step 8: Write Local Color Table for each frame if applicable. */ - if (globalTable == 0) { - writePalette(data[frame].palette, depth); - } - - /* Step 9: Write the actual data for each frame. */ - try { - outputStream.write(depth); // Minimum LZW Code size - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - new LZWCodec().encode(outputStream, data[frame]); - } - - /* Step 10: Write GIF terminator. */ - try { - outputStream.write(0x3B); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - /** - * Write out a GraphicsControlBlock to describe - * the specified device independent image. - */ - void writeGraphicsControlBlock(ImageData image) { - try { - outputStream.write(GIF_EXTENSION_BLOCK_ID); - outputStream.write(GIF_GRAPHICS_CONTROL_BLOCK_ID); - byte[] gcBlock = new byte[4]; - gcBlock[0] = 0; - gcBlock[1] = 0; - gcBlock[2] = 0; - gcBlock[3] = 0; - if (image.transparentPixel != -1) { - gcBlock[0] = (byte)0x01; - gcBlock[3] = (byte)image.transparentPixel; - } - if (image.disposalMethod != 0) { - gcBlock[0] |= (byte)((image.disposalMethod & 0x07) << 2); - } - if (image.delayTime != 0) { - gcBlock[1] = (byte)(image.delayTime & 0xFF); - gcBlock[2] = (byte)((image.delayTime >> 8) & 0xFF); - } - outputStream.write((byte)gcBlock.length); - outputStream.write(gcBlock); - outputStream.write(0); // Block terminator - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - /** - * Write the specified palette to the output stream. - */ - void writePalette(PaletteData palette, int depth) { - byte[] bytes = new byte[(1 << depth) * 3]; - int offset = 0; - for (int i = 0; i < palette.colors.length; i++) { - RGB color = palette.colors[i]; - bytes[offset] = (byte)color.red; - bytes[offset + 1] = (byte)color.green; - bytes[offset + 2] = (byte)color.blue; - offset += 3; - } - try { - outputStream.write(bytes); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java deleted file mode 100755 index 37160a220b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGAppn extends JPEGVariableSizeSegment { - - public JPEGAppn(byte[] reference) { - super(reference); - } - - public JPEGAppn(LEDataInputStream byteStream) { - super(byteStream); - } - - public boolean verify() { - int marker = getSegmentMarker(); - return marker >= JPEGFileFormat.APP0 && marker <= JPEGFileFormat.APP15; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java deleted file mode 100755 index b8c8392e1e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGArithmeticConditioningTable extends JPEGVariableSizeSegment { - - public JPEGArithmeticConditioningTable(LEDataInputStream byteStream) { - super(byteStream); - } - - public int signature() { - return JPEGFileFormat.DAC; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java deleted file mode 100755 index 21070f16ea..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGComment extends JPEGVariableSizeSegment { - - public JPEGComment(byte[] reference) { - super(reference); - } - - public JPEGComment(LEDataInputStream byteStream) { - super(byteStream); - } - - public int signature() { - return JPEGFileFormat.COM; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java deleted file mode 100644 index 54d6daa793..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java +++ /dev/null @@ -1,6355 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -public class JPEGDecoder { - - static final int DCTSIZE = 8; - static final int DCTSIZE2 = 64; - static final int NUM_QUANT_TBLS = 4; - static final int NUM_HUFF_TBLS = 4; - static final int NUM_ARITH_TBLS = 16; - static final int MAX_COMPS_IN_SCAN = 4; - static final int MAX_COMPONENTS = 10; - static final int MAX_SAMP_FACTOR = 4; - static final int D_MAX_BLOCKS_IN_MCU = 10; - static final int HUFF_LOOKAHEAD = 8; - static final int MAX_Q_COMPS = 4; - static final int IFAST_SCALE_BITS = 2; - static final int MAXJSAMPLE = 255; - static final int CENTERJSAMPLE = 128; - static final int MIN_GET_BITS = 32-7; - static final int INPUT_BUFFER_SIZE = 4096; - - static final int SCALEBITS = 16; /* speediest right-shift on some machines */ - static final int ONE_HALF = 1 << (SCALEBITS-1); - - static final int RGB_RED = 2; /* Offset of Red in an RGB scanline element */ - static final int RGB_GREEN = 1; /* Offset of Green */ - static final int RGB_BLUE = 0; /* Offset of Blue */ - static final int RGB_PIXELSIZE = 3; - - static final int JBUF_PASS_THRU = 0; - static final int JBUF_SAVE_SOURCE = 1; /* Run source subobject only, save output */ - static final int JBUF_CRANK_DEST = 2; /* Run dest subobject only, using saved data */ - static final int JBUF_SAVE_AND_PASS = 3; - - static final int JPEG_MAX_DIMENSION = 65500; - static final int BITS_IN_JSAMPLE = 8; - - static final int JDITHER_NONE = 0; /* no dithering */ - static final int JDITHER_ORDERED = 1; /* simple ordered dither */ - static final int JDITHER_FS = 2; - - static final int JDCT_ISLOW = 0; /* slow but accurate integer algorithm */ - static final int JDCT_IFAST = 1; /* faster, less accurate integer method */ - static final int JDCT_FLOAT = 2; /* floating-point: accurate, fast on fast HW */ - static final int JDCT_DEFAULT = JDCT_ISLOW; - - static final int JCS_UNKNOWN = 0; /* error/unspecified */ - static final int JCS_GRAYSCALE = 1; /* monochrome */ - static final int JCS_RGB = 2; /* red/green/blue */ - static final int JCS_YCbCr = 3; /* Y/Cb/Cr (also known as YUV) */ - static final int JCS_CMYK = 4; /* C/M/Y/K */ - static final int JCS_YCCK = 5; /* Y/Cb/Cr/K */ - - static final int SAVED_COEFS = 6; - static final int Q01_POS = 1; - static final int Q10_POS = 8; - static final int Q20_POS = 16; - static final int Q11_POS = 9; - static final int Q02_POS = 2; - - static final int CTX_PREPARE_FOR_IMCU = 0; /* need to prepare for MCU row */ - static final int CTX_PROCESS_IMCU = 1; /* feeding iMCU to postprocessor */ - static final int CTX_POSTPONED_ROW = 2; /* feeding postponed row group */ - - static final int APP0_DATA_LEN = 14; /* Length of interesting data in APP0 */ - static final int APP14_DATA_LEN = 12; /* Length of interesting data in APP14 */ - static final int APPN_DATA_LEN = 14; /* Must be the largest of the above!! */ - - /* markers */ - static final int M_SOF0 = 0xc0; - static final int M_SOF1 = 0xc1; - static final int M_SOF2 = 0xc2; - static final int M_SOF3 = 0xc3; - static final int M_SOF5 = 0xc5; - static final int M_SOF6 = 0xc6; - static final int M_SOF7 = 0xc7; - static final int M_JPG = 0xc8; - static final int M_SOF9 = 0xc9; - static final int M_SOF10 = 0xca; - static final int M_SOF11 = 0xcb; - static final int M_SOF13 = 0xcd; - static final int M_SOF14 = 0xce; - static final int M_SOF15 = 0xcf; - static final int M_DHT = 0xc4; - static final int M_DAC = 0xcc; - static final int M_RST0 = 0xd0; - static final int M_RST1 = 0xd1; - static final int M_RST2 = 0xd2; - static final int M_RST3 = 0xd3; - static final int M_RST4 = 0xd4; - static final int M_RST5 = 0xd5; - static final int M_RST6 = 0xd6; - static final int M_RST7 = 0xd7; - static final int M_SOI = 0xd8; - static final int M_EOI = 0xd9; - static final int M_SOS = 0xda; - static final int M_DQT = 0xdb; - static final int M_DNL = 0xdc; - static final int M_DRI = 0xdd; - static final int M_DHP = 0xde; - static final int M_EXP = 0xdf; - static final int M_APP0 = 0xe0; - static final int M_APP1 = 0xe1; - static final int M_APP2 = 0xe2; - static final int M_APP3 = 0xe3; - static final int M_APP4 = 0xe4; - static final int M_APP5 = 0xe5; - static final int M_APP6 = 0xe6; - static final int M_APP7 = 0xe7; - static final int M_APP8 = 0xe8; - static final int M_APP9 = 0xe9; - static final int M_APP10 = 0xea; - static final int M_APP11 = 0xeb; - static final int M_APP12 = 0xec; - static final int M_APP13 = 0xed; - static final int M_APP14 = 0xee; - static final int M_APP15 = 0xef; - static final int M_JPG0 = 0xf0; - static final int M_JPG13 = 0xfd; - static final int M_COM = 0xfe; - static final int M_TEM = 0x01; - static final int M_ERROR = 0x100; - - /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ - static final int CSTATE_START = 100; /* after create_compress */ - static final int CSTATE_SCANNING = 101; /* start_compress done, write_scanlines OK */ - static final int CSTATE_RAW_OK = 102; /* start_compress done, write_raw_data OK */ - static final int CSTATE_WRCOEFS = 103; /* jpeg_write_coefficients done */ - static final int DSTATE_START = 200; /* after create_decompress */ - static final int DSTATE_INHEADER = 201; /* reading header markers, no SOS yet */ - static final int DSTATE_READY = 202; /* found SOS, ready for start_decompress */ - static final int DSTATE_PRELOAD = 203; /* reading multiscan file in start_decompress*/ - static final int DSTATE_PRESCAN = 204; /* performing dummy pass for 2-pass quant */ - static final int DSTATE_SCANNING = 205; /* start_decompress done, read_scanlines OK */ - static final int DSTATE_RAW_OK = 206; /* start_decompress done, read_raw_data OK */ - static final int DSTATE_BUFIMAGE = 207; /* expecting jpeg_start_output */ - static final int DSTATE_BUFPOST = 208; /* looking for SOS/EOI in jpeg_finish_output */ - static final int DSTATE_RDCOEFS = 209; /* reading file in jpeg_read_coefficients */ - static final int DSTATE_STOPPING = 210; /* looking for EOI in jpeg_finish_decompress */ - - static final int JPEG_REACHED_SOS = 1; /* Reached start of new scan */ - static final int JPEG_REACHED_EOI = 2; /* Reached end of image */ - static final int JPEG_ROW_COMPLETED = 3; /* Completed one iMCU row */ - static final int JPEG_SCAN_COMPLETED = 4; /* Completed last iMCU row of a scan */ - - static final int JPEG_SUSPENDED = 0; /* Suspended due to lack of input data */ - static final int JPEG_HEADER_OK = 1; /* Found valid image datastream */ - static final int JPEG_HEADER_TABLES_ONLY = 2; /* Found valid table-specs-only datastream */ - - /* Function pointers */ - static final int DECOMPRESS_DATA = 0; - static final int DECOMPRESS_SMOOTH_DATA = 1; - static final int DECOMPRESS_ONEPASS = 2; - - static final int CONSUME_DATA = 0; - static final int DUMMY_CONSUME_DATA = 1; - - static final int PROCESS_DATA_SIMPLE_MAIN = 0; - static final int PROCESS_DATA_CONTEXT_MAIN = 1; - static final int PROCESS_DATA_CRANK_POST = 2; - - static final int POST_PROCESS_1PASS = 0; - static final int POST_PROCESS_DATA_UPSAMPLE = 1; - - static final int NULL_CONVERT = 0; - static final int GRAYSCALE_CONVERT = 1; - static final int YCC_RGB_CONVERT = 2; - static final int GRAY_RGB_CONVERT = 3; - static final int YCCK_CMYK_CONVERT = 4; - - static final int NOOP_UPSAMPLE = 0; - static final int FULLSIZE_UPSAMPLE = 1; - static final int H2V1_FANCY_UPSAMPLE = 2; - static final int H2V1_UPSAMPLE = 3; - static final int H2V2_FANCY_UPSAMPLE = 4; - static final int H2V2_UPSAMPLE = 5; - static final int INT_UPSAMPLE = 6; - - static final int INPUT_CONSUME_INPUT = 0; - static final int COEF_CONSUME_INPUT = 1; - - static int extend_test[] = /* entry n is 2**(n-1) */ - { - 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, - 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 - }; - - static int extend_offset[] = /* entry n is (-1 << n) + 1 */ - { - 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, - ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, - ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, - ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 - }; - - static int jpeg_natural_order[] = { - 0, 1, 8, 16, 9, 2, 3, 10, - 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, - 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, - 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, - 53, 60, 61, 54, 47, 55, 62, 63, - 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ - 63, 63, 63, 63, 63, 63, 63, 63 - }; - - static final class JQUANT_TBL { - /* This array gives the coefficient quantizers in natural array order - * (not the zigzag order in which they are stored in a JPEG DQT marker). - * CAUTION: IJG versions prior to v6a kept this array in zigzag order. - */ - short[] quantval = new short[DCTSIZE2]; /* quantization step for each coefficient */ - /* This field is used only during compression. It's initialized false when - * the table is created, and set true when it's been output to the file. - * You could suppress output of a table by setting this to true. - * (See jpeg_suppress_tables for an example.) - */ - boolean sent_table; /* true when table has been output */ - } - - static final class JHUFF_TBL { - /* These two fields directly represent the contents of a JPEG DHT marker */ - byte[] bits = new byte[17]; /* bits[k] = # of symbols with codes of */ - /* length k bits; bits[0] is unused */ - byte[] huffval = new byte[256]; /* The symbols, in order of incr code length */ - /* This field is used only during compression. It's initialized false when - * the table is created, and set true when it's been output to the file. - * You could suppress output of a table by setting this to true. - * (See jpeg_suppress_tables for an example.) - */ - boolean sent_table; /* true when table has been output */ - } - - static final class bitread_perm_state { /* Bitreading state saved across MCUs */ - int get_buffer; /* current bit-extraction buffer */ - int bits_left; /* # of unused bits in it */ - } - - static final class bitread_working_state { /* Bitreading working state within an MCU */ - /* Current data source location */ - /* We need a copy, rather than munging the original, in case of suspension */ - byte[] buffer; /* => next byte to read from source */ - int bytes_offset; - int bytes_in_buffer; /* # of bytes remaining in source buffer */ - /* Bit input buffer --- note these values are kept in register variables, - * not in this struct, inside the inner loops. - */ - int get_buffer; /* current bit-extraction buffer */ - int bits_left; /* # of unused bits in it */ - /* Pointer needed by jpeg_fill_bit_buffer. */ - jpeg_decompress_struct cinfo; /* back link to decompress master record */ - } - - static final class savable_state { - int EOBRUN; //Note that this is only used in the progressive case - int[] last_dc_val = new int[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ - } - - static final class d_derived_tbl { - /* Basic tables: (element [0] of each array is unused) */ - int[] maxcode = new int[18]; /* largest code of length k (-1 if none) */ - /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ - int[] valoffset = new int[17]; /* huffval[] offset for codes of length k */ - /* valoffset[k] = huffval[] index of 1st symbol of code length k, less - * the smallest code of length k; so given a code of length k, the - * corresponding symbol is huffval[code + valoffset[k]] - */ - - /* Link to public Huffman table (needed only in jpeg_huff_decode) */ - JHUFF_TBL pub; - - /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of - * the input data stream. If the next Huffman code is no more - * than HUFF_LOOKAHEAD bits long, we can obtain its length and - * the corresponding symbol directly from these tables. - */ - int[] look_nbits = new int[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */ - byte[] look_sym = new byte[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */ - } - - static final class jpeg_d_coef_controller { - int consume_data; - int decompress_data; - - /* Pointer to array of coefficient virtual arrays, or null if none */ - short[][][] coef_arrays; - - /* These variables keep track of the current location of the input side. */ - /* cinfo.input_iMCU_row is also used for this. */ - int MCU_ctr; /* counts MCUs processed in current row */ - int MCU_vert_offset; /* counts MCU rows within iMCU row */ - int MCU_rows_per_iMCU_row; /* number of such rows needed */ - - /* The output side's location is represented by cinfo.output_iMCU_row. */ - - /* In single-pass modes, it's sufficient to buffer just one MCU. - * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks, - * and let the entropy decoder write into that workspace each time. - * (On 80x86, the workspace is FAR even though it's not really very big; - * this is to keep the module interfaces unchanged when a large coefficient - * buffer is necessary.) - * In multi-pass modes, this array points to the current MCU's blocks - * within the virtual arrays; it is used only by the input side. - */ - short[][] MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][]; - - /* In multi-pass modes, we need a virtual block array for each component. */ - short[][][][] whole_image = new short[MAX_COMPONENTS][][][]; - - /* When doing block smoothing, we latch coefficient Al values here */ - int[] coef_bits_latch; - - short[] workspace; - - void start_input_pass (jpeg_decompress_struct cinfo) { - cinfo.input_iMCU_row = 0; - start_iMCU_row(cinfo); - } - - /* Reset within-iMCU-row counters for a new row (input side) */ - void start_iMCU_row (jpeg_decompress_struct cinfo) { - jpeg_d_coef_controller coef = cinfo.coef; - - /* In an interleaved scan, an MCU row is the same as an iMCU row. - * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. - * But at the bottom of the image, process only what's left. - */ - if (cinfo.comps_in_scan > 1) { - coef.MCU_rows_per_iMCU_row = 1; - } else { - if (cinfo.input_iMCU_row < (cinfo.total_iMCU_rows-1)) - coef.MCU_rows_per_iMCU_row = cinfo.cur_comp_info[0].v_samp_factor; - else - coef.MCU_rows_per_iMCU_row = cinfo.cur_comp_info[0].last_row_height; - } - - coef.MCU_ctr = 0; - coef.MCU_vert_offset = 0; - } - - } - - static abstract class jpeg_entropy_decoder { - abstract void start_pass (jpeg_decompress_struct cinfo); - abstract boolean decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data); - - /* This is here to share code between baseline and progressive decoders; */ - /* other modules probably should not use it */ - boolean insufficient_data; /* set true after emitting warning */ - - bitread_working_state br_state_local = new bitread_working_state(); - savable_state state_local = new savable_state(); - } - - static final class huff_entropy_decoder extends jpeg_entropy_decoder { - bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */ - savable_state saved = new savable_state(); /* Other state at start of MCU */ - - /* These fields are NOT loaded into local working state. */ - int restarts_to_go; /* MCUs left in this restart interval */ - - /* Pointers to derived tables (these workspaces have image lifespan) */ - d_derived_tbl[] dc_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS]; - d_derived_tbl[] ac_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS]; - - /* Precalculated info set up by start_pass for use in decode_mcu: */ - - /* Pointers to derived tables to be used for each block within an MCU */ - d_derived_tbl[] dc_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU]; - d_derived_tbl[] ac_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU]; - /* Whether we care about the DC and AC coefficient values for each block */ - boolean[] dc_needed = new boolean[D_MAX_BLOCKS_IN_MCU]; - boolean[] ac_needed = new boolean[D_MAX_BLOCKS_IN_MCU]; - - void start_pass (jpeg_decompress_struct cinfo) { - start_pass_huff_decoder(cinfo); - } - - boolean decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) { - huff_entropy_decoder entropy = this; - int blkn; -// BITREAD_STATE_VARS; - int get_buffer; - int bits_left; -// bitread_working_state br_state = new bitread_working_state(); -// savable_state state = new savable_state(); - bitread_working_state br_state = br_state_local; - savable_state state = state_local; - - /* Process restart marker if needed; may have to suspend */ - if (cinfo.restart_interval != 0) { - if (entropy.restarts_to_go == 0) - if (! process_restart(cinfo)) - return false; - } - - /* If we've run out of data, just leave the MCU set to zeroes. - * This way, we return uniform gray for the remainder of the segment. - */ - if (! entropy.insufficient_data) { - - /* Load up working state */ -// BITREAD_LOAD_STATE(cinfo,entropy.bitstate); - br_state.cinfo = cinfo; - br_state.buffer = cinfo.buffer; - br_state.bytes_in_buffer = cinfo.bytes_in_buffer; - br_state.bytes_offset = cinfo.bytes_offset; - get_buffer = entropy.bitstate.get_buffer; - bits_left = entropy.bitstate.bits_left; - -// ASSIGN_STATE(state, entropy.saved); - state.last_dc_val[0] = entropy.saved.last_dc_val[0]; - state.last_dc_val[1] = entropy.saved.last_dc_val[1]; - state.last_dc_val[2] = entropy.saved.last_dc_val[2]; - state.last_dc_val[3] = entropy.saved.last_dc_val[3]; - - /* Outer loop handles each block in the MCU */ - - for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { - short[] block = MCU_data[blkn]; - d_derived_tbl dctbl = entropy.dc_cur_tbls[blkn]; - d_derived_tbl actbl = entropy.ac_cur_tbls[blkn]; - int s = 0, k, r; - - /* Decode a single block's worth of coefficients */ - - /* Section F.2.2.1: decode the DC coefficient difference */ -// HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); - { - int nb = 0, look; - if (bits_left < HUFF_LOOKAHEAD) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - if (bits_left < HUFF_LOOKAHEAD) { - nb = 1; -// goto slowlabel; - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,dctbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } -// look = PEEK_BITS(HUFF_LOOKAHEAD); - if (nb != 1) { - look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); - if ((nb = dctbl.look_nbits[look]) != 0) { -// DROP_BITS(nb); - bits_left -= nb; - s = dctbl.look_sym[look] & 0xFF; - } else { - nb = HUFF_LOOKAHEAD+1; -// slowlabel: - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,dctbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - } - - if (s != 0) { -// CHECK_BIT_BUFFER(br_state, s, return FALSE); - { - if (bits_left < (s)) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// r = GET_BITS(s); - r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); -// s = HUFF_EXTEND(r, s); - s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r)); - } - - if (entropy.dc_needed[blkn]) { - /* Convert DC difference to actual value, update last_dc_val */ - int ci = cinfo.MCU_membership[blkn]; - s += state.last_dc_val[ci]; - state.last_dc_val[ci] = s; - /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ - block[0] = (short) s; - } - - if (entropy.ac_needed[blkn]) { - - /* Section F.2.2.2: decode the AC coefficients */ - /* Since zeroes are skipped, output area must be cleared beforehand */ - for (k = 1; k < DCTSIZE2; k++) { -// HUFF_DECODE(s, br_state, actbl, return FALSE, label2); - { - int nb = 0, look; - if (bits_left < HUFF_LOOKAHEAD) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - if (bits_left < HUFF_LOOKAHEAD) { - nb = 1; -// goto slowlabel; - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - if (nb != 1) { -// look = PEEK_BITS(HUFF_LOOKAHEAD); - look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); - if ((nb = actbl.look_nbits[look]) != 0) { -// DROP_BITS(nb); - bits_left -= (nb); - s = actbl.look_sym[look] & 0xFF; - } else { - nb = HUFF_LOOKAHEAD+1; -// slowlabel: - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - } - r = s >> 4; - s &= 15; - - if (s != 0) { - k += r; -// CHECK_BIT_BUFFER(br_state, s, return FALSE); - { - if (bits_left < (s)) { - if (!jpeg_fill_bit_buffer(br_state, get_buffer, bits_left, s)) { - return false; - } - get_buffer = (br_state).get_buffer; - bits_left = (br_state).bits_left; - } - } -// r = GET_BITS(s); - r = (((get_buffer >> (bits_left -= (s)))) & ((1 << (s)) - 1)); -// s = HUFF_EXTEND(r, s); - s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r)); - /* - * Output coefficient in natural (dezigzagged) - * order. Note: the extra entries in - * jpeg_natural_order[] will save us if k >= - * DCTSIZE2, which could happen if the data is - * corrupted. - */ - block[jpeg_natural_order[k]] = (short) s; - } else { - if (r != 15) - break; - k += 15; - } - } - - } else { - - /* Section F.2.2.2: decode the AC coefficients */ - /* In this path we just discard the values */ - for (k = 1; k < DCTSIZE2; k++) { -// HUFF_DECODE(s, br_state, actbl, return FALSE, label3); - { - int nb = 0, look; - if (bits_left < HUFF_LOOKAHEAD) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - if (bits_left < HUFF_LOOKAHEAD) { - nb = 1; -// goto slowlabel; - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - if (nb != 1) { -// look = PEEK_BITS(HUFF_LOOKAHEAD); - look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); - if ((nb = actbl.look_nbits[look]) != 0) { -// DROP_BITS(nb); - bits_left -= (nb); - s = actbl.look_sym[look] & 0xFF; - } else { - nb = HUFF_LOOKAHEAD+1; -// slowlabel: - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - } - r = s >> 4; - s &= 15; - - if (s != 0) { - k += r; -// CHECK_BIT_BUFFER(br_state, s, return FALSE); - { - if (bits_left < (s)) { - if (!jpeg_fill_bit_buffer((br_state),get_buffer,bits_left,s)) { - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// DROP_BITS(s); - bits_left -= s; - } else { - if (r != 15) - break; - k += 15; - } - } - - } - } - - /* Completed MCU, so update state */ -// BITREAD_SAVE_STATE(cinfo,entropy.bitstate); - cinfo.buffer = br_state.buffer; - cinfo.bytes_in_buffer = br_state.bytes_in_buffer; - cinfo.bytes_offset = br_state.bytes_offset; - entropy.bitstate.get_buffer = get_buffer; - entropy.bitstate.bits_left = bits_left; -// ASSIGN_STATE(entropy.saved, state); - entropy.saved.last_dc_val[0] = state.last_dc_val[0]; - entropy.saved.last_dc_val[1] = state.last_dc_val[1]; - entropy.saved.last_dc_val[2] = state.last_dc_val[2]; - entropy.saved.last_dc_val[3] = state.last_dc_val[3]; - } - - /* Account for restart interval (no-op if not using restarts) */ - entropy.restarts_to_go--; - - return true; - } - - void start_pass_huff_decoder (jpeg_decompress_struct cinfo) { - huff_entropy_decoder entropy = this; - int ci, blkn, dctbl, actbl; - jpeg_component_info compptr; - - /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. - * This ought to be an error condition, but we make it a warning because - * there are some baseline files out there with all zeroes in these bytes. - */ - if (cinfo.Ss != 0 || cinfo.Se != DCTSIZE2-1 || cinfo.Ah != 0 || cinfo.Al != 0) { -// WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); - } - - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - compptr = cinfo.cur_comp_info[ci]; - dctbl = compptr.dc_tbl_no; - actbl = compptr.ac_tbl_no; - /* Compute derived values for Huffman tables */ - /* We may do this more than once for a table, but it's not expensive */ - jpeg_make_d_derived_tbl(cinfo, true, dctbl, entropy.dc_derived_tbls[dctbl] = new d_derived_tbl()); - jpeg_make_d_derived_tbl(cinfo, false, actbl, entropy.ac_derived_tbls[actbl] = new d_derived_tbl()); - /* Initialize DC predictions to 0 */ - entropy.saved.last_dc_val[ci] = 0; - } - - /* Precalculate decoding info for each block in an MCU of this scan */ - for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { - ci = cinfo.MCU_membership[blkn]; - compptr = cinfo.cur_comp_info[ci]; - /* Precalculate which table to use for each block */ - entropy.dc_cur_tbls[blkn] = entropy.dc_derived_tbls[compptr.dc_tbl_no]; - entropy.ac_cur_tbls[blkn] = entropy.ac_derived_tbls[compptr.ac_tbl_no]; - /* Decide whether we really care about the coefficient values */ - if (compptr.component_needed) { - entropy.dc_needed[blkn] = true; - /* we don't need the ACs if producing a 1/8th-size image */ - entropy.ac_needed[blkn] = (compptr.DCT_scaled_size > 1); - } else { - entropy.dc_needed[blkn] = entropy.ac_needed[blkn] = false; - } - } - - /* Initialize bitread state variables */ - entropy.bitstate.bits_left = 0; - entropy.bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ - entropy.insufficient_data = false; - - /* Initialize restart counter */ - entropy.restarts_to_go = cinfo.restart_interval; - } - - boolean process_restart (jpeg_decompress_struct cinfo) { - huff_entropy_decoder entropy = this; - int ci; - - /* Throw away any unused bits remaining in bit buffer; */ - /* include any full bytes in next_marker's count of discarded bytes */ - cinfo.marker.discarded_bytes += entropy.bitstate.bits_left / 8; - entropy.bitstate.bits_left = 0; - - /* Advance past the RSTn marker */ - if (! read_restart_marker (cinfo)) - return false; - - /* Re-initialize DC predictions to 0 */ - for (ci = 0; ci < cinfo.comps_in_scan; ci++) - entropy.saved.last_dc_val[ci] = 0; - - /* Reset restart counter */ - entropy.restarts_to_go = cinfo.restart_interval; - - /* Reset out-of-data flag, unless read_restart_marker left us smack up - * against a marker. In that case we will end up treating the next data - * segment as empty, and we can avoid producing bogus output pixels by - * leaving the flag set. - */ - if (cinfo.unread_marker == 0) - entropy.insufficient_data = false; - - return true; - } - } - - static final class phuff_entropy_decoder extends jpeg_entropy_decoder { - - /* These fields are loaded into local variables at start of each MCU. - * In case of suspension, we exit WITHOUT updating them. - */ - bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */ - savable_state saved = new savable_state(); /* Other state at start of MCU */ - - /* These fields are NOT loaded into local working state. */ - int restarts_to_go; /* MCUs left in this restart interval */ - - /* Pointers to derived tables (these workspaces have image lifespan) */ - d_derived_tbl[] derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS]; - - d_derived_tbl ac_derived_tbl; /* active table during an AC scan */ - - int[] newnz_pos = new int[DCTSIZE2]; - - void start_pass (jpeg_decompress_struct cinfo) { - start_pass_phuff_decoder(cinfo); - } - - boolean decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) { - boolean is_DC_band = (cinfo.Ss == 0); - if (cinfo.Ah == 0) { - if (is_DC_band) - return decode_mcu_DC_first(cinfo, MCU_data); - else - return decode_mcu_AC_first(cinfo, MCU_data); - } else { - if (is_DC_band) - return decode_mcu_DC_refine(cinfo, MCU_data); - else - return decode_mcu_AC_refine(cinfo, MCU_data); - } - } - - boolean decode_mcu_DC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) { - phuff_entropy_decoder entropy = this; - int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */ - int blkn; - short[] block; -// BITREAD_STATE_VARS; - int get_buffer; - int bits_left; -// bitread_working_state br_state = new bitread_working_state(); - bitread_working_state br_state = br_state_local; - - /* Process restart marker if needed; may have to suspend */ - if (cinfo.restart_interval != 0) { - if (entropy.restarts_to_go == 0) - if (! process_restart(cinfo)) - return false; - } - - /* Not worth the cycles to check insufficient_data here, - * since we will not change the data anyway if we read zeroes. - */ - - /* Load up working state */ -// BITREAD_LOAD_STATE(cinfo,entropy.bitstate); - br_state.cinfo = cinfo; - br_state.buffer = cinfo.buffer; - br_state.bytes_in_buffer = cinfo.bytes_in_buffer; - br_state.bytes_offset = cinfo.bytes_offset; - get_buffer = entropy.bitstate.get_buffer; - bits_left = entropy.bitstate.bits_left; - - /* Outer loop handles each block in the MCU */ - - for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { - block = MCU_data[blkn]; - - /* Encoded data is simply the next bit of the two's-complement DC value */ -// CHECK_BIT_BUFFER(br_state, 1, return FALSE); - { - if (bits_left < (1)) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// if (GET_BITS(1)) - if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0) - block[0] |= p1; - /* Note: since we use |=, repeating the assignment later is safe */ - } - - /* Completed MCU, so update state */ -// BITREAD_SAVE_STATE(cinfo,entropy.bitstate); - cinfo.buffer = br_state.buffer; - cinfo.bytes_in_buffer = br_state.bytes_in_buffer; - cinfo.bytes_offset = br_state.bytes_offset; - entropy.bitstate.get_buffer = get_buffer; - entropy.bitstate.bits_left = bits_left; - - /* Account for restart interval (no-op if not using restarts) */ - entropy.restarts_to_go--; - - return true; - - } - - boolean decode_mcu_AC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) { - phuff_entropy_decoder entropy = this; - int Se = cinfo.Se; - int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */ - int m1 = (-1) << cinfo.Al; /* -1 in the bit position being coded */ - int s = 0, k, r; - int EOBRUN; - short[] block; - short[] thiscoef; -// BITREAD_STATE_VARS; - int get_buffer; - int bits_left; -// bitread_working_state br_state = new bitread_working_state(); - bitread_working_state br_state = br_state_local; - - d_derived_tbl tbl; - int num_newnz; - int[] newnz_pos = entropy.newnz_pos; - - /* Process restart marker if needed; may have to suspend */ - if (cinfo.restart_interval != 0) { - if (entropy.restarts_to_go == 0) - if (! process_restart(cinfo)) - return false; - } - - /* If we've run out of data, don't modify the MCU. - */ - if (! entropy.insufficient_data) { - - /* Load up working state */ -// BITREAD_LOAD_STATE(cinfo,entropy.bitstate); - br_state.cinfo = cinfo; - br_state.buffer = cinfo.buffer; - br_state.bytes_in_buffer = cinfo.bytes_in_buffer; - br_state.bytes_offset = cinfo.bytes_offset; - get_buffer = entropy.bitstate.get_buffer; - bits_left = entropy.bitstate.bits_left; - - EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */ - - /* There is always only one block per MCU */ - block = MCU_data[0]; - tbl = entropy.ac_derived_tbl; - - /* If we are forced to suspend, we must undo the assignments to any newly - * nonzero coefficients in the block, because otherwise we'd get confused - * next time about which coefficients were already nonzero. - * But we need not undo addition of bits to already-nonzero coefficients; - * instead, we can test the current bit to see if we already did it. - */ - num_newnz = 0; - - /* initialize coefficient loop counter to start of band */ - k = cinfo.Ss; - - if (EOBRUN == 0) { - for (; k <= Se; k++) { -// HUFF_DECODE(s, br_state, tbl, goto undoit, label3); - { - int nb = 0, look; - if (bits_left < HUFF_LOOKAHEAD) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - if (bits_left < HUFF_LOOKAHEAD) { - nb = 1; -// goto slowlabel; - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - if (nb != 1) { -// look = PEEK_BITS(HUFF_LOOKAHEAD); - look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); - if ((nb = tbl.look_nbits[look]) != 0) { -// DROP_BITS(nb); - bits_left -= nb; - s = tbl.look_sym[look] & 0xFF; - } else { - nb = HUFF_LOOKAHEAD+1; -// slowlabel: - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - } - r = s >> 4; - s &= 15; - if (s != 0) { - if (s != 1) { /* size of new coef should always be 1 */ -// WARNMS(cinfo, JWRN_HUFF_BAD_CODE); - } -// CHECK_BIT_BUFFER(br_state, 1, goto undoit); - { - if (bits_left < (1)) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// if (GET_BITS(1)) - if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0) - s = p1; /* newly nonzero coef is positive */ - else - s = m1; /* newly nonzero coef is negative */ - } else { - if (r != 15) { - EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */ - if (r != 0) { -// CHECK_BIT_BUFFER(br_state, r, goto undoit); - { - if (bits_left < (r)) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// r = GET_BITS(r); - r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1)); - EOBRUN += r; - } - break; /* rest of block is handled by EOB logic */ - } - /* note s = 0 for processing ZRL */ - } - /* Advance over already-nonzero coefs and r still-zero coefs, - * appending correction bits to the nonzeroes. A correction bit is 1 - * if the absolute value of the coefficient must be increased. - */ - do { - thiscoef = block; - int thiscoef_offset = jpeg_natural_order[k]; - if (thiscoef[thiscoef_offset] != 0) { -// CHECK_BIT_BUFFER(br_state, 1, goto undoit); - { - if (bits_left < (1)) { - if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// if (GET_BITS(1)) { - if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0) { - if ((thiscoef[thiscoef_offset] & p1) == 0) { /* do nothing if already set it */ - if (thiscoef[thiscoef_offset] >= 0) - thiscoef[thiscoef_offset] += p1; - else - thiscoef[thiscoef_offset] += m1; - } - } - } else { - if (--r < 0) - break; /* reached target zero coefficient */ - } - k++; - } while (k <= Se); - if (s != 0) { - int pos = jpeg_natural_order[k]; - /* Output newly nonzero coefficient */ - block[pos] = (short) s; - /* Remember its position in case we have to suspend */ - newnz_pos[num_newnz++] = pos; - } - } - } - - if (EOBRUN > 0) { - /* Scan any remaining coefficient positions after the end-of-band - * (the last newly nonzero coefficient, if any). Append a correction - * bit to each already-nonzero coefficient. A correction bit is 1 - * if the absolute value of the coefficient must be increased. - */ - for (; k <= Se; k++) { - thiscoef = block; - int thiscoef_offset = jpeg_natural_order[k]; - if (thiscoef[thiscoef_offset] != 0) { -// CHECK_BIT_BUFFER(br_state, 1, goto undoit); - { - if (bits_left < (1)) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { -// failaction; - while (num_newnz > 0) - block[newnz_pos[--num_newnz]] = 0; - - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// if (GET_BITS(1)) { - if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0) { - if ((thiscoef[thiscoef_offset] & p1) == 0) { /* do nothing if already changed it */ - if (thiscoef[thiscoef_offset] >= 0) - thiscoef[thiscoef_offset] += p1; - else - thiscoef[thiscoef_offset] += m1; - } - } - } - } - /* Count one block completed in EOB run */ - EOBRUN--; - } - - /* Completed MCU, so update state */ -// BITREAD_SAVE_STATE(cinfo,entropy.bitstate); - cinfo.buffer = br_state.buffer; - cinfo.bytes_in_buffer = br_state.bytes_in_buffer; - cinfo.bytes_offset = br_state.bytes_offset; - entropy.bitstate.get_buffer = get_buffer; - entropy.bitstate.bits_left = bits_left; - - entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */ - } - - /* Account for restart interval (no-op if not using restarts) */ - entropy.restarts_to_go--; - - return true; - -// undoit: -// /* Re-zero any output coefficients that we made newly nonzero */ -// while (num_newnz > 0) -// (*block)[newnz_pos[--num_newnz]] = 0; -// -// return false; - - } - - boolean decode_mcu_AC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) { - phuff_entropy_decoder entropy = this; - int Se = cinfo.Se; - int Al = cinfo.Al; - int s = 0, k, r; - int EOBRUN; - short[] block; -// BITREAD_STATE_VARS; - int get_buffer; - int bits_left; -// bitread_working_state br_state = new bitread_working_state(); - bitread_working_state br_state = br_state_local; - - d_derived_tbl tbl; - - /* Process restart marker if needed; may have to suspend */ - if (cinfo.restart_interval != 0) { - if (entropy.restarts_to_go == 0) - if (! process_restart(cinfo)) - return false; - } - - /* If we've run out of data, just leave the MCU set to zeroes. - * This way, we return uniform gray for the remainder of the segment. - */ - if (! entropy.insufficient_data) { - - /* Load up working state. - * We can avoid loading/saving bitread state if in an EOB run. - */ - EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */ - - /* There is always only one block per MCU */ - - if (EOBRUN > 0) /* if it's a band of zeroes... */ - EOBRUN--; /* ...process it now (we do nothing) */ - else { -// BITREAD_LOAD_STATE(cinfo,entropy.bitstate); - br_state.cinfo = cinfo; - br_state.buffer = cinfo.buffer; - br_state.bytes_in_buffer = cinfo.bytes_in_buffer; - br_state.bytes_offset = cinfo.bytes_offset; - get_buffer = entropy.bitstate.get_buffer; - bits_left = entropy.bitstate.bits_left; - - block = MCU_data[0]; - tbl = entropy.ac_derived_tbl; - - for (k = cinfo.Ss; k <= Se; k++) { -// HUFF_DECODE(s, br_state, tbl, return FALSE, label2); - { - int nb = 0, look; - if (bits_left < HUFF_LOOKAHEAD) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - if (bits_left < HUFF_LOOKAHEAD) { - nb = 1; -// goto slowlabel; - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - if (nb != 1) { -// look = PEEK_BITS(HUFF_LOOKAHEAD); - look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); - - if ((nb = tbl.look_nbits[look]) != 0) { -// DROP_BITS(nb); - bits_left -= nb; - s = tbl.look_sym[look] & 0xFF; - } else { - nb = HUFF_LOOKAHEAD+1; -// slowlabel: - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - } - r = s >> 4; - s &= 15; - if (s != 0) { - k += r; -// CHECK_BIT_BUFFER(br_state, s, return FALSE); - { - if (bits_left < (s)) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// r = GET_BITS(s); - r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); -// s = HUFF_EXTEND(r, s); - s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r)); - /* Scale and output coefficient in natural (dezigzagged) order */ - block[jpeg_natural_order[k]] = (short) (s << Al); - } else { - if (r == 15) { /* ZRL */ - k += 15; /* skip 15 zeroes in band */ - } else { /* EOBr, run length is 2^r + appended bits */ - EOBRUN = 1 << r; - if (r != 0) { /* EOBr, r > 0 */ -// CHECK_BIT_BUFFER(br_state, r, return FALSE); - { - if (bits_left < (r)) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) { - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// r = GET_BITS(r); - r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1)); - EOBRUN += r; - } - EOBRUN--; /* this band is processed at this moment */ - break; /* force end-of-band */ - } - } - } - -// BITREAD_SAVE_STATE(cinfo,entropy.bitstate); - cinfo.buffer = br_state.buffer; - cinfo.bytes_in_buffer = br_state.bytes_in_buffer; - cinfo.bytes_offset = br_state.bytes_offset; - entropy.bitstate.get_buffer = get_buffer; - entropy.bitstate.bits_left = bits_left; - } - - /* Completed MCU, so update state */ - entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */ - } - - /* Account for restart interval (no-op if not using restarts) */ - entropy.restarts_to_go--; - - return true; - } - - boolean decode_mcu_DC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) { - phuff_entropy_decoder entropy = this; - int Al = cinfo.Al; - int s = 0, r; - int blkn, ci; - short[] block; -// BITREAD_STATE_VARS; - int get_buffer; - int bits_left; -// bitread_working_state br_state = new bitread_working_state(); - bitread_working_state br_state = br_state_local; - -// savable_state state = new savable_state(); - savable_state state = state_local; - d_derived_tbl tbl; - jpeg_component_info compptr; - - /* Process restart marker if needed; may have to suspend */ - if (cinfo.restart_interval != 0) { - if (entropy.restarts_to_go == 0) - if (! process_restart(cinfo)) - return false; - } - - /* If we've run out of data, just leave the MCU set to zeroes. - * This way, we return uniform gray for the remainder of the segment. - */ - if (! entropy.insufficient_data) { - - /* Load up working state */ -// BITREAD_LOAD_STATE(cinfo,entropy.bitstate); - br_state.cinfo = cinfo; - br_state.buffer = cinfo.buffer; - br_state.bytes_in_buffer = cinfo.bytes_in_buffer; - br_state.bytes_offset = cinfo.bytes_offset; - get_buffer = entropy.bitstate.get_buffer; - bits_left = entropy.bitstate.bits_left; - -// ASSIGN_STATE(state, entropy.saved); - state.EOBRUN = entropy.saved.EOBRUN; - state.last_dc_val[0] = entropy.saved.last_dc_val[0]; - state.last_dc_val[1] = entropy.saved.last_dc_val[1]; - state.last_dc_val[2] = entropy.saved.last_dc_val[2]; - state.last_dc_val[3] = entropy.saved.last_dc_val[3]; - - /* Outer loop handles each block in the MCU */ - - for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { - block = MCU_data[blkn]; - ci = cinfo.MCU_membership[blkn]; - compptr = cinfo.cur_comp_info[ci]; - tbl = entropy.derived_tbls[compptr.dc_tbl_no]; - - /* Decode a single block's worth of coefficients */ - - /* Section F.2.2.1: decode the DC coefficient difference */ -// HUFF_DECODE(s, br_state, tbl, return FALSE, label1); - { - int nb = 0, look; - if (bits_left < HUFF_LOOKAHEAD) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - if (bits_left < HUFF_LOOKAHEAD) { - nb = 1; -// goto slowlabel; - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - if (nb != 1) { -// look = PEEK_BITS(HUFF_LOOKAHEAD); - look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); - - if ((nb = tbl.look_nbits[look]) != 0) { -// DROP_BITS(nb); - bits_left -= nb; - s = tbl.look_sym[look] & 0xFF; - } else { - nb = HUFF_LOOKAHEAD+1; -// slowlabel: - if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { - return false; - } - get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; - } - } - } - if (s != 0) { -// CHECK_BIT_BUFFER(br_state, s, return FALSE); - { - if (bits_left < (s)) { - if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { - return false; - } - get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; - } - } -// r = GET_BITS(s); - r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); -// s = HUFF_EXTEND(r, s); - s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r)); - } - - /* Convert DC difference to actual value, update last_dc_val */ - s += state.last_dc_val[ci]; - state.last_dc_val[ci] = s; - /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */ - block[0] = (short) (s << Al); - } - - /* Completed MCU, so update state */ -// BITREAD_SAVE_STATE(cinfo,entropy.bitstate); - cinfo.buffer = br_state.buffer; - cinfo.bytes_in_buffer = br_state.bytes_in_buffer; - cinfo.bytes_offset = br_state.bytes_offset; - entropy.bitstate.get_buffer = get_buffer; - entropy.bitstate.bits_left = bits_left; -// ASSIGN_STATE(entropy.saved, state); - entropy.saved.EOBRUN = state.EOBRUN; - entropy.saved.last_dc_val[0] = state.last_dc_val[0]; - entropy.saved.last_dc_val[1] = state.last_dc_val[1]; - entropy.saved.last_dc_val[2] = state.last_dc_val[2]; - entropy.saved.last_dc_val[3] = state.last_dc_val[3]; - } - - /* Account for restart interval (no-op if not using restarts) */ - entropy.restarts_to_go--; - - return true; - } - - boolean process_restart (jpeg_decompress_struct cinfo) { - phuff_entropy_decoder entropy = this; - int ci; - - /* Throw away any unused bits remaining in bit buffer; */ - /* include any full bytes in next_marker's count of discarded bytes */ - cinfo.marker.discarded_bytes += entropy.bitstate.bits_left / 8; - entropy.bitstate.bits_left = 0; - - /* Advance past the RSTn marker */ - if (! read_restart_marker (cinfo)) - return false; - - /* Re-initialize DC predictions to 0 */ - for (ci = 0; ci < cinfo.comps_in_scan; ci++) - entropy.saved.last_dc_val[ci] = 0; - /* Re-init EOB run count, too */ - entropy.saved.EOBRUN = 0; - - /* Reset restart counter */ - entropy.restarts_to_go = cinfo.restart_interval; - - /* Reset out-of-data flag, unless read_restart_marker left us smack up - * against a marker. In that case we will end up treating the next data - * segment as empty, and we can avoid producing bogus output pixels by - * leaving the flag set. - */ - if (cinfo.unread_marker == 0) - entropy.insufficient_data = false; - - return true; - } - - void start_pass_phuff_decoder (jpeg_decompress_struct cinfo) { - phuff_entropy_decoder entropy = this; - boolean is_DC_band, bad; - int ci, coefi, tbl; - int[] coef_bit_ptr; - jpeg_component_info compptr; - - is_DC_band = (cinfo.Ss == 0); - - /* Validate scan parameters */ - bad = false; - if (is_DC_band) { - if (cinfo.Se != 0) - bad = true; - } else { - /* need not check Ss/Se < 0 since they came from unsigned bytes */ - if (cinfo.Ss > cinfo.Se || cinfo.Se >= DCTSIZE2) - bad = true; - /* AC scans may have only one component */ - if (cinfo.comps_in_scan != 1) - bad = true; - } - if (cinfo.Ah != 0) { - /* Successive approximation refinement scan: must have Al = Ah-1. */ - if (cinfo.Al != cinfo.Ah-1) - bad = true; - } - if (cinfo.Al > 13) /* need not check for < 0 */ - bad = true; - /* Arguably the maximum Al value should be less than 13 for 8-bit precision, - * but the spec doesn't say so, and we try to be liberal about what we - * accept. Note: large Al values could result in out-of-range DC - * coefficients during early scans, leading to bizarre displays due to - * overflows in the IDCT math. But we won't crash. - */ - if (bad) - error(); -// ERREXIT4(cinfo, JERR_BAD_PROGRESSION, cinfo.Ss, cinfo.Se, cinfo.Ah, cinfo.Al); - /* Update progression status, and verify that scan order is legal. - * Note that inter-scan inconsistencies are treated as warnings - * not fatal errors ... not clear if this is right way to behave. - */ - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - int cindex = cinfo.cur_comp_info[ci].component_index; - coef_bit_ptr = cinfo.coef_bits[cindex]; - if (!is_DC_band && coef_bit_ptr[0] < 0) {/* AC without prior DC scan */ -// WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); - } - for (coefi = cinfo.Ss; coefi <= cinfo.Se; coefi++) { - int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; - if (cinfo.Ah != expected) { -// WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); - } - coef_bit_ptr[coefi] = cinfo.Al; - } - } - - /* Select MCU decoding routine */ -// if (cinfo.Ah == 0) { -// if (is_DC_band) -// entropy.pub.decode_mcu = decode_mcu_DC_first; -// else -// entropy.pub.decode_mcu = decode_mcu_AC_first; -// } else { -// if (is_DC_band) -// entropy.pub.decode_mcu = decode_mcu_DC_refine; -// else -// entropy.pub.decode_mcu = decode_mcu_AC_refine; -// } - - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - compptr = cinfo.cur_comp_info[ci]; - /* Make sure requested tables are present, and compute derived tables. - * We may build same derived table more than once, but it's not expensive. - */ - if (is_DC_band) { - if (cinfo.Ah == 0) { /* DC refinement needs no table */ - tbl = compptr.dc_tbl_no; - jpeg_make_d_derived_tbl(cinfo, true, tbl, entropy.derived_tbls[tbl] = new d_derived_tbl()); - } - } else { - tbl = compptr.ac_tbl_no; - jpeg_make_d_derived_tbl(cinfo, false, tbl, entropy.derived_tbls[tbl] = new d_derived_tbl()); - /* remember the single active table */ - entropy.ac_derived_tbl = entropy.derived_tbls[tbl]; - } - /* Initialize DC predictions to 0 */ - entropy.saved.last_dc_val[ci] = 0; - } - - /* Initialize bitread state variables */ - entropy.bitstate.bits_left = 0; - entropy.bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ - entropy.insufficient_data = false; - - /* Initialize private state variables */ - entropy.saved.EOBRUN = 0; - - /* Initialize restart counter */ - entropy.restarts_to_go = cinfo.restart_interval; - } - - } - - static final class jpeg_component_info { - /* These values are fixed over the whole image. */ - /* For compression, they must be supplied by parameter setup; */ - /* for decompression, they are read from the SOF marker. */ - int component_id; /* identifier for this component (0..255) */ - int component_index; /* its index in SOF or cinfo.comp_info[] */ - int h_samp_factor; /* horizontal sampling factor (1..4) */ - int v_samp_factor; /* vertical sampling factor (1..4) */ - int quant_tbl_no; /* quantization table selector (0..3) */ - /* These values may vary between scans. */ - /* For compression, they must be supplied by parameter setup; */ - /* for decompression, they are read from the SOS marker. */ - /* The decompressor output side may not use these variables. */ - int dc_tbl_no; /* DC entropy table selector (0..3) */ - int ac_tbl_no; /* AC entropy table selector (0..3) */ - - /* Remaining fields should be treated as private by applications. */ - - /* These values are computed during compression or decompression startup: */ - /* Component's size in DCT blocks. - * Any dummy blocks added to complete an MCU are not counted; therefore - * these values do not depend on whether a scan is interleaved or not. - */ - int width_in_blocks; - int height_in_blocks; - /* Size of a DCT block in samples. Always DCTSIZE for compression. - * For decompression this is the size of the output from one DCT block, - * reflecting any scaling we choose to apply during the IDCT step. - * Values of 1,2,4,8 are likely to be supported. Note that different - * components may receive different IDCT scalings. - */ - int DCT_scaled_size; - /* The downsampled dimensions are the component's actual, unpadded number - * of samples at the main buffer (preprocessing/compression interface), thus - * downsampled_width = ceil(image_width * Hi/Hmax) - * and similarly for height. For decompression, IDCT scaling is included, so - * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE) - */ - int downsampled_width; /* actual width in samples */ - int downsampled_height; /* actual height in samples */ - /* This flag is used only for decompression. In cases where some of the - * components will be ignored (eg grayscale output from YCbCr image), - * we can skip most computations for the unused components. - */ - boolean component_needed; /* do we need the value of this component? */ - - /* These values are computed before starting a scan of the component. */ - /* The decompressor output side may not use these variables. */ - int MCU_width; /* number of blocks per MCU, horizontally */ - int MCU_height; /* number of blocks per MCU, vertically */ - int MCU_blocks; /* MCU_width * MCU_height */ - int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */ - int last_col_width; /* # of non-dummy blocks across in last MCU */ - int last_row_height; /* # of non-dummy blocks down in last MCU */ - - /* Saved quantization table for component; null if none yet saved. - * See jdinput.c comments about the need for this information. - * This field is currently used only for decompression. - */ - JQUANT_TBL quant_table; - - /* Private per-component storage for DCT or IDCT subsystem. */ - int[] dct_table; - } - - static final class jpeg_color_quantizer { -// JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); -// JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, -// JSAMPARRAY input_buf, JSAMPARRAY output_buf, -// int num_rows)); -// JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); -// JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); - - /* Initially allocated colormap is saved here */ - int[][] sv_colormap; /* The color map as a 2-D pixel array */ - int sv_actual; /* number of entries in use */ - - int[][] colorindex; /* Precomputed mapping for speed */ - /* colorindex[i][j] = index of color closest to pixel value j in component i, - * premultiplied as described above. Since colormap indexes must fit into - * JSAMPLEs, the entries of this array will too. - */ - boolean is_padded; /* is the colorindex padded for odither? */ - - int[] Ncolors = new int [MAX_Q_COMPS]; /* # of values alloced to each component */ - - /* Variables for ordered dithering */ - int row_index; /* cur row's vertical index in dither matrix */ -// ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ - - /* Variables for Floyd-Steinberg dithering */ -// FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ - boolean on_odd_row; - - void start_pass (jpeg_decompress_struct cinfo, boolean is_pre_scan) { - error(); - } - } - - static final class jpeg_upsampler { -// JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); -// JMETHOD(void, upsample, (j_decompress_ptr cinfo, -// JSAMPIMAGE input_buf, -// JDIMENSION *in_row_group_ctr, -// JDIMENSION in_row_groups_avail, -// JSAMPARRAY output_buf, -// JDIMENSION *out_row_ctr, -// JDIMENSION out_rows_avail)); - - boolean need_context_rows; /* TRUE if need rows above & below */ - - /* Color conversion buffer. When using separate upsampling and color - * conversion steps, this buffer holds one upsampled row group until it - * has been color converted and output. - * Note: we do not allocate any storage for component(s) which are full-size, - * ie do not need rescaling. The corresponding entry of color_buf[] is - * simply set to point to the input data array, thereby avoiding copying. - */ - byte[][][] color_buf = new byte[MAX_COMPONENTS][][]; - int[] color_buf_offset = new int[MAX_COMPONENTS]; - - /* Per-component upsampling method pointers */ - int[] methods = new int[MAX_COMPONENTS]; - - int next_row_out; /* counts rows emitted from color_buf */ - int rows_to_go; /* counts rows remaining in image */ - - /* Height of an input row group for each component. */ - int[] rowgroup_height = new int[MAX_COMPONENTS]; - - /* These arrays save pixel expansion factors so that int_expand need not - * recompute them each time. They are unused for other upsampling methods. - */ - byte[] h_expand = new byte[MAX_COMPONENTS]; - byte[] v_expand = new byte[MAX_COMPONENTS]; - - void start_pass (jpeg_decompress_struct cinfo) { - jpeg_upsampler upsample = cinfo.upsample; - - /* Mark the conversion buffer empty */ - upsample.next_row_out = cinfo.max_v_samp_factor; - /* Initialize total-height counter for detecting bottom of image */ - upsample.rows_to_go = cinfo.output_height; - } - - } - - static final class jpeg_marker_reader { - /* Read a restart marker --- exported for use by entropy decoder only */ -// jpeg_marker_parser_method read_restart_marker; - - /* State of marker reader --- nominally internal, but applications - * supplying COM or APPn handlers might like to know the state. - */ - boolean saw_SOI; /* found SOI? */ - boolean saw_SOF; /* found SOF? */ - int next_restart_num; /* next restart number expected (0-7) */ - int discarded_bytes; /* # of bytes skipped looking for a marker */ - - /* Application-overridable marker processing methods */ -// jpeg_marker_parser_method process_COM; -// jpeg_marker_parser_method process_APPn[16]; - - /* Limit on marker data length to save for each marker type */ - int length_limit_COM; - int[] length_limit_APPn = new int[16]; - - /* Status of COM/APPn marker saving */ -// jpeg_marker_reader cur_marker; /* null if not processing a marker */ -// int bytes_read; /* data bytes read so far in marker */ - /* Note: cur_marker is not linked into marker_list until it's all read. */ - } - - - static final class jpeg_d_main_controller { -// JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); - int process_data; - - /* Pointer to allocated workspace (M or M+2 row groups). */ - byte[][][] buffer = new byte[MAX_COMPONENTS][][]; - int[] buffer_offset = new int[MAX_COMPONENTS]; - - boolean buffer_full; /* Have we gotten an iMCU row from decoder? */ - int[] rowgroup_ctr = new int[1]; /* counts row groups output to postprocessor */ - - /* Remaining fields are only used in the context case. */ - - /* These are the master pointers to the funny-order pointer lists. */ - byte[][][][] xbuffer = new byte[2][][][]; /* pointers to weird pointer lists */ - int[][] xbuffer_offset = new int[2][]; - - int whichptr; /* indicates which pointer set is now in use */ - int context_state; /* process_data state machine status */ - int rowgroups_avail; /* row groups available to postprocessor */ - int iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ - - void start_pass (jpeg_decompress_struct cinfo, int pass_mode) { - jpeg_d_main_controller main = cinfo.main; - - switch (pass_mode) { - case JBUF_PASS_THRU: - if (cinfo.upsample.need_context_rows) { - main.process_data = PROCESS_DATA_CONTEXT_MAIN; - make_funny_pointers(cinfo); /* Create the xbuffer[] lists */ - main.whichptr = 0; /* Read first iMCU row into xbuffer[0] */ - main.context_state = CTX_PREPARE_FOR_IMCU; - main.iMCU_row_ctr = 0; - } else { - /* Simple case with no context needed */ - main.process_data = PROCESS_DATA_SIMPLE_MAIN; - } - main.buffer_full = false; /* Mark buffer empty */ - main.rowgroup_ctr[0] = 0; - break; -// #ifdef QUANT_2PASS_SUPPORTED -// case JBUF_CRANK_DEST: -// /* For last pass of 2-pass quantization, just crank the postprocessor */ -// main.process_data = PROCESS_DATA_CRANK_POST; -// break; -// #endif - default: - error(); -// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); - break; - } - } - - } - - static final class jpeg_decomp_master { -// JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); -// JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); - - /* State variables made visible to other modules */ - boolean is_dummy_pass; - - int pass_number; /* # of passes completed */ - - boolean using_merged_upsample; /* true if using merged upsample/cconvert */ - - /* Saved references to initialized quantizer modules, - * in case we need to switch modes. - */ - jpeg_color_quantizer quantizer_1pass; - jpeg_color_quantizer quantizer_2pass; - } - - static final class jpeg_inverse_dct { -// JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); -// /* It is useful to allow each component to have a separate IDCT method. */ -// inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; - int[] cur_method = new int[MAX_COMPONENTS]; - - void start_pass (jpeg_decompress_struct cinfo) { - jpeg_inverse_dct idct = cinfo.idct; - int ci, i; - jpeg_component_info compptr; - int method = 0; -// inverse_DCT_method_ptr method_ptr = NULL; - JQUANT_TBL qtbl; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Select the proper IDCT routine for this component's scaling */ - switch (compptr.DCT_scaled_size) { -// #ifdef IDCT_SCALING_SUPPORTED -// case 1: -// method_ptr = jpeg_idct_1x1; -// method = JDCT_ISLOW; /* jidctred uses islow-style table */ -// break; -// case 2: -// method_ptr = jpeg_idct_2x2; -// method = JDCT_ISLOW; /* jidctred uses islow-style table */ -// break; -// case 4: -// method_ptr = jpeg_idct_4x4; -// method = JDCT_ISLOW; /* jidctred uses islow-style table */ -// break; -// #endif - case DCTSIZE: - switch (cinfo.dct_method) { -// #ifdef DCT_ISLOW_SUPPORTED - case JDCT_ISLOW: -// method_ptr = jpeg_idct_islow; - method = JDCT_ISLOW; - break; -// #endif -// #ifdef DCT_IFAST_SUPPORTED -// case JDCT_IFAST: -// method_ptr = jpeg_idct_ifast; -// method = JDCT_IFAST; -// break; -// #endif -// #ifdef DCT_FLOAT_SUPPORTED -// case JDCT_FLOAT: -// method_ptr = jpeg_idct_float; -// method = JDCT_FLOAT; -// break; -// #endif - default: - error(); -// ERREXIT(cinfo, JERR_NOT_COMPILED); - break; - } - break; - default: - error(); -// ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr.DCT_scaled_size); - break; - } -// idct.inverse_DCT[ci] = method_ptr; - /* Create multiplier table from quant table. - * However, we can skip this if the component is uninteresting - * or if we already built the table. Also, if no quant table - * has yet been saved for the component, we leave the - * multiplier table all-zero; we'll be reading zeroes from the - * coefficient controller's buffer anyway. - */ - if (! compptr.component_needed || idct.cur_method[ci] == method) - continue; - qtbl = compptr.quant_table; - if (qtbl == null) /* happens if no data yet for component */ - continue; - idct.cur_method[ci] = method; - switch (method) { -// #ifdef PROVIDE_ISLOW_TABLES - case JDCT_ISLOW: - { - /* For LL&M IDCT method, multipliers are equal to raw quantization - * coefficients, but are stored as ints to ensure access efficiency. - */ - int[] ismtbl = compptr.dct_table; - for (i = 0; i < DCTSIZE2; i++) { - ismtbl[i] = qtbl.quantval[i]; - } - } - break; -// #endif -// #ifdef DCT_IFAST_SUPPORTED -// case JDCT_IFAST: -// { -// /* For AA&N IDCT method, multipliers are equal to quantization -// * coefficients scaled by scalefactor[row]*scalefactor[col], where -// * scalefactor[0] = 1 -// * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 -// * For integer operation, the multiplier table is to be scaled by -// * IFAST_SCALE_BITS. -// */ -// int[] ifmtbl = compptr.dct_table; -// short aanscales[] = { -// /* precomputed values scaled up by 14 bits */ -// 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, -// 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, -// 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, -// 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, -// 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, -// 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, -// 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, -// 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 -// }; -// SHIFT_TEMPS -// -// for (i = 0; i < DCTSIZE2; i++) { -// ifmtbl[i] = DESCALE(MULTIPLY16V16( qtbl.quantval[i], aanscales[i]), CONST_BITS-IFAST_SCALE_BITS); -// } -// } -// break; -// #endif -// #ifdef DCT_FLOAT_SUPPORTED -// case JDCT_FLOAT: -// { -// /* For float AA&N IDCT method, multipliers are equal to quantization -// * coefficients scaled by scalefactor[row]*scalefactor[col], where -// * scalefactor[0] = 1 -// * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 -// */ -// FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr.dct_table; -// int row, col; -// static const double aanscalefactor[DCTSIZE] = { -// 1.0, 1.387039845, 1.306562965, 1.175875602, -// 1.0, 0.785694958, 0.541196100, 0.275899379 -// }; -// -// i = 0; -// for (row = 0; row < DCTSIZE; row++) { -// for (col = 0; col < DCTSIZE; col++) { -// fmtbl[i] = (FLOAT_MULT_TYPE) -// ((double) qtbl.quantval[i] * -// aanscalefactor[row] * aanscalefactor[col]); -// i++; -// } -// } -// } -// break; -// #endif - default: - error(); -// ERREXIT(cinfo, JERR_NOT_COMPILED); - break; - } - } - } - } - - static final class jpeg_input_controller { - int consume_input; - boolean has_multiple_scans; /* True if file has multiple scans */ - boolean eoi_reached; - - boolean inheaders; /* true until first SOS is reached */ - } - - static final class jpeg_color_deconverter { -// JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); - int color_convert; - - /* Private state for YCC.RGB conversion */ - int[] Cr_r_tab; /* => table for Cr to R conversion */ - int[] Cb_b_tab; /* => table for Cb to B conversion */ - int[] Cr_g_tab; /* => table for Cr to G conversion */ - int[] Cb_g_tab; /* => table for Cb to G conversion */ - - void start_pass (jpeg_decompress_struct cinfo) { - /* no work needed */ - } - - } - - static final class jpeg_d_post_controller { -// JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); - int post_process_data; - - /* Color quantization source buffer: this holds output data from - * the upsample/color conversion step to be passed to the quantizer. - * For two-pass color quantization, we need a full-image buffer; - * for one-pass operation, a strip buffer is sufficient. - */ - int[] whole_image; /* virtual array, or NULL if one-pass */ - int[][] buffer; /* strip buffer, or current strip of virtual */ - int strip_height; /* buffer size in rows */ - /* for two-pass mode only: */ - int starting_row; /* row # of first row in current strip */ - int next_row; /* index of next row to fill/empty in strip */ - - void start_pass (jpeg_decompress_struct cinfo, int pass_mode) { - jpeg_d_post_controller post = cinfo.post; - - switch (pass_mode) { - case JBUF_PASS_THRU: - if (cinfo.quantize_colors) { - error(SWT.ERROR_NOT_IMPLEMENTED); -// /* Single-pass processing with color quantization. */ -// post.post_process_data = POST_PROCESS_1PASS; -// /* We could be doing buffered-image output before starting a 2-pass -// * color quantization; in that case, jinit_d_post_controller did not -// * allocate a strip buffer. Use the virtual-array buffer as workspace. -// */ -// if (post.buffer == null) { -// post.buffer = (*cinfo.mem.access_virt_sarray) -// ((j_common_ptr) cinfo, post.whole_image, -// (JDIMENSION) 0, post.strip_height, TRUE); -// } - } else { - /* For single-pass processing without color quantization, - * I have no work to do; just call the upsampler directly. - */ - post.post_process_data = POST_PROCESS_DATA_UPSAMPLE; - } - break; -// #ifdef QUANT_2PASS_SUPPORTED -// case JBUF_SAVE_AND_PASS: -// /* First pass of 2-pass quantization */ -// if (post.whole_image == NULL) -// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); -// post.pub.post_process_data = post_process_prepass; -// break; -// case JBUF_CRANK_DEST: -// /* Second pass of 2-pass quantization */ -// if (post.whole_image == NULL) -// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); -// post.pub.post_process_data = post_process_2pass; -// break; -// #endif /* QUANT_2PASS_SUPPORTED */ - default: - error(); -// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); - break; - } - post.starting_row = post.next_row = 0; - } - - } - - static final class jpeg_decompress_struct { -// jpeg_error_mgr * err; /* Error handler module */\ -// struct jpeg_memory_mgr * mem; /* Memory manager module */\ -// struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\ -// void * client_data; /* Available for use by application */\ - boolean is_decompressor; /* So common code can tell which is which */ - int global_state; /* For checking call sequence validity */ - -// /* Source of compressed data */ -// struct jpeg_source_mgr * src; - InputStream inputStream; - byte[] buffer; - int bytes_in_buffer; - int bytes_offset; - boolean start_of_file; - - /* Basic description of image --- filled in by jpeg_read_header(). */ - /* Application may inspect these values to decide how to process image. */ - - int image_width; /* nominal image width (from SOF marker) */ - int image_height; /* nominal image height */ - int num_components; /* # of color components in JPEG image */ - int jpeg_color_space; /* colorspace of JPEG image */ - - /* Decompression processing parameters --- these fields must be set before - * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes - * them to default values. - */ - - int out_color_space; /* colorspace for output */ - - int scale_num, scale_denom; /* fraction by which to scale image */ - - double output_gamma; /* image gamma wanted in output */ - - boolean buffered_image; /* true=multiple output passes */ - boolean raw_data_out; /* true=downsampled data wanted */ - - int dct_method; /* IDCT algorithm selector */ - boolean do_fancy_upsampling; /* true=apply fancy upsampling */ - boolean do_block_smoothing; /* true=apply interblock smoothing */ - - boolean quantize_colors; /* true=colormapped output wanted */ - /* the following are ignored if not quantize_colors: */ - int dither_mode; /* type of color dithering to use */ - boolean two_pass_quantize; /* true=use two-pass color quantization */ - int desired_number_of_colors; /* max # colors to use in created colormap */ - /* these are significant only in buffered-image mode: */ - boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ - boolean enable_external_quant;/* enable future use of external colormap */ - boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ - - /* Description of actual output image that will be returned to application. - * These fields are computed by jpeg_start_decompress(). - * You can also use jpeg_calc_output_dimensions() to determine these values - * in advance of calling jpeg_start_decompress(). - */ - - int output_width; /* scaled image width */ - int output_height; /* scaled image height */ - int out_color_components; /* # of color components in out_color_space */ - int output_components; /* # of color components returned */ - /* output_components is 1 (a colormap index) when quantizing colors; - * otherwise it equals out_color_components. - */ - int rec_outbuf_height; /* min recommended height of scanline buffer */ - /* If the buffer passed to jpeg_read_scanlines() is less than this many rows - * high, space and time will be wasted due to unnecessary data copying. - * Usually rec_outbuf_height will be 1 or 2, at most 4. - */ - - /* When quantizing colors, the output colormap is described by these fields. - * The application can supply a colormap by setting colormap non-null before - * calling jpeg_start_decompress; otherwise a colormap is created during - * jpeg_start_decompress or jpeg_start_output. - * The map has out_color_components rows and actual_number_of_colors columns. - */ - int actual_number_of_colors; /* number of entries in use */ - int[] colormap; /* The color map as a 2-D pixel array */ - - /* State variables: these variables indicate the progress of decompression. - * The application may examine these but must not modify them. - */ - - /* Row index of next scanline to be read from jpeg_read_scanlines(). - * Application may use this to control its processing loop, e.g., - * "while (output_scanline < output_height)". - */ - int output_scanline; /* 0 .. output_height-1 */ - - /* Current input scan number and number of iMCU rows completed in scan. - * These indicate the progress of the decompressor input side. - */ - int input_scan_number; /* Number of SOS markers seen so far */ - int input_iMCU_row; /* Number of iMCU rows completed */ - - /* The "output scan number" is the notional scan being displayed by the - * output side. The decompressor will not allow output scan/row number - * to get ahead of input scan/row, but it can fall arbitrarily far behind. - */ - int output_scan_number; /* Nominal scan number being displayed */ - int output_iMCU_row; /* Number of iMCU rows read */ - - /* Current progression status. coef_bits[c][i] indicates the precision - * with which component c's DCT coefficient i (in zigzag order) is known. - * It is -1 when no data has yet been received, otherwise it is the point - * transform (shift) value for the most recent scan of the coefficient - * (thus, 0 at completion of the progression). - * This pointer is null when reading a non-progressive file. - */ - int[][] coef_bits; /* -1 or current Al value for each coef */ - - /* Internal JPEG parameters --- the application usually need not look at - * these fields. Note that the decompressor output side may not use - * any parameters that can change between scans. - */ - - /* Quantization and Huffman tables are carried forward across input - * datastreams when processing abbreviated JPEG datastreams. - */ - - JQUANT_TBL[] quant_tbl_ptrs = new JQUANT_TBL[NUM_QUANT_TBLS]; - /* ptrs to coefficient quantization tables, or null if not defined */ - - JHUFF_TBL[] dc_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS]; - JHUFF_TBL[] ac_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS]; - /* ptrs to Huffman coding tables, or null if not defined */ - - /* These parameters are never carried across datastreams, since they - * are given in SOF/SOS markers or defined to be reset by SOI. - */ - - int data_precision; /* bits of precision in image data */ - - jpeg_component_info[] comp_info; - /* comp_info[i] describes component that appears i'th in SOF */ - - boolean progressive_mode; /* true if SOFn specifies progressive mode */ - boolean arith_code; /* true=arithmetic coding, false=Huffman */ - - byte[] arith_dc_L = new byte[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ - byte[] arith_dc_U = new byte[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ - byte[] arith_ac_K = new byte[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ - - int restart_interval; /* MCUs per restart interval, or 0 for no restart */ - - /* These fields record data obtained from optional markers recognized by - * the JPEG library. - */ - boolean saw_JFIF_marker; /* true iff a JFIF APP0 marker was found */ - /* Data copied from JFIF marker; only valid if saw_JFIF_marker is true: */ - byte JFIF_major_version; /* JFIF version number */ - byte JFIF_minor_version; - byte density_unit; /* JFIF code for pixel size units */ - short X_density; /* Horizontal pixel density */ - short Y_density; /* Vertical pixel density */ - boolean saw_Adobe_marker; /* true iff an Adobe APP14 marker was found */ - byte Adobe_transform; /* Color transform code from Adobe marker */ - - boolean CCIR601_sampling; /* true=first samples are cosited */ - - /* Aside from the specific data retained from APPn markers known to the - * library, the uninterpreted contents of any or all APPn and COM markers - * can be saved in a list for examination by the application. - */ - jpeg_marker_reader marker_list; /* Head of list of saved markers */ - - /* Remaining fields are known throughout decompressor, but generally - * should not be touched by a surrounding application. - */ - - /* - * These fields are computed during decompression startup - */ - int max_h_samp_factor; /* largest h_samp_factor */ - int max_v_samp_factor; /* largest v_samp_factor */ - - int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ - - int total_iMCU_rows; /* # of iMCU rows in image */ - /* The coefficient controller's input and output progress is measured in - * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows - * in fully interleaved JPEG scans, but are used whether the scan is - * interleaved or not. We define an iMCU row as v_samp_factor DCT block - * rows of each component. Therefore, the IDCT output contains - * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row. - */ - - byte[] sample_range_limit; /* table for fast range-limiting */ - int sample_range_limit_offset; - - /* - * These fields are valid during any one scan. - * They describe the components and MCUs actually appearing in the scan. - * Note that the decompressor output side must not use these fields. - */ - int comps_in_scan; /* # of JPEG components in this scan */ - jpeg_component_info[] cur_comp_info = new jpeg_component_info[MAX_COMPS_IN_SCAN]; - /* *cur_comp_info[i] describes component that appears i'th in SOS */ - - int MCUs_per_row; /* # of MCUs across the image */ - int MCU_rows_in_scan; /* # of MCU rows in the image */ - - int blocks_in_MCU; /* # of DCT blocks per MCU */ - int[] MCU_membership = new int[D_MAX_BLOCKS_IN_MCU]; - /* MCU_membership[i] is index in cur_comp_info of component owning */ - /* i'th block in an MCU */ - - int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ - - /* This field is shared between entropy decoder and marker parser. - * It is either zero or the code of a JPEG marker that has been - * read from the data source, but has not yet been processed. - */ - int unread_marker; - - int[] workspace = new int[DCTSIZE2]; - int[] row_ctr = new int[1]; - - /* - * Links to decompression subobjects (methods, private variables of modules) - */ - jpeg_decomp_master master; - jpeg_d_main_controller main; - jpeg_d_coef_controller coef; - jpeg_d_post_controller post; - jpeg_input_controller inputctl; - jpeg_marker_reader marker; - jpeg_entropy_decoder entropy; - jpeg_inverse_dct idct; - jpeg_upsampler upsample; - jpeg_color_deconverter cconvert; - jpeg_color_quantizer cquantize; - } - -static void error() { - SWT.error(SWT.ERROR_INVALID_IMAGE); -} - -static void error(int code) { - SWT.error(code); -} - -static void error(String msg) { - SWT.error(SWT.ERROR_INVALID_IMAGE, null, msg); -} - -static void jinit_marker_reader (jpeg_decompress_struct cinfo) { - jpeg_marker_reader marker = cinfo.marker = new jpeg_marker_reader(); -// int i; - - /* Initialize COM/APPn processing. - * By default, we examine and then discard APP0 and APP14, - * but simply discard COM and all other APPn. - */ -// marker.process_COM = skip_variable; - marker.length_limit_COM = 0; -// for (i = 0; i < 16; i++) { -// marker.process_APPn[i] = skip_variable; -// marker.length_limit_APPn[i] = 0; -// } -// marker.process_APPn[0] = get_interesting_appn; -// marker.process_APPn[14] = get_interesting_appn; - /* Reset marker processing state */ - reset_marker_reader(cinfo); -} - -static void jinit_d_coef_controller (jpeg_decompress_struct cinfo, boolean need_full_buffer) { - jpeg_d_coef_controller coef = new jpeg_d_coef_controller(); - cinfo.coef = coef; -// coef.pub.start_input_pass = start_input_pass; -// coef.pub.start_output_pass = start_output_pass; - coef.coef_bits_latch = null; - - /* Create the coefficient buffer. */ - if (need_full_buffer) { -//#ifdef D_MULTISCAN_FILES_SUPPORTED - /* Allocate a full-image virtual array for each component, */ - /* padded to a multiple of samp_factor DCT blocks in each direction. */ - /* Note we ask for a pre-zeroed array. */ - int ci, access_rows; - jpeg_component_info compptr; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - access_rows = compptr.v_samp_factor; -//#ifdef BLOCK_SMOOTHING_SUPPORTED - /* If block smoothing could be used, need a bigger window */ - if (cinfo.progressive_mode) - access_rows *= 3; -//#endif - coef.whole_image[ci] = - new short - [(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor)] - [(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor)] - [DCTSIZE2]; - } -// coef.consume_data = consume_data; - coef.decompress_data = DECOMPRESS_DATA; - coef.coef_arrays = coef.whole_image[0]; /* link to virtual arrays */ -// #else -// ERREXIT(cinfo, JERR_NOT_COMPILED); -// #endif - } else { - /* We only need a single-MCU buffer. */ - coef.MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][DCTSIZE2]; -// coef.consume_data = dummy_consume_data; - coef.decompress_data = DECOMPRESS_ONEPASS; - coef.coef_arrays = null; /* flag for no virtual arrays */ - } -} - -static void start_output_pass (jpeg_decompress_struct cinfo) { -//#ifdef BLOCK_SMOOTHING_SUPPORTED - jpeg_d_coef_controller coef = cinfo.coef; - - /* If multipass, check to see whether to use block smoothing on this pass */ - if (coef.coef_arrays != null) { - if (cinfo.do_block_smoothing && smoothing_ok(cinfo)) - coef.decompress_data = DECOMPRESS_SMOOTH_DATA; - else - coef.decompress_data = DECOMPRESS_DATA; - } -//#endif - cinfo.output_iMCU_row = 0; -} - -static void jpeg_create_decompress(jpeg_decompress_struct cinfo) { - cinfo.is_decompressor = true; - - - /* Initialize marker processor so application can override methods - * for COM, APPn markers before calling jpeg_read_header. - */ - cinfo.marker_list = null; - jinit_marker_reader(cinfo); - - /* And initialize the overall input controller. */ - jinit_input_controller(cinfo); - - /* OK, I'm ready */ - cinfo.global_state = DSTATE_START; -} - -static void jpeg_calc_output_dimensions (jpeg_decompress_struct cinfo) -/* Do computations that are needed before master selection phase */ -{ -//#ifdef IDCT_SCALING_SUPPORTED -// int ci; -// jpeg_component_info compptr; -//#endif - - /* Prevent application from calling me at wrong times */ - if (cinfo.global_state != DSTATE_READY) - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - -//#ifdef IDCT_SCALING_SUPPORTED -// -// /* Compute actual output image dimensions and DCT scaling choices. */ -// if (cinfo.scale_num * 8 <= cinfo.scale_denom) { -// /* Provide 1/8 scaling */ -// cinfo.output_width = (int) -// jdiv_round_up(cinfo.image_width, 8L); -// cinfo.output_height = (int) -// jdiv_round_up(cinfo.image_height, 8L); -// cinfo.min_DCT_scaled_size = 1; -// } else if (cinfo.scale_num * 4 <= cinfo.scale_denom) { -// /* Provide 1/4 scaling */ -// cinfo.output_width = (int) -// jdiv_round_up(cinfo.image_width, 4L); -// cinfo.output_height = (int) -// jdiv_round_up(cinfo.image_height, 4L); -// cinfo.min_DCT_scaled_size = 2; -// } else if (cinfo.scale_num * 2 <= cinfo.scale_denom) { -// /* Provide 1/2 scaling */ -// cinfo.output_width = (int) -// jdiv_round_up(cinfo.image_width, 2L); -// cinfo.output_height = (int) -// jdiv_round_up(cinfo.image_height, 2L); -// cinfo.min_DCT_scaled_size = 4; -// } else { -// /* Provide 1/1 scaling */ -// cinfo.output_width = cinfo.image_width; -// cinfo.output_height = cinfo.image_height; -// cinfo.min_DCT_scaled_size = DCTSIZE; -// } -// /* In selecting the actual DCT scaling for each component, we try to -// * scale up the chroma components via IDCT scaling rather than upsampling. -// * This saves time if the upsampler gets to use 1:1 scaling. -// * Note this code assumes that the supported DCT scalings are powers of 2. -// */ -// for (ci = 0; ci < cinfo.num_components; ci++) { -// compptr = cinfo.comp_info[ci]; -// int ssize = cinfo.min_DCT_scaled_size; -// while (ssize < DCTSIZE && -// (compptr.h_samp_factor * ssize * 2 <= cinfo.max_h_samp_factor * cinfo.min_DCT_scaled_size) && -// (compptr.v_samp_factor * ssize * 2 <= cinfo.max_v_samp_factor * cinfo.min_DCT_scaled_size)) -// { -// ssize = ssize * 2; -// } -// compptr.DCT_scaled_size = ssize; -// } -// -// /* Recompute downsampled dimensions of components; -// * application needs to know these if using raw downsampled data. -// */ -// for (ci = 0; ci < cinfo.num_components; ci++) { -// compptr = cinfo.comp_info[ci]; -// /* Size in samples, after IDCT scaling */ -// compptr.downsampled_width = (int) -// jdiv_round_up((long) cinfo.image_width * (long) (compptr.h_samp_factor * compptr.DCT_scaled_size), -// (cinfo.max_h_samp_factor * DCTSIZE)); -// compptr.downsampled_height = (int) -// jdiv_round_up((long) cinfo.image_height * (long) (compptr.v_samp_factor * compptr.DCT_scaled_size), -// (cinfo.max_v_samp_factor * DCTSIZE)); -// } -// -//#else /* !IDCT_SCALING_SUPPORTED */ - - /* Hardwire it to "no scaling" */ - cinfo.output_width = cinfo.image_width; - cinfo.output_height = cinfo.image_height; - /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, - * and has computed unscaled downsampled_width and downsampled_height. - */ - -//#endif /* IDCT_SCALING_SUPPORTED */ - - /* Report number of components in selected colorspace. */ - /* Probably this should be in the color conversion module... */ - switch (cinfo.out_color_space) { - case JCS_GRAYSCALE: - cinfo.out_color_components = 1; - break; - case JCS_RGB: - case JCS_YCbCr: - cinfo.out_color_components = 3; - break; - case JCS_CMYK: - case JCS_YCCK: - cinfo.out_color_components = 4; - break; - default: /* else must be same colorspace as in file */ - cinfo.out_color_components = cinfo.num_components; - break; - } - cinfo.output_components = (cinfo.quantize_colors ? 1 : cinfo.out_color_components); - - /* See if upsampler will want to emit more than one row at a time */ - if (use_merged_upsample(cinfo)) - cinfo.rec_outbuf_height = cinfo.max_v_samp_factor; - else - cinfo.rec_outbuf_height = 1; -} - -static boolean use_merged_upsample (jpeg_decompress_struct cinfo) { -//#ifdef UPSAMPLE_MERGING_SUPPORTED - /* Merging is the equivalent of plain box-filter upsampling */ - if (cinfo.do_fancy_upsampling || cinfo.CCIR601_sampling) - return false; - /* jdmerge.c only supports YCC=>RGB color conversion */ - if (cinfo.jpeg_color_space != JCS_YCbCr || cinfo.num_components != 3 || - cinfo.out_color_space != JCS_RGB || - cinfo.out_color_components != RGB_PIXELSIZE) - return false; - /* and it only handles 2h1v or 2h2v sampling ratios */ - if (cinfo.comp_info[0].h_samp_factor != 2 || - cinfo.comp_info[1].h_samp_factor != 1 || - cinfo.comp_info[2].h_samp_factor != 1 || - cinfo.comp_info[0].v_samp_factor > 2 || - cinfo.comp_info[1].v_samp_factor != 1 || - cinfo.comp_info[2].v_samp_factor != 1) - return false; - /* furthermore, it doesn't work if we've scaled the IDCTs differently */ - if (cinfo.comp_info[0].DCT_scaled_size != cinfo.min_DCT_scaled_size || - cinfo.comp_info[1].DCT_scaled_size != cinfo.min_DCT_scaled_size || - cinfo.comp_info[2].DCT_scaled_size != cinfo.min_DCT_scaled_size) - return false; - /* ??? also need to test for upsample-time rescaling, when & if supported */ - return true; /* by golly, it'll work... */ -//#else -// return false; -//#endif -} - -static void prepare_range_limit_table (jpeg_decompress_struct cinfo) -/* Allocate and fill in the sample_range_limit table */ -{ - byte[] table; - int i; - - table = new byte[5 * (MAXJSAMPLE+1) + CENTERJSAMPLE]; - int offset = (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ - cinfo.sample_range_limit_offset = offset; - cinfo.sample_range_limit = table; - /* First segment of "simple" table: limit[x] = 0 for x < 0 */ - /* Main part of "simple" table: limit[x] = x */ - for (i = 0; i <= MAXJSAMPLE; i++) - table[i + offset] = (byte)i; - offset += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ - /* End of simple table, rest of first half of post-IDCT table */ - for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) - table[i+offset] = (byte)MAXJSAMPLE; - /* Second half of post-IDCT table */ - System.arraycopy(cinfo.sample_range_limit, cinfo.sample_range_limit_offset, table, offset + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), CENTERJSAMPLE); -} - -static void build_ycc_rgb_table (jpeg_decompress_struct cinfo) { - jpeg_color_deconverter cconvert = cinfo.cconvert; - int i; - int x; -// SHIFT_TEMPS - - cconvert.Cr_r_tab = new int[MAXJSAMPLE+1]; - cconvert.Cb_b_tab = new int[MAXJSAMPLE+1]; - cconvert.Cr_g_tab = new int[MAXJSAMPLE+1]; - cconvert.Cb_g_tab = new int[MAXJSAMPLE+1]; - - for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { - /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ - /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ - /* Cr=>R value is nearest int to 1.40200 * x */ - cconvert.Cr_r_tab[i] = ((int)(1.40200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS; - /* Cb=>B value is nearest int to 1.77200 * x */ - cconvert.Cb_b_tab[i] = ((int)(1.77200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS; - /* Cr=>G value is scaled-up -0.71414 * x */ - cconvert.Cr_g_tab[i] = ((int)(- (0.71414f * (1<<SCALEBITS) + 0.5f)) * x); - /* Cb=>G value is scaled-up -0.34414 * x */ - /* We also add in ONE_HALF so that need not do it in inner loop */ - cconvert.Cb_g_tab[i] = ((int)(- (0.34414f* (1<<SCALEBITS) + 0.5f)) * x + ONE_HALF); - } -} - -static void jinit_color_deconverter (jpeg_decompress_struct cinfo) { - jpeg_color_deconverter cconvert = cinfo.cconvert = new jpeg_color_deconverter(); -// cconvert.start_pass = start_pass_dcolor; - - /* Make sure num_components agrees with jpeg_color_space */ - switch (cinfo.jpeg_color_space) { - case JCS_GRAYSCALE: - if (cinfo.num_components != 1) - error(); -// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); - break; - - case JCS_RGB: - case JCS_YCbCr: - if (cinfo.num_components != 3) - error(); -// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); - break; - - case JCS_CMYK: - case JCS_YCCK: - if (cinfo.num_components != 4) - error(); -// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); - break; - - default: /* JCS_UNKNOWN can be anything */ - if (cinfo.num_components < 1) - error(); -// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); - break; - } - - /* Set out_color_components and conversion method based on requested space. - * Also clear the component_needed flags for any unused components, - * so that earlier pipeline stages can avoid useless computation. - */ - - int ci; - switch (cinfo.out_color_space) { - case JCS_GRAYSCALE: - cinfo.out_color_components = 1; - if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr) { - cconvert.color_convert = GRAYSCALE_CONVERT; - /* For color.grayscale conversion, only the Y (0) component is needed */ - for (ci = 1; ci < cinfo.num_components; ci++) - cinfo.comp_info[ci].component_needed = false; - } else - error(); -// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); - break; - - case JCS_RGB: - cinfo.out_color_components = RGB_PIXELSIZE; - if (cinfo.jpeg_color_space == JCS_YCbCr) { - cconvert.color_convert = YCC_RGB_CONVERT; - build_ycc_rgb_table(cinfo); - } else if (cinfo.jpeg_color_space == JCS_GRAYSCALE) { - cconvert.color_convert = GRAY_RGB_CONVERT; - } else if (cinfo.jpeg_color_space == JCS_RGB) { - cconvert.color_convert = NULL_CONVERT; - } else - error(); -// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); - break; - - case JCS_CMYK: - cinfo.out_color_components = 4; - if (cinfo.jpeg_color_space == JCS_YCCK) { - cconvert.color_convert = YCCK_CMYK_CONVERT; - build_ycc_rgb_table(cinfo); - } else if (cinfo.jpeg_color_space == JCS_CMYK) { - cconvert.color_convert = NULL_CONVERT; - } else - error(); -// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); - break; - - default: - /* Permit null conversion to same output space */ - if (cinfo.out_color_space == cinfo.jpeg_color_space) { - cinfo.out_color_components = cinfo.num_components; - cconvert.color_convert = NULL_CONVERT; - } else /* unsupported non-null conversion */ - error(); -// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); - break; - } - - if (cinfo.quantize_colors) - cinfo.output_components = 1; /* single colormapped output component */ - else - cinfo.output_components = cinfo.out_color_components; -} - -static void jinit_d_post_controller (jpeg_decompress_struct cinfo, boolean need_full_buffer) { - jpeg_d_post_controller post = cinfo.post = new jpeg_d_post_controller(); -// post.pub.start_pass = start_pass_dpost; - post.whole_image = null; /* flag for no virtual arrays */ - post.buffer = null; /* flag for no strip buffer */ - - /* Create the quantization buffer, if needed */ - if (cinfo.quantize_colors) { - error(SWT.ERROR_NOT_IMPLEMENTED); -// /* The buffer strip height is max_v_samp_factor, which is typically -// * an efficient number of rows for upsampling to return. -// * (In the presence of output rescaling, we might want to be smarter?) -// */ -// post.strip_height = cinfo.max_v_samp_factor; -// if (need_full_buffer) { -// /* Two-pass color quantization: need full-image storage. */ -// /* We round up the number of rows to a multiple of the strip height. */ -//#ifdef QUANT_2PASS_SUPPORTED -// post.whole_image = (*cinfo.mem.request_virt_sarray) -// ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, -// cinfo.output_width * cinfo.out_color_components, -// (JDIMENSION) jround_up((long) cinfo.output_height, -// (long) post.strip_height), -// post.strip_height); -//#else -// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); -//#endif /* QUANT_2PASS_SUPPORTED */ -// } else { -// /* One-pass color quantization: just make a strip buffer. */ -// post.buffer = (*cinfo.mem.alloc_sarray) -// ((j_common_ptr) cinfo, JPOOL_IMAGE, -// cinfo.output_width * cinfo.out_color_components, -// post.strip_height); -// } - } -} - -static void make_funny_pointers (jpeg_decompress_struct cinfo) -/* Create the funny pointer lists discussed in the comments above. - * The actual workspace is already allocated (in main.buffer), - * and the space for the pointer lists is allocated too. - * This routine just fills in the curiously ordered lists. - * This will be repeated at the beginning of each pass. - */ -{ - jpeg_d_main_controller main = cinfo.main; - int ci, i, rgroup; - int M = cinfo.min_DCT_scaled_size; - jpeg_component_info compptr; - byte[][] buf, xbuf0, xbuf1; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / - cinfo.min_DCT_scaled_size; /* height of a row group of component */ - xbuf0 = main.xbuffer[0][ci]; - int xbuf0_offset = main.xbuffer_offset[0][ci]; - xbuf1 = main.xbuffer[1][ci]; - int xbuf1_offset = main.xbuffer_offset[1][ci]; - /* First copy the workspace pointers as-is */ - buf = main.buffer[ci]; - for (i = 0; i < rgroup * (M + 2); i++) { - xbuf0[i + xbuf0_offset] = xbuf1[i + xbuf1_offset] = buf[i]; - } - /* In the second list, put the last four row groups in swapped order */ - for (i = 0; i < rgroup * 2; i++) { - xbuf1[rgroup*(M-2) + i + xbuf1_offset] = buf[rgroup*M + i]; - xbuf1[rgroup*M + i + xbuf1_offset] = buf[rgroup*(M-2) + i]; - } - /* The wraparound pointers at top and bottom will be filled later - * (see set_wraparound_pointers, below). Initially we want the "above" - * pointers to duplicate the first actual data line. This only needs - * to happen in xbuffer[0]. - */ - for (i = 0; i < rgroup; i++) { - xbuf0[i - rgroup + xbuf0_offset] = xbuf0[0 + xbuf0_offset]; - } - } -} - -static void alloc_funny_pointers (jpeg_decompress_struct cinfo) -/* Allocate space for the funny pointer lists. - * This is done only once, not once per pass. - */ -{ - jpeg_d_main_controller main = cinfo.main; - int ci, rgroup; - int M = cinfo.min_DCT_scaled_size; - jpeg_component_info compptr; - byte[][] xbuf; - - /* Get top-level space for component array pointers. - * We alloc both arrays with one call to save a few cycles. - */ - main.xbuffer[0] = new byte[cinfo.num_components][][]; - main.xbuffer[1] = new byte[cinfo.num_components][][]; - main.xbuffer_offset[0] = new int[cinfo.num_components]; - main.xbuffer_offset[1] = new int[cinfo.num_components]; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ - /* Get space for pointer lists --- M+4 row groups in each list. - * We alloc both pointer lists with one call to save a few cycles. - */ - xbuf = new byte[2 * (rgroup * (M + 4))][]; - int offset = rgroup; - main.xbuffer_offset[0][ci] = offset; - main.xbuffer[0][ci] = xbuf; - offset += rgroup * (M + 4); - main.xbuffer_offset[1][ci] = offset; - main.xbuffer[1][ci] = xbuf; - } -} - - -static void jinit_d_main_controller (jpeg_decompress_struct cinfo, boolean need_full_buffer) { - int ci, rgroup, ngroups; - jpeg_component_info compptr; - - jpeg_d_main_controller main = cinfo.main = new jpeg_d_main_controller(); -// main.pub.start_pass = start_pass_main; - - if (need_full_buffer) /* shouldn't happen */ - error(); -// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); - - /* Allocate the workspace. - * ngroups is the number of row groups we need. - */ - if (cinfo.upsample.need_context_rows) { - if (cinfo.min_DCT_scaled_size < 2) /* unsupported, see comments above */ - error(); -// ERREXIT(cinfo, JERR_NOTIMPL); - alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ - ngroups = cinfo.min_DCT_scaled_size + 2; - } else { - ngroups = cinfo.min_DCT_scaled_size; - } - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ - main.buffer[ci] = new byte[rgroup * ngroups][compptr.width_in_blocks * compptr.DCT_scaled_size]; - } -} - -static long jround_up (long a, long b) -/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ -/* Assumes a >= 0, b > 0 */ -{ - a += b - 1L; - return a - (a % b); -} - -static void jinit_upsampler (jpeg_decompress_struct cinfo) { - int ci; - jpeg_component_info compptr; - boolean need_buffer, do_fancy; - int h_in_group, v_in_group, h_out_group, v_out_group; - - jpeg_upsampler upsample = new jpeg_upsampler(); - cinfo.upsample = upsample; -// upsample.start_pass = start_pass_upsample; -// upsample.upsample = sep_upsample; - upsample.need_context_rows = false; /* until we find out differently */ - - if (cinfo.CCIR601_sampling) /* this isn't supported */ - error(); -// ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); - - /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, - * so don't ask for it. - */ - do_fancy = cinfo.do_fancy_upsampling && cinfo.min_DCT_scaled_size > 1; - - /* Verify we can handle the sampling factors, select per-component methods, - * and create storage as needed. - */ - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Compute size of an "input group" after IDCT scaling. This many samples - * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. - */ - h_in_group = (compptr.h_samp_factor * compptr.DCT_scaled_size) / - cinfo.min_DCT_scaled_size; - v_in_group = (compptr.v_samp_factor * compptr.DCT_scaled_size) / - cinfo.min_DCT_scaled_size; - h_out_group = cinfo.max_h_samp_factor; - v_out_group = cinfo.max_v_samp_factor; - upsample.rowgroup_height[ci] = v_in_group; /* save for use later */ - need_buffer = true; - if (! compptr.component_needed) { - /* Don't bother to upsample an uninteresting component. */ - upsample.methods[ci] = NOOP_UPSAMPLE; - need_buffer = false; - } else if (h_in_group == h_out_group && v_in_group == v_out_group) { - /* Fullsize components can be processed without any work. */ - upsample.methods[ci] = FULLSIZE_UPSAMPLE; - need_buffer = false; - } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { - /* Special cases for 2h1v upsampling */ - if (do_fancy && compptr.downsampled_width > 2) - upsample.methods[ci] = H2V1_FANCY_UPSAMPLE; - else - upsample.methods[ci] = H2V1_UPSAMPLE; - } else if (h_in_group * 2 == h_out_group && v_in_group * 2 == v_out_group) { - /* Special cases for 2h2v upsampling */ - if (do_fancy && compptr.downsampled_width > 2) { - upsample.methods[ci] = H2V2_FANCY_UPSAMPLE; - upsample.need_context_rows = true; - } else - upsample.methods[ci] = H2V2_UPSAMPLE; - } else if ((h_out_group % h_in_group) == 0 && (v_out_group % v_in_group) == 0) { - /* Generic integral-factors upsampling method */ - upsample.methods[ci] = INT_UPSAMPLE; - upsample.h_expand[ci] = (byte) (h_out_group / h_in_group); - upsample.v_expand[ci] = (byte) (v_out_group / v_in_group); - } else - error(); -// ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); - if (need_buffer) { - upsample.color_buf[ci] = new byte[cinfo.max_v_samp_factor] - [(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)]; - } - } -} - -static void jinit_phuff_decoder (jpeg_decompress_struct cinfo) { - int[][] coef_bit_ptr; - int ci, i; - - cinfo.entropy = new phuff_entropy_decoder(); -// entropy.pub.start_pass = start_pass_phuff_decoder; - - /* Create progression status table */ - cinfo.coef_bits = new int[cinfo.num_components][DCTSIZE2]; - coef_bit_ptr = cinfo.coef_bits; - for (ci = 0; ci < cinfo.num_components; ci++) - for (i = 0; i < DCTSIZE2; i++) - coef_bit_ptr[ci][i] = -1; -} - - -static void jinit_huff_decoder (jpeg_decompress_struct cinfo) { - - cinfo.entropy = new huff_entropy_decoder(); -// entropy.pub.start_pass = start_pass_huff_decoder; -// entropy.pub.decode_mcu = decode_mcu; - -} - -static void jinit_inverse_dct (jpeg_decompress_struct cinfo) { - int ci; - jpeg_component_info compptr; - - jpeg_inverse_dct idct = cinfo.idct = new jpeg_inverse_dct(); -// idct.pub.start_pass = start_pass; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Allocate and pre-zero a multiplier table for each component */ - compptr.dct_table = new int[DCTSIZE2]; - /* Mark multiplier table not yet set up for any method */ - idct.cur_method[ci] = -1; - } -} - -static final int CONST_BITS = 13; -static final int PASS1_BITS = 2; -static final int RANGE_MASK =(MAXJSAMPLE * 4 + 3); -static void jpeg_idct_islow (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - short[] coef_block, - byte[][] output_buf, int output_buf_offset, int output_col) -{ - int tmp0, tmp1, tmp2, tmp3; - int tmp10, tmp11, tmp12, tmp13; - int z1, z2, z3, z4, z5; - short[] inptr; - int[] quantptr; - int[] wsptr; - byte[] outptr; - byte[] range_limit = cinfo.sample_range_limit; - int range_limit_offset = cinfo.sample_range_limit_offset + CENTERJSAMPLE; - int ctr; - int[] workspace = cinfo.workspace; /* buffers data between passes */ -// SHIFT_TEMPS - - /* Pass 1: process columns from input, store into work array. */ - /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ - /* furthermore, we scale the results by 2**PASS1_BITS. */ - - inptr = coef_block; - quantptr = compptr.dct_table; - wsptr = workspace; - int inptr_offset = 0, quantptr_offset = 0, wsptr_offset = 0; - for (ctr = DCTSIZE; ctr > 0; ctr--) { - /* Due to quantization, we will usually find that many of the input - * coefficients are zero, especially the AC terms. We can exploit this - * by short-circuiting the IDCT calculation for any column in which all - * the AC terms are zero. In that case each output is equal to the - * DC coefficient (with scale factor as needed). - * With typical images and quantization tables, half or more of the - * column DCT calculations can be simplified this way. - */ - - if (inptr[DCTSIZE*1+inptr_offset] == 0 && inptr[DCTSIZE*2+inptr_offset] == 0 && - inptr[DCTSIZE*3+inptr_offset] == 0 && inptr[DCTSIZE*4+inptr_offset] == 0 && - inptr[DCTSIZE*5+inptr_offset] == 0 && inptr[DCTSIZE*6+inptr_offset] == 0 && - inptr[DCTSIZE*7+inptr_offset] == 0) - { - /* AC terms all zero */ - int dcval = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]) << PASS1_BITS; - - wsptr[DCTSIZE*0+wsptr_offset] = dcval; - wsptr[DCTSIZE*1+wsptr_offset] = dcval; - wsptr[DCTSIZE*2+wsptr_offset] = dcval; - wsptr[DCTSIZE*3+wsptr_offset] = dcval; - wsptr[DCTSIZE*4+wsptr_offset] = dcval; - wsptr[DCTSIZE*5+wsptr_offset] = dcval; - wsptr[DCTSIZE*6+wsptr_offset] = dcval; - wsptr[DCTSIZE*7+wsptr_offset] = dcval; - - inptr_offset++; /* advance pointers to next column */ - quantptr_offset++; - wsptr_offset++; - continue; - } - - /* Even part: reverse the even part of the forward DCT. */ - /* The rotator is sqrt(2)*c(-6). */ - - z2 = ((inptr[DCTSIZE*2+inptr_offset]) * quantptr[DCTSIZE*2+quantptr_offset]); - z3 = ((inptr[DCTSIZE*6+inptr_offset]) * quantptr[DCTSIZE*6+quantptr_offset]); - - z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/); - tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/); - tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/); - - z2 = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]); - z3 = ((inptr[DCTSIZE*4+inptr_offset]) * quantptr[DCTSIZE*4+quantptr_offset]); - - tmp0 = (z2 + z3) << CONST_BITS; - tmp1 = (z2 - z3) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - - /* Odd part per figure 8; the matrix is unitary and hence its - * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. - */ - - tmp0 = ((inptr[DCTSIZE*7+inptr_offset]) * quantptr[DCTSIZE*7+quantptr_offset]); - tmp1 = ((inptr[DCTSIZE*5+inptr_offset]) * quantptr[DCTSIZE*5+quantptr_offset]); - tmp2 = ((inptr[DCTSIZE*3+inptr_offset]) * quantptr[DCTSIZE*3+quantptr_offset]); - tmp3 = ((inptr[DCTSIZE*1+inptr_offset]) * quantptr[DCTSIZE*1+quantptr_offset]); - - z1 = tmp0 + tmp3; - z2 = tmp1 + tmp2; - z3 = tmp0 + tmp2; - z4 = tmp1 + tmp3; - z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */ - - tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */ - z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */ - z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */ - z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */ - - z3 += z5; - z4 += z5; - - tmp0 += z1 + z3; - tmp1 += z2 + z4; - tmp2 += z2 + z3; - tmp3 += z1 + z4; - - /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - -// #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) - wsptr[DCTSIZE*0+wsptr_offset] = (((tmp10 + tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*7+wsptr_offset] = (((tmp10 - tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*1+wsptr_offset] = (((tmp11 + tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*6+wsptr_offset] = (((tmp11 - tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*2+wsptr_offset] = (((tmp12 + tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*5+wsptr_offset] = (((tmp12 - tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*3+wsptr_offset] = (((tmp13 + tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - wsptr[DCTSIZE*4+wsptr_offset] = (((tmp13 - tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); - - inptr_offset++; /* advance pointers to next column */ - quantptr_offset++; - wsptr_offset++; - } - - - /* Pass 2: process rows from work array, store into output array. */ - /* Note that we must descale the results by a factor of 8 == 2**3, */ - /* and also undo the PASS1_BITS scaling. */ - - int outptr_offset = 0; - wsptr = workspace; - wsptr_offset =0; - for (ctr = 0; ctr < DCTSIZE; ctr++) { - outptr = output_buf[ctr+output_buf_offset]; - outptr_offset = output_col; - /* Rows of zeroes can be exploited in the same way as we did with columns. - * However, the column calculation has created many nonzero AC terms, so - * the simplification applies less often (typically 5% to 10% of the time). - * On machines with very fast multiplication, it's possible that the - * test takes more time than it's worth. In that case this section - * may be commented out. - */ - -//#ifndef NO_ZERO_ROW_TEST - if (wsptr[1+wsptr_offset] == 0 && wsptr[2+wsptr_offset] == 0 && wsptr[3+wsptr_offset] == 0 && wsptr[4+wsptr_offset] == 0 && - wsptr[5+wsptr_offset] == 0 && wsptr[6+wsptr_offset] == 0 && wsptr[7+wsptr_offset] == 0) - { - /* AC terms all zero */ -// #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) - byte dcval = range_limit[range_limit_offset + ((((wsptr[0+wsptr_offset]) + (1 << ((PASS1_BITS+3)-1))) >> PASS1_BITS+3) - & RANGE_MASK)]; - - outptr[0+outptr_offset] = dcval; - outptr[1+outptr_offset] = dcval; - outptr[2+outptr_offset] = dcval; - outptr[3+outptr_offset] = dcval; - outptr[4+outptr_offset] = dcval; - outptr[5+outptr_offset] = dcval; - outptr[6+outptr_offset] = dcval; - outptr[7+outptr_offset] = dcval; - - wsptr_offset += DCTSIZE; /* advance pointer to next row */ - continue; - } -//#endif - - /* Even part: reverse the even part of the forward DCT. */ - /* The rotator is sqrt(2)*c(-6). */ - - z2 = wsptr[2+wsptr_offset]; - z3 = wsptr[6+wsptr_offset]; - - z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/); - tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/); - tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/); - - tmp0 = (wsptr[0+wsptr_offset] + wsptr[4+wsptr_offset]) << CONST_BITS; - tmp1 = (wsptr[0+wsptr_offset] - wsptr[4+wsptr_offset]) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - - /* Odd part per figure 8; the matrix is unitary and hence its - * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. - */ - - tmp0 = wsptr[7+wsptr_offset]; - tmp1 = wsptr[5+wsptr_offset]; - tmp2 = wsptr[3+wsptr_offset]; - tmp3 = wsptr[1+wsptr_offset]; - - z1 = tmp0 + tmp3; - z2 = tmp1 + tmp2; - z3 = tmp0 + tmp2; - z4 = tmp1 + tmp3; - z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */ - - tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */ - z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */ - z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */ - z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */ - - z3 += z5; - z4 += z5; - - tmp0 += z1 + z3; - tmp1 += z2 + z4; - tmp2 += z2 + z3; - tmp3 += z1 + z4; - - /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - - -// #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) - outptr[0+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 + tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[7+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 - tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[1+outptr_offset] = range_limit[range_limit_offset + ((((tmp11 + tmp2) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[6+outptr_offset] = range_limit[range_limit_offset + ((((tmp11 - tmp2) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[2+outptr_offset] = range_limit[range_limit_offset + ((((tmp12 + tmp1) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[5+outptr_offset] = range_limit[range_limit_offset + ((((tmp12 - tmp1) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[3+outptr_offset] = range_limit[range_limit_offset + ((((tmp13 + tmp0) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - outptr[4+outptr_offset] = range_limit[range_limit_offset + ((((tmp13 - tmp0) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> - CONST_BITS+PASS1_BITS+3) - & RANGE_MASK)]; - - wsptr_offset += DCTSIZE; /* advance pointer to next row */ - } -} - -static void upsample (jpeg_decompress_struct cinfo, - byte[][][] input_buf, int[] input_buf_offset, int[] in_row_group_ctr, - int in_row_groups_avail, - byte[][] output_buf, int[] out_row_ctr, - int out_rows_avail) -{ - sep_upsample(cinfo, input_buf, input_buf_offset, in_row_group_ctr, in_row_groups_avail, output_buf, out_row_ctr, out_rows_avail); -} - -static boolean smoothing_ok (jpeg_decompress_struct cinfo) { - jpeg_d_coef_controller coef = cinfo.coef; - boolean smoothing_useful = false; - int ci, coefi; - jpeg_component_info compptr; - JQUANT_TBL qtable; - int[] coef_bits; - int[] coef_bits_latch; - - if (! cinfo.progressive_mode || cinfo.coef_bits == null) - return false; - - /* Allocate latch area if not already done */ - if (coef.coef_bits_latch == null) - coef.coef_bits_latch = new int[cinfo.num_components * SAVED_COEFS]; - coef_bits_latch = coef.coef_bits_latch; - int coef_bits_latch_offset = 0; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* All components' quantization values must already be latched. */ - if ((qtable = compptr.quant_table) == null) - return false; - /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ - if (qtable.quantval[0] == 0 || - qtable.quantval[Q01_POS] == 0 || - qtable.quantval[Q10_POS] == 0 || - qtable.quantval[Q20_POS] == 0 || - qtable.quantval[Q11_POS] == 0 || - qtable.quantval[Q02_POS] == 0) - return false; - /* DC values must be at least partly known for all components. */ - coef_bits = cinfo.coef_bits[ci]; - if (coef_bits[0] < 0) - return false; - /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ - for (coefi = 1; coefi <= 5; coefi++) { - coef_bits_latch[coefi+coef_bits_latch_offset] = coef_bits[coefi]; - if (coef_bits[coefi] != 0) - smoothing_useful = true; - } - coef_bits_latch_offset += SAVED_COEFS; - } - - return smoothing_useful; -} - -static void master_selection (jpeg_decompress_struct cinfo) { - jpeg_decomp_master master = cinfo.master; - boolean use_c_buffer; - long samplesperrow; - int jd_samplesperrow; - - /* Initialize dimensions and other stuff */ - jpeg_calc_output_dimensions(cinfo); - prepare_range_limit_table(cinfo); - - /* Width of an output scanline must be representable as JDIMENSION. */ - samplesperrow = (long) cinfo.output_width * (long) cinfo.out_color_components; - jd_samplesperrow = (int) samplesperrow; - if ( jd_samplesperrow != samplesperrow) - error(); -// ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); - - /* Initialize my private state */ - master.pass_number = 0; - master.using_merged_upsample = use_merged_upsample(cinfo); - - /* Color quantizer selection */ - master.quantizer_1pass = null; - master.quantizer_2pass = null; - /* No mode changes if not using buffered-image mode. */ - if (! cinfo.quantize_colors || ! cinfo.buffered_image) { - cinfo.enable_1pass_quant = false; - cinfo.enable_external_quant = false; - cinfo.enable_2pass_quant = false; - } - if (cinfo.quantize_colors) { - error(SWT.ERROR_NOT_IMPLEMENTED); -// if (cinfo.raw_data_out) -// ERREXIT(cinfo, JERR_NOTIMPL); -// /* 2-pass quantizer only works in 3-component color space. */ -// if (cinfo.out_color_components != 3) { -// cinfo.enable_1pass_quant = true; -// cinfo.enable_external_quant = false; -// cinfo.enable_2pass_quant = false; -// cinfo.colormap = null; -// } else if (cinfo.colormap != null) { -// cinfo.enable_external_quant = true; -// } else if (cinfo.two_pass_quantize) { -// cinfo.enable_2pass_quant = true; -// } else { -// cinfo.enable_1pass_quant = true; -// } -// -// if (cinfo.enable_1pass_quant) { -//#ifdef QUANT_1PASS_SUPPORTED -// jinit_1pass_quantizer(cinfo); -// master.quantizer_1pass = cinfo.cquantize; -//#else -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif -// } -// -// /* We use the 2-pass code to map to external colormaps. */ -// if (cinfo.enable_2pass_quant || cinfo.enable_external_quant) { -//#ifdef QUANT_2PASS_SUPPORTED -// jinit_2pass_quantizer(cinfo); -// master.quantizer_2pass = cinfo.cquantize; -//#else -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif -// } -// /* If both quantizers are initialized, the 2-pass one is left active; -// * this is necessary for starting with quantization to an external map. -// */ - } - - /* Post-processing: in particular, color conversion first */ - if (! cinfo.raw_data_out) { - if (master.using_merged_upsample) { -//#ifdef UPSAMPLE_MERGING_SUPPORTED -// jinit_merged_upsampler(cinfo); /* does color conversion too */ -//#else - error(); -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif - } else { - jinit_color_deconverter(cinfo); - jinit_upsampler(cinfo); - } - jinit_d_post_controller(cinfo, cinfo.enable_2pass_quant); - } - /* Inverse DCT */ - jinit_inverse_dct(cinfo); - /* Entropy decoding: either Huffman or arithmetic coding. */ - if (cinfo.arith_code) { - error(); -// ERREXIT(cinfo, JERR_ARITH_NOTIMPL); - } else { - if (cinfo.progressive_mode) { -//#ifdef D_PROGRESSIVE_SUPPORTED - jinit_phuff_decoder(cinfo); -//#else -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif - } else - jinit_huff_decoder(cinfo); - } - - /* Initialize principal buffer controllers. */ - use_c_buffer = cinfo.inputctl.has_multiple_scans || cinfo.buffered_image; - jinit_d_coef_controller(cinfo, use_c_buffer); - - if (! cinfo.raw_data_out) - jinit_d_main_controller(cinfo, false /* never need full buffer here */); - - /* Initialize input side of decompressor to consume first scan. */ - start_input_pass (cinfo); - -//#ifdef D_MULTISCAN_FILES_SUPPORTED - /* If jpeg_start_decompress will read the whole file, initialize - * progress monitoring appropriately. The input step is counted - * as one pass. - */ -// if (cinfo.progress != null && ! cinfo.buffered_image && -// cinfo.inputctl.has_multiple_scans) { -// int nscans; -// /* Estimate number of scans to set pass_limit. */ -// if (cinfo.progressive_mode) { -// /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ -// nscans = 2 + 3 * cinfo.num_components; -// } else { -// /* For a nonprogressive multiscan file, estimate 1 scan per component. */ -// nscans = cinfo.num_components; -// } -// cinfo.progress.pass_counter = 0L; -// cinfo.progress.pass_limit = (long) cinfo.total_iMCU_rows * nscans; -// cinfo.progress.completed_passes = 0; -// cinfo.progress.total_passes = (cinfo.enable_2pass_quant ? 3 : 2); -// /* Count the input pass as done */ -// master.pass_number++; -// } -//#endif /* D_MULTISCAN_FILES_SUPPORTED */ -} - -static void jinit_master_decompress (jpeg_decompress_struct cinfo) { - jpeg_decomp_master master = new jpeg_decomp_master(); - cinfo.master = master; -// master.prepare_for_output_pass = prepare_for_output_pass; -// master.finish_output_pass = finish_output_pass; - - master.is_dummy_pass = false; - - master_selection(cinfo); -} - -static void -jcopy_sample_rows (byte[][] input_array, int source_row, - byte[][] output_array, int dest_row, - int num_rows, int num_cols) -/* Copy some rows of samples from one place to another. - * num_rows rows are copied from input_array[source_row++] - * to output_array[dest_row++]; these areas may overlap for duplication. - * The source and destination arrays must be at least as wide as num_cols. - */ -{ - byte[] inptr, outptr; - int count = num_cols; - int row; - - int input_array_offset = source_row; - int output_array_offset = dest_row; - - for (row = num_rows; row > 0; row--) { - inptr = input_array[input_array_offset++]; - outptr = output_array[output_array_offset++]; - System.arraycopy(inptr, 0, outptr, 0, count); - } -} - -static boolean jpeg_start_decompress (jpeg_decompress_struct cinfo) { - if (cinfo.global_state == DSTATE_READY) { - /* First call: initialize master control, select active modules */ - jinit_master_decompress(cinfo); - if (cinfo.buffered_image) { - /* No more work here; expecting jpeg_start_output next */ - cinfo.global_state = DSTATE_BUFIMAGE; - return true; - } - cinfo.global_state = DSTATE_PRELOAD; - } - if (cinfo.global_state == DSTATE_PRELOAD) { - /* If file has multiple scans, absorb them all into the coef buffer */ - if (cinfo.inputctl.has_multiple_scans) { -//#ifdef D_MULTISCAN_FILES_SUPPORTED - for (;;) { - int retcode; - /* Call progress monitor hook if present */ -// if (cinfo.progress != null) -// (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); - /* Absorb some more input */ - retcode = consume_input (cinfo); - if (retcode == JPEG_SUSPENDED) - return false; - if (retcode == JPEG_REACHED_EOI) - break; - /* Advance progress counter if appropriate */ -// if (cinfo.progress != null && (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { -// if (++cinfo.progress.pass_counter >= cinfo.progress.pass_limit) { -// /* jdmaster underestimated number of scans; ratchet up one scan */ -// cinfo.progress.pass_limit += (long) cinfo.total_iMCU_rows; -// } -// } - } -//#else -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif /* D_MULTISCAN_FILES_SUPPORTED */ - } - cinfo.output_scan_number = cinfo.input_scan_number; - } else if (cinfo.global_state != DSTATE_PRESCAN) - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - /* Perform any dummy output passes, and set up for the final pass */ - return output_pass_setup(cinfo); -} - -static void prepare_for_output_pass (jpeg_decompress_struct cinfo) { - jpeg_decomp_master master = cinfo.master; - - if (master.is_dummy_pass) { -//#ifdef QUANT_2PASS_SUPPORTED -// /* Final pass of 2-pass quantization */ -// master.pub.is_dummy_pass = FALSE; -// (*cinfo.cquantize.start_pass) (cinfo, FALSE); -// (*cinfo.post.start_pass) (cinfo, JBUF_CRANK_DEST); -// (*cinfo.main.start_pass) (cinfo, JBUF_CRANK_DEST); -//#else - error(SWT.ERROR_NOT_IMPLEMENTED); -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif /* QUANT_2PASS_SUPPORTED */ - } else { - if (cinfo.quantize_colors && cinfo.colormap == null) { - /* Select new quantization method */ - if (cinfo.two_pass_quantize && cinfo.enable_2pass_quant) { - cinfo.cquantize = master.quantizer_2pass; - master.is_dummy_pass = true; - } else if (cinfo.enable_1pass_quant) { - cinfo.cquantize = master.quantizer_1pass; - } else { - error(); -// ERREXIT(cinfo, JERR_MODE_CHANGE); - } - } - cinfo.idct.start_pass (cinfo); - start_output_pass (cinfo); - if (! cinfo.raw_data_out) { - if (! master.using_merged_upsample) - cinfo.cconvert.start_pass (cinfo); - cinfo.upsample.start_pass (cinfo); - if (cinfo.quantize_colors) - cinfo.cquantize.start_pass (cinfo, master.is_dummy_pass); - cinfo.post.start_pass (cinfo, (master.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); - cinfo.main.start_pass (cinfo, JBUF_PASS_THRU); - } - } - -// /* Set up progress monitor's pass info if present */ -// if (cinfo.progress != NULL) { -// cinfo.progress.completed_passes = master.pass_number; -// cinfo.progress.total_passes = master.pass_number + -// (master.pub.is_dummy_pass ? 2 : 1); -// /* In buffered-image mode, we assume one more output pass if EOI not -// * yet reached, but no more passes if EOI has been reached. -// */ -// if (cinfo.buffered_image && ! cinfo.inputctl.eoi_reached) { -// cinfo.progress.total_passes += (cinfo.enable_2pass_quant ? 2 : 1); -// } -// } -} - - -static boolean jpeg_resync_to_restart (jpeg_decompress_struct cinfo, int desired) { - int marker = cinfo.unread_marker; - int action = 1; - - /* Always put up a warning. */ -// WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired); - - /* Outer loop handles repeated decision after scanning forward. */ - for (;;) { - if (marker < M_SOF0) - action = 2; /* invalid marker */ - else if (marker < M_RST0 || marker > M_RST7) - action = 3; /* valid non-restart marker */ - else { - if (marker == (M_RST0 + ((desired+1) & 7)) || marker == ( M_RST0 + ((desired+2) & 7))) - action = 3; /* one of the next two expected restarts */ - else if (marker == (M_RST0 + ((desired-1) & 7)) || marker == ( M_RST0 + ((desired-2) & 7))) - action = 2; /* a prior restart, so advance */ - else - action = 1; /* desired restart or too far away */ - } -// TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action); - switch (action) { - case 1: - /* Discard marker and let entropy decoder resume processing. */ - cinfo.unread_marker = 0; - return true; - case 2: - /* Scan to the next marker, and repeat the decision loop. */ - if (! next_marker(cinfo)) - return false; - marker = cinfo.unread_marker; - break; - case 3: - /* Return without advancing past this marker. */ - /* Entropy decoder will be forced to process an empty segment. */ - return true; - } - } /* end loop */ -} - -static boolean read_restart_marker (jpeg_decompress_struct cinfo) { - /* Obtain a marker unless we already did. */ - /* Note that next_marker will complain if it skips any data. */ - if (cinfo.unread_marker == 0) { - if (! next_marker(cinfo)) - return false; - } - - if (cinfo.unread_marker == (M_RST0 + cinfo.marker.next_restart_num)) { - /* Normal case --- swallow the marker and let entropy decoder continue */ -// TRACEMS1(cinfo, 3, JTRC_RST, cinfo.marker.next_restart_num); - cinfo.unread_marker = 0; - } else { - /* Uh-oh, the restart markers have been messed up. */ - /* Let the data source manager determine how to resync. */ - if (! jpeg_resync_to_restart (cinfo, cinfo.marker.next_restart_num)) - return false; - } - - /* Update next-restart state */ - cinfo.marker.next_restart_num = (cinfo.marker.next_restart_num + 1) & 7; - - return true; -} - -static boolean jpeg_fill_bit_buffer (bitread_working_state state, int get_buffer, int bits_left, int nbits) -/* Load up the bit buffer to a depth of at least nbits */ -{ - /* Copy heavily used state fields into locals (hopefully registers) */ - byte[] buffer = state.buffer; - int bytes_in_buffer = state.bytes_in_buffer; - int bytes_offset = state.bytes_offset; - jpeg_decompress_struct cinfo = state.cinfo; - - /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */ - /* (It is assumed that no request will be for more than that many bits.) */ - /* We fail to do so only if we hit a marker or are forced to suspend. */ - - if (cinfo.unread_marker == 0) { /* cannot advance past a marker */ - while (bits_left < MIN_GET_BITS) { - int c; - - /* Attempt to read a byte */ - if (bytes_offset == bytes_in_buffer) { - if (! fill_input_buffer (cinfo)) - return false; - buffer = cinfo.buffer; - bytes_in_buffer = cinfo.bytes_in_buffer; - bytes_offset = cinfo.bytes_offset; - } - c = buffer[bytes_offset++] & 0xFF; - - /* If it's 0xFF, check and discard stuffed zero byte */ - if (c == 0xFF) { - /* Loop here to discard any padding FF's on terminating marker, - * so that we can save a valid unread_marker value. NOTE: we will - * accept multiple FF's followed by a 0 as meaning a single FF data - * byte. This data pattern is not valid according to the standard. - */ - do { - if (bytes_offset == bytes_in_buffer) { - if (! fill_input_buffer (cinfo)) - return false; - buffer = cinfo.buffer; - bytes_in_buffer = cinfo.bytes_in_buffer; - bytes_offset = cinfo.bytes_offset; - } - c = buffer[bytes_offset++] & 0xFF; - } while (c == 0xFF); - - if (c == 0) { - /* Found FF/00, which represents an FF data byte */ - c = 0xFF; - } else { - /* Oops, it's actually a marker indicating end of compressed data. - * Save the marker code for later use. - * Fine point: it might appear that we should save the marker into - * bitread working state, not straight into permanent state. But - * once we have hit a marker, we cannot need to suspend within the - * current MCU, because we will read no more bytes from the data - * source. So it is OK to update permanent state right away. - */ - cinfo.unread_marker = c; - /* See if we need to insert some fake zero bits. */ -// goto no_more_bytes; - if (nbits > bits_left) { - /* Uh-oh. Report corrupted data to user and stuff zeroes into - * the data stream, so that we can produce some kind of image. - * We use a nonvolatile flag to ensure that only one warning message - * appears per data segment. - */ - if (! cinfo.entropy.insufficient_data) { -// WARNMS(cinfo, JWRN_HIT_MARKER); - cinfo.entropy.insufficient_data = true; - } - /* Fill the buffer with zero bits */ - get_buffer <<= MIN_GET_BITS - bits_left; - bits_left = MIN_GET_BITS; - } - - /* Unload the local registers */ - state.buffer = buffer; - state.bytes_in_buffer = bytes_in_buffer; - state.bytes_offset = bytes_offset; - state.get_buffer = get_buffer; - state.bits_left = bits_left; - - return true; - - } - } - - /* OK, load c into get_buffer */ - get_buffer = (get_buffer << 8) | c; - bits_left += 8; - } /* end while */ - } else { -// no_more_bytes: - /* We get here if we've read the marker that terminates the compressed - * data segment. There should be enough bits in the buffer register - * to satisfy the request; if so, no problem. - */ - if (nbits > bits_left) { - /* Uh-oh. Report corrupted data to user and stuff zeroes into - * the data stream, so that we can produce some kind of image. - * We use a nonvolatile flag to ensure that only one warning message - * appears per data segment. - */ - if (! cinfo.entropy.insufficient_data) { -// WARNMS(cinfo, JWRN_HIT_MARKER); - cinfo.entropy.insufficient_data = true; - } - /* Fill the buffer with zero bits */ - get_buffer <<= MIN_GET_BITS - bits_left; - bits_left = MIN_GET_BITS; - } - } - - /* Unload the local registers */ - state.buffer = buffer; - state.bytes_in_buffer = bytes_in_buffer; - state.bytes_offset = bytes_offset; - state.get_buffer = get_buffer; - state.bits_left = bits_left; - - return true; -} - -static int jpeg_huff_decode (bitread_working_state state, int get_buffer, int bits_left, d_derived_tbl htbl, int min_bits) { - int l = min_bits; - int code; - - /* HUFF_DECODE has determined that the code is at least min_bits */ - /* bits long, so fetch that many bits in one swoop. */ - -// CHECK_BIT_BUFFER(*state, l, return -1); - { - if (bits_left < (l)) { - if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,l)) { - return -1; - } - get_buffer = (state).get_buffer; bits_left = (state).bits_left; - } - } -// code = GET_BITS(l); - code = (( (get_buffer >> (bits_left -= (l)))) & ((1<<(l))-1)); - - /* Collect the rest of the Huffman code one bit at a time. */ - /* This is per Figure F.16 in the JPEG spec. */ - - while (code > htbl.maxcode[l]) { - code <<= 1; -// CHECK_BIT_BUFFER(*state, 1, return -1); - { - if (bits_left < (1)) { - if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,1)) { - return -1; - } - get_buffer = (state).get_buffer; bits_left = (state).bits_left; - } - } -// code |= GET_BITS(1); - code |= (( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)); - l++; - } - - /* Unload the local registers */ - state.get_buffer = get_buffer; - state.bits_left = bits_left; - - /* With garbage input we may reach the sentinel value l = 17. */ - - if (l > 16) { -// WARNMS(state.cinfo, JWRN_HUFF_BAD_CODE); - return 0; /* fake a zero as the safest result */ - } - - return htbl.pub.huffval[ (code + htbl.valoffset[l]) ] & 0xFF; -} - -static int decompress_onepass (jpeg_decompress_struct cinfo, byte[][][] output_buf, int[] output_buf_offset) { - jpeg_d_coef_controller coef = cinfo.coef; - int MCU_col_num; /* index of current MCU within row */ - int last_MCU_col = cinfo.MCUs_per_row - 1; - int last_iMCU_row = cinfo.total_iMCU_rows - 1; - int blkn, ci, xindex, yindex, yoffset, useful_width; - byte[][] output_ptr; - int start_col, output_col; - jpeg_component_info compptr; -// inverse_DCT_method_ptr inverse_DCT; - - /* Loop to process as much as one whole iMCU row */ - for (yoffset = coef.MCU_vert_offset; yoffset < coef.MCU_rows_per_iMCU_row; yoffset++) { - for (MCU_col_num = coef.MCU_ctr; MCU_col_num <= last_MCU_col; MCU_col_num++) { - /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ - for (int i = 0; i < cinfo.blocks_in_MCU; i++) { - short[] blk = coef.MCU_buffer[i]; - for (int j = 0; j < blk.length; j++) { - blk[j] = 0; - } - } - if (! cinfo.entropy.decode_mcu (cinfo, coef.MCU_buffer)) { - /* Suspension forced; update state counters and exit */ - coef.MCU_vert_offset = yoffset; - coef.MCU_ctr = MCU_col_num; - return JPEG_SUSPENDED; - } - /* Determine where data should go in output_buf and do the IDCT thing. - * We skip dummy blocks at the right and bottom edges (but blkn gets - * incremented past them!). Note the inner loop relies on having - * allocated the MCU_buffer[] blocks sequentially. - */ - blkn = 0; /* index of current DCT block within MCU */ - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - compptr = cinfo.cur_comp_info[ci]; - /* Don't bother to IDCT an uninteresting component. */ - if (! compptr.component_needed) { - blkn += compptr.MCU_blocks; - continue; - } -// inverse_DCT = cinfo.idct.inverse_DCT[compptr.component_index]; - useful_width = (MCU_col_num < last_MCU_col) ? compptr.MCU_width : compptr.last_col_width; - output_ptr = output_buf[compptr.component_index]; - int output_ptr_offset = output_buf_offset[compptr.component_index] + yoffset * compptr.DCT_scaled_size; - start_col = MCU_col_num * compptr.MCU_sample_width; - for (yindex = 0; yindex < compptr.MCU_height; yindex++) { - if (cinfo.input_iMCU_row < last_iMCU_row || yoffset+yindex < compptr.last_row_height) { - output_col = start_col; - for (xindex = 0; xindex < useful_width; xindex++) { - jpeg_idct_islow(cinfo, compptr, coef.MCU_buffer[blkn+xindex], output_ptr, output_ptr_offset, output_col); - output_col += compptr.DCT_scaled_size; - } - } - blkn += compptr.MCU_width; - output_ptr_offset += compptr.DCT_scaled_size; - } - } - } - /* Completed an MCU row, but perhaps not an iMCU row */ - coef.MCU_ctr = 0; - } - /* Completed the iMCU row, advance counters for next one */ - cinfo.output_iMCU_row++; - if (++(cinfo.input_iMCU_row) < cinfo.total_iMCU_rows) { - coef.start_iMCU_row(cinfo); - return JPEG_ROW_COMPLETED; - } - /* Completed the scan */ - finish_input_pass (cinfo); - return JPEG_SCAN_COMPLETED; -} - -static int decompress_smooth_data (jpeg_decompress_struct cinfo, byte[][][] output_buf, int[] output_buf_offset) { - jpeg_d_coef_controller coef = cinfo.coef; - int last_iMCU_row = cinfo.total_iMCU_rows - 1; - int block_num, last_block_column; - int ci, block_row, block_rows, access_rows; - short[][][] buffer; - short[][] buffer_ptr, prev_block_row, next_block_row; - byte[][] output_ptr; - int output_col; - jpeg_component_info compptr; -// inverse_DCT_method_ptr inverse_DCT; - boolean first_row, last_row; - short[] workspace = coef.workspace; - if (workspace == null) workspace = coef.workspace = new short[DCTSIZE2]; - int[] coef_bits; - JQUANT_TBL quanttbl; - int Q00,Q01,Q02,Q10,Q11,Q20, num; - int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; - int Al, pred; - - /* Force some input to be done if we are getting ahead of the input. */ - while (cinfo.input_scan_number <= cinfo.output_scan_number && ! cinfo.inputctl.eoi_reached) { - if (cinfo.input_scan_number == cinfo.output_scan_number) { - /* If input is working on current scan, we ordinarily want it to - * have completed the current row. But if input scan is DC, - * we want it to keep one row ahead so that next block row's DC - * values are up to date. - */ - int delta = (cinfo.Ss == 0) ? 1 : 0; - if (cinfo.input_iMCU_row > cinfo.output_iMCU_row+delta) - break; - } - if (consume_input(cinfo) == JPEG_SUSPENDED) - return JPEG_SUSPENDED; - } - - /* OK, output from the virtual arrays. */ - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Don't bother to IDCT an uninteresting component. */ - if (! compptr.component_needed) - continue; - /* Count non-dummy DCT block rows in this iMCU row. */ - if (cinfo.output_iMCU_row < last_iMCU_row) { - block_rows = compptr.v_samp_factor; - access_rows = block_rows * 2; /* this and next iMCU row */ - last_row = false; - } else { - /* NB: can't use last_row_height here; it is input-side-dependent! */ - block_rows = (compptr.height_in_blocks % compptr.v_samp_factor); - if (block_rows == 0) block_rows = compptr.v_samp_factor; - access_rows = block_rows; /* this iMCU row only */ - last_row = true; - } - /* Align the virtual buffer for this component. */ - int buffer_offset; - if (cinfo.output_iMCU_row > 0) { - access_rows += compptr.v_samp_factor; /* prior iMCU row too */ - buffer = coef.whole_image[ci]; - buffer_offset = (cinfo.output_iMCU_row - 1) * compptr.v_samp_factor; - buffer_offset += compptr.v_samp_factor; /* point to current iMCU row */ - first_row = false; - } else { - buffer = coef.whole_image[ci]; - buffer_offset = 0; - first_row = true; - } - /* Fetch component-dependent info */ - coef_bits = coef.coef_bits_latch; - int coef_offset = (ci * SAVED_COEFS); - quanttbl = compptr.quant_table; - Q00 = quanttbl.quantval[0]; - Q01 = quanttbl.quantval[Q01_POS]; - Q10 = quanttbl.quantval[Q10_POS]; - Q20 = quanttbl.quantval[Q20_POS]; - Q11 = quanttbl.quantval[Q11_POS]; - Q02 = quanttbl.quantval[Q02_POS]; -// inverse_DCT = cinfo.idct.inverse_DCT[ci]; - output_ptr = output_buf[ci]; - int output_ptr_offset = output_buf_offset[ci]; - /* Loop over all DCT blocks to be processed. */ - for (block_row = 0; block_row < block_rows; block_row++) { - buffer_ptr = buffer[block_row+buffer_offset]; - int buffer_ptr_offset = 0, prev_block_row_offset = 0, next_block_row_offset = 0; - if (first_row && block_row == 0) { - prev_block_row = buffer_ptr; - prev_block_row_offset = buffer_ptr_offset; - } else { - prev_block_row = buffer[block_row-1+buffer_offset]; - prev_block_row_offset = 0; - } - if (last_row && block_row == block_rows-1) { - next_block_row = buffer_ptr; - next_block_row_offset = buffer_ptr_offset; - } else { - next_block_row = buffer[block_row+1+buffer_offset]; - next_block_row_offset = 0; - } - /* We fetch the surrounding DC values using a sliding-register approach. - * Initialize all nine here so as to do the right thing on narrow pics. - */ - DC1 = DC2 = DC3 = prev_block_row[0+prev_block_row_offset][0]; - DC4 = DC5 = DC6 = buffer_ptr[0+buffer_ptr_offset][0]; - DC7 = DC8 = DC9 = next_block_row[0+next_block_row_offset][0]; - output_col = 0; - last_block_column = compptr.width_in_blocks - 1; - for (block_num = 0; block_num <= last_block_column; block_num++) { - /* Fetch current DCT block into workspace so we can modify it. */ -// jcopy_block_row(buffer_ptr, workspace, 1); - System.arraycopy(buffer_ptr[buffer_ptr_offset], 0, workspace, 0, workspace.length); - /* Update DC values */ - if (block_num < last_block_column) { - DC3 = prev_block_row[1+prev_block_row_offset][0]; - DC6 = buffer_ptr[1+buffer_ptr_offset][0]; - DC9 = next_block_row[1+next_block_row_offset][0]; - } - /* Compute coefficient estimates per K.8. - * An estimate is applied only if coefficient is still zero, - * and is not known to be fully accurate. - */ - /* AC01 */ - if ((Al=coef_bits[1+coef_offset]) != 0 && workspace[1] == 0) { - num = 36 * Q00 * (DC4 - DC6); - if (num >= 0) { - pred = (((Q01<<7) + num) / (Q01<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - } else { - pred = (((Q01<<7) - num) / (Q01<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - pred = -pred; - } - workspace[1] = (short) pred; - } - /* AC10 */ - if ((Al=coef_bits[2+coef_offset]) != 0 && workspace[8] == 0) { - num = 36 * Q00 * (DC2 - DC8); - if (num >= 0) { - pred = (((Q10<<7) + num) / (Q10<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - } else { - pred = (((Q10<<7) - num) / (Q10<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - pred = -pred; - } - workspace[8] = (short) pred; - } - /* AC20 */ - if ((Al=coef_bits[3+coef_offset]) != 0 && workspace[16] == 0) { - num = 9 * Q00 * (DC2 + DC8 - 2*DC5); - if (num >= 0) { - pred = (((Q20<<7) + num) / (Q20<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - } else { - pred = (((Q20<<7) - num) / (Q20<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - pred = -pred; - } - workspace[16] = (short) pred; - } - /* AC11 */ - if ((Al=coef_bits[4+coef_offset]) != 0 && workspace[9] == 0) { - num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); - if (num >= 0) { - pred = (((Q11<<7) + num) / (Q11<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - } else { - pred = (((Q11<<7) - num) / (Q11<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - pred = -pred; - } - workspace[9] = (short) pred; - } - /* AC02 */ - if ((Al=coef_bits[5+coef_offset]) != 0 && workspace[2] == 0) { - num = 9 * Q00 * (DC4 + DC6 - 2*DC5); - if (num >= 0) { - pred = (((Q02<<7) + num) / (Q02<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - } else { - pred = (((Q02<<7) - num) / (Q02<<8)); - if (Al > 0 && pred >= (1<<Al)) - pred = (1<<Al)-1; - pred = -pred; - } - workspace[2] = (short) pred; - } - /* OK, do the IDCT */ - jpeg_idct_islow(cinfo, compptr, workspace, output_ptr, output_ptr_offset, output_col); - /* Advance for next column */ - DC1 = DC2; DC2 = DC3; - DC4 = DC5; DC5 = DC6; - DC7 = DC8; DC8 = DC9; - buffer_ptr_offset++; prev_block_row_offset++; next_block_row_offset++; - output_col += compptr.DCT_scaled_size; - } - output_ptr_offset += compptr.DCT_scaled_size; - } - } - - if (++(cinfo.output_iMCU_row) < cinfo.total_iMCU_rows) - return JPEG_ROW_COMPLETED; - return JPEG_SCAN_COMPLETED; -} - -static int decompress_data (jpeg_decompress_struct cinfo, byte[][][] output_buf, int[] output_buf_offset) { - jpeg_d_coef_controller coef = cinfo.coef; - int last_iMCU_row = cinfo.total_iMCU_rows - 1; - int block_num; - int ci, block_row, block_rows; - short[][][] buffer; - short[][] buffer_ptr; - byte[][] output_ptr; - int output_col; - jpeg_component_info compptr; -// inverse_DCT_method_ptr inverse_DCT; - - /* Force some input to be done if we are getting ahead of the input. */ - while (cinfo.input_scan_number < cinfo.output_scan_number || - (cinfo.input_scan_number == cinfo.output_scan_number && - cinfo.input_iMCU_row <= cinfo.output_iMCU_row)) - { - if (consume_input(cinfo) == JPEG_SUSPENDED) - return JPEG_SUSPENDED; - } - - /* OK, output from the virtual arrays. */ - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Don't bother to IDCT an uninteresting component. */ - if (! compptr.component_needed) - continue; - /* Align the virtual buffer for this component. */ - buffer = coef.whole_image[ci]; - int buffer_offset = cinfo.output_iMCU_row * compptr.v_samp_factor; - /* Count non-dummy DCT block rows in this iMCU row. */ - if (cinfo.output_iMCU_row < last_iMCU_row) - block_rows = compptr.v_samp_factor; - else { - /* NB: can't use last_row_height here; it is input-side-dependent! */ - block_rows = (compptr.height_in_blocks % compptr.v_samp_factor); - if (block_rows == 0) block_rows = compptr.v_samp_factor; - } -// inverse_DCT = cinfo.idct.inverse_DCT[ci]; - output_ptr = output_buf[ci]; - int output_ptr_offset = output_buf_offset[ci]; - /* Loop over all DCT blocks to be processed. */ - for (block_row = 0; block_row < block_rows; block_row++) { - buffer_ptr = buffer[block_row+buffer_offset]; - int buffer_ptr_offset = 0; - output_col = 0; - for (block_num = 0; block_num < compptr.width_in_blocks; block_num++) { - jpeg_idct_islow(cinfo, compptr, buffer_ptr[buffer_ptr_offset], output_ptr, output_ptr_offset, output_col); - - buffer_ptr_offset++; - output_col += compptr.DCT_scaled_size; - } - output_ptr_offset += compptr.DCT_scaled_size; - } - } - - if (++(cinfo.output_iMCU_row) < cinfo.total_iMCU_rows) - return JPEG_ROW_COMPLETED; - return JPEG_SCAN_COMPLETED; -} - -static void post_process_data (jpeg_decompress_struct cinfo, - byte[][][] input_buf, int[] input_buf_offset, int[] in_row_group_ctr, - int in_row_groups_avail, - byte[][] output_buf, int[] out_row_ctr, - int out_rows_avail) -{ - upsample(cinfo, input_buf, input_buf_offset, in_row_group_ctr, in_row_groups_avail, output_buf, out_row_ctr, out_rows_avail); -} - -static void set_bottom_pointers (jpeg_decompress_struct cinfo) -/* Change the pointer lists to duplicate the last sample row at the bottom - * of the image. whichptr indicates which xbuffer holds the final iMCU row. - * Also sets rowgroups_avail to indicate number of nondummy row groups in row. - */ -{ - jpeg_d_main_controller main = cinfo.main; - int ci, i, rgroup, iMCUheight, rows_left; - jpeg_component_info compptr; - byte[][] xbuf; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Count sample rows in one iMCU row and in one row group */ - iMCUheight = compptr.v_samp_factor * compptr.DCT_scaled_size; - rgroup = iMCUheight / cinfo.min_DCT_scaled_size; - /* Count nondummy sample rows remaining for this component */ - rows_left = (compptr.downsampled_height % iMCUheight); - if (rows_left == 0) rows_left = iMCUheight; - /* Count nondummy row groups. Should get same answer for each component, - * so we need only do it once. - */ - if (ci == 0) { - main.rowgroups_avail = ((rows_left-1) / rgroup + 1); - } - /* Duplicate the last real sample row rgroup*2 times; this pads out the - * last partial rowgroup and ensures at least one full rowgroup of context. - */ - xbuf = main.xbuffer[main.whichptr][ci]; - int xbuf_offset = main.xbuffer_offset[main.whichptr][ci]; - for (i = 0; i < rgroup * 2; i++) { - xbuf[rows_left + i + xbuf_offset] = xbuf[rows_left-1 + xbuf_offset]; - } - } -} - -static void set_wraparound_pointers (jpeg_decompress_struct cinfo) -/* Set up the "wraparound" pointers at top and bottom of the pointer lists. - * This changes the pointer list state from top-of-image to the normal state. - */ -{ - jpeg_d_main_controller main = cinfo.main; - int ci, i, rgroup; - int M = cinfo.min_DCT_scaled_size; - jpeg_component_info compptr; - byte[][] xbuf0, xbuf1; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ - xbuf0 = main.xbuffer[0][ci]; - int xbuf0_offset = main.xbuffer_offset[0][ci]; - xbuf1 = main.xbuffer[1][ci]; - int xbuf1_offset = main.xbuffer_offset[1][ci]; - for (i = 0; i < rgroup; i++) { - xbuf0[i - rgroup + xbuf0_offset] = xbuf0[rgroup*(M+1) + i + xbuf0_offset]; - xbuf1[i - rgroup + xbuf1_offset] = xbuf1[rgroup*(M+1) + i + xbuf1_offset]; - xbuf0[rgroup*(M+2) + i + xbuf0_offset] = xbuf0[i + xbuf0_offset]; - xbuf1[rgroup*(M+2) + i + xbuf1_offset] = xbuf1[i + xbuf1_offset]; - } - } -} - -static void process_data_crank_post (jpeg_decompress_struct cinfo, - byte[][] output_buf, int[] out_row_ctr, - int out_rows_avail) -{ - error(); -} - -static void process_data_context_main (jpeg_decompress_struct cinfo, - byte[][] output_buf, int[] out_row_ctr, - int out_rows_avail) -{ - jpeg_d_main_controller main = cinfo.main; - - /* Read input data if we haven't filled the main buffer yet */ - if (! main.buffer_full) { - int result; - switch (cinfo.coef.decompress_data) { - case DECOMPRESS_DATA: - result = decompress_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); - break; - case DECOMPRESS_SMOOTH_DATA: - result = decompress_smooth_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); - break; - case DECOMPRESS_ONEPASS: - result = decompress_onepass(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); - break; - default: result = 0; - } - if (result == 0) - return; /* suspension forced, can do nothing more */ - main.buffer_full = true; /* OK, we have an iMCU row to work with */ - main.iMCU_row_ctr++; /* count rows received */ - } - - /* Postprocessor typically will not swallow all the input data it is handed - * in one call (due to filling the output buffer first). Must be prepared - * to exit and restart. This switch lets us keep track of how far we got. - * Note that each case falls through to the next on successful completion. - */ - switch (main.context_state) { - case CTX_POSTPONED_ROW: - /* Call postprocessor using previously set pointers for postponed row */ - post_process_data (cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr], main.rowgroup_ctr, main.rowgroups_avail, output_buf, out_row_ctr, out_rows_avail); - if (main.rowgroup_ctr[0] < main.rowgroups_avail) - return; /* Need to suspend */ - main.context_state = CTX_PREPARE_FOR_IMCU; - if (out_row_ctr[0] >= out_rows_avail) - return; /* Postprocessor exactly filled output buf */ - /*FALLTHROUGH*/ - case CTX_PREPARE_FOR_IMCU: - /* Prepare to process first M-1 row groups of this iMCU row */ - main.rowgroup_ctr[0] = 0; - main.rowgroups_avail = (cinfo.min_DCT_scaled_size - 1); - /* Check for bottom of image: if so, tweak pointers to "duplicate" - * the last sample row, and adjust rowgroups_avail to ignore padding rows. - */ - if (main.iMCU_row_ctr == cinfo.total_iMCU_rows) - set_bottom_pointers(cinfo); - main.context_state = CTX_PROCESS_IMCU; - /*FALLTHROUGH*/ - case CTX_PROCESS_IMCU: - /* Call postprocessor using previously set pointers */ - post_process_data (cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr], main.rowgroup_ctr, main.rowgroups_avail, output_buf, out_row_ctr, out_rows_avail); - if (main.rowgroup_ctr[0] < main.rowgroups_avail) - return; /* Need to suspend */ - /* After the first iMCU, change wraparound pointers to normal state */ - if (main.iMCU_row_ctr == 1) - set_wraparound_pointers(cinfo); - /* Prepare to load new iMCU row using other xbuffer list */ - main.whichptr ^= 1; /* 0=>1 or 1=>0 */ - main.buffer_full = false; - /* Still need to process last row group of this iMCU row, */ - /* which is saved at index M+1 of the other xbuffer */ - main.rowgroup_ctr[0] = (cinfo.min_DCT_scaled_size + 1); - main.rowgroups_avail = (cinfo.min_DCT_scaled_size + 2); - main.context_state = CTX_POSTPONED_ROW; - } -} - -static void process_data_simple_main (jpeg_decompress_struct cinfo, byte[][] output_buf, int[] out_row_ctr, int out_rows_avail) { - jpeg_d_main_controller main = cinfo.main; - int rowgroups_avail; - - /* Read input data if we haven't filled the main buffer yet */ - if (! main.buffer_full) { - int result; - switch (cinfo.coef.decompress_data) { - case DECOMPRESS_DATA: - result = decompress_data(cinfo, main.buffer, main.buffer_offset); - break; - case DECOMPRESS_SMOOTH_DATA: - result = decompress_smooth_data(cinfo, main.buffer, main.buffer_offset); - break; - case DECOMPRESS_ONEPASS: - result = decompress_onepass(cinfo, main.buffer, main.buffer_offset); - break; - default: result = 0; - } - if (result == 0) - return; /* suspension forced, can do nothing more */ - main.buffer_full = true; /* OK, we have an iMCU row to work with */ - } - - /* There are always min_DCT_scaled_size row groups in an iMCU row. */ - rowgroups_avail = cinfo.min_DCT_scaled_size; - /* Note: at the bottom of the image, we may pass extra garbage row groups - * to the postprocessor. The postprocessor has to check for bottom - * of image anyway (at row resolution), so no point in us doing it too. - */ - - /* Feed the postprocessor */ - post_process_data (cinfo, main.buffer, main.buffer_offset, main.rowgroup_ctr, rowgroups_avail, output_buf, out_row_ctr, out_rows_avail); - - /* Has postprocessor consumed all the data yet? If so, mark buffer empty */ - if (main.rowgroup_ctr[0] >= rowgroups_avail) { - main.buffer_full = false; - main.rowgroup_ctr[0] = 0; - } -} - -static int jpeg_read_scanlines (jpeg_decompress_struct cinfo, byte[][] scanlines, int max_lines) { - - if (cinfo.global_state != DSTATE_SCANNING) - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - if (cinfo.output_scanline >= cinfo.output_height) { -// WARNMS(cinfo, JWRN_TOO_MUCH_DATA); - return 0; - } - - /* Call progress monitor hook if present */ -// if (cinfo.progress != NULL) { -// cinfo.progress.pass_counter = (long) cinfo.output_scanline; -// cinfo.progress.pass_limit = (long) cinfo.output_height; -// (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); -// } - - /* Process some data */ - cinfo.row_ctr[0] = 0; - switch (cinfo.main.process_data) { - case PROCESS_DATA_SIMPLE_MAIN: - process_data_simple_main (cinfo, scanlines, cinfo.row_ctr, max_lines); - break; - case PROCESS_DATA_CONTEXT_MAIN: - process_data_context_main (cinfo, scanlines, cinfo.row_ctr, max_lines); - break; - case PROCESS_DATA_CRANK_POST: - process_data_crank_post (cinfo, scanlines, cinfo.row_ctr, max_lines); - break; - default: error(); - } - cinfo.output_scanline += cinfo.row_ctr[0]; - return cinfo.row_ctr[0]; -} - - -static boolean output_pass_setup (jpeg_decompress_struct cinfo) { - if (cinfo.global_state != DSTATE_PRESCAN) { - /* First call: do pass setup */ - prepare_for_output_pass (cinfo); - cinfo.output_scanline = 0; - cinfo.global_state = DSTATE_PRESCAN; - } - /* Loop over any required dummy passes */ - while (cinfo.master.is_dummy_pass) { - error(); -//#ifdef QUANT_2PASS_SUPPORTED -// /* Crank through the dummy pass */ -// while (cinfo.output_scanline < cinfo.output_height) { -// JDIMENSION last_scanline; -// /* Call progress monitor hook if present */ -// if (cinfo.progress != NULL) { -// cinfo.progress.pass_counter = (long) cinfo.output_scanline; -// cinfo.progress.pass_limit = (long) cinfo.output_height; -// (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); -// } -// /* Process some data */ -// last_scanline = cinfo.output_scanline; -// (*cinfo.main.process_data) (cinfo, (JSAMPARRAY) NULL, -// &cinfo.output_scanline, (JDIMENSION) 0); -// if (cinfo.output_scanline == last_scanline) -// return FALSE; /* No progress made, must suspend */ -// } -// /* Finish up dummy pass, and set up for another one */ -// (*cinfo.master.finish_output_pass) (cinfo); -// (*cinfo.master.prepare_for_output_pass) (cinfo); -// cinfo.output_scanline = 0; -//#else -// ERREXIT(cinfo, JERR_NOT_COMPILED); -//#endif /* QUANT_2PASS_SUPPORTED */ - } - /* Ready for application to drive output pass through - * jpeg_read_scanlines or jpeg_read_raw_data. - */ - cinfo.global_state = cinfo.raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING; - return true; -} - -static boolean get_dht (jpeg_decompress_struct cinfo) -/* Process a DHT marker */ -{ - int length; - byte[] bits = new byte[17]; - byte[] huffval = new byte[256]; - int i, index, count; - JHUFF_TBL htblptr; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - length -= 2; - - while (length > 16) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - -// TRACEMS1(cinfo, 1, JTRC_DHT, index); - - bits[0] = 0; - count = 0; - for (i = 1; i <= 16; i++) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - bits[i] = cinfo.buffer[cinfo.bytes_offset++]; - count += bits[i] & 0xFF; - } - - length -= 1 + 16; - -// TRACEMS8(cinfo, 2, JTRC_HUFFBITS, -// bits[1], bits[2], bits[3], bits[4], -// bits[5], bits[6], bits[7], bits[8]); -// TRACEMS8(cinfo, 2, JTRC_HUFFBITS, -// bits[9], bits[10], bits[11], bits[12], -// bits[13], bits[14], bits[15], bits[16]); - - /* Here we just do minimal validation of the counts to avoid walking - * off the end of our table space. jdhuff.c will check more carefully. - */ - if (count > 256 || (count) > length) - error(); -// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); - - for (i = 0; i < count; i++) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - huffval[i] = cinfo.buffer[cinfo.bytes_offset++]; - } - - length -= count; - - if ((index & 0x10) != 0) { /* AC table definition */ - index -= 0x10; - htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL(); - } else { /* DC table definition */ - htblptr = cinfo.dc_huff_tbl_ptrs[index] = new JHUFF_TBL(); - } - - if (index < 0 || index >= NUM_HUFF_TBLS) - error(); -// ERREXIT1(cinfo, JERR_DHT_INDEX, index); - - System.arraycopy(bits, 0, htblptr.bits, 0, bits.length); - System.arraycopy(huffval, 0, htblptr.huffval, 0, huffval.length); - } - - if (length != 0) - error(); -// ERREXIT(cinfo, JERR_BAD_LENGTH); - - return true; -} - - -static boolean get_dqt (jpeg_decompress_struct cinfo) -/* Process a DQT marker */ -{ - int length; - int n, i, prec; - int tmp; - JQUANT_TBL quant_ptr; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - length -= 2; - - while (length > 0) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - n = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - prec = n >> 4; - n &= 0x0F; - -// TRACEMS2(cinfo, 1, JTRC_DQT, n, prec); - - if (n >= NUM_QUANT_TBLS) - error(); -// ERREXIT1(cinfo, JERR_DQT_INDEX, n); - - if (cinfo.quant_tbl_ptrs[n] == null) - cinfo.quant_tbl_ptrs[n] = new JQUANT_TBL(); - quant_ptr = cinfo.quant_tbl_ptrs[n]; - - for (i = 0; i < DCTSIZE2; i++) { - if (prec != 0) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - tmp = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - tmp |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - } else { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - tmp = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - } - /* We convert the zigzag-order table to natural array order. */ - quant_ptr.quantval[jpeg_natural_order[i]] = (short) tmp; - } - -// if (cinfo.err.trace_level >= 2) { -// for (i = 0; i < DCTSIZE2; i += 8) { -// TRACEMS8(cinfo, 2, JTRC_QUANTVALS, -// quant_ptr.quantval[i], quant_ptr.quantval[i+1], -// quant_ptr.quantval[i+2], quant_ptr.quantval[i+3], -// quant_ptr.quantval[i+4], quant_ptr.quantval[i+5], -// quant_ptr.quantval[i+6], quant_ptr.quantval[i+7]); -// } -// } - - length -= (DCTSIZE2+1); - if (prec != 0) length -= DCTSIZE2; - } - - if (length != 0) - error(); -// ERREXIT(cinfo, JERR_BAD_LENGTH); - - return true; -} - -static boolean get_dri (jpeg_decompress_struct cinfo) -/* Process a DRI marker */ -{ - int length; - int tmp; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - if (length != 4) - error(); -// ERREXIT(cinfo, JERR_BAD_LENGTH); - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - tmp = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - tmp |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - -// TRACEMS1(cinfo, 1, JTRC_DRI, tmp); - - cinfo.restart_interval = tmp; - - return true; -} - -static boolean get_dac (jpeg_decompress_struct cinfo) -/* Process a DAC marker */ -{ - int length; - int index, val; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - length -= 2; - - while (length > 0) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - val = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - length -= 2; - -// TRACEMS2(cinfo, 1, JTRC_DAC, index, val); - - if (index < 0 || index >= (2*NUM_ARITH_TBLS)) - error(); -// ERREXIT1(cinfo, JERR_DAC_INDEX, index); - - if (index >= NUM_ARITH_TBLS) { /* define AC table */ - cinfo.arith_ac_K[index-NUM_ARITH_TBLS] = (byte) val; - } else { /* define DC table */ - cinfo.arith_dc_L[index] = (byte) (val & 0x0F); - cinfo.arith_dc_U[index] = (byte) (val >> 4); - if (cinfo.arith_dc_L[index] > cinfo.arith_dc_U[index]) - error(); -// ERREXIT1(cinfo, JERR_DAC_VALUE, val); - } - } - - if (length != 0) - error(); -// ERREXIT(cinfo, JERR_BAD_LENGTH); - - return true; -} - - -static boolean get_sos (jpeg_decompress_struct cinfo) -/* Process a SOS marker */ -{ - int length; - int i, ci, n, c, cc; - jpeg_component_info compptr = null; - - if (! cinfo.marker.saw_SOF) - error(); -// ERREXIT(cinfo, JERR_SOS_NO_SOF); - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - n = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - -// TRACEMS1(cinfo, 1, JTRC_SOS, n); - - if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN) - error(); -// ERREXIT(cinfo, JERR_BAD_LENGTH); - - cinfo.comps_in_scan = n; - - /* Collect the component-spec parameters */ - - for (i = 0; i < n; i++) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cc = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - if (cc == compptr.component_id) - break; - } - - if (ci == cinfo.num_components) - error(); -// ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); - - cinfo.cur_comp_info[i] = compptr; - compptr.dc_tbl_no = (c >> 4) & 15; - compptr.ac_tbl_no = (c ) & 15; - -// TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, compptr.dc_tbl_no, compptr.ac_tbl_no); - } - - /* Collect the additional scan parameters Ss, Se, Ah/Al. */ - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - cinfo.Ss = c; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - cinfo.Se = c; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - cinfo.Ah = (c >> 4) & 15; - cinfo.Al = (c ) & 15; - -// TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo.Ss, cinfo.Se, cinfo.Ah, cinfo.Al); - - /* Prepare to scan data & restart markers */ - cinfo.marker.next_restart_num = 0; - - /* Count another SOS marker */ - cinfo.input_scan_number++; - - return true; -} - -static boolean get_sof (jpeg_decompress_struct cinfo, boolean is_prog, boolean is_arith) { - int length; - int c, ci; - - cinfo.progressive_mode = is_prog; - cinfo.arith_code = is_arith; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cinfo.data_precision = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cinfo.image_height = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cinfo.image_height |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cinfo.image_width = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cinfo.image_width |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - length -= 8; - -// TRACEMS4(cinfo, 1, JTRC_SOF, cinfo.unread_marker, -// (int) cinfo.image_width, (int) cinfo.image_height, -// cinfo.num_components); - - if (cinfo.marker.saw_SOF) - error(); -// ERREXIT(cinfo, JERR_SOF_DUPLICATE); - - /* We don't support files in which the image height is initially specified */ - /* as 0 and is later redefined by DNL. As long as we have to check that, */ - /* might as well have a general sanity check. */ - if (cinfo.image_height <= 0 || cinfo.image_width <= 0 || cinfo.num_components <= 0) - error(); -// ERREXIT(cinfo, JERR_EMPTY_IMAGE); - - if (length != (cinfo.num_components * 3)) - error(); -// ERREXIT(cinfo, JERR_BAD_LENGTH); - - if (cinfo.comp_info == null) /* do only once, even if suspend */ - cinfo.comp_info = new jpeg_component_info[cinfo.num_components]; - - for (ci = 0; ci < cinfo.num_components; ci++) { - jpeg_component_info compptr = cinfo.comp_info[ci] = new jpeg_component_info(); - compptr.component_index = ci; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - compptr.component_id = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - compptr.h_samp_factor = (c >> 4) & 15; - compptr.v_samp_factor = (c ) & 15; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - compptr.quant_tbl_no = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - -// TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT, -// compptr.component_id, compptr.h_samp_factor, -// compptr.v_samp_factor, compptr.quant_tbl_no); - } - - cinfo.marker.saw_SOF = true; - - return true; -} - -static void sep_upsample (jpeg_decompress_struct cinfo, byte[][][] input_buf, int[] input_buf_offset, - int[] in_row_group_ctr, int in_row_groups_avail, - byte[][] output_buf, int[] out_row_ctr, int out_rows_avail) -{ - jpeg_upsampler upsample = cinfo.upsample; - int ci; - jpeg_component_info compptr; - int num_rows; - - /* Fill the conversion buffer, if it's empty */ - if (upsample.next_row_out >= cinfo.max_v_samp_factor) { - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - /* Invoke per-component upsample method. Notice we pass a POINTER - * to color_buf[ci], so that fullsize_upsample can change it. - */ - int offset = input_buf_offset[ci] + (in_row_group_ctr[0] * upsample.rowgroup_height[ci]); - switch (upsample.methods[ci]) { - case NOOP_UPSAMPLE: noop_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - case FULLSIZE_UPSAMPLE: fullsize_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - case H2V1_FANCY_UPSAMPLE: h2v1_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - case H2V1_UPSAMPLE: h2v1_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - case H2V2_FANCY_UPSAMPLE: h2v2_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - case H2V2_UPSAMPLE: h2v2_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - case INT_UPSAMPLE: int_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; - } - } - upsample.next_row_out = 0; - } - - /* Color-convert and emit rows */ - - /* How many we have in the buffer: */ - num_rows = (cinfo.max_v_samp_factor - upsample.next_row_out); - /* Not more than the distance to the end of the image. Need this test - * in case the image height is not a multiple of max_v_samp_factor: - */ - if (num_rows > upsample.rows_to_go) - num_rows = upsample.rows_to_go; - /* And not more than what the client can accept: */ - out_rows_avail -= out_row_ctr[0]; - if (num_rows > out_rows_avail) - num_rows = out_rows_avail; - - switch (cinfo.cconvert.color_convert) { - case NULL_CONVERT: null_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; - case GRAYSCALE_CONVERT: grayscale_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; - case YCC_RGB_CONVERT: ycc_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; - case GRAY_RGB_CONVERT: gray_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; - case YCCK_CMYK_CONVERT: error(); break; - } - - /* Adjust counts */ - out_row_ctr[0] += num_rows; - upsample.rows_to_go -= num_rows; - upsample.next_row_out += num_rows; - /* When the buffer is emptied, declare this input row group consumed */ - if (upsample.next_row_out >= cinfo.max_v_samp_factor) { - in_row_group_ctr[0]++; - } -} - -static void noop_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - output_data_ptr[output_data_index] = null; /* safety check */ -} - -static void fullsize_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - output_data_ptr[output_data_index] = input_data; - output_data_offset[output_data_index] = input_data_offset; -} - -static void h2v1_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - byte[][] output_data = output_data_ptr[output_data_index]; - byte[] inptr, outptr; - byte invalue; - int outend; - int inrow; - output_data_offset[output_data_index] = 0; - - for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) { - inptr = input_data[inrow+input_data_offset]; - outptr = output_data[inrow]; - int inptr_offset = 0, outptr_offset = 0; - outend = outptr_offset + cinfo.output_width; - while (outptr_offset < outend) { - invalue = inptr[inptr_offset++]; /* don't need GETJSAMPLE() here */ - outptr[outptr_offset++] = invalue; - outptr[outptr_offset++] = invalue; - } - } -} - -static void h2v2_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - byte[][] output_data = output_data_ptr[output_data_index]; - byte[] inptr, outptr; - byte invalue; - int outend; - int inrow, outrow; - output_data_offset[output_data_index] = 0; - - inrow = outrow = 0; - while (outrow < cinfo.max_v_samp_factor) { - inptr = input_data[inrow+input_data_offset]; - outptr = output_data[outrow]; - int inptr_offset = 0, outptr_offset = 0; - outend = outptr_offset + cinfo.output_width; - while (outptr_offset < outend) { - invalue = inptr[inptr_offset++]; /* don't need GETJSAMPLE() here */ - outptr[outptr_offset++] = invalue; - outptr[outptr_offset++] = invalue; - } - jcopy_sample_rows(output_data, outrow, output_data, outrow+1, 1, cinfo.output_width); - inrow++; - outrow += 2; - } -} - -static void h2v1_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - byte[][] output_data = output_data_ptr[output_data_index]; - byte[] inptr, outptr; - int invalue; - int colctr; - int inrow; - output_data_offset[output_data_index] = 0; - - for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) { - inptr = input_data[inrow+input_data_offset]; - outptr = output_data[inrow]; - int inptr_offset = 0, outptr_offset = 0; - /* Special case for first column */ - invalue = inptr[inptr_offset++] & 0xFF; - outptr[outptr_offset++] = (byte) invalue; - outptr[outptr_offset++] = (byte) ((invalue * 3 + (inptr[inptr_offset] & 0xFF) + 2) >> 2); - - for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) { - /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ - invalue = (inptr[inptr_offset++] & 0xFF) * 3; - outptr[outptr_offset++] = (byte) ((invalue + (inptr[inptr_offset-2] & 0xFF) + 1) >> 2); - outptr[outptr_offset++] = (byte) ((invalue + (inptr[inptr_offset] & 0xFF) + 2) >> 2); - } - - /* Special case for last column */ - invalue = (inptr[inptr_offset] & 0xFF); - outptr[outptr_offset++] = (byte) ((invalue * 3 + (inptr[inptr_offset-1] & 0xFF) + 1) >> 2); - outptr[outptr_offset++] = (byte) invalue; - } -} - -static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - byte[][] output_data = output_data_ptr[output_data_index]; - byte[] inptr0, inptr1, outptr; - int thiscolsum, lastcolsum, nextcolsum; - int colctr; - int inrow, outrow, v; - output_data_offset[output_data_index] = 0; - - inrow = outrow = 0; - while (outrow < cinfo.max_v_samp_factor) { - for (v = 0; v < 2; v++) { - /* inptr0 points to nearest input row, inptr1 points to next nearest */ - inptr0 = input_data[inrow+input_data_offset]; - if (v == 0) /* next nearest is row above */ - inptr1 = input_data[inrow-1+input_data_offset]; - else /* next nearest is row below */ - inptr1 = input_data[inrow+1+input_data_offset]; - outptr = output_data[outrow++]; - - int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0; - - /* Special case for first column */ - thiscolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); - nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); - outptr[outptr_offset++] = (byte) ((thiscolsum * 4 + 8) >> 4); - outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4); - lastcolsum = thiscolsum; thiscolsum = nextcolsum; - - for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) { - /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ - /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ - nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); - outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4); - outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4); - lastcolsum = thiscolsum; thiscolsum = nextcolsum; - } - - /* Special case for last column */ - outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4); - outptr[outptr_offset++] = (byte) ((thiscolsum * 4 + 7) >> 4); - } - inrow++; - } -} - -static void int_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, - byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) -{ - jpeg_upsampler upsample = cinfo.upsample; - byte[][] output_data = output_data_ptr[output_data_index]; - byte[] inptr, outptr; - byte invalue; - int h; - int outend; - int h_expand, v_expand; - int inrow, outrow; - output_data_offset[output_data_index] = 0; - - h_expand = upsample.h_expand[compptr.component_index]; - v_expand = upsample.v_expand[compptr.component_index]; - - inrow = outrow = 0; - while (outrow < cinfo.max_v_samp_factor) { - /* Generate one output row with proper horizontal expansion */ - inptr = input_data[inrow+input_data_offset]; - int inptr_offset = 0; - outptr = output_data[outrow]; - int outptr_offset = 0; - outend = outptr_offset + cinfo.output_width; - while (outptr_offset < outend) { - invalue = inptr[inptr_offset++]; /* don't need GETJSAMPLE() here */ - for (h = h_expand; h > 0; h--) { - outptr[outptr_offset++] = invalue; - } - } - /* Generate any additional output rows by duplicating the first one */ - if (v_expand > 1) { - jcopy_sample_rows(output_data, outrow, output_data, outrow+1, v_expand-1, cinfo.output_width); - } - inrow++; - outrow += v_expand; - } -} - -static void null_convert (jpeg_decompress_struct cinfo, - byte[][][] input_buf, int[] input_buf_offset, int input_row, - byte[][] output_buf, int output_buf_offset, int num_rows) -{ - byte[] inptr, outptr; - int count; - int num_components = cinfo.num_components; - int num_cols = cinfo.output_width; - int ci; - - while (--num_rows >= 0) { - for (ci = 0; ci < num_components; ci++) { - inptr = input_buf[ci][input_row+input_buf_offset[0]]; - outptr = output_buf[output_buf_offset]; - /* BGR instead of RGB */ - int offset = 0; - switch (ci) { - case 2: offset = RGB_BLUE; break; - case 1: offset = RGB_GREEN; break; - case 0: offset = RGB_RED; break; - } - int outptr_offset = offset, inptr_offset = 0; - for (count = num_cols; count > 0; count--) { - outptr[outptr_offset] = inptr[inptr_offset++]; /* needn't bother with GETJSAMPLE() here */ - outptr_offset += num_components; - } - } - input_row++; - output_buf_offset++; - } -} - -static void grayscale_convert (jpeg_decompress_struct cinfo, - byte[][][] input_buf, int[] input_buf_offset, int input_row, - byte[][] output_buf, int output_buf_offset, int num_rows) -{ - jcopy_sample_rows(input_buf[0], input_row+input_buf_offset[0], output_buf, output_buf_offset, - num_rows, cinfo.output_width); -} - -static void gray_rgb_convert (jpeg_decompress_struct cinfo, - byte[][][] input_buf, int[] input_buf_offset, int input_row, - byte[][] output_buf, int output_buf_offset, int num_rows) -{ - byte[] inptr, outptr; - int col; - int num_cols = cinfo.output_width; - - while (--num_rows >= 0) { - inptr = input_buf[0][input_row+++input_buf_offset[0]]; - outptr = output_buf[output_buf_offset++]; - int outptr_offset = 0; - for (col = 0; col < num_cols; col++) { - /* We can dispense with GETJSAMPLE() here */ - outptr[RGB_RED+outptr_offset] = outptr[RGB_GREEN+outptr_offset] = outptr[RGB_BLUE+outptr_offset] = inptr[col]; - outptr_offset += RGB_PIXELSIZE; - } - } -} - -static void ycc_rgb_convert (jpeg_decompress_struct cinfo, - byte[][][] input_buf, int[] input_buf_offset, int input_row, - byte[][] output_buf, int output_buf_offset, int num_rows) -{ - jpeg_color_deconverter cconvert = cinfo.cconvert; - int y, cb, cr; - byte[] outptr; - byte[] inptr0, inptr1, inptr2; - int col; - int num_cols = cinfo.output_width; - /* copy these pointers into registers if possible */ - byte[] range_limit = cinfo.sample_range_limit; - int range_limit_offset = cinfo.sample_range_limit_offset; - int[] Crrtab = cconvert.Cr_r_tab; - int[] Cbbtab = cconvert.Cb_b_tab; - int[] Crgtab = cconvert.Cr_g_tab; - int[] Cbgtab = cconvert.Cb_g_tab; -// SHIFT_TEMPS - - while (--num_rows >= 0) { - inptr0 = input_buf[0][input_row+input_buf_offset[0]]; - inptr1 = input_buf[1][input_row+input_buf_offset[1]]; - inptr2 = input_buf[2][input_row+input_buf_offset[2]]; - input_row++; - outptr = output_buf[output_buf_offset++]; - int outptr_offset = 0; - for (col = 0; col < num_cols; col++) { - y = (inptr0[col] & 0xFF); - cb = (inptr1[col] & 0xFF); - cr = (inptr2[col] & 0xFF); - /* Range-limiting is essential due to noise introduced by DCT losses. */ - outptr[outptr_offset + RGB_RED] = range_limit[y + Crrtab[cr] + range_limit_offset]; - outptr[outptr_offset + RGB_GREEN] = range_limit[y + ((Cbgtab[cb] + Crgtab[cr]>>SCALEBITS)) + range_limit_offset]; - outptr[outptr_offset + RGB_BLUE] = range_limit[y + Cbbtab[cb] + range_limit_offset]; - outptr_offset += RGB_PIXELSIZE; - } - } -} - -static boolean process_APPn(int n, jpeg_decompress_struct cinfo) { - if (n == 0 || n == 14) { - return get_interesting_appn(cinfo); - } - return skip_variable(cinfo); -} - -static boolean process_COM(jpeg_decompress_struct cinfo) { - return skip_variable(cinfo); -} - -static void skip_input_data (jpeg_decompress_struct cinfo, int num_bytes) { - if (num_bytes > 0) { - while (num_bytes > cinfo.bytes_in_buffer - cinfo.bytes_offset) { - num_bytes -= cinfo.bytes_in_buffer - cinfo.bytes_offset; - if (!fill_input_buffer(cinfo)) error(); - /* note we assume that fill_input_buffer will never return FALSE, - * so suspension need not be handled. - */ - } - cinfo.bytes_offset += num_bytes; - } -} - -static boolean skip_variable (jpeg_decompress_struct cinfo) -/* Skip over an unknown or uninteresting variable-length marker */ -{ - int length; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - - length -= 2; - -// TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, (int) length); - - if (length > 0) { - skip_input_data (cinfo, length); - } - - return true; -} - -static boolean get_interesting_appn (jpeg_decompress_struct cinfo) -/* Process an APP0 or APP14 marker without saving it */ -{ - int length; - byte[] b = new byte[APPN_DATA_LEN]; - int i, numtoread; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - length -= 2; - - /* get the interesting part of the marker data */ - if (length >= APPN_DATA_LEN) - numtoread = APPN_DATA_LEN; - else if (length > 0) - numtoread = length; - else - numtoread = 0; - for (i = 0; i < numtoread; i++) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - b[i] = cinfo.buffer[cinfo.bytes_offset++]; - } - length -= numtoread; - - /* process it */ - switch (cinfo.unread_marker) { - case M_APP0: - examine_app0(cinfo, b, numtoread, length); - break; - case M_APP14: - examine_app14(cinfo, b, numtoread, length); - break; - default: - /* can't get here unless jpeg_save_markers chooses wrong processor */ - error(); -// ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo.unread_marker); - break; - } - - /* skip any remaining data -- could be lots */ - if (length > 0) - skip_input_data (cinfo, length); - - return true; -} - -static void examine_app0 (jpeg_decompress_struct cinfo, byte[] data, int datalen, int remaining) -/* Examine first few bytes from an APP0. - * Take appropriate action if it is a JFIF marker. - * datalen is # of bytes at data[], remaining is length of rest of marker data. - */ -{ - int totallen = datalen + remaining; - - if (datalen >= APP0_DATA_LEN && - (data[0] & 0xFF) == 0x4A && - (data[1] & 0xFF) == 0x46 && - (data[2] & 0xFF) == 0x49 && - (data[3] & 0xFF) == 0x46 && - (data[4] & 0xFF) == 0) - { - /* Found JFIF APP0 marker: save info */ - cinfo.saw_JFIF_marker = true; - cinfo.JFIF_major_version = (data[5]); - cinfo.JFIF_minor_version = (byte)(data[6] & 0xFF); - cinfo.density_unit = (byte)(data[7] & 0xFF); - cinfo.X_density = (short)(((data[8] & 0xFF) << 8) + (data[9] & 0xFF)); - cinfo.Y_density = (short)(((data[10] & 0xFF) << 8) + (data[11] & 0xFF)); - /* Check version. - * Major version must be 1, anything else signals an incompatible change. - * (We used to treat this as an error, but now it's a nonfatal warning, - * because some bozo at Hijaak couldn't read the spec.) - * Minor version should be 0..2, but process anyway if newer. - */ - if (cinfo.JFIF_major_version != 1) { -// WARNMS2(cinfo, JWRN_JFIF_MAJOR, -// cinfo.JFIF_major_version, cinfo.JFIF_minor_version); - } - /* Generate trace messages */ -// TRACEMS5(cinfo, 1, JTRC_JFIF, -// cinfo.JFIF_major_version, cinfo.JFIF_minor_version, -// cinfo.X_density, cinfo.Y_density, cinfo.density_unit); - /* Validate thumbnail dimensions and issue appropriate messages */ - if (((data[12] & 0xFF) | (data[13]) & 0xFF) != 0) { -// TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, -// GETJOCTET(data[12]), GETJOCTET(data[13])); - } - totallen -= APP0_DATA_LEN; - if (totallen != ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { -// TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen); - } - } else if (datalen >= 6 && - (data[0] & 0xFF) == 0x4A && - (data[1] & 0xFF) == 0x46 && - (data[2] & 0xFF) == 0x58 && - (data[3] & 0xFF) == 0x58 && - (data[4] & 0xFF) == 0) - { - /* Found JFIF "JFXX" extension APP0 marker */ - /* The library doesn't actually do anything with these, - * but we try to produce a helpful trace message. - */ - switch ((data[5]) & 0xFF) { - case 0x10: -// TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen); - break; - case 0x11: -// TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen); - break; - case 0x13: -// TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen); - break; - default: -// TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, GETJOCTET(data[5]), (int) totallen); - break; - } - } else { - /* Start of APP0 does not match "JFIF" or "JFXX", or too short */ -// TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen); - } -} - -static void examine_app14 (jpeg_decompress_struct cinfo, byte[] data, int datalen, int remaining) -/* Examine first few bytes from an APP14. - * Take appropriate action if it is an Adobe marker. - * datalen is # of bytes at data[], remaining is length of rest of marker data. - */ -{ - int /*version, flags0, flags1, */transform; - - if (datalen >= APP14_DATA_LEN && - (data[0] & 0xFF) == 0x41 && - (data[1] & 0xFF) == 0x64 && - (data[2] & 0xFF) == 0x6F && - (data[3] & 0xFF) == 0x62 && - (data[4] & 0xFF) == 0x65) - { - /* Found Adobe APP14 marker */ -// version = ((data[5] & 0xFF) << 8) + (data[6] & 0xFF); -// flags0 = ((data[7] & 0xFF) << 8) + (data[8] & 0xFF); -// flags1 = ((data[9] & 0xFF) << 8) + (data[10] & 0xFF); - transform = (data[11] & 0xFF); -// TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); - cinfo.saw_Adobe_marker = true; - cinfo.Adobe_transform = (byte) transform; - } else { - /* Start of APP14 does not match "Adobe", or too short */ -// TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining)); - } -} - -static boolean get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ { - int i; - -// TRACEMS(cinfo, 1, JTRC_SOI); - - if (cinfo.marker.saw_SOI) - error(); -// ERREXIT(cinfo, JERR_SOI_DUPLICATE); - - /* Reset all parameters that are defined to be reset by SOI */ - - for (i = 0; i < NUM_ARITH_TBLS; i++) { - cinfo.arith_dc_L[i] = 0; - cinfo.arith_dc_U[i] = 1; - cinfo.arith_ac_K[i] = 5; - } - cinfo.restart_interval = 0; - - /* Set initial assumptions for colorspace etc */ - - cinfo.jpeg_color_space = JCS_UNKNOWN; - cinfo.CCIR601_sampling = false; /* Assume non-CCIR sampling??? */ - - cinfo.saw_JFIF_marker = false; - cinfo.JFIF_major_version = 1; /* set default JFIF APP0 values */ - cinfo.JFIF_minor_version = 1; - cinfo.density_unit = 0; - cinfo.X_density = 1; - cinfo.Y_density = 1; - cinfo.saw_Adobe_marker = false; - cinfo.Adobe_transform = 0; - - cinfo.marker.saw_SOI = true; - - return true; -} - -static void jinit_input_controller (jpeg_decompress_struct cinfo) -{ - /* Initialize state: can't use reset_input_controller since we don't - * want to try to reset other modules yet. - */ - jpeg_input_controller inputctl = cinfo.inputctl = new jpeg_input_controller(); - inputctl.has_multiple_scans = false; /* "unknown" would be better */ - inputctl.eoi_reached = false; - inputctl.inheaders = true; -} - -static void reset_marker_reader (jpeg_decompress_struct cinfo) { - jpeg_marker_reader marker = cinfo.marker; - - cinfo.comp_info = null; /* until allocated by get_sof */ - cinfo.input_scan_number = 0; /* no SOS seen yet */ - cinfo.unread_marker = 0; /* no pending marker */ - marker.saw_SOI = false; /* set internal state too */ - marker.saw_SOF = false; - marker.discarded_bytes = 0; -// marker.cur_marker = null; -} - -static void reset_input_controller (jpeg_decompress_struct cinfo) { - jpeg_input_controller inputctl = cinfo.inputctl; - - inputctl.has_multiple_scans = false; /* "unknown" would be better */ - inputctl.eoi_reached = false; - inputctl.inheaders = true; - /* Reset other modules */ - reset_marker_reader (cinfo); - /* Reset progression state -- would be cleaner if entropy decoder did this */ - cinfo.coef_bits = null; -} - -static void finish_output_pass (jpeg_decompress_struct cinfo) { - jpeg_decomp_master master = cinfo.master; - - if (cinfo.quantize_colors) { - error(SWT.ERROR_NOT_IMPLEMENTED); -// (*cinfo.cquantize.finish_pass) (cinfo); - } - master.pass_number++; -} - -static void jpeg_destroy (jpeg_decompress_struct cinfo) { - /* We need only tell the memory manager to release everything. */ - /* NB: mem pointer is NULL if memory mgr failed to initialize. */ -// if (cinfo.mem != NULL) -// (*cinfo.mem.self_destruct) (cinfo); -// cinfo.mem = NULL; /* be safe if jpeg_destroy is called twice */ - cinfo.global_state = 0; /* mark it destroyed */ -} - -static void jpeg_destroy_decompress (jpeg_decompress_struct cinfo) { - jpeg_destroy(cinfo); /* use common routine */ -} - -static boolean jpeg_input_complete (jpeg_decompress_struct cinfo) { - /* Check for valid jpeg object */ - if (cinfo.global_state < DSTATE_START || cinfo.global_state > DSTATE_STOPPING) - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - return cinfo.inputctl.eoi_reached; -} - -static boolean jpeg_start_output (jpeg_decompress_struct cinfo, int scan_number) { - if (cinfo.global_state != DSTATE_BUFIMAGE && cinfo.global_state != DSTATE_PRESCAN) - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - /* Limit scan number to valid range */ - if (scan_number <= 0) - scan_number = 1; - if (cinfo.inputctl.eoi_reached && scan_number > cinfo.input_scan_number) - scan_number = cinfo.input_scan_number; - cinfo.output_scan_number = scan_number; - /* Perform any dummy output passes, and set up for the real pass */ - return output_pass_setup(cinfo); -} - -static boolean jpeg_finish_output (jpeg_decompress_struct cinfo) { - if ((cinfo.global_state == DSTATE_SCANNING || cinfo.global_state == DSTATE_RAW_OK) && cinfo.buffered_image) { - /* Terminate this pass. */ - /* We do not require the whole pass to have been completed. */ - finish_output_pass (cinfo); - cinfo.global_state = DSTATE_BUFPOST; - } else if (cinfo.global_state != DSTATE_BUFPOST) { - /* BUFPOST = repeat call after a suspension, anything else is error */ - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - } - /* Read markers looking for SOS or EOI */ - while (cinfo.input_scan_number <= cinfo.output_scan_number && !cinfo.inputctl.eoi_reached) { - if (consume_input (cinfo) == JPEG_SUSPENDED) - return false; /* Suspend, come back later */ - } - cinfo.global_state = DSTATE_BUFIMAGE; - return true; -} - -static boolean jpeg_finish_decompress (jpeg_decompress_struct cinfo) { - if ((cinfo.global_state == DSTATE_SCANNING || cinfo.global_state == DSTATE_RAW_OK) && ! cinfo.buffered_image) { - /* Terminate final pass of non-buffered mode */ - if (cinfo.output_scanline < cinfo.output_height) - error(); -// ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); - finish_output_pass (cinfo); - cinfo.global_state = DSTATE_STOPPING; - } else if (cinfo.global_state == DSTATE_BUFIMAGE) { - /* Finishing after a buffered-image operation */ - cinfo.global_state = DSTATE_STOPPING; - } else if (cinfo.global_state != DSTATE_STOPPING) { - /* STOPPING = repeat call after a suspension, anything else is error */ - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - } - /* Read until EOI */ - while (! cinfo.inputctl.eoi_reached) { - if (consume_input (cinfo) == JPEG_SUSPENDED) - return false; /* Suspend, come back later */ - } - /* Do final cleanup */ -// (*cinfo.src.term_source) (cinfo); - /* We can use jpeg_abort to release memory and reset global_state */ - jpeg_abort(cinfo); - return true; -} - - -static int jpeg_read_header (jpeg_decompress_struct cinfo, boolean require_image) { - int retcode; - - if (cinfo.global_state != DSTATE_START && cinfo.global_state != DSTATE_INHEADER) - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - - retcode = jpeg_consume_input(cinfo); - - switch (retcode) { - case JPEG_REACHED_SOS: - retcode = JPEG_HEADER_OK; - break; - case JPEG_REACHED_EOI: - if (require_image) /* Complain if application wanted an image */ - error(); -// ERREXIT(cinfo, JERR_NO_IMAGE); - /* Reset to start state; it would be safer to require the application to - * call jpeg_abort, but we can't change it now for compatibility reasons. - * A side effect is to free any temporary memory (there shouldn't be any). - */ - jpeg_abort(cinfo); /* sets state = DSTATE_START */ - retcode = JPEG_HEADER_TABLES_ONLY; - break; - case JPEG_SUSPENDED: - /* no work */ - break; - } - - return retcode; -} - -static int dummy_consume_data (jpeg_decompress_struct cinfo) { - return JPEG_SUSPENDED; /* Always indicate nothing was done */ -} - -static int consume_data (jpeg_decompress_struct cinfo) { - jpeg_d_coef_controller coef = cinfo.coef; - int MCU_col_num; /* index of current MCU within row */ - int blkn, ci, xindex, yindex, yoffset; - int start_col; -// short[][][][] buffer = new short[MAX_COMPS_IN_SCAN][][][]; - short[][] buffer_ptr; - jpeg_component_info compptr; - -// /* Align the virtual buffers for the components used in this scan. */ -// for (ci = 0; ci < cinfo.comps_in_scan; ci++) { -// compptr = cinfo.cur_comp_info[ci]; -// buffer[ci] = coef.whole_image[compptr.component_index]; -// /* Note: entropy decoder expects buffer to be zeroed, -// * but this is handled automatically by the memory manager -// * because we requested a pre-zeroed array. -// */ -// } - - /* Loop to process one whole iMCU row */ - for (yoffset = coef.MCU_vert_offset; yoffset < coef.MCU_rows_per_iMCU_row; yoffset++) { - for (MCU_col_num = coef.MCU_ctr; MCU_col_num < cinfo.MCUs_per_row; MCU_col_num++) { - /* Construct list of pointers to DCT blocks belonging to this MCU */ - blkn = 0; /* index of current DCT block within MCU */ - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - compptr = cinfo.cur_comp_info[ci]; - start_col = MCU_col_num * compptr.MCU_width; - for (yindex = 0; yindex < compptr.MCU_height; yindex++) { -// buffer_ptr = buffer[ci][yindex+yoffset] + start_col; - buffer_ptr = coef.whole_image[compptr.component_index][yindex+yoffset+cinfo.input_iMCU_row*compptr.v_samp_factor]; - int buffer_ptr_offset = start_col; - for (xindex = 0; xindex < compptr.MCU_width; xindex++) { - coef.MCU_buffer[blkn++] = buffer_ptr[buffer_ptr_offset++]; - } - } - } - /* Try to fetch the MCU. */ - if (! cinfo.entropy.decode_mcu (cinfo, coef.MCU_buffer)) { - /* Suspension forced; update state counters and exit */ - coef.MCU_vert_offset = yoffset; - coef.MCU_ctr = MCU_col_num; - return JPEG_SUSPENDED; - } - } - /* Completed an MCU row, but perhaps not an iMCU row */ - coef.MCU_ctr = 0; - } - /* Completed the iMCU row, advance counters for next one */ - if (++(cinfo.input_iMCU_row) < cinfo.total_iMCU_rows) { - coef.start_iMCU_row(cinfo); - return JPEG_ROW_COMPLETED; - } - /* Completed the scan */ - finish_input_pass (cinfo); - return JPEG_SCAN_COMPLETED; -} - -static int consume_input (jpeg_decompress_struct cinfo) { - switch (cinfo.inputctl.consume_input) { - case COEF_CONSUME_INPUT: - switch (cinfo.coef.consume_data) { - case CONSUME_DATA: return consume_data(cinfo); - case DUMMY_CONSUME_DATA: return dummy_consume_data(cinfo); - default: error(); - } - break; - case INPUT_CONSUME_INPUT: - return consume_markers(cinfo); - default: - error(); - } - return 0; -} - -static boolean fill_input_buffer(jpeg_decompress_struct cinfo) { - try { - InputStream inputStream = cinfo.inputStream; - int nbytes = inputStream.read(cinfo.buffer); - if (nbytes <= 0) { - if (cinfo.start_of_file) /* Treat empty input file as fatal error */ - error(); -// ERREXIT(cinfo, JERR_INPUT_EMPTY); -// WARNMS(cinfo, JWRN_JPEG_EOF); - /* Insert a fake EOI marker */ - cinfo.buffer[0] = (byte)0xFF; - cinfo.buffer[1] = (byte)M_EOI; - nbytes = 2; - } - cinfo.bytes_in_buffer = nbytes; - cinfo.bytes_offset = 0; - cinfo.start_of_file = false; - } catch (IOException e) { - error(SWT.ERROR_IO); - return false; - } - return true; -} - -static boolean first_marker (jpeg_decompress_struct cinfo) { - /* Like next_marker, but used to obtain the initial SOI marker. */ - /* For this marker, we do not allow preceding garbage or fill; otherwise, - * we might well scan an entire input file before realizing it ain't JPEG. - * If an application wants to process non-JFIF files, it must seek to the - * SOI before calling the JPEG library. - */ - int c, c2; - - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c2 = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - if (c != 0xFF || c2 != M_SOI) - error(); -// ERREXIT2(cinfo, JERR_NO_SOI, c, c2); - - cinfo.unread_marker = c2; - - return true; -} - -static boolean next_marker (jpeg_decompress_struct cinfo) { - int c; - - for (;;) { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - /* Skip any non-FF bytes. - * This may look a bit inefficient, but it will not occur in a valid file. - * We sync after each discarded byte so that a suspending data source - * can discard the byte from its buffer. - */ - while (c != 0xFF) { - cinfo.marker.discarded_bytes++; - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - } - /* This loop swallows any duplicate FF bytes. Extra FFs are legal as - * pad bytes, so don't count them in discarded_bytes. We assume there - * will not be so many consecutive FF bytes as to overflow a suspending - * data source's input buffer. - */ - do { - if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo); - c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; - } while (c == 0xFF); - if (c != 0) - break; /* found a valid marker, exit loop */ - /* Reach here if we found a stuffed-zero data sequence (FF/00). - * Discard it and loop back to try again. - */ - cinfo.marker.discarded_bytes += 2; - } - - if (cinfo.marker.discarded_bytes != 0) { -// WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo.marker.discarded_bytes, c); - cinfo.marker.discarded_bytes = 0; - } - - cinfo.unread_marker = c; - - return true; -} - -static int read_markers (jpeg_decompress_struct cinfo) { - /* Outer loop repeats once for each marker. */ - for (;;) { - /* Collect the marker proper, unless we already did. */ - /* NB: first_marker() enforces the requirement that SOI appear first. */ - if (cinfo.unread_marker == 0) { - if (! cinfo.marker.saw_SOI) { - if (! first_marker(cinfo)) - return JPEG_SUSPENDED; - } else { - if (! next_marker(cinfo)) - return JPEG_SUSPENDED; - } - } - /* At this point cinfo.unread_marker contains the marker code and the - * input point is just past the marker proper, but before any parameters. - * A suspension will cause us to return with this state still true. - */ - switch (cinfo.unread_marker) { - case M_SOI: - if (! get_soi(cinfo)) - return JPEG_SUSPENDED; - break; - - case M_SOF0: /* Baseline */ - case M_SOF1: /* Extended sequential, Huffman */ - if (! get_sof(cinfo, false, false)) - return JPEG_SUSPENDED; - break; - - case M_SOF2: /* Progressive, Huffman */ - if (! get_sof(cinfo, true, false)) - return JPEG_SUSPENDED; - break; - - case M_SOF9: /* Extended sequential, arithmetic */ - if (! get_sof(cinfo, false, true)) - return JPEG_SUSPENDED; - break; - - case M_SOF10: /* Progressive, arithmetic */ - if (! get_sof(cinfo, true, true)) - return JPEG_SUSPENDED; - break; - - /* Currently unsupported SOFn types */ - case M_SOF3: /* Lossless, Huffman */ - case M_SOF5: /* Differential sequential, Huffman */ - case M_SOF6: /* Differential progressive, Huffman */ - case M_SOF7: /* Differential lossless, Huffman */ - case M_JPG: /* Reserved for JPEG extensions */ - case M_SOF11: /* Lossless, arithmetic */ - case M_SOF13: /* Differential sequential, arithmetic */ - case M_SOF14: /* Differential progressive, arithmetic */ - case M_SOF15: /* Differential lossless, arithmetic */ - error(); -// ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo.unread_marker); - break; - - case M_SOS: - if (! get_sos(cinfo)) - return JPEG_SUSPENDED; - cinfo.unread_marker = 0; /* processed the marker */ - return JPEG_REACHED_SOS; - - case M_EOI: -// TRACEMS(cinfo, 1, JTRC_EOI); - cinfo.unread_marker = 0; /* processed the marker */ - return JPEG_REACHED_EOI; - - case M_DAC: - if (! get_dac(cinfo)) - return JPEG_SUSPENDED; - break; - - case M_DHT: - if (! get_dht(cinfo)) - return JPEG_SUSPENDED; - break; - - case M_DQT: - if (! get_dqt(cinfo)) - return JPEG_SUSPENDED; - break; - - case M_DRI: - if (! get_dri(cinfo)) - return JPEG_SUSPENDED; - break; - - case M_APP0: - case M_APP1: - case M_APP2: - case M_APP3: - case M_APP4: - case M_APP5: - case M_APP6: - case M_APP7: - case M_APP8: - case M_APP9: - case M_APP10: - case M_APP11: - case M_APP12: - case M_APP13: - case M_APP14: - case M_APP15: - if (! process_APPn(cinfo.unread_marker - M_APP0, cinfo)) - return JPEG_SUSPENDED; - break; - - case M_COM: - if (! process_COM(cinfo)) - return JPEG_SUSPENDED; - break; - - case M_RST0: /* these are all parameterless */ - case M_RST1: - case M_RST2: - case M_RST3: - case M_RST4: - case M_RST5: - case M_RST6: - case M_RST7: - case M_TEM: -// TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo.unread_marker); - break; - - case M_DNL: /* Ignore DNL ... perhaps the wrong thing */ - if (! skip_variable(cinfo)) - return JPEG_SUSPENDED; - break; - - default: /* must be DHP, EXP, JPGn, or RESn */ - /* For now, we treat the reserved markers as fatal errors since they are - * likely to be used to signal incompatible JPEG Part 3 extensions. - * Once the JPEG 3 version-number marker is well defined, this code - * ought to change! - */ - error(); - // ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo.unread_marker); - break; - } - /* Successfully processed marker, so reset state variable */ - cinfo.unread_marker = 0; - } /* end loop */ -} - -static long jdiv_round_up (long a, long b) -/* Compute a/b rounded up to next integer, ie, ceil(a/b) */ -/* Assumes a >= 0, b > 0 */ -{ - return (a + b - 1) / b; -} - -static void initial_setup (jpeg_decompress_struct cinfo) -/* Called once, when first SOS marker is reached */ -{ - int ci; - jpeg_component_info compptr; - - /* Make sure image isn't bigger than I can handle */ - if (cinfo.image_height > JPEG_MAX_DIMENSION || cinfo.image_width > JPEG_MAX_DIMENSION) - error(); -// ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); - - /* For now, precision must match compiled-in value... */ - if (cinfo.data_precision != BITS_IN_JSAMPLE) - error(" [data precision=" + cinfo.data_precision + "]"); -// ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo.data_precision); - - /* Check that number of components won't exceed internal array sizes */ - if (cinfo.num_components > MAX_COMPONENTS) - error(); -// ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.num_components, MAX_COMPONENTS); - - /* Compute maximum sampling factors; check factor validity */ - cinfo.max_h_samp_factor = 1; - cinfo.max_v_samp_factor = 1; - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - if (compptr.h_samp_factor<=0 || compptr.h_samp_factor>MAX_SAMP_FACTOR || compptr.v_samp_factor<=0 || compptr.v_samp_factor>MAX_SAMP_FACTOR) - error(); -// ERREXIT(cinfo, JERR_BAD_SAMPLING); - cinfo.max_h_samp_factor = Math.max(cinfo.max_h_samp_factor, compptr.h_samp_factor); - cinfo.max_v_samp_factor = Math.max(cinfo.max_v_samp_factor, compptr.v_samp_factor); - } - - /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. - * In the full decompressor, this will be overridden by jdmaster.c; - * but in the transcoder, jdmaster.c is not used, so we must do it here. - */ - cinfo.min_DCT_scaled_size = DCTSIZE; - - /* Compute dimensions of components */ - for (ci = 0; ci < cinfo.num_components; ci++) { - compptr = cinfo.comp_info[ci]; - compptr.DCT_scaled_size = DCTSIZE; - /* Size in DCT blocks */ - compptr.width_in_blocks = (int)jdiv_round_up((long) cinfo.image_width * (long) compptr.h_samp_factor, (cinfo.max_h_samp_factor * DCTSIZE)); - compptr.height_in_blocks = (int)jdiv_round_up((long) cinfo.image_height * (long) compptr.v_samp_factor, (cinfo.max_v_samp_factor * DCTSIZE)); - /* downsampled_width and downsampled_height will also be overridden by - * jdmaster.c if we are doing full decompression. The transcoder library - * doesn't use these values, but the calling application might. - */ - /* Size in samples */ - compptr.downsampled_width = (int)jdiv_round_up((long) cinfo.image_width * (long) compptr.h_samp_factor, cinfo.max_h_samp_factor); - compptr.downsampled_height = (int)jdiv_round_up((long) cinfo.image_height * (long) compptr.v_samp_factor, cinfo.max_v_samp_factor); - /* Mark component needed, until color conversion says otherwise */ - compptr.component_needed = true; - /* Mark no quantization table yet saved for component */ - compptr.quant_table = null; - } - - /* Compute number of fully interleaved MCU rows. */ - cinfo.total_iMCU_rows = (int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); - - /* Decide whether file contains multiple scans */ - if (cinfo.comps_in_scan < cinfo.num_components || cinfo.progressive_mode) - cinfo.inputctl.has_multiple_scans = true; - else - cinfo.inputctl.has_multiple_scans = false; -} - - -static void per_scan_setup (jpeg_decompress_struct cinfo) -/* Do computations that are needed before processing a JPEG scan */ -/* cinfo.comps_in_scan and cinfo.cur_comp_info[] were set from SOS marker */ -{ - int ci, mcublks, tmp = 0; - jpeg_component_info compptr; - - if (cinfo.comps_in_scan == 1) { - - /* Noninterleaved (single-component) scan */ - compptr = cinfo.cur_comp_info[0]; - - /* Overall image size in MCUs */ - cinfo.MCUs_per_row = compptr.width_in_blocks; - cinfo.MCU_rows_in_scan = compptr.height_in_blocks; - - /* For noninterleaved scan, always one block per MCU */ - compptr.MCU_width = 1; - compptr.MCU_height = 1; - compptr.MCU_blocks = 1; - compptr.MCU_sample_width = compptr.DCT_scaled_size; - compptr.last_col_width = 1; - /* For noninterleaved scans, it is convenient to define last_row_height - * as the number of block rows present in the last iMCU row. - */ - tmp = (compptr.height_in_blocks % compptr.v_samp_factor); - if (tmp == 0) tmp = compptr.v_samp_factor; - compptr.last_row_height = tmp; - - /* Prepare array describing MCU composition */ - cinfo.blocks_in_MCU = 1; - cinfo.MCU_membership[0] = 0; - - } else { - - /* Interleaved (multi-component) scan */ - if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN) - error(); -// ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN); - - /* Overall image size in MCUs */ - cinfo.MCUs_per_row = (int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE)); - cinfo.MCU_rows_in_scan = (int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); - - cinfo.blocks_in_MCU = 0; - - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - compptr = cinfo.cur_comp_info[ci]; - /* Sampling factors give # of blocks of component in each MCU */ - compptr.MCU_width = compptr.h_samp_factor; - compptr.MCU_height = compptr.v_samp_factor; - compptr.MCU_blocks = compptr.MCU_width * compptr.MCU_height; - compptr.MCU_sample_width = compptr.MCU_width * compptr.DCT_scaled_size; - /* Figure number of non-dummy blocks in last MCU column & row */ - tmp = (compptr.width_in_blocks % compptr.MCU_width); - if (tmp == 0) tmp = compptr.MCU_width; - compptr.last_col_width = tmp; - tmp = (compptr.height_in_blocks % compptr.MCU_height); - if (tmp == 0) tmp = compptr.MCU_height; - compptr.last_row_height = tmp; - /* Prepare array describing MCU composition */ - mcublks = compptr.MCU_blocks; - if (cinfo.blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) - error(); -// ERREXIT(cinfo, JERR_BAD_MCU_SIZE); - while (mcublks-- > 0) { - cinfo.MCU_membership[cinfo.blocks_in_MCU++] = ci; - } - } - - } -} - -static void latch_quant_tables (jpeg_decompress_struct cinfo) { - int ci, qtblno; - jpeg_component_info compptr; - JQUANT_TBL qtbl; - - for (ci = 0; ci < cinfo.comps_in_scan; ci++) { - compptr = cinfo.cur_comp_info[ci]; - /* No work if we already saved Q-table for this component */ - if (compptr.quant_table != null) - continue; - /* Make sure specified quantization table is present */ - qtblno = compptr.quant_tbl_no; - if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || cinfo.quant_tbl_ptrs[qtblno] == null) - error(); -// ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); - /* OK, save away the quantization table */ - qtbl = new JQUANT_TBL(); - System.arraycopy(cinfo.quant_tbl_ptrs[qtblno].quantval, 0, qtbl.quantval, 0, qtbl.quantval.length); - qtbl.sent_table = cinfo.quant_tbl_ptrs[qtblno].sent_table; - compptr.quant_table = qtbl; - } -} - -static void jpeg_make_d_derived_tbl (jpeg_decompress_struct cinfo, boolean isDC, int tblno, d_derived_tbl dtbl) { - JHUFF_TBL htbl; - int p, i = 0, l, si, numsymbols; - int lookbits, ctr; - byte[] huffsize = new byte[257]; - int[] huffcode = new int[257]; - int code; - - /* Note that huffsize[] and huffcode[] are filled in code-length order, - * paralleling the order of the symbols themselves in htbl.huffval[]. - */ - - /* Find the input Huffman table */ - if (tblno < 0 || tblno >= NUM_HUFF_TBLS) - error(); -// ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); - htbl = isDC ? cinfo.dc_huff_tbl_ptrs[tblno] : cinfo.ac_huff_tbl_ptrs[tblno]; - if (htbl == null) - error(); -// ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); - - /* Allocate a workspace if we haven't already done so. */ - dtbl.pub = htbl; /* fill in back link */ - - /* Figure C.1: make table of Huffman code length for each symbol */ - - p = 0; - for (l = 1; l <= 16; l++) { - i = htbl.bits[l] & 0xFF; - if (i < 0 || p + i > 256) /* protect against table overrun */ - error(); -// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); - while (i-- != 0) - huffsize[p++] = (byte) l; - } - huffsize[p] = 0; - numsymbols = p; - - /* Figure C.2: generate the codes themselves */ - /* We also validate that the counts represent a legal Huffman code tree. */ - - code = 0; - si = huffsize[0]; - p = 0; - while ((huffsize[p]) != 0) { - while (( huffsize[p]) == si) { - huffcode[p++] = code; - code++; - } - /* code is now 1 more than the last code used for codelength si; but - * it must still fit in si bits, since no code is allowed to be all ones. - */ - if (( code) >= (( 1) << si)) - error(); -// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); - code <<= 1; - si++; - } - - /* Figure F.15: generate decoding tables for bit-sequential decoding */ - - p = 0; - for (l = 1; l <= 16; l++) { - if ((htbl.bits[l] & 0xFF) != 0) { - /* valoffset[l] = huffval[] index of 1st symbol of code length l, - * minus the minimum code of length l - */ - dtbl.valoffset[l] = p - huffcode[p]; - p += (htbl.bits[l] & 0xFF); - dtbl.maxcode[l] = huffcode[p-1]; /* maximum code of length l */ - } else { - dtbl.maxcode[l] = -1; /* -1 if no codes of this length */ - } - } - dtbl.maxcode[17] = 0xFFFFF; /* ensures jpeg_huff_decode terminates */ - - /* Compute lookahead tables to speed up decoding. - * First we set all the table entries to 0, indicating "too long"; - * then we iterate through the Huffman codes that are short enough and - * fill in all the entries that correspond to bit sequences starting - * with that code. - */ - - for (int j = 0; j < dtbl.look_nbits.length; j++) { - dtbl.look_nbits[j] = 0; - } - - p = 0; - for (l = 1; l <= HUFF_LOOKAHEAD; l++) { - for (i = 1; i <= (htbl.bits[l] & 0xFF); i++, p++) { - /* l = current code's length, p = its index in huffcode[] & huffval[]. */ - /* Generate left-justified code followed by all possible bit sequences */ - lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l); - for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) { - dtbl.look_nbits[lookbits] = l; - dtbl.look_sym[lookbits] = htbl.huffval[p]; - lookbits++; - } - } - } - - /* Validate symbols as being reasonable. - * For AC tables, we make no check, but accept all byte values 0..255. - * For DC tables, we require the symbols to be in range 0..15. - * (Tighter bounds could be applied depending on the data depth and mode, - * but this is sufficient to ensure safe decoding.) - */ - if (isDC) { - for (i = 0; i < numsymbols; i++) { - int sym = htbl.huffval[i] & 0xFF; - if (sym < 0 || sym > 15) - error(); -// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); - } - } -} - -static void start_input_pass (jpeg_decompress_struct cinfo) { - per_scan_setup(cinfo); - latch_quant_tables(cinfo); - cinfo.entropy.start_pass(cinfo); - cinfo.coef.start_input_pass (cinfo); - cinfo.inputctl.consume_input = COEF_CONSUME_INPUT; -} - -static void finish_input_pass (jpeg_decompress_struct cinfo) { - cinfo.inputctl.consume_input = INPUT_CONSUME_INPUT; -} - -static int consume_markers (jpeg_decompress_struct cinfo) { - jpeg_input_controller inputctl = cinfo.inputctl; - int val; - - if (inputctl.eoi_reached) /* After hitting EOI, read no further */ - return JPEG_REACHED_EOI; - - val = read_markers (cinfo); - - switch (val) { - case JPEG_REACHED_SOS: /* Found SOS */ - if (inputctl.inheaders) { /* 1st SOS */ - initial_setup(cinfo); - inputctl.inheaders = false; - /* Note: start_input_pass must be called by jdmaster.c - * before any more input can be consumed. jdapimin.c is - * responsible for enforcing this sequencing. - */ - } else { /* 2nd or later SOS marker */ - if (! inputctl.has_multiple_scans) - error(); -// ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ - start_input_pass(cinfo); - } - break; - case JPEG_REACHED_EOI: /* Found EOI */ - inputctl.eoi_reached = true; - if (inputctl.inheaders) { /* Tables-only datastream, apparently */ - if (cinfo.marker.saw_SOF) - error(); -// ERREXIT(cinfo, JERR_SOF_NO_SOS); - } else { - /* Prevent infinite loop in coef ctlr's decompress_data routine - * if user set output_scan_number larger than number of scans. - */ - if (cinfo.output_scan_number > cinfo.input_scan_number) - cinfo.output_scan_number = cinfo.input_scan_number; - } - break; - case JPEG_SUSPENDED: - break; - } - - return val; -} - -static void default_decompress_parms (jpeg_decompress_struct cinfo) { - /* Guess the input colorspace, and set output colorspace accordingly. */ - /* (Wish JPEG committee had provided a real way to specify this...) */ - /* Note application may override our guesses. */ - switch (cinfo.num_components) { - case 1: - cinfo.jpeg_color_space = JCS_GRAYSCALE; - cinfo.out_color_space = JCS_GRAYSCALE; - break; - - case 3: - if (cinfo.saw_JFIF_marker) { - cinfo.jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ - } else if (cinfo.saw_Adobe_marker) { - switch (cinfo.Adobe_transform) { - case 0: - cinfo.jpeg_color_space = JCS_RGB; - break; - case 1: - cinfo.jpeg_color_space = JCS_YCbCr; - break; - default: -// WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); - cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ - break; - } - } else { - /* Saw no special markers, try to guess from the component IDs */ - int cid0 = cinfo.comp_info[0].component_id; - int cid1 = cinfo.comp_info[1].component_id; - int cid2 = cinfo.comp_info[2].component_id; - - if (cid0 == 1 && cid1 == 2 && cid2 == 3) - cinfo.jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ - else if (cid0 == 82 && cid1 == 71 && cid2 == 66) - cinfo.jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ - else { -// TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); - cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ - } - } - /* Always guess RGB is proper output colorspace. */ - cinfo.out_color_space = JCS_RGB; - break; - - case 4: - if (cinfo.saw_Adobe_marker) { - switch (cinfo.Adobe_transform) { - case 0: - cinfo.jpeg_color_space = JCS_CMYK; - break; - case 2: - cinfo.jpeg_color_space = JCS_YCCK; - break; - default: -// WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); - cinfo.jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ - break; - } - } else { - /* No special markers, assume straight CMYK. */ - cinfo.jpeg_color_space = JCS_CMYK; - } - cinfo.out_color_space = JCS_CMYK; - break; - - default: - cinfo.jpeg_color_space = JCS_UNKNOWN; - cinfo.out_color_space = JCS_UNKNOWN; - break; - } - - /* Set defaults for other decompression parameters. */ - cinfo.scale_num = 1; /* 1:1 scaling */ - cinfo.scale_denom = 1; - cinfo.output_gamma = 1.0; - cinfo.buffered_image = false; - cinfo.raw_data_out = false; - cinfo.dct_method = JDCT_DEFAULT; - cinfo.do_fancy_upsampling = true; - cinfo.do_block_smoothing = true; - cinfo.quantize_colors = false; - /* We set these in case application only sets quantize_colors. */ - cinfo.dither_mode = JDITHER_FS; - cinfo.two_pass_quantize = true; - cinfo.desired_number_of_colors = 256; - cinfo.colormap = null; - /* Initialize for no mode change in buffered-image mode. */ - cinfo.enable_1pass_quant = false; - cinfo.enable_external_quant = false; - cinfo.enable_2pass_quant = false; -} - -static void init_source(jpeg_decompress_struct cinfo) { - cinfo.buffer = new byte[INPUT_BUFFER_SIZE]; - cinfo.bytes_in_buffer = 0; - cinfo.bytes_offset = 0; - cinfo.start_of_file = true; -} - -static int jpeg_consume_input (jpeg_decompress_struct cinfo) { - int retcode = JPEG_SUSPENDED; - - /* NB: every possible DSTATE value should be listed in this switch */ - switch (cinfo.global_state) { - case DSTATE_START: - /* Start-of-datastream actions: reset appropriate modules */ - reset_input_controller(cinfo); - /* Initialize application's data source module */ - init_source (cinfo); - cinfo.global_state = DSTATE_INHEADER; - /*FALLTHROUGH*/ - case DSTATE_INHEADER: - retcode = consume_input(cinfo); - if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */ - /* Set up default parameters based on header data */ - default_decompress_parms(cinfo); - /* Set global state: ready for start_decompress */ - cinfo.global_state = DSTATE_READY; - } - break; - case DSTATE_READY: - /* Can't advance past first SOS until start_decompress is called */ - retcode = JPEG_REACHED_SOS; - break; - case DSTATE_PRELOAD: - case DSTATE_PRESCAN: - case DSTATE_SCANNING: - case DSTATE_RAW_OK: - case DSTATE_BUFIMAGE: - case DSTATE_BUFPOST: - case DSTATE_STOPPING: - retcode = consume_input (cinfo); - break; - default: - error(); -// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state); - } - return retcode; -} - - -static void jpeg_abort (jpeg_decompress_struct cinfo) { -// int pool; -// -// /* Releasing pools in reverse order might help avoid fragmentation -// * with some (brain-damaged) malloc libraries. -// */ -// for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { -// (*cinfo.mem.free_pool) (cinfo, pool); -// } - - /* Reset overall state for possible reuse of object */ - if (cinfo.is_decompressor) { - cinfo.global_state = DSTATE_START; - /* Try to keep application from accessing now-deleted marker list. - * A bit kludgy to do it here, but this is the most central place. - */ -// ((j_decompress_ptr) cinfo).marker_list = null; - } else { - cinfo.global_state = CSTATE_START; - } -} - - -static boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] buffer = new byte[2]; - stream.read(buffer); - stream.unread(buffer); - return (buffer[0] & 0xFF) == 0xFF && (buffer[1] & 0xFF) == M_SOI; - } catch (Exception e) { - return false; - } -} - -static ImageData[] loadFromByteStream(InputStream inputStream, ImageLoader loader) { - jpeg_decompress_struct cinfo = new jpeg_decompress_struct(); - cinfo.inputStream = inputStream; - jpeg_create_decompress(cinfo); - jpeg_read_header(cinfo, true); - cinfo.buffered_image = cinfo.progressive_mode && loader.hasListeners(); - jpeg_start_decompress(cinfo); - PaletteData palette = null; - switch (cinfo.out_color_space) { - case JCS_RGB: - palette = new PaletteData(0xFF, 0xFF00, 0xFF0000); - break; - case JCS_GRAYSCALE: - RGB[] colors = new RGB[256]; - for (int i = 0; i < colors.length; i++) { - colors[i] = new RGB(i, i, i); - } - palette = new PaletteData(colors); - break; - default: - error(); - } - int scanlinePad = 4; - int row_stride = (((cinfo.output_width * cinfo.out_color_components * 8 + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad; - byte[][] buffer = new byte[1][row_stride]; - byte[] data = new byte[row_stride * cinfo.output_height]; - ImageData imageData = ImageData.internal_new( - cinfo.output_width, cinfo.output_height, palette.isDirect ? 24 : 8, palette, scanlinePad, data, - 0, null, null, -1, -1, SWT.IMAGE_JPEG, 0, 0, 0, 0); - if (cinfo.buffered_image) { - boolean done; - do { - int incrementCount = cinfo.input_scan_number - 1; - jpeg_start_output(cinfo, cinfo.input_scan_number); - while (cinfo.output_scanline < cinfo.output_height) { - int offset = row_stride * cinfo.output_scanline; - jpeg_read_scanlines(cinfo, buffer, 1); - System.arraycopy(buffer[0], 0, data, offset, row_stride); - } - jpeg_finish_output(cinfo); - loader.notifyListeners(new ImageLoaderEvent(loader, (ImageData)imageData.clone(), incrementCount, done = jpeg_input_complete(cinfo))); - } while (!done); - } else { - while (cinfo.output_scanline < cinfo.output_height) { - int offset = row_stride * cinfo.output_scanline; - jpeg_read_scanlines(cinfo, buffer, 1); - System.arraycopy(buffer[0], 0, data, offset, row_stride); - } - } - jpeg_finish_decompress(cinfo); - jpeg_destroy_decompress(cinfo); - return new ImageData[]{imageData}; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java deleted file mode 100755 index faa369ccb0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGEndOfImage extends JPEGFixedSizeSegment { - - public JPEGEndOfImage() { - super(); - } - - public JPEGEndOfImage(byte[] reference) { - super(reference); - } - - public int signature() { - return JPEGFileFormat.EOI; - } - - public int fixedSize() { - return 2; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java deleted file mode 100755 index 967feb708d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java +++ /dev/null @@ -1,1882 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This source file is made available under the terms contained in the README file - * accompanying this program. The README file should be located in the about_files directory of the - * plug-in that contains this source file. - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -public final class JPEGFileFormat extends FileFormat { - int restartInterval; - JPEGFrameHeader frameHeader; - int imageWidth, imageHeight; - int interleavedMcuCols, interleavedMcuRows; - int maxV, maxH; - boolean progressive; - int samplePrecision; - int nComponents; - int[][] frameComponents; - int[] componentIds; - byte[][] imageComponents; - int[] dataUnit; - int[][][] dataUnits; - int[] precedingDCs; - JPEGScanHeader scanHeader; - byte[] dataBuffer; - int currentBitCount; - int bufferCurrentPosition; - int restartsToGo; - int nextRestartNumber; - JPEGHuffmanTable[] acHuffmanTables; - JPEGHuffmanTable[] dcHuffmanTables; - int[][] quantizationTables; - int currentByte; - int encoderQFactor = 75; - int eobrun = 0; - /* JPEGConstants */ - public static final int DCTSIZE = 8; - public static final int DCTSIZESQR = 64; - /* JPEGFixedPointConstants */ - public static final int FIX_0_899976223 = 7373; - public static final int FIX_1_961570560 = 16069; - public static final int FIX_2_053119869 = 16819; - public static final int FIX_0_298631336 = 2446; - public static final int FIX_1_847759065 = 15137; - public static final int FIX_1_175875602 = 9633; - public static final int FIX_3_072711026 = 25172; - public static final int FIX_0_765366865 = 6270; - public static final int FIX_2_562915447 = 20995; - public static final int FIX_0_541196100 = 4433; - public static final int FIX_0_390180644 = 3196; - public static final int FIX_1_501321110 = 12299; - /* JPEGMarkerCodes */ - public static final int APP0 = 0xFFE0; - public static final int APP15 = 0xFFEF; - public static final int COM = 0xFFFE; - public static final int DAC = 0xFFCC; - public static final int DHP = 0xFFDE; - public static final int DHT = 0xFFC4; - public static final int DNL = 0xFFDC; - public static final int DRI = 0xFFDD; - public static final int DQT = 0xFFDB; - public static final int EOI = 0xFFD9; - public static final int EXP = 0xFFDF; - public static final int JPG = 0xFFC8; - public static final int JPG0 = 0xFFF0; - public static final int JPG13 = 0xFFFD; - public static final int RST0 = 0xFFD0; - public static final int RST1 = 0xFFD1; - public static final int RST2 = 0xFFD2; - public static final int RST3 = 0xFFD3; - public static final int RST4 = 0xFFD4; - public static final int RST5 = 0xFFD5; - public static final int RST6 = 0xFFD6; - public static final int RST7 = 0xFFD7; - public static final int SOF0 = 0xFFC0; - public static final int SOF1 = 0xFFC1; - public static final int SOF2 = 0xFFC2; - public static final int SOF3 = 0xFFC3; - public static final int SOF5 = 0xFFC5; - public static final int SOF6 = 0xFFC6; - public static final int SOF7 = 0xFFC7; - public static final int SOF9 = 0xFFC9; - public static final int SOF10 = 0xFFCA; - public static final int SOF11 = 0xFFCB; - public static final int SOF13 = 0xFFCD; - public static final int SOF14 = 0xFFCE; - public static final int SOF15 = 0xFFCF; - public static final int SOI = 0xFFD8; - public static final int SOS = 0xFFDA; - public static final int TEM = 0xFF01; - /* JPEGFrameComponentParameterConstants */ - public static final int TQI = 0; - public static final int HI = 1; - public static final int VI = 2; - public static final int CW = 3; - public static final int CH = 4; - /* JPEGScanComponentParameterConstants */ - public static final int DC = 0; - public static final int AC = 1; - /* JFIF Component Constants */ - public static final int ID_Y = 1 - 1; - public static final int ID_CB = 2 - 1; - public static final int ID_CR = 3 - 1; - public static final RGB[] RGB16 = new RGB[] { - new RGB(0,0,0), - new RGB(0x80,0,0), - new RGB(0,0x80,0), - new RGB(0x80,0x80,0), - new RGB(0,0,0x80), - new RGB(0x80,0,0x80), - new RGB(0,0x80,0x80), - new RGB(0xC0,0xC0,0xC0), - new RGB(0x80,0x80,0x80), - new RGB(0xFF,0,0), - new RGB(0,0xFF,0), - new RGB(0xFF,0xFF,0), - new RGB(0,0,0xFF), - new RGB(0xFF,0,0xFF), - new RGB(0,0xFF,0xFF), - new RGB(0xFF,0xFF,0xFF), - }; - public static final int[] ExtendTest = { - 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, - 4096, 8192, 16384, 32768, 65536, 131072, 262144 - }; - public static final int[] ExtendOffset = new int[] { - 0, -1, -3, -7, -15, -31, -63, -127, -255, -511, -1023, -2047, - -4095, -8191, -16383, -32767, -65535, -131071, -262143 - }; - public static final int[] ZigZag8x8 = { - 0, 1, 8, 16, 9, 2, 3, 10, - 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, - 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, - 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, - 53, 60, 61, 54, 47, 55, 62, 63 - }; - - public static final int[] CrRTable, CbBTable, CrGTable, CbGTable; - public static final int[] RYTable, GYTable, BYTable, - RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable; - static { - /* Initialize RGB-YCbCr Tables */ - int [] rYTable = new int[256]; - int [] gYTable = new int[256]; - int [] bYTable = new int[256]; - int [] rCbTable = new int[256]; - int [] gCbTable = new int[256]; - int [] bCbTable = new int[256]; - int [] gCrTable = new int[256]; - int [] bCrTable = new int[256]; - for (int i = 0; i < 256; i++) { - rYTable[i] = i * 19595; - gYTable[i] = i * 38470; - bYTable[i] = i * 7471 + 32768; - rCbTable[i] = i * -11059; - gCbTable[i] = i * -21709; - bCbTable[i] = i * 32768 + 8388608; - gCrTable[i] = i * -27439; - bCrTable[i] = i * -5329; - } - RYTable = rYTable; - GYTable = gYTable; - BYTable = bYTable; - RCbTable = rCbTable; - GCbTable = gCbTable; - BCbTable = bCbTable; - RCrTable = bCbTable; - GCrTable = gCrTable; - BCrTable = bCrTable; - - /* Initialize YCbCr-RGB Tables */ - int [] crRTable = new int[256]; - int [] cbBTable = new int[256]; - int [] crGTable = new int[256]; - int [] cbGTable = new int[256]; - for (int i = 0; i < 256; i++) { - int x2 = 2 * i - 255; - crRTable[i] = (45941 * x2 + 32768) >> 16; - cbBTable[i] = (58065 * x2 + 32768) >> 16; - crGTable[i] = -23401 * x2; - cbGTable[i] = -11277 * x2 + 32768; - } - CrRTable = crRTable; - CbBTable = cbBTable; - CrGTable = crGTable; - CbGTable = cbGTable; - - /* Initialize BitCount Table */ - int nBits = 1; - int power2 = 2; - int [] nBitsTable = new int[2048]; - nBitsTable[0] = 0; - for (int i = 1; i < nBitsTable.length; i++) { - if (!(i < power2)) { - nBits++; - power2 *= 2; - } - nBitsTable[i] = nBits; - } - NBitsTable = nBitsTable; - } -void compress(ImageData image, byte[] dataYComp, byte[] dataCbComp, byte[] dataCrComp) { - int srcWidth = image.width; - int srcHeight = image.height; - int vhFactor = maxV * maxH; - int[] frameComponent; - imageComponents = new byte[nComponents][]; - for (int i = 0; i < nComponents; i++) { - frameComponent = frameComponents[componentIds[i]]; - imageComponents[i] = new byte[frameComponent[CW] * frameComponent[CH]]; - } - frameComponent = frameComponents[componentIds[ID_Y]]; - for (int yPos = 0; yPos < srcHeight; yPos++) { - int srcOfs = yPos * srcWidth; - int dstOfs = yPos * frameComponent[CW]; - System.arraycopy(dataYComp, srcOfs, imageComponents[ID_Y], dstOfs, srcWidth); - } - frameComponent = frameComponents[componentIds[ID_CB]]; - for (int yPos = 0; yPos < srcHeight / maxV; yPos++) { - int destRowIndex = yPos * frameComponent[CW]; - for (int xPos = 0; xPos < srcWidth / maxH; xPos++) { - int sum = 0; - for (int iv = 0; iv < maxV; iv++) { - int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH); - for (int ih = 0; ih < maxH; ih++) { - sum += dataCbComp[srcIndex + ih] & 0xFF; - } - } - imageComponents[ID_CB][destRowIndex + xPos] = (byte)(sum / vhFactor); - } - } - frameComponent = frameComponents[componentIds[ID_CR]]; - for (int yPos = 0; yPos < srcHeight / maxV; yPos++) { - int destRowIndex = yPos * frameComponent[CW]; - for (int xPos = 0; xPos < srcWidth / maxH; xPos++) { - int sum = 0; - for (int iv = 0; iv < maxV; iv++) { - int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH); - for (int ih = 0; ih < maxH; ih++) { - sum += dataCrComp[srcIndex + ih] & 0xFF; - } - } - imageComponents[ID_CR][destRowIndex + xPos] = (byte)(sum / vhFactor); - } - } - for (int iComp = 0; iComp < nComponents; iComp++) { - byte[] imageComponent = imageComponents[iComp]; - frameComponent = frameComponents[componentIds[iComp]]; - int hFactor = frameComponent[HI]; - int vFactor = frameComponent[VI]; - int componentWidth = frameComponent[CW]; - int componentHeight = frameComponent[CH]; - int compressedWidth = srcWidth / (maxH / hFactor); - int compressedHeight = srcHeight / (maxV / vFactor); - if (compressedWidth < componentWidth) { - int delta = componentWidth - compressedWidth; - for (int yPos = 0; yPos < compressedHeight; yPos++) { - int dstOfs = ((yPos + 1) * componentWidth - delta); - int dataValue = imageComponent[(dstOfs > 0) ? dstOfs - 1 : 0] & 0xFF; - for (int i = 0; i < delta; i++) { - imageComponent[dstOfs + i] = (byte)dataValue; - } - } - } - if (compressedHeight < componentHeight) { - int srcOfs = (compressedHeight > 0) ? (compressedHeight - 1) * componentWidth : 1; - for (int yPos = (compressedHeight > 0) ? compressedHeight : 1; yPos <= componentHeight; yPos++) { - int dstOfs = (yPos - 1) * componentWidth; - System.arraycopy(imageComponent, srcOfs, imageComponent, dstOfs, componentWidth); - } - } - } -} -void convert4BitRGBToYCbCr(ImageData image) { - RGB[] rgbs = image.getRGBs(); - int paletteSize = rgbs.length; - byte[] yComp = new byte[paletteSize]; - byte[] cbComp = new byte[paletteSize]; - byte[] crComp = new byte[paletteSize]; - int srcWidth = image.width; - int srcHeight = image.height; - for (int i = 0; i < paletteSize; i++) { - RGB color = rgbs[i]; - int r = color.red; - int g = color.green; - int b = color.blue; - int n = RYTable[r] + GYTable[g] + BYTable[b]; - yComp[i] = (byte)(n >> 16); - if ((n < 0) && ((n & 0xFFFF) != 0)) yComp[i]--; - n = RCbTable[r] + GCbTable[g] + BCbTable[b]; - cbComp[i] = (byte)(n >> 16); - if ((n < 0) && ((n & 0xFFFF) != 0)) cbComp[i]--; - n = RCrTable[r] + GCrTable[g] + BCrTable[b]; - crComp[i] = (byte)(n >> 16); - if ((n < 0) && ((n & 0xFFFF) != 0)) crComp[i]--; - } - int bSize = srcWidth * srcHeight; - byte[] dataYComp = new byte[bSize]; - byte[] dataCbComp = new byte[bSize]; - byte[] dataCrComp = new byte[bSize]; - byte[] origData = image.data; - int bytesPerLine = image.bytesPerLine; - int maxScanlineByte = srcWidth >> 1; - for (int yPos = 0; yPos < srcHeight; yPos++) { - for (int xPos = 0; xPos < maxScanlineByte; xPos++) { - int srcIndex = yPos * bytesPerLine + xPos; - int dstIndex = yPos * srcWidth + (xPos * 2); - int value2 = origData[srcIndex] & 0xFF; - int value1 = value2 >> 4; - value2 &= 0x0F; - dataYComp[dstIndex] = yComp[value1]; - dataCbComp[dstIndex] = cbComp[value1]; - dataCrComp[dstIndex] = crComp[value1]; - dataYComp[dstIndex + 1] = yComp[value2]; - dataCbComp[dstIndex + 1] = cbComp[value2]; - dataCrComp[dstIndex + 1] = crComp[value2]; - } - } - compress(image, dataYComp, dataCbComp, dataCrComp); -} -void convert8BitRGBToYCbCr(ImageData image) { - RGB[] rgbs = image.getRGBs(); - int paletteSize = rgbs.length; - byte[] yComp = new byte[paletteSize]; - byte[] cbComp = new byte[paletteSize]; - byte[] crComp = new byte[paletteSize]; - int srcWidth = image.width; - int srcHeight = image.height; - for (int i = 0; i < paletteSize; i++) { - RGB color = rgbs[i]; - int r = color.red; - int g = color.green; - int b = color.blue; - int n = RYTable[r] + GYTable[g] + BYTable[b]; - yComp[i] = (byte)(n >> 16); - if ((n < 0) && ((n & 0xFFFF) != 0)) yComp[i]--; - n = RCbTable[r] + GCbTable[g] + BCbTable[b]; - cbComp[i] = (byte)(n >> 16); - if ((n < 0) && ((n & 0xFFFF) != 0)) cbComp[i]--; - n = RCrTable[r] + GCrTable[g] + BCrTable[b]; - crComp[i] = (byte)(n >> 16); - if ((n < 0) && ((n & 0xFFFF) != 0)) crComp[i]--; - } - int dstWidth = image.width; - int dstHeight = srcHeight; - int stride = ((srcWidth + 3) >> 2) << 2; - int bSize = dstWidth * dstHeight; - byte[] dataYComp = new byte[bSize]; - byte[] dataCbComp = new byte[bSize]; - byte[] dataCrComp = new byte[bSize]; - byte[] origData = image.data; - for (int yPos = 0; yPos < srcHeight; yPos++) { - int srcRowIndex = yPos * stride; - int dstRowIndex = yPos * dstWidth; - for (int xPos = 0; xPos < srcWidth; xPos++) { - int value = origData[srcRowIndex + xPos] & 0xFF; - int dstIndex = dstRowIndex + xPos; - dataYComp[dstIndex] = yComp[value]; - dataCbComp[dstIndex] = cbComp[value]; - dataCrComp[dstIndex] = crComp[value]; - } - } - compress(image, dataYComp, dataCbComp, dataCrComp); -} -byte[] convertCMYKToRGB() { - /* Unsupported CMYK format. Answer an empty byte array. */ - return new byte[0]; -} -void convertImageToYCbCr(ImageData image) { - switch (image.depth) { - case 4: - convert4BitRGBToYCbCr(image); - return; - case 8: - convert8BitRGBToYCbCr(image); - return; - case 16: - case 24: - case 32: - convertMultiRGBToYCbCr(image); - return; - default: - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - } - return; -} -void convertMultiRGBToYCbCr(ImageData image) { - int srcWidth = image.width; - int srcHeight = image.height; - int bSize = srcWidth * srcHeight; - byte[] dataYComp = new byte[bSize]; - byte[] dataCbComp = new byte[bSize]; - byte[] dataCrComp = new byte[bSize]; - PaletteData palette = image.palette; - int[] buffer = new int[srcWidth]; - if (palette.isDirect) { - int redMask = palette.redMask; - int greenMask = palette.greenMask; - int blueMask = palette.blueMask; - int redShift = palette.redShift; - int greenShift = palette.greenShift; - int blueShift = palette.blueShift; - for (int yPos = 0; yPos < srcHeight; yPos++) { - image.getPixels(0, yPos, srcWidth, buffer, 0); - int dstRowIndex = yPos * srcWidth; - for (int xPos = 0; xPos < srcWidth; xPos++) { - int pixel = buffer[xPos]; - int dstDataIndex = dstRowIndex + xPos; - int r = pixel & redMask; - r = (redShift < 0) ? r >>> -redShift : r << redShift; - int g = pixel & greenMask; - g = (greenShift < 0) ? g >>> -greenShift : g << greenShift; - int b = pixel & blueMask; - b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; - dataYComp[dstDataIndex] = (byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16); - dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16); - dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16); - } - } - } else { - for (int yPos = 0; yPos < srcHeight; yPos++) { - image.getPixels(0, yPos, srcWidth, buffer, 0); - int dstRowIndex = yPos * srcWidth; - for (int xPos = 0; xPos < srcWidth; xPos++) { - int pixel = buffer[xPos]; - int dstDataIndex = dstRowIndex + xPos; - RGB rgb = palette.getRGB(pixel); - int r = rgb.red; - int g = rgb.green; - int b = rgb.blue; - dataYComp[dstDataIndex] = (byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16); - dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16); - dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16); - } - } - } - compress(image, dataYComp, dataCbComp, dataCrComp); -} -byte[] convertYToRGB() { - int compWidth = frameComponents[componentIds[ID_Y]][CW]; - int bytesPerLine = (((imageWidth * 8 + 7) / 8) + 3) / 4 * 4; - byte[] data = new byte[bytesPerLine * imageHeight]; - byte[] yComp = imageComponents[ID_Y]; - int destIndex = 0; - for (int i = 0; i < imageHeight; i++) { - int srcIndex = i * compWidth; - for (int j = 0; j < bytesPerLine; j++) { - int y = yComp[srcIndex] & 0xFF; - if (y < 0) { - y = 0; - } else { - if (y > 255) y = 255; - } - if (j >= imageWidth) { - y = 0; - } - data[destIndex] = (byte)y; - srcIndex++; - destIndex++; - } - } - return data; -} -byte[] convertYCbCrToRGB() { - /** - * Convert existing image components into an RGB format. - * YCbCr is defined per CCIR 601-1, except that Cb and Cr are - * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. - * The conversion equations to be implemented are therefore - * R = Y + 1.40200 * Cr - * G = Y - 0.34414 * Cb - 0.71414 * Cr - * B = Y + 1.77200 * Cb - * where Cb and Cr represent the incoming values less MAXJSAMPLE/2. - * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) - * - * To avoid floating-point arithmetic, we represent the fractional constants - * as integers scaled up by 2^16 (about 4 digits precision); we have to divide - * the products by 2^16, with appropriate rounding, to get the correct answer. - * Notice that Y, being an integral input, does not contribute any fraction - * so it need not participate in the rounding. - * - * For even more speed, we avoid doing any multiplications in the inner loop - * by precalculating the constants times Cb and Cr for all possible values. - * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); - * for 12-bit samples it is still acceptable. It's not very reasonable for - * 16-bit samples, but if you want lossless storage you shouldn't be changing - * colorspace anyway. - * The Cr=>R and Cb=>B values can be rounded to integers in advance; the - * values for the G calculation are left scaled up, since we must add them - * together before rounding. - */ - int bSize = imageWidth * imageHeight * nComponents; - byte[] rgbData = new byte[bSize]; - int destIndex = 0; - expandImageComponents(); - byte[] yComp = imageComponents[ID_Y]; - byte[] cbComp = imageComponents[ID_CB]; - byte[] crComp = imageComponents[ID_CR]; - int compWidth = frameComponents[componentIds[ID_Y]][CW]; - for (int v = 0; v < imageHeight; v++) { - int srcIndex = v * compWidth; - for (int i = 0; i < imageWidth; i++) { - int y = yComp[srcIndex] & 0xFF; - int cb = cbComp[srcIndex] & 0xFF; - int cr = crComp[srcIndex] & 0xFF; - int r = y + CrRTable[cr]; - int g = y + ((CbGTable[cb] + CrGTable[cr]) >> 16); - int b = y + CbBTable[cb]; - if (r < 0) { - r = 0; - } else { - if (r > 255) r = 255; - } - if (g < 0) { - g = 0; - } else { - if (g > 255) g = 255; - } - if (b < 0) { - b = 0; - } else { - if (b > 255) b = 255; - } - rgbData[destIndex] = (byte)b; - rgbData[destIndex + 1] = (byte)g; - rgbData[destIndex + 2] = (byte)r; - destIndex += 3; - srcIndex++; - } - } - return rgbData; -} -void decodeACCoefficients(int[] dataUnit, int iComp) { - int[] sParams = scanHeader.componentParameters[componentIds[iComp]]; - JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]]; - int k = 1; - while (k < 64) { - int rs = decodeUsingTable(acTable); - int r = rs >> 4; - int s = rs & 0xF; - if (s == 0) { - if (r == 15) { - k += 16; - } else { - break; - } - } else { - k += r; - int bits = receive(s); - dataUnit[ZigZag8x8[k]] = extendBy(bits, s); - k++; - } - } -} -void decodeACFirstCoefficients(int[] dataUnit, int iComp, int start, int end, int approxBit) { - if (eobrun > 0) { - eobrun--; - return; - } - int[] sParams = scanHeader.componentParameters[componentIds[iComp]]; - JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]]; - int k = start; - while (k <= end) { - int rs = decodeUsingTable(acTable); - int r = rs >> 4; - int s = rs & 0xF; - if (s == 0) { - if (r == 15) { - k += 16; - } else { - eobrun = (1 << r) + receive(r) - 1; - break; - } - } else { - k += r; - int bits = receive(s); - dataUnit[ZigZag8x8[k]] = extendBy(bits, s) << approxBit; - k++; - } - } -} -void decodeACRefineCoefficients(int[] dataUnit, int iComp, int start, int end, int approxBit) { - int[] sParams = scanHeader.componentParameters[componentIds[iComp]]; - JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]]; - int k = start; - while (k <= end) { - if (eobrun > 0) { - while (k <= end) { - int zzIndex = ZigZag8x8[k]; - if (dataUnit[zzIndex] != 0) { - dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit); - } - k++; - } - eobrun--; - } else { - int rs = decodeUsingTable(acTable); - int r = rs >> 4; - int s = rs & 0xF; - if (s == 0) { - if (r == 15) { - int zeros = 0; - while (zeros < 16 && k <= end) { - int zzIndex = ZigZag8x8[k]; - if (dataUnit[zzIndex] != 0) { - dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit); - } else { - zeros++; - } - k++; - } - } else { - eobrun = (1 << r) + receive(r); - } - } else { - int bit = receive(s); - int zeros = 0; - int zzIndex = ZigZag8x8[k]; - while ((zeros < r || dataUnit[zzIndex] != 0) && k <= end) { - if (dataUnit[zzIndex] != 0) { - dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit); - } else { - zeros++; - } - k++; - zzIndex = ZigZag8x8[k]; - } - if (bit != 0) { - dataUnit[zzIndex] = 1 << approxBit; - } else { - dataUnit[zzIndex] = -1 << approxBit; - } - k++; - } - } - } -} -int refineAC(int ac, int approxBit) { - if (ac > 0) { - int bit = nextBit(); - if (bit != 0) { - ac += 1 << approxBit; - } - } else if (ac < 0) { - int bit = nextBit(); - if (bit != 0) { - ac += -1 << approxBit; - } - } - return ac; -} -void decodeDCCoefficient(int[] dataUnit, int iComp, boolean first, int approxBit) { - int[] sParams = scanHeader.componentParameters[componentIds[iComp]]; - JPEGHuffmanTable dcTable = dcHuffmanTables[sParams[DC]]; - int lastDC = 0; - if (progressive && !first) { - int bit = nextBit(); - lastDC = dataUnit[0] + (bit << approxBit); - } else { - lastDC = precedingDCs[iComp]; - int nBits = decodeUsingTable(dcTable); - if (nBits != 0) { - int bits = receive(nBits); - int diff = extendBy(bits, nBits); - lastDC += diff; - precedingDCs[iComp] = lastDC; - } - if (progressive) { - lastDC = lastDC << approxBit; - } - } - dataUnit[0] = lastDC; -} -void dequantize(int[] dataUnit, int iComp) { - int[] qTable = quantizationTables[frameComponents[componentIds[iComp]][TQI]]; - for (int i = 0; i < dataUnit.length; i++) { - int zzIndex = ZigZag8x8[i]; - dataUnit[zzIndex] = dataUnit[zzIndex] * qTable[i]; - } -} -byte[] decodeImageComponents() { - if (nComponents == 3) { // compIds 1, 2, 3 - return convertYCbCrToRGB(); - } -// if (nComponents == 3) { // compIds 1, 4, 5 -// Unsupported CMYK format. -// return convertYIQToRGB(); -// } - if (nComponents == 4) { - return convertCMYKToRGB(); - } - return convertYToRGB(); -} -void decodeMCUAtXAndY(int xmcu, int ymcu, int nComponentsInScan, boolean first, int start, int end, int approxBit) { - for (int iComp = 0; iComp < nComponentsInScan; iComp++) { - int scanComponent = iComp; - while (scanHeader.componentParameters[componentIds[scanComponent]] == null) { - scanComponent++; - } - int[] frameComponent = frameComponents[componentIds[scanComponent]]; - int hi = frameComponent[HI]; - int vi = frameComponent[VI]; - if (nComponentsInScan == 1) { - hi = 1; - vi = 1; - } - int compWidth = frameComponent[CW]; - for (int ivi = 0; ivi < vi; ivi++) { - for (int ihi = 0; ihi < hi; ihi++) { - if (progressive) { - // Progressive: First scan - create a new data unit. - // Subsequent scans - refine the existing data unit. - int index = (ymcu * vi + ivi) * compWidth + xmcu * hi + ihi; - dataUnit = dataUnits[scanComponent][index]; - if (dataUnit == null) { - dataUnit = new int[64]; - dataUnits[scanComponent][index] = dataUnit; - } - } else { - // Sequential: Clear and reuse the data unit buffer. - for (int i = 0; i < dataUnit.length; i++) { - dataUnit[i] = 0; - } - } - if (!progressive || scanHeader.isDCProgressiveScan()) { - decodeDCCoefficient(dataUnit, scanComponent, first, approxBit); - } - if (!progressive) { - decodeACCoefficients(dataUnit, scanComponent); - } else { - if (scanHeader.isACProgressiveScan()) { - if (first) { - decodeACFirstCoefficients(dataUnit, scanComponent, start, end, approxBit); - } else { - decodeACRefineCoefficients(dataUnit, scanComponent, start, end, approxBit); - } - } - if (loader.hasListeners()) { - // Dequantization, IDCT, up-sampling and color conversion - // are done on a copy of the coefficient data in order to - // display the image incrementally. - int[] temp = dataUnit; - dataUnit = new int[64]; - System.arraycopy(temp, 0, dataUnit, 0, 64); - } - } - if (!progressive || (progressive && loader.hasListeners())) { - dequantize(dataUnit, scanComponent); - inverseDCT(dataUnit); - storeData(dataUnit, scanComponent, xmcu, ymcu, hi, ihi, vi, ivi); - } - } - } - } -} -void decodeScan() { - if (progressive && !scanHeader.verifyProgressiveScan()) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - int nComponentsInScan = scanHeader.getNumberOfImageComponents(); - int mcuRowsInScan = interleavedMcuRows; - int mcusPerRow = interleavedMcuCols; - if (nComponentsInScan == 1) { - // Non-interleaved. - int scanComponent = 0; - while (scanHeader.componentParameters[componentIds[scanComponent]] == null) { - scanComponent++; - } - int[] frameComponent = frameComponents[componentIds[scanComponent]]; - int hi = frameComponent[HI]; - int vi = frameComponent[VI]; - int mcuWidth = DCTSIZE * maxH / hi; - int mcuHeight = DCTSIZE * maxV / vi; - mcusPerRow = (imageWidth + mcuWidth - 1) / mcuWidth; - mcuRowsInScan = (imageHeight + mcuHeight - 1) / mcuHeight; - } - boolean first = scanHeader.isFirstScan(); - int start = scanHeader.getStartOfSpectralSelection(); - int end = scanHeader.getEndOfSpectralSelection(); - int approxBit = scanHeader.getApproxBitPositionLow(); - restartsToGo = restartInterval; - nextRestartNumber = 0; - for (int ymcu = 0; ymcu < mcuRowsInScan; ymcu++) { - for (int xmcu = 0; xmcu < mcusPerRow; xmcu++) { - if (restartInterval != 0) { - if (restartsToGo == 0) processRestartInterval(); - restartsToGo--; - } - decodeMCUAtXAndY(xmcu, ymcu, nComponentsInScan, first, start, end, approxBit); - } - } -} -int decodeUsingTable(JPEGHuffmanTable huffmanTable) { - int i = 0; - int[] maxCodes = huffmanTable.getDhMaxCodes(); - int[] minCodes = huffmanTable.getDhMinCodes(); - int[] valPtrs = huffmanTable.getDhValPtrs(); - int[] huffVals = huffmanTable.getDhValues(); - int code = nextBit(); - while (code > maxCodes[i]) { - code = code * 2 + nextBit(); - i++; - } - int j = valPtrs[i] + code - minCodes[i]; - return huffVals[j]; -} -void emit(int huffCode, int nBits) { - if (nBits == 0) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - int[] power2m1 = new int[] { - 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, - 16383, 32767, 65535, 131125 - }; - int code = (huffCode & power2m1[nBits - 1]) << (24 - nBits - currentBitCount); - byte[] codeBuffer = new byte[4]; - codeBuffer[0] = (byte)(code & 0xFF); - codeBuffer[1] = (byte)((code >> 8) & 0xFF); - codeBuffer[2] = (byte)((code >> 16) & 0xFF); - codeBuffer[3] = (byte)((code >> 24) & 0xFF); - int abs = nBits - (8 - currentBitCount); - if (abs < 0) abs = -abs; - if ((abs >> 3) > 0) { - currentByte += codeBuffer[2]; - emitByte((byte)currentByte); - emitByte(codeBuffer[1]); - currentByte = codeBuffer[0]; - currentBitCount += nBits - 16; - } else { - currentBitCount += nBits; - if (currentBitCount >= 8) { - currentByte += codeBuffer[2]; - emitByte((byte)currentByte); - currentByte = codeBuffer[1]; - currentBitCount -= 8; - } else { - currentByte += codeBuffer[2]; - } - } -} -void emitByte(byte byteValue) { - if (bufferCurrentPosition >= 512) { - resetOutputBuffer(); - } - dataBuffer[bufferCurrentPosition] = byteValue; - bufferCurrentPosition++; - if (byteValue == -1) { - emitByte((byte)0); - } -} -void encodeACCoefficients(int[] dataUnit, int iComp) { - int[] sParams = scanHeader.componentParameters[iComp]; - JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]]; - int[] ehCodes = acTable.ehCodes; - byte[] ehSizes = acTable.ehCodeLengths; - int r = 0; - int k = 1; - while (k < 64) { - k++; - int acValue = dataUnit[ZigZag8x8[k - 1]]; - if (acValue == 0) { - if (k == 64) { - emit(ehCodes[0], ehSizes[0] & 0xFF); - } else { - r++; - } - } else { - while (r > 15) { - emit(ehCodes[0xF0], ehSizes[0xF0] & 0xFF); - r -= 16; - } - if (acValue < 0) { - int absACValue = acValue; - if (absACValue < 0) absACValue = -absACValue; - int nBits = NBitsTable[absACValue]; - int rs = r * 16 + nBits; - emit(ehCodes[rs], ehSizes[rs] & 0xFF); - emit(0xFFFFFF - absACValue, nBits); - } else { - int nBits = NBitsTable[acValue]; - int rs = r * 16 + nBits; - emit(ehCodes[rs], ehSizes[rs] & 0xFF); - emit(acValue, nBits); - } - r = 0; - } - } -} -void encodeDCCoefficients(int[] dataUnit, int iComp) { - int[] sParams = scanHeader.componentParameters[iComp]; - JPEGHuffmanTable dcTable = dcHuffmanTables[sParams[DC]]; - int lastDC = precedingDCs[iComp]; - int dcValue = dataUnit[0]; - int diff = dcValue - lastDC; - precedingDCs[iComp] = dcValue; - if (diff < 0) { - int absDiff = 0 - diff; - int nBits = NBitsTable[absDiff]; - emit(dcTable.ehCodes[nBits], dcTable.ehCodeLengths[nBits]); - emit(0xFFFFFF - absDiff, nBits); - } else { - int nBits = NBitsTable[diff]; - emit(dcTable.ehCodes[nBits], dcTable.ehCodeLengths[nBits]); - if (nBits != 0) { - emit(diff, nBits); - } - } -} -void encodeMCUAtXAndY(int xmcu, int ymcu) { - int nComponentsInScan = scanHeader.getNumberOfImageComponents(); - dataUnit = new int[64]; - for (int iComp = 0; iComp < nComponentsInScan; iComp++) { - int[] frameComponent = frameComponents[componentIds[iComp]]; - int hi = frameComponent[HI]; - int vi = frameComponent[VI]; - for (int ivi = 0; ivi < vi; ivi++) { - for (int ihi = 0; ihi < hi; ihi++) { - extractData(dataUnit, iComp, xmcu, ymcu, ihi, ivi); - forwardDCT(dataUnit); - quantizeData(dataUnit, iComp); - encodeDCCoefficients(dataUnit, iComp); - encodeACCoefficients(dataUnit, iComp); - } - } - } -} -void encodeScan() { - for (int ymcu = 0; ymcu < interleavedMcuRows; ymcu++) { - for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) { - encodeMCUAtXAndY(xmcu, ymcu); - } - } - if (currentBitCount != 0) { - emitByte((byte)currentByte); - } - resetOutputBuffer(); -} -void expandImageComponents() { - for (int iComp = 0; iComp < nComponents; iComp++) { - int[] frameComponent = frameComponents[componentIds[iComp]]; - int hi = frameComponent[HI]; - int vi = frameComponent[VI]; - int upH = maxH / hi; - int upV = maxV / vi; - if ((upH * upV) > 1) { - byte[] component = imageComponents[iComp]; - int compWidth = frameComponent[CW]; - int compHeight = frameComponent[CH]; - int upCompWidth = compWidth * upH; - int upCompHeight = compHeight * upV; - ImageData src = new ImageData(compWidth, compHeight, 8, new PaletteData(RGB16), 4, component); - ImageData dest = src.scaledTo(upCompWidth, upCompHeight); - imageComponents[iComp] = dest.data; - } - } -} -int extendBy(int diff, int t) { - if (diff < ExtendTest[t]) { - return diff + ExtendOffset[t]; - } else { - return diff; - } -} -void extractData(int[] dataUnit, int iComp, int xmcu, int ymcu, int ihi, int ivi) { - byte[] compImage = imageComponents[iComp]; - int[] frameComponent = frameComponents[componentIds[iComp]]; - int hi = frameComponent[HI]; - int vi = frameComponent[VI]; - int compWidth = frameComponent[CW]; - int srcIndex = ((ymcu * vi + ivi) * compWidth * DCTSIZE) + ((xmcu * hi + ihi) * DCTSIZE); - int destIndex = 0; - for (int i = 0; i < DCTSIZE; i++) { - for (int col = 0; col < DCTSIZE; col++) { - dataUnit[destIndex] = (compImage[srcIndex + col] & 0xFF) - 128; - destIndex++; - } - srcIndex += compWidth; - } -} -void forwardDCT(int[] dataUnit) { - for (int row = 0; row < 8; row++) { - int rIndex = row * DCTSIZE; - int tmp0 = dataUnit[rIndex] + dataUnit[rIndex + 7]; - int tmp7 = dataUnit[rIndex] - dataUnit[rIndex + 7]; - int tmp1 = dataUnit[rIndex + 1] + dataUnit[rIndex + 6]; - int tmp6 = dataUnit[rIndex + 1] - dataUnit[rIndex + 6]; - int tmp2 = dataUnit[rIndex + 2] + dataUnit[rIndex + 5]; - int tmp5 = dataUnit[rIndex + 2] - dataUnit[rIndex + 5]; - int tmp3 = dataUnit[rIndex + 3] + dataUnit[rIndex + 4]; - int tmp4 = dataUnit[rIndex + 3] - dataUnit[rIndex + 4]; - - /** - * Even part per LL&M figure 1 --- note that published figure - * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'. - */ - int tmp10 = tmp0 + tmp3; - int tmp13 = tmp0 - tmp3; - int tmp11 = tmp1 + tmp2; - int tmp12 = tmp1 - tmp2; - - dataUnit[rIndex] = (tmp10 + tmp11) * 4; - dataUnit[rIndex + 4] = (tmp10 - tmp11) * 4; - - int z1 = (tmp12 + tmp13) * FIX_0_541196100; - int n = z1 + (tmp13 * FIX_0_765366865) + 1024; - dataUnit[rIndex + 2] = n >> 11; - if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 2]--; - n = z1 + (tmp12 * (0 - FIX_1_847759065)) + 1024; - dataUnit[rIndex + 6] = n >> 11; - if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 6]--; - - /** - * Odd part per figure 8 --- note paper omits factor of sqrt(2). - * cK represents cos(K*pi/16). - * i0..i3 in the paper are tmp4..tmp7 here. - */ - z1 = tmp4 + tmp7; - int z2 = tmp5 + tmp6; - int z3 = tmp4 + tmp6; - int z4 = tmp5 + tmp7; - int z5 = (z3 + z4) * FIX_1_175875602; // sqrt(2) * c3 - - tmp4 *= FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7) - tmp5 *= FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7) - tmp6 *= FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7) - tmp7 *= FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7) - z1 *= 0 - FIX_0_899976223; // sqrt(2) * (c7-c3) - z2 *= 0 - FIX_2_562915447; // sqrt(2) * (-c1-c3) - z3 *= 0 - FIX_1_961570560; // sqrt(2) * (-c3-c5) - z4 *= 0 - FIX_0_390180644; // sqrt(2) * (c5-c3) - - z3 += z5; - z4 += z5; - - n = tmp4 + z1 + z3 + 1024; - dataUnit[rIndex + 7] = n >> 11; - if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 7]--; - n = tmp5 + z2 + z4 + 1024; - dataUnit[rIndex + 5] = n >> 11; - if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 5]--; - n = tmp6 + z2 + z3 + 1024; - dataUnit[rIndex + 3] = n >> 11; - if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 3]--; - n = tmp7 + z1 + z4 + 1024; - dataUnit[rIndex + 1] = n >> 11; - if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 1]--; - } - - /** - * Pass 2: process columns. - * Note that we must descale the results by a factor of 8 == 2**3, - * and also undo the PASS1_BITS scaling. - */ - for (int col = 0; col < 8; col++) { - int c0 = col; - int c1 = col + 8; - int c2 = col + 16; - int c3 = col + 24; - int c4 = col + 32; - int c5 = col + 40; - int c6 = col + 48; - int c7 = col + 56; - int tmp0 = dataUnit[c0] + dataUnit[c7]; - int tmp7 = dataUnit[c0] - dataUnit[c7]; - int tmp1 = dataUnit[c1] + dataUnit[c6]; - int tmp6 = dataUnit[c1] - dataUnit[c6]; - int tmp2 = dataUnit[c2] + dataUnit[c5]; - int tmp5 = dataUnit[c2] - dataUnit[c5]; - int tmp3 = dataUnit[c3] + dataUnit[c4]; - int tmp4 = dataUnit[c3] - dataUnit[c4]; - - /** - * Even part per LL&M figure 1 --- note that published figure - * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'. - */ - int tmp10 = tmp0 + tmp3; - int tmp13 = tmp0 - tmp3; - int tmp11 = tmp1 + tmp2; - int tmp12 = tmp1 - tmp2; - - int n = tmp10 + tmp11 + 16; - dataUnit[c0] = n >> 5; - if ((n < 0) && ((n & 0x1F) != 0)) dataUnit[c0]--; - n = tmp10 - tmp11 + 16; - dataUnit[c4] = n >> 5; - if ((n < 0) && ((n & 0x1F) != 0)) dataUnit[c4]--; - - int z1 = (tmp12 + tmp13) * FIX_0_541196100; - n = z1 + (tmp13 * FIX_0_765366865) + 131072; - dataUnit[c2] = n >> 18; - if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c2]--; - n = z1 + (tmp12 * (0 - FIX_1_847759065)) + 131072; - dataUnit[c6] = n >> 18; - if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c6]--; - - /** - * Odd part per figure 8 --- note paper omits factor of sqrt(2). - * cK represents cos(K*pi/16). - * i0..i3 in the paper are tmp4..tmp7 here. - */ - z1 = tmp4 + tmp7; - int z2 = tmp5 + tmp6; - int z3 = tmp4 + tmp6; - int z4 = tmp5 + tmp7; - int z5 = (z3 + z4) * FIX_1_175875602; // sqrt(2) * c3 - - tmp4 *= FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7) - tmp5 *= FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7) - tmp6 *= FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7) - tmp7 *= FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7) - z1 *= 0 - FIX_0_899976223; // sqrt(2) * (c7-c3) - z2 *= 0 - FIX_2_562915447; // sqrt(2) * (-c1-c3) - z3 *= 0 - FIX_1_961570560; // sqrt(2) * (-c3-c5) - z4 *= 0 - FIX_0_390180644; // sqrt(2) * (c5-c3) - - z3 += z5; - z4 += z5; - - n = tmp4 + z1 + z3 + 131072; - dataUnit[c7] = n >> 18; - if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c7]--; - n = tmp5 + z2 + z4 + 131072; - dataUnit[c5] = n >> 18; - if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c5]--; - n = tmp6 + z2 + z3 + 131072; - dataUnit[c3] = n >> 18; - if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c3]--; - n = tmp7 + z1 + z4 + 131072; - dataUnit[c1] = n >> 18; - if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c1]--; - } -} -void getAPP0() { - JPEGAppn appn = new JPEGAppn(inputStream); - if (!appn.verify()) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } -} -void getCOM() { - new JPEGComment(inputStream); -} -void getDAC() { - new JPEGArithmeticConditioningTable(inputStream); -} -void getDHT() { - JPEGHuffmanTable dht = new JPEGHuffmanTable(inputStream); - if (!dht.verify()) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - if (acHuffmanTables == null) { - acHuffmanTables = new JPEGHuffmanTable[4]; - } - if (dcHuffmanTables == null) { - dcHuffmanTables = new JPEGHuffmanTable[4]; - } - JPEGHuffmanTable[] dhtTables = dht.getAllTables(); - for (int i = 0; i < dhtTables.length; i++) { - JPEGHuffmanTable dhtTable = dhtTables[i]; - if (dhtTable.getTableClass() == 0) { - dcHuffmanTables[dhtTable.getTableIdentifier()] = dhtTable; - } else { - acHuffmanTables[dhtTable.getTableIdentifier()] = dhtTable; - } - } -} -void getDNL() { - new JPEGRestartInterval(inputStream); -} -void getDQT() { - JPEGQuantizationTable dqt = new JPEGQuantizationTable(inputStream); - int[][] currentTables = quantizationTables; - if (currentTables == null) { - currentTables = new int[4][]; - } - int[] dqtTablesKeys = dqt.getQuantizationTablesKeys(); - int[][] dqtTablesValues = dqt.getQuantizationTablesValues(); - for (int i = 0; i < dqtTablesKeys.length; i++) { - int index = dqtTablesKeys[i]; - currentTables[index] = dqtTablesValues[i]; - } - quantizationTables = currentTables; -} -void getDRI() { - JPEGRestartInterval dri = new JPEGRestartInterval(inputStream); - if (!dri.verify()) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - restartInterval = dri.getRestartInterval(); -} -void inverseDCT(int[] dataUnit) { - for (int row = 0; row < 8; row++) { - int rIndex = row * DCTSIZE; - /** - * Due to quantization, we will usually find that many of the input - * coefficients are zero, especially the AC terms. We can exploit this - * by short-circuiting the IDCT calculation for any row in which all - * the AC terms are zero. In that case each output is equal to the - * DC coefficient (with scale factor as needed). - * With typical images and quantization tables, half or more of the - * row DCT calculations can be simplified this way. - */ - if (isZeroInRow(dataUnit, rIndex)) { - int dcVal = dataUnit[rIndex] << 2; - for (int i = rIndex + 7; i >= rIndex; i--) { - dataUnit[i] = dcVal; - } - } else { - /** - * Even part: reverse the even part of the forward DCT. - * The rotator is sqrt(2)*c(-6). - */ - int z2 = dataUnit[rIndex + 2]; - int z3 = dataUnit[rIndex + 6]; - int z1 = (z2 + z3) * FIX_0_541196100; - int tmp2 = z1 + (z3 * (0 - FIX_1_847759065)); - int tmp3 = z1 + (z2 * FIX_0_765366865); - int tmp0 = (dataUnit[rIndex] + dataUnit[rIndex + 4]) << 13; - int tmp1 = (dataUnit[rIndex] - dataUnit[rIndex + 4]) << 13; - int tmp10 = tmp0 + tmp3; - int tmp13 = tmp0 - tmp3; - int tmp11 = tmp1 + tmp2; - int tmp12 = tmp1 - tmp2; - /** - * Odd part per figure 8; the matrix is unitary and hence its - * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. - */ - tmp0 = dataUnit[rIndex + 7]; - tmp1 = dataUnit[rIndex + 5]; - tmp2 = dataUnit[rIndex + 3]; - tmp3 = dataUnit[rIndex + 1]; - z1 = tmp0 + tmp3; - z2 = tmp1 + tmp2; - z3 = tmp0 + tmp2; - int z4 = tmp1 + tmp3; - int z5 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */ - - tmp0 *= FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp1 *= FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp2 *= FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp3 *= FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 *= 0 - FIX_0_899976223; /* sqrt(2) * (c7-c3) */ - z2 *= 0 - FIX_2_562915447; /* sqrt(2) * (-c1-c3) */ - z3 *= 0 - FIX_1_961570560; /* sqrt(2) * (-c3-c5) */ - z4 *= 0 - FIX_0_390180644; /* sqrt(2) * (c5-c3) */ - - z3 += z5; - z4 += z5; - tmp0 += z1 + z3; - tmp1 += z2 + z4; - tmp2 += z2 + z3; - tmp3 += z1 + z4; - - dataUnit[rIndex] = (tmp10 + tmp3 + 1024) >> 11; - dataUnit[rIndex + 7] = (tmp10 - tmp3 + 1024) >> 11; - dataUnit[rIndex + 1] = (tmp11 + tmp2 + 1024) >> 11; - dataUnit[rIndex + 6] = (tmp11 - tmp2 + 1024) >> 11; - dataUnit[rIndex + 2] = (tmp12 + tmp1 + 1024) >> 11; - dataUnit[rIndex + 5] = (tmp12 - tmp1 + 1024) >> 11; - dataUnit[rIndex + 3] = (tmp13 + tmp0 + 1024) >> 11; - dataUnit[rIndex + 4] = (tmp13 - tmp0 + 1024) >> 11; - } - } - /** - * Pass 2: process columns. - * Note that we must descale the results by a factor of 8 == 2**3, - * and also undo the PASS1_BITS scaling. - */ - for (int col = 0; col < 8; col++) { - int c0 = col; - int c1 = col + 8; - int c2 = col + 16; - int c3 = col + 24; - int c4 = col + 32; - int c5 = col + 40; - int c6 = col + 48; - int c7 = col + 56; - if (isZeroInColumn(dataUnit, col)) { - int dcVal = (dataUnit[c0] + 16) >> 5; - dataUnit[c0] = dcVal; - dataUnit[c1] = dcVal; - dataUnit[c2] = dcVal; - dataUnit[c3] = dcVal; - dataUnit[c4] = dcVal; - dataUnit[c5] = dcVal; - dataUnit[c6] = dcVal; - dataUnit[c7] = dcVal; - } else { - /** - * Even part: reverse the even part of the forward DCT. - * The rotator is sqrt(2)*c(-6). - */ - int z0 = dataUnit[c0]; - int z2 = dataUnit[c2]; - int z3 = dataUnit[c6]; - int z4 = dataUnit[c4]; - int z1 = (z2 + z3) * FIX_0_541196100; - int tmp2 = z1 + (z3 * (0 - FIX_1_847759065)); - int tmp3 = z1 + (z2 * FIX_0_765366865); - int tmp0 = (z0 + z4) << 13; - int tmp1 = (z0 - z4) << 13; - int tmp10 = tmp0 + tmp3; - int tmp13 = tmp0 - tmp3; - int tmp11 = tmp1 + tmp2; - int tmp12 = tmp1 - tmp2; - /** - * Odd part per figure 8; the matrix is unitary and hence its - * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. - */ - tmp0 = dataUnit[c7]; - tmp1 = dataUnit[c5]; - tmp2 = dataUnit[c3]; - tmp3 = dataUnit[c1]; - z1 = tmp0 + tmp3; - z2 = tmp1 + tmp2; - z3 = tmp0 + tmp2; - z4 = tmp1 + tmp3; - z0 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */ - - tmp0 *= FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp1 *= FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp2 *= FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp3 *= FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 *= 0 - FIX_0_899976223; /* sqrt(2) * (c7-c3) */ - z2 *= 0 - FIX_2_562915447; /* sqrt(2) * (-c1-c3) */ - z3 *= 0 - FIX_1_961570560; /* sqrt(2) * (-c3-c5) */ - z4 *= 0 - FIX_0_390180644; /* sqrt(2) * (c5-c3) */ - - z3 += z0; - z4 += z0; - - tmp0 += z1 + z3; - tmp1 += z2 + z4; - tmp2 += z2 + z3; - tmp3 += z1 + z4; - - /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataUnit[c0] = (tmp10 + tmp3 + 131072) >> 18; - dataUnit[c7] = (tmp10 - tmp3 + 131072) >> 18; - dataUnit[c1] = (tmp11 + tmp2 + 131072) >> 18; - dataUnit[c6] = (tmp11 - tmp2 + 131072) >> 18; - dataUnit[c2] = (tmp12 + tmp1 + 131072) >> 18; - dataUnit[c5] = (tmp12 - tmp1 + 131072) >> 18; - dataUnit[c3] = (tmp13 + tmp0 + 131072) >> 18; - dataUnit[c4] = (tmp13 - tmp0 + 131072) >> 18; - } - } -} -boolean isFileFormat(LEDataInputStream stream) { - try { - JPEGStartOfImage soi = new JPEGStartOfImage(stream); - stream.unread(soi.reference); - return soi.verify(); // we no longer check for appN - } catch (Exception e) { - return false; - } -} -boolean isZeroInColumn(int[] dataUnit, int col) { - return dataUnit[col + 8] == 0 && dataUnit[col + 16] == 0 - && dataUnit[col + 24] == 0 && dataUnit[col + 32] == 0 - && dataUnit[col + 40] == 0 && dataUnit[col + 48] == 0 - && dataUnit[col + 56] == 0; -} -boolean isZeroInRow(int[] dataUnit, int rIndex) { - return dataUnit[rIndex + 1] == 0 && dataUnit[rIndex + 2] == 0 - && dataUnit[rIndex + 3] == 0 && dataUnit[rIndex + 4] == 0 - && dataUnit[rIndex + 5] == 0 && dataUnit[rIndex + 6] == 0 - && dataUnit[rIndex + 7] == 0; -} -ImageData[] loadFromByteStream() { - //TEMPORARY CODE - if (System.getProperty("org.eclipse.swt.internal.image.JPEGFileFormat_3.2") == null) { - return JPEGDecoder.loadFromByteStream(inputStream, loader); - } - JPEGStartOfImage soi = new JPEGStartOfImage(inputStream); - if (!soi.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE); - restartInterval = 0; - - /* Process the tables preceding the frame header. */ - processTables(); - - /* Start of Frame. */ - frameHeader = new JPEGFrameHeader(inputStream); - if (!frameHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE); - imageWidth = frameHeader.getSamplesPerLine(); - imageHeight = frameHeader.getNumberOfLines(); - maxH = frameHeader.getMaxHFactor(); - maxV = frameHeader.getMaxVFactor(); - int mcuWidth = maxH * DCTSIZE; - int mcuHeight = maxV * DCTSIZE; - interleavedMcuCols = (imageWidth + mcuWidth - 1) / mcuWidth; - interleavedMcuRows = (imageHeight + mcuHeight - 1) / mcuHeight; - progressive = frameHeader.isProgressive(); - samplePrecision = frameHeader.getSamplePrecision(); - nComponents = frameHeader.getNumberOfImageComponents(); - frameComponents = frameHeader.componentParameters; - componentIds = frameHeader.componentIdentifiers; - imageComponents = new byte[nComponents][]; - if (progressive) { - // Progressive jpeg: need to keep all of the data units. - dataUnits = new int[nComponents][][]; - } else { - // Sequential jpeg: only need one data unit. - dataUnit = new int[8 * 8]; - } - for (int i = 0; i < nComponents; i++) { - int[] frameComponent = frameComponents[componentIds[i]]; - int bufferSize = frameComponent[CW] * frameComponent[CH]; - imageComponents[i] = new byte[bufferSize]; - if (progressive) { - dataUnits[i] = new int[bufferSize][]; - } - } - - /* Process the tables preceding the scan header. */ - processTables(); - - /* Start of Scan. */ - scanHeader = new JPEGScanHeader(inputStream); - if (!scanHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE); - - /* Process scan(s) and further tables until EOI. */ - int progressiveScanCount = 0; - boolean done = false; - while(!done) { - resetInputBuffer(); - precedingDCs = new int[4]; - decodeScan(); - if (progressive && loader.hasListeners()) { - ImageData imageData = createImageData(); - loader.notifyListeners(new ImageLoaderEvent(loader, imageData, progressiveScanCount, false)); - progressiveScanCount++; - } - - /* Unread any buffered data before looking for tables again. */ - int delta = 512 - bufferCurrentPosition - 1; - if (delta > 0) { - byte[] unreadBuffer = new byte[delta]; - System.arraycopy(dataBuffer, bufferCurrentPosition + 1, unreadBuffer, 0, delta); - try { - inputStream.unread(unreadBuffer); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - /* Process the tables preceding the next scan header. */ - JPEGSegment jpegSegment = processTables(); - if (jpegSegment == null || jpegSegment.getSegmentMarker() == EOI) { - done = true; - } else { - scanHeader = new JPEGScanHeader(inputStream); - if (!scanHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE); - } - } - - if (progressive) { - for (int ymcu = 0; ymcu < interleavedMcuRows; ymcu++) { - for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) { - for (int iComp = 0; iComp < nComponents; iComp++) { - int[] frameComponent = frameComponents[componentIds[iComp]]; - int hi = frameComponent[HI]; - int vi = frameComponent[VI]; - int compWidth = frameComponent[CW]; - for (int ivi = 0; ivi < vi; ivi++) { - for (int ihi = 0; ihi < hi; ihi++) { - int index = (ymcu * vi + ivi) * compWidth + xmcu * hi + ihi; - dataUnit = dataUnits[iComp][index]; - dequantize(dataUnit, iComp); - inverseDCT(dataUnit); - storeData(dataUnit, iComp, xmcu, ymcu, hi, ihi, vi, ivi); - } - } - } - } - } - dataUnits = null; // release memory - } - ImageData imageData = createImageData(); - if (progressive && loader.hasListeners()) { - loader.notifyListeners(new ImageLoaderEvent(loader, imageData, progressiveScanCount, true)); - } - return new ImageData[] {imageData}; -} -ImageData createImageData() { - return ImageData.internal_new( - imageWidth, - imageHeight, - nComponents * samplePrecision, - setUpPalette(), - nComponents == 1 ? 4 : 1, - decodeImageComponents(), - 0, - null, - null, - -1, - -1, - SWT.IMAGE_JPEG, - 0, - 0, - 0, - 0); -} -int nextBit() { - if (currentBitCount != 0) { - currentBitCount--; - currentByte *= 2; - if (currentByte > 255) { - currentByte -= 256; - return 1; - } else { - return 0; - } - } - bufferCurrentPosition++; - if (bufferCurrentPosition >= 512) { - resetInputBuffer(); - bufferCurrentPosition = 0; - } - currentByte = dataBuffer[bufferCurrentPosition] & 0xFF; - currentBitCount = 8; - byte nextByte; - if (bufferCurrentPosition == 511) { - resetInputBuffer(); - currentBitCount = 8; - nextByte = dataBuffer[0]; - } else { - nextByte = dataBuffer[bufferCurrentPosition + 1]; - } - if (currentByte == 0xFF) { - if (nextByte == 0) { - bufferCurrentPosition ++; - currentBitCount--; - currentByte *= 2; - if (currentByte > 255) { - currentByte -= 256; - return 1; - } else { - return 0; - } - } else { - if ((nextByte & 0xFF) + 0xFF00 == DNL) { - getDNL(); - return 0; - } else { - SWT.error(SWT.ERROR_INVALID_IMAGE); - return 0; - } - } - } else { - currentBitCount--; - currentByte *= 2; - if (currentByte > 255) { - currentByte -= 256; - return 1; - } else { - return 0; - } - } -} -void processRestartInterval() { - do { - bufferCurrentPosition++; - if (bufferCurrentPosition > 511) { - resetInputBuffer(); - bufferCurrentPosition = 0; - } - currentByte = dataBuffer[bufferCurrentPosition] & 0xFF; - } while (currentByte != 0xFF); - while (currentByte == 0xFF) { - bufferCurrentPosition++; - if (bufferCurrentPosition > 511) { - resetInputBuffer(); - bufferCurrentPosition = 0; - } - currentByte = dataBuffer[bufferCurrentPosition] & 0xFF; - } - if (currentByte != ((RST0 + nextRestartNumber) & 0xFF)) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - bufferCurrentPosition++; - if (bufferCurrentPosition > 511) { - resetInputBuffer(); - bufferCurrentPosition = 0; - } - currentByte = dataBuffer[bufferCurrentPosition] & 0xFF; - currentBitCount = 8; - restartsToGo = restartInterval; - nextRestartNumber = (nextRestartNumber + 1) & 0x7; - precedingDCs = new int[4]; - eobrun = 0; -} -/* Process all markers until a frame header, scan header, or EOI is found. */ -JPEGSegment processTables() { - while (true) { - JPEGSegment jpegSegment = seekUnspecifiedMarker(inputStream); - if (jpegSegment == null) return null; - JPEGFrameHeader sof = new JPEGFrameHeader(jpegSegment.reference); - if (sof.verify()) { - return jpegSegment; - } - int marker = jpegSegment.getSegmentMarker(); - switch (marker) { - case SOI: // there should only be one SOI per file - SWT.error(SWT.ERROR_INVALID_IMAGE); - case EOI: - case SOS: - return jpegSegment; - case DQT: - getDQT(); - break; - case DHT: - getDHT(); - break; - case DAC: - getDAC(); - break; - case DRI: - getDRI(); - break; - case APP0: - getAPP0(); - break; - case COM: - getCOM(); - break; - default: - skipSegmentFrom(inputStream); - - } - } -} -void quantizeData(int[] dataUnit, int iComp) { - int[] qTable = quantizationTables[frameComponents[componentIds[iComp]][TQI]]; - for (int i = 0; i < dataUnit.length; i++) { - int zzIndex = ZigZag8x8[i]; - int data = dataUnit[zzIndex]; - int absData = data < 0 ? 0 - data : data; - int qValue = qTable[i]; - int q2 = qValue >> 1; - absData += q2; - if (absData < qValue) { - dataUnit[zzIndex] = 0; - } else { - absData /= qValue; - if (data >= 0) { - dataUnit[zzIndex] = absData; - } else { - dataUnit[zzIndex] = 0 - absData; - } - } - } -} -int receive(int nBits) { - int v = 0; - for (int i = 0; i < nBits; i++) { - v = v * 2 + nextBit(); - } - return v; -} -void resetInputBuffer() { - if (dataBuffer == null) { - dataBuffer = new byte[512]; - } - try { - inputStream.read(dataBuffer); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - currentBitCount = 0; - bufferCurrentPosition = -1; -} -void resetOutputBuffer() { - if (dataBuffer == null) { - dataBuffer = new byte[512]; - } else { - try { - outputStream.write(dataBuffer, 0, bufferCurrentPosition); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - bufferCurrentPosition = 0; -} -static JPEGSegment seekUnspecifiedMarker(LEDataInputStream byteStream) { - byte[] byteArray = new byte[2]; - try { - while (true) { - if (byteStream.read(byteArray, 0, 1) != 1) return null; - if (byteArray[0] == (byte) 0xFF) { - if (byteStream.read(byteArray, 1, 1) != 1) return null; - if (byteArray[1] != (byte) 0xFF && byteArray[1] != 0) { - byteStream.unread(byteArray); - return new JPEGSegment(byteArray); - } - } - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return null; -} -PaletteData setUpPalette() { - if (nComponents == 1) { - RGB[] entries = new RGB[256]; - for (int i = 0; i < 256; i++) { - entries[i] = new RGB(i, i, i); - } - return new PaletteData(entries); - } - return new PaletteData(0xFF, 0xFF00, 0xFF0000); -} -static void skipSegmentFrom(LEDataInputStream byteStream) { - try { - byte[] byteArray = new byte[4]; - JPEGSegment jpegSegment = new JPEGSegment(byteArray); - - if (byteStream.read(byteArray) != byteArray.length) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - if (!(byteArray[0] == -1 && byteArray[1] != 0 && byteArray[1] != -1)) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - int delta = jpegSegment.getSegmentLength() - 2; - byteStream.skip(delta); - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } -} -void storeData(int[] dataUnit, int iComp, int xmcu, int ymcu, int hi, int ihi, int vi, int ivi) { - byte[] compImage = imageComponents[iComp]; - int[] frameComponent = frameComponents[componentIds[iComp]]; - int compWidth = frameComponent[CW]; - int destIndex = ((ymcu * vi + ivi) * compWidth * DCTSIZE) + ((xmcu * hi + ihi) * DCTSIZE); - int srcIndex = 0; - for (int i = 0; i < DCTSIZE; i++) { - for (int col = 0; col < DCTSIZE; col++) { - int x = dataUnit[srcIndex] + 128; - if (x < 0) { - x = 0; - } else { - if (x > 255) x = 255; - } - compImage[destIndex + col] = (byte)x; - srcIndex++; - } - destIndex += compWidth; - } -} -void unloadIntoByteStream(ImageLoader loader) { - ImageData image = loader.data[0]; - if (!new JPEGStartOfImage().writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - JPEGAppn appn = new JPEGAppn(new byte[] {(byte)0xFF, (byte)0xE0, 0, 0x10, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0}); - if (!appn.writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - quantizationTables = new int[4][]; - JPEGQuantizationTable chromDQT = JPEGQuantizationTable.defaultChrominanceTable(); - chromDQT.scaleBy(encoderQFactor); - int[] jpegDQTKeys = chromDQT.getQuantizationTablesKeys(); - int[][] jpegDQTValues = chromDQT.getQuantizationTablesValues(); - for (int i = 0; i < jpegDQTKeys.length; i++) { - quantizationTables[jpegDQTKeys[i]] = jpegDQTValues[i]; - } - JPEGQuantizationTable lumDQT = JPEGQuantizationTable.defaultLuminanceTable(); - lumDQT.scaleBy(encoderQFactor); - jpegDQTKeys = lumDQT.getQuantizationTablesKeys(); - jpegDQTValues = lumDQT.getQuantizationTablesValues(); - for (int i = 0; i < jpegDQTKeys.length; i++) { - quantizationTables[jpegDQTKeys[i]] = jpegDQTValues[i]; - } - if (!lumDQT.writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - if (!chromDQT.writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - int frameLength, scanLength, precision; - int[][] frameParams, scanParams; - if (image.depth == 1) { - frameLength = 11; - frameParams = new int[1][]; - frameParams[0] = new int[] {1, 1, 1, 0, 0}; - scanParams = new int[1][]; - scanParams[0] = new int[] {0, 0}; - scanLength = 8; - nComponents = 1; - precision = 1; - } else { - frameLength = 17; - frameParams = new int[3][]; - frameParams[0] = new int[] {0, 2, 2, 0, 0}; - frameParams[1] = new int[] {1, 1, 1, 0, 0}; - frameParams[2] = new int[] {1, 1, 1, 0, 0}; - scanParams = new int[3][]; - scanParams[0] = new int[] {0, 0}; - scanParams[1] = new int[] {1, 1}; - scanParams[2] = new int[] {1, 1}; - scanLength = 12; - nComponents = 3; - precision = 8; - } - imageWidth = image.width; - imageHeight = image.height; - frameHeader = new JPEGFrameHeader(new byte[19]); - frameHeader.setSegmentMarker(SOF0); - frameHeader.setSegmentLength(frameLength); - frameHeader.setSamplePrecision(precision); - frameHeader.setSamplesPerLine(imageWidth); - frameHeader.setNumberOfLines(imageHeight); - frameHeader.setNumberOfImageComponents(nComponents); - frameHeader.componentParameters = frameParams; - frameHeader.componentIdentifiers = new int[] {0, 1, 2}; - frameHeader.initializeContents(); - if (!frameHeader.writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - frameComponents = frameParams; - componentIds = frameHeader.componentIdentifiers; - maxH = frameHeader.getMaxHFactor(); - maxV = frameHeader.getMaxVFactor(); - int mcuWidth = maxH * DCTSIZE; - int mcuHeight = maxV * DCTSIZE; - interleavedMcuCols = (imageWidth + mcuWidth - 1) / mcuWidth; - interleavedMcuRows = (imageHeight + mcuHeight - 1) / mcuHeight; - acHuffmanTables = new JPEGHuffmanTable[4]; - dcHuffmanTables = new JPEGHuffmanTable[4]; - JPEGHuffmanTable[] dhtTables = new JPEGHuffmanTable[] { - JPEGHuffmanTable.getDefaultDCLuminanceTable(), - JPEGHuffmanTable.getDefaultDCChrominanceTable(), - JPEGHuffmanTable.getDefaultACLuminanceTable(), - JPEGHuffmanTable.getDefaultACChrominanceTable() - }; - for (int i = 0; i < dhtTables.length; i++) { - JPEGHuffmanTable dhtTable = dhtTables[i]; - if (!dhtTable.writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - JPEGHuffmanTable[] allTables = dhtTable.getAllTables(); - for (int j = 0; j < allTables.length; j++) { - JPEGHuffmanTable huffmanTable = allTables[j]; - if (huffmanTable.getTableClass() == 0) { - dcHuffmanTables[huffmanTable.getTableIdentifier()] = huffmanTable; - } else { - acHuffmanTables[huffmanTable.getTableIdentifier()] = huffmanTable; - } - } - } - precedingDCs = new int[4]; - scanHeader = new JPEGScanHeader(new byte[14]); - scanHeader.setSegmentMarker(SOS); - scanHeader.setSegmentLength(scanLength); - scanHeader.setNumberOfImageComponents(nComponents); - scanHeader.setStartOfSpectralSelection(0); - scanHeader.setEndOfSpectralSelection(63); - scanHeader.componentParameters = scanParams; - scanHeader.initializeContents(); - if (!scanHeader.writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } - convertImageToYCbCr(image); - resetOutputBuffer(); - currentByte = 0; - currentBitCount = 0; - encodeScan(); - if (!new JPEGEndOfImage().writeToStream(outputStream)) { - SWT.error(SWT.ERROR_IO); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java deleted file mode 100755 index 28da86905d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -abstract class JPEGFixedSizeSegment extends JPEGSegment { - - public JPEGFixedSizeSegment() { - reference = new byte[fixedSize()]; - setSegmentMarker(signature()); - } - - public JPEGFixedSizeSegment(byte[] reference) { - super(reference); - } - - public JPEGFixedSizeSegment(LEDataInputStream byteStream) { - reference = new byte[fixedSize()]; - try { - byteStream.read(reference); - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - abstract public int fixedSize(); - - public int getSegmentLength() { - return fixedSize() - 2; - } - - public void setSegmentLength(int length) { - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java deleted file mode 100755 index 00d761078c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -final class JPEGFrameHeader extends JPEGVariableSizeSegment { - int maxVFactor; - int maxHFactor; - public int[] componentIdentifiers; - public int[][] componentParameters; - - public JPEGFrameHeader(byte[] reference) { - super(reference); - } - - public JPEGFrameHeader(LEDataInputStream byteStream) { - super(byteStream); - initializeComponentParameters(); - } - - public int getSamplePrecision() { - return reference[4] & 0xFF; - } - - public int getNumberOfLines() { - return (reference[5] & 0xFF) << 8 | (reference[6] & 0xFF); - } - - public int getSamplesPerLine() { - return (reference[7] & 0xFF) << 8 | (reference[8] & 0xFF); - } - - public int getNumberOfImageComponents() { - return reference[9] & 0xFF; - } - - public void setSamplePrecision(int precision) { - reference[4] = (byte)(precision & 0xFF); - } - - public void setNumberOfLines(int anInteger) { - reference[5] = (byte)((anInteger & 0xFF00) >> 8); - reference[6] = (byte)(anInteger & 0xFF); - } - - public void setSamplesPerLine(int samples) { - reference[7] = (byte)((samples & 0xFF00) >> 8); - reference[8] = (byte)(samples & 0xFF); - } - - public void setNumberOfImageComponents(int anInteger) { - reference[9] = (byte)(anInteger & 0xFF); - } - - public int getMaxHFactor() { - return maxHFactor; - } - - public int getMaxVFactor() { - return maxVFactor; - } - - public void setMaxHFactor(int anInteger) { - maxHFactor = anInteger; - } - - public void setMaxVFactor(int anInteger) { - maxVFactor = anInteger; - } - - /* Used when decoding. */ - void initializeComponentParameters() { - int nf = getNumberOfImageComponents(); - componentIdentifiers = new int[nf]; - int[][] compSpecParams = new int[0][]; - int hmax = 1; - int vmax = 1; - for (int i = 0; i < nf; i++) { - int ofs = i * 3 + 10; - int ci = reference[ofs] & 0xFF; - componentIdentifiers[i] = ci; - int hi = (reference[ofs + 1] & 0xFF) >> 4; - int vi = reference[ofs + 1] & 0xF; - int tqi = reference[ofs + 2] & 0xFF; - if (hi > hmax) { - hmax = hi; - } - if (vi > vmax) { - vmax = vi; - } - int[] compParam = new int[5]; - compParam[0] = tqi; - compParam[1] = hi; - compParam[2] = vi; - if (compSpecParams.length <= ci) { - int[][] newParams = new int[ci + 1][]; - System.arraycopy(compSpecParams, 0, newParams, 0, compSpecParams.length); - compSpecParams = newParams; - } - compSpecParams[ci] = compParam; - } - int x = getSamplesPerLine(); - int y = getNumberOfLines(); - int[] multiples = new int[] { 8, 16, 24, 32 }; - for (int i = 0; i < nf; i++) { - int[] compParam = compSpecParams[componentIdentifiers[i]]; - int hi = compParam[1]; - int vi = compParam[2]; - int compWidth = (x * hi + hmax - 1) / hmax; - int compHeight = (y * vi + vmax - 1) / vmax; - int dsWidth = roundUpToMultiple(compWidth, multiples[hi - 1]); - int dsHeight = roundUpToMultiple(compHeight, multiples[vi - 1]); - compParam[3] = dsWidth; - compParam[4] = dsHeight; - } - setMaxHFactor(hmax); - setMaxVFactor(vmax); - componentParameters = compSpecParams; - } - - /* Used when encoding. */ - public void initializeContents() { - int nf = getNumberOfImageComponents(); - if (nf == 0 || nf != componentParameters.length) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - int hmax = 0; - int vmax = 0; - int[][] compSpecParams = componentParameters; - for (int i = 0; i < nf; i++) { - int ofs = i * 3 + 10; - int[] compParam = compSpecParams[componentIdentifiers[i]]; - int hi = compParam[1]; - int vi = compParam[2]; - if (hi * vi > 4) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - reference[ofs] = (byte)(i + 1); - reference[ofs + 1] = (byte)(hi * 16 + vi); - reference[ofs + 2] = (byte)(compParam[0]); - if (hi > hmax) hmax = hi; - if (vi > vmax) vmax = vi; - } - int x = getSamplesPerLine(); - int y = getNumberOfLines(); - int[] multiples = new int[] {8, 16, 24, 32}; - for (int i = 0; i < nf; i++) { - int[] compParam = compSpecParams[componentIdentifiers[i]]; - int hi = compParam[1]; - int vi = compParam[2]; - int compWidth = (x * hi + hmax - 1) / hmax; - int compHeight = (y * vi + vmax - 1) / vmax; - int dsWidth = roundUpToMultiple(compWidth, multiples[hi - 1]); - int dsHeight = roundUpToMultiple(compHeight, multiples[vi - 1]); - compParam[3] = dsWidth; - compParam[4] = dsHeight; - } - setMaxHFactor(hmax); - setMaxVFactor(vmax); - } - - int roundUpToMultiple(int anInteger, int mInteger) { - int a = anInteger + mInteger - 1; - return a - (a % mInteger); - } - - /* - * Verify the information contained in the receiver is correct. - * Answer true if the header contains a valid marker. Otherwise, - * answer false. Valid Start Of Frame markers are: - * SOF_0 - Baseline DCT, Huffman coding - * SOF_1 - Extended sequential DCT, Huffman coding - * SOF_2 - Progressive DCT, Huffman coding - * SOF_3 - Lossless (sequential), Huffman coding - * SOF_5 - Differential sequential, Huffman coding - * SOF_6 - Differential progressive, Huffman coding - * SOF_7 - Differential lossless, Huffman coding - * SOF_9 - Extended sequential DCT, arithmetic coding - * SOF_10 - Progressive DCT, arithmetic coding - * SOF_11 - Lossless (sequential), arithmetic coding - * SOF_13 - Differential sequential, arithmetic coding - * SOF_14 - Differential progressive, arithmetic coding - * SOF_15 - Differential lossless, arithmetic coding - */ - public boolean verify() { - int marker = getSegmentMarker(); - return (marker >= JPEGFileFormat.SOF0 && marker <= JPEGFileFormat.SOF3) || - (marker >= JPEGFileFormat.SOF5 && marker <= JPEGFileFormat.SOF7) || - (marker >= JPEGFileFormat.SOF9 && marker <= JPEGFileFormat.SOF11) || - (marker >= JPEGFileFormat.SOF13 && marker <= JPEGFileFormat.SOF15); - } - - public boolean isProgressive() { - int marker = getSegmentMarker(); - return marker == JPEGFileFormat.SOF2 - || marker == JPEGFileFormat.SOF6 - || marker == JPEGFileFormat.SOF10 - || marker == JPEGFileFormat.SOF14; - } - - public boolean isArithmeticCoding() { - return getSegmentMarker() >= JPEGFileFormat.SOF9; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java deleted file mode 100755 index 043c6157e0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -/** - * JPEGHuffmanTable class actually represents two types of object: - * 1) A DHT (Define Huffman Tables) segment, which may represent - * as many as 4 Huffman tables. In this case, the tables are - * stored in the allTables array. - * 2) A single Huffman table. In this case, the allTables array - * will be null. - * The 'reference' field is stored in both types of object, but - * 'initialize' is only called if the object represents a DHT. - */ -final class JPEGHuffmanTable extends JPEGVariableSizeSegment { - JPEGHuffmanTable[] allTables; - int tableClass; - int tableIdentifier; - int[] dhMaxCodes; - int[] dhMinCodes; - int[] dhValPtrs; - int[] dhValues; - int[] ehCodes; - byte[] ehCodeLengths; - static byte[] DCLuminanceTable = { - (byte)255, (byte)196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 - }; - static byte[] DCChrominanceTable = { - (byte)255, (byte)196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 - }; - static byte[] ACLuminanceTable = { - (byte)255, (byte)196, 0, (byte)181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, - 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, - 50, (byte)129, (byte)145, (byte)161, 8, 35, 66, (byte)177, (byte)193, 21, 82, (byte)209, (byte)240, 36, 51, 98, - 114, (byte)130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, - 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, - 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, - 119, 120, 121, 122, (byte)131, (byte)132, (byte)133, (byte)134, (byte)135, (byte)136, (byte)137, (byte)138, (byte)146, (byte)147, (byte)148, - (byte)149, (byte)150, (byte)151, (byte)152, (byte)153, (byte)154, (byte)162, (byte)163, (byte)164, (byte)165, (byte)166, (byte)167, (byte)168, (byte)169, (byte)170, - (byte)178, (byte)179, (byte)180, (byte)181, (byte)182, (byte)183, (byte)184, (byte)185, (byte)186, (byte)194, (byte)195, (byte)196, (byte)197, (byte)198, (byte)199, - (byte)200, (byte)201, (byte)202, (byte)210, (byte)211, (byte)212, (byte)213, (byte)214, (byte)215, (byte)216, (byte)217, (byte)218, (byte)225, (byte)226, (byte)227, - (byte)228, (byte)229, (byte)230, (byte)231, (byte)232, (byte)233, (byte)234, (byte)241, (byte)242, (byte)243, (byte)244, (byte)245, (byte)246, (byte)247, (byte)248, - (byte)249, (byte)250 - }; - static byte[] ACChrominanceTable = { - (byte)255, (byte)196, 0, (byte)181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, - 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, - 50, (byte)129, 8, 20, 66, (byte)145, (byte)161, (byte)177, (byte)193, 9, 35, - 51, 82, (byte)240, 21, 98, 114, (byte)209, 10, 22, 36, 52, (byte)225, 37, - (byte)241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, - 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, - 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, (byte)130, - (byte)131, (byte)132, (byte)133, (byte)134, (byte)135, (byte)136, (byte)137, - (byte)138, (byte)146, (byte)147, (byte)148, (byte)149, (byte)150, (byte)151, - (byte)152, (byte)153, (byte)154, (byte)162, (byte)163, (byte)164, (byte)165, - (byte)166, (byte)167, (byte)168, (byte)169, (byte)170, (byte)178, (byte)179, - (byte)180, (byte)181, (byte)182, (byte)183, (byte)184, (byte)185, (byte)186, - (byte)194, (byte)195, (byte)196, (byte)197, (byte)198, (byte)199, (byte)200, - (byte)201, (byte)202, (byte)210, (byte)211, (byte)212, (byte)213, (byte)214, - (byte)215, (byte)216, (byte)217, (byte)218, (byte)226, (byte)227, (byte)228, - (byte)229, (byte)230, (byte)231, (byte)232, (byte)233, (byte)234, (byte)242, - (byte)243, (byte)244, (byte)245, (byte)246, (byte)247, (byte)248, (byte)249, - (byte)250 - }; - -public JPEGHuffmanTable(byte[] reference) { - super(reference); -} - -public JPEGHuffmanTable(LEDataInputStream byteStream) { - super(byteStream); - initialize(); -} - -public JPEGHuffmanTable[] getAllTables() { - return allTables; -} - -public static JPEGHuffmanTable getDefaultACChrominanceTable() { - JPEGHuffmanTable result = new JPEGHuffmanTable(ACChrominanceTable); - result.initialize(); - return result; -} - -public static JPEGHuffmanTable getDefaultACLuminanceTable() { - JPEGHuffmanTable result = new JPEGHuffmanTable(ACLuminanceTable); - result.initialize(); - return result; -} - -public static JPEGHuffmanTable getDefaultDCChrominanceTable() { - JPEGHuffmanTable result = new JPEGHuffmanTable(DCChrominanceTable); - result.initialize(); - return result; -} - -public static JPEGHuffmanTable getDefaultDCLuminanceTable() { - JPEGHuffmanTable result = new JPEGHuffmanTable(DCLuminanceTable); - result.initialize(); - return result; -} - -public int[] getDhMaxCodes() { - return dhMaxCodes; -} - -public int[] getDhMinCodes() { - return dhMinCodes; -} - -public int[] getDhValPtrs() { - return dhValPtrs; -} - -public int[] getDhValues() { - return dhValues; -} - -public int getTableClass() { - return tableClass; -} - -public int getTableIdentifier() { - return tableIdentifier; -} - -void initialize() { - int totalLength = getSegmentLength() - 2; - int ofs = 4; - int[] bits = new int[16]; - JPEGHuffmanTable[] huffTables = new JPEGHuffmanTable[8]; // maximum is 4 AC + 4 DC - int huffTableCount = 0; - while (totalLength > 0) { - int tc = (reference[ofs] & 0xFF) >> 4; // table class: AC (1) or DC (0) - int tid = reference[ofs] & 0xF; // table id: 0-1 baseline, 0-3 prog/ext - ofs++; - - /* Read the 16 count bytes and add them together to get the table size. */ - int count = 0; - for (int i = 0; i < bits.length; i++) { - int bCount = reference[ofs + i] & 0xFF; - bits[i] = bCount; - count += bCount; - } - ofs += 16; - totalLength -= 17; - - /* Read the table. */ - int[] huffVals = new int[count]; - for (int i = 0; i < count; i++) { - huffVals[i] = reference[ofs + i] & 0xFF; - } - ofs += count; - totalLength -= count; - - /* Calculate the lengths. */ - int[] huffCodeLengths = new int[50]; // start with 50 and increment as needed - int huffCodeLengthsIndex = 0; - for (int i = 0; i < 16; i++) { - for (int j = 0; j < bits[i]; j++) { - if (huffCodeLengthsIndex >= huffCodeLengths.length) { - int[] newHuffCodeLengths = new int[huffCodeLengths.length + 50]; - System.arraycopy(huffCodeLengths, 0, newHuffCodeLengths, 0, huffCodeLengths.length); - huffCodeLengths = newHuffCodeLengths; - } - huffCodeLengths[huffCodeLengthsIndex] = i + 1; - huffCodeLengthsIndex++; - } - } - - /* Truncate huffCodeLengths to the correct size. */ - if (huffCodeLengthsIndex < huffCodeLengths.length) { - int[] newHuffCodeLengths = new int[huffCodeLengthsIndex]; - System.arraycopy(huffCodeLengths, 0, newHuffCodeLengths, 0, huffCodeLengthsIndex); - huffCodeLengths = newHuffCodeLengths; - } - - /* Calculate the Huffman codes. */ - int[] huffCodes = new int[50]; // start with 50 and increment as needed - int huffCodesIndex = 0; - int k = 1; - int code = 0; - int si = huffCodeLengths[0]; - int p = 0; - while (p < huffCodeLengthsIndex) { - while ((p < huffCodeLengthsIndex) && (huffCodeLengths[p] == si)) { - if (huffCodesIndex >= huffCodes.length) { - int[] newHuffCodes = new int[huffCodes.length + 50]; - System.arraycopy(huffCodes, 0, newHuffCodes, 0, huffCodes.length); - huffCodes = newHuffCodes; - } - huffCodes[huffCodesIndex] = code; - huffCodesIndex++; - code++; - p++; - } - code *= 2; - si++; - } - - /* Truncate huffCodes to the correct size. */ - if (huffCodesIndex < huffCodes.length) { - int[] newHuffCodes = new int[huffCodesIndex]; - System.arraycopy(huffCodes, 0, newHuffCodes, 0, huffCodesIndex); - huffCodes = newHuffCodes; - } - - /* Calculate the maximum and minimum codes */ - k = 0; - int[] maxCodes = new int[16]; - int[] minCodes = new int[16]; - int[] valPtrs = new int[16]; - for (int i = 0; i < 16; i++) { - int bSize = bits[i]; - if (bSize == 0) { - maxCodes[i] = -1; - } else { - valPtrs[i] = k; - minCodes[i] = huffCodes[k]; - k += bSize; - maxCodes[i] = huffCodes[k - 1]; - } - } - - /* Calculate the eHuffman codes and lengths. */ - int[] eHuffCodes = new int[256]; - byte[] eHuffSize = new byte[256]; - for (int i = 0; i < huffCodesIndex; i++) { - eHuffCodes[huffVals[i]] = huffCodes[i]; - eHuffSize[huffVals[i]] = (byte)huffCodeLengths[i]; - } - - /* Create the new JPEGHuffmanTable and add it to the allTables array. */ - JPEGHuffmanTable dhtTable = new JPEGHuffmanTable(reference); - dhtTable.tableClass = tc; - dhtTable.tableIdentifier = tid; - dhtTable.dhValues = huffVals; - dhtTable.dhMinCodes = minCodes; - dhtTable.dhMaxCodes = maxCodes; - dhtTable.dhValPtrs = valPtrs; - dhtTable.ehCodes = eHuffCodes; - dhtTable.ehCodeLengths = eHuffSize; - huffTables[huffTableCount] = dhtTable; - huffTableCount++; - } - allTables = new JPEGHuffmanTable[huffTableCount]; - System.arraycopy(huffTables, 0, allTables, 0, huffTableCount); -} - -public int signature() { - return JPEGFileFormat.DHT; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java deleted file mode 100755 index 18eab61ff6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGQuantizationTable extends JPEGVariableSizeSegment { - public static byte[] DefaultLuminanceQTable = { - (byte)255, (byte)219, 0, 67, 0, - 16, 11, 10, 16, 24, 40, 51, 61, - 12, 12, 14, 19, 26, 58, 60, 55, - 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, - 18, 22, 37, 56, 68, 109, 103, 77, - 24, 35, 55, 64, 81, 104, 113, 92, - 49, 64, 78, 87, 103, 121, 120, 101, - 72, 92, 95, 98, 112, 100, 103, 99 - }; - public static byte[] DefaultChrominanceQTable = { - (byte)255, (byte)219, 0, 67, 1, - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 - }; - -public JPEGQuantizationTable(byte[] reference) { - super(reference); -} - -public JPEGQuantizationTable(LEDataInputStream byteStream) { - super(byteStream); -} - -public static JPEGQuantizationTable defaultChrominanceTable() { - byte[] data = new byte[DefaultChrominanceQTable.length]; - System.arraycopy(DefaultChrominanceQTable, 0, data, 0, data.length); - return new JPEGQuantizationTable(data); -} - -public static JPEGQuantizationTable defaultLuminanceTable() { - byte[] data = new byte[DefaultLuminanceQTable.length]; - System.arraycopy(DefaultLuminanceQTable, 0, data, 0, data.length); - return new JPEGQuantizationTable(data); -} - -public int[] getQuantizationTablesKeys() { - int[] keys = new int[4]; - int keysIndex = 0; - int totalLength = getSegmentLength() - 2; - int ofs = 4; - while (totalLength > 64) { - int tq = reference[ofs] & 0xF; - int pq = (reference[ofs] & 0xFF) >> 4; - if (pq == 0) { - ofs += 65; - totalLength -= 65; - } else { - ofs += 129; - totalLength -= 129; - } - if (keysIndex >= keys.length) { - int[] newKeys = new int[keys.length + 4]; - System.arraycopy(keys, 0, newKeys, 0, keys.length); - keys = newKeys; - } - keys[keysIndex] = tq; - keysIndex++; - } - int[] newKeys = new int[keysIndex]; - System.arraycopy(keys, 0, newKeys, 0, keysIndex); - return newKeys; -} - -public int[][] getQuantizationTablesValues() { - int[][] values = new int[4][]; - int valuesIndex = 0; - int totalLength = getSegmentLength() - 2; - int ofs = 4; - while (totalLength > 64) { - int[] qk = new int[64]; - int pq = (reference[ofs] & 0xFF) >> 4; - if (pq == 0) { - for (int i = 0; i < qk.length; i++) { - qk[i] = reference[ofs + i + 1] & 0xFF; - } - ofs += 65; - totalLength -= 65; - } else { - for (int i = 0; i < qk.length; i++) { - int idx = (i - 1) * 2 ; - qk[i] = (reference[ofs + idx + 1] & 0xFF) * 256 + (reference[ofs + idx + 2] & 0xFF); - } - ofs += 129; - totalLength -= 129; - } - if (valuesIndex >= values.length) { - int[][] newValues = new int[values.length + 4][]; - System.arraycopy(values, 0, newValues, 0, values.length); - values = newValues; - } - values[valuesIndex] = qk; - valuesIndex++; - } - int[][] newValues = new int[valuesIndex][]; - System.arraycopy(values, 0, newValues, 0, valuesIndex); - return newValues; -} - -public void scaleBy(int qualityFactor) { - int qFactor = qualityFactor; - if (qFactor <= 0) { - qFactor = 1; - } - if (qFactor > 100) { - qFactor = 100; - } - if (qFactor < 50) { - qFactor = 5000 / qFactor; - } else { - qFactor = 200 - (qFactor * 2); - } - int totalLength = getSegmentLength() - 2; - int ofs = 4; - while (totalLength > 64) { -// int tq = reference[ofs] & 0xFF; - int pq = (reference[ofs] & 0xFF) >> 4; - if (pq == 0) { - for (int i = ofs + 1; i <= ofs + 64; i++) { - int temp = ((reference[i] & 0xFF) * qFactor + 50) / 100; - if (temp <= 0) temp = 1; - if (temp > 255) temp = 255; - reference[i] = (byte)temp; - } - ofs += 65; - totalLength -= 65; - } else { - for (int i = ofs + 1; i <= ofs + 128; i += 2) { - int temp = (((reference[i] & 0xFF) * 256 + (reference[i + 1] & 0xFF)) * qFactor + 50) / 100; - if (temp <= 0) temp = 1; - if (temp > 32767) temp = 32767; - reference[i] = (byte)(temp >> 8); - reference[i + 1] = (byte)(temp & 0xFF); - } - ofs += 129; - totalLength -= 129; - } - } -} - -public int signature() { - return JPEGFileFormat.DQT; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java deleted file mode 100755 index fd6fc48ef0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGRestartInterval extends JPEGFixedSizeSegment { - - public JPEGRestartInterval(LEDataInputStream byteStream) { - super(byteStream); - } - - public int signature() { - return JPEGFileFormat.DRI; - } - - public int getRestartInterval() { - return ((reference[4] & 0xFF) << 8 | (reference[5] & 0xFF)); - } - - public int fixedSize() { - return 6; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java deleted file mode 100755 index ae8d25d884..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -final class JPEGScanHeader extends JPEGVariableSizeSegment { - public int[][] componentParameters; - -public JPEGScanHeader(byte[] reference) { - super(reference); -} - -public JPEGScanHeader(LEDataInputStream byteStream) { - super(byteStream); - initializeComponentParameters(); -} - -public int getApproxBitPositionHigh() { - return reference[(2 * getNumberOfImageComponents()) + 7] >> 4; -} - -public int getApproxBitPositionLow() { - return reference[(2 * getNumberOfImageComponents()) + 7] & 0xF; -} - -public int getEndOfSpectralSelection() { - return reference[(2 * getNumberOfImageComponents()) + 6]; -} - -public int getNumberOfImageComponents() { - return reference[4]; -} - -public int getStartOfSpectralSelection() { - return reference[(2 * getNumberOfImageComponents()) + 5]; -} - -/* Used when decoding. */ -void initializeComponentParameters() { - int compCount = getNumberOfImageComponents(); - componentParameters = new int[0][]; - for (int i = 0; i < compCount; i++) { - int ofs = 5 + i * 2; - int cid = reference[ofs] & 0xFF; - int dc = (reference[ofs + 1] & 0xFF) >> 4; - int ac = reference[ofs + 1] & 0xF; - if (componentParameters.length <= cid) { - int[][] newParams = new int[cid + 1][]; - System.arraycopy(componentParameters, 0, newParams, 0, componentParameters.length); - componentParameters = newParams; - } - componentParameters[cid] = new int[] { dc, ac }; - } -} - -/* Used when encoding. */ -public void initializeContents() { - int compCount = getNumberOfImageComponents(); - int[][] compSpecParams = componentParameters; - if (compCount == 0 || compCount != compSpecParams.length) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - for (int i = 0; i < compCount; i++) { - int ofs = i * 2 + 5; - int[] compParams = compSpecParams[i]; - reference[ofs] = (byte)(i + 1); - reference[ofs + 1] = (byte)(compParams[0] * 16 + compParams[1]); - } -} - -public void setEndOfSpectralSelection(int anInteger) { - reference[(2 * getNumberOfImageComponents()) + 6] = (byte)anInteger; -} - -public void setNumberOfImageComponents(int anInteger) { - reference[4] = (byte)(anInteger & 0xFF); -} - -public void setStartOfSpectralSelection(int anInteger) { - reference[(2 * getNumberOfImageComponents()) + 5] = (byte)anInteger; -} - -public int signature() { - return JPEGFileFormat.SOS; -} - -public boolean verifyProgressiveScan() { - int start = getStartOfSpectralSelection(); - int end = getEndOfSpectralSelection(); - int low = getApproxBitPositionLow(); - int high = getApproxBitPositionHigh(); - int count = getNumberOfImageComponents(); - if ((start == 0 && end == 00) || (start <= end && end <= 63)) { - if (low <= 13 && high <= 13 && (high == 0 || high == low + 1)) { - return start == 0 || (start > 0 && count == 1); - } - } - return false; -} - -public boolean isACProgressiveScan() { - return getStartOfSpectralSelection() != 0 && getEndOfSpectralSelection() != 0; -} - -public boolean isDCProgressiveScan() { - return getStartOfSpectralSelection() == 0 && getEndOfSpectralSelection() == 0; -} - -public boolean isFirstScan() { - return getApproxBitPositionHigh() == 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java deleted file mode 100755 index 0dbf42aa89..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -class JPEGSegment { - public byte[] reference; - - JPEGSegment() { - } - - public JPEGSegment(byte[] reference) { - this.reference = reference; - } - - public int signature() { - return 0; - } - - public boolean verify() { - return getSegmentMarker() == signature(); - } - - public int getSegmentMarker() { - return ((reference[0] & 0xFF) << 8 | (reference[1] & 0xFF)); - } - - public void setSegmentMarker(int marker) { - reference[0] = (byte)((marker & 0xFF00) >> 8); - reference[1] = (byte)(marker & 0xFF); - } - - public int getSegmentLength() { - return ((reference[2] & 0xFF) << 8 | (reference[3] & 0xFF)); - } - - public void setSegmentLength(int length) { - reference[2] = (byte)((length & 0xFF00) >> 8); - reference[3] = (byte)(length & 0xFF); - } - - public boolean writeToStream(LEDataOutputStream byteStream) { - try { - byteStream.write(reference); - return true; - } catch (Exception e) { - return false; - } - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java deleted file mode 100755 index 5b809994e4..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class JPEGStartOfImage extends JPEGFixedSizeSegment { - - public JPEGStartOfImage() { - super(); - } - - public JPEGStartOfImage(byte[] reference) { - super(reference); - } - - public JPEGStartOfImage(LEDataInputStream byteStream) { - super(byteStream); - } - - public int signature() { - return JPEGFileFormat.SOI; - } - - public int fixedSize() { - return 2; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java deleted file mode 100755 index a3896e6706..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -abstract class JPEGVariableSizeSegment extends JPEGSegment { - - public JPEGVariableSizeSegment(byte[] reference) { - super(reference); - } - - public JPEGVariableSizeSegment(LEDataInputStream byteStream) { - try { - byte[] header = new byte[4]; - byteStream.read(header); - reference = header; // to use getSegmentLength() - byte[] contents = new byte[getSegmentLength() + 2]; - contents[0] = header[0]; - contents[1] = header[1]; - contents[2] = header[2]; - contents[3] = header[3]; - byteStream.read(contents, 4, contents.length - 4); - reference = contents; - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java deleted file mode 100755 index f399989a32..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import java.io.*; - -final class LEDataInputStream extends InputStream { - int position; - InputStream in; - - /** - * The byte array containing the bytes to read. - */ - protected byte[] buf; - - /** - * The current position within the byte array <code>buf</code>. A value - * equal to buf.length indicates no bytes available. A value of - * 0 indicates the buffer is full. - */ - protected int pos; - - - public LEDataInputStream(InputStream input) { - this(input, 512); - } - - public LEDataInputStream(InputStream input, int bufferSize) { - this.in = input; - if (bufferSize > 0) { - buf = new byte[bufferSize]; - pos = bufferSize; - } - else throw new IllegalArgumentException(); - } - - public void close() throws IOException { - buf = null; - if (in != null) { - in.close(); - in = null; - } - } - - /** - * Answer how many bytes were read. - */ - public int getPosition() { - return position; - } - - /** - * Answers how many bytes are available for reading without blocking - */ - public int available() throws IOException { - if (buf == null) throw new IOException(); - return (buf.length - pos) + in.available(); - } - - /** - * Answer the next byte of the input stream. - */ - public int read() throws IOException { - if (buf == null) throw new IOException(); - if (pos < buf.length) { - position++; - return (buf[pos++] & 0xFF); - } - int c = in.read(); - if (c != -1) position++; - return c; - } - - /** - * Don't imitate the JDK behaviour of reading a random number - * of bytes when you can actually read them all. - */ - public int read(byte b[], int off, int len) throws IOException { - int read = 0, count; - while (read != len && (count = readData(b, off, len - read)) != -1) { - off += count; - read += count; - } - position += read; - if (read == 0 && read != len) return -1; - return read; - } - - /** - * Reads at most <code>length</code> bytes from this LEDataInputStream and - * stores them in byte array <code>buffer</code> starting at <code>offset</code>. - * <p> - * Answer the number of bytes actually read or -1 if no bytes were read and - * end of stream was encountered. This implementation reads bytes from - * the pushback buffer first, then the target stream if more bytes are required - * to satisfy <code>count</code>. - * </p> - * @param buffer the byte array in which to store the read bytes. - * @param offset the offset in <code>buffer</code> to store the read bytes. - * @param length the maximum number of bytes to store in <code>buffer</code>. - * - * @return int the number of bytes actually read or -1 if end of stream. - * - * @exception java.io.IOException if an IOException occurs. - */ - private int readData(byte[] buffer, int offset, int length) throws IOException { - if (buf == null) throw new IOException(); - if (offset < 0 || offset > buffer.length || - length < 0 || (length > buffer.length - offset)) { - throw new ArrayIndexOutOfBoundsException(); - } - - int cacheCopied = 0; - int newOffset = offset; - - // Are there pushback bytes available? - int available = buf.length - pos; - if (available > 0) { - cacheCopied = (available >= length) ? length : available; - System.arraycopy(buf, pos, buffer, newOffset, cacheCopied); - newOffset += cacheCopied; - pos += cacheCopied; - } - - // Have we copied enough? - if (cacheCopied == length) return length; - - int inCopied = in.read(buffer, newOffset, length - cacheCopied); - - if (inCopied > 0) return inCopied + cacheCopied; - if (cacheCopied == 0) return inCopied; - return cacheCopied; - } - - /** - * Answer an integer comprised of the next - * four bytes of the input stream. - */ - public int readInt() throws IOException { - byte[] buf = new byte[4]; - read(buf); - return ((buf[3] & 0xFF) << 24) | - ((buf[2] & 0xFF) << 16) | - ((buf[1] & 0xFF) << 8) | - (buf[0] & 0xFF); - } - - /** - * Answer a short comprised of the next - * two bytes of the input stream. - */ - public short readShort() throws IOException { - byte[] buf = new byte[2]; - read(buf); - return (short)(((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF)); - } - - /** - * Push back the entire content of the given buffer <code>b</code>. - * <p> - * The bytes are pushed so that they would be read back b[0], b[1], etc. - * If the push back buffer cannot handle the bytes copied from <code>b</code>, - * an IOException will be thrown and no byte will be pushed back. - * </p> - * - * @param b the byte array containing bytes to push back into the stream - * - * @exception java.io.IOException if the pushback buffer is too small - */ - public void unread(byte[] b) throws IOException { - int length = b.length; - if (length > pos) throw new IOException(); - position -= length; - pos -= length; - System.arraycopy(b, 0, buf, pos, length); - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java deleted file mode 100755 index bd8a330280..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import java.io.*; - -final class LEDataOutputStream extends OutputStream { - OutputStream out; -public LEDataOutputStream(OutputStream output) { - this.out = output; -} -/** - * Write the specified number of bytes of the given byte array, - * starting at the specified offset, to the output stream. - */ -public void write(byte b[], int off, int len) throws IOException { - out.write(b, off, len); -} -/** - * Write the given byte to the output stream. - */ -public void write(int b) throws IOException { - out.write(b); -} -/** - * Write the given byte to the output stream. - */ -public void writeByte(byte b) throws IOException { - out.write(b & 0xFF); -} -/** - * Write the four bytes of the given integer - * to the output stream. - */ -public void writeInt(int theInt) throws IOException { - out.write(theInt & 0xFF); - out.write((theInt >> 8) & 0xFF); - out.write((theInt >> 16) & 0xFF); - out.write((theInt >> 24) & 0xFF); -} -/** - * Write the two bytes of the given short - * to the output stream. - */ -public void writeShort(int theShort) throws IOException { - out.write(theShort & 0xFF); - out.write((theShort >> 8) & 0xFF); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java deleted file mode 100755 index 190ff01b7e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java +++ /dev/null @@ -1,477 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -final class LZWCodec { - int bitsPerPixel, blockSize, blockIndex, currentByte, bitsLeft, - codeSize, clearCode, endCode, newCodes, topSlot, currentSlot, - imageWidth, imageHeight, imageX, imageY, pass, line, codeMask; - byte[] block, lineArray; - int[] stack, suffix, prefix; - LZWNode[] nodeStack; - LEDataInputStream inputStream; - LEDataOutputStream outputStream; - ImageData image; - ImageLoader loader; - boolean interlaced; - static final int[] MASK_TABLE = new int[] { - 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, - 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF - }; - -/** - * Decode the input. - */ -void decode() { - int code; - int oc = 0; - int fc = 0; - byte[] buf = new byte[imageWidth]; - int stackIndex = 0; - int bufIndex = 0; - int c; - while ((c = nextCode()) != endCode) { - if (c == clearCode) { - codeSize = bitsPerPixel + 1; - codeMask = MASK_TABLE[bitsPerPixel]; - currentSlot = newCodes; - topSlot = 1 << codeSize; - while ((c = nextCode()) == clearCode) {} - if (c != endCode) { - oc = fc = c; - buf[bufIndex] = (byte)c; - bufIndex++; - if (bufIndex == imageWidth) { - nextPutPixels(buf); - bufIndex = 0; - } - } - } else { - code = c; - if (code >= currentSlot) { - code = oc; - stack[stackIndex] = fc; - stackIndex++; - } - while (code >= newCodes) { - stack[stackIndex] = suffix[code]; - stackIndex++; - code = prefix[code]; - } - stack[stackIndex] = code; - stackIndex++; - if (currentSlot < topSlot) { - fc = code; - suffix[currentSlot] = fc; - prefix[currentSlot] = oc; - currentSlot++; - oc = c; - } - if (currentSlot >= topSlot) { - if (codeSize < 12) { - codeMask = MASK_TABLE[codeSize]; - codeSize++; - topSlot = topSlot + topSlot; - } - } - while (stackIndex > 0) { - stackIndex--; - buf[bufIndex] = (byte)stack[stackIndex]; - bufIndex++; - if (bufIndex == imageWidth) { - nextPutPixels(buf); - bufIndex = 0; - } - } - } - } - if (bufIndex != 0 && line < imageHeight) { - nextPutPixels(buf); - } -} -/** - * Decode the LZW-encoded bytes in the given byte stream - * into the given DeviceIndependentImage. - */ -public void decode(LEDataInputStream inputStream, ImageLoader loader, ImageData image, boolean interlaced, int depth) { - this.inputStream = inputStream; - this.loader = loader; - this.image = image; - this.interlaced = interlaced; - this.bitsPerPixel = depth; - initializeForDecoding(); - decode(); -} -/** - * Encode the image. - */ -void encode() { - nextPutCode(clearCode); - int lastPrefix = encodeLoop(); - nextPutCode(lastPrefix); - nextPutCode(endCode); - - // Write out last partial block - if (bitsLeft == 8) { - block[0] = (byte)(blockIndex - 1); // Nothing in last byte - } else { - block[0] = (byte)(blockIndex); // Last byte has data - } - writeBlock(); - - // Write out empty block to indicate the end (if needed) - if (block[0] != 0) { - block[0] = 0; - writeBlock(); - } -} -/** - * Encode the bytes into the given byte stream - * from the given DeviceIndependentImage. - */ -public void encode(LEDataOutputStream byteStream, ImageData image) { - this.outputStream = byteStream; - this.image = image; - initializeForEncoding(); - encode(); -} -/** - * Encoding loop broken out to allow early return. - */ -int encodeLoop() { - int pixel = nextPixel(); - boolean found; - LZWNode node; - while (true) { - int currentPrefix = pixel; - node = nodeStack[currentPrefix]; - found = true; - pixel = nextPixel(); - if (pixel < 0) - return currentPrefix; - while (found && (node.children != null)) { - node = node.children; - while (found && (node.suffix != pixel)) { - if (pixel < node.suffix) { - if (node.left == null) { - node.left = new LZWNode(); - found = false; - } - node = node.left; - } else { - if (node.right == null) { - node.right = new LZWNode(); - found = false; - } - node = node.right; - } - } - if (found) { - currentPrefix = node.code; - pixel = nextPixel(); - if (pixel < 0) - return currentPrefix; - } - } - if (found) { - node.children = new LZWNode(); - node = node.children; - } - node.children = null; - node.left = null; - node.right = null; - node.code = currentSlot; - node.prefix = currentPrefix; - node.suffix = pixel; - nextPutCode(currentPrefix); - currentSlot++; - // Off by one? - if (currentSlot < 4096) { - if (currentSlot > topSlot) { - codeSize++; - codeMask = MASK_TABLE[codeSize - 1]; - topSlot *= 2; - } - } else { - nextPutCode(clearCode); - for (int i = 0; i < nodeStack.length; i++) - nodeStack[i].children = null; - codeSize = bitsPerPixel + 1; - codeMask = MASK_TABLE[codeSize - 1]; - currentSlot = newCodes; - topSlot = 1 << codeSize; - } - } -} -/** - * Initialize the receiver for decoding the given - * byte array. - */ -void initializeForDecoding() { - pass = 1; - line = 0; - codeSize = bitsPerPixel + 1; - topSlot = 1 << codeSize; - clearCode = 1 << bitsPerPixel; - endCode = clearCode + 1; - newCodes = currentSlot = endCode + 1; - currentByte = -1; - blockSize = bitsLeft = 0; - blockIndex = 0; - codeMask = MASK_TABLE[codeSize - 1]; - stack = new int[4096]; - suffix = new int[4096]; - prefix = new int[4096]; - block = new byte[256]; - imageWidth = image.width; - imageHeight = image.height; -} -/** - * Initialize the receiver for encoding the given - * byte array. - */ -void initializeForEncoding() { - interlaced = false; - bitsPerPixel = image.depth; - codeSize = bitsPerPixel + 1; - topSlot = 1 << codeSize; - clearCode = 1 << bitsPerPixel; - endCode = clearCode + 1; - newCodes = currentSlot = endCode + 1; - bitsLeft = 8; - currentByte = 0; - blockIndex = 1; - blockSize = 255; - block = new byte[blockSize]; - block[0] = (byte)(blockSize - 1); - nodeStack = new LZWNode[1 << bitsPerPixel]; - for (int i = 0; i < nodeStack.length; i++) { - LZWNode node = new LZWNode(); - node.code = i + 1; - node.prefix = -1; - node.suffix = i + 1; - nodeStack[i] = node; - } - imageWidth = image.width; - imageHeight = image.height; - imageY = -1; - lineArray = new byte[imageWidth]; - imageX = imageWidth + 1; // Force a read -} -/** - * Answer the next code from the input byte array. - */ -int nextCode() { - int code; - if (bitsLeft == 0) { - if (blockIndex >= blockSize) { - blockSize = readBlock(); - blockIndex = 0; - if (blockSize == 0) return endCode; - } - blockIndex++; - currentByte = block[blockIndex] & 0xFF; - bitsLeft = 8; - code = currentByte; - } else { - int shift = bitsLeft - 8; - if (shift < 0) - code = currentByte >> (0 - shift); - else - code = currentByte << shift; - } - while (codeSize > bitsLeft) { - if (blockIndex >= blockSize) { - blockSize = readBlock(); - blockIndex = 0; - if (blockSize == 0) return endCode; - } - blockIndex++; - currentByte = block[blockIndex] & 0xFF; - code += currentByte << bitsLeft; - bitsLeft += 8; - } - bitsLeft -= codeSize; - return code & codeMask; -} -/** - * Answer the next pixel to encode in the image - */ -int nextPixel() { - imageX++; - if (imageX > imageWidth) { - imageY++; - if (imageY >= imageHeight) { - return -1; - } else { - nextPixels(lineArray, imageWidth); - } - imageX = 1; - } - return this.lineArray[imageX - 1] & 0xFF; -} -/** - * Copy a row of pixel values from the image. - */ -void nextPixels(byte[] buf, int lineWidth) { - if (image.depth == 8) { - System.arraycopy(image.data, imageY * image.bytesPerLine, buf, 0, lineWidth); - } else { - image.getPixels(0, imageY, lineWidth, buf, 0); - } -} -/** - * Output aCode to the output stream. - */ -void nextPutCode(int aCode) { - int codeToDo = aCode; - int codeBitsToDo = codeSize; - // Fill in the remainder of the current byte with the - // *high-order* bits of the code. - int c = codeToDo & MASK_TABLE[bitsLeft - 1]; - currentByte = currentByte | (c << (8 - bitsLeft)); - block[blockIndex] = (byte)currentByte; - codeBitsToDo -= bitsLeft; - if (codeBitsToDo < 1) { - // The whole code fit in the first byte, so we are done. - bitsLeft -= codeSize; - if (bitsLeft == 0) { - // We used the whole last byte, so get ready - // for the next one. - bitsLeft = 8; - blockIndex++; - if (blockIndex >= blockSize) { - writeBlock(); - blockIndex = 1; - } - currentByte = 0; - } - return; - } - codeToDo = codeToDo >> bitsLeft; - - // Fill in any remaining whole bytes (i.e. not the last one!) - blockIndex++; - if (blockIndex >= blockSize) { - writeBlock(); - blockIndex = 1; - } - while (codeBitsToDo >= 8) { - currentByte = codeToDo & 0xFF; - block[blockIndex] = (byte)currentByte; - codeToDo = codeToDo >> 8; - codeBitsToDo -= 8; - blockIndex++; - if (blockIndex >= blockSize) { - writeBlock(); - blockIndex = 1; - } - } - // Fill the *low-order* bits of the last byte with the remainder - bitsLeft = 8 - codeBitsToDo; - currentByte = codeToDo; - block[blockIndex] = (byte)currentByte; -} -/** - * Copy a row of pixel values to the image. - */ -void nextPutPixels(byte[] buf) { - if (image.depth == 8) { - // Slight optimization for depth = 8. - int start = line * image.bytesPerLine; - for (int i = 0; i < imageWidth; i++) - image.data[start + i] = buf[i]; - } else { - image.setPixels(0, line, imageWidth, buf, 0); - } - if (interlaced) { - if (pass == 1) { - copyRow(buf, 7); - line += 8; - } else if (pass == 2) { - copyRow(buf, 3); - line += 8; - } else if (pass == 3) { - copyRow(buf, 1); - line += 4; - } else if (pass == 4) { - line += 2; - } else if (pass == 5) { - line += 0; - } - if (line >= imageHeight) { - pass++; - if (pass == 2) line = 4; - else if (pass == 3) line = 2; - else if (pass == 4) line = 1; - else if (pass == 5) line = 0; - if (pass < 5) { - if (loader.hasListeners()) { - ImageData imageCopy = (ImageData) image.clone(); - loader.notifyListeners( - new ImageLoaderEvent(loader, imageCopy, pass - 2, false)); - } - } - } - if (line >= imageHeight) line = 0; - } else { - line++; - } -} -/** - * Copy duplicate rows of pixel values to the image. - * This is to fill in rows if the image is interlaced. - */ -void copyRow(byte[] buf, int copies) { - for (int i = 1; i <= copies; i++) { - if (line + i < imageHeight) { - image.setPixels(0, line + i, imageWidth, buf, 0); - } - } -} -/** - * Read a block from the byte stream. - * Return the number of bytes read. - * Throw an exception if the block could not be read. - */ -int readBlock() { - int size = -1; - try { - size = inputStream.read(); - if (size == -1) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - block[0] = (byte)size; - size = inputStream.read(block, 1, size); - if (size == -1) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } - return size; -} -/** - * Write a block to the byte stream. - * Throw an exception if the block could not be written. - */ -void writeBlock() { - try { - outputStream.write(block, 0, (block[0] & 0xFF) + 1); - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java deleted file mode 100755 index 869e532ba3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -final class LZWNode { - public LZWNode left, right, children; - public int code, prefix, suffix; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java deleted file mode 100644 index 4f4a2d34d5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -public final class OS2BMPFileFormat extends FileFormat { - static final int BMPFileHeaderSize = 14; - static final int BMPHeaderFixedSize = 12; - int width, height, bitCount; - -boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] header = new byte[18]; - stream.read(header); - stream.unread(header); - int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24); - return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize == BMPHeaderFixedSize; - } catch (Exception e) { - return false; - } -} -byte[] loadData(byte[] infoHeader) { - int stride = (width * bitCount + 7) / 8; - stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple - byte[] data = loadData(infoHeader, stride); - flipScanLines(data, stride, height); - return data; -} -byte[] loadData(byte[] infoHeader, int stride) { - int dataSize = height * stride; - byte[] data = new byte[dataSize]; - try { - if (inputStream.read(data) != dataSize) - SWT.error(SWT.ERROR_INVALID_IMAGE); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return data; -} -int[] loadFileHeader() { - int[] header = new int[5]; - try { - header[0] = inputStream.readShort(); - header[1] = inputStream.readInt(); - header[2] = inputStream.readShort(); - header[3] = inputStream.readShort(); - header[4] = inputStream.readInt(); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - if (header[0] != 0x4D42) - SWT.error(SWT.ERROR_INVALID_IMAGE); - return header; -} -ImageData[] loadFromByteStream() { - int[] fileHeader = loadFileHeader(); - byte[] infoHeader = new byte[BMPHeaderFixedSize]; - try { - inputStream.read(infoHeader); - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } - width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8); - height = (infoHeader[6] & 0xFF) | ((infoHeader[7] & 0xFF) << 8); - bitCount = (infoHeader[10] & 0xFF) | ((infoHeader[11] & 0xFF) << 8); - PaletteData palette = loadPalette(infoHeader); - if (inputStream.getPosition() < fileHeader[4]) { - // Seek to the specified offset - try { - inputStream.skip(fileHeader[4] - inputStream.getPosition()); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - byte[] data = loadData(infoHeader); - int type = SWT.IMAGE_OS2_BMP; - return new ImageData[] { - ImageData.internal_new( - width, - height, - bitCount, - palette, - 4, - data, - 0, - null, - null, - -1, - -1, - type, - 0, - 0, - 0, - 0) - }; -} -PaletteData loadPalette(byte[] infoHeader) { - if (bitCount <= 8) { - int numColors = 1 << bitCount; - byte[] buf = new byte[numColors * 3]; - try { - if (inputStream.read(buf) != buf.length) - SWT.error(SWT.ERROR_INVALID_IMAGE); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return paletteFromBytes(buf, numColors); - } - if (bitCount == 16) return new PaletteData(0x7C00, 0x3E0, 0x1F); - if (bitCount == 24) return new PaletteData(0xFF, 0xFF00, 0xFF0000); - return new PaletteData(0xFF00, 0xFF0000, 0xFF000000); -} -PaletteData paletteFromBytes(byte[] bytes, int numColors) { - int bytesOffset = 0; - RGB[] colors = new RGB[numColors]; - for (int i = 0; i < numColors; i++) { - colors[i] = new RGB(bytes[bytesOffset + 2] & 0xFF, - bytes[bytesOffset + 1] & 0xFF, - bytes[bytesOffset] & 0xFF); - bytesOffset += 3; - } - return new PaletteData(colors); -} -/** - * Answer a byte array containing the BMP representation of - * the given device independent palette. - */ -static byte[] paletteToBytes(PaletteData pal) { - int n = pal.colors == null ? 0 : (pal.colors.length < 256 ? pal.colors.length : 256); - byte[] bytes = new byte[n * 3]; - int offset = 0; - for (int i = 0; i < n; i++) { - RGB col = pal.colors[i]; - bytes[offset] = (byte)col.blue; - bytes[offset + 1] = (byte)col.green; - bytes[offset + 2] = (byte)col.red; - offset += 3; - } - return bytes; -} -/** - * Unload the given image's data into the given byte stream. - * Answer the number of bytes written. - */ -int unloadData(ImageData image, OutputStream out) { - int bmpBpl = 0; - try { - int bpl = (image.width * image.depth + 7) / 8; - bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes - int linesPerBuf = 32678 / bmpBpl; - byte[] buf = new byte[linesPerBuf * bmpBpl]; - byte[] data = image.data; - int imageBpl = image.bytesPerLine; - int dataIndex = imageBpl * (image.height - 1); // Start at last line - if (image.depth == 16) { - for (int y = 0; y < image.height; y += linesPerBuf) { - int count = image.height - y; - if (linesPerBuf < count) count = linesPerBuf; - int bufOffset = 0; - for (int i = 0; i < count; i++) { - for (int wIndex = 0; wIndex < bpl; wIndex += 2) { - buf[bufOffset + wIndex + 1] = data[dataIndex + wIndex + 1]; - buf[bufOffset + wIndex] = data[dataIndex + wIndex]; - } - bufOffset += bmpBpl; - dataIndex -= imageBpl; - } - out.write(buf, 0, bufOffset); - } - } else { - for (int y = 0; y < image.height; y += linesPerBuf) { - int tmp = image.height - y; - int count = tmp < linesPerBuf ? tmp : linesPerBuf; - int bufOffset = 0; - for (int i = 0; i < count; i++) { - System.arraycopy(data, dataIndex, buf, bufOffset, bpl); - bufOffset += bmpBpl; - dataIndex -= imageBpl; - } - out.write(buf, 0, bufOffset); - } - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return bmpBpl * image.height; -} -/** - * Unload a DeviceIndependentImage using Windows .BMP format into the given - * byte stream. - */ -void unloadIntoByteStream(ImageLoader loader) { - ImageData image = loader.data[0]; - byte[] rgbs; - int numCols; - if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8) || - (image.depth == 16) || (image.depth == 24) || (image.depth == 32))) - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - PaletteData pal = image.palette; - if ((image.depth == 16) || (image.depth == 24) || (image.depth == 32)) { - if (!pal.isDirect) - SWT.error(SWT.ERROR_INVALID_IMAGE); - numCols = 0; - rgbs = null; - } else { - if (pal.isDirect) - SWT.error(SWT.ERROR_INVALID_IMAGE); - numCols = pal.colors.length; - rgbs = paletteToBytes(pal); - } - // Fill in file header, except for bfsize, which is done later. - int headersSize = BMPFileHeaderSize + BMPHeaderFixedSize; - int[] fileHeader = new int[5]; - fileHeader[0] = 0x4D42; // Signature - fileHeader[1] = 0; // File size - filled in later - fileHeader[2] = 0; // Reserved 1 - fileHeader[3] = 0; // Reserved 2 - fileHeader[4] = headersSize; // Offset to data - if (rgbs != null) { - fileHeader[4] += rgbs.length; - } - - // Prepare data. This is done first so we don't have to try to rewind - // the stream and fill in the details later. - ByteArrayOutputStream out = new ByteArrayOutputStream(); - unloadData(image, out); - byte[] data = out.toByteArray(); - - // Calculate file size - fileHeader[1] = fileHeader[4] + data.length; - - // Write the headers - try { - outputStream.writeShort(fileHeader[0]); - outputStream.writeInt(fileHeader[1]); - outputStream.writeShort(fileHeader[2]); - outputStream.writeShort(fileHeader[3]); - outputStream.writeInt(fileHeader[4]); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - try { - outputStream.writeInt(BMPHeaderFixedSize); - outputStream.writeShort(image.width); - outputStream.writeShort(image.height); - outputStream.writeShort(1); - outputStream.writeShort((short)image.depth); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - - // Unload palette - if (numCols > 0) { - try { - outputStream.write(rgbs); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - // Unload the data - try { - outputStream.write(data); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } -} -void flipScanLines(byte[] data, int stride, int height) { - int i1 = 0; - int i2 = (height - 1) * stride; - for (int i = 0; i < height / 2; i++) { - for (int index = 0; index < stride; index++) { - byte b = data[index + i1]; - data[index + i1] = data[index + i2]; - data[index + i2] = b; - } - i1 += stride; - i2 -= stride; - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java deleted file mode 100755 index cf563d4e20..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java +++ /dev/null @@ -1,574 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import java.io.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.*; - -public final class PNGFileFormat extends FileFormat { - static final int SIGNATURE_LENGTH = 8; - static final int PRIME = 65521; - PngIhdrChunk headerChunk; - PngPlteChunk paletteChunk; - ImageData imageData; - byte[] data; - byte[] alphaPalette; - byte headerByte1; - byte headerByte2; - int adler; - -/** - * Skip over signature data. This has already been - * verified in isFileFormat(). - */ -void readSignature() throws IOException { - byte[] signature = new byte[SIGNATURE_LENGTH]; - inputStream.read(signature); -} -/** - * Load the PNG image from the byte stream. - */ -ImageData[] loadFromByteStream() { - try { - readSignature(); - PngChunkReader chunkReader = new PngChunkReader(inputStream); - headerChunk = chunkReader.getIhdrChunk(); - int width = headerChunk.getWidth(), height = headerChunk.getHeight(); - if (width <= 0 || height <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE); - int imageSize = getAlignedBytesPerRow() * height; - data = new byte[imageSize]; - imageData = ImageData.internal_new( - width, - height, - headerChunk.getSwtBitsPerPixel(), - new PaletteData(0, 0, 0), - 4, - data, - 0, - null, - null, - -1, - -1, - SWT.IMAGE_PNG, - 0, - 0, - 0, - 0); - - if (headerChunk.usesDirectColor()) { - imageData.palette = headerChunk.getPaletteData(); - } - - // Read and process chunks until the IEND chunk is encountered. - while (chunkReader.hasMoreChunks()) { - readNextChunk(chunkReader); - } - - return new ImageData[] {imageData}; - } catch (IOException e) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - return null; - } -} -/** - * Read and handle the next chunk of data from the - * PNG file. - */ -void readNextChunk(PngChunkReader chunkReader) throws IOException { - PngChunk chunk = chunkReader.readNextChunk(); - switch (chunk.getChunkType()) { - case PngChunk.CHUNK_IEND: - break; - case PngChunk.CHUNK_PLTE: - if (!headerChunk.usesDirectColor()) { - paletteChunk = (PngPlteChunk) chunk; - imageData.palette = paletteChunk.getPaletteData(); - } - break; - case PngChunk.CHUNK_tRNS: - PngTrnsChunk trnsChunk = (PngTrnsChunk) chunk; - if (trnsChunk.getTransparencyType(headerChunk) == - PngTrnsChunk.TRANSPARENCY_TYPE_PIXEL) - { - imageData.transparentPixel = - trnsChunk.getSwtTransparentPixel(headerChunk); - } else { - alphaPalette = trnsChunk.getAlphaValues(headerChunk, paletteChunk); - int transparentCount = 0, transparentPixel = -1; - for (int i = 0; i < alphaPalette.length; i++) { - if ((alphaPalette[i] & 0xFF) != 255) { - transparentCount++; - transparentPixel = i; - } - } - if (transparentCount == 0) { - alphaPalette = null; - } else if (transparentCount == 1 && alphaPalette[transparentPixel] == 0) { - alphaPalette = null; - imageData.transparentPixel = transparentPixel; - } - } - break; - case PngChunk.CHUNK_IDAT: - if (chunkReader.readPixelData()) { - // All IDAT chunks in an image file must be - // sequential. If the pixel data has already - // been read and another IDAT block is encountered, - // then this is an invalid image. - SWT.error(SWT.ERROR_INVALID_IMAGE); - } else { - // Read in the pixel data for the image. This should - // go through all the image's IDAT chunks. - PngIdatChunk dataChunk = (PngIdatChunk) chunk; - readPixelData(dataChunk, chunkReader); - } - break; - default: - if (chunk.isCritical()) { - // All critical chunks must be supported. - SWT.error(SWT.ERROR_NOT_IMPLEMENTED); - } - } -} -void unloadIntoByteStream(ImageLoader loader) { - PngEncoder encoder = new PngEncoder(loader); - encoder.encode(outputStream); -} -boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] signature = new byte[SIGNATURE_LENGTH]; - stream.read(signature); - stream.unread(signature); - if ((signature[0] & 0xFF) != 137) return false; //137 - if ((signature[1] & 0xFF) != 80) return false; //P - if ((signature[2] & 0xFF) != 78) return false; //N - if ((signature[3] & 0xFF) != 71) return false; //G - if ((signature[4] & 0xFF) != 13) return false; //<RETURN> - if ((signature[5] & 0xFF) != 10) return false; //<LINEFEED> - if ((signature[6] & 0xFF) != 26) return false; //<CTRL/Z> - if ((signature[7] & 0xFF) != 10) return false; //<LINEFEED> - return true; - } catch (Exception e) { - return false; - } -} -/** - * SWT does not support 16-bit depths. If this image uses - * 16-bit depths, convert the data to an 8-bit depth. - */ -byte[] validateBitDepth(byte[] data) { - if (headerChunk.getBitDepth() > 8) { - byte[] result = new byte[data.length / 2]; - compress16BitDepthTo8BitDepth(data, 0, result, 0, result.length); - return result; - } else { - return data; - } -} -/** - * SWT does not support greyscale as a color type. For - * plain grayscale, we create a palette. For Grayscale - * with Alpha, however, we need to convert the pixels - * to use RGB values. - * Note: This method assumes that the bit depth of the - * data has already been restricted to 8 or less. - */ -void setPixelData(byte[] data, ImageData imageData) { - switch (headerChunk.getColorType()) { - case PngIhdrChunk.COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - { - int width = imageData.width; - int height = imageData.height; - int destBytesPerLine = imageData.bytesPerLine; - /* - * If the image uses 16-bit depth, it is converted - * to an 8-bit depth image. - */ - int srcBytesPerLine = getAlignedBytesPerRow(); - if (headerChunk.getBitDepth() > 8) srcBytesPerLine /= 2; - - byte[] rgbData = new byte[destBytesPerLine * height]; - byte[] alphaData = new byte[width * height]; - for (int y = 0; y < height; y++) { - int srcIndex = srcBytesPerLine * y; - int destIndex = destBytesPerLine * y; - int destAlphaIndex = width * y; - for (int x = 0; x < width; x++) { - byte grey = data[srcIndex]; - byte alpha = data[srcIndex + 1]; - rgbData[destIndex + 0] = grey; - rgbData[destIndex + 1] = grey; - rgbData[destIndex + 2] = grey; - alphaData[destAlphaIndex] = alpha; - srcIndex += 2; - destIndex += 3; - destAlphaIndex++; - } - } - imageData.data = rgbData; - imageData.alphaData = alphaData; - break; - } - case PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA: - { - int width = imageData.width; - int height = imageData.height; - int destBytesPerLine = imageData.bytesPerLine; - int srcBytesPerLine = getAlignedBytesPerRow(); - /* - * If the image uses 16-bit depth, it is converted - * to an 8-bit depth image. - */ - if (headerChunk.getBitDepth() > 8) srcBytesPerLine /= 2; - - byte[] rgbData = new byte[destBytesPerLine * height]; - byte[] alphaData = new byte[width * height]; - for (int y = 0; y < height; y++) { - int srcIndex = srcBytesPerLine * y; - int destIndex = destBytesPerLine * y; - int destAlphaIndex = width * y; - for (int x = 0; x < width; x++) { - rgbData[destIndex + 0] = data[srcIndex + 0]; - rgbData[destIndex + 1] = data[srcIndex + 1]; - rgbData[destIndex + 2] = data[srcIndex + 2]; - alphaData[destAlphaIndex] = data[srcIndex + 3]; - srcIndex += 4; - destIndex += 3; - destAlphaIndex++; - } - } - imageData.data = rgbData; - imageData.alphaData = alphaData; - break; - } - case PngIhdrChunk.COLOR_TYPE_RGB: - imageData.data = data; - break; - case PngIhdrChunk.COLOR_TYPE_PALETTE: - imageData.data = data; - if (alphaPalette != null) { - int size = imageData.width * imageData.height; - byte[] alphaData = new byte[size]; - byte[] pixelData = new byte[size]; - imageData.getPixels(0, 0, size, pixelData, 0); - for (int i = 0; i < pixelData.length; i++) { - alphaData[i] = alphaPalette[pixelData[i] & 0xFF]; - } - imageData.alphaData = alphaData; - } - break; - default: - imageData.data = data; - break; - } -} -/** - * PNG supports some color types and bit depths that are - * unsupported by SWT. If the image uses an unsupported - * color type (either of the gray scale types) or bit - * depth (16), convert the data to an SWT-supported - * format. Then assign the data into the ImageData given. - */ -void setImageDataValues(byte[] data, ImageData imageData) { - byte[] result = validateBitDepth(data); - setPixelData(result, imageData); -} -/** - * Read the image data from the data stream. This must handle - * decoding the data, filtering, and interlacing. - */ -void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) throws IOException { - InputStream stream = new PngInputStream(chunk, chunkReader); - //TEMPORARY CODE - boolean use3_2 = System.getProperty("org.eclipse.swt.internal.image.PNGFileFormat_3.2") != null; - InputStream inflaterStream = use3_2 ? null : Compatibility.newInflaterInputStream(stream); - if (inflaterStream != null) { - stream = inflaterStream; - } else { - stream = new PngDecodingDataStream(stream); - } - int interlaceMethod = headerChunk.getInterlaceMethod(); - if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) { - readNonInterlacedImage(stream); - } else { - readInterlacedImage(stream); - } - /* - * InflaterInputStream does not consume all bytes in the stream - * when it is closed. This may leave unread IDAT chunks. The fix - * is to read all available bytes before closing it. - */ - while (stream.available() > 0) stream.read(); - stream.close(); -} -/** - * Answer the number of bytes in a word-aligned row of pixel data. - */ -int getAlignedBytesPerRow() { - return ((getBytesPerRow(headerChunk.getWidth()) + 3) / 4) * 4; -} -/** - * Answer the number of bytes in each row of the image - * data. Each PNG row is byte-aligned, so images with bit - * depths less than a byte may have unused bits at the - * end of each row. The value of these bits is undefined. - */ -int getBytesPerRow() { - return getBytesPerRow(headerChunk.getWidth()); -} -/** - * Answer the number of bytes needed to represent a pixel. - * This value depends on the image's color type and bit - * depth. - * Note that this method rounds up if an image's pixel size - * isn't byte-aligned. - */ -int getBytesPerPixel() { - int bitsPerPixel = headerChunk.getBitsPerPixel(); - return (bitsPerPixel + 7) / 8; -} -/** - * Answer the number of bytes in a row of the given pixel - * width. Each row is byte-aligned, so images with bit - * depths less than a byte may have unused bits at the - * end of each row. The value of these bits is undefined. - */ -int getBytesPerRow(int rowWidthInPixels) { - int bitsPerPixel = headerChunk.getBitsPerPixel(); - int bitsPerRow = bitsPerPixel * rowWidthInPixels; - int bitsPerByte = 8; - return (bitsPerRow + (bitsPerByte - 1)) / bitsPerByte; -} -/** - * 1. Read one of the seven frames of interlaced data. - * 2. Update the imageData. - * 3. Notify the image loader's listeners of the frame load. - */ -void readInterlaceFrame( - InputStream inputStream, - int rowInterval, - int columnInterval, - int startRow, - int startColumn, - int frameCount) throws IOException -{ - int width = headerChunk.getWidth(); - int alignedBytesPerRow = getAlignedBytesPerRow(); - int height = headerChunk.getHeight(); - if (startRow >= height || startColumn >= width) return; - - int pixelsPerRow = (width - startColumn + columnInterval - 1) / columnInterval; - int bytesPerRow = getBytesPerRow(pixelsPerRow); - byte[] row1 = new byte[bytesPerRow]; - byte[] row2 = new byte[bytesPerRow]; - byte[] currentRow = row1; - byte[] lastRow = row2; - for (int row = startRow; row < height; row += rowInterval) { - byte filterType = (byte)inputStream.read(); - int read = 0; - while (read != bytesPerRow) { - read += inputStream.read(currentRow, read, bytesPerRow - read); - } - filterRow(currentRow, lastRow, filterType); - if (headerChunk.getBitDepth() >= 8) { - int bytesPerPixel = getBytesPerPixel(); - int dataOffset = (row * alignedBytesPerRow) + (startColumn * bytesPerPixel); - for (int rowOffset = 0; rowOffset < currentRow.length; rowOffset += bytesPerPixel) { - for (int byteOffset = 0; byteOffset < bytesPerPixel; byteOffset++) { - data[dataOffset + byteOffset] = currentRow[rowOffset + byteOffset]; - } - dataOffset += (columnInterval * bytesPerPixel); - } - } else { - int bitsPerPixel = headerChunk.getBitDepth(); - int pixelsPerByte = 8 / bitsPerPixel; - int column = startColumn; - int rowBase = row * alignedBytesPerRow; - int valueMask = 0; - for (int i = 0; i < bitsPerPixel; i++) { - valueMask <<= 1; - valueMask |= 1; - } - int maxShift = 8 - bitsPerPixel; - for (int byteOffset = 0; byteOffset < currentRow.length; byteOffset++) { - for (int bitOffset = maxShift; bitOffset >= 0; bitOffset -= bitsPerPixel) { - if (column < width) { - int dataOffset = rowBase + (column * bitsPerPixel / 8); - int value = (currentRow[byteOffset] >> bitOffset) & valueMask; - int dataShift = maxShift - (bitsPerPixel * (column % pixelsPerByte)); - data[dataOffset] |= value << dataShift; - } - column += columnInterval; - } - } - } - currentRow = (currentRow == row1) ? row2 : row1; - lastRow = (lastRow == row1) ? row2 : row1; - } - setImageDataValues(data, imageData); - fireInterlacedFrameEvent(frameCount); -} -/** - * Read the pixel data for an interlaced image from the - * data stream. - */ -void readInterlacedImage(InputStream inputStream) throws IOException { - readInterlaceFrame(inputStream, 8, 8, 0, 0, 0); - readInterlaceFrame(inputStream, 8, 8, 0, 4, 1); - readInterlaceFrame(inputStream, 8, 4, 4, 0, 2); - readInterlaceFrame(inputStream, 4, 4, 0, 2, 3); - readInterlaceFrame(inputStream, 4, 2, 2, 0, 4); - readInterlaceFrame(inputStream, 2, 2, 0, 1, 5); - readInterlaceFrame(inputStream, 2, 1, 1, 0, 6); -} -/** - * Fire an event to let listeners know that an interlaced - * frame has been loaded. - * finalFrame should be true if the image has finished - * loading, false if there are more frames to come. - */ -void fireInterlacedFrameEvent(int frameCount) { - if (loader.hasListeners()) { - ImageData image = (ImageData) imageData.clone(); - boolean finalFrame = frameCount == 6; - loader.notifyListeners(new ImageLoaderEvent(loader, image, frameCount, finalFrame)); - } -} -/** - * Read the pixel data for a non-interlaced image from the - * data stream. - * Update the imageData to reflect the new data. - */ -void readNonInterlacedImage(InputStream inputStream) throws IOException { - int dataOffset = 0; - int alignedBytesPerRow = getAlignedBytesPerRow(); - int bytesPerRow = getBytesPerRow(); - byte[] row1 = new byte[bytesPerRow]; - byte[] row2 = new byte[bytesPerRow]; - byte[] currentRow = row1; - byte[] lastRow = row2; - int height = headerChunk.getHeight(); - for (int row = 0; row < height; row++) { - byte filterType = (byte)inputStream.read(); - int read = 0; - while (read != bytesPerRow) { - read += inputStream.read(currentRow, read, bytesPerRow - read); - } - filterRow(currentRow, lastRow, filterType); - System.arraycopy(currentRow, 0, data, dataOffset, bytesPerRow); - dataOffset += alignedBytesPerRow; - currentRow = (currentRow == row1) ? row2 : row1; - lastRow = (lastRow == row1) ? row2 : row1; - } - setImageDataValues(data, imageData); -} -/** - * SWT does not support 16-bit depth color formats. - * Convert the 16-bit data to 8-bit data. - * The correct way to do this is to multiply each - * 16 bit value by the value: - * (2^8 - 1) / (2^16 - 1). - * The fast way to do this is just to drop the low - * byte of the 16-bit value. - */ -static void compress16BitDepthTo8BitDepth( - byte[] source, - int sourceOffset, - byte[] destination, - int destinationOffset, - int numberOfValues) -{ - //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1); - for (int i = 0; i < numberOfValues; i++) { - int sourceIndex = sourceOffset + (2 * i); - int destinationIndex = destinationOffset + i; - //int value = (source[sourceIndex] << 8) | source[sourceIndex + 1]; - //byte compressedValue = (byte)(value * multiplier); - byte compressedValue = source[sourceIndex]; - destination[destinationIndex] = compressedValue; - } -} -/** - * SWT does not support 16-bit depth color formats. - * Convert the 16-bit data to 8-bit data. - * The correct way to do this is to multiply each - * 16 bit value by the value: - * (2^8 - 1) / (2^16 - 1). - * The fast way to do this is just to drop the low - * byte of the 16-bit value. - */ -static int compress16BitDepthTo8BitDepth(int value) { - //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1); - //byte compressedValue = (byte)(value * multiplier); - return value >> 8; -} -/** - * PNG supports four filtering types. These types are applied - * per row of image data. This method unfilters the given row - * based on the filterType. - */ -void filterRow(byte[] row, byte[] previousRow, int filterType) { - int byteOffset = headerChunk.getFilterByteOffset(); - switch (filterType) { - case PngIhdrChunk.FILTER_NONE: - break; - case PngIhdrChunk.FILTER_SUB: - for (int i = byteOffset; i < row.length; i++) { - int current = row[i] & 0xFF; - int left = row[i - byteOffset] & 0xFF; - row[i] = (byte)((current + left) & 0xFF); - } - break; - case PngIhdrChunk.FILTER_UP: - for (int i = 0; i < row.length; i++) { - int current = row[i] & 0xFF; - int above = previousRow[i] & 0xFF; - row[i] = (byte)((current + above) & 0xFF); - } - break; - case PngIhdrChunk.FILTER_AVERAGE: - for (int i = 0; i < row.length; i++) { - int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF; - int above = previousRow[i] & 0xFF; - int current = row[i] & 0xFF; - row[i] = (byte)((current + ((left + above) / 2)) & 0xFF); - } - break; - case PngIhdrChunk.FILTER_PAETH: - for (int i = 0; i < row.length; i++) { - int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF; - int aboveLeft = (i < byteOffset) ? 0 : previousRow[i - byteOffset] & 0xFF; - int above = previousRow[i] & 0xFF; - - int a = Math.abs(above - aboveLeft); - int b = Math.abs(left - aboveLeft); - int c = Math.abs(left - aboveLeft + above - aboveLeft); - - int preductor = 0; - if (a <= b && a <= c) { - preductor = left; - } else if (b <= c) { - preductor = above; - } else { - preductor = aboveLeft; - } - - int currentValue = row[i] & 0xFF; - row[i] = (byte) ((currentValue + preductor) & 0xFF); - } - break; - } -} - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java deleted file mode 100755 index 74b438ea46..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java +++ /dev/null @@ -1,381 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import java.io.*; - -class PngChunk extends Object { - byte[] reference; - - static final int LENGTH_OFFSET = 0; - static final int TYPE_OFFSET = 4; - static final int DATA_OFFSET = 8; - - static final int TYPE_FIELD_LENGTH = 4; - static final int LENGTH_FIELD_LENGTH = 4; - static final int MIN_LENGTH = 12; - - static final int CHUNK_UNKNOWN = -1; - // Critical chunks. - static final int CHUNK_IHDR = 0; - static final int CHUNK_PLTE = 1; - static final int CHUNK_IDAT = 2; - static final int CHUNK_IEND = 3; - // Non-critical chunks. - static final int CHUNK_tRNS = 5; - - static final byte[] TYPE_IHDR = {(byte) 'I', (byte) 'H', (byte) 'D', (byte) 'R'}; - static final byte[] TYPE_PLTE = {(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'}; - static final byte[] TYPE_IDAT = {(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'}; - static final byte[] TYPE_IEND = {(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'}; - static final byte[] TYPE_tRNS = {(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'}; - - static final int[] CRC_TABLE; - static { - CRC_TABLE = new int[256]; - for (int i = 0; i < 256; i++) { - CRC_TABLE[i] = i; - for (int j = 0; j < 8; j++) { - if ((CRC_TABLE[i] & 0x1) == 0) { - CRC_TABLE[i] = (CRC_TABLE[i] >> 1) & 0x7FFFFFFF; - } else { - CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF); - } - } - } - } - - int length; - -/** - * Construct a PngChunk using the reference bytes - * given. - */ -PngChunk(byte[] reference) { - super(); - setReference(reference); - if (reference.length < LENGTH_OFFSET + LENGTH_FIELD_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE); - length = getInt32(LENGTH_OFFSET); -} - -/** - * Construct a PngChunk with the specified number of - * data bytes. - */ -PngChunk(int dataLength) { - this(new byte[MIN_LENGTH + dataLength]); - setLength(dataLength); -} - -/** - * Get the PngChunk's reference byteArray; - */ -byte[] getReference() { - return reference; -} - -/** - * Set the PngChunk's reference byteArray; - */ -void setReference(byte[] reference) { - this.reference = reference; -} - -/** - * Get the 16-bit integer from the reference byte - * array at the given offset. - */ -int getInt16(int offset) { - int answer = 0; - answer |= (reference[offset] & 0xFF) << 8; - answer |= (reference[offset + 1] & 0xFF); - return answer; -} - -/** - * Set the 16-bit integer in the reference byte - * array at the given offset. - */ -void setInt16(int offset, int value) { - reference[offset] = (byte) ((value >> 8) & 0xFF); - reference[offset + 1] = (byte) (value & 0xFF); -} - -/** - * Get the 32-bit integer from the reference byte - * array at the given offset. - */ -int getInt32(int offset) { - int answer = 0; - answer |= (reference[offset] & 0xFF) << 24; - answer |= (reference[offset + 1] & 0xFF) << 16; - answer |= (reference[offset + 2] & 0xFF) << 8; - answer |= (reference[offset + 3] & 0xFF); - return answer; -} - -/** - * Set the 32-bit integer in the reference byte - * array at the given offset. - */ -void setInt32(int offset, int value) { - reference[offset] = (byte) ((value >> 24) & 0xFF); - reference[offset + 1] = (byte) ((value >> 16) & 0xFF); - reference[offset + 2] = (byte) ((value >> 8) & 0xFF); - reference[offset + 3] = (byte) (value & 0xFF); -} - -/** - * Get the length of the data component of this chunk. - * This is not the length of the entire chunk. - */ -int getLength() { - return length; -} - -/** - * Set the length of the data component of this chunk. - * This is not the length of the entire chunk. - */ -void setLength(int value) { - setInt32(LENGTH_OFFSET, value); - length = value; -} - -/** - * Get the chunk type. This is a four byte value. - * Each byte should be an ASCII character. - * The first byte is upper case if the chunk is critical. - * The second byte is upper case if the chunk is publicly defined. - * The third byte must be upper case. - * The fourth byte is upper case if the chunk is unsafe to copy. - * Public chunk types are defined by the PNG Development Group. - */ -byte[] getTypeBytes() { - byte[] type = new byte[4]; - System.arraycopy(reference, TYPE_OFFSET, type, 0, TYPE_FIELD_LENGTH); - return type; -} - -/** - * Set the chunk type. This is a four byte value. - * Each byte should be an ASCII character. - * The first byte is upper case if the chunk is critical. - * The second byte is upper case if the chunk is publicly defined. - * The third byte must be upper case. - * The fourth byte is upper case if the chunk is unsafe to copy. - * Public chunk types are defined by the PNG Development Group. - */ -void setType(byte[] value) { - if (value.length != TYPE_FIELD_LENGTH) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - System.arraycopy(value, 0, reference, TYPE_OFFSET, TYPE_FIELD_LENGTH); -} - -/** - * Get the chunk's data. - */ -byte[] getData() { - int dataLength = getLength(); - if (reference.length < MIN_LENGTH + dataLength) { - SWT.error (SWT.ERROR_INVALID_RANGE); - } - byte[] data = new byte[dataLength]; - System.arraycopy(reference, DATA_OFFSET, data, 0, dataLength); - return data; -} - -/** - * Set the chunk's data. - * This method has two side-effects. - * 1. It will set the length field to be the length - * of the data array given. - * 2. It will set the CRC field to the computed CRC - * value of the data array given. - */ -void setData(byte[] data) { - setLength(data.length); - System.arraycopy(data, 0, reference, DATA_OFFSET, data.length); - setCRC(computeCRC()); -} - -/** - * Get the CRC value for the chunk's data. - * Ensure that the length field has a good - * value before making this call. - */ -int getCRC() { - int crcOffset = DATA_OFFSET + getLength(); - return getInt32(crcOffset); -} - -/** - * Set the CRC value for the chunk's data. - * Ensure that the length field has a good - * value before making this call. - */ -void setCRC(int value) { - int crcOffset = DATA_OFFSET + getLength(); - setInt32(crcOffset, value); -} - -/** - * Get the chunk's total size including the length, type, and crc fields. - */ -int getSize() { - return MIN_LENGTH + getLength(); -} - -/** - * Compute the CRC value for the chunk's data. Answer - * whether this value matches the value stored in the - * chunk. - */ -boolean checkCRC() { - int crc = computeCRC(); - int storedCRC = getCRC(); - return crc == storedCRC; -} - -/** - * Answer the CRC value of chunk's data. - */ -int computeCRC() { - int crc = 0xFFFFFFFF; - int start = TYPE_OFFSET; - int stop = DATA_OFFSET + getLength(); - for (int i = start; i < stop; i++) { - int index = (crc ^ reference[i]) & 0xFF; - crc = CRC_TABLE[index] ^ ((crc >> 8) & 0x00FFFFFF); - } - return ~crc; -} - -boolean typeMatchesArray(byte[] array) { - for (int i = 0; i < TYPE_FIELD_LENGTH; i++) { - if (reference[TYPE_OFFSET + i] != array[i]){ - return false; - } - } - return true; -} - -boolean isCritical() { - char c = (char) getTypeBytes()[0]; - return 'A' <= c && c <= 'Z'; -} - -int getChunkType() { - if (typeMatchesArray(TYPE_IHDR)) return CHUNK_IHDR; - if (typeMatchesArray(TYPE_PLTE)) return CHUNK_PLTE; - if (typeMatchesArray(TYPE_IDAT)) return CHUNK_IDAT; - if (typeMatchesArray(TYPE_IEND)) return CHUNK_IEND; - if (typeMatchesArray(TYPE_tRNS)) return CHUNK_tRNS; - return CHUNK_UNKNOWN; -} - -/** - * Read the next PNG chunk from the input stream given. - * If unable to read a chunk, return null. - */ -static PngChunk readNextFromStream(LEDataInputStream stream) { - try { - int headerLength = LENGTH_FIELD_LENGTH + TYPE_FIELD_LENGTH; - byte[] headerBytes = new byte[headerLength]; - int result = stream.read(headerBytes, 0, headerLength); - stream.unread(headerBytes); - if (result != headerLength) return null; - - PngChunk tempChunk = new PngChunk(headerBytes); - - int chunkLength = tempChunk.getSize(); - byte[] chunk = new byte[chunkLength]; - result = stream.read(chunk, 0, chunkLength); - if (result != chunkLength) return null; - - switch (tempChunk.getChunkType()) { - case CHUNK_IHDR: - return new PngIhdrChunk(chunk); - case CHUNK_PLTE: - return new PngPlteChunk(chunk); - case CHUNK_IDAT: - return new PngIdatChunk(chunk); - case CHUNK_IEND: - return new PngIendChunk(chunk); - case CHUNK_tRNS: - return new PngTrnsChunk(chunk); - default: - return new PngChunk(chunk); - } - } catch (IOException e) { - return null; - } -} - -/** - * Answer whether the chunk is a valid PNG chunk. - */ -void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { - if (reference.length < MIN_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE); - - byte[] type = getTypeBytes(); - - // The third character MUST be upper case. - char c = (char) type[2]; - if (!('A' <= c && c <= 'Z')) SWT.error(SWT.ERROR_INVALID_IMAGE); - - // All characters must be letters. - for (int i = 0; i < TYPE_FIELD_LENGTH; i++) { - c = (char) type[i]; - if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - } - - // The stored CRC must match the data's computed CRC. - if (!checkCRC()) SWT.error(SWT.ERROR_INVALID_IMAGE); -} - -/** - * Provided so that subclasses can override and add - * data to the toString() call. - */ -void contributeToString(StringBuffer buffer) {} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("{"); - buffer.append("\n\tLength: "); - buffer.append(getLength()); - buffer.append("\n\tType: "); - byte[] type = getTypeBytes(); - for(int i = 0; i < type.length; i++) { - buffer.append((char) type[i]); - } - - contributeToString(buffer); - - buffer.append("\n\tCRC: "); - buffer.append(Integer.toHexString(getCRC())); - buffer.append("\n}"); - return buffer.toString(); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java deleted file mode 100755 index 0997c46b97..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -public class PngChunkReader { - LEDataInputStream inputStream; - PngFileReadState readState; - PngIhdrChunk headerChunk; - PngPlteChunk paletteChunk; - -PngChunkReader(LEDataInputStream inputStream) { - this.inputStream = inputStream; - readState = new PngFileReadState(); - headerChunk = null; -} - -PngIhdrChunk getIhdrChunk() { - if (headerChunk == null) { - try { - PngChunk chunk = PngChunk.readNextFromStream(inputStream); - if (chunk == null) SWT.error(SWT.ERROR_INVALID_IMAGE); - headerChunk = (PngIhdrChunk) chunk; - headerChunk.validate(readState, null); - } catch (ClassCastException e) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - } - return headerChunk; -} - -PngChunk readNextChunk() { - if (headerChunk == null) return getIhdrChunk(); - - PngChunk chunk = PngChunk.readNextFromStream(inputStream); - if (chunk == null) SWT.error(SWT.ERROR_INVALID_IMAGE); - switch (chunk.getChunkType()) { - case PngChunk.CHUNK_tRNS: - ((PngTrnsChunk) chunk).validate(readState, headerChunk, paletteChunk); - break; - case PngChunk.CHUNK_PLTE: - chunk.validate(readState, headerChunk); - paletteChunk = (PngPlteChunk) chunk; - break; - default: - chunk.validate(readState, headerChunk); - } - if (readState.readIDAT && !(chunk.getChunkType() == PngChunk.CHUNK_IDAT)) { - readState.readPixelData = true; - } - return chunk; -} - -boolean readPixelData() { - return readState.readPixelData; -} - -boolean hasMoreChunks() { - return !readState.readIEND; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java deleted file mode 100755 index a05021a0db..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import java.io.*; - -import org.eclipse.swt.*; - -public class PngDecodingDataStream extends InputStream { - InputStream stream; - byte currentByte; - int nextBitIndex; - - PngLzBlockReader lzBlockReader; - int adlerValue; - - static final int PRIME = 65521; - static final int MAX_BIT = 7; - -PngDecodingDataStream(InputStream stream) throws IOException { - super(); - this.stream = stream; - nextBitIndex = MAX_BIT + 1; - adlerValue = 1; - lzBlockReader = new PngLzBlockReader(this); - readCompressedDataHeader(); - lzBlockReader.readNextBlockHeader(); -} - -/** - * This method should be called when the image decoder thinks - * that all of the compressed image data has been read. This - * method will ensure that the next data value is an end of - * block marker. If there are more blocks after this one, - * the method will read them and ensure that they are empty. - */ -void assertImageDataAtEnd() throws IOException { - lzBlockReader.assertCompressedDataAtEnd(); -} - -public void close() throws IOException { - assertImageDataAtEnd(); - checkAdler(); -} - -int getNextIdatBits(int length) throws IOException { - int value = 0; - for (int i = 0; i < length; i++) { - value |= (getNextIdatBit() << i); - } - return value; -} - -int getNextIdatBit() throws IOException { - if (nextBitIndex > MAX_BIT) { - currentByte = getNextIdatByte(); - nextBitIndex = 0; - } - return (currentByte & (1 << nextBitIndex)) >> nextBitIndex++; -} - -byte getNextIdatByte() throws IOException { - byte nextByte = (byte)stream.read(); - nextBitIndex = MAX_BIT + 1; - return nextByte; -} - -void updateAdler(byte value) { - int low = adlerValue & 0xFFFF; - int high = (adlerValue >> 16) & 0xFFFF; - int valueInt = value & 0xFF; - low = (low + valueInt) % PRIME; - high = (low + high) % PRIME; - adlerValue = (high << 16) | low; -} - -public int read() throws IOException { - byte nextDecodedByte = lzBlockReader.getNextByte(); - updateAdler(nextDecodedByte); - return nextDecodedByte & 0xFF; -} - -public int read(byte[] buffer, int off, int len) throws IOException { - for (int i = 0; i < len; i++) { - int b = read(); - if (b == -1) return i; - buffer[off + i] = (byte)b; - } - return len; -} - -void error() { - SWT.error(SWT.ERROR_INVALID_IMAGE); -} - -private void readCompressedDataHeader() throws IOException { - byte headerByte1 = getNextIdatByte(); - byte headerByte2 = getNextIdatByte(); - - int number = ((headerByte1 & 0xFF) << 8) | (headerByte2 & 0xFF); - if (number % 31 != 0) error(); - - int compressionMethod = headerByte1 & 0x0F; - if (compressionMethod != 8) error(); - - int windowSizeHint = (headerByte1 & 0xF0) >> 4; - if (windowSizeHint > 7) error(); - int windowSize = (1 << (windowSizeHint + 8)); - lzBlockReader.setWindowSize(windowSize); - - int dictionary = (headerByte2 & (1 << 5)); - if (dictionary != 0) error(); - -// int compressionLevel = (headerByte2 & 0xC0) >> 6; -} - -void checkAdler() throws IOException { - int storedAdler = ((getNextIdatByte() & 0xFF) << 24) - | ((getNextIdatByte() & 0xFF) << 16) - | ((getNextIdatByte() & 0xFF) << 8) - | (getNextIdatByte() & 0xFF); - if (storedAdler != adlerValue) error(); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java deleted file mode 100644 index d382f38d4f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java +++ /dev/null @@ -1,618 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.ByteArrayOutputStream; - -public class PngDeflater { - - static final int BASE = 65521; - static final int WINDOW = 32768; - static final int MIN_LENGTH = 3; - static final int MAX_MATCHES = 32; - static final int HASH = 8209; - - byte[] in; - int inLength; - - ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024); - - int adler32 = 1; - - int buffer, bitCount; - - Link[] hashtable = new Link[HASH]; - Link[] window = new Link[WINDOW]; - int nextWindow; - -static class Link { - - int hash, value; - Link previous, next; - - Link() { - - this.hash = 0; - this.value = 0; - this.previous = null; - this.next = null; - - } - -} - -static class Match { - - int length, distance; - - Match(int length, int distance) { - - this.length = length; - this.distance = distance; - - } - -} - -static final short mirrorBytes[] = { - - 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, - 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, - 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, - 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, - 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, - 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, - 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, - 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, - 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, - 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, - 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, - 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, - 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, - 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, - 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, - 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, - 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, - 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, - 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, - 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, - 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, - 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, - 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, - 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, - 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, - 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, - 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, - 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, - 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, - 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, - 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, - 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, - -}; - -static class Code { - - int code, extraBits, min, max; - - Code(int code, int extraBits, int min, int max) { - - this.code = code; - this.extraBits = extraBits; - this.min = min; - this.max = max; - - } - -} - -static final Code lengthCodes[] = { - - new Code(257, 0, 3, 3), - new Code(258, 0, 4, 4), - new Code(259, 0, 5, 5), - new Code(260, 0, 6, 6), - new Code(261, 0, 7, 7), - new Code(262, 0, 8, 8), - new Code(263, 0, 9, 9), - new Code(264, 0, 10, 10), - new Code(265, 1, 11, 12), - new Code(266, 1, 13, 14), - new Code(267, 1, 15, 16), - new Code(268, 1, 17, 18), - new Code(269, 2, 19, 22), - new Code(270, 2, 23, 26), - new Code(271, 2, 27, 30), - new Code(272, 2, 31, 34), - new Code(273, 3, 35, 42), - new Code(274, 3, 43, 50), - new Code(275, 3, 51, 58), - new Code(276, 3, 59, 66), - new Code(277, 4, 67, 82), - new Code(278, 4, 83, 98), - new Code(279, 4, 99, 114), - new Code(280, 4, 115, 130), - new Code(281, 5, 131, 162), - new Code(282, 5, 163, 194), - new Code(283, 5, 195, 226), - new Code(284, 5, 227, 257), - new Code(285, 0, 258, 258) - -}; - -static final Code distanceCodes[] = { - - new Code(0, 0, 1, 1), - new Code(1, 0, 2, 2), - new Code(2, 0, 3, 3), - new Code(3, 0, 4, 4), - new Code(4, 1, 5, 6), - new Code(5, 1, 7, 8), - new Code(6, 2, 9, 12), - new Code(7, 2, 13, 16), - new Code(8, 3, 17, 24), - new Code(9, 3, 25, 32), - new Code(10, 4, 33, 48), - new Code(11, 4, 49, 64), - new Code(12, 5, 65, 96), - new Code(13, 5, 97, 128), - new Code(14, 6, 129, 192), - new Code(15, 6, 193, 256), - new Code(16, 7, 257, 384), - new Code(17, 7, 385, 512), - new Code(18, 8, 513, 768), - new Code(19, 8, 769, 1024), - new Code(20, 9, 1025, 1536), - new Code(21, 9, 1537, 2048), - new Code(22, 10, 2049, 3072), - new Code(23, 10, 3073, 4096), - new Code(24, 11, 4097, 6144), - new Code(25, 11, 6145, 8192), - new Code(26, 12, 8193, 12288), - new Code(27, 12, 12289, 16384), - new Code(28, 13, 16385, 24576), - new Code(29, 13, 24577, 32768) - -}; - -void writeShortLSB(ByteArrayOutputStream baos, int theShort) { - - byte byte1 = (byte) (theShort & 0xff); - byte byte2 = (byte) ((theShort >> 8) & 0xff); - byte[] temp = {byte1, byte2}; - baos.write(temp, 0, 2); - -} - -void writeInt(ByteArrayOutputStream baos, int theInt) { - - byte byte1 = (byte) ((theInt >> 24) & 0xff); - byte byte2 = (byte) ((theInt >> 16) & 0xff); - byte byte3 = (byte) ((theInt >> 8) & 0xff); - byte byte4 = (byte) (theInt & 0xff); - byte[] temp = {byte1, byte2, byte3, byte4}; - baos.write(temp, 0, 4); - -} - -void updateAdler(byte value) { - - int low = adler32 & 0xffff; - int high = (adler32 >> 16) & 0xffff; - int valueInt = value & 0xff; - low = (low + valueInt) % BASE; - high = (low + high) % BASE; - adler32 = (high << 16) | low; - -} - -int hash(byte[] bytes) { - - int hash = ((bytes[0] & 0xff) << 24 | (bytes[1] & 0xff) << 16 | (bytes[2] & 0xff) << 8) % HASH; - if (hash < 0) { - hash = hash + HASH; - } - return hash; - -} - -void writeBits(int value, int count) { - - buffer |= value << bitCount; - bitCount += count; - if (bitCount >= 16) { - bytes.write((byte) buffer); - bytes.write((byte) (buffer >>> 8)); - buffer >>>= 16; - bitCount -= 16; - } - -} - -void alignToByte() { - - if (bitCount > 0) { - bytes.write((byte) buffer); - if (bitCount > 8) bytes.write((byte) (buffer >>> 8)); - } - buffer = 0; - bitCount = 0; - -} - -void outputLiteral(byte literal) { - - int i = literal & 0xff; - - if (i <= 143) { - // 0 through 143 are 8 bits long starting at 00110000 - writeBits(mirrorBytes[0x30 + i], 8); - } - else { - // 144 through 255 are 9 bits long starting at 110010000 - writeBits(1 + 2 * mirrorBytes[0x90 - 144 + i], 9); - } - -} - -Code findCode(int value, Code[] codes) { - - int i, j, k; - - i = -1; - j = codes.length; - while (true) { - k = (j + i) / 2; - if (value < codes[k].min) { - j = k; - } - else if (value > codes[k].max) { - i = k; - } - else { - return codes[k]; - } - } - -} - -void outputMatch(int length, int distance) { - - Code d, l; - int thisLength; - - while (length > 0) { - - // we can transmit matches of lengths 3 through 258 inclusive - // so if length exceeds 258, we must transmit in several steps, - // with 258 or less in each step - - if (length > 260) { - thisLength = 258; - } - else if (length <= 258) { - thisLength = length; - } - else { - thisLength = length - 3; - } - - length = length - thisLength; - - // find length code - l = findCode(thisLength, lengthCodes); - - // transmit the length code - // 256 through 279 are 7 bits long starting at 0000000 - // 280 through 287 are 8 bits long starting at 11000000 - if (l.code <= 279) { - writeBits(mirrorBytes[(l.code - 256) * 2], 7); - } - else { - writeBits(mirrorBytes[0xc0 - 280 + l.code], 8); - } - - // transmit the extra bits - if (l.extraBits != 0) { - writeBits(thisLength - l.min, l.extraBits); - } - - // find distance code - d = findCode(distance, distanceCodes); - - // transmit the distance code - // 5 bits long starting at 00000 - writeBits(mirrorBytes[d.code * 8], 5); - - // transmit the extra bits - if (d.extraBits != 0) { - writeBits(distance - d.min, d.extraBits); - } - - } - -} - -Match findLongestMatch(int position, Link firstPosition) { - - Link link = firstPosition; - int numberOfMatches = 0; - Match bestMatch = new Match(-1, -1); - - while (true) { - - int matchPosition = link.value; - - if (position - matchPosition < WINDOW && matchPosition != 0) { - - int i; - - for (i = 1; position + i < inLength; i++) { - if (in[position + i] != in[matchPosition + i]) { - break; - } - } - - if (i >= MIN_LENGTH) { - - if (i > bestMatch.length) { - bestMatch.length = i; - bestMatch.distance = position - matchPosition; - } - - numberOfMatches = numberOfMatches + 1; - - if (numberOfMatches == MAX_MATCHES) { - break; - } - - } - - } - - link = link.next; - if (link == null) { - break; - } - - } - - if (bestMatch.length < MIN_LENGTH || bestMatch.distance < 1 || bestMatch.distance > WINDOW) { - return null; - } - - return bestMatch; - -} - -void updateHashtable(int to, int from) { - - byte[] data = new byte[3]; - int hash; - Link temp; - - for (int i = to; i < from; i++) { - - if (i + MIN_LENGTH > inLength) { - break; - } - - data[0] = in[i]; - data[1] = in[i + 1]; - data[2] = in[i + 2]; - - hash = hash(data); - - if (window[nextWindow].previous != null) { - window[nextWindow].previous.next = null; - } - else if (window[nextWindow].hash != 0) { - hashtable[window[nextWindow].hash].next = null; - } - - window[nextWindow].hash = hash; - window[nextWindow].value = i; - window[nextWindow].previous = null; - temp = window[nextWindow].next = hashtable[hash].next; - hashtable[hash].next = window[nextWindow]; - if (temp != null) { - temp.previous = window[nextWindow]; - } - - nextWindow = nextWindow + 1; - if (nextWindow == WINDOW) { - nextWindow = 0; - } - - } - -} - -void compress() { - - int position, newPosition; - byte[] data = new byte[3]; - int hash; - for (int i = 0; i < HASH; i++) { - hashtable[i] = new Link(); - } - for (int i = 0; i < WINDOW; i++) { - window[i] = new Link(); - } - nextWindow = 0; - Link firstPosition; - Match match; - int deferredPosition = -1; - Match deferredMatch = null; - - writeBits(0x01, 1); // BFINAL = 0x01 (final block) - writeBits(0x01, 2); // BTYPE = 0x01 (compression with fixed Huffman codes) - - // just output first byte so we never match at zero - outputLiteral(in[0]); - position = 1; - - while (position < inLength) { - - if (inLength - position < MIN_LENGTH) { - outputLiteral(in[position]); - position = position + 1; - continue; - } - - data[0] = in[position]; - data[1] = in[position + 1]; - data[2] = in[position + 2]; - - hash = hash(data); - firstPosition = hashtable[hash]; - - match = findLongestMatch(position, firstPosition); - - updateHashtable(position, position + 1); - - if (match != null) { - - if (deferredMatch != null) { - if (match.length > deferredMatch.length + 1) { - // output literal at deferredPosition - outputLiteral(in[deferredPosition]); - // defer this match - deferredPosition = position; - deferredMatch = match; - position = position + 1; - } - else { - // output deferredMatch - outputMatch(deferredMatch.length, deferredMatch.distance); - newPosition = deferredPosition + deferredMatch.length; - deferredPosition = -1; - deferredMatch = null; - updateHashtable(position + 1, newPosition); - position = newPosition; - } - } - else { - // defer this match - deferredPosition = position; - deferredMatch = match; - position = position + 1; - } - - } - - else { - - // no match found - if (deferredMatch != null) { - outputMatch(deferredMatch.length, deferredMatch.distance); - newPosition = deferredPosition + deferredMatch.length; - deferredPosition = -1; - deferredMatch = null; - updateHashtable(position + 1, newPosition); - position = newPosition; - } - else { - outputLiteral(in[position]); - position = position + 1; - } - - } - - } - - writeBits(0, 7); // end of block code - alignToByte(); - -} - -void compressHuffmanOnly() { - - int position; - - writeBits(0x01, 1); // BFINAL = 0x01 (final block) - writeBits(0x01, 2); // BTYPE = 0x01 (compression with fixed Huffman codes) - - for (position = 0; position < inLength;) { - - outputLiteral(in[position]); - position = position + 1; - - } - - writeBits(0, 7); // end of block code - alignToByte(); - -} - -void store() { - - // stored blocks are limited to 0xffff bytes - - int start = 0; - int length = inLength; - int blockLength; - int BFINAL = 0x00; // BFINAL = 0x00 or 0x01 (if final block), BTYPE = 0x00 (no compression) - - while (length > 0) { - - if (length < 65535) { - blockLength = length; - BFINAL = 0x01; - } - else { - blockLength = 65535; - BFINAL = 0x00; - } - - // write data header - bytes.write((byte) BFINAL); - writeShortLSB(bytes, blockLength); // LEN - writeShortLSB(bytes, blockLength ^ 0xffff); // NLEN (one's complement of LEN) - - // write actual data - bytes.write(in, start, blockLength); - - length = length - blockLength; - start = start + blockLength; - - } - -} - -public byte[] deflate(byte[] input) { - - in = input; - inLength = input.length; - - // write zlib header - bytes.write((byte) 0x78); // window size = 0x70 (32768), compression method = 0x08 - bytes.write((byte) 0x9C); // compression level = 0x80 (default), check bits = 0x1C - - // compute checksum - for (int i = 0; i < inLength; i++) { - updateAdler(in[i]); - } - - //store(); - - //compressHuffmanOnly(); - - compress(); - - // write checksum - writeInt(bytes, adler32); - - return bytes.toByteArray(); - -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java deleted file mode 100644 index 26fe5746b7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java +++ /dev/null @@ -1,364 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.ImageLoader; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.internal.Compatibility; - -final class PngEncoder extends Object { - - static final byte SIGNATURE[] = {(byte) '\211', (byte) 'P', (byte) 'N', (byte) 'G', (byte) '\r', (byte) '\n', (byte) '\032', (byte) '\n'}; - static final byte TAG_IHDR[] = {(byte) 'I', (byte) 'H', (byte) 'D', (byte) 'R'}; - static final byte TAG_PLTE[] = {(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'}; - static final byte TAG_TRNS[] = {(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'}; - static final byte TAG_IDAT[] = {(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'}; - static final byte TAG_IEND[] = {(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'}; - - ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024); - PngChunk chunk; - - ImageLoader loader; - ImageData data; - int transparencyType; - - int width, height, bitDepth, colorType; - - int compressionMethod = 0; - int filterMethod = 0; - int interlaceMethod = 0; - -public PngEncoder(ImageLoader loader) { - - this.loader = loader; - this.data = loader.data[0]; - this.transparencyType = data.getTransparencyType(); - - this.width = data.width; - this.height = data.height; - - this.bitDepth = 8; - - this.colorType = 2; - - if (data.palette.isDirect) { - if (transparencyType == SWT.TRANSPARENCY_ALPHA) { - this.colorType = 6; - } - } - else { - this.colorType = 3; - } - - if (!(colorType == 2 || colorType == 3 || colorType == 6)) SWT.error(SWT.ERROR_INVALID_IMAGE); - -} - -void writeShort(ByteArrayOutputStream baos, int theShort) { - - byte byte1 = (byte) ((theShort >> 8) & 0xff); - byte byte2 = (byte) (theShort & 0xff); - byte[] temp = {byte1, byte2}; - baos.write(temp, 0, 2); - -} - -void writeInt(ByteArrayOutputStream baos, int theInt) { - - byte byte1 = (byte) ((theInt >> 24) & 0xff); - byte byte2 = (byte) ((theInt >> 16) & 0xff); - byte byte3 = (byte) ((theInt >> 8) & 0xff); - byte byte4 = (byte) (theInt & 0xff); - byte[] temp = {byte1, byte2, byte3, byte4}; - baos.write(temp, 0, 4); - -} - -void writeChunk(byte[] tag, byte[] buffer) { - - int bufferLength = (buffer != null) ? buffer.length : 0; - - chunk = new PngChunk(bufferLength); - - writeInt(bytes, bufferLength); - bytes.write(tag, 0, 4); - chunk.setType(tag); - if (bufferLength != 0) { - bytes.write(buffer, 0, bufferLength); - chunk.setData(buffer); - } - else { - chunk.setCRC(chunk.computeCRC()); - } - writeInt(bytes, chunk.getCRC()); - -} - -void writeSignature() { - - bytes.write(SIGNATURE, 0, 8); - -} - -void writeHeader() { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(13); - - writeInt(baos, width); - writeInt(baos, height); - baos.write(bitDepth); - baos.write(colorType); - baos.write(compressionMethod); - baos.write(filterMethod); - baos.write(interlaceMethod); - - writeChunk(TAG_IHDR, baos.toByteArray()); - -} - -void writePalette() { - - RGB[] RGBs = data.palette.getRGBs(); - - if (RGBs.length > 256) SWT.error(SWT.ERROR_INVALID_IMAGE); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(RGBs.length); - - for (int i = 0; i < RGBs.length; i++) { - - baos.write((byte) RGBs[i].red); - baos.write((byte) RGBs[i].green); - baos.write((byte) RGBs[i].blue); - - } - - writeChunk(TAG_PLTE, baos.toByteArray()); - -} - -void writeTransparency() { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - switch (transparencyType) { - - case SWT.TRANSPARENCY_ALPHA: - - int pixelValue, alphaValue; - - byte[] alphas = new byte[data.palette.getRGBs().length]; - - for (int y = 0; y < height; y++) { - - for (int x = 0; x < width; x++) { - - pixelValue = data.getPixel(x, y); - alphaValue = data.getAlpha(x, y); - - alphas[pixelValue] = (byte) alphaValue; - - } - - } - - baos.write(alphas, 0, alphas.length); - - break; - - case SWT.TRANSPARENCY_PIXEL: - - int pixel = data.transparentPixel; - - if (colorType == 2) { - - int redMask = data.palette.redMask; - int redShift = data.palette.redShift; - int greenMask = data.palette.greenMask; - int greenShift = data.palette.greenShift; - int blueShift = data.palette.blueShift; - int blueMask = data.palette.blueMask; - - int r = pixel & redMask; - r = (redShift < 0) ? r >>> -redShift : r << redShift; - int g = pixel & greenMask; - g = (greenShift < 0) ? g >>> -greenShift : g << greenShift; - int b = pixel & blueMask; - b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; - - writeShort(baos, r); - writeShort(baos, g); - writeShort(baos, b); - - } - - if (colorType == 3) { - - byte[] padding = new byte[pixel + 1]; - - for (int i = 0; i < pixel; i++) { - - padding[i] = (byte) 255; - - } - - padding[pixel] = (byte) 0; - - baos.write(padding, 0, padding.length); - - } - - break; - - } - - writeChunk(TAG_TRNS, baos.toByteArray()); - -} - -void writeImageData() throws IOException { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - OutputStream os = Compatibility.newDeflaterOutputStream(baos); - if (os == null) os = baos; - - if (colorType == 3) { - - byte[] lineData = new byte[width]; - - for (int y = 0; y < height; y++) { - - int filter = 0; - os.write(filter); - - data.getPixels(0, y, width, lineData, 0); - - for (int x = 0; x < lineData.length; x++) { - - os.write(lineData[x]); - - } - - } - - } - - else { - - int[] lineData = new int[width]; - byte[] alphaData = null; - if (colorType == 6) { - alphaData = new byte[width]; - } - - int redMask = data.palette.redMask; - int redShift = data.palette.redShift; - int greenMask = data.palette.greenMask; - int greenShift = data.palette.greenShift; - int blueShift = data.palette.blueShift; - int blueMask = data.palette.blueMask; - - for (int y = 0; y < height; y++) { - - int filter = 0; - os.write(filter); - - data.getPixels(0, y, width, lineData, 0); - - if (colorType == 6) { - data.getAlphas(0, y, width, alphaData, 0); - } - - for (int x = 0; x < lineData.length; x++) { - - int pixel = lineData[x]; - - int r = pixel & redMask; - r = (redShift < 0) ? r >>> -redShift : r << redShift; - int g = pixel & greenMask; - g = (greenShift < 0) ? g >>> -greenShift : g << greenShift; - int b = pixel & blueMask; - b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; - - os.write(r); - os.write(g); - os.write(b); - - if (colorType == 6) { - os.write(alphaData[x]); - } - - } - - } - - } - - os.flush(); - os.close(); - - byte[] compressed = baos.toByteArray(); - if (os == baos) { - PngDeflater deflater = new PngDeflater(); - compressed = deflater.deflate(compressed); - } - - writeChunk(TAG_IDAT, compressed); - -} - -void writeEnd() { - - writeChunk(TAG_IEND, null); - -} - -public void encode(LEDataOutputStream outputStream) { - - try { - - writeSignature(); - writeHeader(); - - if (colorType == 3) { - writePalette(); - } - - boolean transparencyAlpha = (transparencyType == SWT.TRANSPARENCY_ALPHA); - boolean transparencyPixel = (transparencyType == SWT.TRANSPARENCY_PIXEL); - boolean type2Transparency = (colorType == 2 && transparencyPixel); - boolean type3Transparency = (colorType == 3 && (transparencyAlpha || transparencyPixel)); - - if (type2Transparency || type3Transparency) { - writeTransparency(); - } - - writeImageData(); - writeEnd(); - - outputStream.write(bytes.toByteArray()); - - } - - catch (IOException e) { - - SWT.error(SWT.ERROR_IO, e); - - } - -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java deleted file mode 100755 index f8f0064de7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -class PngFileReadState extends Object { - boolean readIHDR; - boolean readPLTE; - boolean readIDAT; - boolean readIEND; - - // Non - critical chunks - boolean readTRNS; - - // Set to true after IDATs have been read. - boolean readPixelData; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java deleted file mode 100755 index 48e026958b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.*; - -public class PngHuffmanTable { - CodeLengthInfo[] codeLengthInfo; - int[] codeValues; - - static final int MAX_CODE_LENGTH = 15; - static final int BAD_CODE = 0xFFFFFFF; - static final int incs[] = {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1}; - -PngHuffmanTable (int[] lengths) { - super(); - initialize(lengths); - generateTable(lengths); -} - -private void initialize(int[] lengths) { - codeValues = new int[lengths.length]; - for (int i = 0; i < codeValues.length; i++) { - codeValues[i] = i; - } - - // minCodesByLength[n] : The smallest Huffman code of length n + 1. - // maxCodesByLength[n] : The largest Huffman code of length n + 1. - // indexesByLength[n] : Index into the values array. First value with a code of length n + 1. - codeLengthInfo = new CodeLengthInfo[MAX_CODE_LENGTH]; - for (int i = 0; i < MAX_CODE_LENGTH; i++) { - codeLengthInfo[i] = new CodeLengthInfo(); - codeLengthInfo[i].length = i; - codeLengthInfo[i].baseIndex = 0; - codeLengthInfo[i].min = BAD_CODE; - codeLengthInfo[i].max = -1; - } -} - -private void generateTable(int[] lengths) { - // Sort the values using shellsort. Primary key is code size. Secondary key is value. - int codeValuesTemp; - for (int k = 0; k < 16; k++) { - for (int h = incs[k], i = h; i < lengths.length; i++) { - int v = lengths[i]; - codeValuesTemp = codeValues[i]; - int j = i; - while (j >= h && (lengths[j - h] > v || (lengths[j - h] == v && codeValues[j - h] > codeValuesTemp))) { - lengths[j] = lengths[j - h]; - codeValues[j] = codeValues[j - h]; - j -= h; - } - lengths[j] = v; - codeValues[j] = codeValuesTemp; - } - } - - // These values in these arrays correspond to the elements of the - // "values" array. The Huffman code for codeValues[N] is codes[N] - // and the length of the code is lengths[N]. - int[] codes = new int[lengths.length]; - int lastLength = 0; - int code = 0; - for (int i = 0; i < lengths.length; i++) { - while (lastLength != lengths[i]) { - lastLength++; - code <<= 1; - } - if (lastLength != 0) { - codes[i] = code; - code++; - } - } - - int last = 0; - for (int i = 0; i < lengths.length; i++) { - if (last != lengths[i]) { - last = lengths[i]; - codeLengthInfo[last - 1].baseIndex = i; - codeLengthInfo[last - 1].min = codes[i]; - } - if (last != 0) codeLengthInfo[last - 1].max = codes[i]; - } -} - -int getNextValue(PngDecodingDataStream stream) throws IOException { - int code = stream.getNextIdatBit(); - int codelength = 0; - - // Here we are taking advantage of the fact that 1 bits are used as - // a prefix to the longer codeValues. - while (codelength < MAX_CODE_LENGTH && code > codeLengthInfo[codelength].max) { - code = ((code << 1) | stream.getNextIdatBit()); - codelength++; - } - if (codelength >= MAX_CODE_LENGTH) stream.error(); - - // Now we have a Huffman code of length (codelength + 1) that - // is somewhere in the range - // minCodesByLength[codelength]..maxCodesByLength[codelength]. - // This code is the (offset + 1)'th code of (codelength + 1); - int offset = code - codeLengthInfo[codelength].min; - - // indexesByLength[codelength] is the first code of length (codelength + 1) - // so now we can look up the value for the Huffman code in the table. - int index = codeLengthInfo[codelength].baseIndex + offset; - return codeValues[index]; -} - -static class CodeLengthInfo { - int length; - int max; - int min; - int baseIndex; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java deleted file mode 100755 index 6ecaeb4764..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.*; - -public class PngHuffmanTables { - PngHuffmanTable literalTable; - PngHuffmanTable distanceTable; - - static PngHuffmanTable FixedLiteralTable; - static PngHuffmanTable FixedDistanceTable; - - static final int LiteralTableSize = 288; - static final int[] FixedLiteralLengths = { - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, - }; - - static final int DistanceTableSize = 32; - static final int[] FixedDistanceLengths = { - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - }; - - static final int LengthCodeTableSize = 19; - static final int[] LengthCodeOrder = { - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, - 11, 4, 12, 3, 13, 2, 14, 1, 15 - }; - -static PngHuffmanTables getDynamicTables(PngDecodingDataStream stream) throws IOException { - return new PngHuffmanTables(stream); -} -static PngHuffmanTables getFixedTables() { - return new PngHuffmanTables(); -} - -private PngHuffmanTable getFixedLiteralTable() { - if (FixedLiteralTable == null) { - FixedLiteralTable = new PngHuffmanTable(FixedLiteralLengths); - } - return FixedLiteralTable; -} - -private PngHuffmanTable getFixedDistanceTable() { - if (FixedDistanceTable == null) { - FixedDistanceTable = new PngHuffmanTable(FixedDistanceLengths); - } - return FixedDistanceTable; -} - -private PngHuffmanTables () { - literalTable = getFixedLiteralTable(); - distanceTable = getFixedDistanceTable(); -} - -private PngHuffmanTables (PngDecodingDataStream stream) throws IOException { - int literals = PngLzBlockReader.FIRST_LENGTH_CODE - + stream.getNextIdatBits(5); - int distances = PngLzBlockReader.FIRST_DISTANCE_CODE - + stream.getNextIdatBits(5); - int codeLengthCodes = PngLzBlockReader.FIRST_CODE_LENGTH_CODE - + stream.getNextIdatBits(4); - - if (codeLengthCodes > PngLzBlockReader.LAST_CODE_LENGTH_CODE) { - stream.error(); - } - - /* Tricky, tricky, tricky. The length codes are stored in - * a very odd order. (For the order, see the definition of - * the static field lengthCodeOrder.) Also, the data may - * not contain values for all the codes. It may just contain - * values for the first X number of codes. The table should - * be of size <LengthCodeTableSize> regardless of the number - * of values actually given in the table. - */ - int[] lengthCodes = new int[LengthCodeTableSize]; - for (int i = 0; i < codeLengthCodes; i++) { - lengthCodes[LengthCodeOrder[i]] = stream.getNextIdatBits(3); - } - PngHuffmanTable codeLengthsTable = new PngHuffmanTable(lengthCodes); - - int[] literalLengths = readLengths( - stream, literals, codeLengthsTable, LiteralTableSize); - int[] distanceLengths = readLengths( - stream, distances, codeLengthsTable, DistanceTableSize); - - literalTable = new PngHuffmanTable(literalLengths); - distanceTable = new PngHuffmanTable(distanceLengths); -} - -private int [] readLengths (PngDecodingDataStream stream, - int numLengths, - PngHuffmanTable lengthsTable, - int tableSize) throws IOException -{ - int[] lengths = new int[tableSize]; - - for (int index = 0; index < numLengths;) { - int value = lengthsTable.getNextValue(stream); - if (value < 16) { - // Literal value - lengths[index] = value; - index++; - } else if (value == 16) { - // Repeat the previous code 3-6 times. - int count = stream.getNextIdatBits(2) + 3; - for (int i = 0; i < count; i++) { - lengths[index] = lengths [index - 1]; - index++; - } - } else if (value == 17) { - // Repeat 0 3-10 times. - int count = stream.getNextIdatBits(3) + 3; - for (int i = 0; i < count; i++) { - lengths[index] = 0; - index++; - } - } else if (value == 18) { - // Repeat 0 11-138 times. - int count = stream.getNextIdatBits(7) + 11; - for (int i = 0; i < count; i++) { - lengths[index] = 0; - index++; - } - } else { - stream.error(); - } - } - return lengths; -} - -int getNextLiteralValue(PngDecodingDataStream stream) throws IOException { - return literalTable.getNextValue(stream); -} - -int getNextDistanceValue(PngDecodingDataStream stream) throws IOException { - return distanceTable.getNextValue(stream); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java deleted file mode 100755 index 6dfac62210..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -class PngIdatChunk extends PngChunk { - - static final int HEADER_BYTES_LENGTH = 2; - static final int ADLER_FIELD_LENGTH = 4; - static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0; - static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1; - static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length - -PngIdatChunk(byte headerByte1, byte headerByte2, byte[] data, int adler) { - super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH); - setType(TYPE_IDAT); - reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1; - reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2; - System.arraycopy(data, 0, reference, DATA_OFFSET, data.length); - setInt32(ADLER_DATA_OFFSET, adler); - setCRC(computeCRC()); -} - -PngIdatChunk(byte[] reference) { - super(reference); -} - -int getChunkType() { - return CHUNK_IDAT; -} - -/** - * Answer whether the chunk is a valid IDAT chunk. - */ -void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { - if (!readState.readIHDR - || (headerChunk.getMustHavePalette() && !readState.readPLTE) - || readState.readIEND) - { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } else { - readState.readIDAT = true; - } - - super.validate(readState, headerChunk); -} - -byte getDataByteAtOffset(int offset) { - return reference[DATA_OFFSET + offset]; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java deleted file mode 100755 index ed604e0ae9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; - -class PngIendChunk extends PngChunk { - -PngIendChunk() { - super(0); - setType(TYPE_IEND); - setCRC(computeCRC()); -} - -PngIendChunk(byte[] reference){ - super(reference); -} - -int getChunkType() { - return CHUNK_IEND; -} - -/** - * Answer whether the chunk is a valid IEND chunk. - */ -void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { - // An IEND chunk is invalid if no IHDR has been read. - // Or if a palette is required and has not been read. - // Or if no IDAT chunk has been read. - if (!readState.readIHDR - || (headerChunk.getMustHavePalette() && !readState.readPLTE) - || !readState.readIDAT - || readState.readIEND) - { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } else { - readState.readIEND = true; - } - - super.validate(readState, headerChunk); - - // IEND chunks are not allowed to have any data. - if (getLength() > 0) SWT.error(SWT.ERROR_INVALID_IMAGE); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java deleted file mode 100755 index 37d550883e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java +++ /dev/null @@ -1,408 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -class PngIhdrChunk extends PngChunk { - static final int IHDR_DATA_LENGTH = 13; - - static final int WIDTH_DATA_OFFSET = DATA_OFFSET + 0; - static final int HEIGHT_DATA_OFFSET = DATA_OFFSET + 4; - static final int BIT_DEPTH_OFFSET = DATA_OFFSET + 8; - static final int COLOR_TYPE_OFFSET = DATA_OFFSET + 9; - static final int COMPRESSION_METHOD_OFFSET = DATA_OFFSET + 10; - static final int FILTER_METHOD_OFFSET = DATA_OFFSET + 11; - static final int INTERLACE_METHOD_OFFSET = DATA_OFFSET + 12; - - static final byte COLOR_TYPE_GRAYSCALE = 0; - static final byte COLOR_TYPE_RGB = 2; - static final byte COLOR_TYPE_PALETTE = 3; - static final byte COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4; - static final byte COLOR_TYPE_RGB_WITH_ALPHA = 6; - - static final int INTERLACE_METHOD_NONE = 0; - static final int INTERLACE_METHOD_ADAM7 = 1; - - static final int FILTER_NONE = 0; - static final int FILTER_SUB = 1; - static final int FILTER_UP = 2; - static final int FILTER_AVERAGE = 3; - static final int FILTER_PAETH = 4; - - static final byte[] ValidBitDepths = {1, 2, 4, 8, 16}; - static final byte[] ValidColorTypes = {0, 2, 3, 4, 6}; - - int width, height; - byte bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod; - -PngIhdrChunk(int width, int height, byte bitDepth, byte colorType, byte compressionMethod, byte filterMethod, byte interlaceMethod) { - super(IHDR_DATA_LENGTH); - setType(TYPE_IHDR); - setWidth(width); - setHeight(height); - setBitDepth(bitDepth); - setColorType(colorType); - setCompressionMethod(compressionMethod); - setFilterMethod(filterMethod); - setInterlaceMethod(interlaceMethod); - setCRC(computeCRC()); -} - -/** - * Construct a PNGChunk using the reference bytes - * given. - */ -PngIhdrChunk(byte[] reference) { - super(reference); - if (reference.length <= IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE); - width = getInt32(WIDTH_DATA_OFFSET); - height = getInt32(HEIGHT_DATA_OFFSET); - bitDepth = reference[BIT_DEPTH_OFFSET]; - colorType = reference[COLOR_TYPE_OFFSET]; - compressionMethod = reference[COMPRESSION_METHOD_OFFSET]; - filterMethod = reference[FILTER_METHOD_OFFSET]; - interlaceMethod = reference[INTERLACE_METHOD_OFFSET]; -} - -int getChunkType() { - return CHUNK_IHDR; -} - -/** - * Get the image's width in pixels. - */ -int getWidth() { - return width; -} - -/** - * Set the image's width in pixels. - */ -void setWidth(int value) { - setInt32(WIDTH_DATA_OFFSET, value); - width = value; -} - -/** - * Get the image's height in pixels. - */ -int getHeight() { - return height; -} - -/** - * Set the image's height in pixels. - */ -void setHeight(int value) { - setInt32(HEIGHT_DATA_OFFSET, value); - height = value; -} - -/** - * Get the image's bit depth. - * This is limited to the values 1, 2, 4, 8, or 16. - */ -byte getBitDepth() { - return bitDepth; -} - -/** - * Set the image's bit depth. - * This is limited to the values 1, 2, 4, 8, or 16. - */ -void setBitDepth(byte value) { - reference[BIT_DEPTH_OFFSET] = value; - bitDepth = value; -} - -/** - * Get the image's color type. - * This is limited to the values: - * 0 - Grayscale image. - * 2 - RGB triple. - * 3 - Palette. - * 4 - Grayscale with Alpha channel. - * 6 - RGB with Alpha channel. - */ -byte getColorType() { - return colorType; -} - -/** - * Set the image's color type. - * This is limited to the values: - * 0 - Grayscale image. - * 2 - RGB triple. - * 3 - Palette. - * 4 - Grayscale with Alpha channel. - * 6 - RGB with Alpha channel. - */ -void setColorType(byte value) { - reference[COLOR_TYPE_OFFSET] = value; - colorType = value; -} - -/** - * Get the image's compression method. - * This value must be 0. - */ -byte getCompressionMethod() { - return compressionMethod; -} - -/** - * Set the image's compression method. - * This value must be 0. - */ -void setCompressionMethod(byte value) { - reference[COMPRESSION_METHOD_OFFSET] = value; - compressionMethod = value; -} - -/** - * Get the image's filter method. - * This value must be 0. - */ -byte getFilterMethod() { - return filterMethod; -} - -/** - * Set the image's filter method. - * This value must be 0. - */ -void setFilterMethod(byte value) { - reference[FILTER_METHOD_OFFSET] = value; - filterMethod = value; -} - -/** - * Get the image's interlace method. - * This value is limited to: - * 0 - No interlacing used. - * 1 - Adam7 interlacing used. - */ -byte getInterlaceMethod() { - return interlaceMethod; -} - -/** - * Set the image's interlace method. - * This value is limited to: - * 0 - No interlacing used. - * 1 - Adam7 interlacing used. - */ -void setInterlaceMethod(byte value) { - reference[INTERLACE_METHOD_OFFSET] = value; - interlaceMethod = value; -} - -/** - * Answer whether the chunk is a valid IHDR chunk. - */ -void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { - // An IHDR chunk is invalid if any other chunk has - // been read. - if (readState.readIHDR - || readState.readPLTE - || readState.readIDAT - || readState.readIEND) - { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } else { - readState.readIHDR = true; - } - - super.validate(readState, headerChunk); - - if (length != IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE); - if (compressionMethod != 0) SWT.error(SWT.ERROR_INVALID_IMAGE); - if (interlaceMethod != INTERLACE_METHOD_NONE && - interlaceMethod != INTERLACE_METHOD_ADAM7) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - - boolean colorTypeIsValid = false; - for (int i = 0; i < ValidColorTypes.length; i++) { - if (ValidColorTypes[i] == colorType) { - colorTypeIsValid = true; - break; - } - } - if (!colorTypeIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE); - - boolean bitDepthIsValid = false; - for (int i = 0; i < ValidBitDepths.length; i++) { - if (ValidBitDepths[i] == bitDepth) { - bitDepthIsValid = true; - break; - } - } - if (!bitDepthIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE); - - if ((colorType == COLOR_TYPE_RGB - || colorType == COLOR_TYPE_RGB_WITH_ALPHA - || colorType == COLOR_TYPE_GRAYSCALE_WITH_ALPHA) - && bitDepth < 8) - { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - - if (colorType == COLOR_TYPE_PALETTE && bitDepth > 8) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } -} - -String getColorTypeString() { - switch (colorType) { - case COLOR_TYPE_GRAYSCALE: return "Grayscale"; - case COLOR_TYPE_RGB: return "RGB"; - case COLOR_TYPE_PALETTE: return "Palette"; - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: return "Grayscale with Alpha"; - case COLOR_TYPE_RGB_WITH_ALPHA: return "RGB with Alpha"; - default: return "Unknown - " + colorType; - } -} - -String getFilterMethodString() { - switch (filterMethod) { - case FILTER_NONE: return "None"; - case FILTER_SUB: return "Sub"; - case FILTER_UP: return "Up"; - case FILTER_AVERAGE: return "Average"; - case FILTER_PAETH: return "Paeth"; - default: return "Unknown"; - } -} - -String getInterlaceMethodString() { - switch (interlaceMethod) { - case INTERLACE_METHOD_NONE: return "Not Interlaced"; - case INTERLACE_METHOD_ADAM7: return "Interlaced - ADAM7"; - default: return "Unknown"; - } -} - -void contributeToString(StringBuffer buffer) { - buffer.append("\n\tWidth: "); - buffer.append(width); - buffer.append("\n\tHeight: "); - buffer.append(height); - buffer.append("\n\tBit Depth: "); - buffer.append(bitDepth); - buffer.append("\n\tColor Type: "); - buffer.append(getColorTypeString()); - buffer.append("\n\tCompression Method: "); - buffer.append(compressionMethod); - buffer.append("\n\tFilter Method: "); - buffer.append(getFilterMethodString()); - buffer.append("\n\tInterlace Method: "); - buffer.append(getInterlaceMethodString()); -} - -boolean getMustHavePalette() { - return colorType == COLOR_TYPE_PALETTE; -} - -boolean getCanHavePalette() { - return colorType != COLOR_TYPE_GRAYSCALE && - colorType != COLOR_TYPE_GRAYSCALE_WITH_ALPHA; -} - -/** - * Answer the pixel size in bits based on the color type - * and bit depth. - */ -int getBitsPerPixel() { - switch (colorType) { - case COLOR_TYPE_RGB_WITH_ALPHA: - return 4 * bitDepth; - case COLOR_TYPE_RGB: - return 3 * bitDepth; - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - return 2 * bitDepth; - case COLOR_TYPE_GRAYSCALE: - case COLOR_TYPE_PALETTE: - return bitDepth; - default: - SWT.error(SWT.ERROR_INVALID_IMAGE); - return 0; - } -} - -/** - * Answer the pixel size in bits based on the color type - * and bit depth. - */ -int getSwtBitsPerPixel() { - switch (colorType) { - case COLOR_TYPE_RGB_WITH_ALPHA: - case COLOR_TYPE_RGB: - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - return 24; - case COLOR_TYPE_GRAYSCALE: - case COLOR_TYPE_PALETTE: - return Math.min(bitDepth, 8); - default: - SWT.error(SWT.ERROR_INVALID_IMAGE); - return 0; - } -} - -int getFilterByteOffset() { - if (bitDepth < 8) return 1; - return getBitsPerPixel() / 8; -} - -boolean usesDirectColor() { - switch (colorType) { - case COLOR_TYPE_GRAYSCALE: - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - case COLOR_TYPE_RGB: - case COLOR_TYPE_RGB_WITH_ALPHA: - return true; - default: - return false; - } -} - -PaletteData createGrayscalePalette() { - int depth = Math.min(bitDepth, 8); - int max = (1 << depth) - 1; - int delta = 255 / max; - int gray = 0; - RGB[] rgbs = new RGB[max + 1]; - for (int i = 0; i <= max; i++) { - rgbs[i] = new RGB(gray, gray, gray); - gray += delta; - } - return new PaletteData(rgbs); -} - -PaletteData getPaletteData() { - switch (colorType) { - case COLOR_TYPE_GRAYSCALE: - return createGrayscalePalette(); - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - case COLOR_TYPE_RGB: - case COLOR_TYPE_RGB_WITH_ALPHA: - return new PaletteData(0xFF0000, 0xFF00, 0xFF); - default: - return null; - } -} - - - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java deleted file mode 100644 index c0fd08e329..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.*; - -public class PngInputStream extends InputStream { - PngChunkReader reader; - PngChunk chunk; - int offset, length; - - final static int DATA_OFFSET = 8; - -public PngInputStream(PngIdatChunk chunk, PngChunkReader reader) { - this.chunk = chunk; - this.reader = reader; - length = chunk.getLength(); - offset = 0; -} - -private boolean checkChunk() throws IOException { - while (offset == length) { - chunk = reader.readNextChunk(); - if (chunk == null) throw new IOException(); - if (chunk.getChunkType() == PngChunk.CHUNK_IEND) return false; - if (chunk.getChunkType() != PngChunk.CHUNK_IDAT) throw new IOException(); - length = chunk.getLength(); - offset = 0; - } - return true; -} - -public void close() throws IOException { - chunk = null; -} - -public int read() throws IOException { - if (chunk == null) throw new IOException(); - if (offset == length && !checkChunk()) return -1; - int b = chunk.reference[DATA_OFFSET + offset] & 0xFF; - offset++; - return b; -} - -public int read(byte[] b, int off, int len) throws IOException { - if (chunk == null) throw new IOException(); - if (offset == length && !checkChunk()) return -1; - len = Math.min(len, length - offset); - System.arraycopy(chunk.reference, DATA_OFFSET + offset, b, off, len); - offset += len; - return len; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java deleted file mode 100755 index e4b8d71a7e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.*; - -public class PngLzBlockReader { - boolean isLastBlock; - byte compressionType; - int uncompressedBytesRemaining; - PngDecodingDataStream stream; - PngHuffmanTables huffmanTables; - - byte[] window; - int windowIndex; - int copyIndex; - int copyBytesRemaining; - - static final int UNCOMPRESSED = 0; - static final int COMPRESSED_FIXED = 1; - static final int COMPRESSED_DYNAMIC = 2; - - static final int END_OF_COMPRESSED_BLOCK = 256; - static final int FIRST_LENGTH_CODE = 257; - static final int LAST_LENGTH_CODE = 285; - static final int FIRST_DISTANCE_CODE = 1; - static final int LAST_DISTANCE_CODE = 29; - static final int FIRST_CODE_LENGTH_CODE = 4; - static final int LAST_CODE_LENGTH_CODE = 19; - - static final int[] lengthBases = { - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, - 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 - } ; - static final int[] extraLengthBits = { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, - }; - static final int[] distanceBases = { - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, - 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, - 6145, 8193, 12289, 16385, 24577, - }; - static final int[] extraDistanceBits = { - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, - 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, - }; - - -PngLzBlockReader(PngDecodingDataStream stream) { - this.stream = stream; - isLastBlock = false; -} - -void setWindowSize(int windowSize) { - window = new byte[windowSize]; -} - -void readNextBlockHeader() throws IOException { - isLastBlock = stream.getNextIdatBit() != 0; - compressionType = (byte)(stream.getNextIdatBits(2) & 0xFF); - if (compressionType > 2) stream.error(); - - if (compressionType == UNCOMPRESSED) { - byte b1 = stream.getNextIdatByte(); - byte b2 = stream.getNextIdatByte(); - byte b3 = stream.getNextIdatByte(); - byte b4 = stream.getNextIdatByte(); - if (b1 != ~b3 || b2 != ~b4) stream.error(); - uncompressedBytesRemaining = (b1 & 0xFF) | ((b2 & 0xFF) << 8); - } else if (compressionType == COMPRESSED_DYNAMIC) { - huffmanTables = PngHuffmanTables.getDynamicTables(stream); - } else { - huffmanTables = PngHuffmanTables.getFixedTables(); - } -} - -byte getNextByte() throws IOException { - if (compressionType == UNCOMPRESSED) { - if (uncompressedBytesRemaining == 0) { - readNextBlockHeader(); - return getNextByte(); - } - uncompressedBytesRemaining--; - return stream.getNextIdatByte(); - } else { - byte value = getNextCompressedByte(); - if (value == END_OF_COMPRESSED_BLOCK) { - if (isLastBlock) stream.error(); - readNextBlockHeader(); - return getNextByte(); - } else { - return value; - } - } -} - -private void assertBlockAtEnd() throws IOException { - if (compressionType == UNCOMPRESSED) { - if (uncompressedBytesRemaining > 0) stream.error(); - } else if (copyBytesRemaining > 0 || - (huffmanTables.getNextLiteralValue(stream) != END_OF_COMPRESSED_BLOCK)) - { - stream.error(); - } -} -void assertCompressedDataAtEnd() throws IOException { - assertBlockAtEnd(); - while (!isLastBlock) { - readNextBlockHeader(); - assertBlockAtEnd(); - } -} - -private byte getNextCompressedByte() throws IOException { - if (copyBytesRemaining > 0) { - byte value = window[copyIndex]; - window[windowIndex] = value; - copyBytesRemaining--; - - copyIndex++; - windowIndex++; - if (copyIndex == window.length) copyIndex = 0; - if (windowIndex == window.length) windowIndex = 0; - - return value; - } - - int value = huffmanTables.getNextLiteralValue(stream); - if (value < END_OF_COMPRESSED_BLOCK) { - window[windowIndex] = (byte) (value & 0xFF); - windowIndex++; - if (windowIndex >= window.length) windowIndex = 0; - return (byte) (value & 0xFF); - } else if (value == END_OF_COMPRESSED_BLOCK) { - readNextBlockHeader(); - return getNextByte(); - } else if (value <= LAST_LENGTH_CODE) { - int extraBits = extraLengthBits[value - FIRST_LENGTH_CODE]; - int length = lengthBases[value - FIRST_LENGTH_CODE]; - if (extraBits > 0) { - length += stream.getNextIdatBits(extraBits); - } - - value = huffmanTables.getNextDistanceValue(stream); - if (value > LAST_DISTANCE_CODE) stream.error(); - extraBits = extraDistanceBits[value]; - int distance = distanceBases[value]; - if (extraBits > 0) { - distance += stream.getNextIdatBits(extraBits); - } - - copyIndex = windowIndex - distance; - if (copyIndex < 0) copyIndex += window.length; - - copyBytesRemaining = length; - return getNextCompressedByte(); - } else { - stream.error(); - return 0; - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java deleted file mode 100755 index 421849b730..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -class PngPlteChunk extends PngChunk { - - int paletteSize; - -PngPlteChunk(PaletteData palette) { - super(palette.getRGBs().length * 3); - paletteSize = length / 3; - setType(TYPE_PLTE); - setPaletteData(palette); - setCRC(computeCRC()); -} - -PngPlteChunk(byte[] reference){ - super(reference); - paletteSize = length / 3; -} - -int getChunkType() { - return CHUNK_PLTE; -} - -/** - * Get the number of colors in this palette. - */ -int getPaletteSize() { - return paletteSize; -} - -/** - * Get a PaletteData object representing the colors - * stored in this PLTE chunk. - * The result should be cached as the PLTE chunk - * does not store the palette data created. - */ -PaletteData getPaletteData() { - RGB[] rgbs = new RGB[paletteSize]; -// int start = DATA_OFFSET; -// int end = DATA_OFFSET + length; - for (int i = 0; i < rgbs.length; i++) { - int offset = DATA_OFFSET + (i * 3); - int red = reference[offset] & 0xFF; - int green = reference[offset + 1] & 0xFF; - int blue = reference[offset + 2] & 0xFF; - rgbs[i] = new RGB(red, green, blue); - } - return new PaletteData(rgbs); -} - -/** - * Set the data of a PLTE chunk to the colors - * stored in the specified PaletteData object. - */ -void setPaletteData(PaletteData palette) { - RGB[] rgbs = palette.getRGBs(); - for (int i = 0; i < rgbs.length; i++) { - int offset = DATA_OFFSET + (i * 3); - reference[offset] = (byte) rgbs[i].red; - reference[offset + 1] = (byte) rgbs[i].green; - reference[offset + 2] = (byte) rgbs[i].blue; - } -} - -/** - * Answer whether the chunk is a valid PLTE chunk. - */ -void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { - // A PLTE chunk is invalid if no IHDR has been read or if any PLTE, - // IDAT, or IEND chunk has been read. - if (!readState.readIHDR - || readState.readPLTE - || readState.readTRNS - || readState.readIDAT - || readState.readIEND) - { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } else { - readState.readPLTE = true; - } - - super.validate(readState, headerChunk); - - // Palettes cannot be included in grayscale images. - // - // Note: just ignore the palette. -// if (!headerChunk.getCanHavePalette()) SWT.error(SWT.ERROR_INVALID_IMAGE); - - // Palette chunks' data fields must be event multiples - // of 3. Each 3-byte group represents an RGB value. - if (getLength() % 3 != 0) SWT.error(SWT.ERROR_INVALID_IMAGE); - - // Palettes cannot have more entries than 2^bitDepth - // where bitDepth is the bit depth of the image given - // in the IHDR chunk. - if (1 << headerChunk.getBitDepth() < paletteSize) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - - // Palettes cannot have more than 256 entries. - if (256 < paletteSize) SWT.error(SWT.ERROR_INVALID_IMAGE); -} - -void contributeToString(StringBuffer buffer) { - buffer.append("\n\tPalette size:"); - buffer.append(paletteSize); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java deleted file mode 100755 index d659a677d8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -public class PngTrnsChunk extends PngChunk { - static final int TRANSPARENCY_TYPE_PIXEL = 0; - static final int TRANSPARENCY_TYPE_ALPHAS = 1; - static final int RGB_DATA_LENGTH = 6; - -PngTrnsChunk(RGB rgb) { - super(RGB_DATA_LENGTH); - setType(TYPE_tRNS); - setInt16(DATA_OFFSET, rgb.red); - setInt16(DATA_OFFSET + 2, rgb.green); - setInt16(DATA_OFFSET + 4, rgb.blue); - setCRC(computeCRC()); -} - -PngTrnsChunk(byte[] reference){ - super(reference); -} - -int getChunkType() { - return CHUNK_tRNS; -} - -void validateLength(PngIhdrChunk header, PngPlteChunk paletteChunk) { - boolean valid; - switch (header.getColorType()) { - case PngIhdrChunk.COLOR_TYPE_RGB: - // Three 2-byte values (RGB) - valid = getLength() == 6; - break; - case PngIhdrChunk.COLOR_TYPE_PALETTE: - // Three 2-byte values (RGB) - valid = getLength() <= paletteChunk.getLength(); - break; - case PngIhdrChunk.COLOR_TYPE_GRAYSCALE: - // One 2-byte value - valid = getLength() == 2; - break; - // Cannot use both Alpha and tRNS - case PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA: - case PngIhdrChunk.COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - default: - valid = false; - } - if (!valid) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } -} - -/** - * Answer whether the chunk is a valid tRNS chunk. - */ -void validate(PngFileReadState readState, PngIhdrChunk headerChunk, PngPlteChunk paletteChunk) { - if (!readState.readIHDR - || (headerChunk.getMustHavePalette() && !readState.readPLTE) - || readState.readIDAT - || readState.readIEND) - { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } else { - readState.readTRNS = true; - } - - validateLength(headerChunk, paletteChunk); - - super.validate(readState, headerChunk); -} - - -int getTransparencyType(PngIhdrChunk header) { - if (header.getColorType() == PngIhdrChunk.COLOR_TYPE_PALETTE) { - return TRANSPARENCY_TYPE_ALPHAS; - } - return TRANSPARENCY_TYPE_PIXEL; -} - -/** - * Answer the transparent pixel RGB value. - * This is not valid for palette color types. - * This is not valid for alpha color types. - * This will convert a grayscale value into - * a palette index. - * It will compress a 6 byte RGB into a 3 byte - * RGB. - */ -int getSwtTransparentPixel(PngIhdrChunk header) { - switch (header.getColorType()) { - case PngIhdrChunk.COLOR_TYPE_GRAYSCALE: - int gray = ((reference[DATA_OFFSET] & 0xFF) << 8) - + (reference[DATA_OFFSET + 1] & 0xFF); - if (header.getBitDepth() > 8) { - return PNGFileFormat.compress16BitDepthTo8BitDepth(gray); - } - return gray & 0xFF; - case PngIhdrChunk.COLOR_TYPE_RGB: - int red = ((reference[DATA_OFFSET] & 0xFF) << 8) - | (reference[DATA_OFFSET + 1] & 0xFF); - int green = ((reference[DATA_OFFSET + 2] & 0xFF) << 8) - | (reference[DATA_OFFSET + 3] & 0xFF); - int blue = ((reference[DATA_OFFSET + 4] & 0xFF) << 8) - | (reference[DATA_OFFSET + 5] & 0xFF); - if (header.getBitDepth() > 8) { - red = PNGFileFormat.compress16BitDepthTo8BitDepth(red); - green = PNGFileFormat.compress16BitDepthTo8BitDepth(green); - blue = PNGFileFormat.compress16BitDepthTo8BitDepth(blue); - } - return (red << 16) | (green << 8) | blue; - default: - SWT.error(SWT.ERROR_INVALID_IMAGE); - return -1; - } -} - -/** - * Answer an array of Alpha values that correspond to the - * colors in the palette. - * This is only valid for the COLOR_TYPE_PALETTE color type. - */ -byte[] getAlphaValues(PngIhdrChunk header, PngPlteChunk paletteChunk) { - if (header.getColorType() != PngIhdrChunk.COLOR_TYPE_PALETTE) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - byte[] alphas = new byte[paletteChunk.getPaletteSize()]; - int dataLength = getLength(); - int i = 0; - for (i = 0; i < dataLength; i++) { - alphas[i] = reference[DATA_OFFSET + i]; - } - /** - * Any palette entries which do not have a corresponding - * alpha value in the tRNS chunk are spec'd to have an - * alpha of 255. - */ - for (int j = i; j < alphas.length; j++) { - alphas[j] = (byte) 255; - } - return alphas; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java deleted file mode 100644 index da5f84cf1f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java +++ /dev/null @@ -1,625 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -final class TIFFDirectory { - - TIFFRandomFileAccess file; - boolean isLittleEndian; - ImageLoader loader; - int depth; - - /* Directory fields */ - int imageWidth; - int imageLength; - int[] bitsPerSample; - int compression; - int photometricInterpretation; - int[] stripOffsets; - int samplesPerPixel; - int rowsPerStrip; - int[] stripByteCounts; - int t4Options; - int colorMapOffset; - - /* Encoder fields */ - ImageData image; - LEDataOutputStream out; - - static final int NO_VALUE = -1; - - static final short TAG_ImageWidth = 256; - static final short TAG_ImageLength = 257; - static final short TAG_BitsPerSample = 258; - static final short TAG_Compression = 259; - static final short TAG_PhotometricInterpretation = 262; - static final short TAG_StripOffsets = 273; - static final short TAG_SamplesPerPixel = 277; - static final short TAG_RowsPerStrip = 278; - static final short TAG_StripByteCounts = 279; - static final short TAG_XResolution = 282; - static final short TAG_YResolution = 283; - static final short TAG_T4Options = 292; - static final short TAG_ResolutionUnit = 296; - static final short TAG_ColorMap = 320; - - static final int TYPE_BYTE = 1; - static final int TYPE_ASCII = 2; - static final int TYPE_SHORT = 3; - static final int TYPE_LONG = 4; - static final int TYPE_RATIONAL = 5; - - /* Different compression schemes */ - static final int COMPRESSION_NONE = 1; - static final int COMPRESSION_CCITT_3_1 = 2; - static final int COMPRESSION_PACKBITS = 32773; - - static final int IFD_ENTRY_SIZE = 12; - -public TIFFDirectory(TIFFRandomFileAccess file, boolean isLittleEndian, ImageLoader loader) { - this.file = file; - this.isLittleEndian = isLittleEndian; - this.loader = loader; -} - -public TIFFDirectory(ImageData image) { - this.image = image; -} - -/* PackBits decoder */ -int decodePackBits(byte[] src, byte[] dest, int offsetDest) { - int destIndex = offsetDest; - int srcIndex = 0; - while (srcIndex < src.length) { - byte n = src[srcIndex]; - if (0 <= n && n <= 127) { - /* Copy next n+1 bytes literally */ - System.arraycopy(src, ++srcIndex, dest, destIndex, n + 1); - srcIndex += n + 1; - destIndex += n + 1; - } else if (-127 <= n && n <= -1) { - /* Copy next byte -n+1 times */ - byte value = src[++srcIndex]; - for (int j = 0; j < -n + 1; j++) { - dest[destIndex++] = value; - } - srcIndex++; - } else { - /* Noop when n == -128 */ - srcIndex++; - } - } - /* Number of bytes copied */ - return destIndex - offsetDest; -} - -int getEntryValue(int type, byte[] buffer, int index) { - return toInt(buffer, index + 8, type); -} - -void getEntryValue(int type, byte[] buffer, int index, int[] values) throws IOException { - int start = index + 8; - int size; - int offset = toInt(buffer, start, TYPE_LONG); - switch (type) { - case TYPE_SHORT: size = 2; break; - case TYPE_LONG: size = 4; break; - case TYPE_RATIONAL: size = 8; break; - case TYPE_ASCII: - case TYPE_BYTE: size = 1; break; - default: SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); return; - } - if (values.length * size > 4) { - buffer = new byte[values.length * size]; - file.seek(offset); - file.read(buffer); - start = 0; - } - for (int i = 0; i < values.length; i++) { - values[i] = toInt(buffer, start + i * size, type); - } -} - -void decodePixels(ImageData image) throws IOException { - /* Each row is byte aligned */ - byte[] imageData = new byte[(imageWidth * depth + 7) / 8 * imageLength]; - image.data = imageData; - int destIndex = 0; - int length = stripOffsets.length; - for (int i = 0; i < length; i++) { - /* Read a strip */ - byte[] data = new byte[stripByteCounts[i]]; - file.seek(stripOffsets[i]); - file.read(data); - if (compression == COMPRESSION_NONE) { - System.arraycopy(data, 0, imageData, destIndex, data.length); - destIndex += data.length; - } else if (compression == COMPRESSION_PACKBITS) { - destIndex += decodePackBits(data, imageData, destIndex); - } else if (compression == COMPRESSION_CCITT_3_1 || compression == 3) { - TIFFModifiedHuffmanCodec codec = new TIFFModifiedHuffmanCodec(); - int nRows = rowsPerStrip; - if (i == length -1) { - int n = imageLength % rowsPerStrip; - if (n != 0) nRows = n; - } - destIndex += codec.decode(data, imageData, destIndex, imageWidth, nRows); - } - if (loader.hasListeners()) { - loader.notifyListeners(new ImageLoaderEvent(loader, image, i, i == length - 1)); - } - } -} - -PaletteData getColorMap() throws IOException { - int numColors = 1 << bitsPerSample[0]; - /* R, G, B entries are 16 bit wide (2 bytes) */ - int numBytes = 3 * 2 * numColors; - byte[] buffer = new byte[numBytes]; - file.seek(colorMapOffset); - file.read(buffer); - RGB[] colors = new RGB[numColors]; - /** - * SWT does not support 16-bit depth color formats. - * Convert the 16-bit data to 8-bit data. - * The correct way to do this is to multiply each - * 16 bit value by the value: - * (2^8 - 1) / (2^16 - 1). - * The fast way to do this is just to drop the low - * byte of the 16-bit value. - */ - int offset = isLittleEndian ? 1 : 0; - int startG = 2 * numColors; - int startB = startG + 2 * numColors; - for (int i = 0; i < numColors; i++) { - int r = buffer[offset] & 0xFF; - int g = buffer[startG + offset] & 0xFF; - int b = buffer[startB + offset] & 0xFF; - colors[i] = new RGB(r, g, b); - offset += 2; - } - return new PaletteData(colors); -} - -PaletteData getGrayPalette() { - int numColors = 1 << bitsPerSample[0]; - RGB[] rgbs = new RGB[numColors]; - for (int i = 0; i < numColors; i++) { - int value = i * 0xFF / (numColors - 1); - if (photometricInterpretation == 0) value = 0xFF - value; - rgbs[i] = new RGB(value, value, value); - } - return new PaletteData(rgbs); -} - -PaletteData getRGBPalette(int bitsR, int bitsG, int bitsB) { - int blueMask = 0; - for (int i = 0; i < bitsB; i++) { - blueMask |= 1 << i; - } - int greenMask = 0; - for (int i = bitsB; i < bitsB + bitsG; i++) { - greenMask |= 1 << i; - } - int redMask = 0; - for (int i = bitsB + bitsG; i < bitsB + bitsG + bitsR; i++) { - redMask |= 1 << i; - } - return new PaletteData(redMask, greenMask, blueMask); -} - -int formatStrips(int rowByteSize, int nbrRows, byte[] data, int maxStripByteSize, int offsetPostIFD, int extraBytes, int[][] strips) { - /* - * Calculate the nbr of required strips given the following requirements: - * - each strip should, if possible, not be greater than maxStripByteSize - * - each strip should contain 1 or more entire rows - * - * Format the strip fields arrays so that the image data is stored in one - * contiguous block. This block is stored after the IFD and after any tag - * info described in the IFD. - */ - int n, nbrRowsPerStrip; - if (rowByteSize > maxStripByteSize) { - /* Each strip contains 1 row */ - n = data.length / rowByteSize; - nbrRowsPerStrip = 1; - } else { - int nbr = (data.length + maxStripByteSize - 1) / maxStripByteSize; - nbrRowsPerStrip = nbrRows / nbr; - n = (nbrRows + nbrRowsPerStrip - 1) / nbrRowsPerStrip; - } - int stripByteSize = rowByteSize * nbrRowsPerStrip; - - int[] offsets = new int[n]; - int[] counts = new int[n]; - /* - * Nbr of bytes between the end of the IFD directory and the start of - * the image data. Keep space for at least the offsets and counts - * data, each field being TYPE_LONG (4 bytes). If other tags require - * space between the IFD and the image block, use the extraBytes - * parameter. - * If there is only one strip, the offsets and counts data is stored - * directly in the IFD and we need not reserve space for it. - */ - int postIFDData = n == 1 ? 0 : n * 2 * 4; - int startOffset = offsetPostIFD + extraBytes + postIFDData; /* offset of image data */ - - int offset = startOffset; - for (int i = 0; i < n; i++) { - /* - * Store all strips sequentially to allow us - * to copy all pixels in one contiguous area. - */ - offsets[i] = offset; - counts[i] = stripByteSize; - offset += stripByteSize; - } - /* The last strip may contain fewer rows */ - int mod = data.length % stripByteSize; - if (mod != 0) counts[counts.length - 1] = mod; - - strips[0] = offsets; - strips[1] = counts; - return nbrRowsPerStrip; -} - -int[] formatColorMap(RGB[] rgbs) { - /* - * In a TIFF ColorMap, all red come first, followed by - * green and blue. All values must be converted from - * 8 bit to 16 bit. - */ - int[] colorMap = new int[rgbs.length * 3]; - int offsetGreen = rgbs.length; - int offsetBlue = rgbs.length * 2; - for (int i = 0; i < rgbs.length; i++) { - colorMap[i] = rgbs[i].red << 8 | rgbs[i].red; - colorMap[i + offsetGreen] = rgbs[i].green << 8 | rgbs[i].green; - colorMap[i + offsetBlue] = rgbs[i].blue << 8 | rgbs[i].blue; - } - return colorMap; -} - -void parseEntries(byte[] buffer) throws IOException { - for (int offset = 0; offset < buffer.length; offset += IFD_ENTRY_SIZE) { - int tag = toInt(buffer, offset, TYPE_SHORT); - int type = toInt(buffer, offset + 2, TYPE_SHORT); - int count = toInt(buffer, offset + 4, TYPE_LONG); - switch (tag) { - case TAG_ImageWidth: { - imageWidth = getEntryValue(type, buffer, offset); - break; - } - case TAG_ImageLength: { - imageLength = getEntryValue(type, buffer, offset); - break; - } - case TAG_BitsPerSample: { - if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE); - bitsPerSample = new int[count]; - getEntryValue(type, buffer, offset, bitsPerSample); - break; - } - case TAG_Compression: { - compression = getEntryValue(type, buffer, offset); - break; - } - case TAG_PhotometricInterpretation: { - photometricInterpretation = getEntryValue(type, buffer, offset); - break; - } - case TAG_StripOffsets: { - if (type != TYPE_LONG && type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE); - stripOffsets = new int[count]; - getEntryValue(type, buffer, offset, stripOffsets); - break; - } - case TAG_SamplesPerPixel: { - if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE); - samplesPerPixel = getEntryValue(type, buffer, offset); - /* Only the basic 1 and 3 values are supported */ - if (samplesPerPixel != 1 && samplesPerPixel != 3) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - break; - } - case TAG_RowsPerStrip: { - rowsPerStrip = getEntryValue(type, buffer, offset); - break; - } - case TAG_StripByteCounts: { - stripByteCounts = new int[count]; - getEntryValue(type, buffer, offset, stripByteCounts); - break; - } - case TAG_XResolution: { - /* Ignored */ - break; - } - case TAG_YResolution: { - /* Ignored */ - break; - } - case TAG_T4Options: { - if (type != TYPE_LONG) SWT.error(SWT.ERROR_INVALID_IMAGE); - t4Options = getEntryValue(type, buffer, offset); - if ((t4Options & 0x1) == 1) { - /* 2-dimensional coding is not supported */ - SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - } - break; - } - case TAG_ResolutionUnit: { - /* Ignored */ - break; - } - case TAG_ColorMap: { - if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE); - /* Get the offset of the colorMap (use TYPE_LONG) */ - colorMapOffset = getEntryValue(TYPE_LONG, buffer, offset); - break; - } - } - } -} - -public ImageData read() throws IOException { - /* Set TIFF default values */ - bitsPerSample = new int[] {1}; - colorMapOffset = NO_VALUE; - compression = 1; - imageLength = NO_VALUE; - imageWidth = NO_VALUE; - photometricInterpretation = NO_VALUE; - rowsPerStrip = Integer.MAX_VALUE; - samplesPerPixel = 1; - stripByteCounts = null; - stripOffsets = null; - - byte[] buffer = new byte[2]; - file.read(buffer); - int numberEntries = toInt(buffer, 0, TYPE_SHORT); - buffer = new byte[IFD_ENTRY_SIZE * numberEntries]; - file.read(buffer); - parseEntries(buffer); - - PaletteData palette = null; - depth = 0; - switch (photometricInterpretation) { - case 0: - case 1: { - /* Bilevel or Grayscale image */ - palette = getGrayPalette(); - depth = bitsPerSample[0]; - break; - } - case 2: { - /* RGB image */ - if (colorMapOffset != NO_VALUE) SWT.error(SWT.ERROR_INVALID_IMAGE); - /* SamplesPerPixel 3 is the only value supported */ - palette = getRGBPalette(bitsPerSample[0], bitsPerSample[1], bitsPerSample[2]); - depth = bitsPerSample[0] + bitsPerSample[1] + bitsPerSample[2]; - break; - } - case 3: { - /* Palette Color image */ - if (colorMapOffset == NO_VALUE) SWT.error(SWT.ERROR_INVALID_IMAGE); - palette = getColorMap(); - depth = bitsPerSample[0]; - break; - } - default: { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - } - - ImageData image = ImageData.internal_new( - imageWidth, - imageLength, - depth, - palette, - 1, - null, - 0, - null, - null, - -1, - -1, - SWT.IMAGE_TIFF, - 0, - 0, - 0, - 0); - decodePixels(image); - return image; -} - -int toInt(byte[] buffer, int i, int type) { - if (type == TYPE_LONG) { - return isLittleEndian ? - (buffer[i] & 0xFF) | ((buffer[i + 1] & 0xFF) << 8) | ((buffer[i + 2] & 0xFF) << 16) | ((buffer[i + 3] & 0xFF) << 24) : - (buffer[i + 3] & 0xFF) | ((buffer[i + 2] & 0xFF) << 8) | ((buffer[i + 1] & 0xFF) << 16) | ((buffer[i] & 0xFF) << 24); - } - if (type == TYPE_SHORT) { - return isLittleEndian ? - (buffer[i] & 0xFF) | ((buffer[i + 1] & 0xFF) << 8) : - (buffer[i + 1] & 0xFF) | ((buffer[i] & 0xFF) << 8); - } - /* Invalid type */ - SWT.error(SWT.ERROR_INVALID_IMAGE); - return -1; -} - -void write(int photometricInterpretation) throws IOException { - boolean isRGB = photometricInterpretation == 2; - boolean isColorMap = photometricInterpretation == 3; - boolean isBiLevel = photometricInterpretation == 0 || photometricInterpretation == 1; - - int imageWidth = image.width; - int imageLength = image.height; - int rowByteSize = image.bytesPerLine; - - int numberEntries = isBiLevel ? 9 : 11; - int lengthDirectory = 2 + 12 * numberEntries + 4; - /* Offset following the header and the directory */ - int nextOffset = 8 + lengthDirectory; - - /* Extra space used by XResolution and YResolution values */ - int extraBytes = 16; - - int[] colorMap = null; - if (isColorMap) { - PaletteData palette = image.palette; - RGB[] rgbs = palette.getRGBs(); - colorMap = formatColorMap(rgbs); - /* The number of entries of the Color Map must match the bitsPerSample field */ - if (colorMap.length != 3 * 1 << image.depth) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - /* Extra space used by ColorMap values */ - extraBytes += colorMap.length * 2; - } - if (isRGB) { - /* Extra space used by BitsPerSample values */ - extraBytes += 6; - } - /* TIFF recommends storing the data in strips of no more than 8 Ko */ - byte[] data = image.data; - int[][] strips = new int[2][]; - int nbrRowsPerStrip = formatStrips(rowByteSize, imageLength, data, 8192, nextOffset, extraBytes, strips); - int[] stripOffsets = strips[0]; - int[] stripByteCounts = strips[1]; - - int bitsPerSampleOffset = NO_VALUE; - if (isRGB) { - bitsPerSampleOffset = nextOffset; - nextOffset += 6; - } - int stripOffsetsOffset = NO_VALUE, stripByteCountsOffset = NO_VALUE; - int xResolutionOffset, yResolutionOffset, colorMapOffset = NO_VALUE; - int cnt = stripOffsets.length; - if (cnt > 1) { - stripOffsetsOffset = nextOffset; - nextOffset += 4 * cnt; - stripByteCountsOffset = nextOffset; - nextOffset += 4 * cnt; - } - xResolutionOffset = nextOffset; - nextOffset += 8; - yResolutionOffset = nextOffset; - nextOffset += 8; - if (isColorMap) { - colorMapOffset = nextOffset; - nextOffset += colorMap.length * 2; - } - /* TIFF header */ - writeHeader(); - - /* Image File Directory */ - out.writeShort(numberEntries); - writeEntry(TAG_ImageWidth, TYPE_LONG, 1, imageWidth); - writeEntry(TAG_ImageLength, TYPE_LONG, 1, imageLength); - if (isColorMap) writeEntry(TAG_BitsPerSample, TYPE_SHORT, 1, image.depth); - if (isRGB) writeEntry(TAG_BitsPerSample, TYPE_SHORT, 3, bitsPerSampleOffset); - writeEntry(TAG_Compression, TYPE_SHORT, 1, COMPRESSION_NONE); - writeEntry(TAG_PhotometricInterpretation, TYPE_SHORT, 1, photometricInterpretation); - writeEntry(TAG_StripOffsets, TYPE_LONG, cnt, cnt > 1 ? stripOffsetsOffset : stripOffsets[0]); - if (isRGB) writeEntry(TAG_SamplesPerPixel, TYPE_SHORT, 1, 3); - writeEntry(TAG_RowsPerStrip, TYPE_LONG, 1, nbrRowsPerStrip); - writeEntry(TAG_StripByteCounts, TYPE_LONG, cnt, cnt > 1 ? stripByteCountsOffset : stripByteCounts[0]); - writeEntry(TAG_XResolution, TYPE_RATIONAL, 1, xResolutionOffset); - writeEntry(TAG_YResolution, TYPE_RATIONAL, 1, yResolutionOffset); - if (isColorMap) writeEntry(TAG_ColorMap, TYPE_SHORT, colorMap.length, colorMapOffset); - /* Offset of next IFD (0 for last IFD) */ - out.writeInt(0); - - /* Values longer than 4 bytes Section */ - - /* BitsPerSample 8,8,8 */ - if (isRGB) for (int i = 0; i < 3; i++) out.writeShort(8); - if (cnt > 1) { - for (int i = 0; i < cnt; i++) out.writeInt(stripOffsets[i]); - for (int i = 0; i < cnt; i++) out.writeInt(stripByteCounts[i]); - } - /* XResolution and YResolution set to 300 dpi */ - for (int i = 0; i < 2; i++) { - out.writeInt(300); - out.writeInt(1); - } - /* ColorMap */ - if (isColorMap) for (int i = 0; i < colorMap.length; i++) out.writeShort(colorMap[i]); - - /* Image Data */ - out.write(data); -} - -void writeEntry(short tag, int type, int count, int value) throws IOException { - out.writeShort(tag); - out.writeShort(type); - out.writeInt(count); - out.writeInt(value); -} - -void writeHeader() throws IOException { - /* little endian */ - out.write(0x49); - out.write(0x49); - - /* TIFF identifier */ - out.writeShort(42); - /* - * Offset of the first IFD is chosen to be 8. - * It is word aligned and immediately after this header. - */ - out.writeInt(8); -} - -void writeToStream(LEDataOutputStream byteStream) throws IOException { - out = byteStream; - int photometricInterpretation = -1; - - /* Scanline pad must be 1 */ - if (image.scanlinePad != 1) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - switch (image.depth) { - case 1: { - /* Palette must be black and white or white and black */ - PaletteData palette = image.palette; - RGB[] rgbs = palette.colors; - if (palette.isDirect || rgbs == null || rgbs.length != 2) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - RGB rgb0 = rgbs[0]; - RGB rgb1 = rgbs[1]; - if (!(rgb0.red == rgb0.green && rgb0.green == rgb0.blue && - rgb1.red == rgb1.green && rgb1.green == rgb1.blue && - ((rgb0.red == 0x0 && rgb1.red == 0xFF) || (rgb0.red == 0xFF && rgb1.red == 0x0)))) { - SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - } - /* 0 means a color index of 0 is imaged as white */ - photometricInterpretation = image.palette.colors[0].red == 0xFF ? 0 : 1; - break; - } - case 4: - case 8: { - photometricInterpretation = 3; - break; - } - case 24: { - photometricInterpretation = 2; - break; - } - default: { - SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); - } - } - write(photometricInterpretation); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java deleted file mode 100644 index b419a57106..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -/** - * Baseline TIFF decoder revision 6.0 - * Extension T4-encoding CCITT T.4 1D - */ -public final class TIFFFileFormat extends FileFormat { - -boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] header = new byte[4]; - stream.read(header); - stream.unread(header); - if (header[0] != header[1]) return false; - if (!(header[0] == 0x49 && header[2] == 42 && header[3] == 0) && - !(header[0] == 0x4d && header[2] == 0 && header[3] == 42)) { - return false; - } - return true; - } catch (Exception e) { - return false; - } -} - -ImageData[] loadFromByteStream() { - byte[] header = new byte[8]; - boolean isLittleEndian; - ImageData[] images = new ImageData[0]; - TIFFRandomFileAccess file = new TIFFRandomFileAccess(inputStream); - try { - file.read(header); - if (header[0] != header[1]) SWT.error(SWT.ERROR_INVALID_IMAGE); - if (!(header[0] == 0x49 && header[2] == 42 && header[3] == 0) && - !(header[0] == 0x4d && header[2] == 0 && header[3] == 42)) { - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - isLittleEndian = header[0] == 0x49; - int offset = isLittleEndian ? - (header[4] & 0xFF) | ((header[5] & 0xFF) << 8) | ((header[6] & 0xFF) << 16) | ((header[7] & 0xFF) << 24) : - (header[7] & 0xFF) | ((header[6] & 0xFF) << 8) | ((header[5] & 0xFF) << 16) | ((header[4] & 0xFF) << 24); - file.seek(offset); - TIFFDirectory directory = new TIFFDirectory(file, isLittleEndian, loader); - ImageData image = directory.read(); - /* A baseline reader is only expected to read the first directory */ - images = new ImageData[] {image}; - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return images; -} - -void unloadIntoByteStream(ImageLoader loader) { - /* We do not currently support writing multi-page tiff, - * so we use the first image data in the loader's array. */ - ImageData image = loader.data[0]; - TIFFDirectory directory = new TIFFDirectory(image); - try { - directory.writeToStream(outputStream); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java deleted file mode 100644 index 5f0904c790..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import org.eclipse.swt.*; - -/* -* Decoder for -* - CCITT Group 3 1-Dimensional Modified Huffman run length encoding -* (TIFF compression type 2) -* - CCITT T.4 bi-level encoding 1D -* (TIFF compression type 3 option 1D) -*/ -final class TIFFModifiedHuffmanCodec { - static final short[][][] BLACK_CODE = { - /* 2 bits */ - {{2, 3}, {3, 2}}, - /* 3 bits */ - {{2, 1}, {3, 4}}, - /* 4 bits */ - {{2, 6}, {3, 5}}, - /* 5 bits */ - {{3, 7}}, - /* 6 bits */ - {{4, 9}, {5, 8}}, - /* 7 bits */ - {{4, 10}, {5, 11}, {7, 12}}, - /* 8 bits */ - {{4, 13}, {7, 14}}, - /* 9 bits */ - {{24, 15}}, - /* 10 bits */ - {{8, 18}, {15, 64}, {23, 16}, {24, 17}, {55, 0}}, - /* 11 bits */ - {/* EOL */{0, -1}, {8, 1792}, {23, 24}, {24, 25}, {40, 23}, {55, 22}, {103, 19}, - {104, 20}, {108, 21}, {12, 1856}, {13, 1920}}, - /* 12 bits */ - {{18, 1984}, {19, 2048}, {20, 2112}, {21, 2176}, {22, 2240}, {23, 2304}, - {28, 2368}, {29, 2432}, {30, 2496}, {31, 2560}, {36, 52}, {39, 55}, {40, 56}, - {43, 59}, {44, 60}, {51, 320}, {52, 384}, {53, 448}, {55, 53}, {56, 54}, {82, 50}, - {83, 51}, {84, 44}, {85, 45}, {86, 46}, {87, 47}, {88, 57}, {89, 58}, {90, 61}, - {91, 256}, {100, 48}, {101, 49}, {102, 62}, {103, 63}, {104, 30}, {105, 31}, - {106, 32}, {107, 33}, {108, 40}, {109, 41}, {200, 128}, {201, 192}, {202, 26}, - {203, 27}, {204, 28}, {205, 29}, {210, 34}, {211, 35}, {212, 36}, {213, 37}, - {214, 38}, {215, 39}, {218, 42}, {219, 43}}, - /* 13 bits */ - {{74, 640}, {75, 704}, {76, 768}, {77, 832}, {82, 1280}, {83, 1344}, {84, 1408}, - {85, 1472}, {90, 1536}, {91, 1600}, {100, 1664}, {101, 1728}, {108, 512}, - {109, 576}, {114, 896}, {115, 960}, {116, 1024}, {117, 1088}, {118, 1152}, - {119, 1216}} - }; - - static final short[][][] WHITE_CODE = { - /* 4 bits */ - {{7, 2}, {8, 3}, {11, 4}, {12, 5}, {14, 6}, {15, 7}}, - /* 5 bits */ - {{7, 10}, {8, 11}, {18, 128}, {19, 8}, {20, 9}, {27, 64}}, - /* 6 bits */ - {{3, 13}, {7, 1}, {8, 12}, {23, 192}, {24, 1664}, {42, 16}, {43, 17}, {52, 14}, - {53, 15}}, - /* 7 bits */ - {{3, 22}, {4, 23}, {8, 20}, {12, 19}, {19, 26}, {23, 21}, {24, 28}, {36, 27}, - {39, 18}, {40, 24}, {43, 25}, {55, 256}}, - /* 8 bits */ - {{2, 29}, {3, 30}, {4, 45}, {5, 46}, {10, 47}, {11, 48}, {18, 33}, {19, 34}, - {20, 35}, {21, 36}, {22, 37}, {23, 38}, {26, 31}, {27, 32}, {36, 53}, {37, 54}, - {40, 39}, {41, 40}, {42, 41}, {43, 42}, {44, 43}, {45, 44}, {50, 61}, {51, 62}, - {52, 63}, {53, 0}, {54, 320}, {55, 384}, {74, 59}, {75, 60}, {82, 49}, {83, 50}, - {84, 51}, {85, 52}, {88, 55}, {89, 56}, {90, 57}, {91, 58}, {100, 448}, - {101, 512}, {103, 640}, {104, 576}}, - /* 9 bits */ - {{152, 1472}, {153, 1536}, {154, 1600}, {155, 1728}, {204, 704}, {205, 768}, - {210, 832}, {211, 896}, {212, 960}, {213, 1024}, {214, 1088}, {215, 1152}, - {216, 1216}, {217, 1280}, {218, 1344}, {219, 1408}}, - /* 10 bits */ - {}, - /* 11 bits */ - {{8, 1792}, {12, 1856}, {13, 1920}}, - /* 12 bits */ - {/* EOL */{1, -1}, {18, 1984}, {19, 2048}, {20, 2112}, {21, 2176}, {22, 2240}, {23, 2304}, - {28, 2368}, {29, 2432}, {30, 2496}, {31, 2560}} - }; - - static final int BLACK_MIN_BITS = 2; - static final int WHITE_MIN_BITS = 4; - - boolean isWhite; - int whiteValue = 0; - int blackValue = 1; - byte[] src; - byte[] dest; - int byteOffsetSrc = 0; - int bitOffsetSrc = 0; - int byteOffsetDest = 0; - int bitOffsetDest = 0; - int code = 0; - int nbrBits = 0; - /* nbr of bytes per row */ - int rowSize; - -public int decode(byte[] src, byte[] dest, int offsetDest, int rowSize, int nRows) { - this.src = src; - this.dest = dest; - this.rowSize = rowSize; - byteOffsetSrc = 0; - bitOffsetSrc = 0; - byteOffsetDest = offsetDest; - bitOffsetDest = 0; - int cnt = 0; - while (cnt < nRows && decodeRow()) { - cnt++; - /* byte aligned */ - if (bitOffsetDest > 0) { - byteOffsetDest++; - bitOffsetDest = 0; - } - } - return byteOffsetDest - offsetDest; -} - -boolean decodeRow() { - isWhite = true; - int n = 0; - while (n < rowSize) { - int runLength = decodeRunLength(); - if (runLength < 0) return false; - n += runLength; - setNextBits(isWhite ? whiteValue : blackValue, runLength); - isWhite = !isWhite; - } - return true; -} - -int decodeRunLength() { - int runLength = 0; - int partialRun = 0; - short[][][] huffmanCode = isWhite ? WHITE_CODE : BLACK_CODE; - while (true) { - boolean found = false; - nbrBits = isWhite ? WHITE_MIN_BITS : BLACK_MIN_BITS; - code = getNextBits(nbrBits); - for (int i = 0; i < huffmanCode.length; i++) { - for (int j = 0; j < huffmanCode[i].length; j++) { - if (huffmanCode[i][j][0] == code) { - found = true; - partialRun = huffmanCode[i][j][1]; - if (partialRun == -1) { - /* Stop when reaching final EOL on last byte */ - if (byteOffsetSrc == src.length - 1) return -1; - /* Group 3 starts each row with an EOL - ignore it */ - } else { - runLength += partialRun; - if (partialRun < 64) return runLength; - } - break; - } - } - if (found) break; - code = code << 1 | getNextBit(); - } - if (!found) SWT.error(SWT.ERROR_INVALID_IMAGE); - } -} - -int getNextBit() { - int value = (src[byteOffsetSrc] >>> (7 - bitOffsetSrc)) & 0x1; - bitOffsetSrc++; - if (bitOffsetSrc > 7) { - byteOffsetSrc++; - bitOffsetSrc = 0; - } - return value; -} - -int getNextBits(int cnt) { - int value = 0; - for (int i = 0; i < cnt; i++) { - value = value << 1 | getNextBit(); - } - return value; -} - -void setNextBits(int value, int cnt) { - int n = cnt; - while (bitOffsetDest > 0 && bitOffsetDest <= 7 && n > 0) { - dest[byteOffsetDest] = value == 1 ? - (byte)(dest[byteOffsetDest] | (1 << (7 - bitOffsetDest))) : - (byte)(dest[byteOffsetDest] & ~(1 << (7 - bitOffsetDest))); - n--; - bitOffsetDest++; - } - if (bitOffsetDest == 8) { - byteOffsetDest++; - bitOffsetDest = 0; - } - while (n >= 8) { - dest[byteOffsetDest++] = (byte) (value == 1 ? 0xFF : 0); - n -= 8; - } - while (n > 0) { - dest[byteOffsetDest] = value == 1 ? - (byte)(dest[byteOffsetDest] | (1 << (7 - bitOffsetDest))) : - (byte)(dest[byteOffsetDest] & ~(1 << (7 - bitOffsetDest))); - n--; - bitOffsetDest++; - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java deleted file mode 100644 index 8cc7e390f3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - -import java.io.*; - -final class TIFFRandomFileAccess { - - LEDataInputStream inputStream; - int start, current, next; - byte[][] buffers; - - static final int CHUNK_SIZE = 8192; - static final int LIST_SIZE = 128; - -public TIFFRandomFileAccess(LEDataInputStream stream) { - inputStream = stream; - start = current = next = inputStream.getPosition(); - buffers = new byte[LIST_SIZE][]; -} - -void seek(int pos) throws IOException { - if (pos == current) return; - if (pos < start) throw new IOException(); - current = pos; - if (current > next) { - int n = current - next; - /* store required bytes */ - int index = next / CHUNK_SIZE; - int offset = next % CHUNK_SIZE; - while (n > 0) { - if (index >= buffers.length) { - byte[][] oldBuffers = buffers; - buffers = new byte[Math.max(index + 1, oldBuffers.length + LIST_SIZE)][]; - System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length); - } - if (buffers[index] == null) buffers[index] = new byte[CHUNK_SIZE]; - int cnt = inputStream.read(buffers[index], offset, Math.min(n, CHUNK_SIZE - offset)); - n -= cnt; - next += cnt; - index++; - offset = 0; - } - } -} - -void read(byte b[]) throws IOException { - int size = b.length; - int nCached = Math.min(size, next - current); - int nMissing = size - next + current; - int destNext = 0; - if (nCached > 0) { - /* Get cached bytes */ - int index = 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; - destNext += cnt; - index++; - offset = 0; - } - } - if (nMissing > 0) { - /* Read required bytes */ - int index = next / CHUNK_SIZE; - int offset = next % CHUNK_SIZE; - while (nMissing > 0) { - if (index >= buffers.length) { - byte[][] oldBuffers = buffers; - buffers = new byte[Math.max(index, oldBuffers.length + LIST_SIZE)][]; - System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length); - } - if (buffers[index] == null) buffers[index] = new byte[CHUNK_SIZE]; - int cnt = inputStream.read(buffers[index], offset, Math.min(nMissing, CHUNK_SIZE - offset)); - System.arraycopy(buffers[index], offset, b, destNext, cnt); - nMissing -= cnt; - next += cnt; - destNext += cnt; - index++; - offset = 0; - } - } - current += size; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java deleted file mode 100755 index 81d08aa7bf..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java +++ /dev/null @@ -1,690 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -public final class WinBMPFileFormat extends FileFormat { - static final int BMPFileHeaderSize = 14; - static final int BMPHeaderFixedSize = 40; - int importantColors; - Point pelsPerMeter = new Point(0, 0); - -/** - * Compress numBytes bytes of image data from src, storing in dest - * (starting at 0), using the technique specified by comp. - * If last is true, this indicates the last line of the image. - * Answer the size of the compressed data. - */ -int compress(int comp, byte[] src, int srcOffset, int numBytes, byte[] dest, boolean last) { - if (comp == 1) { // BMP_RLE8_COMPRESSION - return compressRLE8Data(src, srcOffset, numBytes, dest, last); - } - if (comp == 2) { // BMP_RLE4_COMPRESSION - return compressRLE4Data(src, srcOffset, numBytes, dest, last); - } - SWT.error(SWT.ERROR_INVALID_IMAGE); - return 0; -} -int compressRLE4Data(byte[] src, int srcOffset, int numBytes, byte[] dest, boolean last) { - int sp = srcOffset, end = srcOffset + numBytes, dp = 0; - int size = 0, left, i, n; - byte theByte; - while (sp < end) { - /* find two consecutive bytes that are the same in the next 128 */ - left = end - sp - 1; - if (left > 127) - left = 127; - for (n = 0; n < left; n++) { - if (src[sp + n] == src[sp + n + 1]) - break; - } - /* if there is only one more byte in the scan line, include it */ - if (n < 127 && n == left) - n++; - /* store the intervening data */ - switch (n) { - case 0: - break; - case 1: /* handled separately because 0,2 is a command */ - dest[dp] = 2; dp++; /* 1 byte == 2 pixels */ - dest[dp] = src[sp]; - dp++; sp++; - size += 2; - break; - default: - dest[dp] = 0; dp++; - dest[dp] = (byte)(n + n); dp++; /* n bytes = n*2 pixels */ - for (i = n; i > 0; i--) { - dest[dp] = src[sp]; - dp++; sp++; - } - size += 2 + n; - if ((n & 1) != 0) { /* pad to word */ - dest[dp] = 0; - dp++; - size++; - } - break; - } - /* find the length of the next run (up to 127) and store it */ - left = end - sp; - if (left > 0) { - if (left > 127) - left = 127; - theByte = src[sp]; - for (n = 1; n < left; n++) { - if (src[sp + n] != theByte) - break; - } - dest[dp] = (byte)(n + n); dp++; /* n bytes = n*2 pixels */ - dest[dp] = theByte; dp++; - sp += n; - size += 2; - } - } - - /* store the end of line or end of bitmap codes */ - dest[dp] = 0; dp++; - if (last) { - dest[dp] = 1; dp++; - } else { - dest[dp] = 0; dp++; - } - size += 2; - - return size; -} -int compressRLE8Data(byte[] src, int srcOffset, int numBytes, byte[] dest, boolean last) { - int sp = srcOffset, end = srcOffset + numBytes, dp = 0; - int size = 0, left, i, n; - byte theByte; - while (sp < end) { - /* find two consecutive bytes that are the same in the next 256 */ - left = end - sp - 1; - if (left > 254) - left = 254; - for (n = 0; n < left; n++) { - if (src[sp + n] == src[sp + n + 1]) - break; - } - /* if there is only one more byte in the scan line, include it */ - if (n == left) - n++; - /* store the intervening data */ - switch (n) { - case 0: - break; - case 2: /* handled separately because 0,2 is a command */ - dest[dp] = 1; dp++; - dest[dp] = src[sp]; - dp++; sp++; - size += 2; - /* don't break, fall through */ - case 1: /* handled separately because 0,1 is a command */ - dest[dp] = 1; dp++; - dest[dp] = src[sp]; - dp++; sp++; - size += 2; - break; - default: - dest[dp] = 0; dp++; - dest[dp] = (byte)n; dp++; - for (i = n; i > 0; i--) { - dest[dp] = src[sp]; - dp++; sp++; - } - size += 2 + n; - if ((n & 1) != 0) { /* pad to word */ - dest[dp] = 0; - dp++; - size++; - } - break; - } - /* find the length of the next run (up to 255) and store it */ - left = end - sp; - if (left > 0) { - if (left > 255) - left = 255; - theByte = src[sp]; - for (n = 1; n < left; n++) { - if (src[sp + n] != theByte) - break; - } - dest[dp] = (byte)n; dp++; - dest[dp] = theByte; dp++; - sp += n; - size += 2; - } - } - - /* store the end of line or end of bitmap codes */ - dest[dp] = 0; dp++; - if (last) { - dest[dp] = 1; dp++; - } else { - dest[dp] = 0; dp++; - } - size += 2; - - return size; -} -void decompressData(byte[] src, byte[] dest, int stride, int cmp) { - if (cmp == 1) { // BMP_RLE8_COMPRESSION - if (decompressRLE8Data(src, src.length, stride, dest, dest.length) <= 0) - SWT.error(SWT.ERROR_INVALID_IMAGE); - return; - } - if (cmp == 2) { // BMP_RLE4_COMPRESSION - if (decompressRLE4Data(src, src.length, stride, dest, dest.length) <= 0) - SWT.error(SWT.ERROR_INVALID_IMAGE); - return; - } - SWT.error(SWT.ERROR_INVALID_IMAGE); -} -int decompressRLE4Data(byte[] src, int numBytes, int stride, byte[] dest, int destSize) { - int sp = 0; - int se = numBytes; - int dp = 0; - int de = destSize; - int x = 0, y = 0; - while (sp < se) { - int len = src[sp] & 0xFF; - sp++; - if (len == 0) { - len = src[sp] & 0xFF; - sp++; - switch (len) { - case 0: /* end of line */ - y++; - x = 0; - dp = y * stride; - if (dp > de) - return -1; - break; - case 1: /* end of bitmap */ - return 1; - case 2: /* delta */ - x += src[sp] & 0xFF; - sp++; - y += src[sp] & 0xFF; - sp++; - dp = y * stride + x / 2; - if (dp > de) - return -1; - break; - default: /* absolute mode run */ - if ((len & 1) != 0) /* odd run lengths not currently supported */ - return -1; - x += len; - len = len / 2; - if (len > (se - sp)) - return -1; - if (len > (de - dp)) - return -1; - for (int i = 0; i < len; i++) { - dest[dp] = src[sp]; - dp++; - sp++; - } - if ((sp & 1) != 0) - sp++; /* word align sp? */ - break; - } - } else { - if ((len & 1) != 0) - return -1; - x += len; - len = len / 2; - byte theByte = src[sp]; - sp++; - if (len > (de - dp)) - return -1; - for (int i = 0; i < len; i++) { - dest[dp] = theByte; - dp++; - } - } - } - return 1; -} -int decompressRLE8Data(byte[] src, int numBytes, int stride, byte[] dest, int destSize) { - int sp = 0; - int se = numBytes; - int dp = 0; - int de = destSize; - int x = 0, y = 0; - while (sp < se) { - int len = src[sp] & 0xFF; - sp++; - if (len == 0) { - len = src[sp] & 0xFF; - sp++; - switch (len) { - case 0: /* end of line */ - y++; - x = 0; - dp = y * stride; - if (dp > de) - return -1; - break; - case 1: /* end of bitmap */ - return 1; - case 2: /* delta */ - x += src[sp] & 0xFF; - sp++; - y += src[sp] & 0xFF; - sp++; - dp = y * stride + x; - if (dp > de) - return -1; - break; - default: /* absolute mode run */ - if (len > (se - sp)) - return -1; - if (len > (de - dp)) - return -1; - for (int i = 0; i < len; i++) { - dest[dp] = src[sp]; - dp++; - sp++; - } - if ((sp & 1) != 0) - sp++; /* word align sp? */ - x += len; - break; - } - } else { - byte theByte = src[sp]; - sp++; - if (len > (de - dp)) - return -1; - for (int i = 0; i < len; i++) { - dest[dp] = theByte; - dp++; - } - x += len; - } - } - return 1; -} -boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] header = new byte[18]; - stream.read(header); - stream.unread(header); - int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24); - return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize >= BMPHeaderFixedSize; - } catch (Exception e) { - return false; - } -} -byte[] loadData(byte[] infoHeader) { - int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24); - int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24); - int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8); - int stride = (width * bitCount + 7) / 8; - stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple - byte[] data = loadData(infoHeader, stride); - flipScanLines(data, stride, height); - return data; -} -byte[] loadData(byte[] infoHeader, int stride) { - int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24); - if (height < 0) height = -height; - int dataSize = height * stride; - byte[] data = new byte[dataSize]; - int cmp = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24); - if (cmp == 0 || cmp == 3) { // BMP_NO_COMPRESSION - try { - if (inputStream.read(data) != dataSize) - SWT.error(SWT.ERROR_INVALID_IMAGE); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } else { - int compressedSize = (infoHeader[20] & 0xFF) | ((infoHeader[21] & 0xFF) << 8) | ((infoHeader[22] & 0xFF) << 16) | ((infoHeader[23] & 0xFF) << 24); - byte[] compressed = new byte[compressedSize]; - try { - if (inputStream.read(compressed) != compressedSize) - SWT.error(SWT.ERROR_INVALID_IMAGE); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - decompressData(compressed, data, stride, cmp); - } - return data; -} -int[] loadFileHeader() { - int[] header = new int[5]; - try { - header[0] = inputStream.readShort(); - header[1] = inputStream.readInt(); - header[2] = inputStream.readShort(); - header[3] = inputStream.readShort(); - header[4] = inputStream.readInt(); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - if (header[0] != 0x4D42) - SWT.error(SWT.ERROR_INVALID_IMAGE); - return header; -} -ImageData[] loadFromByteStream() { - int[] fileHeader = loadFileHeader(); - byte[] infoHeader = new byte[BMPHeaderFixedSize]; - try { - inputStream.read(infoHeader); - } catch (Exception e) { - SWT.error(SWT.ERROR_IO, e); - } - int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24); - int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24); - if (height < 0) height = -height; - int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8); - this.compression = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24); - PaletteData palette = loadPalette(infoHeader); - if (inputStream.getPosition() < fileHeader[4]) { - // Seek to the specified offset - try { - inputStream.skip(fileHeader[4] - inputStream.getPosition()); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - byte[] data = loadData(infoHeader); - this.importantColors = (infoHeader[36] & 0xFF) | ((infoHeader[37] & 0xFF) << 8) | ((infoHeader[38] & 0xFF) << 16) | ((infoHeader[39] & 0xFF) << 24); - int xPelsPerMeter = (infoHeader[24] & 0xFF) | ((infoHeader[25] & 0xFF) << 8) | ((infoHeader[26] & 0xFF) << 16) | ((infoHeader[27] & 0xFF) << 24); - int yPelsPerMeter = (infoHeader[28] & 0xFF) | ((infoHeader[29] & 0xFF) << 8) | ((infoHeader[30] & 0xFF) << 16) | ((infoHeader[31] & 0xFF) << 24); - this.pelsPerMeter = new Point(xPelsPerMeter, yPelsPerMeter); - int type = (this.compression == 1 /*BMP_RLE8_COMPRESSION*/) || (this.compression == 2 /*BMP_RLE4_COMPRESSION*/) ? SWT.IMAGE_BMP_RLE : SWT.IMAGE_BMP; - return new ImageData[] { - ImageData.internal_new( - width, - height, - bitCount, - palette, - 4, - data, - 0, - null, - null, - -1, - -1, - type, - 0, - 0, - 0, - 0) - }; -} -PaletteData loadPalette(byte[] infoHeader) { - int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8); - if (depth <= 8) { - int numColors = (infoHeader[32] & 0xFF) | ((infoHeader[33] & 0xFF) << 8) | ((infoHeader[34] & 0xFF) << 16) | ((infoHeader[35] & 0xFF) << 24); - if (numColors == 0) { - numColors = 1 << depth; - } else { - if (numColors > 256) - numColors = 256; - } - byte[] buf = new byte[numColors * 4]; - try { - if (inputStream.read(buf) != buf.length) - SWT.error(SWT.ERROR_INVALID_IMAGE); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return paletteFromBytes(buf, numColors); - } - if (depth == 16) { - if (this.compression == 3) { - try { - return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt()); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - return new PaletteData(0x7C00, 0x3E0, 0x1F); - } - if (depth == 24) return new PaletteData(0xFF, 0xFF00, 0xFF0000); - if (this.compression == 3) { - try { - return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt()); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - return new PaletteData(0xFF00, 0xFF0000, 0xFF000000); -} -PaletteData paletteFromBytes(byte[] bytes, int numColors) { - int bytesOffset = 0; - RGB[] colors = new RGB[numColors]; - for (int i = 0; i < numColors; i++) { - colors[i] = new RGB(bytes[bytesOffset + 2] & 0xFF, - bytes[bytesOffset + 1] & 0xFF, - bytes[bytesOffset] & 0xFF); - bytesOffset += 4; - } - return new PaletteData(colors); -} -/** - * Answer a byte array containing the BMP representation of - * the given device independent palette. - */ -static byte[] paletteToBytes(PaletteData pal) { - int n = pal.colors == null ? 0 : (pal.colors.length < 256 ? pal.colors.length : 256); - byte[] bytes = new byte[n * 4]; - int offset = 0; - for (int i = 0; i < n; i++) { - RGB col = pal.colors[i]; - bytes[offset] = (byte)col.blue; - bytes[offset + 1] = (byte)col.green; - bytes[offset + 2] = (byte)col.red; - offset += 4; - } - return bytes; -} -/** - * Unload the given image's data into the given byte stream - * using the given compression strategy. - * Answer the number of bytes written. - */ -int unloadData(ImageData image, OutputStream out, int comp) { - int totalSize = 0; - try { - if (comp == 0) - return unloadDataNoCompression(image, out); - int bpl = (image.width * image.depth + 7) / 8; - int bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes - int imageBpl = image.bytesPerLine; - // Compression can actually take twice as much space, in worst case - byte[] buf = new byte[bmpBpl * 2]; - int srcOffset = imageBpl * (image.height - 1); // Start at last line - byte[] data = image.data; - totalSize = 0; - byte[] buf2 = new byte[32768]; - int buf2Offset = 0; - for (int y = image.height - 1; y >= 0; y--) { - int lineSize = compress(comp, data, srcOffset, bpl, buf, y == 0); - if (buf2Offset + lineSize > buf2.length) { - out.write(buf2, 0, buf2Offset); - buf2Offset = 0; - } - System.arraycopy(buf, 0, buf2, buf2Offset, lineSize); - buf2Offset += lineSize; - totalSize += lineSize; - srcOffset -= imageBpl; - } - if (buf2Offset > 0) - out.write(buf2, 0, buf2Offset); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return totalSize; -} -/** - * Prepare the given image's data for unloading into a byte stream - * using no compression strategy. - * Answer the number of bytes written. - */ -int unloadDataNoCompression(ImageData image, OutputStream out) { - int bmpBpl = 0; - try { - int bpl = (image.width * image.depth + 7) / 8; - bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes - int linesPerBuf = 32678 / bmpBpl; - byte[] buf = new byte[linesPerBuf * bmpBpl]; - byte[] data = image.data; - int imageBpl = image.bytesPerLine; - int dataIndex = imageBpl * (image.height - 1); // Start at last line - if (image.depth == 16) { - for (int y = 0; y < image.height; y += linesPerBuf) { - int count = image.height - y; - if (linesPerBuf < count) count = linesPerBuf; - int bufOffset = 0; - for (int i = 0; i < count; i++) { - for (int wIndex = 0; wIndex < bpl; wIndex += 2) { - buf[bufOffset + wIndex + 1] = data[dataIndex + wIndex + 1]; - buf[bufOffset + wIndex] = data[dataIndex + wIndex]; - } - bufOffset += bmpBpl; - dataIndex -= imageBpl; - } - out.write(buf, 0, bufOffset); - } - } else { - for (int y = 0; y < image.height; y += linesPerBuf) { - int tmp = image.height - y; - int count = tmp < linesPerBuf ? tmp : linesPerBuf; - int bufOffset = 0; - for (int i = 0; i < count; i++) { - System.arraycopy(data, dataIndex, buf, bufOffset, bpl); - bufOffset += bmpBpl; - dataIndex -= imageBpl; - } - out.write(buf, 0, bufOffset); - } - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return bmpBpl * image.height; -} -/** - * Unload a DeviceIndependentImage using Windows .BMP format into the given - * byte stream. - */ -void unloadIntoByteStream(ImageLoader loader) { - ImageData image = loader.data[0]; - byte[] rgbs; - int numCols; - if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8) || - (image.depth == 16) || (image.depth == 24) || (image.depth == 32))) - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - int comp = this.compression; - if (!((comp == 0) || ((comp == 1) && (image.depth == 8)) || - ((comp == 2) && (image.depth == 4)))) - SWT.error(SWT.ERROR_INVALID_IMAGE); - PaletteData pal = image.palette; - if ((image.depth == 16) || (image.depth == 24) || (image.depth == 32)) { - if (!pal.isDirect) - SWT.error(SWT.ERROR_INVALID_IMAGE); - numCols = 0; - rgbs = null; - } else { - if (pal.isDirect) - SWT.error(SWT.ERROR_INVALID_IMAGE); - numCols = pal.colors.length; - rgbs = paletteToBytes(pal); - } - // Fill in file header, except for bfsize, which is done later. - int headersSize = BMPFileHeaderSize + BMPHeaderFixedSize; - int[] fileHeader = new int[5]; - fileHeader[0] = 0x4D42; // Signature - fileHeader[1] = 0; // File size - filled in later - fileHeader[2] = 0; // Reserved 1 - fileHeader[3] = 0; // Reserved 2 - fileHeader[4] = headersSize; // Offset to data - if (rgbs != null) { - fileHeader[4] += rgbs.length; - } - - // Prepare data. This is done first so we don't have to try to rewind - // the stream and fill in the details later. - ByteArrayOutputStream out = new ByteArrayOutputStream(); - unloadData(image, out, comp); - byte[] data = out.toByteArray(); - - // Calculate file size - fileHeader[1] = fileHeader[4] + data.length; - - // Write the headers - try { - outputStream.writeShort(fileHeader[0]); - outputStream.writeInt(fileHeader[1]); - outputStream.writeShort(fileHeader[2]); - outputStream.writeShort(fileHeader[3]); - outputStream.writeInt(fileHeader[4]); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - try { - outputStream.writeInt(BMPHeaderFixedSize); - outputStream.writeInt(image.width); - outputStream.writeInt(image.height); - outputStream.writeShort(1); - outputStream.writeShort((short)image.depth); - outputStream.writeInt(comp); - outputStream.writeInt(data.length); - outputStream.writeInt(pelsPerMeter.x); - outputStream.writeInt(pelsPerMeter.y); - outputStream.writeInt(numCols); - outputStream.writeInt(importantColors); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - - // Unload palette - if (numCols > 0) { - try { - outputStream.write(rgbs); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - } - - // Unload the data - try { - outputStream.write(data); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } -} -void flipScanLines(byte[] data, int stride, int height) { - int i1 = 0; - int i2 = (height - 1) * stride; - for (int i = 0; i < height / 2; i++) { - for (int index = 0; index < stride; index++) { - byte b = data[index + i1]; - data[index + i1] = data[index + i2]; - data[index + i2] = b; - } - i1 += stride; - i2 -= stride; - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java deleted file mode 100755 index 3dbc5f51b3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java +++ /dev/null @@ -1,325 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.internal.image; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import java.io.*; - -public final class WinICOFileFormat extends FileFormat { - -byte[] bitInvertData(byte[] data, int startIndex, int endIndex) { - // Destructively bit invert data in the given byte array. - for (int i = startIndex; i < endIndex; i++) { - data[i] = (byte)(255 - data[i - startIndex]); - } - return data; -} - -static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) { - if (pad == newPad) return data; - int stride = (width * depth + 7) / 8; - int bpl = (stride + (pad - 1)) / pad * pad; - int newBpl = (stride + (newPad - 1)) / newPad * newPad; - byte[] newData = new byte[height * newBpl]; - int srcIndex = 0, destIndex = 0; - for (int y = 0; y < height; y++) { - System.arraycopy(data, srcIndex, newData, destIndex, newBpl); - srcIndex += bpl; - destIndex += newBpl; - } - return newData; -} -/** - * Answer the size in bytes of the file representation of the given - * icon - */ -int iconSize(ImageData i) { - int shapeDataStride = (i.width * i.depth + 31) / 32 * 4; - int maskDataStride = (i.width + 31) / 32 * 4; - int dataSize = (shapeDataStride + maskDataStride) * i.height; - int paletteSize = i.palette.colors != null ? i.palette.colors.length * 4 : 0; - return WinBMPFileFormat.BMPHeaderFixedSize + paletteSize + dataSize; -} -boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] header = new byte[4]; - stream.read(header); - stream.unread(header); - return header[0] == 0 && header[1] == 0 && header[2] == 1 && header[3] == 0; - } catch (Exception e) { - return false; - } -} -boolean isValidIcon(ImageData i) { - switch (i.depth) { - case 1: - case 4: - case 8: - if (i.palette.isDirect) return false; - int size = i.palette.colors.length; - return size == 2 || size == 16 || size == 32 || size == 256; - case 24: - case 32: - return i.palette.isDirect; - } - return false; -} -int loadFileHeader(LEDataInputStream byteStream) { - int[] fileHeader = new int[3]; - try { - fileHeader[0] = byteStream.readShort(); - fileHeader[1] = byteStream.readShort(); - fileHeader[2] = byteStream.readShort(); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - if ((fileHeader[0] != 0) || (fileHeader[1] != 1)) - SWT.error(SWT.ERROR_INVALID_IMAGE); - int numIcons = fileHeader[2]; - if (numIcons <= 0) - SWT.error(SWT.ERROR_INVALID_IMAGE); - return numIcons; -} -int loadFileHeader(LEDataInputStream byteStream, boolean hasHeader) { - int[] fileHeader = new int[3]; - try { - if (hasHeader) { - fileHeader[0] = byteStream.readShort(); - fileHeader[1] = byteStream.readShort(); - } else { - fileHeader[0] = 0; - fileHeader[1] = 1; - } - fileHeader[2] = byteStream.readShort(); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - if ((fileHeader[0] != 0) || (fileHeader[1] != 1)) - SWT.error(SWT.ERROR_INVALID_IMAGE); - int numIcons = fileHeader[2]; - if (numIcons <= 0) - SWT.error(SWT.ERROR_INVALID_IMAGE); - return numIcons; -} -ImageData[] loadFromByteStream() { - int numIcons = loadFileHeader(inputStream); - int[][] headers = loadIconHeaders(numIcons); - ImageData[] icons = new ImageData[headers.length]; - for (int i = 0; i < icons.length; i++) { - icons[i] = loadIcon(headers[i]); - } - return icons; -} -/** - * Load one icon from the byte stream. - */ -ImageData loadIcon(int[] iconHeader) { - byte[] infoHeader = loadInfoHeader(iconHeader); - WinBMPFileFormat bmpFormat = new WinBMPFileFormat(); - bmpFormat.inputStream = inputStream; - PaletteData palette = bmpFormat.loadPalette(infoHeader); - byte[] shapeData = bmpFormat.loadData(infoHeader); - int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24); - int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24); - if (height < 0) height = -height; - int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8); - infoHeader[14] = 1; - infoHeader[15] = 0; - byte[] maskData = bmpFormat.loadData(infoHeader); - maskData = convertPad(maskData, width, height, 1, 4, 2); - bitInvertData(maskData, 0, maskData.length); - return ImageData.internal_new( - width, - height, - depth, - palette, - 4, - shapeData, - 2, - maskData, - null, - -1, - -1, - SWT.IMAGE_ICO, - 0, - 0, - 0, - 0); -} -int[][] loadIconHeaders(int numIcons) { - int[][] headers = new int[numIcons][7]; - try { - for (int i = 0; i < numIcons; i++) { - headers[i][0] = inputStream.read(); - headers[i][1] = inputStream.read(); - headers[i][2] = inputStream.readShort(); - headers[i][3] = inputStream.readShort(); - headers[i][4] = inputStream.readShort(); - headers[i][5] = inputStream.readInt(); - headers[i][6] = inputStream.readInt(); - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - return headers; -} -byte[] loadInfoHeader(int[] iconHeader) { - int width = iconHeader[0]; - int height = iconHeader[1]; - int numColors = iconHeader[2]; // the number of colors is in the low byte, but the high byte must be 0 - if (numColors == 0) numColors = 256; // this is specified: '00' represents '256' (0x100) colors - if ((numColors != 2) && (numColors != 8) && (numColors != 16) && - (numColors != 32) && (numColors != 256)) - SWT.error(SWT.ERROR_INVALID_IMAGE); - if (inputStream.getPosition() < iconHeader[6]) { - // Seek to the specified offset - try { - inputStream.skip(iconHeader[6] - inputStream.getPosition()); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - return null; - } - } - byte[] infoHeader = new byte[WinBMPFileFormat.BMPHeaderFixedSize]; - try { - inputStream.read(infoHeader); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - if (((infoHeader[12] & 0xFF) | ((infoHeader[13] & 0xFF) << 8)) != 1) - SWT.error(SWT.ERROR_INVALID_IMAGE); - int infoWidth = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24); - int infoHeight = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24); - int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8); - if (height == infoHeight && bitCount == 1) height /= 2; - if (!((width == infoWidth) && (height * 2 == infoHeight) && - (bitCount == 1 || bitCount == 4 || bitCount == 8 || bitCount == 24 || bitCount == 32))) - SWT.error(SWT.ERROR_INVALID_IMAGE); - infoHeader[8] = (byte)(height & 0xFF); - infoHeader[9] = (byte)((height >> 8) & 0xFF); - infoHeader[10] = (byte)((height >> 16) & 0xFF); - infoHeader[11] = (byte)((height >> 24) & 0xFF); - return infoHeader; -} -/** - * Unload a single icon - */ -void unloadIcon(ImageData icon) { - int sizeImage = (((icon.width * icon.depth + 31) / 32 * 4) + - ((icon.width + 31) / 32 * 4)) * icon.height; - try { - outputStream.writeInt(WinBMPFileFormat.BMPHeaderFixedSize); - outputStream.writeInt(icon.width); - outputStream.writeInt(icon.height * 2); - outputStream.writeShort(1); - outputStream.writeShort((short)icon.depth); - outputStream.writeInt(0); - outputStream.writeInt(sizeImage); - outputStream.writeInt(0); - outputStream.writeInt(0); - outputStream.writeInt(icon.palette.colors != null ? icon.palette.colors.length : 0); - outputStream.writeInt(0); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - - byte[] rgbs = WinBMPFileFormat.paletteToBytes(icon.palette); - try { - outputStream.write(rgbs); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - unloadShapeData(icon); - unloadMaskData(icon); -} -/** - * Unload the icon header for the given icon, calculating the offset. - */ -void unloadIconHeader(ImageData i) { - int headerSize = 16; - int offset = headerSize + 6; - int iconSize = iconSize(i); - try { - outputStream.write(i.width); - outputStream.write(i.height); - outputStream.writeShort(i.palette.colors != null ? i.palette.colors.length : 0); - outputStream.writeShort(0); - outputStream.writeShort(0); - outputStream.writeInt(iconSize); - outputStream.writeInt(offset); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } -} -void unloadIntoByteStream(ImageLoader loader) { - /* We do not currently support writing multi-image ico, - * so we use the first image data in the loader's array. */ - ImageData image = loader.data[0]; - if (!isValidIcon(image)) - SWT.error(SWT.ERROR_INVALID_IMAGE); - try { - outputStream.writeShort(0); - outputStream.writeShort(1); - outputStream.writeShort(1); - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } - unloadIconHeader(image); - unloadIcon(image); -} -/** - * Unload the mask data for an icon. The data is flipped vertically - * and inverted. - */ -void unloadMaskData(ImageData icon) { - ImageData mask = icon.getTransparencyMask(); - int bpl = (icon.width + 7) / 8; - int pad = mask.scanlinePad; - int srcBpl = (bpl + pad - 1) / pad * pad; - int destBpl = (bpl + 3) / 4 * 4; - byte[] buf = new byte[destBpl]; - int offset = (icon.height - 1) * srcBpl; - byte[] data = mask.data; - try { - for (int i = 0; i < icon.height; i++) { - System.arraycopy(data, offset, buf, 0, bpl); - bitInvertData(buf, 0, bpl); - outputStream.write(buf, 0, destBpl); - offset -= srcBpl; - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } -} -/** - * Unload the shape data for an icon. The data is flipped vertically. - */ -void unloadShapeData(ImageData icon) { - int bpl = (icon.width * icon.depth + 7) / 8; - int pad = icon.scanlinePad; - int srcBpl = (bpl + pad - 1) / pad * pad; - int destBpl = (bpl + 3) / 4 * 4; - byte[] buf = new byte[destBpl]; - int offset = (icon.height - 1) * srcBpl; - byte[] data = icon.data; - try { - for (int i = 0; i < icon.height; i++) { - System.arraycopy(data, offset, buf, 0, bpl); - outputStream.write(buf, 0, destBpl); - offset -= srcBpl; - } - } catch (IOException e) { - SWT.error(SWT.ERROR_IO, e); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html deleted file mode 100755 index ab7efd4a18..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html +++ /dev/null @@ -1,19 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -SWT internal image loading/saving support classes. -<h2> -Package Specification</h2> -This package contains the classes used by SWT to load and save images -in the various formats we support, including GIF, JPEG, PNG, BMP, and ICO. -<p> -Applications should not need to reference the classes in this package -directly. -</p> -</body> -</html> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html deleted file mode 100755 index d1b671ef87..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html +++ /dev/null @@ -1,21 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -SWT internal classes -<h2> -Package Specification</h2> -This package provides the <code>Callback</code> class which is used to -map the operating system's callback mechanism to Java message sends, and -the <code>Converter</code> class which provides translation between Unicode -and platform specific character sets. -<p> -Applications should not need to reference the classes in this package -directly. -</p> -</body> -</html> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java deleted file mode 100644 index ef9de8ac9d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -class FillData { - - int defaultWidth = -1, defaultHeight = -1; - int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1; - -Point computeSize (Control control, int wHint, int hHint, boolean flushCache) { - if (flushCache) flushCache(); - if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) { - if (defaultWidth == -1 || defaultHeight == -1) { - Point size = control.computeSize (wHint, hHint, flushCache); - defaultWidth = size.x; - defaultHeight = size.y; - } - return new Point(defaultWidth, defaultHeight); - } - if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); - currentWhint = wHint; - currentHhint = hHint; - currentWidth = size.x; - currentHeight = size.y; - } - return new Point(currentWidth, currentHeight); -} -void flushCache () { - defaultWidth = defaultHeight = -1; - currentWidth = currentHeight = -1; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java deleted file mode 100755 index b2354723d3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * <code>FillLayout</code> is the simplest layout class. It lays out - * controls in a single row or column, forcing them to be the same size. - * <p> - * Initially, the controls will all be as tall as the tallest control, - * and as wide as the widest. <code>FillLayout</code> does not wrap, - * but you can specify margins and spacing. You might use it to - * lay out buttons in a task bar or tool bar, or to stack checkboxes - * in a <code>Group</code>. <code>FillLayout</code> can also be used - * when a <code>Composite</code> only has one child. For example, - * if a <code>Shell</code> has a single <code>Group</code> child, - * <code>FillLayout</code> will cause the <code>Group</code> to - * completely fill the <code>Shell</code> (if margins are 0). - * </p> - * <p> - * Example code: first a <code>FillLayout</code> is created and - * its type field is set, and then the layout is set into the - * <code>Composite</code>. Note that in a <code>FillLayout</code>, - * children are always the same size, and they fill all available space. - * <pre> - * FillLayout fillLayout = new FillLayout(); - * fillLayout.type = SWT.VERTICAL; - * shell.setLayout(fillLayout); - * </pre> - * </p> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class FillLayout extends Layout { - /** - * type specifies how controls will be positioned - * within the layout. - * - * The default value is HORIZONTAL. - * - * Possible values are: <ul> - * <li>HORIZONTAL: Position the controls horizontally from left to right</li> - * <li>VERTICAL: Position the controls vertically from top to bottom</li> - * </ul> - */ - public int type = SWT.HORIZONTAL; - - /** - * marginWidth specifies the number of pixels of horizontal margin - * that will be placed along the left and right edges of the layout. - * - * The default value is 0. - * - * @since 3.0 - */ - public int marginWidth = 0; - - /** - * marginHeight specifies the number of pixels of vertical margin - * that will be placed along the top and bottom edges of the layout. - * - * The default value is 0. - * - * @since 3.0 - */ - public int marginHeight = 0; - - /** - * spacing specifies the number of pixels between the edge of one cell - * and the edge of its neighbouring cell. - * - * The default value is 0. - * - * @since 3.0 - */ - public int spacing = 0; - -/** - * Constructs a new instance of this class. - */ -public FillLayout () { -} - -/** - * Constructs a new instance of this class given the type. - * - * @param type the type of fill layout - * - * @since 2.0 - */ -public FillLayout (int type) { - this.type = type; -} - -protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { - Control [] children = composite.getChildren (); - int count = children.length; - int maxWidth = 0, maxHeight = 0; - for (int i=0; i<count; i++) { - Control child = children [i]; - int w = wHint, h = hHint; - if (count > 0) { - if (type == SWT.HORIZONTAL && wHint != SWT.DEFAULT) { - w = Math.max (0, (wHint - (count - 1) * spacing) / count); - } - if (type == SWT.VERTICAL && hHint != SWT.DEFAULT) { - h = Math.max (0, (hHint - (count - 1) * spacing) / count); - } - } - Point size = computeChildSize (child, w, h, flushCache); - maxWidth = Math.max (maxWidth, size.x); - maxHeight = Math.max (maxHeight, size.y); - } - int width = 0, height = 0; - if (type == SWT.HORIZONTAL) { - width = count * maxWidth; - if (count != 0) width += (count - 1) * spacing; - height = maxHeight; - } else { - width = maxWidth; - height = count * maxHeight; - if (count != 0) height += (count - 1) * spacing; - } - width += marginWidth * 2; - height += marginHeight * 2; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - return new Point (width, height); -} - -Point computeChildSize (Control control, int wHint, int hHint, boolean flushCache) { - FillData data = (FillData)control.getLayoutData (); - if (data == null) { - data = new FillData (); - control.setLayoutData (data); - } - Point size = null; - if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) { - size = data.computeSize (control, wHint, hHint, flushCache); - } else { - // TEMPORARY CODE - int trimX, trimY; - if (control instanceof Scrollable) { - Rectangle rect = ((Scrollable) control).computeTrim (0, 0, 0, 0); - trimX = rect.width; - trimY = rect.height; - } else { - trimX = trimY = control.getBorderWidth () * 2; - } - int w = wHint == SWT.DEFAULT ? wHint : Math.max (0, wHint - trimX); - int h = hHint == SWT.DEFAULT ? hHint : Math.max (0, hHint - trimY); - size = data.computeSize (control, w, h, flushCache); - } - return size; -} - -protected boolean flushCache (Control control) { - Object data = control.getLayoutData(); - if (data != null) ((FillData)data).flushCache(); - return true; -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -protected void layout (Composite composite, boolean flushCache) { - Rectangle rect = composite.getClientArea (); - Control [] children = composite.getChildren (); - int count = children.length; - if (count == 0) return; - int width = rect.width - marginWidth * 2; - int height = rect.height - marginHeight * 2; - if (type == SWT.HORIZONTAL) { - width -= (count - 1) * spacing; - int x = rect.x + marginWidth, extra = width % count; - int y = rect.y + marginHeight, cellWidth = width / count; - for (int i=0; i<count; i++) { - Control child = children [i]; - int childWidth = cellWidth; - if (i == 0) { - childWidth += extra / 2; - } else { - if (i == count - 1) childWidth += (extra + 1) / 2; - } - child.setBounds (x, y, childWidth, height); - x += childWidth + spacing; - } - } else { - height -= (count - 1) * spacing; - int x = rect.x + marginWidth, cellHeight = height / count; - int y = rect.y + marginHeight, extra = height % count; - for (int i=0; i<count; i++) { - Control child = children [i]; - int childHeight = cellHeight; - if (i == 0) { - childHeight += extra / 2; - } else { - if (i == count - 1) childHeight += (extra + 1) / 2; - } - child.setBounds (x, y, width, childHeight); - y += childHeight + spacing; - } - } -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the layout - */ -public String toString () { - String string = getName ()+" {"; - string += "type="+((type == SWT.VERTICAL) ? "SWT.VERTICAL" : "SWT.HORIZONTAL")+" "; - if (marginWidth != 0) string += "marginWidth="+marginWidth+" "; - if (marginHeight != 0) string += "marginHeight="+marginHeight+" "; - if (spacing != 0) string += "spacing="+spacing+" "; - string = string.trim(); - string += "}"; - return string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java deleted file mode 100644 index d426a8a43e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java +++ /dev/null @@ -1,316 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class are used to define the edges of a control - * within a <code>FormLayout</code>. - * <p> - * <code>FormAttachments</code> are set into the top, bottom, left, - * and right fields of the <code>FormData</code> for a control. - * For example: - * <pre> - * FormData data = new FormData(); - * data.top = new FormAttachment(0,5); - * data.bottom = new FormAttachment(100,-5); - * data.left = new FormAttachment(0,5); - * data.right = new FormAttachment(100,-5); - * button.setLayoutData(data); - * </pre> - * </p> - * <p> - * A <code>FormAttachment</code> defines where to attach the side of - * a control by using the equation, y = ax + b. The "a" term represents - * a fraction of the parent composite's width (from the left) or height - * (from the top). It can be defined using a numerator and denominator, - * or just a percentage value. If a percentage is used, the denominator - * is set to 100. The "b" term in the equation represents an offset, in - * pixels, from the attachment position. For example: - * <pre> - * FormAttachment attach = new FormAttachment (20, -5); - * </pre> - * specifies that the side to which the <code>FormAttachment</code> - * object belongs will lie at 20% of the parent composite, minus 5 pixels. - * </p> - * <p> - * Control sides can also be attached to another control. - * For example: - * <pre> - * FormAttachment attach = new FormAttachment (button, 10); - * </pre> - * specifies that the side to which the <code>FormAttachment</code> - * object belongs will lie in the same position as the adjacent side of - * the <code>button</code> control, plus 10 pixels. The control side can - * also be attached to the opposite side of the specified control. - * For example: - * <pre> - * FormData data = new FormData (); - * data.left = new FormAttachment (button, 0, SWT.LEFT); - * </pre> - * specifies that the left side of the control will lie in the same position - * as the left side of the <code>button</code> control. The control can also - * be attached in a position that will center the control on the specified - * control. For example: - * <pre> - * data.left = new FormAttachment (button, 0, SWT.CENTER); - * </pre> - * specifies that the left side of the control will be positioned so that it is - * centered between the left and right sides of the <code>button</code> control. - * If the alignment is not specified, the default is to attach to the adjacent side. - * </p> - * - * @see FormLayout - * @see FormData - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 2.0 - */ -public final class FormAttachment { - /** - * numerator specifies the numerator of the "a" term in the - * equation, y = ax + b, which defines the attachment. - */ - public int numerator; - - /** - * denominator specifies the denominator of the "a" term in the - * equation, y = ax + b, which defines the attachment. - * - * The default value is 100. - */ - public int denominator = 100; - - /** - * offset specifies the offset, in pixels, of the control side - * from the attachment position. - * If the offset is positive, then the control side is offset - * to the right of or below the attachment position. If it is - * negative, then the control side is offset to the left of or - * above the attachment position. - * - * This is equivalent to the "b" term in the equation y = ax + b. - * The default value is 0. - */ - public int offset; - - /** - * control specifies the control to which the control side is - * attached. - */ - public Control control; - - /** - * alignment specifies the alignment of the control side that is - * attached to a control. - * <p> - * For top and bottom attachments, TOP, BOTTOM and CENTER are used. For left - * and right attachments, LEFT, RIGHT and CENTER are used. If any other case - * occurs, the default will be used instead. - * </p> - * - * <br>Possible values are: <ul> - * <li>{@link SWT#TOP}: Attach the side to the top side of the specified control.</li> - * <li>{@link SWT#BOTTOM}: Attach the side to the bottom side of the specified control.</li> - * <li>{@link SWT#LEFT}: Attach the side to the left side of the specified control.</li> - * <li>{@link SWT#RIGHT}: Attach the side to the right side of the specified control.</li> - * <li>{@link SWT#CENTER}: Attach the side at a position which will center the control on the specified control.</li> - * <li>{@link SWT#DEFAULT}: Attach the side to the adjacent side of the specified control.</li> - * </ul> - */ - public int alignment; - -/** - * Constructs a new instance of this class. - * Since no numerator, denominator or offset is specified, - * the attachment is treated as a percentage of the form. - * The numerator is zero, the denominator is 100 and the - * offset is zero. - * - * @since 3.2 - */ -public FormAttachment () { -} - -/** - * Constructs a new instance of this class given a numerator - * Since no denominator or offset is specified, the default - * is to treat the numerator as a percentage of the form, with a - * denominator of 100. The offset is zero. - * - * @param numerator the percentage of the position - * - * @since 3.0 - */ -public FormAttachment (int numerator) { - this (numerator, 100, 0); -} - -/** - * Constructs a new instance of this class given a numerator - * and an offset. Since no denominator is specified, the default - * is to treat the numerator as a percentage of the form, with a - * denominator of 100. - * - * @param numerator the percentage of the position - * @param offset the offset of the side from the position - */ -public FormAttachment (int numerator, int offset) { - this (numerator, 100, offset); -} - -/** - * Constructs a new instance of this class given a numerator - * and denominator and an offset. The position of the side is - * given by the fraction of the form defined by the numerator - * and denominator. - * - * @param numerator the numerator of the position - * @param denominator the denominator of the position - * @param offset the offset of the side from the position - */ -public FormAttachment (int numerator, int denominator, int offset) { - if (denominator == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO); - this.numerator = numerator; - this.denominator = denominator; - this.offset = offset; -} - -/** - * Constructs a new instance of this class given a control. - * Since no alignment is specified, the default alignment is - * to attach the side to the adjacent side of the specified - * control. Since no offset is specified, an offset of 0 is - * used. - * - * @param control the control the side is attached to - */ -public FormAttachment (Control control) { - this (control, 0, SWT.DEFAULT); -} - -/** - * Constructs a new instance of this class given a control - * and an offset. Since no alignment is specified, the default - * alignment is to attach the side to the adjacent side of the - * specified control. - * - * @param control the control the side is attached to - * @param offset the offset of the side from the control - */ -public FormAttachment (Control control, int offset) { - this (control, offset, SWT.DEFAULT); -} - -/** - * Constructs a new instance of this class given a control, - * an offset and an alignment. The possible alignment values are: - * <dl> - * <dt><b>{@link SWT#TOP}</b></dt> - * <dd>the side will be attached to the top side of the specified control</dd> - * <dt><b>{@link SWT#BOTTOM}</b></dt> - * <dd>the side will be attached to the bottom side of the specified control</dd> - * <dt><b>{@link SWT#LEFT}</b></dt> - * <dd>the side will be attached to the left side of the specified control</dd> - * <dt><b>{@link SWT#RIGHT}</b></dt> - * <dd>the side will be attached to the right side of the specified control</dd> - * <dt><b>{@link SWT#CENTER}</b></dt> - * <dd>the side will be centered on the same side of the specified control</dd> - * <dt><b>{@link SWT#DEFAULT}</b></dt> - * <dd>the side will be attached to the adjacent side of the specified control</dd> - * </dl> - * - * @param control the control the side is attached to - * @param offset the offset of the side from the control - * @param alignment the alignment of the side to the control it is attached to, - * one of TOP, BOTTOM, LEFT, RIGHT, CENTER, or DEFAULT - */ -public FormAttachment (Control control, int offset, int alignment) { - this.control = control; - this.offset = offset; - this.alignment = alignment; -} - -FormAttachment divide (int value) { - return new FormAttachment (numerator, denominator * value, offset / value); -} - -int gcd (int m, int n) { - int temp; - m = Math.abs (m); - n = Math.abs (n); - if (m < n) { - temp = m; - m = n; - n = temp; - } - while (n != 0){ - temp = m; - m = n; - n = temp % n; - } - return m; -} - -FormAttachment minus (FormAttachment attachment) { - FormAttachment solution = new FormAttachment (); - solution.numerator = numerator * attachment.denominator - denominator * attachment.numerator; - solution.denominator = denominator * attachment.denominator; - int gcd = gcd (solution.denominator, solution.numerator); - solution.numerator = solution.numerator / gcd; - solution.denominator = solution.denominator / gcd; - solution.offset = offset - attachment.offset; - return solution; -} - -FormAttachment minus (int value) { - return new FormAttachment (numerator, denominator, offset - value); -} - -FormAttachment plus (FormAttachment attachment) { - FormAttachment solution = new FormAttachment (); - solution.numerator = numerator * attachment.denominator + denominator * attachment.numerator; - solution.denominator = denominator * attachment.denominator; - int gcd = gcd (solution.denominator, solution.numerator); - solution.numerator = solution.numerator / gcd; - solution.denominator = solution.denominator / gcd; - solution.offset = offset + attachment.offset; - return solution; -} - -FormAttachment plus (int value) { - return new FormAttachment (numerator, denominator, offset + value); -} - -int solveX (int value) { - if (denominator == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO); - return ((numerator * value) / denominator) + offset; -} - -int solveY (int value) { - if (numerator == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO); - return (value - offset) * denominator / numerator; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the FormAttachment - */ -public String toString () { - String string = control != null ? control.toString () : numerator + "/" + denominator; - return "{y = (" + string + (offset >= 0 ? ")x + " + offset: ")x - " + (-offset))+"}"; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java deleted file mode 100644 index cd6939d093..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class are used to define the attachments - * of a control in a <code>FormLayout</code>. - * <p> - * To set a <code>FormData</code> object into a control, you use the - * <code>setLayoutData ()</code> method. To define attachments for the - * <code>FormData</code>, set the fields directly, like this: - * <pre> - * FormData data = new FormData(); - * data.left = new FormAttachment(0,5); - * data.right = new FormAttachment(100,-5); - * button.setLayoutData(formData); - * </pre> - * </p> - * <p> - * <code>FormData</code> contains the <code>FormAttachments</code> for - * each edge of the control that the <code>FormLayout</code> uses to - * determine the size and position of the control. <code>FormData</code> - * objects also allow you to set the width and height of controls within - * a <code>FormLayout</code>. - * </p> - * - * @see FormLayout - * @see FormAttachment - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 2.0 - */ -public final class FormData { - /** - * width specifies the preferred width in pixels. This value - * is the wHint passed into Control.computeSize(int, int, boolean) - * to determine the preferred size of the control. - * - * The default value is SWT.DEFAULT. - * - * @see Control#computeSize(int, int, boolean) - */ - public int width = SWT.DEFAULT; - /** - * height specifies the preferred height in pixels. This value - * is the hHint passed into Control.computeSize(int, int, boolean) - * to determine the preferred size of the control. - * - * The default value is SWT.DEFAULT. - * - * @see Control#computeSize(int, int, boolean) - */ - public int height = SWT.DEFAULT; - /** - * left specifies the attachment of the left side of - * the control. - */ - public FormAttachment left; - /** - * right specifies the attachment of the right side of - * the control. - */ - public FormAttachment right; - /** - * top specifies the attachment of the top of the control. - */ - public FormAttachment top; - /** - * bottom specifies the attachment of the bottom of the - * control. - */ - public FormAttachment bottom; - - int cacheWidth = -1, cacheHeight = -1; - int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1; - int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1; - FormAttachment cacheLeft, cacheRight, cacheTop, cacheBottom; - boolean isVisited, needed; - -/** - * Constructs a new instance of FormData using - * default values. - */ -public FormData () { -} - -/** - * Constructs a new instance of FormData according to the parameters. - * A value of SWT.DEFAULT indicates that no minimum width or - * no minimum height is specified. - * - * @param width a minimum width for the control - * @param height a minimum height for the control - */ -public FormData (int width, int height) { - this.width = width; - this.height = height; -} - -void computeSize (Control control, int wHint, int hHint, boolean flushCache) { - if (cacheWidth != -1 && cacheHeight != -1) return; - if (wHint == this.width && hHint == this.height) { - if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); - defaultWhint = wHint; - defaultHhint = hHint; - defaultWidth = size.x; - defaultHeight = size.y; - } - cacheWidth = defaultWidth; - cacheHeight = defaultHeight; - return; - } - if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); - currentWhint = wHint; - currentHhint = hHint; - currentWidth = size.x; - currentHeight = size.y; - } - cacheWidth = currentWidth; - cacheHeight = currentHeight; -} - -void flushCache () { - cacheWidth = cacheHeight = -1; - defaultHeight = defaultWidth = -1; - currentHeight = currentWidth = -1; -} - -int getWidth (Control control, boolean flushCache) { - needed = true; - computeSize (control, width, height, flushCache); - return cacheWidth; -} - -int getHeight (Control control, boolean flushCache) { - computeSize (control, width, height, flushCache); - return cacheHeight; -} - -FormAttachment getBottomAttachment (Control control, int spacing, boolean flushCache) { - if (cacheBottom != null) return cacheBottom; - if (isVisited) return cacheBottom = new FormAttachment (0, getHeight (control, flushCache)); - if (bottom == null) { - if (top == null) return cacheBottom = new FormAttachment (0, getHeight (control, flushCache)); - return cacheBottom = getTopAttachment (control, spacing, flushCache).plus (getHeight (control, flushCache)); - } - Control bottomControl = bottom.control; - if (bottomControl != null) { - if (bottomControl.isDisposed ()) { - bottom.control = bottomControl = null; - } else { - if (bottomControl.getParent () != control.getParent ()) { - bottomControl = null; - } - } - } - if (bottomControl == null) return cacheBottom = bottom; - isVisited = true; - FormData bottomData = (FormData) bottomControl.getLayoutData (); - FormAttachment bottomAttachment = bottomData.getBottomAttachment (bottomControl, spacing, flushCache); - switch (bottom.alignment) { - case SWT.BOTTOM: - cacheBottom = bottomAttachment.plus (bottom.offset); - break; - case SWT.CENTER: { - FormAttachment topAttachment = bottomData.getTopAttachment (bottomControl, spacing, flushCache); - FormAttachment bottomHeight = bottomAttachment.minus (topAttachment); - cacheBottom = bottomAttachment.minus (bottomHeight.minus (getHeight (control, flushCache)).divide (2)); - break; - } - default: { - FormAttachment topAttachment = bottomData.getTopAttachment (bottomControl, spacing, flushCache); - cacheBottom = topAttachment.plus (bottom.offset - spacing); - break; - } - } - isVisited = false; - return cacheBottom; -} - -FormAttachment getLeftAttachment (Control control, int spacing, boolean flushCache) { - if (cacheLeft != null) return cacheLeft; - if (isVisited) return cacheLeft = new FormAttachment (0, 0); - if (left == null) { - if (right == null) return cacheLeft = new FormAttachment (0, 0); - return cacheLeft = getRightAttachment (control, spacing, flushCache).minus (getWidth (control, flushCache)); - } - Control leftControl = left.control; - if (leftControl != null) { - if (leftControl.isDisposed ()) { - left.control = leftControl = null; - } else { - if (leftControl.getParent () != control.getParent ()) { - leftControl = null; - } - } - } - if (leftControl == null) return cacheLeft = left; - isVisited = true; - FormData leftData = (FormData) leftControl.getLayoutData (); - FormAttachment leftAttachment = leftData.getLeftAttachment (leftControl, spacing, flushCache); - switch (left.alignment) { - case SWT.LEFT: - cacheLeft = leftAttachment.plus (left.offset); - break; - case SWT.CENTER: { - FormAttachment rightAttachment = leftData.getRightAttachment (leftControl, spacing, flushCache); - FormAttachment leftWidth = rightAttachment.minus (leftAttachment); - cacheLeft = leftAttachment.plus (leftWidth.minus (getWidth (control, flushCache)).divide (2)); - break; - } - default: { - FormAttachment rightAttachment = leftData.getRightAttachment (leftControl, spacing, flushCache); - cacheLeft = rightAttachment.plus (left.offset + spacing); - } - } - isVisited = false; - return cacheLeft; -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -FormAttachment getRightAttachment (Control control, int spacing, boolean flushCache) { - if (cacheRight != null) return cacheRight; - if (isVisited) return cacheRight = new FormAttachment (0, getWidth (control, flushCache)); - if (right == null) { - if (left == null) return cacheRight = new FormAttachment (0, getWidth (control, flushCache)); - return cacheRight = getLeftAttachment (control, spacing, flushCache).plus (getWidth (control, flushCache)); - } - Control rightControl = right.control; - if (rightControl != null) { - if (rightControl.isDisposed ()) { - right.control = rightControl = null; - } else { - if (rightControl.getParent () != control.getParent ()) { - rightControl = null; - } - } - } - if (rightControl == null) return cacheRight = right; - isVisited = true; - FormData rightData = (FormData) rightControl.getLayoutData (); - FormAttachment rightAttachment = rightData.getRightAttachment (rightControl, spacing, flushCache); - switch (right.alignment) { - case SWT.RIGHT: - cacheRight = rightAttachment.plus (right.offset); - break; - case SWT.CENTER: { - FormAttachment leftAttachment = rightData.getLeftAttachment (rightControl, spacing, flushCache); - FormAttachment rightWidth = rightAttachment.minus (leftAttachment); - cacheRight = rightAttachment.minus (rightWidth.minus (getWidth (control, flushCache)).divide (2)); - break; - } - default: { - FormAttachment leftAttachment = rightData.getLeftAttachment (rightControl, spacing, flushCache); - cacheRight = leftAttachment.plus (right.offset - spacing); - break; - } - } - isVisited = false; - return cacheRight; -} - -FormAttachment getTopAttachment (Control control, int spacing, boolean flushCache) { - if (cacheTop != null) return cacheTop; - if (isVisited) return cacheTop = new FormAttachment (0, 0); - if (top == null) { - if (bottom == null) return cacheTop = new FormAttachment (0, 0); - return cacheTop = getBottomAttachment (control, spacing, flushCache).minus (getHeight (control, flushCache)); - } - Control topControl = top.control; - if (topControl != null) { - if (topControl.isDisposed ()) { - top.control = topControl = null; - } else { - if (topControl.getParent () != control.getParent ()) { - topControl = null; - } - } - } - if (topControl == null) return cacheTop = top; - isVisited = true; - FormData topData = (FormData) topControl.getLayoutData (); - FormAttachment topAttachment = topData.getTopAttachment (topControl, spacing, flushCache); - switch (top.alignment) { - case SWT.TOP: - cacheTop = topAttachment.plus (top.offset); - break; - case SWT.CENTER: { - FormAttachment bottomAttachment = topData.getBottomAttachment (topControl, spacing, flushCache); - FormAttachment topHeight = bottomAttachment.minus (topAttachment); - cacheTop = topAttachment.plus (topHeight.minus (getHeight (control, flushCache)).divide (2)); - break; - } - default: { - FormAttachment bottomAttachment = topData.getBottomAttachment (topControl, spacing, flushCache); - cacheTop = bottomAttachment.plus (top.offset + spacing); - break; - } - } - isVisited = false; - return cacheTop; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the FormData object - */ -public String toString () { - String string = getName()+" {"; - if (width != SWT.DEFAULT) string += "width="+width+" "; - if (height != SWT.DEFAULT) string += "height="+height+" "; - if (left != null) string += "left="+left+" "; - if (right != null) string += "right="+right+" "; - if (top != null) string += "top="+top+" "; - if (bottom != null) string += "bottom="+bottom+" "; - string = string.trim(); - string += "}"; - return string; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java deleted file mode 100644 index 8661996568..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java +++ /dev/null @@ -1,385 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class control the position and size of the - * children of a composite control by using <code>FormAttachments</code> - * to optionally configure the left, top, right and bottom edges of - * each child. - * <p> - * The following example code creates a <code>FormLayout</code> and then sets - * it into a <code>Shell</code>: - * <pre> - * Display display = new Display (); - * Shell shell = new Shell(display); - * FormLayout layout = new FormLayout(); - * layout.marginWidth = 3; - * layout.marginHeight = 3; - * shell.setLayout(layout); - * </pre> - * </p> - * <p> - * To use a <code>FormLayout</code>, create a <code>FormData</code> with - * <code>FormAttachment</code> for each child of <code>Composite</code>. - * The following example code attaches <code>button1</code> to the top - * and left edge of the composite and <code>button2</code> to the right - * edge of <code>button1</code> and the top and right edges of the - * composite: - * <pre> - * FormData data1 = new FormData(); - * data1.left = new FormAttachment(0, 0); - * data1.top = new FormAttachment(0, 0); - * button1.setLayoutData(data1); - * FormData data2 = new FormData(); - * data2.left = new FormAttachment(button1); - * data2.top = new FormAttachment(0, 0); - * data2.right = new FormAttachment(100, 0); - * button2.setLayoutData(data2); - * </pre> - * </p> - * <p> - * Each side of a child control can be attached to a position in the parent - * composite, or to other controls within the <code>Composite</code> by - * creating instances of <code>FormAttachment</code> and setting them into - * the top, bottom, left, and right fields of the child's <code>FormData</code>. - * </p> - * <p> - * If a side is not given an attachment, it is defined as not being attached - * to anything, causing the child to remain at its preferred size. If a child - * is given no attachment on either the left or the right or top or bottom, it is - * automatically attached to the left and top of the composite respectively. - * The following code positions <code>button1</code> and <code>button2</code> - * but relies on default attachments: - * <pre> - * FormData data2 = new FormData(); - * data2.left = new FormAttachment(button1); - * data2.right = new FormAttachment(100, 0); - * button2.setLayoutData(data2); - * </pre> - * </p> - * <p> - * IMPORTANT: Do not define circular attachments. For example, do not attach - * the right edge of <code>button1</code> to the left edge of <code>button2</code> - * and then attach the left edge of <code>button2</code> to the right edge of - * <code>button1</code>. This will over constrain the layout, causing undefined - * behavior. The algorithm will terminate, but the results are undefined. - * </p> - * - * @see FormData - * @see FormAttachment - * @see <a href="http://www.eclipse.org/swt/snippets/#formlayout">FormLayout snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 2.0 - */ -public final class FormLayout extends Layout { - - /** - * marginWidth specifies the number of pixels of horizontal margin - * that will be placed along the left and right edges of the layout. - * - * The default value is 0. - */ - public int marginWidth = 0; - - /** - * marginHeight specifies the number of pixels of vertical margin - * that will be placed along the top and bottom edges of the layout. - * - * The default value is 0. - */ - public int marginHeight = 0; - - - /** - * marginLeft specifies the number of pixels of horizontal margin - * that will be placed along the left edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginLeft = 0; - - /** - * marginTop specifies the number of pixels of vertical margin - * that will be placed along the top edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginTop = 0; - - /** - * marginRight specifies the number of pixels of horizontal margin - * that will be placed along the right edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginRight = 0; - - /** - * marginBottom specifies the number of pixels of vertical margin - * that will be placed along the bottom edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginBottom = 0; - - /** - * spacing specifies the number of pixels between the edge of one control - * and the edge of its neighbouring control. - * - * The default value is 0. - * - * @since 3.0 - */ - public int spacing = 0; - -/** - * Constructs a new instance of this class. - */ -public FormLayout () { -} - -/* - * Computes the preferred height of the form with - * respect to the preferred height of the control. - * - * Given that the equations for top (T) and bottom (B) - * of the control in terms of the height of the form (X) - * are: - * T = AX + B - * B = CX + D - * - * The equation for the height of the control (H) - * is bottom (B) minus top (T) or (H = B - T) or: - * - * H = (CX + D) - (AX + B) - * - * Solving for (X), the height of the form, we get: - * - * X = (H + B - D) / (C - A) - * - * When (A = C), (C - A = 0) and the equation has no - * solution for X. This is a special case meaning that - * the control does not constrain the height of the - * form. In this case, we need to arbitrarily define - * the height of the form (X): - * - * Case 1: A = C, A = 0, C = 0 - * - * Let X = D, the distance from the top of the form - * to the bottom edge of the control. In this case, - * the control was attached to the top of the form - * and the form needs to be large enough to show the - * bottom edge of the control. - * - * Case 2: A = C, A = 1, C = 1 - * - * Let X = -B, the distance from the bottom of the - * form to the top edge of the control. In this case, - * the control was attached to the bottom of the form - * and the only way that the control would be visible - * is if the offset is negative. If the offset is - * positive, there is no possible height for the form - * that will show the control as it will always be - * below the bottom edge of the form. - * - * Case 3: A = C, A != 0, C != 0 and A != 1, C != 0 - * - * Let X = D / (1 - C), the distance from the top of the - * form to the bottom edge of the control. In this case, - * since C is not 0 or 1, it must be a fraction, U / V. - * The offset D is the distance from CX to the bottom edge - * of the control. This represents a fraction of the form - * (1 - C)X. Since the height of a fraction of the form is - * known, the height of the entire form can be found by setting - * (1 - C)X = D. We solve this equation for X in terms of U - * and V, giving us X = (U * D) / (U - V). Similarly, if the - * offset D is negative, the control is positioned above CX. - * The offset -B is the distance from the top edge of the control - * to CX. We can find the height of the entire form by setting - * CX = -B. Solving in terms of U and V gives us X = (-B * V) / U. - */ -int computeHeight (Control control, FormData data, boolean flushCache) { - FormAttachment top = data.getTopAttachment (control, spacing, flushCache); - FormAttachment bottom = data.getBottomAttachment (control, spacing, flushCache); - FormAttachment height = bottom.minus (top); - if (height.numerator == 0) { - if (bottom.numerator == 0) return bottom.offset; - if (bottom.numerator == bottom.denominator) return -top.offset; - if (bottom.offset <= 0) { - return -top.offset * top.denominator / bottom.numerator; - } - int divider = bottom.denominator - bottom.numerator; - return bottom.denominator * bottom.offset / divider; - } - return height.solveY (data.getHeight (control, flushCache)); -} - -protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { - Point size = layout (composite, false, 0, 0, wHint, hHint, flushCache); - if (wHint != SWT.DEFAULT) size.x = wHint; - if (hHint != SWT.DEFAULT) size.y = hHint; - return size; -} - -protected boolean flushCache (Control control) { - Object data = control.getLayoutData (); - if (data != null) ((FormData) data).flushCache (); - return true; -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -/* - * Computes the preferred height of the form with - * respect to the preferred height of the control. - */ -int computeWidth (Control control, FormData data, boolean flushCache) { - FormAttachment left = data.getLeftAttachment (control, spacing, flushCache); - FormAttachment right = data.getRightAttachment (control, spacing, flushCache); - FormAttachment width = right.minus (left); - if (width.numerator == 0) { - if (right.numerator == 0) return right.offset; - if (right.numerator == right.denominator) return -left.offset; - if (right.offset <= 0) { - return -left.offset * left.denominator / left.numerator; - } - int divider = right.denominator - right.numerator; - return right.denominator * right.offset / divider; - } - return width.solveY (data.getWidth (control, flushCache)); -} - -protected void layout (Composite composite, boolean flushCache) { - Rectangle rect = composite.getClientArea (); - int x = rect.x + marginLeft + marginWidth; - int y = rect.y + marginTop + marginHeight; - int width = Math.max (0, rect.width - marginLeft - 2 * marginWidth - marginRight); - int height = Math.max (0, rect.height - marginTop - 2 * marginHeight - marginBottom); - layout (composite, true, x, y, width, height, flushCache); -} - -Point layout (Composite composite, boolean move, int x, int y, int width, int height, boolean flushCache) { - Control [] children = composite.getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - FormData data = (FormData) child.getLayoutData (); - if (data == null) child.setLayoutData (data = new FormData ()); - if (flushCache) data.flushCache (); - data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null; - } - boolean [] flush = null; - Rectangle [] bounds = null; - int w = 0, h = 0; - for (int i=0; i<children.length; i++) { - Control child = children [i]; - FormData data = (FormData) child.getLayoutData (); - if (width != SWT.DEFAULT) { - data.needed = false; - FormAttachment left = data.getLeftAttachment (child, spacing, flushCache); - FormAttachment right = data.getRightAttachment (child, spacing, flushCache); - int x1 = left.solveX (width), x2 = right.solveX (width); - if (data.height == SWT.DEFAULT && !data.needed) { - int trim = 0; - //TEMPORARY CODE - if (child instanceof Scrollable) { - Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); - trim = rect.width; - } else { - trim = child.getBorderWidth () * 2; - } - data.cacheWidth = data.cacheHeight = -1; - int currentWidth = Math.max (0, x2 - x1 - trim); - data.computeSize (child, currentWidth, data.height, flushCache); - if (flush == null) flush = new boolean [children.length]; - flush [i] = true; - } - w = Math.max (x2, w); - if (move) { - if (bounds == null) bounds = new Rectangle [children.length]; - bounds [i] = new Rectangle (0, 0, 0, 0); - bounds [i].x = x + x1; - bounds [i].width = x2 - x1; - } - } else { - w = Math.max (computeWidth (child, data, flushCache), w); - } - } - for (int i=0; i<children.length; i++) { - Control child = children [i]; - FormData data = (FormData) child.getLayoutData (); - if (height != SWT.DEFAULT) { - int y1 = data.getTopAttachment (child, spacing, flushCache).solveX (height); - int y2 = data.getBottomAttachment (child, spacing, flushCache).solveX (height); - h = Math.max (y2, h); - if (move) { - bounds [i].y = y + y1; - bounds [i].height = y2 - y1; - } - } else { - h = Math.max (computeHeight (child, data, flushCache), h); - } - } - for (int i=0; i<children.length; i++) { - Control child = children [i]; - FormData data = (FormData) child.getLayoutData (); - if (flush != null && flush [i]) data.cacheWidth = data.cacheHeight = -1; - data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null; - } - if (move) { - for (int i=0; i<children.length; i++) { - children [i].setBounds (bounds [i]); - } - } - w += marginLeft + marginWidth * 2 + marginRight; - h += marginTop + marginHeight * 2 + marginBottom; - return new Point (w, h); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the layout - */ -public String toString () { - String string = getName ()+" {"; - if (marginWidth != 0) string += "marginWidth="+marginWidth+" "; - if (marginHeight != 0) string += "marginHeight="+marginHeight+" "; - if (marginLeft != 0) string += "marginLeft="+marginLeft+" "; - if (marginRight != 0) string += "marginRight="+marginRight+" "; - if (marginTop != 0) string += "marginTop="+marginTop+" "; - if (marginBottom != 0) string += "marginBottom="+marginBottom+" "; - if (spacing != 0) string += "spacing="+spacing+" "; - string = string.trim(); - string += "}"; - return string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java deleted file mode 100755 index d26c60cf4c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java +++ /dev/null @@ -1,566 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * <code>GridData</code> is the layout data object associated with - * <code>GridLayout</code>. To set a <code>GridData</code> object into a - * control, you use the <code>Control.setLayoutData(Object)</code> method. - * <p> - * There are two ways to create a <code>GridData</code> object with certain - * fields set. The first is to set the fields directly, like this: - * <pre> - * GridData gridData = new GridData(); - * gridData.horizontalAlignment = GridData.FILL; - * gridData.grabExcessHorizontalSpace = true; - * button1.setLayoutData(gridData); - * </pre> - * The second is to take advantage of convenience style bits defined - * by <code>GridData</code>: - * <pre> - * button1.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); - * </pre> - * </p> - * <p> - * NOTE: Do not reuse <code>GridData</code> objects. Every control in a - * <code>Composite</code> that is managed by a <code>GridLayout</code> - * must have a unique <code>GridData</code> object. If the layout data - * for a control in a <code>GridLayout</code> is null at layout time, - * a unique <code>GridData</code> object is created for it. - * </p> - * - * @see GridLayout - * @see Control#setLayoutData - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class GridData { - /** - * verticalAlignment specifies how controls will be positioned - * vertically within a cell. - * - * The default value is CENTER. - * - * Possible values are: <ul> - * <li>SWT.BEGINNING (or SWT.TOP): Position the control at the top of the cell</li> - * <li>SWT.CENTER: Position the control in the vertical center of the cell</li> - * <li>SWT.END (or SWT.BOTTOM): Position the control at the bottom of the cell</li> - * <li>SWT.FILL: Resize the control to fill the cell vertically</li> - * </ul> - */ - public int verticalAlignment = CENTER; - - /** - * horizontalAlignment specifies how controls will be positioned - * horizontally within a cell. - * - * The default value is BEGINNING. - * - * Possible values are: <ul> - * <li>SWT.BEGINNING (or SWT.LEFT): Position the control at the left of the cell</li> - * <li>SWT.CENTER: Position the control in the horizontal center of the cell</li> - * <li>SWT.END (or SWT.RIGHT): Position the control at the right of the cell</li> - * <li>SWT.FILL: Resize the control to fill the cell horizontally</li> - * </ul> - */ - public int horizontalAlignment = BEGINNING; - - /** - * widthHint specifies the preferred width in pixels. This value - * is the wHint passed into Control.computeSize(int, int, boolean) - * to determine the preferred size of the control. - * - * The default value is SWT.DEFAULT. - * - * @see Control#computeSize(int, int, boolean) - */ - public int widthHint = SWT.DEFAULT; - - /** - * heightHint specifies the preferred height in pixels. This value - * is the hHint passed into Control.computeSize(int, int, boolean) - * to determine the preferred size of the control. - * - * The default value is SWT.DEFAULT. - * - * @see Control#computeSize(int, int, boolean) - */ - public int heightHint = SWT.DEFAULT; - - /** - * horizontalIndent specifies the number of pixels of indentation - * that will be placed along the left side of the cell. - * - * The default value is 0. - */ - public int horizontalIndent = 0; - - /** - * verticalIndent specifies the number of pixels of indentation - * that will be placed along the top side of the cell. - * - * The default value is 0. - * - * @since 3.1 - */ - public int verticalIndent = 0; - - /** - * horizontalSpan specifies the number of column cells that the control - * will take up. - * - * The default value is 1. - */ - public int horizontalSpan = 1; - - /** - * verticalSpan specifies the number of row cells that the control - * will take up. - * - * The default value is 1. - */ - public int verticalSpan = 1; - - /** - * <p>grabExcessHorizontalSpace specifies whether the width of the cell - * changes depending on the size of the parent Composite. If - * grabExcessHorizontalSpace is <code>true</code>, the following rules - * apply to the width of the cell:</p> - * <ul> - * <li>If extra horizontal space is available in the parent, the cell will - * grow to be wider than its preferred width. The new width - * will be "preferred width + delta" where delta is the extra - * horizontal space divided by the number of grabbing columns.</li> - * <li>If there is not enough horizontal space available in the parent, the - * cell will shrink until it reaches its minimum width as specified by - * GridData.minimumWidth. The new width will be the maximum of - * "minimumWidth" and "preferred width - delta", where delta is - * the amount of space missing divided by the number of grabbing columns.</li> - * <li>If the parent is packed, the cell will be its preferred width - * as specified by GridData.widthHint.</li> - * <li>If the control spans multiple columns and there are no other grabbing - * controls in any of the spanned columns, the last column in the span will - * grab the extra space. If there is at least one other grabbing control - * in the span, the grabbing will be spread over the columns already - * marked as grabExcessHorizontalSpace.</li> - * </ul> - * - * <p>The default value is false.</p> - * - * @see GridData#minimumWidth - * @see GridData#widthHint - */ - public boolean grabExcessHorizontalSpace = false; - - /** - * <p>grabExcessVerticalSpace specifies whether the height of the cell - * changes depending on the size of the parent Composite. If - * grabExcessVerticalSpace is <code>true</code>, the following rules - * apply to the height of the cell:</p> - * <ul> - * <li>If extra vertical space is available in the parent, the cell will - * grow to be taller than its preferred height. The new height - * will be "preferred height + delta" where delta is the extra - * vertical space divided by the number of grabbing rows.</li> - * <li>If there is not enough vertical space available in the parent, the - * cell will shrink until it reaches its minimum height as specified by - * GridData.minimumHeight. The new height will be the maximum of - * "minimumHeight" and "preferred height - delta", where delta is - * the amount of space missing divided by the number of grabbing rows.</li> - * <li>If the parent is packed, the cell will be its preferred height - * as specified by GridData.heightHint.</li> - * <li>If the control spans multiple rows and there are no other grabbing - * controls in any of the spanned rows, the last row in the span will - * grab the extra space. If there is at least one other grabbing control - * in the span, the grabbing will be spread over the rows already - * marked as grabExcessVerticalSpace.</li> - * </ul> - * - * <p>The default value is false.</p> - * - * @see GridData#minimumHeight - * @see GridData#heightHint - */ - public boolean grabExcessVerticalSpace = false; - - /** - * minimumWidth specifies the minimum width in pixels. This value - * applies only if grabExcessHorizontalSpace is true. A value of - * SWT.DEFAULT means that the minimum width will be the result - * of Control.computeSize(int, int, boolean) where wHint is - * determined by GridData.widthHint. - * - * The default value is 0. - * - * @since 3.1 - * @see Control#computeSize(int, int, boolean) - * @see GridData#widthHint - */ - public int minimumWidth = 0; - - /** - * minimumHeight specifies the minimum height in pixels. This value - * applies only if grabExcessVerticalSpace is true. A value of - * SWT.DEFAULT means that the minimum height will be the result - * of Control.computeSize(int, int, boolean) where hHint is - * determined by GridData.heightHint. - * - * The default value is 0. - * - * @since 3.1 - * @see Control#computeSize(int, int, boolean) - * @see GridData#heightHint - */ - public int minimumHeight = 0; - - /** - * exclude informs the layout to ignore this control when sizing - * and positioning controls. If this value is <code>true</code>, - * the size and position of the control will not be managed by the - * layout. If this value is <code>false</code>, the size and - * position of the control will be computed and assigned. - * - * The default value is <code>false</code>. - * - * @since 3.1 - */ - public boolean exclude = false; - - /** - * Value for horizontalAlignment or verticalAlignment. - * Position the control at the top or left of the cell. - * Not recommended. Use SWT.BEGINNING, SWT.TOP or SWT.LEFT instead. - */ - public static final int BEGINNING = SWT.BEGINNING; - - /** - * Value for horizontalAlignment or verticalAlignment. - * Position the control in the vertical or horizontal center of the cell - * Not recommended. Use SWT.CENTER instead. - */ - public static final int CENTER = 2; - - /** - * Value for horizontalAlignment or verticalAlignment. - * Position the control at the bottom or right of the cell - * Not recommended. Use SWT.END, SWT.BOTTOM or SWT.RIGHT instead. - */ - public static final int END = 3; - - /** - * Value for horizontalAlignment or verticalAlignment. - * Resize the control to fill the cell horizontally or vertically. - * Not recommended. Use SWT.FILL instead. - */ - public static final int FILL = SWT.FILL; - - /** - * Style bit for <code>new GridData(int)</code>. - * Position the control at the top of the cell. - * Not recommended. Use - * <code>new GridData(int, SWT.BEGINNING, boolean, boolean)</code> - * instead. - */ - public static final int VERTICAL_ALIGN_BEGINNING = 1 << 1; - - /** - * Style bit for <code>new GridData(int)</code> to position the - * control in the vertical center of the cell. - * Not recommended. Use - * <code>new GridData(int, SWT.CENTER, boolean, boolean)</code> - * instead. - */ - public static final int VERTICAL_ALIGN_CENTER = 1 << 2; - - /** - * Style bit for <code>new GridData(int)</code> to position the - * control at the bottom of the cell. - * Not recommended. Use - * <code>new GridData(int, SWT.END, boolean, boolean)</code> - * instead. - */ - public static final int VERTICAL_ALIGN_END = 1 << 3; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fill the cell vertically. - * Not recommended. Use - * <code>new GridData(int, SWT.FILL, boolean, boolean)</code> - * instead - */ - public static final int VERTICAL_ALIGN_FILL = 1 << 4; - - /** - * Style bit for <code>new GridData(int)</code> to position the - * control at the left of the cell. - * Not recommended. Use - * <code>new GridData(SWT.BEGINNING, int, boolean, boolean)</code> - * instead. - */ - public static final int HORIZONTAL_ALIGN_BEGINNING = 1 << 5; - - /** - * Style bit for <code>new GridData(int)</code> to position the - * control in the horizontal center of the cell. - * Not recommended. Use - * <code>new GridData(SWT.CENTER, int, boolean, boolean)</code> - * instead. - */ - public static final int HORIZONTAL_ALIGN_CENTER = 1 << 6; - - /** - * Style bit for <code>new GridData(int)</code> to position the - * control at the right of the cell. - * Not recommended. Use - * <code>new GridData(SWT.END, int, boolean, boolean)</code> - * instead. - */ - public static final int HORIZONTAL_ALIGN_END = 1 << 7; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fill the cell horizontally. - * Not recommended. Use - * <code>new GridData(SWT.FILL, int, boolean, boolean)</code> - * instead. - */ - public static final int HORIZONTAL_ALIGN_FILL = 1 << 8; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fit the remaining horizontal space. - * Not recommended. Use - * <code>new GridData(int, int, true, boolean)</code> - * instead. - */ - public static final int GRAB_HORIZONTAL = 1 << 9; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fit the remaining vertical space. - * Not recommended. Use - * <code>new GridData(int, int, boolean, true)</code> - * instead. - */ - public static final int GRAB_VERTICAL = 1 << 10; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fill the cell vertically and to fit the remaining - * vertical space. - * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL - * Not recommended. Use - * <code>new GridData(int, SWT.FILL, boolean, true)</code> - * instead. - */ - public static final int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fill the cell horizontally and to fit the remaining - * horizontal space. - * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL - * Not recommended. Use - * <code>new GridData(SWT.FILL, int, true, boolean)</code> - * instead. - */ - public static final int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL; - - /** - * Style bit for <code>new GridData(int)</code> to resize the - * control to fill the cell horizontally and vertically and - * to fit the remaining horizontal and vertical space. - * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL - * Not recommended. Use - * <code>new GridData(SWT.FILL, SWT.FILL, true, true)</code> - * instead. - */ - public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL; - - int cacheWidth = -1, cacheHeight = -1; - int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1; - int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1; - -/** - * Constructs a new instance of GridData using - * default values. - */ -public GridData () { - super (); -} - -/** - * Constructs a new instance based on the GridData style. - * This constructor is not recommended. - * - * @param style the GridData style - */ -public GridData (int style) { - super (); - if ((style & VERTICAL_ALIGN_BEGINNING) != 0) verticalAlignment = BEGINNING; - if ((style & VERTICAL_ALIGN_CENTER) != 0) verticalAlignment = CENTER; - if ((style & VERTICAL_ALIGN_FILL) != 0) verticalAlignment = FILL; - if ((style & VERTICAL_ALIGN_END) != 0) verticalAlignment = END; - if ((style & HORIZONTAL_ALIGN_BEGINNING) != 0) horizontalAlignment = BEGINNING; - if ((style & HORIZONTAL_ALIGN_CENTER) != 0) horizontalAlignment = CENTER; - if ((style & HORIZONTAL_ALIGN_FILL) != 0) horizontalAlignment = FILL; - if ((style & HORIZONTAL_ALIGN_END) != 0) horizontalAlignment = END; - grabExcessHorizontalSpace = (style & GRAB_HORIZONTAL) != 0; - grabExcessVerticalSpace = (style & GRAB_VERTICAL) != 0; -} - -/** - * Constructs a new instance of GridData according to the parameters. - * - * @param horizontalAlignment how control will be positioned horizontally within a cell, - * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL - * @param verticalAlignment how control will be positioned vertically within a cell, - * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL - * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space - * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space - * - * @since 3.0 - */ -public GridData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace) { - this (horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace, grabExcessVerticalSpace, 1, 1); -} - -/** - * Constructs a new instance of GridData according to the parameters. - * - * @param horizontalAlignment how control will be positioned horizontally within a cell, - * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL - * @param verticalAlignment how control will be positioned vertically within a cell, - * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL - * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space - * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space - * @param horizontalSpan the number of column cells that the control will take up - * @param verticalSpan the number of row cells that the control will take up - * - * @since 3.0 - */ -public GridData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace, int horizontalSpan, int verticalSpan) { - super (); - this.horizontalAlignment = horizontalAlignment; - this.verticalAlignment = verticalAlignment; - this.grabExcessHorizontalSpace = grabExcessHorizontalSpace; - this.grabExcessVerticalSpace = grabExcessVerticalSpace; - this.horizontalSpan = horizontalSpan; - this.verticalSpan = verticalSpan; -} - -/** - * Constructs a new instance of GridData according to the parameters. - * A value of SWT.DEFAULT indicates that no minimum width or - * no minimum height is specified. - * - * @param width a minimum width for the column - * @param height a minimum height for the row - * - * @since 3.0 - */ -public GridData (int width, int height) { - super (); - this.widthHint = width; - this.heightHint = height; -} - -void computeSize (Control control, int wHint, int hHint, boolean flushCache) { - if (cacheWidth != -1 && cacheHeight != -1) return; - if (wHint == this.widthHint && hHint == this.heightHint) { - if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); - defaultWhint = wHint; - defaultHhint = hHint; - defaultWidth = size.x; - defaultHeight = size.y; - } - cacheWidth = defaultWidth; - cacheHeight = defaultHeight; - return; - } - if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { - Point size = control.computeSize (wHint, hHint, flushCache); - currentWhint = wHint; - currentHhint = hHint; - currentWidth = size.x; - currentHeight = size.y; - } - cacheWidth = currentWidth; - cacheHeight = currentHeight; -} - -void flushCache () { - cacheWidth = cacheHeight = -1; - defaultWidth = defaultHeight = -1; - currentWidth = currentHeight = -1; -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the GridData object - */ -public String toString () { - String hAlign = ""; - switch (horizontalAlignment) { - case SWT.FILL: hAlign = "SWT.FILL"; break; - case SWT.BEGINNING: hAlign = "SWT.BEGINNING"; break; - case SWT.LEFT: hAlign = "SWT.LEFT"; break; - case SWT.END: hAlign = "SWT.END"; break; - case END: hAlign = "GridData.END"; break; - case SWT.RIGHT: hAlign = "SWT.RIGHT"; break; - case SWT.CENTER: hAlign = "SWT.CENTER"; break; - case CENTER: hAlign = "GridData.CENTER"; break; - default: hAlign = "Undefined "+horizontalAlignment; break; - } - String vAlign = ""; - switch (verticalAlignment) { - case SWT.FILL: vAlign = "SWT.FILL"; break; - case SWT.BEGINNING: vAlign = "SWT.BEGINNING"; break; - case SWT.TOP: vAlign = "SWT.TOP"; break; - case SWT.END: vAlign = "SWT.END"; break; - case END: vAlign = "GridData.END"; break; - case SWT.BOTTOM: vAlign = "SWT.BOTTOM"; break; - case SWT.CENTER: vAlign = "SWT.CENTER"; break; - case CENTER: vAlign = "GridData.CENTER"; break; - default: vAlign = "Undefined "+verticalAlignment; break; - } - String string = getName()+" {"; - string += "horizontalAlignment="+hAlign+" "; - if (horizontalIndent != 0) string += "horizontalIndent="+horizontalIndent+" "; - if (horizontalSpan != 1) string += "horizontalSpan="+horizontalSpan+" "; - if (grabExcessHorizontalSpace) string += "grabExcessHorizontalSpace="+grabExcessHorizontalSpace+" "; - if (widthHint != SWT.DEFAULT) string += "widthHint="+widthHint+" "; - if (minimumWidth != 0) string += "minimumWidth="+minimumWidth+" "; - string += "verticalAlignment="+vAlign+" "; - if (verticalIndent != 0) string += "verticalIndent="+verticalIndent+" "; - if (verticalSpan != 1) string += "verticalSpan="+verticalSpan+" "; - if (grabExcessVerticalSpace) string += "grabExcessVerticalSpace="+grabExcessVerticalSpace+" "; - if (heightHint != SWT.DEFAULT) string += "heightHint="+heightHint+" "; - if (minimumHeight != 0) string += "minimumHeight="+minimumHeight+" "; - if (exclude) string += "exclude="+exclude+" "; - string = string.trim(); - string += "}"; - return string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java deleted file mode 100755 index 2dd176361e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java +++ /dev/null @@ -1,745 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class lay out the control children of a - * <code>Composite</code> in a grid. - * <p> - * <code>GridLayout</code> has a number of configuration fields, and the - * controls it lays out can have an associated layout data object, called - * <code>GridData</code>. The power of <code>GridLayout</code> lies in the - * ability to configure <code>GridData</code> for each control in the layout. - * </p> - * <p> - * The following code creates a shell managed by a <code>GridLayout</code> - * with 3 columns: - * <pre> - * Display display = new Display(); - * Shell shell = new Shell(display); - * GridLayout gridLayout = new GridLayout(); - * gridLayout.numColumns = 3; - * shell.setLayout(gridLayout); - * </pre> - * The <code>numColumns</code> field is the most important field in a - * <code>GridLayout</code>. Widgets are laid out in columns from left - * to right, and a new row is created when <code>numColumns</code> + 1 - * controls are added to the <code>Composite<code>. - * </p> - * - * @see GridData - * @see <a href="http://www.eclipse.org/swt/snippets/#gridlayout">GridLayout snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class GridLayout extends Layout { - - /** - * numColumns specifies the number of cell columns in the layout. - * If numColumns has a value less than 1, the layout will not - * set the size and position of any controls. - * - * The default value is 1. - */ - public int numColumns = 1; - - /** - * makeColumnsEqualWidth specifies whether all columns in the layout - * will be forced to have the same width. - * - * The default value is false. - */ - public boolean makeColumnsEqualWidth = false; - - /** - * marginWidth specifies the number of pixels of horizontal margin - * that will be placed along the left and right edges of the layout. - * - * The default value is 5. - */ - public int marginWidth = 5; - - /** - * marginHeight specifies the number of pixels of vertical margin - * that will be placed along the top and bottom edges of the layout. - * - * The default value is 5. - */ - public int marginHeight = 5; - - /** - * marginLeft specifies the number of pixels of horizontal margin - * that will be placed along the left edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginLeft = 0; - - /** - * marginTop specifies the number of pixels of vertical margin - * that will be placed along the top edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginTop = 0; - - /** - * marginRight specifies the number of pixels of horizontal margin - * that will be placed along the right edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginRight = 0; - - /** - * marginBottom specifies the number of pixels of vertical margin - * that will be placed along the bottom edge of the layout. - * - * The default value is 0. - * - * @since 3.1 - */ - public int marginBottom = 0; - - /** - * horizontalSpacing specifies the number of pixels between the right - * edge of one cell and the left edge of its neighbouring cell to - * the right. - * - * The default value is 5. - */ - public int horizontalSpacing = 5; - - /** - * verticalSpacing specifies the number of pixels between the bottom - * edge of one cell and the top edge of its neighbouring cell underneath. - * - * The default value is 5. - */ - public int verticalSpacing = 5; - -/** - * Constructs a new instance of this class. - */ -public GridLayout () {} - -/** - * Constructs a new instance of this class given the - * number of columns, and whether or not the columns - * should be forced to have the same width. - * If numColumns has a value less than 1, the layout will not - * set the size and position of any controls. - * - * @param numColumns the number of columns in the grid - * @param makeColumnsEqualWidth whether or not the columns will have equal width - * - * @since 2.0 - */ -public GridLayout (int numColumns, boolean makeColumnsEqualWidth) { - this.numColumns = numColumns; - this.makeColumnsEqualWidth = makeColumnsEqualWidth; -} - -protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { - Point size = layout (composite, false, 0, 0, wHint, hHint, flushCache); - if (wHint != SWT.DEFAULT) size.x = wHint; - if (hHint != SWT.DEFAULT) size.y = hHint; - return size; -} - -protected boolean flushCache (Control control) { - Object data = control.getLayoutData (); - if (data != null) ((GridData) data).flushCache (); - return true; -} - -GridData getData (Control [][] grid, int row, int column, int rowCount, int columnCount, boolean first) { - Control control = grid [row] [column]; - if (control != null) { - GridData data = (GridData) control.getLayoutData (); - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - int vSpan = Math.max (1, data.verticalSpan); - int i = first ? row + vSpan - 1 : row - vSpan + 1; - int j = first ? column + hSpan - 1 : column - hSpan + 1; - if (0 <= i && i < rowCount) { - if (0 <= j && j < columnCount) { - if (control == grid [i][j]) return data; - } - } - } - return null; -} - -protected void layout (Composite composite, boolean flushCache) { - Rectangle rect = composite.getClientArea (); - layout (composite, true, rect.x, rect.y, rect.width, rect.height, flushCache); -} - -Point layout (Composite composite, boolean move, int x, int y, int width, int height, boolean flushCache) { - if (numColumns < 1) { - return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); - } - Control [] children = composite.getChildren (); - int count = 0; - for (int i=0; i<children.length; i++) { - Control control = children [i]; - GridData data = (GridData) control.getLayoutData (); - if (data == null || !data.exclude) { - children [count++] = children [i]; - } - } - if (count == 0) { - return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); - } - for (int i=0; i<count; i++) { - Control child = children [i]; - GridData data = (GridData) child.getLayoutData (); - if (data == null) child.setLayoutData (data = new GridData ()); - if (flushCache) data.flushCache (); - data.computeSize (child, data.widthHint, data.heightHint, flushCache); - if (data.grabExcessHorizontalSpace && data.minimumWidth > 0) { - if (data.cacheWidth < data.minimumWidth) { - int trim = 0; - //TEMPORARY CODE - if (child instanceof Scrollable) { - Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); - trim = rect.width; - } else { - trim = child.getBorderWidth () * 2; - } - data.cacheWidth = data.cacheHeight = SWT.DEFAULT; - data.computeSize (child, Math.max (0, data.minimumWidth - trim), data.heightHint, false); - } - } - if (data.grabExcessVerticalSpace && data.minimumHeight > 0) { - data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight); - } - } - - /* Build the grid */ - int row = 0, column = 0, rowCount = 0, columnCount = numColumns; - Control [][] grid = new Control [4] [columnCount]; - for (int i=0; i<count; i++) { - Control child = children [i]; - GridData data = (GridData) child.getLayoutData (); - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - int vSpan = Math.max (1, data.verticalSpan); - while (true) { - int lastRow = row + vSpan; - if (lastRow >= grid.length) { - Control [][] newGrid = new Control [lastRow + 4] [columnCount]; - System.arraycopy (grid, 0, newGrid, 0, grid.length); - grid = newGrid; - } - if (grid [row] == null) { - grid [row] = new Control [columnCount]; - } - while (column < columnCount && grid [row] [column] != null) { - column++; - } - int endCount = column + hSpan; - if (endCount <= columnCount) { - int index = column; - while (index < endCount && grid [row] [index] == null) { - index++; - } - if (index == endCount) break; - column = index; - } - if (column + hSpan >= columnCount) { - column = 0; - row++; - } - } - for (int j=0; j<vSpan; j++) { - if (grid [row + j] == null) { - grid [row + j] = new Control [columnCount]; - } - for (int k=0; k<hSpan; k++) { - grid [row + j] [column + k] = child; - } - } - rowCount = Math.max (rowCount, row + vSpan); - column += hSpan; - } - - /* Column widths */ - int availableWidth = width - horizontalSpacing * (columnCount - 1) - (marginLeft + marginWidth * 2 + marginRight); - int expandCount = 0; - int [] widths = new int [columnCount]; - int [] minWidths = new int [columnCount]; - boolean [] expandColumn = new boolean [columnCount]; - for (int j=0; j<columnCount; j++) { - for (int i=0; i<rowCount; i++) { - GridData data = getData (grid, i, j, rowCount, columnCount, true); - if (data != null) { - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - if (hSpan == 1) { - int w = data.cacheWidth + data.horizontalIndent; - widths [j] = Math.max (widths [j], w); - if (data.grabExcessHorizontalSpace) { - if (!expandColumn [j]) expandCount++; - expandColumn [j] = true; - } - if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) { - w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth; - w += data.horizontalIndent; - minWidths [j] = Math.max (minWidths [j], w); - } - } - } - } - for (int i=0; i<rowCount; i++) { - GridData data = getData (grid, i, j, rowCount, columnCount, false); - if (data != null) { - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - if (hSpan > 1) { - int spanWidth = 0, spanMinWidth = 0, spanExpandCount = 0; - for (int k=0; k<hSpan; k++) { - spanWidth += widths [j-k]; - spanMinWidth += minWidths [j-k]; - if (expandColumn [j-k]) spanExpandCount++; - } - if (data.grabExcessHorizontalSpace && spanExpandCount == 0) { - expandCount++; - expandColumn [j] = true; - } - int w = data.cacheWidth + data.horizontalIndent - spanWidth - (hSpan - 1) * horizontalSpacing; - if (w > 0) { - if (makeColumnsEqualWidth) { - int equalWidth = (w + spanWidth) / hSpan; - int remainder = (w + spanWidth) % hSpan, last = -1; - for (int k = 0; k < hSpan; k++) { - widths [last=j-k] = Math.max (equalWidth, widths [j-k]); - } - if (last > -1) widths [last] += remainder; - } else { - if (spanExpandCount == 0) { - widths [j] += w; - } else { - int delta = w / spanExpandCount; - int remainder = w % spanExpandCount, last = -1; - for (int k = 0; k < hSpan; k++) { - if (expandColumn [j-k]) { - widths [last=j-k] += delta; - } - } - if (last > -1) widths [last] += remainder; - } - } - } - if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) { - w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth; - w += data.horizontalIndent - spanMinWidth - (hSpan - 1) * horizontalSpacing; - if (w > 0) { - if (spanExpandCount == 0) { - minWidths [j] += w; - } else { - int delta = w / spanExpandCount; - int remainder = w % spanExpandCount, last = -1; - for (int k = 0; k < hSpan; k++) { - if (expandColumn [j-k]) { - minWidths [last=j-k] += delta; - } - } - if (last > -1) minWidths [last] += remainder; - } - } - } - } - } - } - } - if (makeColumnsEqualWidth) { - int minColumnWidth = 0; - int columnWidth = 0; - for (int i=0; i<columnCount; i++) { - minColumnWidth = Math.max (minColumnWidth, minWidths [i]); - columnWidth = Math.max (columnWidth, widths [i]); - } - columnWidth = width == SWT.DEFAULT || expandCount == 0 ? columnWidth : Math.max (minColumnWidth, availableWidth / columnCount); - for (int i=0; i<columnCount; i++) { - expandColumn [i] = expandCount > 0; - widths [i] = columnWidth; - } - } else { - if (width != SWT.DEFAULT && expandCount > 0) { - int totalWidth = 0; - for (int i=0; i<columnCount; i++) { - totalWidth += widths [i]; - } - int c = expandCount; - int delta = (availableWidth - totalWidth) / c; - int remainder = (availableWidth - totalWidth) % c; - int last = -1; - while (totalWidth != availableWidth) { - for (int j=0; j<columnCount; j++) { - if (expandColumn [j]) { - if (widths [j] + delta > minWidths [j]) { - widths [last = j] = widths [j] + delta; - } else { - widths [j] = minWidths [j]; - expandColumn [j] = false; - c--; - } - } - } - if (last > -1) widths [last] += remainder; - - for (int j=0; j<columnCount; j++) { - for (int i=0; i<rowCount; i++) { - GridData data = getData (grid, i, j, rowCount, columnCount, false); - if (data != null) { - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - if (hSpan > 1) { - if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) { - int spanWidth = 0, spanExpandCount = 0; - for (int k=0; k<hSpan; k++) { - spanWidth += widths [j-k]; - if (expandColumn [j-k]) spanExpandCount++; - } - int w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth; - w += data.horizontalIndent - spanWidth - (hSpan - 1) * horizontalSpacing; - if (w > 0) { - if (spanExpandCount == 0) { - widths [j] += w; - } else { - int delta2 = w / spanExpandCount; - int remainder2 = w % spanExpandCount, last2 = -1; - for (int k = 0; k < hSpan; k++) { - if (expandColumn [j-k]) { - widths [last2=j-k] += delta2; - } - } - if (last2 > -1) widths [last2] += remainder2; - } - } - } - } - } - } - } - if (c == 0) break; - totalWidth = 0; - for (int i=0; i<columnCount; i++) { - totalWidth += widths [i]; - } - delta = (availableWidth - totalWidth) / c; - remainder = (availableWidth - totalWidth) % c; - last = -1; - } - } - } - - /* Wrapping */ - GridData [] flush = null; - int flushLength = 0; - if (width != SWT.DEFAULT) { - for (int j=0; j<columnCount; j++) { - for (int i=0; i<rowCount; i++) { - GridData data = getData (grid, i, j, rowCount, columnCount, false); - if (data != null) { - if (data.heightHint == SWT.DEFAULT) { - Control child = grid [i][j]; - //TEMPORARY CODE - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - int currentWidth = 0; - for (int k=0; k<hSpan; k++) { - currentWidth += widths [j-k]; - } - currentWidth += (hSpan - 1) * horizontalSpacing - data.horizontalIndent; - if ((currentWidth != data.cacheWidth && data.horizontalAlignment == SWT.FILL) || (data.cacheWidth > currentWidth)) { - int trim = 0; - if (child instanceof Scrollable) { - Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); - trim = rect.width; - } else { - trim = child.getBorderWidth () * 2; - } - data.cacheWidth = data.cacheHeight = SWT.DEFAULT; - data.computeSize (child, Math.max (0, currentWidth - trim), data.heightHint, false); - if (data.grabExcessVerticalSpace && data.minimumHeight > 0) { - data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight); - } - if (flush == null) flush = new GridData [count]; - flush [flushLength++] = data; - } - } - } - } - } - } - - /* Row heights */ - int availableHeight = height - verticalSpacing * (rowCount - 1) - (marginTop + marginHeight * 2 + marginBottom); - expandCount = 0; - int [] heights = new int [rowCount]; - int [] minHeights = new int [rowCount]; - boolean [] expandRow = new boolean [rowCount]; - for (int i=0; i<rowCount; i++) { - for (int j=0; j<columnCount; j++) { - GridData data = getData (grid, i, j, rowCount, columnCount, true); - if (data != null) { - int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount)); - if (vSpan == 1) { - int h = data.cacheHeight + data.verticalIndent; - heights [i] = Math.max (heights [i], h); - if (data.grabExcessVerticalSpace) { - if (!expandRow [i]) expandCount++; - expandRow [i] = true; - } - if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) { - h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight; - h += data.verticalIndent; - minHeights [i] = Math.max (minHeights [i], h); - } - } - } - } - for (int j=0; j<columnCount; j++) { - GridData data = getData (grid, i, j, rowCount, columnCount, false); - if (data != null) { - int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount)); - if (vSpan > 1) { - int spanHeight = 0, spanMinHeight = 0, spanExpandCount = 0; - for (int k=0; k<vSpan; k++) { - spanHeight += heights [i-k]; - spanMinHeight += minHeights [i-k]; - if (expandRow [i-k]) spanExpandCount++; - } - if (data.grabExcessVerticalSpace && spanExpandCount == 0) { - expandCount++; - expandRow [i] = true; - } - int h = data.cacheHeight + data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing; - if (h > 0) { - if (spanExpandCount == 0) { - heights [i] += h; - } else { - int delta = h / spanExpandCount; - int remainder = h % spanExpandCount, last = -1; - for (int k = 0; k < vSpan; k++) { - if (expandRow [i-k]) { - heights [last=i-k] += delta; - } - } - if (last > -1) heights [last] += remainder; - } - } - if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) { - h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight; - h += data.verticalIndent - spanMinHeight - (vSpan - 1) * verticalSpacing; - if (h > 0) { - if (spanExpandCount == 0) { - minHeights [i] += h; - } else { - int delta = h / spanExpandCount; - int remainder = h % spanExpandCount, last = -1; - for (int k = 0; k < vSpan; k++) { - if (expandRow [i-k]) { - minHeights [last=i-k] += delta; - } - } - if (last > -1) minHeights [last] += remainder; - } - } - } - } - } - } - } - if (height != SWT.DEFAULT && expandCount > 0) { - int totalHeight = 0; - for (int i=0; i<rowCount; i++) { - totalHeight += heights [i]; - } - int c = expandCount; - int delta = (availableHeight - totalHeight) / c; - int remainder = (availableHeight - totalHeight) % c; - int last = -1; - while (totalHeight != availableHeight) { - for (int i=0; i<rowCount; i++) { - if (expandRow [i]) { - if (heights [i] + delta > minHeights [i]) { - heights [last = i] = heights [i] + delta; - } else { - heights [i] = minHeights [i]; - expandRow [i] = false; - c--; - } - } - } - if (last > -1) heights [last] += remainder; - - for (int i=0; i<rowCount; i++) { - for (int j=0; j<columnCount; j++) { - GridData data = getData (grid, i, j, rowCount, columnCount, false); - if (data != null) { - int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount)); - if (vSpan > 1) { - if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) { - int spanHeight = 0, spanExpandCount = 0; - for (int k=0; k<vSpan; k++) { - spanHeight += heights [i-k]; - if (expandRow [i-k]) spanExpandCount++; - } - int h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight; - h += data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing; - if (h > 0) { - if (spanExpandCount == 0) { - heights [i] += h; - } else { - int delta2 = h / spanExpandCount; - int remainder2 = h % spanExpandCount, last2 = -1; - for (int k = 0; k < vSpan; k++) { - if (expandRow [i-k]) { - heights [last2=i-k] += delta2; - } - } - if (last2 > -1) heights [last2] += remainder2; - } - } - } - } - } - } - } - if (c == 0) break; - totalHeight = 0; - for (int i=0; i<rowCount; i++) { - totalHeight += heights [i]; - } - delta = (availableHeight - totalHeight) / c; - remainder = (availableHeight - totalHeight) % c; - last = -1; - } - } - - /* Position the controls */ - if (move) { - int gridY = y + marginTop + marginHeight; - for (int i=0; i<rowCount; i++) { - int gridX = x + marginLeft + marginWidth; - for (int j=0; j<columnCount; j++) { - GridData data = getData (grid, i, j, rowCount, columnCount, true); - if (data != null) { - int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); - int vSpan = Math.max (1, data.verticalSpan); - int cellWidth = 0, cellHeight = 0; - for (int k=0; k<hSpan; k++) { - cellWidth += widths [j+k]; - } - for (int k=0; k<vSpan; k++) { - cellHeight += heights [i+k]; - } - cellWidth += horizontalSpacing * (hSpan - 1); - int childX = gridX + data.horizontalIndent; - int childWidth = Math.min (data.cacheWidth, cellWidth); - switch (data.horizontalAlignment) { - case SWT.CENTER: - case GridData.CENTER: - childX += Math.max (0, (cellWidth - data.horizontalIndent - childWidth) / 2); - break; - case SWT.RIGHT: - case SWT.END: - case GridData.END: - childX += Math.max (0, cellWidth - data.horizontalIndent - childWidth); - break; - case SWT.FILL: - childWidth = cellWidth - data.horizontalIndent; - break; - } - cellHeight += verticalSpacing * (vSpan - 1); - int childY = gridY + data.verticalIndent; - int childHeight = Math.min (data.cacheHeight, cellHeight); - switch (data.verticalAlignment) { - case SWT.CENTER: - case GridData.CENTER: - childY += Math.max (0, (cellHeight - data.verticalIndent - childHeight) / 2); - break; - case SWT.BOTTOM: - case SWT.END: - case GridData.END: - childY += Math.max (0, cellHeight - data.verticalIndent - childHeight); - break; - case SWT.FILL: - childHeight = cellHeight - data.verticalIndent; - break; - } - Control child = grid [i][j]; - if (child != null) { - child.setBounds (childX, childY, childWidth, childHeight); - } - } - gridX += widths [j] + horizontalSpacing; - } - gridY += heights [i] + verticalSpacing; - } - } - - // clean up cache - for (int i = 0; i < flushLength; i++) { - flush [i].cacheWidth = flush [i].cacheHeight = -1; - } - - int totalDefaultWidth = 0; - int totalDefaultHeight = 0; - for (int i=0; i<columnCount; i++) { - totalDefaultWidth += widths [i]; - } - for (int i=0; i<rowCount; i++) { - totalDefaultHeight += heights [i]; - } - totalDefaultWidth += horizontalSpacing * (columnCount - 1) + marginLeft + marginWidth * 2 + marginRight; - totalDefaultHeight += verticalSpacing * (rowCount - 1) + marginTop + marginHeight * 2 + marginBottom; - return new Point (totalDefaultWidth, totalDefaultHeight); -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the layout - */ -public String toString () { - String string = getName ()+" {"; - if (numColumns != 1) string += "numColumns="+numColumns+" "; - if (makeColumnsEqualWidth) string += "makeColumnsEqualWidth="+makeColumnsEqualWidth+" "; - if (marginWidth != 0) string += "marginWidth="+marginWidth+" "; - if (marginHeight != 0) string += "marginHeight="+marginHeight+" "; - if (marginLeft != 0) string += "marginLeft="+marginLeft+" "; - if (marginRight != 0) string += "marginRight="+marginRight+" "; - if (marginTop != 0) string += "marginTop="+marginTop+" "; - if (marginBottom != 0) string += "marginBottom="+marginBottom+" "; - if (horizontalSpacing != 0) string += "horizontalSpacing="+horizontalSpacing+" "; - if (verticalSpacing != 0) string += "verticalSpacing="+verticalSpacing+" "; - string = string.trim(); - string += "}"; - return string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java deleted file mode 100755 index c0a9e03293..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Each control controlled by a <code>RowLayout</code> can have its initial - * width and height specified by setting a <code>RowData</code> object - * into the control. - * <p> - * The following code uses a <code>RowData</code> object to change the initial - * size of a <code>Button</code> in a <code>Shell</code>: - * <pre> - * Display display = new Display(); - * Shell shell = new Shell(display); - * shell.setLayout(new RowLayout()); - * Button button1 = new Button(shell, SWT.PUSH); - * button1.setText("Button 1"); - * button1.setLayoutData(new RowData(50, 40)); - * </pre> - * </p> - * - * @see RowLayout - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class RowData { - /** - * width specifies the desired width in pixels. This value - * is the wHint passed into Control.computeSize(int, int, boolean) - * to determine the preferred size of the control. - * - * The default value is SWT.DEFAULT. - * - * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) - */ - public int width = SWT.DEFAULT; - /** - * height specifies the preferred height in pixels. This value - * is the hHint passed into Control.computeSize(int, int, boolean) - * to determine the preferred size of the control. - * - * The default value is SWT.DEFAULT. - * - * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) - */ - public int height = SWT.DEFAULT; - - /** - * exclude informs the layout to ignore this control when sizing - * and positioning controls. If this value is <code>true</code>, - * the size and position of the control will not be managed by the - * layout. If this value is <code>false</code>, the size and - * position of the control will be computed and assigned. - * - * The default value is <code>false</code>. - * - * @since 3.1 - */ - public boolean exclude = false; - -/** - * Constructs a new instance of RowData using - * default values. - */ -public RowData () { -} - -/** - * Constructs a new instance of RowData according to the parameters. - * A value of SWT.DEFAULT indicates that no minimum width or - * no minimum height is specified. - * - * @param width a minimum width for the control - * @param height a minimum height for the control - */ -public RowData (int width, int height) { - this.width = width; - this.height = height; -} - -/** - * Constructs a new instance of RowData according to the parameter. - * A value of SWT.DEFAULT indicates that no minimum width or - * no minimum height is specified. - * - * @param point a point whose x coordinate specifies a minimum width for the control - * and y coordinate specifies a minimum height for the control - */ -public RowData (Point point) { - this (point.x, point.y); -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the RowData object - */ -public String toString () { - String string = getName ()+" {"; - if (width != SWT.DEFAULT) string += "width="+width+" "; - if (height != SWT.DEFAULT) string += "height="+height+" "; - if (exclude) string += "exclude="+exclude+" "; - string = string.trim(); - string += "}"; - return string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java deleted file mode 100755 index 2d8b5742c1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java +++ /dev/null @@ -1,506 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.layout; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class determine the size and position of the - * children of a <code>Composite</code> by placing them either in - * horizontal rows or vertical columns within the parent <code>Composite</code>. - * <p> - * <code>RowLayout</code> aligns all controls in one row if the - * <code>type</code> is set to horizontal, and one column if it is - * set to vertical. It has the ability to wrap, and provides configurable - * margins and spacing. <code>RowLayout</code> has a number of configuration - * fields. In addition, the height and width of each control in a - * <code>RowLayout</code> can be specified by setting a <code>RowData</code> - * object into the control using <code>setLayoutData ()</code>. - * </p> - * <p> - * The following example code creates a <code>RowLayout</code>, sets all - * of its fields to non-default values, and then sets it into a - * <code>Shell</code>. - * <pre> - * RowLayout rowLayout = new RowLayout(); - * rowLayout.wrap = false; - * rowLayout.pack = false; - * rowLayout.justify = true; - * rowLayout.type = SWT.VERTICAL; - * rowLayout.marginLeft = 5; - * rowLayout.marginTop = 5; - * rowLayout.marginRight = 5; - * rowLayout.marginBottom = 5; - * rowLayout.spacing = 0; - * shell.setLayout(rowLayout); - * </pre> - * If you are using the default field values, you only need one line of code: - * <pre> - * shell.setLayout(new RowLayout()); - * </pre> - * </p> - * - * @see RowData - * @see <a href="http://www.eclipse.org/swt/snippets/#rowlayout">RowLayout snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class RowLayout extends Layout { - - /** - * type specifies whether the layout places controls in rows or - * columns. - * - * The default value is HORIZONTAL. - * - * Possible values are: <ul> - * <li>HORIZONTAL: Position the controls horizontally from left to right</li> - * <li>VERTICAL: Position the controls vertically from top to bottom</li> - * </ul> - * - * @since 2.0 - */ - public int type = SWT.HORIZONTAL; - - /** - * marginWidth specifies the number of pixels of horizontal margin - * that will be placed along the left and right edges of the layout. - * - * The default value is 0. - * - * @since 3.0 - */ - public int marginWidth = 0; - - /** - * marginHeight specifies the number of pixels of vertical margin - * that will be placed along the top and bottom edges of the layout. - * - * The default value is 0. - * - * @since 3.0 - */ - public int marginHeight = 0; - - /** - * spacing specifies the number of pixels between the edge of one cell - * and the edge of its neighbouring cell. - * - * The default value is 3. - */ - public int spacing = 3; - - /** - * wrap specifies whether a control will be wrapped to the next - * row if there is insufficient space on the current row. - * - * The default value is true. - */ - public boolean wrap = true; - - /** - * pack specifies whether all controls in the layout take - * their preferred size. If pack is false, all controls will - * have the same size which is the size required to accommodate the - * largest preferred height and the largest preferred width of all - * the controls in the layout. - * - * The default value is true. - */ - public boolean pack = true; - - /** - * fill specifies whether the controls in a row should be - * all the same height for horizontal layouts, or the same - * width for vertical layouts. - * - * The default value is false. - * - * @since 3.0 - */ - public boolean fill = false; - - /** - * center specifies whether the controls in a row should be - * centered vertically in each cell for horizontal layouts, - * or centered horizontally in each cell for vertical layouts. - * - * The default value is false. - * - * @since 3.4 - */ - public boolean center = false; - - /** - * justify specifies whether the controls in a row should be - * fully justified, with any extra space placed between the controls. - * - * The default value is false. - */ - public boolean justify = false; - - /** - * marginLeft specifies the number of pixels of horizontal margin - * that will be placed along the left edge of the layout. - * - * The default value is 3. - */ - public int marginLeft = 3; - - /** - * marginTop specifies the number of pixels of vertical margin - * that will be placed along the top edge of the layout. - * - * The default value is 3. - */ - public int marginTop = 3; - - /** - * marginRight specifies the number of pixels of horizontal margin - * that will be placed along the right edge of the layout. - * - * The default value is 3. - */ - public int marginRight = 3; - - /** - * marginBottom specifies the number of pixels of vertical margin - * that will be placed along the bottom edge of the layout. - * - * The default value is 3. - */ - public int marginBottom = 3; - -/** - * Constructs a new instance of this class. - */ -public RowLayout () { -} - -/** - * Constructs a new instance of this class given the type. - * - * @param type the type of row layout - * - * @since 2.0 - */ -public RowLayout (int type) { - this.type = type; -} - -protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { - Point extent; - if (type == SWT.HORIZONTAL) { - extent = layoutHorizontal (composite, false, (wHint != SWT.DEFAULT) && wrap, wHint, flushCache); - } else { - extent = layoutVertical (composite, false, (hHint != SWT.DEFAULT) && wrap, hHint, flushCache); - } - if (wHint != SWT.DEFAULT) extent.x = wHint; - if (hHint != SWT.DEFAULT) extent.y = hHint; - return extent; -} - -Point computeSize (Control control, boolean flushCache) { - int wHint = SWT.DEFAULT, hHint = SWT.DEFAULT; - RowData data = (RowData) control.getLayoutData (); - if (data != null) { - wHint = data.width; - hHint = data.height; - } - return control.computeSize (wHint, hHint, flushCache); -} - -protected boolean flushCache (Control control) { - return true; -} - -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} - -protected void layout (Composite composite, boolean flushCache) { - Rectangle clientArea = composite.getClientArea (); - if (type == SWT.HORIZONTAL) { - layoutHorizontal (composite, true, wrap, clientArea.width, flushCache); - } else { - layoutVertical (composite, true, wrap, clientArea.height, flushCache); - } -} - -Point layoutHorizontal (Composite composite, boolean move, boolean wrap, int width, boolean flushCache) { - Control [] children = composite.getChildren (); - int count = 0; - for (int i=0; i<children.length; i++) { - Control control = children [i]; - RowData data = (RowData) control.getLayoutData (); - if (data == null || !data.exclude) { - children [count++] = children [i]; - } - } - if (count == 0) { - return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); - } - int childWidth = 0, childHeight = 0, maxHeight = 0; - if (!pack) { - for (int i=0; i<count; i++) { - Control child = children [i]; - Point size = computeSize (child, flushCache); - childWidth = Math.max (childWidth, size.x); - childHeight = Math.max (childHeight, size.y); - } - maxHeight = childHeight; - } - int clientX = 0, clientY = 0; - if (move) { - Rectangle rect = composite.getClientArea (); - clientX = rect.x; - clientY = rect.y; - } - int [] wraps = null; - boolean wrapped = false; - Rectangle [] bounds = null; - if (move && (justify || fill || center)) { - bounds = new Rectangle [count]; - wraps = new int [count]; - } - int maxX = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight; - for (int i=0; i<count; i++) { - Control child = children [i]; - if (pack) { - Point size = computeSize (child, flushCache); - childWidth = size.x; - childHeight = size.y; - } - if (wrap && (i != 0) && (x + childWidth > width)) { - wrapped = true; - if (move && (justify || fill || center)) wraps [i - 1] = maxHeight; - x = marginLeft + marginWidth; - y += spacing + maxHeight; - if (pack) maxHeight = 0; - } - if (pack || fill || center) { - maxHeight = Math.max (maxHeight, childHeight); - } - if (move) { - int childX = x + clientX, childY = y + clientY; - if (justify || fill || center) { - bounds [i] = new Rectangle (childX, childY, childWidth, childHeight); - } else { - child.setBounds (childX, childY, childWidth, childHeight); - } - } - x += spacing + childWidth; - maxX = Math.max (maxX, x); - } - maxX = Math.max (clientX + marginLeft + marginWidth, maxX - spacing); - if (!wrapped) maxX += marginRight + marginWidth; - if (move && (justify || fill || center)) { - int space = 0, margin = 0; - if (!wrapped) { - space = Math.max (0, (width - maxX) / (count + 1)); - margin = Math.max (0, ((width - maxX) % (count + 1)) / 2); - } else { - if (fill || justify || center) { - int last = 0; - if (count > 0) wraps [count - 1] = maxHeight; - for (int i=0; i<count; i++) { - if (wraps [i] != 0) { - int wrapCount = i - last + 1; - if (justify) { - int wrapX = 0; - for (int j=last; j<=i; j++) { - wrapX += bounds [j].width + spacing; - } - space = Math.max (0, (width - wrapX) / (wrapCount + 1)); - margin = Math.max (0, ((width - wrapX) % (wrapCount + 1)) / 2); - } - for (int j=last; j<=i; j++) { - if (justify) bounds [j].x += (space * (j - last + 1)) + margin; - if (fill) { - bounds [j].height = wraps [i]; - } else { - if (center) { - bounds [j].y += Math.max (0, (wraps [i] - bounds [j].height) / 2); - } - } - } - last = i + 1; - } - } - } - } - for (int i=0; i<count; i++) { - if (!wrapped) { - if (justify) bounds [i].x += (space * (i + 1)) + margin; - if (fill) { - bounds [i].height = maxHeight; - } else { - if (center) { - bounds [i].y += Math.max (0, (maxHeight - bounds [i].height) / 2); - } - } - } - children [i].setBounds (bounds [i]); - } - } - return new Point (maxX, y + maxHeight + marginBottom + marginHeight); -} - -Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) { - Control [] children = composite.getChildren (); - int count = 0; - for (int i=0; i<children.length; i++) { - Control control = children [i]; - RowData data = (RowData) control.getLayoutData (); - if (data == null || !data.exclude) { - children [count++] = children [i]; - } - } - if (count == 0) { - return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); - } - int childWidth = 0, childHeight = 0, maxWidth = 0; - if (!pack) { - for (int i=0; i<count; i++) { - Control child = children [i]; - Point size = computeSize (child, flushCache); - childWidth = Math.max (childWidth, size.x); - childHeight = Math.max (childHeight, size.y); - } - maxWidth = childWidth; - } - int clientX = 0, clientY = 0; - if (move) { - Rectangle rect = composite.getClientArea (); - clientX = rect.x; - clientY = rect.y; - } - int [] wraps = null; - boolean wrapped = false; - Rectangle [] bounds = null; - if (move && (justify || fill || center)) { - bounds = new Rectangle [count]; - wraps = new int [count]; - } - int maxY = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight; - for (int i=0; i<count; i++) { - Control child = children [i]; - if (pack) { - Point size = computeSize (child, flushCache); - childWidth = size.x; - childHeight = size.y; - } - if (wrap && (i != 0) && (y + childHeight > height)) { - wrapped = true; - if (move && (justify || fill || center)) wraps [i - 1] = maxWidth; - x += spacing + maxWidth; - y = marginTop + marginHeight; - if (pack) maxWidth = 0; - } - if (pack || fill || center) { - maxWidth = Math.max (maxWidth, childWidth); - } - if (move) { - int childX = x + clientX, childY = y + clientY; - if (justify || fill || center) { - bounds [i] = new Rectangle (childX, childY, childWidth, childHeight); - } else { - child.setBounds (childX, childY, childWidth, childHeight); - } - } - y += spacing + childHeight; - maxY = Math.max (maxY, y); - } - maxY = Math.max (clientY + marginTop + marginHeight, maxY - spacing); - if (!wrapped) maxY += marginBottom + marginHeight; - if (move && (justify || fill || center)) { - int space = 0, margin = 0; - if (!wrapped) { - space = Math.max (0, (height - maxY) / (count + 1)); - margin = Math.max (0, ((height - maxY) % (count + 1)) / 2); - } else { - if (fill || justify || center) { - int last = 0; - if (count > 0) wraps [count - 1] = maxWidth; - for (int i=0; i<count; i++) { - if (wraps [i] != 0) { - int wrapCount = i - last + 1; - if (justify) { - int wrapY = 0; - for (int j=last; j<=i; j++) { - wrapY += bounds [j].height + spacing; - } - space = Math.max (0, (height - wrapY) / (wrapCount + 1)); - margin = Math.max (0, ((height - wrapY) % (wrapCount + 1)) / 2); - } - for (int j=last; j<=i; j++) { - if (justify) bounds [j].y += (space * (j - last + 1)) + margin; - if (fill) { - bounds [j].width = wraps [i]; - } else { - if (center) { - bounds [j].x += Math.max (0, (wraps [i] - bounds [j].width) / 2); - } - } - } - last = i + 1; - } - } - } - } - for (int i=0; i<count; i++) { - if (!wrapped) { - if (justify) bounds [i].y += (space * (i + 1)) + margin; - if (fill) { - bounds [i].width = maxWidth; - } else { - if (center) { - bounds [i].x += Math.max (0, (maxWidth - bounds [i].width) / 2); - } - } - - } - children [i].setBounds (bounds [i]); - } - } - return new Point (x + maxWidth + marginRight + marginWidth, maxY); -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the layout - */ -public String toString () { - String string = getName ()+" {"; - string += "type="+((type != SWT.HORIZONTAL) ? "SWT.VERTICAL" : "SWT.HORIZONTAL")+" "; - if (marginWidth != 0) string += "marginWidth="+marginWidth+" "; - if (marginHeight != 0) string += "marginHeight="+marginHeight+" "; - if (marginLeft != 0) string += "marginLeft="+marginLeft+" "; - if (marginTop != 0) string += "marginTop="+marginTop+" "; - if (marginRight != 0) string += "marginRight="+marginRight+" "; - if (marginBottom != 0) string += "marginBottom="+marginBottom+" "; - if (spacing != 0) string += "spacing="+spacing+" "; - string += "wrap="+wrap+" "; - string += "pack="+pack+" "; - string += "fill="+fill+" "; - string += "justify="+justify+" "; - string = string.trim(); - string += "}"; - return string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html deleted file mode 100755 index 0c6c14d815..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html +++ /dev/null @@ -1,15 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -This package contains the SWT layout classes. -<h2> -Package Specification</h2> -This package contains several standard layout classes which provide -automated positioning and sizing support for SWT widgets. -</body> -</html> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html deleted file mode 100755 index 31459b907b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -SWT constants and error handling support. -<h2> -Package Specification</h2> -This package provides the class <code>SWT</code> which contains all of the -constants used by SWT as well as a small selection of error handling routines -and queries such as <code>getPlatform</code> and <code>getVersion</code>. -</body> -</html> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java deleted file mode 100755 index 95de81f4fa..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java +++ /dev/null @@ -1,272 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; - -/** - * This class is the abstract superclass of the classes - * that represent the built in platform dialogs. - * A <code>Dialog</code> typically contains other widgets - * that are not accessible. A <code>Dialog</code> is not - * a <code>Widget</code>. - * <p> - * This class can also be used as the abstract superclass - * for user-designed dialogs. Such dialogs usually consist - * of a Shell with child widgets. The basic template for a - * user-defined dialog typically looks something like this: - * <pre><code> - * public class MyDialog extends Dialog { - * Object result; - * - * public MyDialog (Shell parent, int style) { - * super (parent, style); - * } - * public MyDialog (Shell parent) { - * this (parent, 0); // your default style bits go here (not the Shell's style bits) - * } - * public Object open () { - * Shell parent = getParent(); - * Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); - * shell.setText(getText()); - * // Your code goes here (widget creation, set result, etc). - * shell.open(); - * Display display = parent.getDisplay(); - * while (!shell.isDisposed()) { - * if (!display.readAndDispatch()) display.sleep(); - * } - * return result; - * } - * } - * </pre></code> - * <p> - * Note: The <em>modality</em> styles supported by this class - * are treated as <em>HINT</em>s, because not all are supported - * by every subclass on every platform. If a modality style is - * not supported, it is "upgraded" to a more restrictive modality - * style that is supported. For example, if <code>PRIMARY_MODAL</code> - * is not supported by a particular dialog, it would be upgraded to - * <code>APPLICATION_MODAL</code>. In addition, as is the case - * for shells, the window manager for the desktop on which the - * instance is visible has ultimate control over the appearance - * and behavior of the instance, including its modality. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>APPLICATION_MODAL, PRIMARY_MODAL, SYSTEM_MODAL, SHEET</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles APPLICATION_MODAL, PRIMARY_MODAL, - * and SYSTEM_MODAL may be specified. - * </p> - * - * @see Shell - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public abstract class Dialog { - int style; - Shell parent; - String title; - -/** - * Constructs a new instance of this class given only its - * parent. - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - */ -public Dialog (Shell parent) { - this (parent, SWT.PRIMARY_MODAL); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of dialog to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - * - * @see SWT#PRIMARY_MODAL - * @see SWT#APPLICATION_MODAL - * @see SWT#SYSTEM_MODAL - */ -public Dialog (Shell parent, int style) { - checkParent (parent); - this.parent = parent; - this.style = style; - title = ""; -} - -/** - * Checks that this class can be subclassed. - * <p> - * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see Widget#checkSubclass - */ -protected void checkSubclass () { - if (!Display.isValidClass (getClass ())) { - error (SWT.ERROR_INVALID_SUBCLASS); - } -} - -/** - * Throws an exception if the specified widget can not be - * used as a parent for the receiver. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - */ -void checkParent (Shell parent) { - if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); - parent.checkWidget (); -} - -static int checkStyle (Shell parent, int style) { - int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; - if ((style & SWT.SHEET) != 0) { - style &= ~SWT.SHEET; - if ((style & mask) == 0) { - style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL; - } - } - if ((style & mask) == 0) { - style |= SWT.APPLICATION_MODAL; - } - style &= ~SWT.MIRRORED; - if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) { - if (parent != null) { - if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT; - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT; - } - } - return Widget.checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0); -} - -/** - * Does whatever dialog specific cleanup is required, and then - * uses the code in <code>SWTError.error</code> to handle the error. - * - * @param code the descriptive error code - * - * @see SWT#error(int) - */ -void error (int code) { - SWT.error(code); -} - -/** - * Returns the receiver's parent, which must be a <code>Shell</code> - * or null. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Shell getParent () { - return parent; -} - -/** - * Returns the receiver's style information. - * <p> - * Note that, the value which is returned by this method <em>may - * not match</em> the value which was provided to the constructor - * when the receiver was created. - * </p> - * - * @return the style bits - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getStyle () { - return style; -} - -/** - * Returns the receiver's text, which is the string that the - * window manager will typically display as the receiver's - * <em>title</em>. If the text has not previously been set, - * returns an empty string. - * - * @return the text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - return title; -} - -/** - * Sets the receiver's text, which is the string that the - * window manager will typically display as the receiver's - * <em>title</em>, to the argument, which must not be null. - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - title = string; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java deleted file mode 100755 index 76cee32637..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java +++ /dev/null @@ -1,223 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide a description of a particular - * event which occurred within SWT. The SWT <em>untyped listener</em> - * API uses these instances for all event dispatching. - * <p> - * Note: For a given event, only the fields which are appropriate - * will be filled in. The contents of the fields which are not used - * by the event are unspecified. - * </p> - * - * @see Listener - * @see org.eclipse.swt.events.TypedEvent - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Listeners</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public class Event { - - /** - * the display where the event occurred - * - * @since 2.0 - */ - public Display display; - - /** - * the widget that issued the event - */ - public Widget widget; - - /** - * the type of event, as defined by the event type constants - * in class <code>SWT</code> - * - * @see org.eclipse.swt.SWT - */ - public int type; - - /** - * the event specific detail field, as defined by the detail constants - * in class <code>SWT</code> - * - * @see org.eclipse.swt.SWT - */ - public int detail; - - /** - * the item that the event occurred in (can be null) - */ - public Widget item; - - /** - * the index of the item where the event occurred - * - * @since 3.2 - */ - public int index; - - /** - * the graphics context to use when painting - * that is configured to use the colors, font and - * damaged region of the control. It is valid - * only during the paint and must not be disposed - */ - public GC gc; - - /** - * depending on the event type, the x offset of the bounding - * rectangle of the region that requires painting or the - * widget-relative, x coordinate of the pointer at the - * time the mouse button was pressed or released - */ - public int x; - - /** - * depending on the event type, the y offset of the bounding - * rectangle of the region that requires painting or the - * widget-relative, y coordinate of the pointer at the - * time the mouse button was pressed or released - */ - public int y; - - /** - * the width of the bounding rectangle of the - * region that requires painting - */ - public int width; - - /** - * the height of the bounding rectangle of the - * region that requires painting - */ - public int height; - - /** - * depending on the event type, the number of following - * paint events that are pending which may always be zero - * on some platforms, or the number of lines or pages to - * scroll using the mouse wheel, or the number of times the - * mouse has been clicked - */ - public int count; - - /** - * the time that the event occurred. - * - * NOTE: This field is an unsigned integer and should - * be AND'ed with 0xFFFFFFFFL so that it can be treated - * as a signed long. - */ - public int time; - - /** - * the button that was pressed or released; 1 for the - * first button, 2 for the second button, and 3 for the - * third button, etc. - */ - public int button; - - /** - * depending on the event, the character represented by the key - * that was typed. This is the final character that results - * after all modifiers have been applied. For example, when the - * user types Ctrl+A, the character value is 0x01 (ASCII SOH). - * It is important that applications do not attempt to modify the - * character value based on a stateMask (such as SWT.CTRL) or the - * resulting character will not be correct. - */ - public char character; - - /** - * depending on the event, the key code of the key that was typed, - * as defined by the key code constants in class <code>SWT</code>. - * When the character field of the event is ambiguous, this field - * contains the unaffected value of the original character. For - * example, typing Ctrl+M or Enter both result in the character '\r' - * but the keyCode field will also contain '\r' when Enter was typed - * and 'm' when Ctrl+M was typed. - * - * @see org.eclipse.swt.SWT - */ - public int keyCode; - - /** - * depending on the event, the state of the keyboard modifier - * keys and mouse masks at the time the event was generated. - * - * @see org.eclipse.swt.SWT - */ - public int stateMask; - - /** - * depending on the event, the range of text being modified. - * Setting these fields only has effect during ImeComposition - * events. - */ - public int start, end; - - /** - * depending on the event, the new text that will be inserted. - * Setting this field will change the text that is about to - * be inserted or deleted. - */ - public String text; - - /** - * depending on the event, a flag indicating whether the operation - * should be allowed. Setting this field to false will cancel the - * operation. - */ - public boolean doit = true; - - /** - * a field for application use - */ - public Object data; - -/** - * Gets the bounds. - * - * @return a rectangle that is the bounds. - */ -public Rectangle getBounds () { - return new Rectangle (x, y, width, height); -} - -/** - * Sets the bounds. - * - * @param rect the new rectangle - */ -public void setBounds (Rectangle rect) { - this.x = rect.x; - this.y = rect.y; - this.width = rect.width; - this.height = rect.height; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the event - */ -public String toString () { - return "Event {type=" + type + " " + widget + " time=" + time + " data=" + data + " x=" + x + " y=" + y + " width=" + width + " height=" + height + " detail=" + detail + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java deleted file mode 100755 index a9cda7b1b8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.SWTEventListener; - -/** - * Instances of this class implement a simple - * look up mechanism that maps an event type - * to a listener. Multiple listeners for the - * same event type are supported. - */ - -class EventTable { - int [] types; - Listener [] listeners; - int level; - static final int GROW_SIZE = 4; - -public Listener [] getListeners (int eventType) { - if (types == null) return new Listener [0]; - int count = 0; - for (int i=0; i<types.length; i++) { - if (types [i] == eventType) count++; - } - if (count == 0) return new Listener [0]; - Listener [] result = new Listener [count]; - count = 0; - for (int i=0; i<types.length; i++) { - if (types [i] == eventType) { - result [count++] = listeners [i]; - } - } - return result; -} - -public void hook (int eventType, Listener listener) { - if (types == null) types = new int [GROW_SIZE]; - if (listeners == null) listeners = new Listener [GROW_SIZE]; - int length = types.length, index = length - 1; - while (index >= 0) { - if (types [index] != 0) break; - --index; - } - index++; - if (index == length) { - int [] newTypes = new int [length + GROW_SIZE]; - System.arraycopy (types, 0, newTypes, 0, length); - types = newTypes; - Listener [] newListeners = new Listener [length + GROW_SIZE]; - System.arraycopy (listeners, 0, newListeners, 0, length); - listeners = newListeners; - } - types [index] = eventType; - listeners [index] = listener; -} - -public boolean hooks (int eventType) { - if (types == null) return false; - for (int i=0; i<types.length; i++) { - if (types [i] == eventType) return true; - } - return false; -} - -public void sendEvent (Event event) { - if (types == null) return; - level += level >= 0 ? 1 : -1; - try { - for (int i=0; i<types.length; i++) { - if (event.type == SWT.None) return; - if (types [i] == event.type) { - Listener listener = listeners [i]; - if (listener != null) listener.handleEvent (event); - } - } - } finally { - boolean compact = level < 0; - level -= level >= 0 ? 1 : -1; - if (compact && level == 0) { - int index = 0; - for (int i=0; i<types.length; i++) { - if (types [i] != 0) { - types [index] = types [i]; - listeners [index] = listeners [i]; - index++; - } - } - for (int i=index; i<types.length; i++) { - types [i] = 0; - listeners [i] = null; - } - } - } -} - -public int size () { - if (types == null) return 0; - int count = 0; - for (int i=0; i<types.length; i++) { - if (types [i] != 0) count++; - } - return count; -} - -void remove (int index) { - if (level == 0) { - int end = types.length - 1; - System.arraycopy (types, index + 1, types, index, end - index); - System.arraycopy (listeners, index + 1, listeners, index, end - index); - index = end; - } else { - if (level > 0) level = -level; - } - types [index] = 0; - listeners [index] = null; -} - -public void unhook (int eventType, Listener listener) { - if (types == null) return; - for (int i=0; i<types.length; i++) { - if (types [i] == eventType && listeners [i] == listener) { - remove (i); - return; - } - } -} - -public void unhook (int eventType, SWTEventListener listener) { - if (types == null) return; - for (int i=0; i<types.length; i++) { - if (types [i] == eventType) { - if (listeners [i] instanceof TypedListener) { - TypedListener typedListener = (TypedListener) listeners [i]; - if (typedListener.getEventListener () == listener) { - remove (i); - return; - } - } - } - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java deleted file mode 100755 index 282bff2132..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * This class is the abstract superclass of all non-windowed - * user interface objects that occur within specific controls. - * For example, a tree will contain tree items. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ - -public abstract class Item extends Widget { - String text; - Image image; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * The item is added to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of item to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - * - * @see SWT - * @see Widget#getStyle - */ -public Item (Widget parent, int style) { - super (parent, style); - text = ""; -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance, - * and the index at which to place it in the items maintained - * by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of item to construct - * @param index the zero-relative index at which to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - * - * @see SWT - * @see Widget#getStyle - */ -public Item (Widget parent, int style, int index) { - this (parent, style); -} - -protected void checkSubclass () { - /* Do Nothing - Subclassing is allowed */ -} - -/** - * Returns the receiver's image if it has one, or null - * if it does not. - * - * @return the receiver's image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget (); - return image; -} - -String getNameText () { - return getText (); -} - -/** - * Returns the receiver's text, which will be an empty - * string if it has never been set. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - return text; -} - -void releaseWidget () { - super.releaseWidget (); - text = null; - image = null; -} - -/** - * Sets the receiver's image to the argument, which may be - * null indicating that no image should be displayed. - * - * @param image the image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget (); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - this.image = image; -} - -/** - * Sets the receiver's text. - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - text = string; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java deleted file mode 100755 index 5c8f3c2850..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.graphics.*; - -/** - * A layout controls the position and size - * of the children of a composite widget. - * This class is the abstract base class for - * layouts. - * - * @see Composite#setLayout(Layout) - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class Layout { - -/** - * Computes and returns the size of the specified - * composite's client area according to this layout. - * <p> - * This method computes the size that the client area - * of the composite must be in order to position all - * children at their preferred size inside the - * composite according to the layout algorithm - * encoded by this layout. - * </p> - * <p> - * When a width or height hint is supplied, it is - * used to constrain the result. For example, if a - * width hint is provided that is less than the - * width of the client area, the layout may choose - * to wrap and increase height, clip, overlap, or - * otherwise constrain the children. - * </p> - * - * @param composite a composite widget using this layout - * @param wHint width (<code>SWT.DEFAULT</code> for preferred size) - * @param hHint height (<code>SWT.DEFAULT</code> for preferred size) - * @param flushCache <code>true</code> means flush cached layout values - * @return a point containing the computed size (width, height) - * - * @see #layout - * @see Control#getBorderWidth - * @see Control#getBounds - * @see Control#getSize - * @see Control#pack(boolean) - * @see "computeTrim, getClientArea for controls that implement them" - */ -protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache); - -/** - * Instruct the layout to flush any cached values - * associated with the control specified in the argument - * <code>control</code>. - * - * @param control a control managed by this layout - * @return true if the Layout has flushed all cached information associated with control - * - * @since 3.1 - */ -protected boolean flushCache (Control control) { - return false; -} - -/** - * Lays out the children of the specified composite - * according to this layout. - * <p> - * This method positions and sizes the children of a - * composite using the layout algorithm encoded by this - * layout. Children of the composite are positioned in - * the client area of the composite. The position of - * the composite is not altered by this method. - * </p> - * <p> - * When the flush cache hint is true, the layout is - * instructed to flush any cached values associated - * with the children. Typically, a layout will cache - * the preferred sizes of the children to avoid the - * expense of computing these values each time the - * widget is laid out. - * </p> - * <p> - * When layout is triggered explicitly by the programmer - * the flush cache hint is true. When layout is triggered - * by a resize, either caused by the programmer or by the - * user, the hint is false. - * </p> - * - * @param composite a composite widget using this layout - * @param flushCache <code>true</code> means flush cached layout values - */ -protected abstract void layout (Composite composite, boolean flushCache); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java deleted file mode 100755 index b02efa2cd3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -/** - * Implementers of <code>Listener</code> provide a simple - * <code>handleEvent()</code> method that is used internally - * by SWT to dispatch events. - * <p> - * After creating an instance of a class that implements this interface - * it can be added to a widget using the - * <code>addListener(int eventType, Listener handler)</code> method and - * removed using the - * <code>removeListener (int eventType, Listener handler)</code> method. - * When the specified event occurs, <code>handleEvent(...)</code> will - * be sent to the instance. - * </p> - * <p> - * Classes which implement this interface are described within SWT as - * providing the <em>untyped listener</em> API. Typically, widgets will - * also provide a higher-level <em>typed listener</em> API, that is based - * on the standard <code>java.util.EventListener</code> pattern. - * </p> - * <p> - * Note that, since all internal SWT event dispatching is based on untyped - * listeners, it is simple to build subsets of SWT for use on memory - * constrained, small footprint devices, by removing the classes and - * methods which implement the typed listener API. - * </p> - * - * @see Widget#addListener - * @see java.util.EventListener - * @see org.eclipse.swt.events - */ -public interface Listener { - -/** - * Sent when an event that the receiver has registered for occurs. - * - * @param event the event which occurred - */ -void handleEvent (Event event); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java deleted file mode 100644 index f22948a087..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are descriptions of monitors. - * - * @see Display - * @see <a href="http://www.eclipse.org/swt/snippets/#monitor">Monitor snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.0 - */ -public final class Monitor { - int /*long*/ handle; - int x, y, width, height; - int clientX, clientY, clientWidth, clientHeight; - -/** - * Prevents uninitialized instances from being created outside the package. - */ -Monitor () { -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode() - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Monitor)) return false; - Monitor monitor = (Monitor) object; - return handle == monitor.handle; -} - -/** - * Returns a rectangle describing the receiver's size and location - * relative to its device. Note that on multi-monitor systems the - * origin can be negative. - * - * @return the receiver's bounding rectangle - */ -public Rectangle getBounds () { - return new Rectangle (x, y, width, height); -} - -/** - * Returns a rectangle which describes the area of the - * receiver which is capable of displaying data. - * - * @return the client area - */ -public Rectangle getClientArea () { - return new Rectangle (clientX, clientY, clientWidth, clientHeight); -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ -public int hashCode () { - return (int)/*64*/handle; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java deleted file mode 100755 index 40a0e6b2b7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -/** - * Instances of this class are used to ensure that an - * application cannot interfere with the locking mechanism - * used to implement asynchronous and synchronous communication - * between widgets and background threads. - */ - -class RunnableLock { - Runnable runnable; - Thread thread; - Throwable throwable; - -RunnableLock (Runnable runnable) { - this.runnable = runnable; -} - -boolean done () { - return runnable == null || throwable != null; -} - -void run () { - if (runnable != null) runnable.run (); - runnable = null; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java deleted file mode 100755 index 5bcf914974..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.Compatibility; - -/** - * Instances of this class provide synchronization support - * for displays. A default instance is created automatically - * for each display, and this instance is sufficient for almost - * all applications. - * <p> - * <b>IMPORTANT:</b> Typical application code <em>never</em> - * needs to deal with this class. It is provided only to - * allow applications which require non-standard - * synchronization behavior to plug in the support they - * require. <em>Subclasses which override the methods in - * this class must ensure that the superclass methods are - * invoked in their implementations</em> - * </p> - * - * @see Display#setSynchronizer - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public class Synchronizer { - Display display; - int messageCount; - RunnableLock [] messages; - Object messageLock = new Object (); - Thread syncThread; - static final int GROW_SIZE = 4; - static final int MESSAGE_LIMIT = 64; - - //TEMPORARY CODE - static final boolean IS_CARBON = "carbon".equals (SWT.getPlatform ()); - static final boolean IS_GTK = "gtk".equals (SWT.getPlatform ()); - -/** - * Constructs a new instance of this class. - * - * @param display the display to create the synchronizer on - */ -public Synchronizer (Display display) { - this.display = display; -} - -void addLast (RunnableLock lock) { - boolean wake = false; - synchronized (messageLock) { - if (messages == null) messages = new RunnableLock [GROW_SIZE]; - if (messageCount == messages.length) { - RunnableLock[] newMessages = new RunnableLock [messageCount + GROW_SIZE]; - System.arraycopy (messages, 0, newMessages, 0, messageCount); - messages = newMessages; - } - messages [messageCount++] = lock; - wake = messageCount == 1; - } - if (wake) display.wakeThread (); -} - -/** - * Causes the <code>run()</code> method of the runnable to - * be invoked by the user-interface thread at the next - * reasonable opportunity. The caller of this method continues - * to run in parallel, and is not notified when the - * runnable has completed. - * - * @param runnable code to run on the user-interface thread. - * - * @see #syncExec - */ -protected void asyncExec (Runnable runnable) { - if (runnable == null) { - //TEMPORARY CODE - if (!(IS_CARBON || IS_GTK)) { - display.wake (); - return; - } - } - addLast (new RunnableLock (runnable)); -} - -int getMessageCount () { - synchronized (messageLock) { - return messageCount; - } -} - -void releaseSynchronizer () { - display = null; - messages = null; - messageLock = null; - syncThread = null; -} - -RunnableLock removeFirst () { - synchronized (messageLock) { - if (messageCount == 0) return null; - RunnableLock lock = messages [0]; - System.arraycopy (messages, 1, messages, 0, --messageCount); - messages [messageCount] = null; - if (messageCount == 0) { - if (messages.length > MESSAGE_LIMIT) messages = null; - } - return lock; - } -} - -boolean runAsyncMessages () { - return runAsyncMessages (false); -} - -boolean runAsyncMessages (boolean all) { - boolean run = false; - do { - RunnableLock lock = removeFirst (); - if (lock == null) return run; - run = true; - synchronized (lock) { - syncThread = lock.thread; - try { - lock.run (); - } catch (Throwable t) { - lock.throwable = t; - SWT.error (SWT.ERROR_FAILED_EXEC, t); - } finally { - syncThread = null; - lock.notifyAll (); - } - } - } while (all); - return run; -} - -/** - * Causes the <code>run()</code> method of the runnable to - * be invoked by the user-interface thread at the next - * reasonable opportunity. The thread which calls this method - * is suspended until the runnable completes. - * - * @param runnable code to run on the user-interface thread. - * - * @exception SWTException <ul> - * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li> - * </ul> - * - * @see #asyncExec - */ -protected void syncExec (Runnable runnable) { - RunnableLock lock = null; - synchronized (Device.class) { - if (display == null || display.isDisposed ()) SWT.error (SWT.ERROR_DEVICE_DISPOSED); - if (!display.isValidThread ()) { - if (runnable == null) { - display.wake (); - return; - } - lock = new RunnableLock (runnable); - /* - * Only remember the syncThread for syncExec. - */ - lock.thread = Thread.currentThread(); - addLast (lock); - } - } - if (lock == null) { - if (runnable != null) runnable.run (); - return; - } - synchronized (lock) { - boolean interrupted = false; - while (!lock.done ()) { - try { - lock.wait (); - } catch (InterruptedException e) { - interrupted = true; - } - } - if (interrupted) { - Compatibility.interrupt(); - } - if (lock.throwable != null) { - SWT.error (SWT.ERROR_FAILED_EXEC, lock.throwable); - } - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java deleted file mode 100644 index 53fadefae4..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; - -/** - * Instances of this class represent the system tray that is part - * of the task bar status area on some operating systems. - * - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see Display#getSystemTray - * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.0 - * @noextend This class is not intended to be subclassed by clients. - */ -public class Tray extends Widget { - int itemCount; - TrayItem [] items = new TrayItem [4]; - -Tray (Display display, int style) { - if (display == null) display = Display.getCurrent (); - if (display == null) display = Display.getDefault (); - if (!display.isValidThread ()) { - error (SWT.ERROR_THREAD_INVALID_ACCESS); - } - this.display = display; -} - -void createItem (TrayItem item, int index) { - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); - if (itemCount == items.length) { - TrayItem [] newItems = new TrayItem [items.length + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - System.arraycopy (items, index, items, index + 1, itemCount++ - index); - items [index] = item; -} - -void destroyItem (TrayItem item) { - int index = 0; - while (index < itemCount) { - if (items [index] == item) break; - index++; - } - if (index == itemCount) return; - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; -} - -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TrayItem getItem (int index) { - checkWidget (); - if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); - return items [index]; -} - -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget (); - return itemCount; -} - -/** - * Returns an array of <code>TrayItem</code>s which are the items - * in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TrayItem [] getItems () { - checkWidget (); - TrayItem [] result = new TrayItem [itemCount]; - System.arraycopy (items, 0, result, 0, result.length); - return result; -} - -void releaseChildren (boolean destroy) { - if (items != null) { - for (int i=0; i<items.length; i++) { - TrayItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - items = null; - } - super.releaseChildren (destroy); -} - -void releaseParent () { - super.releaseParent (); - if (display.tray == this) display.tray = null; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java deleted file mode 100755 index d352c1051d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.SWTEventListener; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class are <em>internal SWT implementation</em> - * objects which provide a mapping between the typed and untyped - * listener mechanisms that SWT supports. - * <p> - * <b>IMPORTANT:</b> This class is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It should never be - * referenced from application code. - * </p> - * - * @see Listener - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public class TypedListener implements Listener { - - /** - * The receiver's event listener - */ - protected SWTEventListener eventListener; - -/** - * Constructs a new instance of this class for the given event listener. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It should never be - * referenced from application code. - * </p> - * - * @param listener the event listener to store in the receiver - */ -public TypedListener (SWTEventListener listener) { - eventListener = listener; -} - -/** - * Returns the receiver's event listener. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It should never be - * referenced from application code. - * </p> - * - * @return the receiver's event listener - */ -public SWTEventListener getEventListener () { - return eventListener; -} - -/** - * Handles the given event. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It should never be - * referenced from application code. - * </p> - * @param e the event to handle - */ -public void handleEvent (Event e) { - switch (e.type) { - case SWT.Activate: { - ((ShellListener) eventListener).shellActivated(new ShellEvent(e)); - break; - } - case SWT.Arm: { - ((ArmListener) eventListener).widgetArmed (new ArmEvent (e)); - break; - } - case SWT.Close: { - /* Fields set by Decorations */ - ShellEvent event = new ShellEvent (e); - ((ShellListener) eventListener).shellClosed(event); - e.doit = event.doit; - break; - } - case SWT.Collapse: { - if (eventListener instanceof TreeListener) { - ((TreeListener) eventListener).treeCollapsed(new TreeEvent(e)); - } else { - ((ExpandListener) eventListener).itemCollapsed(new ExpandEvent(e)); - } - break; - } - case SWT.Deactivate: { - ((ShellListener) eventListener).shellDeactivated(new ShellEvent(e)); - break; - } - case SWT.Deiconify: { - ((ShellListener) eventListener).shellDeiconified(new ShellEvent(e)); - break; - } - case SWT.DefaultSelection: { - ((SelectionListener)eventListener).widgetDefaultSelected(new SelectionEvent(e)); - break; - } - case SWT.Dispose: { - ((DisposeListener) eventListener).widgetDisposed(new DisposeEvent(e)); - break; - } - case SWT.DragDetect: { - ((DragDetectListener) eventListener).dragDetected(new DragDetectEvent(e)); - break; - } - case SWT.Expand: { - if (eventListener instanceof TreeListener) { - ((TreeListener) eventListener).treeExpanded(new TreeEvent(e)); - } else { - ((ExpandListener) eventListener).itemExpanded(new ExpandEvent(e)); - } - break; - } - case SWT.FocusIn: { - ((FocusListener) eventListener).focusGained(new FocusEvent(e)); - break; - } - case SWT.FocusOut: { - ((FocusListener) eventListener).focusLost(new FocusEvent(e)); - break; - } - case SWT.Help: { - ((HelpListener) eventListener).helpRequested (new HelpEvent (e)); - break; - } - case SWT.Hide: { - ((MenuListener) eventListener).menuHidden(new MenuEvent(e)); - break; - } - case SWT.Iconify: { - ((ShellListener) eventListener).shellIconified(new ShellEvent(e)); - break; - } - case SWT.KeyDown: { - /* Fields set by Control */ - KeyEvent event = new KeyEvent(e); - ((KeyListener) eventListener).keyPressed(event); - e.doit = event.doit; - break; - } - case SWT.KeyUp: { - /* Fields set by Control */ - KeyEvent event = new KeyEvent(e); - ((KeyListener) eventListener).keyReleased(event); - e.doit = event.doit; - break; - } - case SWT.Modify: { - ((ModifyListener) eventListener).modifyText(new ModifyEvent(e)); - break; - } - case SWT.MenuDetect: { - MenuDetectEvent event = new MenuDetectEvent(e); - ((MenuDetectListener) eventListener).menuDetected(event); - e.x = event.x; - e.y = event.y; - e.doit = event.doit; - break; - } - case SWT.MouseDown: { - ((MouseListener) eventListener).mouseDown(new MouseEvent(e)); - break; - } - case SWT.MouseDoubleClick: { - ((MouseListener) eventListener).mouseDoubleClick(new MouseEvent(e)); - break; - } - case SWT.MouseEnter: { - ((MouseTrackListener) eventListener).mouseEnter (new MouseEvent (e)); - break; - } - case SWT.MouseExit: { - ((MouseTrackListener) eventListener).mouseExit (new MouseEvent (e)); - break; - } - case SWT.MouseHover: { - ((MouseTrackListener) eventListener).mouseHover (new MouseEvent (e)); - break; - } - case SWT.MouseMove: { - ((MouseMoveListener) eventListener).mouseMove(new MouseEvent(e)); - return; - } - case SWT.MouseWheel: { - ((MouseWheelListener) eventListener).mouseScrolled(new MouseEvent(e)); - return; - } - case SWT.MouseUp: { - ((MouseListener) eventListener).mouseUp(new MouseEvent(e)); - break; - } - case SWT.Move: { - ((ControlListener) eventListener).controlMoved(new ControlEvent(e)); - break; - } - case SWT.Paint: { - /* Fields set by Control */ - PaintEvent event = new PaintEvent (e); - ((PaintListener) eventListener).paintControl (event); - e.gc = event.gc; - break; - } - case SWT.Resize: { - ((ControlListener) eventListener).controlResized(new ControlEvent(e)); - break; - } - case SWT.Selection: { - /* Fields set by Sash */ - SelectionEvent event = new SelectionEvent (e); - ((SelectionListener) eventListener).widgetSelected (event); - e.x = event.x; - e.y = event.y; - e.doit = event.doit; - break; - } - case SWT.Show: { - ((MenuListener) eventListener).menuShown(new MenuEvent(e)); - break; - } - case SWT.Traverse: { - /* Fields set by Control */ - TraverseEvent event = new TraverseEvent (e); - ((TraverseListener) eventListener).keyTraversed (event); - e.detail = event.detail; - e.doit = event.doit; - break; - } - case SWT.Verify: { - /* Fields set by Text, RichText */ - VerifyEvent event = new VerifyEvent (e); - ((VerifyListener) eventListener).verifyText (event); - e.text = event.text; - e.doit = event.doit; - break; - } - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html deleted file mode 100755 index 6068615622..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> - <meta name="Author" content="IBM"> - <title>Package-level Javadoc</title> -</head> -<body> -SWT widget public API classes. -<h2> -Package Specification</h2> -This package contains the classes which make up the public SWT widget -API as well as the related public support classes (for example, class -<code>Event</code>). -</body> -</html> |