Changeset 110
- Timestamp:
- Mar 16, 2008, 1:19:21 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/gamma.cpp
r106 r110 24 24 25 25 extern int dev_ok; 26 palette *old_pal =NULL;26 palette *old_pal = NULL; 27 27 28 28 class gray_picker : public spicker 29 29 { 30 30 public: 31 32 33 34 35 36 screen->bar( x, y, x2, y2, 0);37 screen->bar( x, y, x2 - 3, y2, sc + num);38 if( active)39 40 screen->rectangle( x, y, x2, y2, 255);41 42 43 void set_pos( int x) { cur_sel = x; }44 45 46 47 48 49 gray_picker( int X, int Y, int ID, int start, int current, ifield *Next) : spicker( X, Y, ID, 1, 20, 0, 0, Next)50 51 52 53 54 55 31 int sc; 32 virtual void draw_item(image *screen, int x, int y, int num, int active) 33 { 34 long x2 = x + item_width() - 1; 35 long y2 = y + item_height() - 1; 36 screen->bar(x, y, x2, y2, 0); 37 screen->bar(x, y, x2 - 3, y2, sc + num); 38 if(active) 39 { 40 screen->rectangle(x, y, x2, y2, 255); 41 } 42 } 43 void set_pos(int x) { cur_sel = x; } 44 virtual int total() { return 32; } 45 virtual int item_width() { return 12; } 46 virtual int item_height() { return 20; } 47 virtual int activate_on_mouse_move() { return 0; } 48 49 gray_picker(int X, int Y, int ID, int start, int current, ifield *Next) : spicker(X, Y, ID, 1, 20, 0, 0, Next) 50 { 51 cur_sel = current; 52 sc = start; 53 reconfigure(); 54 cur_sel=current; 55 } 56 56 }; 57 57 … … 59 59 void gamma_correct(palette *&pal, int force_menu) 60 60 { 61 long dg=0,old_dg=0; 62 int abort=0; 63 64 // see if user has already done this routine 65 Cell *gs = find_symbol("darkest_gray"); 66 67 if( old_pal ) 68 { 69 delete pal; 70 pal = old_pal; 71 old_pal = NULL; 72 } 73 74 if( gs && DEFINEDP(symbol_value(gs)) && !force_menu ) 75 { 76 dg = lnumber_value( symbol_value( gs ) ); 77 } 78 else 79 { 80 if( gs && DEFINEDP( symbol_value( gs ) ) ) 81 { 82 dg = old_dg = lnumber_value( symbol_value( gs ) ); 83 } 84 // load in a fine gray palette they can chose from 85 palette *gray_pal = pal->copy(); 86 int i = 0; 87 int tc = 32; 88 89 for( ;i < tc; i++ ) 90 { 91 gray_pal->set( i, i * 4, i * 4, i * 4 ); 92 } 93 94 gray_pal->load(); 95 96 int wm_bc = wm->bright_color(), wm_mc = wm->medium_color(), wm_dc = wm->dark_color(); 97 98 int br_r = pal->red( wm_bc ) + 20; 99 if( br_r > 255) 100 { 101 br_r = 255; 102 } 103 int br_g = pal->green( wm_bc ) + 20; 104 if( br_g > 255 ) 105 { 106 br_g = 255; 107 } 108 int br_b = pal->blue( wm_bc ) + 20; 109 if( br_b > 255 ) 110 { 111 br_b = 255; 112 } 113 114 int md_r = pal->red( wm_mc ) - 20; 115 if( md_r < 0 ) 116 { 117 md_r = 0; 118 } 119 int md_g = pal->green( wm_mc ) - 20; 120 if( md_g < 0 ) 121 { 122 md_g = 0; 123 } 124 int md_b = pal->blue( wm_mc ) - 20; 125 if( md_b < 0 ) 126 { 127 md_b = 0; 128 } 129 130 int dr_r = pal->red( wm_dc ) - 40; 131 if( dr_r < 0 ) 132 { 133 dr_r = 0; 134 } 135 int dr_g = pal->green( wm_dc ) - 40; 136 if( dr_g < 0 ) 137 { 138 dr_g = 0; 139 } 140 int dr_b = pal->blue( wm_dc ) - 40; 141 if( dr_b < 0 ) 142 { 143 dr_b = 0; 144 } 145 146 wm->set_colors( gray_pal->find_closest( br_r, br_g, br_b ), 147 gray_pal->find_closest( md_r, md_g, md_b ), 148 gray_pal->find_closest( dr_r, dr_g, dr_b ) ); 149 150 int wl = WINDOW_FRAME_LEFT, wh = WINDOW_FRAME_TOP; 151 int sh = wm->font()->height() + 35; 152 button *but = new button( wl + 5, wh + 5 + sh * 3, ID_GAMMA_OK, cash.img( ok_button ), 153 new info_field( wl + 35, wh + 10 + sh * 3, ID_NULL, lang_string( "gamma_msg" ), 0 ) ); 154 155 gray_picker *gp = new gray_picker( wl + 2, wh + 5 + sh * 1, ID_GREEN_PICKER, 0, dg / 4, but); 156 gp->set_pos( dg / 4 ); 157 158 jwindow *gw = wm->new_window( xres / 2 - 190, yres / 2 - 90, -1, -1, gp); 159 160 event ev; 161 wm->flush_screen(); 162 do 163 { 164 do 165 { 166 wm->get_event(ev); 167 } while( ev.type == EV_MOUSE_MOVE && wm->event_waiting() ); 168 wm->flush_screen(); 169 if( ev.type == EV_CLOSE_WINDOW) 170 { 171 abort = 1; 172 } 173 if( ev.type == EV_KEY && ev.key == JK_ESC) 174 { 175 abort = 1; 176 } 177 } while( !abort && ( ev.type != EV_MESSAGE || ev.message.id != ID_GAMMA_OK ) ); 178 179 dg = ( (spicker *)gw->inm->get( ID_GREEN_PICKER ) )->first_selected() * 4; 180 181 wm->close_window( gw ); 182 wm->flush_screen(); 183 184 wm->set_colors( wm_bc, wm_mc, wm_dc); 185 delete gray_pal; 186 187 if( !abort ) 188 { 189 char *gammapath; 190 FILE *fp; 191 192 gammapath = (char *)jmalloc( strlen( get_save_filename_prefix() ) + 10, "gammapath" ); 193 sprintf( gammapath, "%sgamma.lsp", get_save_filename_prefix() ); 194 fp = open_FILE( gammapath, "wb" ); 195 if( fp ) 196 { 197 fprintf( fp, "(setq darkest_gray %ld)\n", dg ); 198 fclose(fp); 199 int sp = current_space; 200 current_space = PERM_SPACE; 201 set_symbol_value( make_find_symbol("darkest_gray"), new_lisp_number( dg ) ); 202 203 current_space = sp; 204 } 205 else 206 { 207 dprintf( "Unable to write to file gamma.lsp\n" ); 208 } 209 jfree( gammapath); 210 } 211 } 212 213 if( abort ) 214 { 215 dg = old_dg; 216 } 217 218 if( dg < 1 ) 219 { 220 dg = 1; 221 } 222 else if( dg > 128 ) 223 { 224 dg = 128; 225 } 226 227 double gamma = log( dg / 255.0 ) / log( 16.0 / 255.0 ); 228 229 old_pal = pal; 230 pal = new palette; 231 for( int i = 0; i < 256; i++ ) 232 { 233 uint8_t oldr, oldg, oldb; 234 old_pal->get( i, oldr, oldg, oldb ); 235 pal->set( i, (int)( pow( oldr / 255.0, gamma ) * 255 ), 236 (int)( pow( oldg / 255.0, gamma ) * 255 ), 237 (int)( pow( oldb / 255.0, gamma ) * 255 ) ); 238 } 239 240 pal->load(); 61 long dg=0,old_dg=0; 62 int abort=0; 63 64 // see if user has already done this routine 65 Cell *gs = find_symbol("darkest_gray"); 66 67 if(old_pal) 68 { 69 delete pal; 70 pal = old_pal; 71 old_pal = NULL; 72 } 73 74 if(gs && DEFINEDP(symbol_value(gs)) && !force_menu) 75 { 76 dg = lnumber_value(symbol_value(gs)); 77 } 78 else 79 { 80 if(gs && DEFINEDP(symbol_value(gs))) 81 { 82 dg = old_dg = lnumber_value(symbol_value(gs)); 83 } 84 // load in a fine gray palette they can chose from 85 palette *gray_pal = pal->copy(); 86 int i = 0; 87 int tc = 32; 88 89 for(;i < tc; i++) 90 { 91 gray_pal->set(i, i * 4, i * 4, i * 4); 92 } 93 94 gray_pal->load(); 95 96 int wm_bc = wm->bright_color(), wm_mc = wm->medium_color(), wm_dc = wm->dark_color(); 97 98 int br_r = pal->red(wm_bc) + 20; 99 if(br_r > 255) 100 br_r = 255; 101 int br_g = pal->green(wm_bc) + 20; 102 if(br_g > 255) 103 br_g = 255; 104 int br_b = pal->blue(wm_bc) + 20; 105 if(br_b > 255) 106 br_b = 255; 107 108 int md_r = pal->red(wm_mc) - 20; 109 if(md_r < 0) 110 md_r = 0; 111 int md_g = pal->green(wm_mc) - 20; 112 if(md_g < 0) 113 md_g = 0; 114 int md_b = pal->blue(wm_mc) - 20; 115 if(md_b < 0) 116 md_b = 0; 117 118 int dr_r = pal->red(wm_dc) - 40; 119 if(dr_r < 0) 120 dr_r = 0; 121 int dr_g = pal->green(wm_dc) - 40; 122 if(dr_g < 0) 123 dr_g = 0; 124 int dr_b = pal->blue(wm_dc) - 40; 125 if(dr_b < 0) 126 dr_b = 0; 127 128 wm->set_colors(gray_pal->find_closest(br_r, br_g, br_b), 129 gray_pal->find_closest(md_r, md_g, md_b), 130 gray_pal->find_closest(dr_r, dr_g, dr_b)); 131 132 int wl = WINDOW_FRAME_LEFT, wh = WINDOW_FRAME_TOP; 133 int sh = wm->font()->height() + 35; 134 button *but = new button(wl + 5, wh + 5 + sh * 3, ID_GAMMA_OK, cash.img(ok_button), 135 new info_field(wl + 35, wh + 10 + sh * 3, ID_NULL, lang_string("gamma_msg"), 0)); 136 137 gray_picker *gp = new gray_picker(wl + 2, wh + 5 + sh * 1, ID_GREEN_PICKER, 0, dg / 4, but); 138 gp->set_pos(dg / 4); 139 140 jwindow *gw = wm->new_window(xres / 2 - 190, yres / 2 - 90, -1, -1, gp); 141 142 event ev; 143 wm->flush_screen(); 144 do 145 { 146 do 147 { 148 wm->get_event(ev); 149 } while(ev.type == EV_MOUSE_MOVE && wm->event_waiting()); 150 wm->flush_screen(); 151 if(ev.type == EV_CLOSE_WINDOW) 152 abort = 1; 153 if(ev.type == EV_KEY && ev.key == JK_ESC) 154 abort = 1; 155 } while(!abort && (ev.type != EV_MESSAGE || ev.message.id != ID_GAMMA_OK)); 156 157 dg = ((spicker *)gw->inm->get(ID_GREEN_PICKER))->first_selected() * 4; 158 159 wm->close_window(gw); 160 wm->flush_screen(); 161 162 wm->set_colors(wm_bc, wm_mc, wm_dc); 163 delete gray_pal; 164 165 if(!abort) 166 { 167 char *gammapath; 168 FILE *fp; 169 170 gammapath = (char *)jmalloc(strlen(get_save_filename_prefix()) + 10, "gammapath"); 171 sprintf(gammapath, "%sgamma.lsp", get_save_filename_prefix()); 172 fp = open_FILE(gammapath, "wb"); 173 if(fp) 174 { 175 fprintf(fp, "(setq darkest_gray %ld)\n", dg); 176 fclose(fp); 177 int sp = current_space; 178 current_space = PERM_SPACE; 179 set_symbol_value(make_find_symbol("darkest_gray"), new_lisp_number(dg)); 180 181 current_space = sp; 182 } 183 else 184 { 185 dprintf("Unable to write to file gamma.lsp\n"); 186 } 187 jfree(gammapath); 188 } 189 } 190 191 if(abort) 192 dg = old_dg; 193 194 if(dg < 1) 195 dg = 1; 196 else if(dg > 128) 197 dg = 128; 198 199 double gamma = log(dg / 255.0) / log(16.0 / 255.0); 200 201 old_pal = pal; 202 pal = new palette; 203 for(int i = 0; i < 256; i++) 204 { 205 uint8_t oldr, oldg, oldb; 206 old_pal->get(i, oldr, oldg, oldb); 207 pal->set(i, (int)(pow(oldr / 255.0, gamma) * 255), 208 (int)(pow(oldg / 255.0, gamma) * 255), 209 (int)(pow(oldb / 255.0, gamma) * 255)); 210 } 211 212 pal->load(); 241 213 }
Note: See TracChangeset
for help on using the changeset viewer.