/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : Images.h                               */
/*                                                 */
/* Purpose: Image related functions.               */
/*                                                 */
/* Author : Merlyn Kline for Customer browser     */
/*          This source adapted by A.D.Hodgkinson  */
/*                                                 */
/* History: 28-Nov-96: Created with dummy function */
/*                     for temporary use in other  */
/*                     routines.                   */
/*          20-Jan-97: Filled in with most of the  */
/*                     functions present and       */
/*                     converted to the new data   */
/*                     structures where needed.    */
/*          15-Mar-97: Reorganised a bit, putting  */
/*                     functions in a more logical */
/*                     order to aid legibility.    */
/***************************************************/

/* Size reported for an image if it's data isn't present and no other size information can be found */

#define ImageDefaultOSSize_X 48
#define ImageDefaultOSSize_Y 48

/* The image_info structure is used for the image handling code, */
/* where each image has associated data about its size, fetch    */
/* status and so-on.                                             */

struct browser_data;

typedef struct image_info
{
  unsigned int          handle;         /* URL fetch handle for this image                              */
  Image               * istore;         /* Imagetrans pointer                                           */
  browser_data        * owner;          /* Owner of this structure                                      */

  int                   x;              /* X position on the page for the owner                         */
  int                   y;              /* Y position on the page for the owner                         */

  int                   dataoffset;     /* Offset of image data within image data block                 */
  int                   alloc;          /* Total space allocated in flex block                          */
  int                   ualloc;         /* Space allocated to url in flex block                         */
  int                   isize;          /* Size of image storage used                                   */
  HStream             * token;          /* Token this image appears in                                  */

  int                   currw;          /* Current width of image                                       */
  int                   currh;          /* Current height of image                                      */

  int                   xref;           /* Cross-reference to image record with same url                */

  int                   bytesgot;       /* Total bytes fetched for this image so far                    */

  unsigned int          fetched     :1; /* Flag indicating the image is fetched                         */
  unsigned int          delayed     :1; /* Flag indicating the image is delayed (by delayimages option) */
  unsigned int          success     :1; /* This image completed fetching without errors                 */
  unsigned int          fixedsize   :1; /* The size has been fixed in the HTML                          */
  unsigned int          started     :1; /* The fetch has started to happen                              */
  unsigned int          priority    :1; /* 1 = show the image regardless of any global settings         */
  unsigned int          hadfirst    :1; /* 1 = image has had image_update_image called for it           */
  unsigned int          canredraw   :1; /* 1 = image may be redrawn, else is waiting for a reformat     */

} image_info;

/* Function prototypes */

_kernel_oserror * image_new_image                (browser_data * b, const char * url, HStream * token, int background);
void              image_abort_fetches            (browser_data * b);
_kernel_oserror * image_process_null             (browser_data * b);
_kernel_oserror * image_discard                  (browser_data * b);
void              image_reload                   (browser_data * b, HStream * token);
void              image_delay_fetches            (browser_data * b);
void              image_restart_fetches          (browser_data * b);

int               image_animate_images           (int eventcode, WimpPollBlock * block, IdBlock * idb, browser_data * handle);
_kernel_oserror * image_fill_background          (void * handle, int * i);

_kernel_oserror * image_redraw                   (browser_data * b, WimpRedrawWindowBlock * r, HStream * token, int x, int y);
int               image_tile_window              (browser_data * b, WimpRedrawWindowBlock * r, int xorigin, int yorigin);
void              image_mark_as_redrawable       (browser_data * b, int image);
void              image_token_check_redrawable   (browser_data * b, HStream * token);

_kernel_oserror * image_mode_change              (void);

int               image_fetching                 (browser_data * b);
int               image_fetched                  (browser_data * b, int image);
int               image_token_fetched            (browser_data * b, HStream * token);
int               image_total_bytes_fetched      (browser_data * b);
int               image_count_pending            (browser_data * b);
int               image_count_specific_pending   (browser_data * b);
int               image_count_delayed            (browser_data * b);
int               image_plot_started             (browser_data * b, int image);
int               image_token_plot_started       (browser_data * b, HStream * token);

_kernel_oserror * image_get_token_image_size     (browser_data * b, HStream * token, BBox * box);
_kernel_oserror * image_get_back_image_size      (browser_data * b, BBox * box);
int               image_get_token_image_position (browser_data * b, HStream * t, int * x, int * y);
int               image_set_token_image_position (browser_data * b, HStream * t, int x, int y);

void              image_convert_to_pixels        (browser_data * b, HStream * token, int * x, int * y);
_kernel_oserror * image_return_click_offset      (browser_data * b, HStream * t, WimpGetPointerInfoBlock * i, int * x, int * y);