const char *SoundDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (digi_card == DIGI_NONE) { DEBUG(driver, 0, "allegro: no sound card found"); return "No sound card found"; } int hz = GetDriverParamInt(parm, "hz", 44100); _buffer_size = GetDriverParamInt(parm, "samples", 1024) * hz / 11025; _stream = play_audio_stream(_buffer_size, 16, true, hz, 255, 128); MxInitialize(hz); return NULL; }
const char *VideoDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; install_timer(); install_mouse(); install_keyboard(); #if defined _DEBUG /* Allegro replaces SEGV/ABRT signals meaning that the debugger will never * be triggered, so rereplace the signals and make the debugger useful. */ signal(SIGABRT, NULL); signal(SIGSEGV, NULL); #endif #if defined(DOS) /* Force DOS builds to ALWAYS use full screen as * it can't do windowed. */ _fullscreen = true; #endif GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { return "Failed to set up Allegro video"; } MarkWholeScreenDirty(); set_close_button_callback(HandleExitGameRequest); return NULL; }
void textgfx_init() { #ifdef UNIX strcpy(_xwin.application_name, "vitetris"); strcpy(_xwin.application_class, "Vitetris"); #endif if (install_allegro(SYSTEM_AUTODETECT, &errno, NULL) != 0) exit(1); #ifdef UNIX sigaction(SIGINT, NULL, &allegro_sigint_handler); signal(SIGINT, sigint_handler); #endif load_pc8x16_font(); set_window_title(VITETRIS_VER); set_close_button_callback(close_btn); #ifndef UNIX /* Seems to cause seg fault later quite randomly on Linux */ int depth = desktop_color_depth(); if (depth != 0) set_color_depth(depth); #endif virt_screen = set_screen(getopt_int("", "fullscreen")); lang |= LATIN1; if (!font8x16) { font8x16 = font; textgfx_flags |= ASCII; } setattr_normal(); #if WIN32 && !ALLEGRO_USE_CONSOLE if (exists("stdout.tmp")) { FILE *fp; freopen("stdout2.tmp", "w", stdout); fp = fopen("stdout.tmp", "r"); if (fp) { char line[80]; int i; for (i=0; i < 25 && fgets(line, 80, fp); i++) { setcurs(0, i); i += printline(line); } fclose(fp); if (i) { refreshscreen(); if (!strncmp(line, "Press ", 6)) { install_keyboard(); clear_keybuf(); readkey(); remove_keyboard(); } } } freopen("stdout.tmp", "w", stdout); delete_file("stdout2.tmp"); } #endif }
int main (int argc, char *argv[]) { setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, KQ_LOCALE); textdomain (PACKAGE); chdir ("maps"); install_allegro (SYSTEM_NONE, &errno, atexit); if (!startup ()) { printf ("wtf?\n"); return 1; } mainwindow (&argc, &argv); cleanup (); allegro_exit (); return 0; }
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow) { install_allegro(SYSTEM_AUTODETECT, &errno, atexit); install_keyboard(); set_color_depth(16); set_gfx_mode (GFX_DIRECTX_WIN, 640, 480, 0,0); set_display_switch_mode(SWITCH_BACKGROUND); dxmedia_play_video ("f:\\download\\Seinfeld S05E04 - The Sniffing Accountant.mpg", 1, 1); dxmedia_play_video ("f:\\download\\Family Guy S02E16 - There's Something About Paulie.mpg", 2, 1); return 0; }
int main( int argc, char **argv ) { PALETTE pal; int i; /* init allegro and init palette */ install_allegro(SYSTEM_NONE, &errno, atexit); set_color_depth(8); set_color_conversion(COLORCONV_REDUCE_TO_256); for( i = 0; i < 256; i++ ) { /* divided by 4 because the colour value ranges from 0-63 */ pal[i].r = pal[i].g = pal[i].b = i/4; } srand(time(NULL)); do_args(argc, argv); if( filename == NULL ) { /* +1 for '\0' char */ filename = malloc(strlen(DEFT_FILENAME)+1); if( filename == NULL ) { fprintf(stderr, "error: can't malloc space for map name.\n"); exit(EXIT_FAILURE); } strcpy(filename, DEFT_FILENAME); } lwmapgen(size, grid_size, func_id); save_bitmap(filename, map.map, pal); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { BITMAP *bmp; PACKFILE *f; if (argc != 3) { usage(); return 1; } if (install_allegro(SYSTEM_NONE, &errno, atexit) != 0) return 1; set_color_conversion(COLORCONV_NONE); bmp = load_bitmap(argv[1], the_pal); if (!bmp) { printf("Error reading palette from '%s'\n", argv[1]); return 1; } destroy_bitmap(bmp); printf("Palette read from '%s'\n", argv[1]); printf("Creating RGB map\n"); create_rgb_table(&the_map, the_pal, NULL); f = pack_fopen(argv[2], F_WRITE); if (!f) { printf("Error writing '%s'\n", argv[2]); return 1; } pack_fwrite(&the_map, sizeof(the_map), f); pack_fclose(f); printf("RGB mapping table written to '%s'\n", argv[2]); return 0; }
const char *MusicDriver_Allegro::Start(const char * const *param) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (midi_card == MIDI_NONE) { DEBUG(driver, 0, "allegro: no midi card found"); return "No sound card found"; } return NULL; }
const char *SoundDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (digi_card == DIGI_NONE) { DEBUG(driver, 0, "allegro: no sound card found"); return "No sound card found"; } _stream = play_audio_stream(BUFFER_SIZE, 16, true, 44100, 255, 128); MxInitialize(44100); return NULL; }
/** * \ingroup Main * * \brief Desenha uma rede no Allegro e imprime num arquivo de imagem. * * \details Esta funcao utiliza a biblioteca grafica Allegro para imprimir uma rede de Petri. * * \param[in] rede A variavel \a rede seria a rede de Petri. * * \param[in] fname A variavel \a fname representa o nome do arquivo que sera gerado. * * \retval void a funcao retorna nada. * */ void desenha_rede(petri_t *rede, const char *fname) { float ang, /* Angulacao antre cada elemento na imagem */ r_lugar, /* Raio da circunferencia que representa o lugar */ smaller, /* A menor das dimensoes da imagem */ x, /* Variavel geral para representar coordenada X */ y, /* Variavel geral para representar coordenada Y */ x1, /* Variavel geral para representar coordenada X */ y1, /* Variavel geral para representar coordenada Y */ x2, /* Variavel geral para representar coordenada X */ y2, /* Variavel geral para representar coordenada Y */ x3, /* Variavel geral para representar coordenada X */ y3, /* Variavel geral para representar coordenada Y */ co, /* Variavel geral para representar cosseno */ si; /* Variavel geral para representar seno */ unsigned i, q; lugar *a_l = rede->l; BITMAP *buff; PALETTE pal; flecha *a_tl = rede->tl, *a_lt = rede->lt; /* Inicializacao Allegro */ if(install_allegro(SYSTEM_NONE, &errno, atexit)!=0) exit(EXIT_FAILURE); set_color_depth(16); get_palette(pal); buff = create_bitmap(IMG_X,IMG_Y); smaller = (float)IMG_X; if(smaller > (float)IMG_Y) smaller = (float)IMG_Y; r_lugar = smaller/4.0*(M_PI/(M_PI+(float)rede->total_l)); if(buff == NULL) { printf("Could not create buffer!\n"); exit(EXIT_FAILURE); } /* Desenho propriamente dito */ if(rede->total_l > rede->total_t) ang = M_PI/rede->total_l; else ang = M_PI/rede->total_t; if(DEBUG == B || DEBUG == D) printf("Desenhando %u lugares e %u transicoes espacados entre si %.2fº...\n", rede->total_l, rede->total_t, ang*180.0/M_PI); /* Desenhando os lugares */ for(i=0;i<rede->total_l;i++) { a_l = buscarLugarPos(rede->l, i); q = 0; if(a_l != NULL) q = a_l->qtd; x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos(2*i*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin(2*i*ang); circle(buff, x, y, r_lugar, CORBRANCO); textprintf_ex(buff, font, x, y, CORVERDE, CORPRETO, "%u", q); if(DEBUG == B || DEBUG == D) printf("L%u(%u) (posicionada %.2fº)\n", i, q, ang*(2*i)*180.0/M_PI); textprintf_ex(buff, font, x, y - r_lugar, CORVERDE, CORPRETO, "L%u", i); } /* Desenhando as transicoes */ for(i=0;i<rede->total_t;i++) { x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos((2*i+1)*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin((2*i+1)*ang); line(buff, x, y+r_lugar, x, y-r_lugar, CORBRANCO); if(DEBUG == B || DEBUG == D) printf("T%u (posicionado %.2fº)\n", i, ang*(2*i+1)*180.0/M_PI); textprintf_ex(buff, font, x, y - r_lugar, CORVERDE, CORPRETO, "T%u", i); } /* Desenhando as flechas */ while(a_tl != NULL) { i = a_tl->de; x1 = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos((2*i+1)*ang); y1 = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin((2*i+1)*ang); i = a_tl->para; x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos(2*i*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin(2*i*ang); co = lcos(x1,y1,x,y); si = lsin(x1,y1,x,y); x -= r_lugar*co; y -= r_lugar*si; line(buff, x1, y1, x, y, CORBRANCO); textprintf_ex(buff, font, (x+x1)/2, (y+y1)/2, CORVERDE, CORPRETO, "%u", a_tl->tk); x2 = x - (r_lugar / 4) * (si + co); y2 = y + (r_lugar / 4) * (co - si); x3 = x + (r_lugar / 4) * (si - co); y3 = y - (r_lugar / 4) * (si + co); triangle(buff, x, y, x2, y2, x3, y3, CORBRANCO); a_tl = a_tl->prox; } while(a_lt != NULL) { i = a_lt->de; x1 = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos(2*i*ang); y1 = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin(2*i*ang); i = a_lt->para; x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos((2*i+1)*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin((2*i+1)*ang); co = lcos(x1,y1,x,y); si = lsin(x1,y1,x,y); x1 += r_lugar*co; y1 += r_lugar*si; line(buff, x1, y1, x, y, CORBRANCO); textprintf_ex(buff, font, (x+x1)/2, (y+y1)/2, CORVERDE, CORPRETO, "%u", a_lt->tk); x2 = x - (r_lugar / 4) * (si + co); y2 = y + (r_lugar / 4) * (co - si); x3 = x + (r_lugar / 4) * (si - co); y3 = y - (r_lugar / 4) * (si + co); triangle(buff, x, y, x2, y2, x3, y3, CORBRANCO); a_lt = a_lt->prox; } /* Salvando Imagem */ save_bitmap(fname, buff, pal); destroy_bitmap(buff); allegro_exit(); if(!GIF) printf("Imagem %s salva com sucesso!\n", fname); return; }
void MainWindow::CreateControls() { ////@begin MainWindow content construction MainWindow* itemFrame1 = this; GetAuiManager().SetManagedWindow(this); wxPanel* itemPanel2 = new wxPanel( itemFrame1, ID_PANEL, wxDefaultPosition, wxSize(-1, 400), wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); itemFrame1->GetAuiManager().AddPane(itemPanel2, wxAuiPaneInfo() .Name(_T("Pane1")).Caption(_("Input images")).Top().CloseButton(false).DestroyOnClose(false).Resizable(true).Floatable(false)); wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL); itemPanel2->SetSizer(itemBoxSizer3); wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL); itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW|wxLEFT|wxRIGHT, 5); wxStaticText* itemStaticText5 = new wxStaticText( itemPanel2, wxID_STATIC, _("Base layer"), wxDefaultPosition, wxSize(325, -1), 0 ); itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); itemBoxSizer4->Add(5, 5, 1, wxGROW|wxALL, 5); wxStaticText* itemStaticText7 = new wxStaticText( itemPanel2, wxID_STATIC, _("Blend layer"), wxDefaultPosition, wxSize(325, -1), 0 ); itemBoxSizer4->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxHORIZONTAL); itemBoxSizer3->Add(itemBoxSizer8, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5); wxStaticBitmap* itemStaticBitmap9 = new wxStaticBitmap( itemPanel2, wxID_STATIC, itemFrame1->GetBitmapResource(wxT("source/test_app/images/Base_325x244.xpm")), wxDefaultPosition, wxSize(325, 244), 0 ); itemBoxSizer8->Add(itemStaticBitmap9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); itemBoxSizer8->Add(5, 5, 1, wxGROW|wxALL, 5); wxStaticBitmap* itemStaticBitmap11 = new wxStaticBitmap( itemPanel2, wxID_STATIC, itemFrame1->GetBitmapResource(wxT("source/test_app/images/Blend_325x244.xpm")), wxDefaultPosition, wxSize(325, 244), 0 ); itemBoxSizer8->Add(itemStaticBitmap11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); // Fit to content itemFrame1->GetAuiManager().GetPane(_T("Pane1")).BestSize(itemPanel2->GetSizer()->Fit(itemPanel2)).MinSize(itemPanel2->GetSizer()->GetMinSize()); scrolledwindowOutput = new wxScrolledWindow( itemFrame1, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxVSCROLL|wxTAB_TRAVERSAL ); itemFrame1->GetAuiManager().AddPane(scrolledwindowOutput, wxAuiPaneInfo() .Name(_T("Pane2")).Caption(_("Output images")).Centre().CloseButton(false).DestroyOnClose(false).Resizable(true).Floatable(false)); scrolledwindowOutput->SetScrollbars(1, 1, 0, 0); sizerOutput = new wxBoxSizer(wxVERTICAL); scrolledwindowOutput->SetSizer(sizerOutput); sizerOutputLabels = new wxBoxSizer(wxHORIZONTAL); sizerOutput->Add(sizerOutputLabels, 0, wxGROW|wxLEFT|wxRIGHT, 5); staticText1 = new wxStaticText( scrolledwindowOutput, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); sizerOutputLabels->Add(staticText1, 1, wxGROW|wxALL, 5); staticText2 = new wxStaticText( scrolledwindowOutput, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); sizerOutputLabels->Add(staticText2, 1, wxGROW|wxALL, 5); staticText3 = new wxStaticText( scrolledwindowOutput, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); sizerOutputLabels->Add(staticText3, 1, wxGROW|wxALL, 5); sizerOutputImages = new wxBoxSizer(wxHORIZONTAL); sizerOutput->Add(sizerOutputImages, 0, wxGROW|wxLEFT|wxRIGHT, 5); wxBoxSizer* itemBoxSizer19 = new wxBoxSizer(wxHORIZONTAL); sizerOutputImages->Add(itemBoxSizer19, 1, wxGROW|wxALL, 0); staticBitmap1 = new wxStaticBitmap( scrolledwindowOutput, wxID_STATIC, wxNullBitmap, wxDefaultPosition, wxSize(250, 188), 0 ); itemBoxSizer19->Add(staticBitmap1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL); sizerOutputImages->Add(itemBoxSizer21, 1, wxGROW|wxALL, 0); staticBitmap2 = new wxStaticBitmap( scrolledwindowOutput, wxID_STATIC, wxNullBitmap, wxDefaultPosition, wxSize(250, 188), 0 ); itemBoxSizer21->Add(staticBitmap2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxHORIZONTAL); sizerOutputImages->Add(itemBoxSizer23, 1, wxGROW|wxALL, 0); staticBitmap3 = new wxStaticBitmap( scrolledwindowOutput, wxID_STATIC, wxNullBitmap, wxDefaultPosition, wxSize(250, 188), 0 ); itemBoxSizer23->Add(staticBitmap3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); scrolledwindowOutput->FitInside(); // Fit to content itemFrame1->GetAuiManager().GetPane(_T("Pane2")).BestSize(scrolledwindowOutput->GetSizer()->Fit(scrolledwindowOutput)).MinSize(scrolledwindowOutput->GetSizer()->GetMinSize()); GetAuiManager().Update(); // Connect events and objects staticBitmap1->Connect(wxID_STATIC, wxEVT_PAINT, wxPaintEventHandler(MainWindow::OnPaint), NULL, this); ////@end MainWindow content construction while (sizerOutput->GetChildren().GetCount() > 0) { sizerOutput->GetItem(static_cast<size_t>(0))->DeleteWindows(); sizerOutput->Remove(0); } RenderBlendingOutput(); install_allegro(SYSTEM_NONE, &errno, NULL); set_palette(desktop_palette); // example set_color_depth(32); // example }
/* main: * Guess what this function does. */ int main(int argc, char *argv[]) { PACKFILE *f; CFURLRef cf_url_ref; FSRef fs_ref; FSSpec fs_spec; IconFamilyHandle icon_family; Handle raw_data; char datafile[MAX_STRING_SIZE]; char bundle[MAX_STRING_SIZE]; char bundle_dir[MAX_STRING_SIZE]; char bundle_contents_dir[MAX_STRING_SIZE]; char bundle_contents_resources_dir[MAX_STRING_SIZE]; char bundle_contents_macos_dir[MAX_STRING_SIZE]; char bundle_contents_frameworks_dir[MAX_STRING_SIZE]; char *bundle_exe = NULL; char bundle_plist[MAX_STRING_SIZE]; char bundle_pkginfo[MAX_STRING_SIZE]; char bundle_icns[MAX_STRING_SIZE]; char bundle_version[MAX_STRING_SIZE]; char bundle_long_version[MAX_STRING_SIZE]; char *buffer = NULL; int arg, type = 0, result = 0; int i, size, x, y, mask_bit, mask_byte; unsigned char *data; install_allegro(SYSTEM_NONE, &errno, &atexit); set_color_depth(32); set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS); if (argc < 2) usage(); datafile[0] = '\0'; bundle[0] = '\0'; select_palette(black_palette); /* Parse command line and load any given resource */ for (arg = 2; arg < argc; arg++) { if (!strcmp(argv[arg], "-m")) flags |= F_MOVE; else if (!strcmp(argv[arg], "-e")) flags |= F_EMBED_FRAMEWORK; else if (!strcmp(argv[arg], "-o")) { if ((argc < arg + 2) || (bundle[0] != '\0')) usage(); strcpy(bundle, argv[++arg]); } else if (!strcmp(argv[arg], "-v")) { if (argc < arg + 2) usage(); flags |= F_GOT_VERSION; strcpy(bundle_version, argv[++arg]); } else if (!strcmp(argv[arg], "-V")) { if (argc < arg + 2) usage(); flags |= F_GOT_LONG_VERSION; strcpy(bundle_long_version, argv[++arg]); } else if (!strcmp(argv[arg], "-d")) { if (argc < arg + 2) usage(); strcpy(datafile, argv[++arg]); } else if ((!strcmp(argv[arg], "-16")) || (!strcmp(argv[arg], "-32")) || (!strcmp(argv[arg], "-48")) || (!strcmp(argv[arg], "-128"))) { if (argc < arg + 2) usage(); switch (atoi(&argv[arg][1])) { case 16: type = 0; break; case 32: type = 1; break; case 48: type = 2; break; case 128: type = 3; break; } if (load_resource(datafile, argv[++arg], &icon_data[type])) { result = -1; goto exit_error; } } else { if (load_resource(datafile, argv[arg], NULL)) { result = -1; goto exit_error; } } } buffer = malloc(4096); if (!buffer) { result = -1; goto exit_error_bundle; } bundle_exe = argv[1]; if (!exists(bundle_exe)) { fprintf(stderr, "Cannot locate executable file '%s'\n", bundle_exe); result = -1; goto exit_error; } if (bundle[0] == '\0') strcpy(bundle, bundle_exe); replace_extension(bundle_dir, bundle, "app", MAX_STRING_SIZE); strcpy(bundle_contents_dir, bundle_dir); strcat(bundle_contents_dir, "/Contents"); strcpy(bundle_contents_resources_dir, bundle_contents_dir); strcat(bundle_contents_resources_dir, "/Resources"); strcpy(bundle_contents_macos_dir, bundle_contents_dir); strcat(bundle_contents_macos_dir, "/MacOS"); strcpy(bundle_contents_frameworks_dir, bundle_contents_dir); strcat(bundle_contents_frameworks_dir, "/Frameworks"); bundle_icns[0] = '\0'; bundle_plist[0] = '\0'; bundle_pkginfo[0] = '\0'; /* Create bundle structure */ if ((mkdir(bundle_dir, 0777) && (errno != EEXIST)) || (mkdir(bundle_contents_dir, 0777) && (errno != EEXIST)) || (mkdir(bundle_contents_resources_dir, 0777) && (errno != EEXIST)) || (mkdir(bundle_contents_macos_dir, 0777) && (errno != EEXIST))) { fprintf(stderr, "Cannot create %s\n", bundle_dir); result = -1; goto exit_error_bundle; } /* Copy/move executable into the bundle */ if (copy_file(bundle_exe, bundle_contents_macos_dir)) { fprintf(stderr, "Cannot create %s\n", bundle_contents_macos_dir); result = -1; goto exit_error_bundle; } strcat(bundle_contents_macos_dir, "/"); strcat(bundle_contents_macos_dir, get_filename(bundle_exe)); chmod(bundle_contents_macos_dir, 0755); if (flags & F_MOVE) unlink(bundle_exe); /* Embed Allegro framework if requested */ if (flags & F_EMBED_FRAMEWORK) { if (!file_exists("/Library/Frameworks/Allegro.framework", FA_RDONLY | FA_DIREC, NULL)) { fprintf(stderr, "Cannot find Allegro framework\n"); result = -1; goto exit_error_bundle; } if (!exists("/Library/Frameworks/Allegro.framework/Resources/Embeddable")) { fprintf(stderr, "Cannot embed system wide Allegro framework; install embeddable version first!\n"); result = -1; goto exit_error_bundle; } sprintf(buffer, "/Developer/Tools/pbxcp -exclude .DS_Store -exclude CVS -resolve-src-symlinks /Library/Frameworks/Allegro.framework %s", bundle_contents_frameworks_dir); if ((mkdir(bundle_contents_frameworks_dir, 0777) && (errno != EEXIST)) || (system(buffer))) { fprintf(stderr, "Cannot create %s\n", bundle_contents_frameworks_dir); result = -1; goto exit_error_bundle; } } /* Setup the .icns resource */ if (flags & F_ICONS_DEFINED) { strcat(bundle_contents_resources_dir, "/"); strcat(bundle_contents_resources_dir, get_filename(bundle)); replace_extension(bundle_icns, bundle_contents_resources_dir, "icns", MAX_STRING_SIZE); icon_family = (IconFamilyHandle)NewHandle(0); for (i = 0; i < 4; i++) { if (flags & icon_data[i].defined) { /* Set 32bit RGBA data */ raw_data = NewHandle(icon_data[i].size * icon_data[i].size * 4); data = *(unsigned char **)raw_data; for (y = 0; y < icon_data[i].size; y++) { for (x = 0; x < icon_data[i].size; x++) { *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); *data++ = getr32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); *data++ = getg32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); *data++ = getb32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); } } if (SetIconFamilyData(icon_family, icon_data[i].data, raw_data) != noErr) { DisposeHandle(raw_data); fprintf(stderr, "Error setting %dx%d icon resource RGBA data\n", icon_data[i].size, icon_data[i].size); result = -1; goto exit_error_bundle; } DisposeHandle(raw_data); /* Set 8bit mask */ raw_data = NewHandle(icon_data[i].size * icon_data[i].size); data = *(unsigned char **)raw_data; for (y = 0; y < icon_data[i].size; y++) { for (x = 0; x < icon_data[i].size; x++) { *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); } } if (SetIconFamilyData(icon_family, icon_data[i].mask8, raw_data) != noErr) { DisposeHandle(raw_data); fprintf(stderr, "Error setting %dx%d icon resource 8bit mask\n", icon_data[i].size, icon_data[i].size); result = -1; goto exit_error_bundle; } DisposeHandle(raw_data); /* Set 1bit mask */ if (icon_data[i].mask1) { size = ((icon_data[i].size * icon_data[i].size) + 7) / 8; raw_data = NewHandle(size * 2); data = *(unsigned char **)raw_data; mask_byte = 0; mask_bit = 7; for (y = 0; y < icon_data[i].size; y++) { for (x = 0; x < icon_data[i].size; x++) { if (geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]) >= 0xfd) mask_byte |= (1 << mask_bit); mask_bit--; if (mask_bit < 0) { *data++ = mask_byte; mask_byte = 0; mask_bit = 7; } } } memcpy(*raw_data + size, *raw_data, size); if (SetIconFamilyData(icon_family, icon_data[i].mask1, raw_data) != noErr) { DisposeHandle(raw_data); fprintf(stderr, "Error setting %dx%d icon resource 1bit mask\n", icon_data[i].size, icon_data[i].size); result = -1; goto exit_error_bundle; } DisposeHandle(raw_data); } } } f = pack_fopen(bundle_icns, F_WRITE); if (!f) { fprintf(stderr, "Cannot create %s\n", bundle_icns); result = -1; goto exit_error_bundle; } pack_fclose(f); cf_url_ref = CFURLCreateWithBytes(kCFAllocatorDefault, (unsigned char *)bundle_icns, strlen(bundle_icns), 0, NULL); if (!cf_url_ref) { fprintf(stderr, "Cannot create %s\n", bundle_icns); result = -1; goto exit_error_bundle; } CFURLGetFSRef(cf_url_ref, &fs_ref); CFRelease(cf_url_ref); if ((FSGetCatalogInfo(&fs_ref, kFSCatInfoNone, NULL, NULL, &fs_spec, NULL)) || (WriteIconFile(icon_family, &fs_spec) != noErr)) { fprintf(stderr, "Cannot create %s\n", bundle_icns); result = -1; goto exit_error_bundle; } DisposeHandle((Handle)icon_family); } /* Setup Info.plist */ sprintf(bundle_plist, "%s/Info.plist", bundle_contents_dir); f = pack_fopen(bundle_plist, F_WRITE); if (!f) { fprintf(stderr, "Cannot create %s\n", bundle_plist); result = -1; goto exit_error_bundle; } sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" "<plist version=\"1.0\">\n" "<dict>\n" "\t<key>CFBundleExecutable</key>\n" "\t<string>%s</string>\n" "\t<key>CFBundleInfoDictionaryVersion</key>\n" "\t<string>6.0</string>\n" "\t<key>CFBundlePackageType</key>\n" "\t<string>APPL</string>\n" "\t<key>CFBundleSignature</key>\n" "\t<string>%s</string>\n" "\t<key>CFBundleVersion</key>\n" "\t<string>%s</string>\n" "\t<key>CFBundleDocumentTypes</key>\n" "\t<array>\n" "\t\t<dict>\n" "\t\t\t<key>CFBundleTypeExtensions</key>\n" "\t\t\t<array>\n" "\t\t\t\t<string>*</string>\n" "\t\t\t</array>\n" "\t\t\t<key>CFBundleTypeName</key>\n" "\t\t\t<string>NSStringPboardType</string>\n" "\t\t\t<key>CFBundleTypeOSTypes</key>\n" "\t\t\t<array>\n" "\t\t\t\t<string>****</string>\n" "\t\t\t</array>\n" "\t\t\t<key>CFBundleTypeRole</key>\n" "\t\t\t<string>Viewer</string>\n" "\t\t</dict>\n" "\t</array>\n", get_filename(bundle_exe), "????", (flags & F_GOT_VERSION) ? bundle_version : "1.0"); pack_fputs(buffer, f); if (flags & F_GOT_LONG_VERSION) { sprintf(buffer, "\t<key>CFBundleGetInfoString</key>\n" "\t<string>%s</string>\n", bundle_long_version); pack_fputs(buffer, f); } if (flags & F_ICONS_DEFINED) { sprintf(buffer, "\t<key>CFBundleIconFile</key>\n" "\t<string>%s</string>\n", get_filename(bundle_icns)); pack_fputs(buffer, f); } pack_fputs("</dict>\n</plist>\n", f); pack_fclose(f); /* Setup PkgInfo */ sprintf(bundle_pkginfo, "%s/PkgInfo", bundle_contents_dir); f = pack_fopen(bundle_pkginfo, F_WRITE); if (!f) { fprintf(stderr, "Cannot create %s\n", bundle_pkginfo); result = -1; goto exit_error_bundle; } pack_fputs("APPL????", f); pack_fclose(f); exit_error: if (buffer) free(buffer); for (i = 0; i < 4; i++) { if (icon_data[i].original) destroy_bitmap(icon_data[i].original); if (icon_data[i].workspace) destroy_bitmap(icon_data[i].workspace); if (icon_data[i].scaled) destroy_bitmap(icon_data[i].scaled); } return result; exit_error_bundle: sprintf(buffer, "%s/%s", bundle_contents_macos_dir, get_filename(bundle_exe)); unlink(buffer); unlink(bundle_plist); unlink(bundle_pkginfo); unlink(bundle_icns); rmdir(bundle_dir); rmdir(bundle_contents_dir); rmdir(bundle_contents_resources_dir); rmdir(bundle_contents_macos_dir); goto exit_error; }
int main(int argc, char *argv[]) { int c; if (install_allegro(SYSTEM_NONE, &errno, atexit) != 0) return 1; for (c=1; c<argc; c++) { if (argv[c][0] == '-') { switch (utolower(argv[c][1])) { case 'a': opt_allegro = TRUE; break; case 'b': opt_binary = TRUE; break; case 'c': opt_compress = TRUE; break; case 'd': opt_delete = TRUE; break; case 'x': opt_extract = TRUE; break; case '0': if ((opt_password) || (c >= argc-1)) { usage(); return 1; } opt_password = argv[++c]; break; default: printf("Unknown option '%s'\n", argv[c]); return 1; } } else { if (!opt_filename) opt_filename = argv[c]; else if (!opt_dataname) opt_dataname = argv[c]; else { usage(); return 1; } } } if ((!opt_filename) || ((opt_allegro) && (opt_binary)) || ((opt_delete) && (opt_extract))) { usage(); return 1; } if (opt_password) packfile_password(opt_password); if (opt_delete) { if (opt_dataname) { usage(); return 1; } update_file(opt_filename, NULL); } else if (opt_extract) { if (!opt_dataname) { usage(); return 1; } if ((!opt_allegro) && (!opt_binary)) { printf("The -x option must be used together with -a or -b\n"); return 1; } extract_data(); } else { if (opt_dataname) update_file(opt_filename, opt_dataname); else show_stats(); } return err; }
int main(int argc, char *argv[]) { /* default values for -f, -i, -r, -c, -b, -g */ char *fontname = "*"; char *filename = "font.pcx"; int start_char = 32, end_char = 255; int ccolor = 000000000; int bcolor = 255255255; int gcolor = 255000255; /* X11 variables */ Display *display; int screen_number; int default_depth; Window window; Font font; GC gc, gc2; Pixmap pixmap; XImage *image; XCharStruct overall; /* misc variables */ int bitmap_width, bitmap_height; int max_ascent, max_descent; int max_width, max_height; int i, opt, x, y, cx, cy, sx, sy, lines; unsigned long black, white; BITMAP *bitmap; RGB palette[256]; /* show usage if no options */ if (argc == 1) { usage(argv[0]); exit(EXIT_SUCCESS); } /* only to access bitmap operations */ install_allegro(SYSTEM_NONE, &errno, atexit); /* parse options */ opterr = 0; while ((opt = getopt(argc, argv, "f:o:z:c:b:g:r:h")) != EOF) { switch (opt) { case 'f': fontname = optarg; break; case 'o': filename = optarg; break; case 'c': ccolor = atol(optarg); break; case 'b': bcolor = atol(optarg); break; case 'g': gcolor = atol(optarg); break; case 'r': { char *str; start_char = strtol(optarg, &str, 0); end_char = strtol(str + 1, NULL, 0); break; } case 'h': usage(argv[0]); exit(EXIT_SUCCESS); default: fprintf(stderr, "%s: unrecognized option -- '%c'\n", argv[0], optopt); fprintf(stderr, "%s: try '%s -h' for more information\n", argv[0], argv[0]); exit(EXIT_FAILURE); } } /* open display */ display = XOpenDisplay(0); if (display == 0) { fprintf(stderr, "%s: XOpenDisplay failed\n", argv[0]); exit(EXIT_FAILURE); } /* default screen number and window */ screen_number = XDefaultScreen(display); default_depth = XDefaultDepth(display, screen_number); window = XDefaultRootWindow(display); /* load font */ font = XLoadFont(display, fontname); /* create gcs */ { unsigned long val_mask; XGCValues val_bits; val_mask = GCForeground | GCBackground | GCFont | GCFunction; val_bits.function = GXcopy; val_bits.foreground = white = WhitePixel(display, screen_number); val_bits.background = black = BlackPixel(display, screen_number); val_bits.font = font; gc = XCreateGC(display, window, val_mask, &val_bits); val_mask = GCForeground; val_bits.foreground = black; gc2 = XCreateGC(display, window, val_mask, &val_bits); } /* query font ascent and descent */ { XFontStruct *xfs; int min, max; xfs = XQueryFont(display, font); max_ascent = xfs->ascent; max_descent = xfs->descent; if (xfs->min_byte1 == 0 && xfs->max_byte1 == 0) { min = xfs->min_char_or_byte2; max = xfs->max_char_or_byte2; } else { min = (xfs->min_byte1 << 8) + xfs->min_char_or_byte2; max = (xfs->max_byte1 << 8) + xfs->max_char_or_byte2; } if (start_char < min || end_char > max) fprintf(stderr, "You specified characters %04x-%04x, but this font " "only has the range %04x-%04x\n", start_char, end_char, min, max); XFreeFontInfo(NULL, xfs, 0); } /* calculate bitmap width and maximum ascent and descent of characters * (can exceed the font ascent/descent queried above!) */ max_width = 0; lines = 1 + (end_char - start_char) / 16; for (cy = 0; cy < lines; cy++) { for (cx = 0; cx < 16 && start_char + cy * 16 + cx <= end_char; cx++) { int dir, ascent, descent; int width; XChar2b string[2] = { {0, 0}, {0, 0} }; /* query character size */ string[0].byte1 = (start_char + cy * 16 + cx) >> 8; string[0].byte2 = (start_char + cy * 16 + cx) & 255; XQueryTextExtents16(display, font, string, 1, &dir, &ascent, &descent, &overall); width = overall.width; if (width < 1) width = 1; if (width > max_width) max_width = width; if (max_ascent < overall.ascent) max_ascent = overall.ascent; if (max_descent < overall.descent) max_descent = overall.descent; } } max_height = max_ascent + max_descent; bitmap_width = (max_width + 1) * 16 + 1; bitmap_height = (max_height + 1) * lines + 1; /* create bitmap */ bitmap = create_bitmap(bitmap_width, bitmap_height); if (bitmap == 0) { fprintf(stderr, "%s: can not create bitmap\n", argv[0]); exit(EXIT_FAILURE); } /* fill with filler color */ clear_to_color(bitmap, 255); /* process all characters */ sy = 1; for (cy = 0; cy < lines; cy++) { sx = 1; for (cx = 0; cx < 16 && start_char + cy * 16 + cx <= end_char; cx++) { int dir, ascent, descent; XChar2b string[2] = { {0, 0}, {0, 0} }; /* query character size */ string[0].byte1 = (start_char + cy * 16 + cx) >> 8; string[0].byte2 = (start_char + cy * 16 + cx) & 255; XQueryTextExtents16(display, font, string, 1, &dir, &ascent, &descent, &overall); if (overall.width < 1) overall.width = 1; /* create pixmap and draw character there */ pixmap = XCreatePixmap(display, window, overall.width, max_height, default_depth); /* some fonts draw outside their ascent/descent, so we need to clear * the pixmap before drawing the glyph */ XFillRectangle(display, pixmap, gc2, 0, 0, overall.width, max_height); XDrawImageString16(display, pixmap, gc, 0, max_ascent, string, 1); /* create image with pixmap contents */ image = XGetImage(display, pixmap, 0, 0, overall.width, max_height, AllPlanes, ZPixmap); if (image == 0) { fprintf(stderr, "%s: can not get image\n", argv[0]); exit(EXIT_FAILURE); } /* copy image to bitmap */ for (y = 0; y < max_height; y++) for (x = 0; x < overall.width; x++) { if (XGetPixel(image, x, y) == white) putpixel(bitmap, sx + x, sy + y, 1); else putpixel(bitmap, sx + x, sy + y, 0); } XDestroyImage(image); XFreePixmap(display, pixmap); sx += max_width + 1; } sy += max_height + 1; } /* initialize palette */ for (i = 0; i < 256; i++) palette[i].r = palette[i].g = palette[i].b = 0; #define CLAMP_COL(v) (((v / 4) > 63) ? 63 : (v / 4)) palette[0].r = CLAMP_COL(bcolor / 1000000); palette[0].g = CLAMP_COL((bcolor % 1000000) / 1000); palette[0].b = CLAMP_COL(bcolor % 1000); palette[1].r = CLAMP_COL(ccolor / 1000000); palette[1].g = CLAMP_COL((ccolor % 1000000) / 1000); palette[1].b = CLAMP_COL(ccolor % 1000); palette[255].r = CLAMP_COL(gcolor / 1000000); palette[255].g = CLAMP_COL((gcolor % 1000000) / 1000); palette[255].b = CLAMP_COL(gcolor % 1000); #undef CLAMP_COL save_pcx(filename, bitmap, palette); /* clean up */ destroy_bitmap(bitmap); XFreeGC(display, gc); XFreeGC(display, gc2); XUnloadFont(display, font); XCloseDisplay(display); exit(EXIT_SUCCESS); }