void qr_code_generation ( char *input, char *output ) { int i; int version; int size; char *str_source_bin; char *data; char **blocks; char **pattern; int **correction_blocks; str_source_bin = convert_to_utf8( input ); //convert string to utf8 ascii version = optimal_version( strlen( str_source_bin ) ); //optimal version str_source_bin = add_service_inf(str_source_bin, &version); //add service information into string blocks = create_blocks( str_source_bin, version ); //create blocks correction_blocks = create_correction_block( blocks, version ); //create correction blocks data = create_data ( blocks, correction_blocks, version ); //create data for qr code pattern = create_canvas_pattern ( data, version ); //create pattern for bmp create_bmp( pattern, output, version ); //create bmp //free str_source_bin free ( str_source_bin ); //free blocks //free correction_blocks for ( i = 0; i < number_of_blocks[version]; i++ ) { free( blocks[i] ); free( correction_blocks[i] ); } free( blocks ); free( correction_blocks ); //free data free( data ); //free pattern size = ( ( ( version - 1 ) * 4 ) + 21 ); size+=8; //white border for ( i = 0; i < size; i++ ) free( pattern[i] ); free( pattern ); }
bmp_t* convert_24bpp(bmp_t *bmp){ bmp_t *converted = create_bmp(bmp->info.w, bmp->info.h, 24); if (!converted){ fprintf(stderr, "convert_24bpp error: Failed to allocate room for conversion\n"); return NULL; } int w = bmp->info.w, h = bmp->info.h; for (int i = 0; i < h; ++i){ for (int j = 0; j < w; ++j){ uint8_t color[3]; get_pixel(bmp, j, i, &color[0], &color[1], &color[2]); set_pixel(converted, j, i, color[0], color[1], color[2]); } } return converted; }
static View* create_title_view(Window* window) { if (!window) return NULL; Rect title_view_frame = rect_make(point_make(0, 0), size_make(window->frame.size.width, WINDOW_TITLE_VIEW_HEIGHT)); View* title_view = create_view(title_view_frame); title_view->background_color = window->border_color; Button* close_button = create_button(rect_make(point_zero(), size_make(CHAR_WIDTH * 2, title_view->frame.size.height)), "X"); close_button->mousedown_handler = (event_handler)&close_button_clicked; add_button(title_view, close_button); Button* minimize_button = create_button(rect_make(point_make(rect_max_x(close_button->frame), 0), size_make(CHAR_WIDTH * 2, title_view->frame.size.height)), "-"); minimize_button->mousedown_handler = (event_handler)&minimize_button_clicked; add_button(title_view, minimize_button); //add title label to title view int label_length = 20 * CHAR_WIDTH; Rect label_frame = rect_make(point_make(rect_max_x(minimize_button->frame) + 15, title_view_frame.size.height / 2 - (CHAR_HEIGHT / 2)), size_make(label_length, CHAR_HEIGHT)); Label* title_label = create_label(label_frame, window->title); title_label->text_color = color_black(); add_sublabel(title_view, title_label); Bmp* dots = create_bmp(title_view_frame, create_layer(title_view_frame.size)); uint8_t* ref = dots->layer->raw; for (int y = 0; y < dots->frame.size.height; y++) { for (int x = 0; x < dots->frame.size.width; x++) { if (!((x + y) % 2)) { *ref++ = 50; *ref++ = 50; *ref++ = 50; } else { *ref++ = 200; *ref++ = 160; *ref++ = 90; } } } add_bmp(title_view, dots); return title_view; }
void dump_histo_img(unsigned char* histo, unsigned int height, unsigned int width, const char *filename) { RGB* pixel_map = (RGB*) malloc (height*width*sizeof(RGB)); size_t y, x; for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { unsigned char value = histo[y * width + x]; if (value == 0){ pixel_map[y*width+x].R = 0; pixel_map[y*width+x].G = 0; pixel_map[y*width+x].B = 0; } else { pixel_map[y*width+x] = HSVtoRGB(0.0,1.0,cbrt(1+ 63.0*((float)value)/((float)UINT8_MAX))/4); } } } create_bmp(pixel_map, height, width, filename); free(pixel_map); }