17dd7cddfSDavid du Colombier /* Copyright (C) 1989, 1993, 1996, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. 27dd7cddfSDavid du Colombier 3*593dc095SDavid du Colombier This software is provided AS-IS with no warranty, either express or 4*593dc095SDavid du Colombier implied. 57dd7cddfSDavid du Colombier 6*593dc095SDavid du Colombier This software is distributed under license and may not be copied, 7*593dc095SDavid du Colombier modified or distributed except as expressly authorized under the terms 8*593dc095SDavid du Colombier of the license contained in the file LICENSE in this distribution. 97dd7cddfSDavid du Colombier 10*593dc095SDavid du Colombier For more information about licensing, please refer to 11*593dc095SDavid du Colombier http://www.ghostscript.com/licensing/. For information on 12*593dc095SDavid du Colombier commercial licensing, go to http://www.artifex.com/licensing/ or 13*593dc095SDavid du Colombier contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14*593dc095SDavid du Colombier San Rafael, CA 94903, U.S.A., +1(415)492-9861. 157dd7cddfSDavid du Colombier */ 167dd7cddfSDavid du Colombier 17*593dc095SDavid du Colombier /* $Id: gxbitmap.h,v 1.6 2002/03/05 16:56:33 lpd Exp $ */ 187dd7cddfSDavid du Colombier /* Definitions for stored bitmaps for Ghostscript */ 197dd7cddfSDavid du Colombier 207dd7cddfSDavid du Colombier #ifndef gxbitmap_INCLUDED 217dd7cddfSDavid du Colombier # define gxbitmap_INCLUDED 227dd7cddfSDavid du Colombier 237dd7cddfSDavid du Colombier #include "gstypes.h" /* for gs_id */ 247dd7cddfSDavid du Colombier #include "gsbitmap.h" 257dd7cddfSDavid du Colombier 267dd7cddfSDavid du Colombier /* Define the gx version of a bitmap identifier. */ 277dd7cddfSDavid du Colombier typedef gs_bitmap_id gx_bitmap_id; 287dd7cddfSDavid du Colombier 297dd7cddfSDavid du Colombier /* Define the gx version of the "no identifier" value. */ 307dd7cddfSDavid du Colombier #define gx_no_bitmap_id gs_no_bitmap_id 317dd7cddfSDavid du Colombier 327dd7cddfSDavid du Colombier /* 33*593dc095SDavid du Colombier * Most graphics library procedures that process bitmap data (such as, for 34*593dc095SDavid du Colombier * example, the "device" procedures in gdevm*.c) impose two requirements 35*593dc095SDavid du Colombier * on such data: an alignment requirement, and a padding requirement. 36*593dc095SDavid du Colombier * Both requirements arise from the fact that these library procedures 37*593dc095SDavid du Colombier * attempt to process the bits in units of align_bitmap_mod bytes. 38*593dc095SDavid du Colombier * 39*593dc095SDavid du Colombier * The alignment requirement is that each scan line must start at an 40*593dc095SDavid du Colombier * address that is 0 mod align_bitmap_mod. This requirement is only for 41*593dc095SDavid du Colombier * the benefit of the hardware (which may, for example, require that 42*593dc095SDavid du Colombier * instructions fetching or storing a 'long' quantity only do so at an 43*593dc095SDavid du Colombier * address that is long-aligned), but it must be respected in all 44*593dc095SDavid du Colombier * platform-independent code. More precisely, platform-independent code 45*593dc095SDavid du Colombier * can *assume* that Ghostscript allocators return blocks that are adequately 46*593dc095SDavid du Colombier * aligned, and then must *ensure* that that alignment is not lost. (The 47*593dc095SDavid du Colombier * assumption is not true in some MSVC implementations, but even in those 48*593dc095SDavid du Colombier * implementations, the alignment is sufficient to satisfy the hardware. 49*593dc095SDavid du Colombier * See gsmemraw.h for more information about this.) 50*593dc095SDavid du Colombier * 51*593dc095SDavid du Colombier * The padding requirement is that if the last data byte being operated on 52*593dc095SDavid du Colombier * is at offset B relative to the start of the scan line, bytes up to and 53*593dc095SDavid du Colombier * including offset ROUND_UP(B + 1, align_bitmap_mod) - 1 may be accessed, 54*593dc095SDavid du Colombier * and therefore must be allocated (not cause hardware-level access faults). 557dd7cddfSDavid du Colombier */ 567dd7cddfSDavid du Colombier /* We assume arch_align_long_mod is 1-4 or 8. */ 577dd7cddfSDavid du Colombier #if arch_align_long_mod <= 4 587dd7cddfSDavid du Colombier # define log2_align_bitmap_mod 2 597dd7cddfSDavid du Colombier #else 607dd7cddfSDavid du Colombier #if arch_align_long_mod == 8 617dd7cddfSDavid du Colombier # define log2_align_bitmap_mod 3 627dd7cddfSDavid du Colombier #endif 637dd7cddfSDavid du Colombier #endif 647dd7cddfSDavid du Colombier #define align_bitmap_mod (1 << log2_align_bitmap_mod) 657dd7cddfSDavid du Colombier #define bitmap_raster(width_bits)\ 667dd7cddfSDavid du Colombier ((uint)((((width_bits) + (align_bitmap_mod * 8 - 1))\ 677dd7cddfSDavid du Colombier >> (log2_align_bitmap_mod + 3)) << log2_align_bitmap_mod)) 687dd7cddfSDavid du Colombier 697dd7cddfSDavid du Colombier /* 707dd7cddfSDavid du Colombier * Define the gx analogue of the basic bitmap structure. Note that since 717dd7cddfSDavid du Colombier * all scan lines must be aligned, the requirement on raster is: 727dd7cddfSDavid du Colombier * If size.y > 1, 737dd7cddfSDavid du Colombier * raster >= bitmap_raster(size.x * depth) 747dd7cddfSDavid du Colombier * raster % align_bitmap_mod = 0 757dd7cddfSDavid du Colombier */ 767dd7cddfSDavid du Colombier #define gx_bitmap_common(data_type) gs_bitmap_common(data_type) 777dd7cddfSDavid du Colombier typedef struct gx_bitmap_s { 787dd7cddfSDavid du Colombier gx_bitmap_common(byte); 797dd7cddfSDavid du Colombier } gx_bitmap; 807dd7cddfSDavid du Colombier typedef struct gx_const_bitmap_s { 817dd7cddfSDavid du Colombier gx_bitmap_common(const byte); 827dd7cddfSDavid du Colombier } gx_const_bitmap; 837dd7cddfSDavid du Colombier 847dd7cddfSDavid du Colombier /* 857dd7cddfSDavid du Colombier * Define the gx analogue of the tile bitmap structure. Note that if 867dd7cddfSDavid du Colombier * shift != 0 (for strip bitmaps, see below), size.y and rep_height 877dd7cddfSDavid du Colombier * mean something slightly different: see below for details. 887dd7cddfSDavid du Colombier */ 897dd7cddfSDavid du Colombier #define gx_tile_bitmap_common(data_type) gs_tile_bitmap_common(data_type) 907dd7cddfSDavid du Colombier typedef struct gx_tile_bitmap_s { 917dd7cddfSDavid du Colombier gx_tile_bitmap_common(byte); 927dd7cddfSDavid du Colombier } gx_tile_bitmap; 937dd7cddfSDavid du Colombier typedef struct gx_const_tile_bitmap_s { 947dd7cddfSDavid du Colombier gx_tile_bitmap_common(const byte); 957dd7cddfSDavid du Colombier } gx_const_tile_bitmap; 967dd7cddfSDavid du Colombier 977dd7cddfSDavid du Colombier /* 987dd7cddfSDavid du Colombier * For halftones at arbitrary angles, we provide for storing the halftone 997dd7cddfSDavid du Colombier * data as a strip that must be shifted in X for different values of Y. For 1007dd7cddfSDavid du Colombier * an ordinary (non-shifted) halftone that has a repetition width of W and a 1017dd7cddfSDavid du Colombier * repetition height of H, the pixel at coordinate (X,Y) corresponds to 1027dd7cddfSDavid du Colombier * halftone pixel (X mod W, Y mod H), ignoring phase; for a strip halftone 1037dd7cddfSDavid du Colombier * with strip shift S and strip height H, the pixel at (X,Y) corresponds to 1047dd7cddfSDavid du Colombier * halftone pixel ((X + S * floor(Y/H)) mod W, Y mod H). In other words, 1057dd7cddfSDavid du Colombier * each Y increment of H shifts the strip left by S pixels. 1067dd7cddfSDavid du Colombier * 1077dd7cddfSDavid du Colombier * As for non-shifted tiles, a strip bitmap may include multiple copies 1087dd7cddfSDavid du Colombier * in X or Y to reduce loop overhead. In this case, we must distinguish: 1097dd7cddfSDavid du Colombier * - The height of an individual strip, which is the same as 1107dd7cddfSDavid du Colombier * the height of the bitmap being replicated (rep_height, H); 1117dd7cddfSDavid du Colombier * - The height of the entire bitmap (size.y). 1127dd7cddfSDavid du Colombier * Similarly, we must distinguish: 1137dd7cddfSDavid du Colombier * - The shift per strip (rep_shift, S); 1147dd7cddfSDavid du Colombier * - The shift for the entire bitmap (shift). 1157dd7cddfSDavid du Colombier * Note that shift = (rep_shift * size.y / rep_height) mod rep_width, 1167dd7cddfSDavid du Colombier * so the shift member of the structure is only an accelerator. It is, 1177dd7cddfSDavid du Colombier * however, an important one, since it indicates whether the overall 1187dd7cddfSDavid du Colombier * bitmap requires shifting or not. 1197dd7cddfSDavid du Colombier * 1207dd7cddfSDavid du Colombier * Note that for shifted tiles, size.y is the size of the stored bitmap 1217dd7cddfSDavid du Colombier * (1 or more strips), and NOT the height of the actual tile. The latter 1227dd7cddfSDavid du Colombier * is not stored in the structure at all: it can be computed as H * W / 1237dd7cddfSDavid du Colombier * gcd(S, W). 1247dd7cddfSDavid du Colombier * 1257dd7cddfSDavid du Colombier * If the bitmap consists of a multiple of W / gcd(S, W) copies in Y, the 1267dd7cddfSDavid du Colombier * effective shift is zero, reducing it to a tile. For simplicity, we 1277dd7cddfSDavid du Colombier * require that if shift is non-zero, the bitmap height be less than H * W / 1287dd7cddfSDavid du Colombier * gcd(S, W). I.e., we don't allow strip bitmaps that are large enough to 1297dd7cddfSDavid du Colombier * include a complete tile but that don't include an integral number of 1307dd7cddfSDavid du Colombier * tiles. Requirements: 1317dd7cddfSDavid du Colombier * rep_shift < rep_width 1327dd7cddfSDavid du Colombier * shift = (rep_shift * (size.y / rep_height)) % rep_width 1337dd7cddfSDavid du Colombier */ 1347dd7cddfSDavid du Colombier #define gx_strip_bitmap_common(data_type)\ 1357dd7cddfSDavid du Colombier gx_tile_bitmap_common(data_type);\ 1367dd7cddfSDavid du Colombier ushort rep_shift;\ 1377dd7cddfSDavid du Colombier ushort shift 1387dd7cddfSDavid du Colombier typedef struct gx_strip_bitmap_s { 1397dd7cddfSDavid du Colombier gx_strip_bitmap_common(byte); 1407dd7cddfSDavid du Colombier } gx_strip_bitmap; 1417dd7cddfSDavid du Colombier typedef struct gx_const_strip_bitmap_s { 1427dd7cddfSDavid du Colombier gx_strip_bitmap_common(const byte); 1437dd7cddfSDavid du Colombier } gx_const_strip_bitmap; 1447dd7cddfSDavid du Colombier 1457dd7cddfSDavid du Colombier extern_st(st_gx_strip_bitmap); 1467dd7cddfSDavid du Colombier #define public_st_gx_strip_bitmap() /* in gspcolor.c */\ 1477dd7cddfSDavid du Colombier gs_public_st_suffix_add0_local(st_gx_strip_bitmap, gx_strip_bitmap,\ 1487dd7cddfSDavid du Colombier "gx_strip_bitmap", bitmap_enum_ptrs, bitmap_reloc_ptrs,\ 1497dd7cddfSDavid du Colombier st_gs_tile_bitmap) 1507dd7cddfSDavid du Colombier #define st_gx_strip_bitmap_max_ptrs 1 1517dd7cddfSDavid du Colombier 1527dd7cddfSDavid du Colombier #endif /* gxbitmap_INCLUDED */ 153