1 /* 2 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 3 * and associated documentation files (the "Software"), to deal in the Software without restriction, 4 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 5 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 6 * subject to the following conditions: 7 * 8 * The above copyright notice and this permission notice shall be included in all copies or substantial 9 * portions of the Software. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 12 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 13 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 14 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 15 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 * 17 * Authors: 18 * Alexandre Pigolkine (pigolkine@gmx.de) 19 * Duncan Mak (duncan@ximian.com) 20 * Miguel de Icaza (miguel@ximian.com) 21 * Ravindra (rkumar@novell.com) 22 * Sanjay Gupta (gsanjay@novell.com) 23 * Vladimir Vukicevic (vladimir@pobox.com) 24 * Geoff Norton (gnorton@customerdna.com) 25 * Jonathan Gilbert (logic@deltaq.org) 26 * Sebastien Pouliot <sebastien@ximian.com> 27 * 28 * Copyright (C) 2003-2007 Novell, Inc (http://www.novell.com) 29 */ 30 31 /* 32 * NOTE: This is a private header files and everything is subject to changes. 33 */ 34 35 #ifndef __BITMAP_PRIVATE_H__ 36 #define __BITMAP_PRIVATE_H__ 37 38 #include "gdiplus-private.h" 39 #include "image-private.h" 40 41 #define COLOR_PALETTE_FLAGS_DEFAULT 0 42 #define COLOR_PALETTE_FLAGS_HAS_ALPHA 1 43 #define COLOR_PALETTE_FLAGS_GREYSCALE 2 44 #define COLOR_PALETTE_FLAGS_HALFTONE 4 45 46 /* LockMode (reserved) flags */ 47 #define GBD_OWN_SCAN0 (1<<8) 48 #define GBD_WRITE_OK (1<<9) 49 #define GBD_LOCKED (1<<10) 50 #define GBD_TRUE24BPP (1<<11) 51 52 #ifdef WORDS_BIGENDIAN 53 #define set_pixel_bgra(pixel,index,b,g,r,a) do { \ 54 ((unsigned char *)(pixel))[index] = a; \ 55 ((unsigned char *)(pixel))[index+1] = r; \ 56 ((unsigned char *)(pixel))[index+2] = g; \ 57 ((unsigned char *)(pixel))[index+3] = b; \ 58 } while (0) 59 #else 60 #define set_pixel_bgra(pixel,index,b,g,r,a) do { \ 61 ((unsigned char *)(pixel))[index] = b; \ 62 ((unsigned char *)(pixel))[index+1] = g; \ 63 ((unsigned char *)(pixel))[index+2] = r; \ 64 ((unsigned char *)(pixel))[index+3] = a; \ 65 } while (0) 66 #endif 67 #define get_pixel_bgra(color, b, g, r, a) do { \ 68 a = ((color & 0xff000000) >> 24); \ 69 r = ((color & 0x00ff0000) >> 16); \ 70 g = ((color & 0x0000ff00) >> 8); \ 71 b = (color & 0x000000ff); \ 72 } while(0) 73 74 /* This structure is mirrored in System.Drawing.Imaging.BitmapData. 75 Any changes here must also be made to BitmapData.cs */ 76 typedef struct { 77 unsigned int width; 78 unsigned int height; 79 int stride; 80 PixelFormat pixel_format; 81 BYTE *scan0; 82 UINT_PTR reserved; 83 /* the rest of the structure isn't part of MS GDI+ definition */ 84 ColorPalette *palette; 85 int property_count; /* Number of properties */ 86 PropertyItem *property; /* Properties associated with image */ 87 88 float dpi_horz; /* */ 89 float dpi_vert; /* */ 90 ImageFlags image_flags; /* Alpha, ColorSpace, etc. */ 91 92 unsigned int left; /* left display coordinate of frame */ 93 unsigned int top; /* top display coordinate of frame */ 94 unsigned int x; /* LockBits: left coordinate of locked rectangle */ 95 unsigned int y; /* LockBits: top coordinate of locked rectangle */ 96 97 int transparent; /* Index of transparent color (<24bit only) */ 98 } ActiveBitmapData; 99 100 typedef struct { 101 int count; /* Number of bitmaps contained in this frame */ 102 ActiveBitmapData *bitmap; /* Bitmaps for this frame */ 103 GUID frame_dimension; /* GUID describing the frame type */ 104 } FrameData; 105 106 typedef struct _Image { 107 /* Image Description */ 108 ImageType type; /* Undefined, Bitmap, MetaFile */ 109 ImageFormat image_format; /* BMP, TIF, GIF, PNG, etc. */ 110 /* Image Data */ 111 int num_of_frames; /* Number of frames */ 112 FrameData *frames; /* Array of frames (Page, Time, Resolution) for the image */ 113 /* Tracking of active image */ 114 int active_frame; /* Index of frame currently used */ 115 int active_bitmap_no; /* Index of active bitmap in current frame */ 116 ActiveBitmapData *active_bitmap; /* Pointer to active frame/bitmap; DO NOT free() */ 117 /* Internal fields */ 118 int cairo_format; 119 cairo_surface_t *surface; 120 } GpBitmap; 121 122 123 void gdip_bitmap_init (GpBitmap *bitmap) GDIP_INTERNAL; 124 125 GpBitmap *gdip_bitmap_new (void) GDIP_INTERNAL; 126 GpBitmap *gdip_bitmap_new_with_frame (const GUID *dimension, BOOL add_bitmapdata) GDIP_INTERNAL; 127 FrameData *gdip_frame_add(GpBitmap *bitmap, const GUID *dimension) GDIP_INTERNAL; 128 ActiveBitmapData *gdip_frame_add_bitmapdata(FrameData *frame) GDIP_INTERNAL; 129 GpStatus gdip_bitmap_dispose (GpBitmap *bitmap) GDIP_INTERNAL; 130 GpStatus gdip_bitmap_clone (GpBitmap *bitmap, GpBitmap **clonedbitmap) GDIP_INTERNAL; 131 GpStatus gdip_bitmap_setactive (GpBitmap *bitmap, const GUID *dimension, int index) GDIP_INTERNAL; 132 GpStatus gdip_bitmapdata_clone (ActiveBitmapData *src, ActiveBitmapData **dest, int count) GDIP_INTERNAL; 133 ColorPalette *gdip_palette_clone(ColorPalette *original) GDIP_INTERNAL; 134 GpStatus gdip_property_get_short (int offset, void *value, unsigned short *result) GDIP_INTERNAL; 135 GpStatus gdip_property_get_long (int offset, void *value, guint32 *result) GDIP_INTERNAL; 136 GpStatus gdip_property_get_srational (int offset, void *value, unsigned short *numerator, unsigned short *denominator) GDIP_INTERNAL; 137 GpStatus gdip_property_get_rational (int offset, void *value, guint32 *numerator, guint32 *denominator) GDIP_INTERNAL; 138 GpStatus gdip_bitmapdata_property_add (ActiveBitmapData *bitmap_data, PROPID id, ULONG length, WORD type, VOID *value) GDIP_INTERNAL; 139 GpStatus gdip_bitmapdata_property_add_byte (ActiveBitmapData *bitmap_data, PROPID id, BYTE value) GDIP_INTERNAL; 140 GpStatus gdip_bitmapdata_property_add_short (ActiveBitmapData *bitmap_data, PROPID id, unsigned short value) GDIP_INTERNAL; 141 GpStatus gdip_bitmapdata_property_add_long (ActiveBitmapData *bitmap_data, PROPID id, guint32 value) GDIP_INTERNAL; 142 GpStatus gdip_bitmapdata_property_add_ASCII (ActiveBitmapData *bitmap_data, PROPID id, unsigned char *value) GDIP_INTERNAL; 143 GpStatus gdip_bitmapdata_property_add_rational (ActiveBitmapData *bitmap_data, PROPID id, guint32 numerator, guint32 denominator) GDIP_INTERNAL; 144 GpStatus gdip_bitmapdata_property_add_srational (ActiveBitmapData *bitmap_data, PROPID id, unsigned short numerator, unsigned short denominator) GDIP_INTERNAL; 145 GpStatus gdip_bitmapdata_property_remove_id (ActiveBitmapData *bitmap_data, PROPID id) GDIP_INTERNAL; 146 GpStatus gdip_bitmapdata_property_remove_index (ActiveBitmapData *bitmap_data, int index) GDIP_INTERNAL; 147 GpStatus gdip_bitmapdata_property_find_id (ActiveBitmapData *bitmap_data, PROPID id, int *index) GDIP_INTERNAL; 148 149 cairo_surface_t* gdip_bitmap_ensure_surface (GpBitmap *bitmap) GDIP_INTERNAL; 150 void gdip_bitmap_flush_surface (GpBitmap *bitmap) GDIP_INTERNAL; 151 void gdip_bitmap_invalidate_surface (GpBitmap *bitmap) GDIP_INTERNAL; 152 GpBitmap* gdip_convert_indexed_to_rgb (GpBitmap *bitmap) GDIP_INTERNAL; 153 154 BOOL gdip_bitmap_format_needs_premultiplication (GpBitmap *bitmap) GDIP_INTERNAL; 155 BYTE* gdip_bitmap_get_premultiplied_scan0 (GpBitmap *bitmap) GDIP_INTERNAL; 156 void gdip_bitmap_get_premultiplied_scan0_inplace (GpBitmap *bitmap, BYTE *premul) GDIP_INTERNAL; 157 void gdip_bitmap_get_premultiplied_scan0_reverse (GpBitmap *bitmap, BYTE *premul) GDIP_INTERNAL; 158 159 GpStatus gdip_process_bitmap_attributes (GpBitmap *bitmap, void **dest, GpImageAttributes* attr, BOOL *allocated) GDIP_INTERNAL; 160 161 ColorPalette* gdip_create_greyscale_palette (int num_colors) GDIP_INTERNAL; 162 163 typedef struct { 164 Rect region; 165 int x, y; /* the offset of the next byte that will be loaded, once the buffer is depleted */ 166 unsigned short buffer; 167 int p; /* index of pixel within 'buffer' that was returned by the last call to gdip_pixel_stream_get_next () */ 168 int one_pixel_mask; 169 int one_pixel_shift; 170 int pixels_per_byte; /* a negative value is used to indicate a count of bytes per pixel for depths of more than 8 bits */ 171 ActiveBitmapData *data; 172 BYTE *scan; 173 } StreamingState; 174 175 GpStatus gdip_init_pixel_stream (StreamingState *state, ActiveBitmapData *data, int x, int y, int w, int h) GDIP_INTERNAL; 176 unsigned int gdip_pixel_stream_get_next (StreamingState *state) GDIP_INTERNAL; 177 178 #include "bitmap.h" 179 180 #endif 181