counting_bloom_t *new_counting_bloom(unsigned int capacity, double error_rate) { counting_bloom_t *cur_bloom; cur_bloom = counting_bloom_init(capacity, error_rate, 0); cur_bloom->bitmap = new_bitmap(cur_bloom->num_bytes); cur_bloom->header = (counting_bloom_header_t *) (cur_bloom->bitmap->array); return cur_bloom; }
void ScopeGUI::allocate_bitmaps() { if(waveform_bitmap) delete waveform_bitmap; if(vector_bitmap) delete vector_bitmap; int w; int h; // printf("ScopeGUI::allocate_bitmaps %d %d %d %d %d\n", // __LINE__, // wave_w, // wave_h, // vector_w, // vector_h); w = MAX(wave_w, 16); h = MAX(wave_h, 16); waveform_bitmap = new_bitmap(w, h); w = MAX(vector_w, 16); h = MAX(vector_h, 16); vector_bitmap = new_bitmap(w, h); }
counting_bloom_t *new_counting_bloom(unsigned int capacity, double error_rate, const char *filename) { counting_bloom_t *cur_bloom; int fd; if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600)) < 0) { perror("Error, Opening File Failed"); fprintf(stderr, " %s \n", filename); return NULL; } cur_bloom = counting_bloom_init(capacity, error_rate, 0); cur_bloom->bitmap = new_bitmap(fd, cur_bloom->num_bytes); cur_bloom->header = (counting_bloom_header_t *)(cur_bloom->bitmap->array); return cur_bloom; }
counting_bloom_t *counting_bloom_from_file(unsigned capacity, double error_rate, const char *filename) { counting_bloom_t *cur_bloom; int fd; if ((fd = open(filename, O_RDWR, (mode_t)0600)) < 0) { perror("Error, Opening File Failed"); fprintf(stderr, " %s \n", filename); return NULL; } cur_bloom = counting_bloom_init(capacity, error_rate, 0); cur_bloom->parent_bitmap = new_bitmap(fd, cur_bloom->num_bytes); return cur_bloom; }
scaling_bloom_t *scaling_bloom_init(unsigned int capacity, double error_rate, const char *filename, int fd) { scaling_bloom_t *bloom; if ((bloom = (scaling_bloom_t *)malloc(sizeof(scaling_bloom_t))) == NULL) { return NULL; } if ((bloom->bitmap = new_bitmap(fd, sizeof(scaling_bloom_header_t))) == NULL) { fprintf(stderr, "Error, Could not create bitmap with file\n"); free_scaling_bloom(bloom); return NULL; } bloom->header = (scaling_bloom_header_t *) bloom->bitmap->array; bloom->capacity = capacity; bloom->error_rate = error_rate; bloom->num_blooms = 0; bloom->num_bytes = sizeof(scaling_bloom_header_t); bloom->fd = fd; bloom->blooms = NULL; return bloom; }
counting_bloom_t *new_counting_bloom_from_file(unsigned int capacity, double error_rate, const char *filename) { int fd; off_t size; counting_bloom_t *bloom; if ((fd = open(filename, O_RDWR, (mode_t)0600)) < 0) { fprintf(stderr, "Error, Could not open file %s: %s\n", filename, strerror(errno)); return NULL; } if ((size = lseek(fd, 0, SEEK_END)) < 0) { perror("Error, calling lseek() to tell file size"); close(fd); return NULL; } if (size == 0) { fprintf(stderr, "Error, File size zero\n"); } bloom = counting_bloom_init(capacity, error_rate, 0); if (size != bloom->num_bytes) { free_counting_bloom(bloom); fprintf(stderr, "Error, Actual filesize and expected filesize are not equal\n"); return NULL; } if ((bloom->bitmap = new_bitmap(fd, size)) == NULL) { fprintf(stderr, "Error, Could not create bitmap with file\n"); free_counting_bloom(bloom); return NULL; } bloom->header = (counting_bloom_header_t *)(bloom->bitmap->array); return bloom; }
int main(int argc , char *argv[]) { // bitmap file and header information bitmap* bmp = new_bitmap(); // RGB pixel data bitmap_pixel pixel; // current column out of all possible columns in output uint32_t current_output_column = 0; // current row out of all possible rows in output uint32_t current_output_row = 0; // current read position of the source line; should // only vary from 0 to number of columns in row. uint32_t source_row_x = 0; // starting output position of the bitmap pixel data uint32_t file_offset = bmp->bitmap_file_header.fileoffset_to_pixelarray; // value read from input source int16_t read_value; #ifdef DEBUG int16_t min_read = 0; int16_t max_read = 0; print_bitmap_info(bmp); printf("OUTPUT_ROW_BYTES: %u\n", OUTPUT_ROW_BYTES); printf("OUTPUT_ROW_BYTES_WITHOUT_PADDING: %u\n", OUTPUT_ROW_BYTES_WITHOUT_PADDING); printf("OUTPUT_RAW_SINGLE_UNITS: %u\n", OUTPUT_RAW_SINGLE_UNITS); #endif FILE* output_file = fopen(OUTPUT_FILE_PATH,"wb+"); FILE* input_file = fopen(INPUT_FILE_PATH, "r"); // Done with the bitmap information, write that to output. All remaining // pixel data comes afterwards which doesn't depend on any of the header // information. fwrite(bmp, 1, sizeof(bitmap), output_file); free(bmp); // for each output that needs to be written ... int i=0; while(i < OUTPUT_RAW_SINGLE_UNITS) { // If this is the end of the row, write the bitmap padding, // advance the row, and reset the column position. Additionally, // since no data was read from the source, don't increment counter. if (current_output_column + PIXEL_BYTES > OUTPUT_ROW_BYTES_WITHOUT_PADDING) { write_bitmap_row_padding(output_file); current_output_column = 0; current_output_row += INVERSE_SCALE; source_row_x = 0; continue; } // seek to next altimetry reading fseek(input_file, (current_output_row * NLON) + source_row_x, 0); // read value fread(&read_value, 1, 2, input_file); // fix endieness read_value = BYTE_SWAP(read_value); // convert to RGB value z_to_pixel(read_value, &pixel); // write to output bitmap_write_pixel(output_file, pixel); // increment counters source_row_x += INVERSE_SCALE; current_output_column += PIXEL_BYTES; i++; #ifdef DEBUG if (read_value < min_read) { min_read = read_value; } if (read_value > max_read) { max_read = read_value; } #endif } // write last padding pixels (if necessary) if (current_output_column > OUTPUT_ROW_BYTES_WITHOUT_PADDING) { write_bitmap_row_padding(output_file); } fclose(output_file); fclose(input_file); #ifdef DEBUG printf("min value read: %d\n", min_read); printf("max value read: %d\n", max_read); #endif return 0; }
bitmap_type * pbm_get_block (unsigned height) { static int image_format; static int image_height; static int image_width = -1; static unsigned scanline_count = 0; static one_byte *saved_scanline = NULL; dimensions_type d; unsigned row; boolean row_has_black; bitmap_type *b = XTALLOC (1, bitmap_type); boolean found_black = false; int c = getc (pbm_input_file); if (c == EOF) return NULL; ungetc (c, pbm_input_file); if (image_width == -1) pbm_readpbminit (pbm_input_file, &image_width, &image_height, &image_format); DIMENSIONS_WIDTH (d) = image_width; DIMENSIONS_HEIGHT (d) = height; *b = new_bitmap (d); for (row = 0; row < height; row += found_black) { if (scanline_count == image_height) FATAL2 ("%s: Tried to read image row %d", pbm_input_filename, scanline_count); if (saved_scanline) { memcpy (BITMAP_ROW (*b, row), saved_scanline, image_width); saved_scanline = NULL; } else { pbm_readpbmrow (pbm_input_file, BITMAP_ROW (*b, row), image_width, image_format); scanline_count++; if (trace_scanlines) { printf ("%5d:", scanline_count); for (c = 0; c < image_width; c++) putchar (BITMAP_ROW (*b, row)[c] ? '*' : ' '); putchar ('\n'); } } /* Ignore this row if it was all-white and we haven't seen any black ones yet. */ row_has_black = memchr (BITMAP_ROW (*b, row), BLACK, image_width) != NULL; if (!found_black && row_has_black) { /* Our first non-blank row. */ found_black = true; } if (row >= height - BLANK_COUNT && row_has_black) { /* We've hit a nonblank row where we shouldn't have. Save this row and return. */ saved_scanline = BITMAP_ROW (*b, row); break; } } BITMAP_HEIGHT (*b) = height - BLANK_COUNT; return b; }
int main() { char pressKey; int ret; bitmap *bm; u_char *w; sys_init(); sleep(2); add_dbs_beep(NULL, 0, 1); bm = new_bitmap("./test.bmp"); SetSrceenColor(0xFFFF); if (init_fonts() != -1) { disp_line("123-:+09", 0, 0, disp12_char); disp_line("123-:+09", 0, 100, disp36_char); } char *path_b = gppath(getpid()); char *path_d = strdup(path_b); printf("This program path is: '%s' at '%s'\n", basename(path_b), dirname(path_d)); u_char dt[7]; get_bcd_datetime(dt); DBG_MEM("BCD datetime:", dt, 7); /* int i; for (i=319; i>-320; i--) { if (i>0) { disp_bitmap(bm, 0, i, 320-i, 240, 0, 0); } else { disp_bitmap(bm, 0, 0, 320+i, 240, 0, -i); } } */ u_char *buf = NULL; u_char factor[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; u_char key[8] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}; u_char m_key[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; int p_len = 0; u_long t1, t2; cpu_card_data_t *ccd = NULL; u_long csn; /* alarm test code begin DBG("Syn alarm 4 times..."); ret = add_syn_beep(&t1, 0, 4); DBG("OK, wait 5 sec(ret: %d)\n", ret); sleep(5); DBG("Syn alarm 4 sec..."); ret = add_syn_beep(&t2, 4000, 0); DBG("OK(ret: %d)\n", ret); sleep(1); terminate_alarm(t2); /* alarm test code end */ while (1) { printf("Press 'b' to test beep\n"); printf("Press 'c' to test COM1\n"); printf("Press 'g' to test GPRS\n"); printf("Press 'p' to test PSAM\n"); printf("Press 'm' to test MIFARE\n"); printf("Press 'e' to enter test screen\n"); pressKey=getchar(); switch (pressKey) { case 'b': test_beep(); break; case 'c': test_COM1(); break; case 'g': startup_poll(); break; case 'p': /* pc = new_ty_psam_cos(); if (NULL == pc) { DBG("Create psam card fail!\n"); break; } DBG("Select file 0x3F00..."); ret = psam_select_id(pc, &buf, 0x3F00); if (ret == -1) { DBG("fail!\n"); break; } DBG_MEM("ok!\nResponse:", buf, ret); DBG("Select file 0x1001..."); ret = psam_select_id(pc, &buf, 0x1001); if (ret == -1) { DBG("fail!\n"); break; } DBG_MEM("ok!\nResponse:", buf, ret); t1 = get_tickcount(); ret = calc_descrypt1(pc, factor, key, 0x0D); t2 = get_tickcount(); if (ret == 0) { DBG("Calcuate descrype OK\n"); DBG_MEM("factor:", factor, 8); DBG_MEM("key:", key, 8); } else DBG("Calcuate descrypt fail!\n"); */ DBG("Calculate descrype consumed %d ms.\n", t2-t1); break; case 'm': /* ret = get_card_sn(&buf); DBG("Get card SN ret: %d (buf: %d)\n", ret, malloc_usable_size(buf)); if (ret != -1) DBG_MEM("SN:", buf, ret); else break; csn = (u_long)(*buf); if ((buf[4] & 0x20)) { DBG("**** CPU Card ****\nReset card ..."); ret = reset_cpu_card(&buf); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nATS:", buf, ret); if (NULL == ccd) { DBG("To create cpu_card_data_t...\n"); ccd = new_cpu_card_data(6001, 1, 21); if (NULL == ccd) { DBG("fail!\n"); break; } else DBG("Ok.\n"); } init_cpu_card_data(ccd, csn, buf, ret, 8, 8); DBG("Fast debit wallet 0.01..."); ret = fast_debit_wallet_PUB1(&fmcos2_opr, ccd, 1); if (-1 == ret) { DBG("fail! ret: %d, errno: %d\n", ret, get_cpu_carderr(ccd)); break; } DBG("Ok! Balance: %d.%d\n", get_pub_wallet_balance(ccd)/100, get_pub_wallet_balance(ccd)%100); */ /* memcpy(factor, buf+ret-8, 8); DBG_MEM("factor:", factor, 8); DBG("\nGet Callagne..."); ret = rf_get_challenge(&fmcos2_opr, &buf, 4); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); memcpy(key, buf, 4); memset(key+4, 0, 4); DBG_MEM("key:", key, 8); DBG("Calculate descrypt..."); ret = calc_descrypt1(factor, key, 0x0D); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResopnse:", key, 8); DBG("Select ADF1..."); ret = rf_select_file_id(&fmcos2_opr, &buf, 0x1001); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResopnse:", buf, ret); DBG("Read Person file(id=2)..."); ret = rf_read_binary(&fmcos2_opr, &buf, 2, 0, NULL, 0); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); DBG("Read wallet file (id=4)..."); ret = rf_read_record(&fmcos2_opr, &buf, 1, 4, NULL, 12); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); DBG("Authenticate Key(id=0x0E)..."); ret = rf_extern_authent(&fmcos2_opr, &buf, 0x0E, key); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); t2 = get_tickcount(); printf("CPU card time %dms", t2-t1); */ /* } else { DBG("**** Mifare Card ****\nAuthent sector 1..."); ret = authent_mifare_card(m_key, 3, MIFARE_KEYA); if (ret != 0) { DBG("fail!(%d)\n", ret); break; } DBG("ok!\nRead block 0..."); ret = read_mifare_card(&buf, 0); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG("ok!(%d)\n", ret); DBG_MEM("Block 0:", buf, ret); DBG("Write x0FF to block 1..."); memset(buf, 0xff, sizeof(buf)); ret = write_mifare_card(buf, 1); if (ret != 0) { DBG("fail!(%d)\n", ret); break; } DBG("ok!\nRead block 1..."); ret = read_mifare_card(&buf, 1); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG("ok!(%d)\n", ret); DBG_MEM("Block 1:", buf, ret); }*/ break; } if (pressKey=='e') break; } }