static void saywhat(NCURSES_CONST char *text) { WINDOW *win = statusline(); if (text != 0 && *text != '\0') { waddstr(win, text); waddstr(win, "; "); } waddstr(win, "press any key to continue"); }
static void show_position(NCURSES_CONST char *text, NCURSES_CONST char *also, int which, int ypos, int xpos) { WINDOW *win = statusline(); wprintw(win, "%s for panel %d now %d,%d%s", text, which, ypos, xpos, also); wmove(stdscr, ypos, xpos); }
/* ******************************************************************** */ int build_rac_index(void) { FILE *fdb; FILE *fndx; unsigned long call_offset = 0; unsigned long x = 0; char racdata[RAC_DATA_LEN+8]; char amacall_path[MAX_VALUE]; get_user_base_dir("data/AMACALL.ndx", amacall_path, sizeof(amacall_path)); /* ==================================================================== */ /* If the index file is there, exit */ /* */ if (filethere(amacall_path)) { /* if file is there make sure the index date is newer */ if(file_time(amacall_path)<=file_time(amacall_path)) { return(1); } else { // RAC index old, rebuilding statusline(langcode("STIFCC0103"), 1); fprintf(stderr,"RAC index is old. Rebuilding index.\n"); // XmTextFieldSetString(text,"RAC Index old rebuilding"); // XtManageChild(text); // XmUpdateDisplay(XtParent(text)); } } /* ==================================================================== */ /* Open the database and index file */ /* */ fdb=fopen(get_data_base_dir("fcc/AMACALL.LST"),"rb"); if (fdb==NULL) { fprintf(stderr,"Build:Could not open RAC data base: %s\n", get_data_base_dir("fcc/AMACALL.LST") ); return(0); } fndx=fopen(amacall_path,"w"); if (fndx==NULL) { fprintf(stderr,"Build:Could not open/create RAC data base index: %s\n", amacall_path ); (void)fclose(fdb); return(0); } /* ==================================================================== */ /* Skip past the header to the first callsign (VA2AA) */ /* */ memset(racdata, 0, sizeof(racdata)); while (!feof(fdb) && strncmp(racdata,"VA",2)) { call_offset = (unsigned long)ftell(fdb); if (fgets(racdata, (int)sizeof(racdata), fdb)==NULL) { fprintf(stderr,"Build:header:Unable to read data base\n"); (void)fclose(fdb); (void)fclose(fndx); fprintf(stderr,"rc=0\n"); return (0); } } /* ==================================================================== */ /* write out the current callsign and RBA of the db file */ /* skip 100 records and do it again until no more */ /* */ while (!feof(fdb)) { fprintf(fndx,"%6.6s%li\n",racdata,(long)call_offset); call_offset = (unsigned long)ftell(fdb); for (x=0;x<=100 && !feof(fdb);x++) if (fgets(racdata, (int)sizeof(racdata), fdb)==NULL) break; } (void)fclose(fdb); (void)fclose(fndx); // XmTextFieldSetString(text,""); // XtManageChild(text); return(1); }
int LYUpload( char *line ) { int eax; char *method, *directory; int method_number; int count; char *the_upload = 0; char tmpbuf[256]; char *filename = 0; lynx_list_item_type *upload_command = 0; char *the_command = 0; directory = strstr( line, "TO=" ); if ( directory != 0 ) { directory[ -1 ] = 0; directory += 3; method = strstr( line, "UPLOAD=" ); if ( method != 0 ) { method += 7; method_number = atoi( method ); count = 0; upload_command = uploaders; for ( ; count < method_number; upload_command = &upload_command ) { count++; //upload_command = &upload_command; } if ( upload_command->command == 0 ) { HTAlert( gettext( "ERROR! - upload command is misconfigured" ) ); } if ( HTCountCommandArgs( upload_command->command ) != 0 ) { mustshow = 1; statusline( gettext( "Enter a filename: " ) ); do { tmpbuf[0] = 0; if ( LYgetstr( tmpbuf, 0, 256, 0 ) >= 0 && ( tmpbuf[0] & 255 ) != 0 ) { if ( strstr( tmpbuf, "../" ) != 0 ) { HTAlert( gettext( "Illegal redirection \"../\" found! Request ignored." ) ); } if ( strchr( tmpbuf, 47 ) != 0 ) { HTAlert( gettext( "Illegal character \"/\" found! Request ignored." ) ); } if ( tmpbuf[0] == '~' ) { HTAlert( gettext( "Illegal redirection using \"~\" found! Request ignored." ) ); } HTSprintf0( &filename, "%s/%s", directory, tmpbuf[0] ); if ( filename[0] == '|' ) { HTAlert( gettext( "Cannot write to file." ) ); mustshow = 1; statusline( gettext( "Enter a new filename: " ) ); } switch ( LYValidateOutput( filename ) ) { case 89: if ( ( WWW_TraceFlag & 255 ) != 0 ) { fprintf( TraceFP( ), "LYUpload: filename is %s", filename ); } break; default: HTInfoMsg( gettext( "Cancelling!" ) ); if ( ( 0 ^ 0 ) != 0 ) { __stack_chk_fail( ); break; } break; } } } while ( ( LYCanWriteFile( filename ) & 255 ) == 0 ); HTAddParam( &the_upload, upload_command->command, 1, filename ); HTEndParam( &the_upload, upload_command->command, 1 ); } else { HTSACopy( &the_upload, upload_command->command ); HTAddParam( &the_command, "cd %s ; ", 1, directory ); HTEndParam( &the_command, "cd %s ; ", 1 ); HTSACat( &the_command, the_upload ); if ( ( WWW_TraceFlag & 255 ) != 0 ) { fprintf( TraceFP( ), "command: %s\n", the_command ); } stop_curses( ); LYSystem( the_command ); start_curses( ); if ( the_command != 0 ) { free( the_command ); the_command = 0; } if ( the_upload != 0 ) { free( the_upload ); the_upload = 0; } if ( filename != 0 ) chmod( filename, 384 ); if ( filename != 0 ) { free( filename ); filename = 0; } } } } HTAlert( gettext( "Unable to upload file." ) ); }
/* * A command consists of one or more letter/digit pairs separated by a space. * Digits are limited to 1..MAX_PANELS. * * End the command with a newline. Reject other characters. */ static bool get_command(PANEL * px[MAX_PANELS + 1], char *buffer, int limit) { int length = 0; int y0, x0; int c0, ch; WINDOW *win; getyx(stdscr, y0, x0); win = statusline(); waddstr(win, "Command:"); buffer[length = 0] = '\0'; if (log_in != 0) { if (fgets(buffer, limit - 3, log_in) != 0) { length = (int) strlen(buffer); while (length > 0 && isspace(UChar(buffer[length - 1]))) buffer[--length] = '\0'; waddstr(win, buffer); } else { close_input(); } (void) wgetch(win); } else { c0 = 0; for (;;) { ch = wgetch(win); if (ch == ERR || ch == QUIT || ch == ESCAPE) { buffer[0] = '\0'; break; } else if (ch == CTRL('L')) { wrefresh(curscr); } else if (ch == '\n' || ch == KEY_ENTER) { break; } else if (ch == '?') { show_panels(px); } else if (length + 3 < limit) { if (ch >= KEY_MIN) { beep(); } else if (ok_letter(UChar(ch))) { if (isalpha(UChar(c0))) { beep(); } else if (isdigit(UChar(c0))) { wprintw(win, " %c", ch); buffer[length++] = ' '; buffer[length++] = (char) (c0 = ch); } else { wprintw(win, "%c", ch); buffer[length++] = (char) (c0 = ch); } } else if (ok_digit(ch)) { if (isalpha(UChar(c0))) { wprintw(win, "%c", ch); buffer[length++] = (char) (c0 = ch); } else { beep(); } } else if (ch == ' ') { if (isdigit(UChar(c0))) { wprintw(win, "%c", ch); buffer[length++] = (char) (c0 = ch); } else { beep(); } } else { beep(); } } else { beep(); } } } wmove(stdscr, y0, x0); buffer[length] = '\0'; if (log_out && length) { fprintf(log_out, "%s\n", buffer); } return (length != 0); }
void draw_tiger_map (Widget w, char *filenm, int destination_pixmap, int nocache) { // For future implementation of a "refresh cached map" option char file[MAX_FILENAME]; // Complete path/name of image file char short_filenm[MAX_FILENAME]; FILE *f; // Filehandle of image file char fileimg[MAX_FILENAME]; // Ascii name of image file, read from GEO file char tigertmp[MAX_FILENAME*2]; // Used for putting together the tigermap query int width, height; tiepoint tp[2]; // Calibration points for map, read in from .geo file register long map_c_T, map_c_L; // map delta NW edge coordinates, DNN: these should be signed register long tp_c_dx, tp_c_dy; // tiepoint coordinate differences unsigned long c_x_min, c_y_min;// top left coordinates of map inside screen unsigned long c_y_max; // bottom right coordinates of map inside screen double c_x; // Xastir coordinates 1/100 sec, 0 = 180°W double c_y; // Xastir coordinates 1/100 sec, 0 = 90°N long map_y_0; // map pixel pointer prior to TM adjustment register long map_x, map_y; // map pixel pointers, DNN: this was a float, chg to long long map_x_min, map_x_max; // map boundaries for in screen part of map long map_y_min, map_y_max; // long map_x_ctr; // half map width in pixel long map_y_ctr; // half map height in pixel int map_seen = 0; int map_act; int map_done; long map_c_yc; // map center, vert coordinate long map_c_xc; // map center, hor coordinate double map_c_dx, map_c_dy; // map coordinates increment (pixel width) double c_dx; // adjusted map pixel width long scr_x, scr_y; // screen pixel plot positions long scr_xp, scr_yp; // previous screen plot positions int scr_dx, scr_dy; // increments in screen plot positions long scr_x_mc; // map center in screen units long scr_c_xr; long scale_xa; // adjusted for topo maps double scale_x_nm; // nm per Xastir coordinate unit long scale_x0; // at widest map area char local_filename[MAX_FILENAME]; ExceptionInfo exception; Image *image; ImageInfo *image_info; PixelPacket *pixel_pack; PixelPacket temp_pack; IndexPacket *index_pack; int l; XColor my_colors[256]; double left, right, top, bottom, map_width, map_height; double lat_center = 0; double long_center = 0; char map_it[MAX_FILENAME]; char tmpstr[100]; int geo_image_width; // Image width from GEO file int geo_image_height; // Image height from GEO file // initialize this local_filename[0]='\0'; // Create a shorter filename for display (one that fits the // status line more closely). Subtract the length of the // "Indexing " and/or "Loading " strings as well. if (strlen(filenm) > (41 - 9)) { int avail = 41 - 11; int new_len = strlen(filenm) - avail; xastir_snprintf(short_filenm, sizeof(short_filenm), "..%s", &filenm[new_len]); } else { xastir_snprintf(short_filenm, sizeof(short_filenm), "%s", filenm); } xastir_snprintf(map_it, sizeof(map_it), langcode ("BBARSTA028"), short_filenm); statusline(map_it,0); // Loading ... // Check whether we're indexing or drawing the map if ( (destination_pixmap == INDEX_CHECK_TIMESTAMPS) || (destination_pixmap == INDEX_NO_TIMESTAMPS) ) { // We're indexing only. Save the extents in the index. // Force the extents to the edges of the earth for the // index file. index_update_xastir(filenm, // Filename only 64800000l, // Bottom 0l, // Top 0l, // Left 129600000l, // Right 0); // Default Map Level // Update statusline xastir_snprintf(map_it, sizeof(map_it), langcode ("BBARSTA039"), short_filenm); statusline(map_it,0); // Loading/Indexing ... return; // Done indexing this file } // Tiepoint for upper left screen corner // tp[0].img_x = 0; // Pixel Coordinates tp[0].img_y = 0; // Pixel Coordinates tp[0].x_long = NW_corner_longitude; // Xastir Coordinates tp[0].y_lat = NW_corner_latitude; // Xastir Coordinates // Tiepoint for lower right screen corner // tp[1].img_x = screen_width - 1; // Pixel Coordinates tp[1].img_y = screen_height - 1; // Pixel Coordinates tp[1].x_long = SE_corner_longitude; // Xastir Coordinates tp[1].y_lat = SE_corner_latitude; // Xastir Coordinates left = (double)((NW_corner_longitude - 64800000l )/360000.0); // Lat/long Coordinates top = (double)(-((NW_corner_latitude - 32400000l )/360000.0)); // Lat/long Coordinates right = (double)((SE_corner_longitude - 64800000l)/360000.0);//Lat/long Coordinates bottom = (double)(-((SE_corner_latitude - 32400000l)/360000.0));//Lat/long Coordinates map_width = right - left; // Lat/long Coordinates map_height = top - bottom; // Lat/long Coordinates geo_image_width = screen_width; geo_image_height = screen_height; long_center = (left + right)/2.0l; lat_center = (top + bottom)/2.0l; // Example query to the census map server.... /* xastir_snprintf(fileimg, sizeof(fileimg), "\'http://tiger.census.gov/cgi-bin/mapper/map.gif?on=CITIES&on=GRID&on=counties&on=majroads&on=places&&on=interstate&on=states&on=ushwy&on=statehwy&lat=%f\046lon=%f\046wid=%f\046ht=%f\046iwd=%i\046iht=%i\'",\ lat_center, long_center, map_width, map_height, tp[1].img_x + 1, tp[1].img_y + 1); */ xastir_snprintf(tigertmp, sizeof(tigertmp), "http://tiger.census.gov/cgi-bin/mapper/map.gif?"); if (tiger_show_grid) strncat(tigertmp, "&on=GRID", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=GRID", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_counties) strncat(tigertmp, "&on=counties", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=counties", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_cities) strncat(tigertmp, "&on=CITIES", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=CITIES", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_places) strncat(tigertmp, "&on=places", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=places", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_majroads) strncat(tigertmp, "&on=majroads", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=majroads", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_streets) strncat(tigertmp, "&on=streets", sizeof(tigertmp) - 1 - strlen(tigertmp)); // Don't turn streets off since this will automagically show up as you zoom in. if (tiger_show_railroad) strncat(tigertmp, "&on=railroad", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=railroad", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_states) strncat(tigertmp, "&on=states", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=states", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_interstate) strncat(tigertmp, "&on=interstate", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=interstate", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_ushwy) strncat(tigertmp, "&on=ushwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=ushwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_statehwy) strncat(tigertmp, "&on=statehwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=statehwy", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_water) strncat(tigertmp, "&on=water", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=water", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_lakes) strncat(tigertmp, "&on=shorelin", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=shorelin", sizeof(tigertmp) - 1 - strlen(tigertmp)); if (tiger_show_misc) strncat(tigertmp, "&on=miscell", sizeof(tigertmp) - 1 - strlen(tigertmp)); else strncat(tigertmp, "&off=miscell", sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "&lat=%f\046lon=%f\046", lat_center, long_center); strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "wid=%f\046ht=%f\046", map_width, map_height); strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "iwd=%i\046iht=%i", tp[1].img_x + 1, tp[1].img_y + 1); strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp)); xastir_snprintf(fileimg, sizeof(fileimg), "%s", tigertmp); if (debug_level & 512) { fprintf(stderr,"left side is %f\n", left); fprintf(stderr,"right side is %f\n", right); fprintf(stderr,"top is %f\n", top); fprintf(stderr,"bottom is %f\n", bottom); fprintf(stderr,"lat center is %f\n", lat_center); fprintf(stderr,"long center is %f\n", long_center); fprintf(stderr,"screen width is %li\n", screen_width); fprintf(stderr,"screen height is %li\n", screen_height); fprintf(stderr,"map width is %f\n", map_width); fprintf(stderr,"map height is %f\n", map_height); fprintf(stderr,"fileimg is %s\n", fileimg); fprintf(stderr,"ftp or http file: %s\n", fileimg); } // Hopefully this will eventually allow us to get maps in the background // while (sometimeout !=0 && local_filename[0]==NULL){ if (local_filename[0]=='\0' ){ if (debug_level & 512 ) { fprintf(stderr,"tiger_local_file=<%s>\n",local_filename); } HandlePendingEvents(app_context); if (interrupt_drawing_now) { // Update to screen (void)XCopyArea(XtDisplay(da), pixmap, XtWindow(da), gc, 0, 0, (unsigned int)screen_width, (unsigned int)screen_height, 0, 0); return; } get_tiger_local_file(local_filename,fileimg); } // whackadoodle // Tell ImageMagick where to find it xastir_snprintf(file, sizeof(file), "%s", local_filename); GetExceptionInfo(&exception); image_info=CloneImageInfo((ImageInfo *) NULL); xastir_snprintf(image_info->filename, sizeof(image_info->filename), "%s", file); if (debug_level & 512) { fprintf(stderr,"Copied %s into image info.\n", file); fprintf(stderr,"image_info got: %s\n", image_info->filename); fprintf(stderr,"Entered ImageMagick code.\n"); fprintf(stderr,"Attempting to open: %s\n", image_info->filename); } // We do a test read first to see if the file exists, so we // don't kill Xastir in the ReadImage routine. f = fopen (image_info->filename, "r"); if (f == NULL) { if (debug_level & 512) fprintf(stderr,"File could not be read\n"); #ifdef USE_MAP_CACHE // clear from cache if bad if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete unreadable map from cache\n"); } } #endif if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } (void)fclose (f); image = ReadImage(image_info, &exception); if (image == (Image *) NULL) { MagickWarning(exception.severity, exception.reason, exception.description); //fprintf(stderr,"MagickWarning\n"); #ifdef USE_MAP_CACHE // clear from cache if bad if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete map from cache\n"); } } #endif if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } if (debug_level & 512) fprintf(stderr,"Color depth is %i \n", (int)image->depth); if (image->colorspace != RGBColorspace) { fprintf(stderr,"TBD: I don't think we can deal with colorspace != RGB"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } width = image->columns; height = image->rows; // Code to mute the image so it's not as bright. /* if (raster_map_intensity < 1.0) { char tempstr[30]; if (debug_level & 512) fprintf(stderr,"level=%s\n", tempstr); xastir_snprintf(tempstr, sizeof(tempstr), "%d, 100, 100", (int)(raster_map_intensity * 100.0)); ModulateImage(image, tempstr); } */ // If were are drawing to a low bpp display (typically < 8bpp) // try to reduce the number of colors in an image. // This may take some time, so it would be best to do ahead of // time if it is a static image. #if (MagickLibVersion < 0x0540) if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL) > 128) { #else // MagickLib >= 540 if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL, &exception) > 128) { #endif // MagickLib Version if (image->storage_class == PseudoClass) { #if (MagickLibVersion < 0x0549) CompressColormap(image); // Remove duplicate colors #else // MagickLib >= 0x0549 CompressImageColormap(image); // Remove duplicate colors #endif // MagickLibVersion < 0x0549 } // Quantize down to 128 will go here... } pixel_pack = GetImagePixels(image, 0, 0, image->columns, image->rows); if (!pixel_pack) { fprintf(stderr,"pixel_pack == NULL!!!"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } index_pack = GetIndexes(image); if (image->storage_class == PseudoClass && !index_pack) { fprintf(stderr,"PseudoClass && index_pack == NULL!!!"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } if (image->storage_class == PseudoClass && image->colors <= 256) { for (l = 0; l < (int)image->colors; l++) { // Need to check how to do this for ANY image, as ImageMagick can read in all sorts // of image files temp_pack = image->colormap[l]; if (debug_level & 512) fprintf(stderr,"Colormap color is %i %i %i \n", temp_pack.red, temp_pack.green, temp_pack.blue); // Here's a tricky bit: PixelPacket entries are defined as Quantum's. Quantum // is defined in /usr/include/magick/image.h as either an unsigned short or an // unsigned char, depending on what "configure" decided when ImageMagick was installed. // We can determine which by looking at MaxRGB or QuantumDepth. // if (QuantumDepth == 16) { // Defined in /usr/include/magick/image.h if (debug_level & 512) fprintf(stderr,"Color quantum is [0..65535]\n"); my_colors[l].red = temp_pack.red * raster_map_intensity; my_colors[l].green = temp_pack.green * raster_map_intensity; my_colors[l].blue = temp_pack.blue * raster_map_intensity; } else { // QuantumDepth = 8 if (debug_level & 512) fprintf(stderr,"Color quantum is [0..255]\n"); my_colors[l].red = (temp_pack.red << 8) * raster_map_intensity; my_colors[l].green = (temp_pack.green << 8) * raster_map_intensity; my_colors[l].blue = (temp_pack.blue << 8) * raster_map_intensity; } // Get the color allocated on < 8bpp displays. pixel color is written to my_colors.pixel if (visual_type == NOT_TRUE_NOR_DIRECT) { // XFreeColors(XtDisplay(w), cmap, &(my_colors[l].pixel),1,0); XAllocColor(XtDisplay(w), cmap, &my_colors[l]); } else { pack_pixel_bits(my_colors[l].red, my_colors[l].green, my_colors[l].blue, &my_colors[l].pixel); } if (debug_level & 512) fprintf(stderr,"Color allocated is %li %i %i %i \n", my_colors[l].pixel, my_colors[l].red, my_colors[l].blue, my_colors[l].green); } } /* * Here are the corners of our viewport, using the Xastir * coordinate system. Notice that Y is upside down: * * left edge of view = NW_corner_longitude * right edge of view = SE_corner_longitude * top edge of view = NW_corner_latitude * bottom edge of view = SE_corner_latitude * * The corners of our map will soon be (after translating the * tiepoints to the corners if they're not already there): * * left edge of map = tp[0].x_long in Xastir format * right edge of map = tp[1].x_long * top edge of map = tp[0].y_lat * bottom edge of map = tp[1].y_lat * */ map_c_L = tp[0].x_long - NW_corner_longitude; // map left coordinate map_c_T = tp[0].y_lat - NW_corner_latitude; // map top coordinate tp_c_dx = (long)(tp[1].x_long - tp[0].x_long);// Width between tiepoints tp_c_dy = (long)(tp[1].y_lat - tp[0].y_lat); // Height between tiepoints // Check for tiepoints being in wrong relation to one another if (tp_c_dx < 0) tp_c_dx = -tp_c_dx; // New width between tiepoints if (tp_c_dy < 0) tp_c_dy = -tp_c_dy; // New height between tiepoints // Calculate step size per pixel map_c_dx = ((double) tp_c_dx / abs(tp[1].img_x - tp[0].img_x)); map_c_dy = ((double) tp_c_dy / abs(tp[1].img_y - tp[0].img_y)); // Scaled screen step size for use with XFillRectangle below scr_dx = (int) (map_c_dx / scale_x) + 1; scr_dy = (int) (map_c_dy / scale_y) + 1; // calculate top left map corner from tiepoints if (tp[0].img_x != 0) { tp[0].x_long -= (tp[0].img_x * map_c_dx); // map left edge longitude map_c_L = tp[0].x_long - NW_corner_longitude; // delta ?? tp[0].img_x = 0; if (debug_level & 512) fprintf(stderr,"Translated tiepoint_0 x: %d\t%lu\n", tp[0].img_x, tp[0].x_long); } if (tp[0].img_y != 0) { tp[0].y_lat -= (tp[0].img_y * map_c_dy); // map top edge latitude map_c_T = tp[0].y_lat - NW_corner_latitude; tp[0].img_y = 0; if (debug_level & 512) fprintf(stderr,"Translated tiepoint_0 y: %d\t%lu\n", tp[0].img_y, tp[0].y_lat); } // calculate bottom right map corner from tiepoints // map size is geo_image_width / geo_image_height if (tp[1].img_x != (geo_image_width - 1) ) { tp[1].img_x = geo_image_width - 1; tp[1].x_long = tp[0].x_long + (tp[1].img_x * map_c_dx); // right if (debug_level & 512) fprintf(stderr,"Translated tiepoint_1 x: %d\t%lu\n", tp[1].img_x, tp[1].x_long); } if (tp[1].img_y != (geo_image_height - 1) ) { tp[1].img_y = geo_image_height - 1; tp[1].y_lat = tp[0].y_lat + (tp[1].img_y * map_c_dy); // bottom if (debug_level & 512) fprintf(stderr,"Translated tiepoint_1 y: %d\t%lu\n", tp[1].img_y, tp[1].y_lat); } if (debug_level & 512) { fprintf(stderr,"X tiepoint width: %ld\n", tp_c_dx); fprintf(stderr,"Y tiepoint width: %ld\n", tp_c_dy); fprintf(stderr,"Loading imagemap: %s\n", file); fprintf(stderr,"\nImage: %s\n", file); fprintf(stderr,"Image size %d %d\n", geo_image_width, geo_image_height); fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y)); fprintf(stderr,"Image size %d %d\n", width, height); #if (MagickLibVersion < 0x0540) fprintf(stderr,"Unique colors = %d\n", GetNumberColors(image, NULL)); #else // MagickLib < 540 fprintf(stderr,"Unique colors = %ld\n", GetNumberColors(image, NULL, &exception)); #endif // MagickLib < 540 fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y)); fprintf(stderr,"image matte is %i\n", image->matte); } // debug_level & 512 // draw the image from the file out to the map screen // Get the border values for the X and Y for loops used // for the XFillRectangle call later. map_c_yc = (tp[0].y_lat + tp[1].y_lat) / 2; // vert center of map as reference map_y_ctr = (long)(height / 2 +0.499); scale_x0 = get_x_scale(0,map_c_yc,scale_y); // reference scaling at vert map center map_c_xc = (tp[0].x_long + tp[1].x_long) / 2; // hor center of map as reference map_x_ctr = (long)(width / 2 +0.499); scr_x_mc = (map_c_xc - NW_corner_longitude) / scale_x; // screen coordinates of map center // calculate map pixel range in y direction that falls into screen area c_y_max = 0ul; map_y_min = map_y_max = 0l; for (map_y_0 = 0, c_y = tp[0].y_lat; map_y_0 < (long)height; map_y_0++, c_y += map_c_dy) { scr_y = (c_y - NW_corner_latitude) / scale_y; // current screen position if (scr_y > 0) { if (scr_y < screen_height) { map_y_max = map_y_0; // update last map pixel in y c_y_max = (unsigned long)c_y;// bottom map inside screen coordinate } else break; // done, reached bottom screen border } else { // pixel is above screen map_y_min = map_y_0; // update first map pixel in y } } c_y_min = (unsigned long)(tp[0].y_lat + map_y_min * map_c_dy); // top map inside screen coordinate map_x_min = map_x_max = 0l; for (map_x = 0, c_x = tp[0].x_long; map_x < (long)width; map_x++, c_x += map_c_dx) { scr_x = (c_x - NW_corner_longitude)/ scale_x; // current screen position if (scr_x > 0) { if (scr_x < screen_width) map_x_max = map_x; // update last map pixel in x else break; // done, reached right screen border } else { // pixel is left from screen map_x_min = map_x; // update first map pixel in x } } c_x_min = (unsigned long)(tp[0].x_long + map_x_min * map_c_dx); // left map inside screen coordinate scr_yp = -1; scr_c_xr = SE_corner_longitude; c_dx = map_c_dx; // map pixel width scale_xa = scale_x0; // the compiler likes it ;-) map_done = 0; map_act = 0; map_seen = 0; scr_y = screen_height - 1; // loop over map pixel rows for (map_y_0 = map_y_min, c_y = (double)c_y_min; (map_y_0 <= map_y_max); map_y_0++, c_y += map_c_dy) { HandlePendingEvents(app_context); if (interrupt_drawing_now) { if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); // Update to screen (void)XCopyArea(XtDisplay(da), pixmap, XtWindow(da), gc, 0, 0, (unsigned int)screen_width, (unsigned int)screen_height, 0, 0); DestroyExceptionInfo(&exception); return; } scr_y = (c_y - NW_corner_latitude) / scale_y; if (scr_y != scr_yp) { // don't do a row twice scr_yp = scr_y; // remember as previous y scr_xp = -1; // loop over map pixel columns map_act = 0; scale_x_nm = calc_dscale_x(0,(long)c_y) / 1852.0; // nm per Xastir coordinate for (map_x = map_x_min, c_x = (double)c_x_min; map_x <= map_x_max; map_x++, c_x += c_dx) { scr_x = (c_x - NW_corner_longitude) / scale_x; if (scr_x != scr_xp) { // don't do a pixel twice scr_xp = scr_x; // remember as previous x map_y = map_y_0; if (map_y >= 0 && map_y <= tp[1].img_y) { // check map boundaries in y direction map_seen = 1; map_act = 1; // detects blank screen rows (end of map) // now copy a pixel from the map image to the screen l = map_x + map_y * image->columns; if (image->storage_class == PseudoClass) { XSetForeground(XtDisplay(w), gc, my_colors[index_pack[l]].pixel); } else { // It is not safe to assume that the red/green/blue // elements of pixel_pack of type Quantum are the // same as the red/green/blue of an XColor! if (QuantumDepth==16) { my_colors[0].red=pixel_pack[l].red; my_colors[0].green=pixel_pack[l].green; my_colors[0].blue=pixel_pack[l].blue; } else { // QuantumDepth=8 // shift the bits of the 8-bit quantity so that // they become the high bigs of my_colors.* my_colors[0].red=pixel_pack[l].red<<8; my_colors[0].green=pixel_pack[l].green<<8; my_colors[0].blue=pixel_pack[l].blue<<8; } // NOW my_colors has the right r,g,b range for // pack_pixel_bits pack_pixel_bits(my_colors[0].red * raster_map_intensity, my_colors[0].green * raster_map_intensity, my_colors[0].blue * raster_map_intensity, &my_colors[0].pixel); XSetForeground(XtDisplay(w), gc, my_colors[0].pixel); } (void)XFillRectangle (XtDisplay (w),pixmap,gc,scr_x,scr_y,scr_dx,scr_dy); } // check map boundaries in y direction } } // loop over map pixel columns if (map_seen && !map_act) map_done = 1; } } // loop over map pixel rows if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); }
static int get_position(NCURSES_CONST char *text, NCURSES_CONST char *also, int which, int *xpos, int *ypos) { int result = 0; int x1, y1; char cmd; getyx(stdscr, y1, x1); (void) statusline(); show_position(text, also, which, y1, x1); if (log_in != 0) { if (fscanf(log_in, "%c%d,%d\n", &cmd, &y1, &x1) == 3) { switch (cmd) { case LAST_POS: result = 1; (void) wgetch(stdscr); break; case TEMP_POS: result = 0; wrefresh(stdscr); napms(100); break; default: result = -1; break; } } else { result = -1; } } else { switch (wgetch(stdscr)) { case QUIT: case ESCAPE: case ERR: result = -1; break; case ' ': result = 1; break; case KEY_UP: if (y1 > 0) { --y1; } else { beep(); } break; case KEY_DOWN: if (y1 < getmaxy(stdscr)) { ++y1; } else { beep(); } break; case KEY_LEFT: if (x1 > 0) { --x1; } else { beep(); } break; case KEY_RIGHT: if (x1 < getmaxx(stdscr)) { ++x1; } else { beep(); } break; } } wmove(stdscr, y1, x1); *ypos = y1; *xpos = x1; if (result >= 0) { if (log_out) fprintf(log_out, "%c%d,%d\n", ((result > 0) ? LAST_POS : TEMP_POS), y1, x1); } return result; }
PUBLIC int LYNewsPost ARGS1(document *,newdoc) { char *newsgroups = strchr(newdoc->address,':')+1; char user_input[1024]; FILE *fd; char *tmptr; char c; /* user input */ char tmpfile[100]; char cmd[130]; DocAddress WWWDoc; term_message=FALSE; /* pop previous document off of stack and load into main memory */ pop(newdoc); WWWDoc.address = newdoc->address; WWWDoc.post_data = newdoc->post_data; WWWDoc.post_content_type = newdoc->post_content_type; if(!HTLoadAbsolute(&WWWDoc)) return(NOT_FOUND); clear(); move(2,0); tempname(tmpfile,NEW_FILE); if((fd = fopen(tmpfile,"w")) == NULL) { statusline("Unable to open temp file"); sleep(2); return(NORMAL); } addstr("You will be posting to:"); addstr("\n "); addstr(newsgroups); addch('\n'); /* Use ^C to cancel mailing of comment */ /* and don't let sigints exit lynx */ signal(SIGINT, terminate_message); term_message=FALSE; addstr("\n\n Please enter your mail address\n"); strcpy(user_input,"From: "); /* add the mail address if there is one */ if(personal_mail_address) strcat(user_input,personal_mail_address); if (LYgetstr(user_input, VISIBLE) < 0 || term_message) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } fprintf(fd,"%s\n",user_input); addstr("\n\n Please enter a subject line\n"); strcpy(user_input,"Subject: "); /* add the default subject */ tmptr = newdoc->title; while(isspace(*tmptr)) tmptr++; if(strncasecomp(tmptr, "Re:",3)) strcat(user_input, "Re: "); strcat(user_input, newdoc->title); if (LYgetstr(user_input, VISIBLE) < 0 || term_message) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } fprintf(fd,"%s\n",user_input); /* add Newsgroups: summary: and Keywords: */ fprintf(fd,"Newsgroups: %s\nSummary: \nKeywords: \n\n",newsgroups); if(!no_editor && editor && *editor != '\0') { /* ask if the user wants to include the original message */ statusline("Do you wish to inlude the original message? (y/n) "); c=0; while((c = toupper(LYgetch())) != 'Y' && c != 'N') ; /* null body */ if(toupper(c) == 'Y') /* the 1 will add the reply ">" in front of every line */ print_wwwfile_to_fd(fd,1); fclose(fd); /* spawn the users editor on the news file */ sprintf(user_input,"%s %s",editor,tmpfile); statusline("Spawning your selected editor to edit mail message"); stop_curses(); if(system(user_input)) { statusline("Error spawning editor, check your editor definition in the options menu"); sleep(1); } start_curses(); } else { addstr("\n\n Please enter your message below."); addstr("\n When you are done, press enter and put a single period (.)"); addstr("\n on a line and press enter again."); addstr("\n\n"); scrollok(stdscr,TRUE); refresh(); *user_input = '\0'; if (LYgetstr(user_input, VISIBLE) < 0 || term_message) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } while(!STREQ(user_input,".") && !term_message) { addch('\n'); fprintf(fd,"%s\n",user_input); *user_input = '\0'; if (LYgetstr(user_input, VISIBLE) < 0) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } } fprintf(fd,"\n"); fclose(fd); /* close the temp file */ scrollok(stdscr,FALSE); /* stop scrolling */ } statusline("Post this message? (y/n) "); while((c = toupper(LYgetch())) != 'Y' && c != 'N') ; /* null body */ clear(); /* clear the screen */ if(c == 'N') { goto cleanup; } sprintf(cmd,"%s %s",INEWS,tmpfile); stop_curses(); printf("Posting your message:\n\n%s\n\nPlease wait...", cmd); #ifndef VMS signal(SIGINT, SIG_IGN); #endif /* not VMS */ system(cmd); start_curses(); #ifdef VMS goto cleandown; #endif /* VMS */ /* come here to cleanup and exit */ cleanup: signal(SIGINT, cleanup_sig); cleandown: term_message = FALSE; scrollok(stdscr,FALSE); /* stop scrolling */ remove(tmpfile); return(NORMAL); }
HTStream *HTSaveToFile( HTPresentation *pres, HTParentAnchor *anchor, HTStream *sink ) { int eax; HTStream *ret_obj; char fnam[256]; char *suffix; char *cp; int c = 0; BOOLEAN IsBinary = 1; ret_obj = calloc( 1, sizeof( HTStream ) ); if ( ret_obj == 0 ) outofmem( "./HTFWriter.c", "HTSaveToFile" ); ret_obj->isa->name[0] = HTFWriter.name; *(int*)&ret_obj->remove_command = 0; *(int*)&ret_obj->end_command = 0; ret_obj->input_format = pres->rep->next; ret_obj->output_format = pres->rep_out; ret_obj->anchor = anchor; ret_obj->sink = sink; if ( dump_output_immediately ) { ret_obj->fp = stdout; if ( HTOutputFormat != HTAtom_for( "www/download" ) ) return ret_obj; } else { LYCancelDownload = 0; if ( HTOutputFormat != HTAtom_for( "www/download" ) ) { if ( traversal || ( no_download && !override_no_download && no_disk_save ) ) { if ( traversal == 0 ) { HTAlert( gettext( "This file cannot be displayed on this terminal." ) ); } LYCancelDownload = 1; if ( traversal ) LYCancelledFetch = 1; if ( ret_obj ) { free( ret_obj ); ret_obj = 0; } return 0; } else { cp = strchr( (char*)pres->rep_out, ';' ); if ( cp && strstr( &cp[1], "charset" ) ) { mustshow = 1; user_message( gettext( "%s D)ownload, or C)ancel" ), (char*)pres->rep_out ); while ( 1 ) { switch ( c ) { case -1: if ( keymap[0] != 47 ) { c = LYgetch_single( ); } break; default: if ( c & 34816 ) { if ( ( c & 255 ) != 47 ) continue; } else if ( keymap[ ( c & 2047 ) + 1 ] != 47 ) continue; break; } switch ( c ) { case -1: if ( keymap[0] == 47 ) { mustshow = 1; statusline( gettext( "Cancelling file." ) ); LYCancelDownload = 1; if ( ret_obj ) { free( ret_obj ); ret_obj = 0; } return 0; } break; default: if ( c & 34816 ) { if ( ( c & 255 ) == 47 ) continue; } else if ( keymap[ ( c & 2047 ) + 1 ] == 47 ) continue; break; } } } else if ( pres->rep_out->next ) { mustshow = 1; user_message( gettext( "%s D)ownload, or C)ancel" ), (char*)pres->rep_out ); } else { mustshow = 1; statusline( gettext( "This file cannot be displayed on this terminal: D)ownload, or C)ancel" ) ); } } } if ( LYCachedTemp( fnam, &anchor->FileCache ) & 255 ) { ret_obj->fp = LYOpenTempRewrite( fnam, ".bin", "wb" ); } else { if ( strcasecomp( (char*)pres->rep_out, "text/html" ) == 0 ) suffix = ".html"; else { if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 ) suffix = ".txt"; else { if ( strncasecomp( (char*)pres->rep_out, "application/", 12 ) == 0 ) suffix = ".bin"; else { suffix = HTFileSuffix( &pres->rep->next, &anchor->content_encoding ); if ( suffix == 0 || suffix[0] != '.' ) suffix = ".html"; } } } ret_obj->fp = LYOpenTemp( fnam, suffix, "wb" ); } if ( ret_obj->fp == 0 ) { HTAlert( gettext( "Can't open output file! Cancelling!" ) ); if ( ret_obj ) { free( ret_obj ); ret_obj = 0; } return 0; } else { if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 || strcasecomp( (char*)pres->rep_out, "application/postscript" ) == 0 || strcasecomp( (char*)pres->rep_out, "application/x-RUNOFF-MANUAL" ) == 0 ) IsBinary = 0; HTInfoMsg2( gettext( "Content-type: %s" ), (char*)pres->rep_out ); HTSACopy( &WWW_Download_File, fnam ); *(int*)&ret_obj->remove_command = 0; HTAddParam( &ret_obj->remove_command, "%s", 1, fnam ); HTEndParam( &ret_obj->remove_command, "%s", 1 ); HTSACopy( &ret_obj->end_command, "SaveToFile" ); mustshow = 1; statusline( gettext( "Retrieving file. - PLEASE WAIT -" ) ); HTSACopy( &anchor->FileCache, fnam ); } } if ( LYPrependBaseToSource && strncasecomp( (char*)pres->rep_out, "text/html", 9 ) == 0 && anchor->content_encoding == 0 ) { char *temp = 0; if ( anchor->content_base && anchor->content_base[0] ) HTSACopy( &temp, &anchor->content_base ); else if ( anchor->content_location && anchor->content_location[0] ) HTSACopy( &temp, &anchor->content_location ); if ( temp ) { LYRemoveBlanks( temp ); if ( !is_url( temp ) && temp ) { free( temp ); temp = 0; } } fprintf( &ret_obj->fp, "<!-- X-URL: %s -->\n", &anchor->address ); if ( anchor->date && anchor->date[0] ) { fprintf( &ret_obj->fp, "<!-- Date: %s -->\n", &anchor->date ); if ( anchor->last_modified && anchor->last_modified[0] && strcmp( &anchor->last_modified, &anchor->date ) && strcmp( &anchor->last_modified, "Thu, 01 Jan 1970 00:00:01 GMT" ) ) fprintf( &ret_obj->fp, "<!-- Last-Modified: %s -->\n", &anchor->last_modified ); } fprintf( &ret_obj->fp, "<BASE HREF=\"%s\">\n\n", temp ? temp : &anchor->address ); if ( temp ) { free( temp ); } } if ( LYPrependCharsetToSource && strncasecomp( (char*)pres->rep_out, "text/html", 9 ) == 0 && anchor->content_encoding == 0 ) { char *temp = 0; if ( anchor->charset && anchor->charset[0] ) { HTSACopy( &temp, &anchor->charset ); LYRemoveBlanks( temp ); fprintf( &ret_obj->fp, "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\">\n\n", temp ); } if ( temp ) { free( temp ); } } return ret_obj; }
void handlerequest(int fd, const char *addr) { char buffer[BUFFER_SIZE]; char can_uri[BUFFER_SIZE]; char filepath[BUFFER_SIZE]; char headers[BUFFER_SIZE]; char pf[BUFFER_SIZE]; int len = 0, ret, begin = 0, p, pbegin = 0, plen = 0; int state = 0, filelen; int fduri; char *uribuffer; int tot; time_t now; struct header rq; rq.code = 500; rq.contentlen = 0; memset(rq.contenttype, 0, sizeof(rq.contenttype)); memset(rq.host, 0, sizeof(rq.host)); memset(rq.cookie, 0, sizeof(rq.cookie)); do { ret = read(fd, buffer + len, BUFFER_SIZE - len); if (ret > 0) { len += ret; while ((state == 0 || state == 1) && begin < len && (p = crlf(buffer + begin, len - begin)) >= 0) { p += begin; if (state == 0) { if (statusline(fd, buffer + begin, p - begin, &rq)) state = 1; else { state = 3; break; } } else if (state == 1) { if (p - begin == 0) { if (rq.contentlen == 0) state = 3; else state = 2; } else if (!header(fd, buffer + begin, p - begin, &rq)) state = 3; } begin = p + 2; if (state == 2 || state == 3) break; } if (state == 2) { memcpy(rq.payload + pbegin, buffer + begin, len - begin); pbegin += len - begin; plen += len - begin; begin += len - begin; if (rq.contentlen != 0 && pbegin >= rq.contentlen) state = 3; } } else { state = 3; break; } } while (state <= 2); if (rq.contentlen == 0) rq.contentlen = plen; if (rq.code != 200) { respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { if (rq.uri[0] == '/') strcpy(can_uri, rq.uri); else { strcpy(can_uri, "/"); strcat(can_uri, rq.uri); } if (!permissible(can_uri)) { rq.code = 403; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { state = locateresource(can_uri, filepath, BUFFER_SIZE, &filelen); if (state == 0) { rq.code = 404; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else if (state == 2) { strcpy(buffer, "Location: "); strcat(buffer, filepath); strcat(buffer, "\r\n"); rq.code = 301; respond(fd, rq.code, rq.protocol, NULL, 0, buffer); } else if (state == 3) { rq.code = 403; respond(fd, rq.code ,rq.protocol, NULL, 0, NULL); } else if (state == 1) { if (postfix(filepath, pf) && strcmp(pf, "php") == 0) { php(fd, filepath, addr, &rq); } else { strcpy(headers, "Content-Type: "); strcat(headers, contenttype(filepath)); strcat(headers, "\r\n"); if (rq.method == METHOD_HEAD) respond(fd, rq.code, rq.protocol, NULL, filelen, headers); else { fduri = open(filepath, O_RDONLY); if (fduri < 0) { rq.code = 404; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { uribuffer = malloc(filelen); if (uribuffer == 0) { rq.code = 500; respond(fd, rq.code, rq.protocol, NULL, 0, NULL); } else { tot = 0; while (tot < filelen) tot += read(fduri, uribuffer + tot, filelen - tot); respond(fd, rq.code, rq.protocol, uribuffer, filelen, headers); free(uribuffer); } close(fduri); } } } } } } now = time(NULL); len = strftime(buffer, BUFFER_SIZE, "%d/%b/%Y %H:%M:%S", gmtime(&now)); fprintf(stdout, "%s - - [%s] \"%s\" %d\n", addr, buffer, rq.statusline, rq.code); }
// // Note that the length of "gps_line_data" can be up to // MAX_DEVICE_BUFFER, which is currently set to 4096. // int gps_data_find(char *gps_line_data, int port) { char long_pos[20],lat_pos[20],aunit[2]; time_t t; char temp_str[MAX_GPS_STRING+1]; int have_valid_string = 0; #ifndef __CYGWIN__ struct timeval tv; struct timezone tz; #endif // __CYGWIN__ if (strncmp(gps_line_data,"$GPRMC,",7)==0) { if (debug_level & 128) { char filtered_data[MAX_LINE_SIZE+1]; xastir_snprintf(filtered_data, sizeof(filtered_data), "%s", gps_line_data); makePrintable(filtered_data); fprintf(stderr,"Got RMC %s\n", filtered_data); } if (debug_level & 128) { // Got GPS RMC String statusline(langcode("BBARSTA015"),0); } xastir_snprintf(gps_gprmc, sizeof(gps_gprmc), "%s", gps_line_data); xastir_snprintf(temp_str, sizeof(temp_str), "%s", gps_gprmc); // decode_gps_rmc is destructive to its first parameter if (decode_gps_rmc( temp_str, long_pos, sizeof(long_pos), lat_pos, sizeof(lat_pos), gps_spd, gps_sunit, sizeof(gps_sunit), gps_cse, &t, &gps_valid ) == 1) { // mod station data // got GPS data have_valid_string++; if (debug_level & 128) fprintf(stderr,"RMC <%s> <%s><%s> %c <%s>\n", long_pos,lat_pos,gps_spd,gps_sunit[0],gps_cse); if (debug_level & 128) { fprintf(stderr,"Checking for Time Set on %d (%d)\n", port, devices[port].set_time); } // Don't set the time if it's a Cygwin system. Causes problems with // date, plus time can be an hour off if daylight savings time is // enabled on Windows. // #ifndef __CYGWIN__ if (devices[port].set_time) { tv.tv_sec=t; tv.tv_usec=0; tz.tz_minuteswest=0; tz.tz_dsttime=0; if (debug_level & 128) { fprintf(stderr,"Setting Time %ld EUID: %d, RUID: %d\n", (long)t, (int)getuid(), (int)getuid()); } #ifdef HAVE_SETTIMEOFDAY ENABLE_SETUID_PRIVILEGE; settimeofday(&tv, &tz); DISABLE_SETUID_PRIVILEGE; #endif // HAVE_SETTIMEOFDAY } #endif // __CYGWIN__ } } else { if (debug_level & 128) { int i; fprintf(stderr,"Not $GPRMC: "); for (i = 0; i<7; i++) fprintf(stderr,"%c", gps_line_data[i]); fprintf(stderr,"\n"); } } if (strncmp(gps_line_data,"$GPGGA,",7)==0) { if (debug_level & 128) { char filtered_data[MAX_LINE_SIZE+1]; xastir_snprintf(filtered_data, sizeof(filtered_data), "%s", gps_line_data); makePrintable(filtered_data); fprintf(stderr,"Got GGA %s\n", filtered_data); } if (debug_level & 128) { // Got GPS GGA String statusline(langcode("BBARSTA016"),0); } xastir_snprintf(gps_gpgga, sizeof(gps_gpgga), "%s", gps_line_data); xastir_snprintf(temp_str, sizeof(temp_str), "%s", gps_gpgga); // decode_gps_gga is destructive to its first parameter if ( decode_gps_gga( temp_str, long_pos, sizeof(long_pos), lat_pos, sizeof(lat_pos), gps_sats, gps_alt, aunit, &gps_valid ) == 1) { // mod station data // got GPS data have_valid_string++; if (debug_level & 128) fprintf(stderr,"GGA <%s> <%s> <%s> <%s> %c\n", long_pos,lat_pos,gps_sats,gps_alt,aunit[0]); } } else { if (debug_level & 128) { int i; fprintf(stderr,"Not $GPGGA: "); for (i = 0; i<7; i++) fprintf(stderr,"%c",gps_line_data[i]); fprintf(stderr,"\n"); } } if (have_valid_string) { if (debug_level & 128) { statusline(langcode("BBARSTA037"),0); } // Go update my screen position my_station_gps_change(long_pos,lat_pos,gps_cse,gps_spd, gps_sunit[0],gps_alt,gps_sats); // gps_stop_now is how we tell main.c that we've got a valid GPS string. // Only useful for HSP mode? if (!gps_stop_now) gps_stop_now=1; // If HSP port, shutdown gps for timed interval if (port_data[port].device_type == DEVICE_SERIAL_TNC_HSP_GPS) { // return dtr to normal port_dtr(port,0); } } return(have_valid_string); }
void draw_WMS_map (Widget w, char *filenm, int destination_pixmap, char *URL, transparent_color_record *c_trans_color_head, int nocache) { // If non-zero, don't use cached version char file[MAX_FILENAME]; // Complete path/name of image file char short_filenm[MAX_FILENAME]; FILE *f; // Filehandle of image file char fileimg[MAX_FILENAME]; // Ascii name of image file, read from GEO file char WMStmp[MAX_FILENAME*2]; // Used for putting together the WMS map query int width, height; tiepoint tp[2]; // Calibration points for map, read in from .geo file register long map_c_T, map_c_L; // map delta NW edge coordinates, DNN: these should be signed register long tp_c_dx, tp_c_dy; // tiepoint coordinate differences unsigned long c_x_min, c_y_min;// top left coordinates of map inside screen unsigned long c_y_max; // bottom right coordinates of map inside screen double c_x; // Xastir coordinates 1/100 sec, 0 = 180°W double c_y; // Xastir coordinates 1/100 sec, 0 = 90°N long map_y_0; // map pixel pointer prior to TM adjustment register long map_x, map_y; // map pixel pointers, DNN: this was a float, chg to long long map_x_min, map_x_max; // map boundaries for in screen part of map long map_y_min, map_y_max; // long map_x_ctr; // half map width in pixel long map_y_ctr; // half map height in pixel int map_seen = 0; int map_act; int map_done; long map_c_yc; // map center, vert coordinate long map_c_xc; // map center, hor coordinate double map_c_dx, map_c_dy; // map coordinates increment (pixel width) double c_dx; // adjusted map pixel width long scr_x, scr_y; // screen pixel plot positions long scr_xp, scr_yp; // previous screen plot positions int scr_dx, scr_dy; // increments in screen plot positions long scr_x_mc; // map center in screen units long scr_c_xr; long scale_xa; // adjusted for topo maps double scale_x_nm; // nm per Xastir coordinate unit long scale_x0; // at widest map area char local_filename[MAX_FILENAME]; ExceptionInfo exception; Image *image; ImageInfo *image_info; PixelPacket *pixel_pack; PixelPacket temp_pack; IndexPacket *index_pack; int l; XColor my_colors[256]; int trans_skip = 0; // skip transparent pixel double left, right, top, bottom, map_width, map_height; double lat_center = 0; double long_center = 0; char map_it[MAX_FILENAME]; char tmpstr[100]; int geo_image_width; // Image width from GEO file int geo_image_height; // Image height from GEO file time_t query_start_time, query_end_time; #ifdef USE_MAP_CACHE int map_cache_return; char * cache_file_id; #endif // USE_MAP_CACHE char temp_file_path[MAX_VALUE]; if (debug_level & 512) { if (nocache) fprintf(stderr,"draw_WMS_map: NOCACHE selected\n"); else fprintf(stderr,"draw_WMS_map: CACHING if enabled\n"); } // Create a shorter filename for display (one that fits the // status line more closely). Subtract the length of the // "Indexing " and/or "Loading " strings as well. if (strlen(filenm) > (41 - 9)) { int avail = 41 - 11; int new_len = strlen(filenm) - avail; xastir_snprintf(short_filenm, sizeof(short_filenm), "..%s", &filenm[new_len]); } else { xastir_snprintf(short_filenm, sizeof(short_filenm), "%s", filenm); } xastir_snprintf(map_it, sizeof(map_it), langcode ("BBARSTA028"), short_filenm); statusline(map_it,0); // Loading ... // Check whether we're indexing or drawing the map if ( (destination_pixmap == INDEX_CHECK_TIMESTAMPS) || (destination_pixmap == INDEX_NO_TIMESTAMPS) ) { // We're indexing only. Save the extents in the index. // Force the extents to the edges of the earth for the // index file. index_update_xastir(filenm, // Filename only 64800000l, // Bottom 0l, // Top 0l, // Left 129600000l, // Right 0); // Default Map Level // Update statusline xastir_snprintf(map_it, sizeof(map_it), langcode ("BBARSTA039"), short_filenm); statusline(map_it,0); // Loading/Indexing ... return; // Done indexing this file } // Tiepoint for upper left screen corner // tp[0].img_x = 0; // Pixel Coordinates tp[0].img_y = 0; // Pixel Coordinates tp[0].x_long = NW_corner_longitude; // Xastir Coordinates tp[0].y_lat = NW_corner_latitude; // Xastir Coordinates // Tiepoint for lower right screen corner // // Here we must use scale_x for both directions because we have // square pixels returned by the WMS server. // Really what we want to do here is to change our bounding box for // our request to fit square pixels, using scale_x for both // dimensions, and to change our tiepoints to match. WMS servers // currently feed us back square pixels but the spec says that the // servers should be capable of sending back rectangular pixels, so // the images we get back may change if we don't request square // pixels each time. // // TODO: Change our imagesize, bounding rectangle requested, and // tiepoints to fit square pixels and to use scale_x for both // dimensions. // // Actually, looking at the changes that were made, it looks like we // _are_ using square pixels and requesting a bounding box based on // scale_x for both dimensions, so we might be good to go as-is. // tp[1].img_x = screen_width - 1; // Pixel Coordinates tp[1].img_y = screen_height - 1; // Pixel Coordinates tp[1].x_long = SE_corner_longitude; // Xastir Coordinates // Modified to use same scale (scale_x) for both dimensions, square // pixels. Don't use SE_corner_latitude here as it uses scale_y! // tp[1].y_lat = NW_corner_latitude + ((screen_height) * scale_y); // Xastir Coordinates tp[1].y_lat = NW_corner_latitude + ((screen_height) * scale_x); // Xastir Coordinates // Again, use scale_x for both directions due to the square // pixels returned from the WMS server. // left = (double)((NW_corner_longitude - 64800000l )/360000.0); // Lat/long Coordinates top = (double)(-((NW_corner_latitude - 32400000l )/360000.0)); // Lat/long Coordinates right = (double)((SE_corner_longitude - 64800000l)/360000.0);//Lat/long Coordinates // Modified to use same scale (scale_x) for both dimensions, square // pixels. Don't use SE_corner_latitude here as it uses scale_y! // bottom = (double)(-(((NW_corner_latitude + ((screen_height) * scale_y) ) - 32400000l)/360000.0));//Lat/long Coordinates bottom = (double)(-(((NW_corner_latitude + ((screen_height) * scale_x) ) - 32400000l)/360000.0));//Lat/long Coordinates map_width = right - left; // Lat/long Coordinates map_height = top - bottom; // Lat/long Coordinates geo_image_width = screen_width; geo_image_height = screen_height; long_center = (left + right)/2.0l; lat_center = (top + bottom)/2.0l; // Example query for a WMS map server.... // xastir_snprintf(fileimg, sizeof(fileimg), // "\'http://mesonet.tamu.edu/cgi-bin/p-warn?SERVICE=WMS&VERSION=1.1.1&REQUEST=getmap&layers=radar&BBOX=-129.000,52.500,-111.000,42.500&HEIGHT=1000&WIDTH=1800&FORMAT=image/png\'"); // xastir_snprintf(WMStmp, sizeof(WMStmp), // "http://mesonet.tamu.edu/cgi-bin/p-warn?SERVICE=WMS&VERSION=1.1.1&REQUEST=getmap"); xastir_snprintf(WMStmp, sizeof(WMStmp), "%s", URL); strncat(WMStmp, "&REQUEST=getmap", sizeof(WMStmp) - 1 - strlen(WMStmp)); strncat(WMStmp, "&EXCEPTIONS=INIMAGE", sizeof(WMStmp) - 1 - strlen(WMStmp)); // This specifies a bounding box based on square pixels. xastir_snprintf(tmpstr, sizeof(tmpstr), "&BBOX=%8.5f,%7.5f,%8.5f,%7.5f", left, // Lower left bottom, // Lower left right, // Upper right top); // Upper right strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "&HEIGHT=%d", geo_image_height); strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "&WIDTH=%d", geo_image_width); strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); // These should be specified in the .geo file instead of hard-coded: // // strncat(WMStmp, "&VERSION=1.0.0", sizeof(WMStmp) - 1 - strlen(WMStmp)); // strncat(WMStmp, "&FORMAT=image/png", sizeof(WMStmp) - 1 - strlen(WMStmp)); // strncat(WMStmp, "&TRANSPARENT=TRUE", sizeof(WMStmp) - 1 - strlen(WMStmp)); // strncat(WMStmp, "&BGCOLOR=0xffffff", sizeof(WMStmp) - 1 - strlen(WMStmp)); // strncat(WMStmp, "&BGCOLOR=0x000000", sizeof(WMStmp) - 1 - strlen(WMStmp)); // strncat(WMStmp, "&CRS=CRS:84", sizeof(WMStmp) - 1 - strlen(WMStmp)); /* xastir_snprintf(WMStmp, sizeof(WMStmp), "http://tiger.census.gov/cgi-bin/mapper/map.png?"); if (tiger_show_grid) strncat(WMStmp, "&on=GRID", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=GRID", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_counties) strncat(WMStmp, "&on=counties", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=counties", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_cities) strncat(WMStmp, "&on=CITIES", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=CITIES", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_places) strncat(WMStmp, "&on=places", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=places", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_majroads) strncat(WMStmp, "&on=majroads", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=majroads", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_streets) strncat(WMStmp, "&on=streets", sizeof(WMStmp) - 1 - strlen(WMStmp)); // Don't turn streets off since this will automagically show up as you zoom in. if (tiger_show_railroad) strncat(WMStmp, "&on=railroad", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=railroad", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_states) strncat(WMStmp, "&on=states", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=states", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_interstate) strncat(WMStmp, "&on=interstate", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=interstate", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_ushwy) strncat(WMStmp, "&on=ushwy", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=ushwy", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_statehwy) strncat(WMStmp, "&on=statehwy", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=statehwy", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_water) strncat(WMStmp, "&on=water", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=water", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_lakes) strncat(WMStmp, "&on=shorelin", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=shorelin", sizeof(WMStmp) - 1 - strlen(WMStmp)); if (tiger_show_misc) strncat(WMStmp, "&on=miscell", sizeof(WMStmp) - 1 - strlen(WMStmp)); else strncat(WMStmp, "&off=miscell", sizeof(WMStmp) - 1 - strlen(WMStmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "&lat=%f\046lon=%f\046", lat_center, long_center); strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "wid=%f\046ht=%f\046", map_width, map_height); strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); xastir_snprintf(tmpstr, sizeof(tmpstr), "iwd=%i\046iht=%i", tp[1].img_x + 1, tp[1].img_y + 1); strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); */ xastir_snprintf(fileimg, sizeof(fileimg), "%s", WMStmp); if (debug_level & 512) { fprintf(stderr,"left side is %f\n", left); fprintf(stderr,"right side is %f\n", right); fprintf(stderr,"top is %f\n", top); fprintf(stderr,"bottom is %f\n", bottom); fprintf(stderr,"lat center is %f\n", lat_center); fprintf(stderr,"long center is %f\n", long_center); fprintf(stderr,"screen width is %li\n", screen_width); fprintf(stderr,"screen height is %li\n", screen_height); fprintf(stderr,"map width is %f\n", map_width); fprintf(stderr,"map height is %f\n", map_height); fprintf(stderr,"fileimg is %s\n", fileimg); fprintf(stderr,"ftp or http file: %s\n", fileimg); } if (debug_level & 512) { query_start_time=time(&query_start_time); } #ifdef USE_MAP_CACHE if (nocache || map_cache_fetch_disable) { // Delete old copy from the cache if (map_cache_fetch_disable && fileimg[0] != '\0') { if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete old map from cache\n"); } } } // Simulate a cache miss map_cache_return = 1; } else { // Else look for the file in the cache map_cache_return = map_cache_get(fileimg,local_filename); } if (debug_level & 512) { fprintf(stderr,"map_cache_return: %d\n", map_cache_return); } // Don't use cached version if "nocache" is non-zero // if (nocache || map_cache_return != 0 ) { // Caching has not been requested or cached file not found. // We must snag the remote file via libcurl or wget. if (nocache) { xastir_snprintf(local_filename, sizeof(local_filename), "%s/map.%s", get_user_base_dir("tmp", temp_file_path, sizeof(temp_file_path)), "png"); } else { cache_file_id = map_cache_fileid(); xastir_snprintf(local_filename, sizeof(local_filename), "%s/map_%s.%s", get_user_base_dir("map_cache", temp_file_path, sizeof(temp_file_path)), cache_file_id, "png"); free(cache_file_id); } #else // USE_MAP_CACHE xastir_snprintf(local_filename, sizeof(local_filename), "%s/map.%s", get_user_base_dir("tmp", temp_file_path, sizeof(temp_file_path)), "png"); #endif // USE_MAP_CACHE // Erase any previously existing local file by the same name. // This avoids the problem of having an old map image here and // the code trying to display it when the download fails. unlink( local_filename ); HandlePendingEvents(app_context); if (interrupt_drawing_now) { // Update to screen (void)XCopyArea(XtDisplay(da), pixmap, XtWindow(da), gc, 0, 0, (unsigned int)screen_width, (unsigned int)screen_height, 0, 0); return; } if (fetch_remote_file(fileimg, local_filename)) { // Had trouble getting the file. Abort. return; } // For debugging the MagickError/MagickWarning segfaults. //system("cat /dev/null >/var/tmp/xastir_hacker_map.png"); #ifdef USE_MAP_CACHE // Cache this map only if nocache is zero if (!nocache) { map_cache_put(fileimg,local_filename); } } // end if is cached DHBROWN #endif // USE_MAP_CACHE if (debug_level & 512) { fprintf (stderr, "Fetch or query took %d seconds\n", (int) (time(&query_end_time) - query_start_time)); } // Set permissions on the file so that any user can overwrite it. chmod(local_filename, 0666); // Tell ImageMagick where to find it xastir_snprintf(file, sizeof(file), "%s", local_filename); GetExceptionInfo(&exception); image_info=CloneImageInfo((ImageInfo *) NULL); xastir_snprintf(image_info->filename, sizeof(image_info->filename), "%s", file); if (debug_level & 512) { fprintf(stderr,"Copied %s into image info.\n", file); fprintf(stderr,"image_info got: %s\n", image_info->filename); fprintf(stderr,"Entered ImageMagick code.\n"); fprintf(stderr,"Attempting to open: %s\n", image_info->filename); } // We do a test read first to see if the file exists, so we // don't kill Xastir in the ReadImage routine. f = fopen (image_info->filename, "r"); if (f == NULL) { if (debug_level & 512) fprintf(stderr,"File could not be read\n"); #ifdef USE_MAP_CACHE // clear from cache if bad if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete map from cache\n"); } } #endif if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } (void)fclose (f); image = ReadImage(image_info, &exception); if (image == (Image *) NULL) { MagickWarning(exception.severity, exception.reason, exception.description); //fprintf(stderr,"MagickWarning\n"); #ifdef USE_MAP_CACHE // clear from cache if bad if (map_cache_del(fileimg)) { if (debug_level & 512) { fprintf(stderr,"Couldn't delete map from cache\n"); } } #endif if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } if (debug_level & 512) fprintf(stderr,"Color depth is %i \n", (int)image->depth); /* if (image->colorspace != RGBColorspace) { fprintf(stderr,"TBD: I don't think we can deal with colorspace != RGB"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } */ width = image->columns; height = image->rows; // Code to mute the image so it's not as bright. /* if (raster_map_intensity < 1.0) { char tempstr[30]; if (debug_level & 512) fprintf(stderr,"level=%s\n", tempstr); xastir_snprintf(tempstr, sizeof(tempstr), "%d, 100, 100", (int)(raster_map_intensity * 100.0)); ModulateImage(image, tempstr); } */ // If were are drawing to a low bpp display (typically < 8bpp) // try to reduce the number of colors in an image. // This may take some time, so it would be best to do ahead of // time if it is a static image. #if (MagickLibVersion < 0x0540) if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL) > 128) { #else // MagickLib >= 540 if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL, &exception) > 128) { #endif // MagickLib Version if (image->storage_class == PseudoClass) { #if (MagickLibVersion < 0x0549) CompressColormap(image); // Remove duplicate colors #else // MagickLib >= 0x0549 CompressImageColormap(image); // Remove duplicate colors #endif // MagickLibVersion < 0x0549 } // Quantize down to 128 will go here... } pixel_pack = GetImagePixels(image, 0, 0, image->columns, image->rows); if (!pixel_pack) { fprintf(stderr,"pixel_pack == NULL!!!"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } index_pack = GetIndexes(image); if (image->storage_class == PseudoClass && !index_pack) { fprintf(stderr,"PseudoClass && index_pack == NULL!!!"); if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); return; } if (image->storage_class == PseudoClass && image->colors <= 256) { for (l = 0; l < (int)image->colors; l++) { // Need to check how to do this for ANY image, as ImageMagick can read in all sorts // of image files temp_pack = image->colormap[l]; if (debug_level & 512) fprintf(stderr,"Colormap color is %i %i %i \n", temp_pack.red, temp_pack.green, temp_pack.blue); // Here's a tricky bit: PixelPacket entries are defined as Quantum's. Quantum // is defined in /usr/include/magick/image.h as either an unsigned short or an // unsigned char, depending on what "configure" decided when ImageMagick was installed. // We can determine which by looking at MaxRGB or QuantumDepth. // if (QuantumDepth == 16) { // Defined in /usr/include/magick/image.h if (debug_level & 512) fprintf(stderr,"Color quantum is [0..65535]\n"); my_colors[l].red = temp_pack.red * raster_map_intensity; my_colors[l].green = temp_pack.green * raster_map_intensity; my_colors[l].blue = temp_pack.blue * raster_map_intensity; } else { // QuantumDepth = 8 if (debug_level & 512) fprintf(stderr,"Color quantum is [0..255]\n"); my_colors[l].red = (temp_pack.red << 8) * raster_map_intensity; my_colors[l].green = (temp_pack.green << 8) * raster_map_intensity; my_colors[l].blue = (temp_pack.blue << 8) * raster_map_intensity; } // Get the color allocated on < 8bpp displays. pixel color is written to my_colors.pixel if (visual_type == NOT_TRUE_NOR_DIRECT) { // XFreeColors(XtDisplay(w), cmap, &(my_colors[l].pixel),1,0); XAllocColor(XtDisplay(w), cmap, &my_colors[l]); } else { pack_pixel_bits(my_colors[l].red, my_colors[l].green, my_colors[l].blue, &my_colors[l].pixel); } if (debug_level & 512) fprintf(stderr,"Color allocated is %li %i %i %i \n", my_colors[l].pixel, my_colors[l].red, my_colors[l].blue, my_colors[l].green); } } /* * Here are the corners of our viewport, using the Xastir * coordinate system. Notice that Y is upside down: * * left edge of view = NW_corner_longitude * right edge of view = SE_corner_longitude * top edge of view = NW_corner_latitude * bottom edge of view = SE_corner_latitude * * The corners of our map will soon be (after translating the * tiepoints to the corners if they're not already there): * * left edge of map = tp[0].x_long in Xastir format * right edge of map = tp[1].x_long * top edge of map = tp[0].y_lat * bottom edge of map = tp[1].y_lat * */ map_c_L = tp[0].x_long - NW_corner_longitude; // map left coordinate map_c_T = tp[0].y_lat - NW_corner_latitude; // map top coordinate tp_c_dx = (long)(tp[1].x_long - tp[0].x_long);// Width between tiepoints tp_c_dy = (long)(tp[1].y_lat - tp[0].y_lat); // Height between tiepoints // Check for tiepoints being in wrong relation to one another if (tp_c_dx < 0) tp_c_dx = -tp_c_dx; // New width between tiepoints if (tp_c_dy < 0) tp_c_dy = -tp_c_dy; // New height between tiepoints // Calculate step size per pixel map_c_dx = ((double) tp_c_dx / abs(tp[1].img_x - tp[0].img_x)); map_c_dy = ((double) tp_c_dy / abs(tp[1].img_y - tp[0].img_y)); // Scaled screen step size for use with XFillRectangle below scr_dx = (int) (map_c_dx / scale_x) + 1; scr_dy = (int) (map_c_dy / scale_y) + 1; // calculate top left map corner from tiepoints if (tp[0].img_x != 0) { tp[0].x_long -= (tp[0].img_x * map_c_dx); // map left edge longitude map_c_L = tp[0].x_long - NW_corner_longitude; // delta ?? tp[0].img_x = 0; if (debug_level & 512) fprintf(stderr,"Translated tiepoint_0 x: %d\t%lu\n", tp[0].img_x, tp[0].x_long); } if (tp[0].img_y != 0) { tp[0].y_lat -= (tp[0].img_y * map_c_dy); // map top edge latitude map_c_T = tp[0].y_lat - NW_corner_latitude; tp[0].img_y = 0; if (debug_level & 512) fprintf(stderr,"Translated tiepoint_0 y: %d\t%lu\n", tp[0].img_y, tp[0].y_lat); } // calculate bottom right map corner from tiepoints // map size is geo_image_width / geo_image_height if (tp[1].img_x != (geo_image_width - 1) ) { tp[1].img_x = geo_image_width - 1; tp[1].x_long = tp[0].x_long + (tp[1].img_x * map_c_dx); // right if (debug_level & 512) fprintf(stderr,"Translated tiepoint_1 x: %d\t%lu\n", tp[1].img_x, tp[1].x_long); } if (tp[1].img_y != (geo_image_height - 1) ) { tp[1].img_y = geo_image_height - 1; tp[1].y_lat = tp[0].y_lat + (tp[1].img_y * map_c_dy); // bottom if (debug_level & 512) fprintf(stderr,"Translated tiepoint_1 y: %d\t%lu\n", tp[1].img_y, tp[1].y_lat); } if (debug_level & 512) { fprintf(stderr,"X tiepoint width: %ld\n", tp_c_dx); fprintf(stderr,"Y tiepoint width: %ld\n", tp_c_dy); fprintf(stderr,"Loading imagemap: %s\n", file); fprintf(stderr,"\nImage: %s\n", file); fprintf(stderr,"Image size %d %d\n", geo_image_width, geo_image_height); fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y)); fprintf(stderr,"Image size %d %d\n", width, height); #if (MagickLibVersion < 0x0540) fprintf(stderr,"Unique colors = %d\n", GetNumberColors(image, NULL)); #else // MagickLib < 540 fprintf(stderr,"Unique colors = %ld\n", GetNumberColors(image, NULL, &exception)); #endif // MagickLib < 540 fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y)); fprintf(stderr,"image matte is %i\n", image->matte); } // debug_level & 512 // draw the image from the file out to the map screen // Get the border values for the X and Y for loops used // for the XFillRectangle call later. map_c_yc = (tp[0].y_lat + tp[1].y_lat) / 2; // vert center of map as reference map_y_ctr = (long)(height / 2 +0.499); scale_x0 = get_x_scale(0,map_c_yc,scale_y); // reference scaling at vert map center map_c_xc = (tp[0].x_long + tp[1].x_long) / 2; // hor center of map as reference map_x_ctr = (long)(width / 2 +0.499); scr_x_mc = (map_c_xc - NW_corner_longitude) / scale_x; // screen coordinates of map center // calculate map pixel range in y direction that falls into screen area c_y_max = 0ul; map_y_min = map_y_max = 0l; for (map_y_0 = 0, c_y = tp[0].y_lat; map_y_0 < (long)height; map_y_0++, c_y += map_c_dy) { scr_y = (c_y - NW_corner_latitude) / scale_y; // current screen position if (scr_y > 0) { if (scr_y < screen_height) { map_y_max = map_y_0; // update last map pixel in y c_y_max = (unsigned long)c_y;// bottom map inside screen coordinate } else break; // done, reached bottom screen border } else { // pixel is above screen map_y_min = map_y_0; // update first map pixel in y } } c_y_min = (unsigned long)(tp[0].y_lat + map_y_min * map_c_dy); // top map inside screen coordinate map_x_min = map_x_max = 0l; for (map_x = 0, c_x = tp[0].x_long; map_x < (long)width; map_x++, c_x += map_c_dx) { scr_x = (c_x - NW_corner_longitude)/ scale_x; // current screen position if (scr_x > 0) { if (scr_x < screen_width) map_x_max = map_x; // update last map pixel in x else break; // done, reached right screen border } else { // pixel is left from screen map_x_min = map_x; // update first map pixel in x } } c_x_min = (unsigned long)(tp[0].x_long + map_x_min * map_c_dx); // left map inside screen coordinate scr_yp = -1; scr_c_xr = SE_corner_longitude; c_dx = map_c_dx; // map pixel width scale_xa = scale_x0; // the compiler likes it ;-) map_done = 0; map_act = 0; map_seen = 0; scr_y = screen_height - 1; // loop over map pixel rows for (map_y_0 = map_y_min, c_y = (double)c_y_min; (map_y_0 <= map_y_max); map_y_0++, c_y += map_c_dy) { HandlePendingEvents(app_context); if (interrupt_drawing_now) { if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); // Update to screen (void)XCopyArea(XtDisplay(da), pixmap, XtWindow(da), gc, 0, 0, (unsigned int)screen_width, (unsigned int)screen_height, 0, 0); return; } scr_y = (c_y - NW_corner_latitude) / scale_y; if (scr_y != scr_yp) { // don't do a row twice scr_yp = scr_y; // remember as previous y scr_xp = -1; // loop over map pixel columns map_act = 0; scale_x_nm = calc_dscale_x(0,(long)c_y) / 1852.0; // nm per Xastir coordinate for (map_x = map_x_min, c_x = (double)c_x_min; map_x <= map_x_max; map_x++, c_x += c_dx) { scr_x = (c_x - NW_corner_longitude) / scale_x; if (scr_x != scr_xp) { // don't do a pixel twice scr_xp = scr_x; // remember as previous x map_y = map_y_0; if (map_y >= 0 && map_y <= tp[1].img_y) { // check map boundaries in y direction map_seen = 1; map_act = 1; // detects blank screen rows (end of map) // now copy a pixel from the map image to the screen l = map_x + map_y * image->columns; trans_skip = 1; // possibly transparent if (image->storage_class == PseudoClass) { if ( c_trans_color_head && check_trans(my_colors[index_pack[l]],c_trans_color_head)) { trans_skip = 1; // skip it } else { XSetForeground(XtDisplay(w), gc, my_colors[index_pack[l]].pixel); trans_skip = 0; // draw it } } else { // It is not safe to assume that the red/green/blue // elements of pixel_pack of type Quantum are the // same as the red/green/blue of an XColor! if (QuantumDepth==16) { my_colors[0].red=pixel_pack[l].red; my_colors[0].green=pixel_pack[l].green; my_colors[0].blue=pixel_pack[l].blue; } else { // QuantumDepth=8 // shift the bits of the 8-bit quantity so that // they become the high bigs of my_colors.* my_colors[0].red=pixel_pack[l].red<<8; my_colors[0].green=pixel_pack[l].green<<8; my_colors[0].blue=pixel_pack[l].blue<<8; } // NOW my_colors has the right r,g,b range for // pack_pixel_bits pack_pixel_bits(my_colors[0].red * raster_map_intensity, my_colors[0].green * raster_map_intensity, my_colors[0].blue * raster_map_intensity, &my_colors[0].pixel); if ( c_trans_color_head && check_trans(my_colors[0],c_trans_color_head)) { trans_skip = 1; // skip it } else { XSetForeground(XtDisplay(w), gc, my_colors[0].pixel); trans_skip = 0; // draw it } } // Skip drawing if a transparent pixel if (!trans_skip) { (void)XFillRectangle (XtDisplay (w),pixmap,gc,scr_x,scr_y,scr_dx,scr_dy); } } // check map boundaries in y direction } } // loop over map pixel columns if (map_seen && !map_act) map_done = 1; } } // loop over map pixel rows if (image) DestroyImage(image); if (image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); }