1 /* vim:expandtab:ts=2 sw=2: 2 */ 3 /* Grafx2 - The Ultimate 256-color bitmap paint program 4 5 Copyright owned by various GrafX2 authors, see COPYRIGHT.txt for details. 6 7 Grafx2 is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; version 2 10 of the License. 11 12 Grafx2 is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Grafx2; if not, see <http://www.gnu.org/licenses/> 19 */ 20 ////////////////////////////////////////////////////////////////////////////// 21 ///@file misc.h 22 /// Miscellanous unsorted functions. 23 ////////////////////////////////////////////////////////////////////////////// 24 25 #ifndef MISC_H__ 26 #define MISC_H__ 27 28 /* For sprintf() used in Num2str() and Dec2str(a,b,c) */ 29 #include <stdio.h> 30 31 #include "struct.h" 32 #include "global.h" 33 34 #define SWAP_BYTES(a,b) { byte c=a; a=b; b=c;} 35 #define SWAP_WORDS(a,b) { word c=a; a=b; b=c;} 36 #define SWAP_DWORDS(a,b) { dword c=a; a=b; b=c;} 37 #define SWAP_SHORTS(a,b) { short c=a; a=b; b=c;} 38 #define SWAP_FLOATS(a,b) { float c=a; a=b; b=c;} 39 #define SWAP_PBYTES(a,b) { byte * c=a; a=b; b=c;} 40 41 void Copy_image_to_brush(short start_x,short start_y,short Brush_width,short Brush_height,word image_width); 42 void Remap_general_lowlevel(byte * conversion_table,byte * in_buffer, byte *out_buffer,short width,short height,short buffer_width); 43 void Scroll_picture(byte * main_src, byte * main_dest, short x_offset,short y_offset); 44 void Wait_end_of_click(void); 45 void Set_color(byte color, byte red, byte green, byte blue); 46 const T_Components * Get_current_palette(void); 47 void Set_palette(T_Palette palette); 48 void Clear_current_image(byte color); 49 void Clear_current_image_with_stencil(byte color, byte * stencil); 50 dword Round_div(dword numerator,dword divisor); 51 word Count_used_colors(dword * usage); 52 word Count_used_colors_area(dword* usage, word start_x, word start_y, word width, word height); 53 word Count_used_colors_screen_area(dword* usage, word start_x, word start_y, word width, word height); 54 void Pixel_in_brush (word x,word y,byte color); 55 byte Read_pixel_from_spare_screen(word x,word y); 56 byte Read_pixel_from_backup_screen (word x,word y); 57 byte Read_pixel_from_feedback_screen (word x,word y); 58 byte Read_pixel_from_brush (word x,word y); 59 60 // Gestion du chrono dans les fileselects 61 void Init_chrono(dword delay); 62 void Check_timer(void); 63 64 void Replace_colors_within_limits(byte * replace_table); 65 66 byte Effect_interpolated_colorize (word x,word y,byte color); 67 byte Effect_additive_colorize (word x,word y,byte color); 68 byte Effect_substractive_colorize(word x,word y,byte color); 69 byte Effect_alpha_colorize(word x,word y,byte color); 70 byte Effect_sieve(word x,word y); 71 72 /// 73 /// Inverts a pixel buffer, according to a horizontal axis. 74 /// @param src Pointer to the pixel buffer to process. 75 /// @param width Width of the buffer. 76 /// @param height Height of the buffer. 77 void Flip_Y_lowlevel(byte *src, short width, short height); 78 79 /// 80 /// Inverts a pixel buffer, according to a vertical axis. 81 /// @param src Pointer to the pixel buffer to process. 82 /// @param width Width of the buffer. 83 /// @param height Height of the buffer. 84 void Flip_X_lowlevel(byte *src, short width, short height); 85 /// 86 /// Rotate a pixel buffer by 90 degrees, clockwise. 87 /// @param source Source pixel buffer. 88 /// @param dest Destination pixel buffer. 89 /// @param width Width of the original buffer (height of the destination one). 90 /// @param height Height of the original buffer (width of the destination one). 91 void Rotate_90_deg_lowlevel(byte * source, byte * dest, short width, short height); 92 /// 93 /// Rotate a pixel buffer by 90 degrees, counter-clockwise. 94 /// @param source Source pixel buffer. 95 /// @param dest Destination pixel buffer. 96 /// @param width Width of the original buffer (height of the destination one). 97 /// @param height Height of the original buffer (width of the destination one). 98 void Rotate_270_deg_lowlevel(byte * source, byte * dest, short width, short height); 99 /// 100 /// Rotate a pixel buffer by 180 degrees. 101 /// @param src The pixel buffer (source and destination). 102 /// @param width Width of the buffer. 103 /// @param height Height of the buffer. 104 void Rotate_180_deg_lowlevel(byte *src, short width, short height); 105 106 /// 107 /// Copies an image to another, rescaling it and optionally flipping it. 108 /// @param src_buffer Original image (address of first byte) 109 /// @param src_width Original image's width in pixels 110 /// @param src_height Original image's height in pixels 111 /// @param dst_buffer Destination image (address of first byte) 112 /// @param dst_width Destination image's width in pixels 113 /// @param dst_height Destination image's height in pixels 114 /// @param x_flipped Boolean, true to flip the image horizontally 115 /// @param y_flipped Boolean, true to flip the image vertically 116 void Rescale(byte *src_buffer, short src_width, short src_height, byte *dst_buffer, short dst_width, short dst_height, short x_flipped, short y_flipped); 117 118 void Zoom_a_line(byte * original_line,byte * zoomed_line,word factor,word width); 119 void Copy_part_of_image_to_another(byte * source,word source_x,word source_y,word width,word height,word source_width,byte * dest,word dest_x,word dest_y,word destination_width); 120 121 // -- Gestion du chrono -- 122 GFX2_GLOBAL byte Timer_state; // State du chrono: 0=Attente d'un Xème de seconde 123 // 1=Il faut afficher la preview 124 // 2=Plus de chrono à gerer pour l'instant 125 GFX2_GLOBAL dword Timer_delay; // Nombre de 18.2ème de secondes demandés 126 GFX2_GLOBAL dword Timer_start; // Heure de départ du chrono 127 128 #define Num2str(a,b,c) snprintf(b,sizeof(b),"%*lu",(int)c,(unsigned long)(a)) 129 130 #define Dec2str(a,b,c) sprintf(b,"%.*f",c,(double)(a)) 131 132 short Round(float value); 133 short Round_div_max(short numerator,short divisor); 134 135 /* round number n to d decimal points */ 136 double Fround(double n, unsigned d); 137 138 139 140 int Min(int a,int b); 141 int Max(int a,int b); 142 143 const char* Mode_label(int mode); 144 int Convert_videomode_arg(const char *argument); 145 146 #endif 147