Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 144155 Details for
Bug 220412
Possible compiler bug in gcc
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
Correct behaviour program
bcrops.c (text/x-csrc), 9.96 KB, created by
Mukund Sivaraman
on 2006-12-21 02:32:51 UTC
(
hide
)
Description:
Correct behaviour program
Filename:
MIME Type:
Creator:
Mukund Sivaraman
Created:
2006-12-21 02:32:51 UTC
Size:
9.96 KB
patch
obsolete
> >#include <stdio.h> >#include <stdlib.h> >#include <math.h> >#include <gtk/gtk.h> > >#define ROUND(x) round(x) > >typedef struct >{ > gdouble x, y; >} Point; > >typedef struct >{ > gint xmin, xmax; > gint ymin, ymax; > gdouble m, b; /* y = mx + b */ > gboolean top, right; >} Edge; > >gdouble ax1, ay1, ax2, ay2, ax3, ay3, ax4, ay4; >gint bx1, bx2, by1, by2; >gdouble aspect_ratio; >int lines = 4; > >static void >edge_init (Edge *edge, > const Point *p, > const Point *q) >{ > edge->xmin = MIN (ceil (p->x), ceil (q->x)); > edge->xmax = MAX (floor (p->x), floor (q->x)); > > edge->ymin = MIN (ceil (p->y), ceil (q->y)); > edge->ymax = MAX (floor (p->y), floor (q->y)); > > edge->top = p->x > q->x; > edge->right = p->y > q->y; > > edge->m = (q->y - p->y) / (q->x - p->x); > edge->b = p->y - edge->m * p->x; >} > >static const Edge * >find_edge (const Edge *edges, > gint x, > gboolean top) >{ > const Edge *emax = edges; > const Edge *e = edges; > gint i; > > for (i = 0; i < 4; i++) > { > if ((e->xmin == x) && (e->xmax != e->xmin) && > ((e->top && top) || (!e->top && !top))) > emax = e; > e++; > } > > return emax; >} > >/* find largest pixel completely inside; > * look through all edges for intersection > */ >static gint >intersect_x (const Edge *edges, > gint y) >{ > gdouble x0 = 0; > gdouble x1 = 0; > gint i; > > for (i = 0; i < 4; i++) > if (edges[i].right && edges[i].ymin <= y && edges[i].ymax >= y) > { > x0 = (y + 0.5 - edges[i].b) / edges[i].m; > x1 = (y - 0.5 - edges[i].b) / edges[i].m; > } > > return (gint) floor (MIN (x0, x1)); >} > >static gint >intersect_y (const Edge *edge, > gint xi) >{ > gdouble yfirst = edge->m * (xi - 0.5) + edge->b; > gdouble ylast = edge->m * (xi + 0.5) + edge->b; > > return (gint) (edge->top ? ceil (MAX (yfirst, ylast)) : floor (MIN (yfirst, ylast))); >} > >static void >gimp_transform_resize_crop (gdouble dx1, > gdouble dy1, > gdouble dx2, > gdouble dy2, > gdouble dx3, > gdouble dy3, > gdouble dx4, > gdouble dy4, > gdouble aspect, > gint *x1, > gint *y1, > gint *x2, > gint *y2) >{ > Point points[4]; > Edge edges[4]; > const Point *a; > const Point *b; > const Edge *top; > const Edge *bottom; > gint cxmin, cymin; > gint cxmax, cymax; > Point *xint; > > gint ymin, ymax; > gint maxarea = 0; > gint xi; > gint i; > > /* fill in the points array */ > points[0].x = ROUND(dx1); > points[0].y = ROUND(dy1); > points[1].x = ROUND(dx2); > points[1].y = ROUND(dy2); > points[2].x = ROUND(dx3); > points[2].y = ROUND(dy3); > points[3].x = ROUND(dx4); > points[3].y = ROUND(dy4); > > /* create an array of edges */ > > cxmin = cxmax = points[3].x; > cymin = cymax = points[3].y; > > for (i = 0, a = points + 3, b = points; i < 4; i++, a = b, b++) > { > if (G_UNLIKELY(i == 0)) > { > cxmin = cxmax = a->x; > cymin = cymax = a->y; > } > else > { > if (a->x < cxmin) > cxmin = a->x; > > if (a->x > cxmax) > cxmax = a->x; > > if (a->y < cymin) > cymin = a->y; > > if (a->y > cymax) > cymax = a->y; > } > > edge_init (edges + i, a, b); > } > > g_printerr ("%d, %d -> %d, %d\n", cxmin, cymin, cxmax, cymax); > > xint = g_new (Point, cymax); > > for (i = 0; i < cymax; i++) > { > xint[i].x = intersect_x (edges, i); > xint[i].y = i; > } > > top = find_edge (edges, cxmin, TRUE); > bottom = find_edge (edges, cxmin, FALSE); > > g_printerr ("top: %d, %d -> %d, %d\n", > top->xmin, top->ymin, top->xmax, top->ymax); > g_printerr ("bottom: %d, %d -> %d, %d\n", > bottom->xmin, bottom->ymin, bottom->xmax, bottom->ymax); > > for (xi = cxmin; xi < cxmax; xi++) > { > gint ylo, yhi; > > ymin = intersect_y (top, xi); > ymax = intersect_y (bottom, xi); > > for (ylo = ymax; ylo >= ymin; ylo--) > { > for (yhi = ymin; yhi <= ymax; yhi++) > { > if (yhi > ylo) > { > gint xlo, xhi; > gint xright; > gint height, width, fixed_width; > gint area; > > xlo = xint[ylo].x; > xhi = xint[yhi].x; > > xright = MIN (xlo, xhi); > > height = yhi - ylo; > width = xright - xi; > > if (aspect != 0) > { > fixed_width = (int) ceil((gdouble) height * aspect); > > if (fixed_width <= width) > width = fixed_width; > else > width = 0; > } > > area = width * height; > > if (area > maxarea) > { > maxarea = area; > > *x1 = xi; > *y1 = ylo; > *x2 = xi + width; > *y2 = ylo + height; > } > } > } > } > > if (xi == top->xmax) > top = find_edge (edges, xi, TRUE); > > if (xi == bottom->xmax) > bottom = find_edge (edges, xi, FALSE); > } > > g_free (xint); >} > >static void >destroy_callback (GtkWidget *widget, gpointer data) >{ > gtk_main_quit (); >} > > >static void >expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) >{ > GtkWidget *draw; > cairo_t *cairo_context; > gint width, height; > > draw = data; > cairo_context = gdk_cairo_create (GDK_DRAWABLE (draw->window)); > > width = draw->allocation.width; > height = draw->allocation.height; > > cairo_scale (cairo_context, 300, 300); > cairo_translate (cairo_context, 0.5, 0.5); > cairo_set_line_width (cairo_context, 0.003); > > /* Fill canvas with white */ > > cairo_save (cairo_context); > cairo_set_source_rgba (cairo_context, 1.0, 1.0, 1.0, 1.0); > cairo_paint (cairo_context); > cairo_restore (cairo_context); > > /* Draw the quardilateral first */ > > cairo_move_to (cairo_context, ax1 / 600, ay1 / 600); > if (lines > 0) > { > cairo_line_to (cairo_context, ax2 / 600, ay2 / 600); > if (lines > 1) > { > cairo_line_to (cairo_context, ax3 / 600, ay3 / 600); > if (lines > 2) > { > cairo_line_to (cairo_context, ax4 / 600, ay4 / 600); > if (lines > 3) > cairo_line_to (cairo_context, ax1 / 600, ay1 / 600); > } > } > } > cairo_stroke (cairo_context); > > cairo_save (cairo_context); > cairo_set_line_width (cairo_context, 0.002); > cairo_set_source_rgba (cairo_context, 0.337, 0.612, 0.117, 1.0); > cairo_move_to (cairo_context, bx1 / 600.0, by1 / 600.0); > cairo_line_to (cairo_context, bx2 / 600.0, by1 / 600.0); > cairo_line_to (cairo_context, bx2 / 600.0, by2 / 600.0); > cairo_line_to (cairo_context, bx1 / 600.0, by2 / 600.0); > cairo_line_to (cairo_context, bx1 / 600.0, by1 / 600.0); > > cairo_stroke (cairo_context); > cairo_restore (cairo_context); > > cairo_destroy (cairo_context); >} > > >int >main (int argc, char *argv[]) >{ > GtkWidget *window; > GtkWidget *draw; > > gtk_init (&argc, &argv); > > if (argc < 10) > { > printf ("\n"); > printf ("Usage: %s <x1> <y1> <x2> <y2> <x3> <y3> <x4> <y4> <aspect>\n", argv[0]); > printf (" where:\n"); > printf (" 1. all arguments are of double type\n"); > printf (" 2. (x, y) lie between 0 and 600 and are convex in order\n"); > printf (" 3. aspect lies between 0 and 1\n"); > printf ("\n"); > printf (" NO input validation is done!\n"); > printf ("\n"); > > ax1 = 100; ay1 = 100; > ax2 = 150; ay2 = 500; > ax3 = 550; ay3 = 400; > ax4 = 500; ay4 = 200; > aspect_ratio = 0; > > printf ("Using (%f, %f), (%f, %f), (%f, %f), (%f, %f) as the points and aspect = %f\n\n", > ax1, ay1, ax2, ay2, ax3, ay3, ax4, ay4, aspect_ratio); > } > else > { > ax1 = atof (argv[1]); > ay1 = atof (argv[2]); > ax2 = atof (argv[3]); > ay2 = atof (argv[4]); > ax3 = atof (argv[5]); > ay3 = atof (argv[6]); > ax4 = atof (argv[7]); > ay4 = atof (argv[8]); >/* > ax1 = atof (argv[1]); > ay1 = atof (argv[2]); > > ax2 = atof (argv[5]); > ay2 = atof (argv[6]); > > ax3 = atof (argv[7]); > ay3 = atof (argv[8]); > > ax4 = atof (argv[3]); > ay4 = atof (argv[4]); >*/ > > aspect_ratio = atof (argv[9]); > > if (argc == 11) > lines = atoi (argv[10]); > } > > gimp_transform_resize_crop (ax1, ay1, ax2, ay2, > ax3, ay3, ax4, ay4, > 0, > &bx1, &by1, &bx2, &by2); > > g_print ("Result is (%d, %d) - (%d, %d)\n", bx1, by1, bx2, by2); > > window = gtk_window_new (GTK_WINDOW_TOPLEVEL); > gtk_window_set_title (GTK_WINDOW (window), > "Quadrilateral clipping against canvas"); > g_signal_connect (G_OBJECT (window), "destroy", > G_CALLBACK (destroy_callback), NULL); > > draw = gtk_drawing_area_new (); > gtk_widget_set_size_request (draw, 600, 600); > > g_signal_connect (G_OBJECT (draw), "expose_event", > G_CALLBACK (expose_event_callback), draw); > > gtk_container_add (GTK_CONTAINER (window), draw); > > gtk_widget_show_all (window); > gtk_window_set_resizable (GTK_WINDOW (window), FALSE); > > gtk_main (); > > return 0; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 220412
: 144155 |
144156