Changeset 78 in projects for paper-tape-project/trunk/visualisator/lochstreifen.c
- Timestamp:
- Jul 27, 2013, 8:49:16 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
paper-tape-project/trunk/visualisator/lochstreifen.c
r77 r78 82 82 **/ 83 83 LOCHSTREIFEN* lochstreifen_copy(const LOCHSTREIFEN* template) { 84 LOCHSTREIFEN *l = malloc (sizeof(LOCHSTREIFEN)); 84 LOCHSTREIFEN *l = lochstreifen_new(); 85 85 86 #define COPY_RGBA_PATTERN(name) { double r,g,b,a; \ 86 87 if(template->name != NULL && \ … … 93 94 l->highlight_region_start = template->highlight_region_start; 94 95 l->highlight_region_end = template->highlight_region_end; 95 printf("Copy1\n");96 96 COPY_RGBA_PATTERN(highlight_region_color); 97 printf("Copy2\n");98 97 l->highlight_row_number = template->highlight_row_number; 99 98 COPY_RGBA_PATTERN(highlight_row_color); … … 457 456 **/ 458 457 void lochstreifen_remove_clip(LOCHSTREIFEN *l) { 459 free(l->clip); 458 if(l->clip != NULL) 459 free(l->clip); 460 460 l->clip = NULL; // not neccessary, I suppose. 461 461 } … … 469 469 void lochstreifen_set_scaling_by_length(LOCHSTREIFEN *l, int length) { 470 470 double scale_factor = ((double)length) / LOCHSTREIFEN_LENGTH; 471 printf("Scaling to length=%i, having length=%f, getting %f as scale factor\n",471 fprintf(stderr, "Scaling to length=%i, having length=%f, getting %f as scale factor\n", 472 472 length, LOCHSTREIFEN_LENGTH, scale_factor); 473 473 cairo_matrix_scale(&l->matrix, scale_factor, scale_factor); 474 l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor; 474 475 lochstreifen_check_matrix(l); 475 476 } … … 478 479 double scale_factor = ((double)width) / LOCHSTREIFEN_WIDTH; 479 480 cairo_matrix_scale(&l->matrix, scale_factor, scale_factor); 481 l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor; 480 482 lochstreifen_check_matrix(l); 481 483 } … … 484 486 double scale_factor = ((double)diameter)/2 / LOCHSTREIFEN_RADIUS_CODE_HOLE; 485 487 cairo_matrix_scale(&l->matrix, scale_factor, scale_factor); 488 l->matrix.x0 *= scale_factor; l->matrix.y0 *= scale_factor; 486 489 lochstreifen_check_matrix(l); 487 490 } … … 749 752 // standard 750 753 case LOCHSTREIFEN_MOVEMENT_TO_TOP: 751 //cairo_matrix_rotate();754 752 755 case LOCHSTREIFEN_MOVEMENT_TO_RIGHT: 753 756 754 757 case LOCHSTREIFEN_MOVEMENT_TO_BOTTOM: 755 758 756 759 case LOCHSTREIFEN_MOVEMENT_NONE: 757 760 default: … … 941 944 cairo_user_to_device(cr, &x, &y); 942 945 cairo_user_to_device_distance(cr, &width, &height); 943 printf("draw: %i|%i %ix%i ", (int)x, (int)y, (int)width, (int)height);944 } else printf("draw: ");945 printf("row %i->%i track %i->%i\n", row, row_max, track_min, track_max);946 fprintf(stderr, "draw: %i|%i %ix%i ", (int)x, (int)y, (int)width, (int)height); 947 } else fprintf(stderr, "draw: "); 948 fprintf(stderr, "row %i->%i track %i->%i\n", row, row_max, track_min, track_max); 946 949 947 950 // loop all the rows (bytes) … … 1030 1033 } // for rows (bytes) 1031 1034 } // function lochstreifen_draw 1035 1036 1037 /** 1038 * Helper function: A simple closure for a cairo_surface_t (PNG and SVG) to write out data 1039 * to a C file stream. Used internally by lochstreifen_export and is not listened in lochstreifen.h. 1040 **/ 1041 cairo_status_t lochstreifen_export_closure(void *closure, unsigned char *data, unsigned int length) { 1042 unsigned int length_written = fwrite(data, length, 1, (FILE *)closure); 1043 cairo_status_t status = (length != length_written) 1044 ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR; 1045 //printf("Writing data, length %i=>%i, status %s\n", length, length_written, cairo_status_to_string(status)); 1046 if(status == CAIRO_STATUS_WRITE_ERROR) { 1047 perror("Lochstreifen export closure"); 1048 } 1049 return status; 1050 } 1051 1052 /** 1053 * Exporting the Lochstreifen. This is both done in cli.c 1054 * (actually cli.c is a wrapper around this function) and 1055 * gtkpapertapeexporter.cc, so they both rely on this function 1056 **/ 1057 cairo_status_t lochstreifen_export(LOCHSTREIFEN *l, lochstreifen_export_type file_type, FILE *out_stream) { 1058 cairo_t *cr; ///< A cairo context, given from... 1059 cairo_surface_t *surface; ///< ...this generic cairo surface 1060 1061 fprintf(stderr, "Lochstreifen: Exporting %s with %i x %i px\n", 1062 file_type == LOCHSTREIFEN_FORMAT_PNG ? "PNG" : "SVG", 1063 lochstreifen_get_target_width(l), 1064 lochstreifen_get_target_height(l) 1065 ); 1066 1067 // setting up the surface and painting... 1068 if(file_type == LOCHSTREIFEN_FORMAT_PNG) { 1069 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1070 lochstreifen_get_target_width(l), 1071 lochstreifen_get_target_height(l) 1072 ); 1073 cr = cairo_create(surface); 1074 lochstreifen_draw(l, cr); 1075 cairo_surface_flush(surface); 1076 1077 cairo_status_t status = cairo_surface_write_to_png_stream(surface, (cairo_write_func_t)lochstreifen_export_closure, out_stream); 1078 1079 cairo_destroy(cr); 1080 cairo_surface_destroy(surface); 1081 return status; 1082 } else { // if(file_type == LOCHSTREIFEN_FORMAT_SVG) { // no other case possible 1083 surface = cairo_svg_surface_create_for_stream( 1084 (cairo_write_func_t)lochstreifen_export_closure, out_stream, 1085 lochstreifen_get_target_width(l), 1086 lochstreifen_get_target_height(l) 1087 ); 1088 cr = cairo_create(surface); 1089 lochstreifen_draw(l, cr); 1090 cairo_surface_flush(surface); 1091 1092 cairo_status_t status = cairo_surface_status(surface); 1093 1094 cairo_destroy(cr); 1095 cairo_surface_destroy(surface); 1096 1097 return status; 1098 } // end case file_type 1099 }
Note: See TracChangeset
for help on using the changeset viewer.