t_image load_bmp(char *path) { int fd; char header[54]; t_image img; if ((fd = open(path, O_RDONLY)) < 0) { img.data = NULL; ft_putendl("Error : can't open image"); } else { if (read(fd, header, 54) != 54) { img.data = NULL; ft_putendl("Error : not a bmp file"); } else if (header[0] != 'B' || header[1] != 'M') { img.data = NULL; ft_putendl("Error : Not a correct BMP file"); } else read_bmp(fd, header, &img); } close(fd); return (img); }
int main(void) { bmp_meta_t meta; unsigned char* image = read_bmp("test.bmp", &meta); if (image) { write_bmp(image, meta.width, meta.height, "test-copy.bmp"); } return 0; }
int main(int argc, char *argv[]) { read_bmp(); glutInit(&argc, argv); glutCreateWindow("Tittle"); glutDisplayFunc(display);//(void (GLUTCALLBACK *func)(void)); glutTimerFunc( 0, //unsigned int millis, 何秒後に起動するか timer, //void (GLUTCALLBACK *func)(int value) なにを起動するのか 0); //int value 引数 glutMainLoop(); }
Matrix<Color> read_img(std::string filename) { std::size_t n = filename.size(); std::string extension3 = filename.substr(n-3, n); std::string extension4 = filename.substr(n-4, n); if(!extension3.compare("bmp")) { return read_bmp(filename); } else if(!extension3.compare("gif")) { return read_gif(filename); } else if(!extension3.compare("ico")) { return read_ico(filename); } /*else if(!extension3.compare("jpg")) { return read_jpeg(filename); }*/ else if(!extension3.compare("pcx")) { return read_pcx(filename); } else if(!extension3.compare("png")) { return read_png(filename); } else if(!extension3.compare("pbm")) { return bw2colorimage(read_pbm(filename)); } else if(!extension3.compare("pgm")) { return gray2colorimage(read_pgm(filename)); } else if(!extension3.compare("ppm")) { return read_ppm(filename); } else if(!extension3.compare("tga")) { return read_tga(filename); } else if(!extension4.compare("tiff")) { return read_tiff(filename); } else { return Matrix<Color>(); } }
int main_replaced(int argc, char** argv){ //Initialization MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); //Reading image if(rank == 0){ image = read_bmp("Lenna_blur.bmp"); } //Creating cartesian communicator MPI_Dims_create(size, 2, dims); MPI_Cart_create( MPI_COMM_WORLD, 2, dims, periods, 0, &cart_comm ); MPI_Cart_coords( cart_comm, rank, 2, coords ); MPI_Cart_shift( cart_comm, 0, 1, &north, &south ); MPI_Cart_shift( cart_comm, 1, 1, &west, &east ); local_image_size[0] = image_size[0]/dims[0]; local_image_size[1] = image_size[1]/dims[1]; //Allocating buffers int lsize = local_image_size[0]*local_image_size[1]; int lsize_border = (local_image_size[0] + 2*BORDER)*(local_image_size[1] + 2*BORDER); local_image_orig = (unsigned char*)malloc(sizeof(unsigned char)*lsize); local_image[0] = (unsigned char*)calloc(lsize_border, sizeof(unsigned char)); local_image[1] = (unsigned char*)calloc(lsize_border, sizeof(unsigned char)); create_types(); distribute_image(); initialilze_guess(); //Main loop for(int i = 0; i < ITERATIONS; i++){ exchange_borders(i); perform_convolution(i); } gather_image(); MPI_Finalize(); //Write image if(rank==0){ write_bmp(image, image_size[0], image_size[1]); } exit(0); }
int main ( int argc, char **argv ) { bmp_image *bitmap_image; Image *plain_img; bitmap_image = read_bmp("me1.bmp"); printf("r=%d\n", bitmap_image->t_pixel[0][0].r); return 0; }
int main(int argc, char** argv){ if(argc != 3){ printf("Usage: %s image n_threads\n", argv[0]); exit(-1); } int n_threads = atoi(argv[2]); // read from the input bmp image file unsigned char* image = read_bmp(argv[1]); unsigned char* output_image = malloc(sizeof(unsigned char) * image_size); // create a histogram for the pixel values int* histogram = (int*)calloc(sizeof(int), color_depth); #pragma omp parallel for num_threads(n_threads) for(int i = 0; i < image_size; i++){ int image_val = image[i]; // histogram[] is a shared variable, hence to avoid race conditions, critical clause has been used #pragma omp critical histogram[image_val]++; } float* transfer_function = (float*)calloc(sizeof(float), color_depth); // finding the normalised values using cumulative mass function // different scheduling clauses can be used here for comparative analysis #pragma omp parallel for num_threads(n_threads) schedule(static,1) for(int i = 0; i < color_depth; i++){ float sum = 0.0; for(int j = 0; j < i+1; j++){ sum += (float)histogram[j]; } transfer_function[i] += color_depth*((float)sum)/(image_size); } #pragma omp parallel for num_threads(n_threads) for(int i = 0; i < image_size; i++){ output_image[i] = transfer_function[image[i]]; } // write data to output bmp image file write_bmp(output_image, image_width, image_height); }
bool FC_capture_chipsight_overlay(RegionList *r, FeatureList *f, uint16* buf_16, uint32* buf_32, uint32 pixelcount) { bool success = true; // FC_stop(); // // rx image if(!read_bmp(buf_16, buf_32, pixelcount)) success = false; else if(!read_regionList(r)) success = false; else if(!read_featureList(f)) success = false; // FC_run(); // return success; }
Ship* get_ship(int x, int y) { SDL_Surface *fb = SDL_GetVideoSurface(); int bpp = fb->pitch / fb->w; Ship* ship = malloc(sizeof(Ship)); ship->pos = malloc(sizeof(Vector)); set_vector(ship->pos, x, y); ship->v = malloc(sizeof(Vector)); set_vector(ship->v, 0, 0); ship->dv = 2; ship->rot = 0; ship->vrot = 0; ship->arot = 0.5; ship->bullets = new_array(sizeof (Bullet)); ship->particles = new_array(sizeof(Particle)); if (!ship_sprite){ bmp_file *bmp = read_bmp("Sprites/ship.bmp"); ship_sprite = malloc(sizeof(Sprite)); ship_sprite->pixels = convert_bmp_to_pixels(bmp, 4); ship_sprite->w = get_bmp_width(bmp); ship_sprite->h = get_bmp_height(bmp); ship_sprite->bpp = 4;//get_bmp_bits_per_pixel(bmp); free_bmp(bmp); } ship->sprite = *ship_sprite; int rrad = ship->sprite.w/sin(45); //rotation buffer width and height Sprite rotBuffer = {malloc(sizeof(int) * rrad * rrad), rrad, rrad, bpp}; memset(rotBuffer.pixels, 0, sizeof(int) * rrad * rrad); rotate_sprite(ship->sprite, rotBuffer, 0); ship->rot_buffer = rotBuffer; ship->rainbow = SDL_CreateRGBSurface(SDL_SWSURFACE, fb->w, fb->h, 8*fb->pitch/fb->w, 0, 0, 0, 0); int bytes = fb->h * fb->pitch; memset(ship->rainbow->pixels, 0, bytes); reset_keys(); return ship; }
int main(int argc, char** argv){ if(argc != 3){ printf("Useage: %s image n_threads\n", argv[0]); exit(-1); } int n_threads = atoi(argv[2]); unsigned char* image = read_bmp(argv[1]); unsigned char* output_image = malloc(sizeof(unsigned char) * image_size); int* histogram = (int*)calloc(sizeof(int), color_depth); #pragma omp parallel for num_threads(n_threads) for(int i = 0; i < image_size; i++){ int image_val = image[i]; #pragma omp critical histogram[image_val]++; } float* transfer_function = (float*)calloc(sizeof(float), color_depth); #pragma omp parallel for num_threads(n_threads) schedule(static,1) for(int i = 0; i < color_depth; i++){ for(int j = 0; j < i+1; j++){ transfer_function[i] += color_depth*((float)histogram[j])/(image_size); } } #pragma omp parallel for num_threads(n_threads) for(int i = 0; i < image_size; i++){ output_image[i] = transfer_function[image[i]]; } write_bmp(output_image, image_width, image_height); }
void read_image(void) { G_debug(1, "read_image"); if (!cairo || !surface) return; if (file_type == FTYPE_PPM) { G_debug(1, "Reading image from %s", file_name); read_ppm(); } else if (file_type == FTYPE_BMP) { G_debug(1, "Reading image from %s", file_name); read_bmp(); } #if CAIRO_HAS_PNG_FUNCTIONS else if (file_type == FTYPE_PNG) { cairo_surface_t *img_surf; G_debug(1, "Reading image from %s", file_name); img_surf = cairo_image_surface_create_from_png(file_name); if (!img_surf) return; cairo_save(cairo); cairo_set_source_surface(cairo, img_surf, 0, 0); cairo_paint(cairo); cairo_restore(cairo); cairo_surface_destroy(img_surf); } #endif /* vector format files are written directly to file */ modified = 0; }
int main () { int i, j, k, t; int fbfd; int screen_width; int screen_height; int bits_per_pixel; int line_length; int coor_x, coor_y; int cols = 0, rows = 0; int mem_size; char *pData, *data; char r, g, b; unsigned long bmpdata[1280*800]; unsigned long pixel; unsigned char *pfbmap; unsigned long *ptr; struct fb_var_screeninfo fbvar; struct fb_fix_screeninfo fbfix; printf("=================================\n"); printf("Frame buffer Application - Bitmap\n"); printf("=================================\n\n"); char* file_name = "bike.bmp"; read_bmp(file_name, &pData, &data, &cols, &rows); printf("Bitmap : cols = %d, rows = %d\n", cols, rows); for(j = 0; j < rows; j++) { k = j * cols * 3; t = (rows - 1 - j) * cols; // 가로 size가 작을 수도 있다. for(i = 0; i < cols; i++) { b = *(data + (k + i * 3)); g = *(data + (k + i * 3 + 1)); r = *(data + (k + i * 3 + 2)); pixel = ((r<<16) | (g<<8) | b); bmpdata[t+i] = pixel; } } close_bmp(&pData); // 메모리 해제 if( (fbfd = open(FBDEV_FILE, O_RDWR)) < 0) // { printf("%s: open error\n", FBDEV_FILE); exit(1); } if( ioctl(fbfd, FBIOGET_VSCREENINFO, &fbvar) ) { printf("%s: ioctl error - FBIOGET_VSCREENINFO \n", FBDEV_FILE); exit(1); } if( ioctl(fbfd, FBIOGET_FSCREENINFO, &fbfix) ) // screen info를 얻어옴 { printf("%s: ioctl error - FBIOGET_FSCREENINFO \n", FBDEV_FILE); exit(1); } if (fbvar.bits_per_pixel != 32) { fprintf(stderr, "bpp is not 32\n"); exit(1); } screen_width = fbvar.xres; screen_height = fbvar.yres; bits_per_pixel = fbvar.bits_per_pixel; line_length = fbfix.line_length; mem_size = line_length * screen_height; printf("screen_width : %d\n", screen_width); printf("screen_height : %d\n", screen_height); printf("bits_per_pixel : %d\n", bits_per_pixel); printf("line_length : %d\n", line_length); pfbmap = (unsigned char *) mmap(0, mem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fbfd, 0); // distance control int offset_x = 640; int offset_y = (screen_height - rows)/2; if ((unsigned)pfbmap == (unsigned)-1) { perror("fbdev mmap\n"); exit(1); } for(coor_y = 0; coor_y < screen_height; coor_y++) { ptr = (unsigned long *)pfbmap + (screen_width * coor_y); for(coor_x = 0; coor_x < screen_width; coor_x++){ *ptr++ = 0xFFFFFF; } } for(coor_y = offset_y; coor_y < rows +offset_y; coor_y++) { ptr = (unsigned long*)pfbmap + (screen_width * coor_y); for(coor_x = 0; coor_x < offset_x; coor_x++){ *ptr++ = 0xFFFFFF; } for (coor_x = offset_x; coor_x < cols +offset_x; coor_x++) { *ptr++ = bmpdata[coor_x-offset_x + (coor_y-offset_y)*cols]; } } munmap( pfbmap, mem_size); close( fbfd); return 0; }
void CItemPicker::Preview(CString &key, loc_entry &fileloc, int restype) { CString tmpstr; int fhandle; int fc; switch(restype) { case REF_VVC: case REF_BMP: case REF_PLT: case REF_BAM: case REF_ITM: case REF_SPL: m_preview.InitView(IW_NOREDRAW); //don't add the 'back' button if(editflg&PREVIEW) { m_preview.ShowWindow(false); return; } m_preview.SetWindowText(key); switch(restype) { case REF_ITM: case REF_SPL: fhandle=locate_file(fileloc, 0); if(restype==REF_ITM) tmpstr=my_item.RetrieveResourceRef(fhandle); else tmpstr=my_spell.RetrieveResourceRef(fhandle); break; case REF_VVC: fhandle=locate_file(fileloc, 0); tmpstr=my_vvc.RetrieveResourceRef(fhandle); break; case REF_BMP: case REF_BAM: case REF_PLT: tmpstr=key; break; } switch(restype) { case REF_BMP: fc=read_bmp(tmpstr, &my_bam); break; case REF_PLT: fc=read_plt(tmpstr, &my_bam); break; default: fc=read_bam_preview(tmpstr,&my_bam); } if(!fc) { fc=my_bam.GetFrameIndex(0,0); if(restype!=REF_SPL) my_bam.MakeBitmap(fc,RGB(32,32,32),m_preview.m_bm,BM_RESIZE,32,32); else my_bam.MakeBitmap(fc,RGB(255,198,128),m_preview.m_bm,BM_RESIZE,32,32); } else { if(m_preview.m_bm) { DeleteObject(m_preview.m_bm); m_preview.m_bm=0; } } m_preview.RedrawContent(); m_preview.ShowWindow(true); break; case REF_ARE: case REF_MOS: case REF_CHU: if(editflg&PREVIEW) { m_preview.ShowWindow(false); return; } m_preview.SetWindowText(key); switch(restype) { case REF_CHU: fhandle=locate_file(fileloc, 0); tmpstr=my_chui.RetrieveMosRef(fhandle); break; case REF_ARE: fhandle=locate_file(fileloc, 0); tmpstr=my_area.RetrieveMosRef(fhandle); break; default: tmpstr=key; } if(read_mos(tmpstr,&my_mos,true)) { my_mos.new_mos(); } else { if(m_preview.m_bm) { DeleteObject(m_preview.m_bm); m_preview.m_bm=0; } } m_preview.m_maxextentx=m_preview.m_maxextenty=8; my_mos.m_tileheaders=NULL; m_preview.InitView(0, &my_mos); m_preview.RedrawContent(); m_preview.ShowWindow(true); break; } }
int main(){ printf("NEW GAME!\n\n"); volatile int old_game_state = 0; int doge = 0; //animation counter //buffer init stuff pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma"); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); //phil's stuff master* m = master_init(); printf("NEW GAME!\n\n"); // Set the 1st buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1); // Swap buffers – we have to swap because there is only an API function // to set the address of the background buffer. alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // Set the 2nd buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2); printf("NEW GAME!\n\n"); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_char_buffer_clear(char_buffer); //Write some text alt_up_char_buffer_string(char_buffer, "LOADING...", 0, 0); //load bitmap files title = read_bmp("title.bmp"); alt_up_char_buffer_string(char_buffer, "title.bmp", 0, 2); menu = read_bmp("menu.bmp"); alt_up_char_buffer_string(char_buffer, "MENU.BMP", 0, 3); selA = read_bmp("selA.bmp"); alt_up_char_buffer_string(char_buffer, "selA.bmp", 0, 4); selB = read_bmp("selB.bmp"); alt_up_char_buffer_string(char_buffer, "selB.bmp", 0, 5); selC = read_bmp("selC.bmp"); alt_up_char_buffer_string(char_buffer, "selC.bmp", 0, 6); dead = read_bmp("dead.bmp"); alt_up_char_buffer_string(char_buffer, "dead.bmp", 0, 7); bmp * b = read_bmp("para1.bmp"); alt_up_char_buffer_string(char_buffer, "para.bmp", 0, 8); bmp * doge0 = read_bmp("doge0.bmp"); alt_up_char_buffer_string(char_buffer, "doge0.bmp", 0, 9); bmp * doge1 = read_bmp("doge1.bmp"); alt_up_char_buffer_string(char_buffer, "doge1.bmp", 0, 10); bmp * doge2 = read_bmp("doge2.bmp"); alt_up_char_buffer_string(char_buffer, "doge2.bmp", 0, 11); bmp * doge3 = read_bmp("doge3.bmp"); alt_up_char_buffer_string(char_buffer, "doge3.bmp", 0, 12); bmp * flat = read_bmp("flat.bmp"); alt_up_char_buffer_string(char_buffer, "flat.bmp", 0, 13); bmp * coin = read_bmp("coin.bmp"); alt_up_char_buffer_string(char_buffer, "coin.bmp", 0, 14); bmp * spike = read_bmp("spike.bmp"); alt_up_char_buffer_string(char_buffer, "spike.bmp", 0, 15); bmp * box1 = read_bmp("box1.bmp"); alt_up_char_buffer_string(char_buffer, "box1.bmp", 0, 16); bmp * box3 = read_bmp("box3.bmp"); alt_up_char_buffer_string(char_buffer, "box3.bmp", 0, 17); bmp * low = read_bmp("low.bmp"); alt_up_char_buffer_string(char_buffer, "low.bmp", 0, 18); bmp * flatb = read_bmp("flatb.bmp"); alt_up_char_buffer_string(char_buffer, "flatb.bmp", 0, 19); bmp * flatr = read_bmp("flatr.bmp"); alt_up_char_buffer_string(char_buffer, "flatr.bmp", 0, 20); bmp * blue = read_bmp("bstar.bmp"); alt_up_char_buffer_string(char_buffer, "blue.bmp", 0, 21); bmp * red = read_bmp("rstar.bmp"); alt_up_char_buffer_string(char_buffer, "red.bmp", 0, 22); bmp * flag_img = read_bmp("flag.bmp"); alt_up_char_buffer_string(char_buffer, "flag.bmp", 0, 23); name = read_bmp("name.bmp"); alt_up_char_buffer_string(char_buffer, "name.bmp", 0, 24); instr = read_bmp("instr.bmp"); alt_up_char_buffer_string(char_buffer, "instr.bmp", 0, 25); dcol = read_bmp("dcol.bmp"); alt_up_char_buffer_string(char_buffer, "dcol.bmp", 0, 26); win = read_bmp("win.bmp"); alt_up_char_buffer_string(char_buffer, "win.bmp", 0,27); alt_up_char_buffer_clear(char_buffer); printf("NEW GAME!\n\n"); //interrupt init stuff (for object writing) //TIMERPERIOD int timer_period = 1 * 500000; IOWR_16DIRECT(TIMER_0_BASE, 8, timer_period & 0xFFFF); //writes the period to the hardware timer IOWR_16DIRECT(TIMER_0_BASE, 12, timer_period >> 16); IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3); //stop timer alt_irq_register(TIMER_0_IRQ,NULL,(void*)handle_timer_interrupts);//registers function to a specific IRQ //IOWR_16DIRECT(TIMER_0_BASE, 4, 0x5); //start timer //SET UP KEYBOARD INTERRUPT// ps2 = alt_up_ps2_open_dev(KEYBOARD_NAME); alt_up_ps2_init(ps2); alt_up_ps2_clear_fifo(ps2); //void* keyboard_control_register_ptr = (void*) (PS2_0_BASE + 4); alt_irq_register(PS2_0_IRQ, m, keyboard_ISR); alt_up_ps2_enable_read_interrupt(ps2); char sw = 0; char p_sw = 0; ///////////////////////////////////////////////////////////////////////// printf("NEW GAME!\n\n"); //SUPERDUPERLOOP while (1){ printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state); draw_menu(game_state); //update screen while (old_game_state == game_state); printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state); //only when entering a new menu alt_up_char_buffer_clear(char_buffer); //ENTER GAME LOOP if (game_state == 5){ printf("START GAME! LEVEL: %i\n\n", highlighted_level); alt_up_char_buffer_string(char_buffer, playername, 10, 4); if (highlighted_level == 1) { free_bmp(b); b = read_bmp("para1.bmp"); game_start(m,b,"lvl/1.txt","song1.wav"); } else if (highlighted_level == 2) { free_bmp(b); b = read_bmp("bg2.bmp"); game_start(m,b,"lvl/2.txt","a/abcd.wav"); } else{ free_bmp(b); b = read_bmp("bg3.bmp"); game_start(m,b,"lvl/2.txt","a/nyan1.wav"); } //collision loop while(!m->c->collide && !m->c->win){ alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4); char str[15]; sprintf(str, "%d", m->c->points); alt_up_char_buffer_string(char_buffer, str, 58, 4); sw = IORD_8DIRECT(SWITCHES_BASE,0); IOWR_8DIRECT(LEDS_BASE,0,sw); if(sw == 1 && p_sw == 0){ //m->ab->sfx_flag = 1; m->c->jump_pressed = 1; } p_sw = sw; //boxes int i; for( i= 0 ; i < OBJECT_SIZE ; i++) { if(m->o->color[i] == -1) draw_object(pixel_buffer, box, flat, i); else if(m->o->color[i] == 0) draw_object(pixel_buffer, box, flatb, i); else if(m->o->color[i] == 1) draw_object(pixel_buffer, box, flatr, i); draw_object(pixel_buffer, co, coin, i ); draw_object(pixel_buffer, spikes, spike, i); draw_object(pixel_buffer, box_3, box3, i); draw_object(pixel_buffer, box_1, box1, i); // if(m->color_gates->color[i] == 1) // draw_object(pixel_buffer,cgates, rgate,i); // else if (m->color_gates->color[i] == 0) // draw_object(pixel_buffer,cgates, bgate,i); } //draws the win flag draw_object(pixel_buffer, flag, flag_img, 0); //Draw Doge if (m->c->ducking) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,low); else{ doge++; if(doge == 37) doge = 0; if( doge <9) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge0); else if (doge <18) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge1); else if (doge <27) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge2); else draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge3); } //Draw Color Indicator if(m->c->color == 0) draw_bmp(pixel_buffer, m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, blue); else draw_bmp(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, red); p_counter++; if(p_counter == 3){ p_shift++; alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer unrolled_parallax_draw(pixel_buffer, b); }else if(p_counter == 4){ //if(p_counter == 1){ alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer unrolled_parallax_draw(pixel_buffer, b); p_counter = 0; }else{ // alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) // refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer // unrolled_parallax_draw(pixel_buffer, b); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer int j; for( j = 0 ; j < OBJECT_SIZE ; j++) { clear_object(pixel_buffer, box, b, j); clear_object(pixel_buffer, co, b, j); clear_object(pixel_buffer, spikes, b, j); clear_object(pixel_buffer, box_3, b, j); clear_object(pixel_buffer, box_1, b, j); } clear_object(pixel_buffer,flag,b,0); //clear doge clear_doge(pixel_buffer, m->c->x - m->c->width, m->c->y - m->c->height , b); //clear_loc(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10,m->c->x- m->c->width + 5 - 10, m->c->y - m->c->height - 20,b); } } alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4); char str[15]; sprintf(str, "%d", m->c->points); alt_up_char_buffer_string(char_buffer, str, 58, 4); printf("game exited\n"); if(m->c->win) game_state = 7; else game_state = 6; highlighted_item = 3; game_reset(m); } //exit game mode, restart superduperloop in main menu old_game_state = game_state; } return 0; }
void handle_bmp(uint8_t opmode, char* in_file, char* out_file, char* data_file) { FILE* fp = fopen(in_file, "rb"); bmp_info_t* bi = read_bmp(fp); if(!bi || bi->compression != 0 || bi->bits_per_pixel != 24) { printf("Only non-compressed " "BGR BMP files are supported\n"); exit(1); } uint8_t* pixel_data = copy_pixel_data_bmp(fp, bi); switch(opmode) { case OP_HIDE: { if(!strcmp(in_file, out_file)) { fprintf(stderr, "input and output files must not be the same file\n"); exit(1); } FILE* data_f = fopen(data_file, "rb"); /* ensure data fits into image */ long data_size = file_size_fp(data_f); //printf("data_size=%ld, bi->data_size/8=%ld\n", data_size, (long)bi->data_size/8); if(data_size > (bi->data_size/8)) { fprintf(stderr, "data is too large to fit in image\n"); exit(1); } char* msg = malloc(data_size); memset(msg, 0, data_size); fseek(data_f, 0L, SEEK_SET); fread(msg, 1, data_size, data_f); fclose(data_f); hide_message_bmp(fp, bi, out_file, pixel_data, msg, REVERSE_BITS); break; } case OP_ADDFRAME: { add_red_frame_bmp(bi, pixel_data); put_pixel_data_bmp(fp, out_file, bi, pixel_data); break; } case OP_UNHIDE: { char* msg = get_hidden_msg_bmp(bi, pixel_data, REVERSE_BITS); if(out_file) { FILE* fp = fopen(out_file, "wb"); fwrite(msg, 1, strlen(msg), fp); fclose(fp); } else { puts(msg); } free(msg); break; } } bmp_info_free(bi); fclose(fp); }
int main(int argc, char const *argv[]) { struct window w; if(create_glfw_window(&w)) { return -1; } struct file vertex_file; vertex_file.filename = "shaders/shader.vert"; if(read_file(&vertex_file)) { return -1; } struct file fragment_file; fragment_file.filename = "shaders/shader.frag"; if(read_file(&fragment_file)) { return -1; } GLuint program = create_gl_program(vertex_file.content, fragment_file.content); glCallWrapper(glUseProgram(program)); free(vertex_file.content); free(fragment_file.content); GLuint vao; glCallWrapper(glGenVertexArrays(1, &vao)); glCallWrapper(glBindVertexArray(vao)); // Position glEnableVertexAttribArray(0); // UV glEnableVertexAttribArray(3); GLuint vbo_1; glCallWrapper(glGenBuffers(1, &vbo_1)); glCallWrapper(glBindBuffer(GL_ARRAY_BUFFER, vbo_1)); GLfloat position[] = { -0.50, 0.50, 0.00, 0.50, -0.50, 0.00, -0.50, -0.50, 0.00, -0.50, 0.50, 0.00, 0.50, 0.50, 0.00, 0.50, -0.50, 0.00, }; glCallWrapper(glBufferData(GL_ARRAY_BUFFER, sizeof(position), position, GL_DYNAMIC_DRAW)); glCallWrapper(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL)); mat4 mvp; cglm_mvp(mvp); GLuint mvp_id = glGetUniformLocation(program, "mvp"); glCallWrapper(glUniformMatrix4fv(mvp_id, 1, GL_FALSE, &mvp[0][0])); GLuint vbo_3; glCallWrapper(glGenBuffers(1, &vbo_3)); glCallWrapper(glBindBuffer(GL_ARRAY_BUFFER, vbo_3)); const GLfloat uvs[] = { 0.00, 0.40, 0.40, 0.00, 0.00, 0.00, 0.00, 0.40, 0.40, 0.40, 0.40, 0.00, }; glCallWrapper(glBufferData(GL_ARRAY_BUFFER, sizeof(uvs), uvs, GL_DYNAMIC_DRAW)); glCallWrapper(glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, NULL)); struct image img; img.imagename = "textures/uvtemplate.bmp"; if(read_bmp(&img)) { return -1; } GLuint img_tex; glCallWrapper(glGenTextures(1, &img_tex)); glCallWrapper(glBindTexture(GL_TEXTURE_2D, img_tex)); glCallWrapper(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.width, img.height, 0, GL_RGB, GL_UNSIGNED_BYTE, img.content)); glCallWrapper(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); glCallWrapper(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); free(img.content); GLuint img_tex_id = glGetUniformLocation(program, "img_sampler"); glCallWrapper(glUniform1i(img_tex_id, 0 /* Default active texture */)); while(1) { glCallWrapper(glDrawArrays(GL_TRIANGLES, 0, 6)); glfwSwapBuffers(w.window); glfwPollEvents(); } return 0; }
int main(int argc, char **argv) { // bmp_t *b1, *b2, *bout; img_t *i1, *i2, **m; FILE *f; double zweight; int diameter; img_pyr_t *a_imgpyr, *b_imgpyr; #if 1 double tmin = 0, tmax = 1.0; int i, steps = 32; #else double tmin = 0.5, tmax = 0.5; int i, steps = 1; #endif img_dist_pyr_t *apyr, *bpyr; if (argc != 8) { printf("Usage: morphimg2 <zweight> <diameter> <in1.bmp> <in2.bmp> <in1.pyr> <in2.pyr> <out.bmp>\n"); return 1; } zweight = atof(argv[1]); diameter = atoi(argv[2]); #if 0 /* Read the first bitmap */ f = fopen(argv[3], "r"); if (f == NULL) { printf("Could not open file %s for reading\n", argv[3]); return 1; } b1 = read_bmp(f); fclose(f); /* Read the second bitmap */ f = fopen(argv[4], "r"); if (f == NULL) { printf("Could not open file %s for reading\n", argv[4]); return 1; } b2 = read_bmp(f); fclose(f); /* Convert the bitmaps to images */ if (b1 == NULL || b2 == NULL) { printf("Error reading bitmaps\n"); return 1; } i1 = bmp2img(b1), i2 = bmp2img(b2); if (i1 == NULL || i2 == NULL) { printf("Error in bmp2img conversion\n"); return 1; } #endif i1 = img_read_bmp_file(argv[3]); i2 = img_read_bmp_file(argv[4]); /* Read the first map */ f = open_file(argv[5], "r"); apyr = img_read_distance_pyramid(f); fclose(f); /* Read the second map */ f = open_file(argv[6], "r"); bpyr = img_read_distance_pyramid(f); fclose(f); set_ann_z_weight(zweight); a_imgpyr = img_create_gaussian_pyramid(i1, 0); b_imgpyr = img_create_gaussian_pyramid(i2, 0); #if 1 m = img_morph3(i1, i2, diameter, &(apyr->dmaps[0]), &(bpyr->dmaps[0]), zweight, 1, tmin, tmax, steps); for (i = 0; i < steps; i++) { char outfile[64]; #if 0 bout = img2bmp(m[i]); if (bout == NULL) { printf("Error in img2bmp conversion\n"); return 1; } #endif sprintf(outfile, "%s%03d.bmp", argv[7], i); f = fopen(outfile, "w"); if (f == NULL) { printf("Error opening %s for writing\n", outfile); return 1; } // write_bmp(f, bout); // fclose(f); img_write_bmp_file(m[i], outfile); // free_bmp(bout); } #else iout = img_morph(i1, i2); bout = img2bmp(iout); if (bout == NULL) { printf("Error in img2bmp conversion\n"); return 1; } f = fopen(argv[7], "w"); if (f == NULL) { printf("Error opening %s for writing\n", argv[7]); return 1; } write_bmp(f, bout); fclose(f); free_bmp(bout); #endif // free_bmp(b1); // free_bmp(b2); img_free(i1); img_free(i2); return 0; }
int main(int argc, char *argv[]) { int cols, rows; char *pData,*data; char r,g,b; unsigned int bmpdata1[ROWS][COLS]; unsigned int pixel; unsigned int *pfbmap; struct fb_var_screeninfo fbvar; int fbfd; int i,j,k,t; if(argc != 2){ usage(); return 0; } /* ?��??? ???۸? ???? ?? */ fbfd = open(FBDEVFILE, O_RDWR); if(fbfd < 0){ perror("fbdev open"); exit(1); } /* mmap ?Լ??? ?̿??Ͽ? flame buffer?? ?????? ???? ?ּҸ? ?????? */ /* 1 pixel?? 2byte?? ?ʿ??ϹǷ? *2 */ pfbmap = (unsigned int *) mmap(0, COLS*ROWS*4,PROT_READ|PROT_WRITE, MAP_SHARED, fbfd, 0); if((unsigned)pfbmap == (unsigned)-1) { perror("fbdev mmap"); exit(1); } /* bmp????�� ?о? ?帲 */ read_bmp(argv[1], &pData, &data, &cols,&rows); /**************************** Image 1 *********************************/ i=0;j=0;k=0; for(j=0;j<rows;j++){ k = j*cols*3; /* ?? ?ȼ??? 3byte?ΰ?�� 2byte?? ?ٲ? */ printf("cols = %d, rows = %d, k = %d\n", cols, j+1, k); /* bmp image?? ?????? ?????ǹǷ? ?ؿ??????? ?о??;? ??. */ for(i=0;i<cols;i++) { b = *(data + (k + i*3)); g = *(data + (k + i*3+1)); r = *(data + (k + i*3+2)); pixel = (r << 16) | (g << 8) | (b); bmpdata1[(rows-1-j)][i] = pixel; } } /* bmp ???Ͽ??? ??�� data?? ?��??? ?????? ?? ī?? ?? */ //memcpy(pfbmap, bmpdata1, COLS*ROWS*4); memcpy(pfbmap, bmpdata1, COLS*ROWS*4); /* Ȱ?? ??�� ?θ???�� ??��?? ?? ?��??? ???۷? close ?? */ munmap(pfbmap,ROWS*COLS*4); close_bmp(&pData); close(fbfd); return 0; }
int read_frame(int number, TFrame *frame) { char filename[MAX_NAME_LEN]; int errcode; int i, j; float factor; frame->time = 0.0; if(input_format == FORMAT_IPX) { /* IPX VIDEO FORMAT */ /* IPX code reads in a single frame and converts to floats */ if(IPX_read_frame(number, frame, &ipx_read_status)) { printf("Error: Could not read frame %d from IPX file %s\n", number, input_template); exit(1); } }else { /* A SET OF FRAME STILLS */ /* Get the filename */ sprintf(filename, input_template, number); /* Read the data in raw format */ errcode = 0; switch(input_format) { case FORMAT_BMP: { errcode = read_bmp(filename, &readraw); break; } case FORMAT_PNG: { errcode = read_png(filename, &readraw); break; } default: { errcode = IO_ERROR_FORMAT; } } /* Check error code */ if(errcode) { switch(errcode) { case IO_ERROR_OPEN: { printf("Error: Could not open input file %s\n", filename); break; } case IO_ERROR_FORMAT: { printf("Error: Input file %s has an invalid file format\n", filename); break; } case IO_ERROR_SIZE: { printf("Error: Size of frame %s different to previous frames\n", filename); break; } case IO_ERROR_OTHER: { printf("Error: Could not read input file %s\n", filename); break; } } exit(1); } /* Check/Allocate the frame */ /* Check if the frame has been allocated */ if(frame->allocated) { /* Data already allocated - check same size */ if((frame->width != readraw.width) || (frame->height != readraw.height)) { /* This should never happen - checked already */ printf("\n====== OUT OF CHEESE ERROR =========\n"); exit(1); } }else { /* Allocate memory. Note organised in COLUMNS */ frame->data = (float**) malloc(sizeof(float*)*readraw.width); for(i=0;i!=readraw.width;i++) frame->data[i] = (float*) malloc(sizeof(float)*readraw.height); frame->width = readraw.width; frame->height = readraw.height; frame->allocated = 1; } /* Change the data to be floating point between 0 and 1 */ factor = (float) ((1 << readraw.bpp) - 1) ; if(readraw.channels != 1) { /* Input frame is in color */ if(readraw.bpp > 8) { printf("\nSorry: Cannot read color images with bpp > 8 yet\n"); exit(1); }else { /* Convert red channel */ for(i=0;i<frame->width;i++) { for(j=0;j<frame->height;j++) { frame->data[i][j] = ((float) readraw.data[j][readraw.channels*i]) / factor; } } } }else { /* Greyscale image */ if(readraw.bpp > 16) { printf("\nSorry: Cannot read greyscale images > 16bpp yet\n"); exit(1); }else if(readraw.bpp > 8) { /* Data has 2 bytes per pixel */ for(i=0;i<frame->width;i++) { for(j=0;j<frame->height;j++) { frame->data[i][j] = ( 256.0*((float) readraw.data[j][2*i]) + ((float) readraw.data[j][2*i+1]) ) / factor; } } }else { /* if less than 8 bit, data must be unpacked into one byte per pixel */ for(i=0;i<frame->width;i++) { for(j=0;j<frame->height;j++) { frame->data[i][j] = ((float) readraw.data[j][i]) / factor; } } } } } frame->number = number; return(0); }
int main(int argc, char** argv){ if(argc != 3){ printf("Useage: %s image n_threads\n", argv[0]); exit(-1); } int n_threads = atoi(argv[2]); pthread_t threads[n_threads]; unsigned char* image = read_bmp(argv[1]); unsigned char* output_image = malloc(sizeof(unsigned char) * image_size); int* histogram = (int*)calloc(sizeof(int), color_depth); int** histograms = (int**)malloc(sizeof(int*)*n_threads); // This for loop have very few iterations so I will not parallelize it (the overhead is greater than the gain) for(int i=0;i<n_threads;i++) { histograms[i] = (int*)calloc(sizeof(int), color_depth); } //For each pixel, increment the correct cell in the local histogram for(int thread = 0; thread<n_threads; thread++) { histogram_count_args* a = malloc(sizeof(histogram_count_args)); a->n_threads = n_threads; a->thread_n = thread; a->histograms = histograms; a->image = image; pthread_create(&threads[thread], NULL, threaded_histogram_count, (void *)a); } for(int i = 0; i < n_threads; i++) pthread_join(threads[i], NULL); // Wait for all threads to finish // For each cell in the local histogram, add it to the global histogram // For the color depths used in these example images, paralellizing this is not that usefull, // For images with larger color depth however, it's quite usefull. for(int thread = 0; thread<n_threads; thread++) { histogram_sum_args* a = malloc(sizeof(histogram_sum_args)); a->n_threads = n_threads; a->thread_n = thread; a->histogram = histogram; a->histograms = histograms; pthread_create(&threads[thread], NULL, threaded_histogram_sum, (void *)a); } for(int i = 0; i < n_threads; i++) pthread_join(threads[i], NULL); // Wait for all threads to finish for(int i=0;i<color_depth;i++) { } float* transfer_function = (float*)calloc(sizeof(float), color_depth); for(int thread = 0; thread<n_threads; thread++) { transfer_args* a = malloc(sizeof(transfer_args)); a->n_threads = n_threads; a->thread_n = thread; a->transfer_function = transfer_function; a->histogram = histogram; pthread_create(&threads[thread], NULL, threaded_transfer, (void *)a); } for(int i = 0; i < n_threads; i++) pthread_join(threads[i], NULL); // Wait for all threads to finish for(int i = 0; i < image_size; i++){ output_image[i] = transfer_function[image[i]]; } write_bmp(output_image, image_width, image_height); // A little code snippet to compare the result to a correct.bmp image. // This is here just for testing. unsigned char* fasit = read_bmp("correct.bmp"); int no_errors = 1; for(int i=0;i<image_size;i++) { if(!(output_image[i] == fasit[i] || output_image[i]+1 == fasit[i] || output_image[i]-1 == fasit[i])) { no_errors = 0; } } printf("Correct: %d\n", no_errors); }
void main(void) { unsigned char n; #pragma optsize- #asm("cli") n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm))) | PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; CCP=CCP_IOREG_gc; PMIC.CTRL=n; PMIC.INTPRI=0x00; #pragma optsize_default system_clocks_init(); ports_init(); usartc0_init(); usartd1_init(); rtc32_init_my(); delay_ms(50); tcd0_init(); twie_init(); sprintf(info,"start i2c"); monitor(); delay_ms(50); #asm("sei") delay_ms(1); PORTE.OUT=PORTE.OUT|0b00010000; init_buferU1(); delay_ms(50); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); PORTE.OUT=PORTE.OUT|0b00010000; init_buferU2(); delay_ms(50); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); PORTE.OUT=PORTE.OUT|0b00010000; init_buferU3(); delay_ms(50); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); sprintf(info,"buf i2c start ok"); monitor(); delay_ms(50); PORTE.OUT=PORTE.OUT|0b00010000; bmp_reg_init(); delay_ms(50); sprintf(info,"bmp i2c start ok"); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(50); monitor(); delay_ms(100); spic_init(); sprintf(info,"SPI START"); monitor(); #asm("sei") delay_ms(200); check_sd_card(); spic_init(); PORTA.DIRSET=0b00000001; PORTA.OUTSET = 0b00000001; delay_ms(10); PORTA.OUTCLR = 0b00000001; delay_ms(100); PORTA.OUTSET = 0b00000001; delay_ms(10); ad7705_init(can1cl,mclk4,can1set,set1); delay_ms(10); PORTE.OUT=PORTE.OUT&0b11101111; delay_ms(10); PORTE.OUT=PORTE.OUT|0b00010000; sprintf(info,"ad7705 start ok"); monitor(); RESULT=ad7705(1); S0[7]=RESULT;// Сигнал усилителя младший S0[8]=(RESULT>>8); //Сигнал усилителя старший // ADCA initialization adca_init(); // ADCB initialization adcb_init(); // Timer/Counter tcc0_init(); tcc1_init(); tcf0_init(); delay_ms(10); sprintf(info,"start device"); monitor(); delay_ms(50); if(Xsave==0xFFFFFFFF)Xsave=0; sprintf(info,"START WHILE"); monitor(); delay_ms(50); if(RTC32.CNT<1454622753) RTC32.CNT=1454622753; PORTE.OUT=PORTE.OUT&0b11101111; //прописываем заводской ответ //!!!! важно смертельно initzavod(); reginit(); while (1) { PORTR.OUTTGL=0b00000010; //////////////////////////////////////************************************* //поиск ошибки буфера //buferU1_error(); //включаю подсветку //if(error_buf!=0) PORTE.OUT=PORTE.OUT|0b00010000; init_buferU1(); ///////////////////////////////////////////////////////////////////////////// read_bmp(); /////////////////////////////////////////////////////////////// if((0.0<Tempf&&Tempf<60.0)&&(300.0<p1&&p1<825.0)) { Tempf_K=Tempf*10.0+2730.0; S0[11]=Tempf_K;// температура бмп младший S0[12]=(Tempf_K>>8); //температура бмп старший /////////////////////////////////////////////////////////////// S0[15]=p/10;//ДАВЛЕНИЕ бмп младший S0[16]=(p/10>>8);//ДАВЛЕНИЕ бмп старший } init_buferU2(); if(SD_IN) { get_CNTRTC(&X); calcDateTime(X, 0, &date1,&time1); bufform(); GETFILNAME(); } init_buferU3(); buferU1_opros(); buferU2_opros(); buferU3_opros(); //обработочка //21.1 b2 io7 + if((U2in.input&0b10000000)==0b10000000) S0[21]=S0[21]|0b00000010; else if((U2in.input&0b10000000)==0b00000000) S0[21]=S0[21]&0b11111101; //21.2 b1 io4 + if((U1in.input&0b00010000)==0b00010000) S0[21]=S0[21]|0b00000100; else if((U1in.input&0b00010000)==0b00000000) S0[21]=S0[21]&0b11111011; //21.3 b1 io5 + if((U1in.input&0b00100000)==0b00100000) S0[21]=S0[21]|0b00001000; else if((U1in.input&0b00100000)==0b00000000) S0[21]=S0[21]&0b11110111; //21.4 b1 io1 ---- if((U1in.input&0b00000010)==0b00000010) S0[21]=S0[21]|0b00010000; else if((U1in.input&0b00000010)==0b00000000) S0[21]=S0[21]&0b11101111; //21.5 b2 io3 if((U2in.input&0b00001000)==0b00001000) S0[21]=S0[21]|0b00100000; else if((U2in.input&0b00001000)==0b00000000) S0[21]=S0[21]&0b11011111; //21.6 b2 io4 if((U2in.input&0b00010000)==0b00010000) S0[21]=S0[21]|0b01000000; else if((U2in.input&0b00010000)==0b00000000) S0[21]=S0[21]&0b10111111; //21.6 b3 io6 if((U3in.input&0b01000000)==0b01000000) S0[21]=S0[21]|0b10000000; else if((U3in.input&0b01000000)==0b00000000) S0[21]=S0[21]&0b01111111; //пождиг if( (B5upr&0b00000010)==0b00000010 ) { U3out.output=U3out.output|0b00000010; } else if( (B5upr&0b00000010)==0b00000000 ) {U3out.output=U3out.output&0b11111101;} //клапан1 if( (B5upr&0b00000100)==0b00000100 ) {U3out.output=U3out.output|0b00000100;} else if( (B5upr&0b00000100)==0b00000000 ) {U3out.output=U3out.output&0b11111011;} //контрольная кювета if( (B5upr&0b00001000)==0b00001000) {U1out.output=U1out.output&0b00111111; U1out.output=U1out.output|0b01000000;} else if((B5upr&0b00001000)==0b00000000) {U1out.output=U1out.output&0b00111111; U1out.output=U1out.output|0b10000000;} //клапан 2 if( (B5upr&0b00010000)==0b00010000 ) {U3out.output=U3out.output|0b00001000;} else if( (B5upr&0b00010000)==0b00000000 ) {U3out.output=U3out.output&0b11110111;} //клапан 3 if( (B5upr&0b00100000)==0b00100000 ) {U3out.output=U3out.output|0b00010000;} else if( (B5upr&0b00100000)==0b00000000 ) {U3out.output=U3out.output&0b11101111;} //реле 1 инверсно if( (B5upr&0b01000000)==0b01000000 ) {U1out.output=U1out.output&0b11111110;} else if( (B5upr&0b01000000)==0b00000000 ) {U1out.output=U1out.output|0b00000001;} //реле 2 инверсно if( (B5upr&0b10000000)==0b10000000 ) {U2out.output=U2out.output&0b11111110;} else if( (B5upr&0b10000000)==0b00000000 ) {U2out.output=U2out.output|0b00000001;} buferU1_set(); buferU2_set(); buferU3_set(); //////////////////////////////////////************************************* //установка даты времени if ((newtime==1)||(newdate==1)) { calcSeconds(date1,time1,0,&X); Xsave=X;//последняя установка set_CNTRTC(); newdate=0; newtime=0; } }
int read_image(const char *filename, int *width, int *height, unsigned char *rgb) { char buf[4]; unsigned char *ubuf = (unsigned char *) buf; int success = 0; FILE *file; file = fopen(filename, "rb"); if (file == NULL) return(0); /* see what kind of file we have */ fread(buf, 1, 4, file); fclose(file); if (!strncmp("BM", buf, 2)) { success = read_bmp(filename, width, height, rgb); } else if (!strncmp("GIF8", buf, 4)) { #ifdef HAVE_LIBGIF success = read_gif(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with GIF support\n"); success = 0; #endif /* HAVE_LIBGIF */ } else if ((ubuf[0] == 0xff) && (ubuf[1] == 0xd8)) { #ifdef HAVE_LIBJPEG success = read_jpeg(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with JPEG support\n"); success = 0; #endif /* HAVE_LIBJPEG */ } else if ((ubuf[0] == 0x89) && !strncmp("PNG", buf+1, 3)) { #ifdef HAVE_LIBPNG success = read_png(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with PNG support\n"); success = 0; #endif /* HAVE_LIBPNG */ } else if (( !strncmp("P6\n", buf, 3)) || (!strncmp("P5\n", buf, 3)) || (!strncmp("P4\n", buf, 3)) || (!strncmp("P3\n", buf, 3)) || (!strncmp("P2\n", buf, 3)) || (!strncmp("P1\n", buf, 3))) { #ifdef HAVE_LIBPNM success = read_pnm(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with PNM support\n"); success = 0; #endif /* HAVE_LIBPNM */ } else if (((!strncmp ("MM", buf, 2)) && (ubuf[2] == 0x00) && (ubuf[3] == 0x2a)) || ((!strncmp ("II", buf, 2)) && (ubuf[2] == 0x2a) && (ubuf[3] == 0x00))) { #ifdef HAVE_LIBTIFF success = read_tiff(filename, width, height, rgb); #else fprintf(stderr, "Sorry, this program was not compiled with TIFF support\n"); success = 0; #endif } else { fprintf(stderr, "Unknown image format\n"); success = 0; } return(success); }