void view_actions_update (GimpActionGroup *group, gpointer data) { GimpDisplay *display = action_data_get_display (data); GimpImage *image = NULL; GimpDisplayShell *shell = NULL; GimpDisplayOptions *options = NULL; gchar *label = NULL; gboolean fullscreen = FALSE; gboolean revert_enabled = FALSE; /* able to revert zoom? */ if (display) { GimpImageWindow *window; image = gimp_display_get_image (display); shell = gimp_display_get_shell (display); window = gimp_display_shell_get_window (shell); if (window) fullscreen = gimp_image_window_get_fullscreen (window); options = (image ? (fullscreen ? shell->fullscreen_options : shell->options) : shell->no_image_options); revert_enabled = gimp_display_shell_scale_can_revert (shell); } #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_COLOR(action,color) \ gimp_action_group_set_action_color (group, action, color, FALSE) SET_SENSITIVE ("view-new", image); SET_SENSITIVE ("view-close", image); SET_SENSITIVE ("view-dot-for-dot", image); SET_ACTIVE ("view-dot-for-dot", display && shell->dot_for_dot); SET_SENSITIVE ("view-zoom-revert", revert_enabled); if (revert_enabled) { label = g_strdup_printf (_("Re_vert Zoom (%d%%)"), ROUND (shell->last_scale * 100)); gimp_action_group_set_action_label (group, "view-zoom-revert", label); g_free (label); } else { gimp_action_group_set_action_label (group, "view-zoom-revert", _("Re_vert Zoom")); } SET_SENSITIVE ("view-zoom-out", image); SET_SENSITIVE ("view-zoom-in", image); SET_SENSITIVE ("view-zoom-fit-in", image); SET_SENSITIVE ("view-zoom-fill", image); SET_SENSITIVE ("view-zoom-16-1", image); SET_SENSITIVE ("view-zoom-8-1", image); SET_SENSITIVE ("view-zoom-4-1", image); SET_SENSITIVE ("view-zoom-2-1", image); SET_SENSITIVE ("view-zoom-1-1", image); SET_SENSITIVE ("view-zoom-1-2", image); SET_SENSITIVE ("view-zoom-1-4", image); SET_SENSITIVE ("view-zoom-1-8", image); SET_SENSITIVE ("view-zoom-1-16", image); SET_SENSITIVE ("view-zoom-other", image); SET_SENSITIVE ("view-rotate-reset", image); SET_SENSITIVE ("view-rotate-90", image); SET_SENSITIVE ("view-rotate-180", image); SET_SENSITIVE ("view-rotate-270", image); SET_SENSITIVE ("view-rotate-other", image); if (image) { view_actions_set_zoom (group, shell); view_actions_set_rotate (group, shell); } SET_SENSITIVE ("view-navigation-window", image); SET_SENSITIVE ("view-display-filters", image); SET_SENSITIVE ("view-show-selection", image); SET_ACTIVE ("view-show-selection", display && options->show_selection); SET_SENSITIVE ("view-show-layer-boundary", image); SET_ACTIVE ("view-show-layer-boundary", display && options->show_layer_boundary); SET_SENSITIVE ("view-show-guides", image); SET_ACTIVE ("view-show-guides", display && options->show_guides); SET_SENSITIVE ("view-show-grid", image); SET_ACTIVE ("view-show-grid", display && options->show_grid); SET_SENSITIVE ("view-show-sample-points", image); SET_ACTIVE ("view-show-sample-points", display && options->show_sample_points); SET_SENSITIVE ("view-snap-to-guides", image); SET_ACTIVE ("view-snap-to-guides", display && options->snap_to_guides); SET_SENSITIVE ("view-snap-to-grid", image); SET_ACTIVE ("view-snap-to-grid", display && options->snap_to_grid); SET_SENSITIVE ("view-snap-to-canvas", image); SET_ACTIVE ("view-snap-to-canvas", display && options->snap_to_canvas); SET_SENSITIVE ("view-snap-to-vectors", image); SET_ACTIVE ("view-snap-to-vectors", display && options->snap_to_path); SET_SENSITIVE ("view-padding-color-theme", image); SET_SENSITIVE ("view-padding-color-light-check", image); SET_SENSITIVE ("view-padding-color-dark-check", image); SET_SENSITIVE ("view-padding-color-custom", image); SET_SENSITIVE ("view-padding-color-prefs", image); if (display) { SET_COLOR ("view-padding-color-menu", &options->padding_color); if (shell->canvas) { GtkStyle *style = gtk_widget_get_style (shell->canvas); GimpRGB color; gtk_widget_ensure_style (shell->canvas); gimp_rgb_set_gdk_color (&color, style->bg + GTK_STATE_NORMAL); gimp_rgb_set_alpha (&color, GIMP_OPACITY_OPAQUE); SET_COLOR ("view-padding-color-theme", &color); } } SET_SENSITIVE ("view-show-menubar", image); SET_ACTIVE ("view-show-menubar", display && options->show_menubar); SET_SENSITIVE ("view-show-rulers", image); SET_ACTIVE ("view-show-rulers", display && options->show_rulers); SET_SENSITIVE ("view-show-scrollbars", image); SET_ACTIVE ("view-show-scrollbars", display && options->show_scrollbars); SET_SENSITIVE ("view-show-statusbar", image); SET_ACTIVE ("view-show-statusbar", display && options->show_statusbar); SET_SENSITIVE ("view-shrink-wrap", image); SET_ACTIVE ("view-fullscreen", display && fullscreen); if (GIMP_IS_IMAGE_WINDOW (group->user_data) || GIMP_IS_GIMP (group->user_data)) { GtkWidget *window = NULL; if (shell) window = gtk_widget_get_toplevel (GTK_WIDGET (shell)); /* see view_actions_setup() */ if (GTK_IS_WINDOW (window)) window_actions_update (group, window); } #undef SET_ACTIVE #undef SET_SENSITIVE #undef SET_COLOR }
void QmitkNumberPropertyEditor::setDoubleValue(double value) { QSpinBox::setValue( ROUND( value * m_FactorPropertyToSpinbox ) ); //QSpinBox::updateDisplay(); }
static void plchar(signed char *vxygrid, PLFLT *xform, PLINT base, PLINT oline, PLINT uline, PLINT refx, PLINT refy, PLFLT scale, PLFLT xpmm, PLFLT ypmm, PLFLT *p_xorg, PLFLT *p_yorg, PLFLT *p_width) { PLINT xbase, ybase, ydisp, lx, ly, cx, cy; PLINT k, penup; PLFLT x, y; PLINT llx[STLEN], lly[STLEN], l = 0; xbase = vxygrid[2]; *p_width = vxygrid[3] - xbase; if (base == 0) { ybase = 0; ydisp = vxygrid[0]; } else { ybase = vxygrid[0]; ydisp = 0; } k = 4; penup = 1; for (;;) { cx = vxygrid[k++]; cy = vxygrid[k++]; if (cx == 64 && cy == 64) { if (l) { plP_draphy_poly(llx, lly, l); l = 0; } break; } if (cx == 64 && cy == 0) { if (l) { plP_draphy_poly(llx, lly, l); l = 0; } penup = 1; } else { x = *p_xorg + (cx - xbase) * scale; y = *p_yorg + (cy - ybase) * scale; lx = refx + ROUND(xpmm * (xform[0] * x + xform[1] * y)); ly = refy + ROUND(ypmm * (xform[2] * x + xform[3] * y)); if (penup == 1) { if (l) { plP_draphy_poly(llx, lly, l); l = 0; } llx[l] = lx; lly[l++] = ly; /* store 1st point ! */ plP_movphy(lx, ly); penup = 0; } else { llx[l] = lx; lly[l++] = ly; } } } if (oline) { x = *p_xorg; y = *p_yorg + (30 + ydisp) * scale; lx = refx + ROUND(xpmm * (xform[0] * x + xform[1] * y)); ly = refy + ROUND(ypmm * (xform[2] * x + xform[3] * y)); plP_movphy(lx, ly); x = *p_xorg + *p_width * scale; lx = refx + ROUND(xpmm * (xform[0] * x + xform[1] * y)); ly = refy + ROUND(ypmm * (xform[2] * x + xform[3] * y)); plP_draphy(lx, ly); } if (uline) { x = *p_xorg; y = *p_yorg + (-5 + ydisp) * scale; lx = refx + ROUND(xpmm * (xform[0] * x + xform[1] * y)); ly = refy + ROUND(ypmm * (xform[2] * x + xform[3] * y)); plP_movphy(lx, ly); x = *p_xorg + *p_width * scale; lx = refx + ROUND(xpmm * (xform[0] * x + xform[1] * y)); ly = refy + ROUND(ypmm * (xform[2] * x + xform[3] * y)); plP_draphy(lx, ly); } *p_xorg = *p_xorg + *p_width * scale; }
void TFeedbackView::DoFeedback( const TEventArgs& inArgs ) { const GenericSignal& signal = *inArgs.signal; float xNormalized = 0.5, yNormalized = 0.5, bNormalized = 1.0; int actualChannels = signal.Channels(); if( xChannel >= 0 && xChannel < actualChannels ) xNormalized = ( signal( xChannel, 0 ) + 100.0 ) / 200.0; if( yChannel >= 0 && yChannel < actualChannels ) yNormalized = ( signal( yChannel, 0 ) + 100.0 ) / 200.0; if( bChannel >= 0 && bChannel < actualChannels ) bNormalized = ( - signal( bChannel, 0 ) + 100.0 ) / 200.0; xNormalized = MAX( 0.0, MIN( xNormalized, 1.0 ) ); yNormalized = MAX( 0.0, MIN( yNormalized, 1.0 ) ); bNormalized = MAX( 0.0, MIN( bNormalized, 1.0 ) ); switch( visFBMode ) { case 0: // none break; case 1: // cursor from file case 2: // ball #ifdef PERUVIAN_BRIGHTNESS_HACK case 3: // brightness #endif // PERUVIAN_BRIGHTNESS_HACK { float xPos = xNormalized, yPos = yNormalized, brightness = bNormalized; unsigned short curArtifactState = artifact.GetStateValue(); if( SUPPRESS_CURSOR_BIT( inArgs.targetCode ) ) { TGUIFeedbackView::HideCursor(); if( curArtifactState == 1 ) TGUIFeedbackView::InvertCursor(); TGUIFeedbackView::SetCursorCoordinates( xPos, yPos, brightness ); } else { if( curArtifactState == 1 ) TGUIFeedbackView::InvertCursor(); TGUIFeedbackView::SetCursorCoordinates( xPos, yPos, brightness ); TGUIFeedbackView::ShowCursor(); } } break; default: assert( false ); } switch( audFBMode ) { case 0: // none break; case 1: // MIDI if( !SUPPRESS_CURSOR_BIT( inArgs.targetCode ) ) { // curNote is the note in the current scale's units. int curNote = ROUND( ( 0.5 - yNormalized ) // We add 1 to get full octaves. * ( gmFBInterval * ( float )scaleLength + 1 ) ), curMidiNote = lastMidiNote; if( curNote > lastNote || curMidiNote < 1 /* For the very first note, use the upScale */ ) { curMidiNote = upScale[ MOD( curNote, scaleLength ) ] + 12 * DIV( curNote, scaleLength ) + gmFBCenterNote; if( curMidiNote > 127 ) curMidiNote = 127; } else if( curNote < lastNote ) { curMidiNote = downScale[ MOD( curNote, scaleLength ) ] + 12 * DIV( curNote, scaleLength ) + gmFBCenterNote; if( curMidiNote < 1 ) curMidiNote = 1; } midiPlayer->Play( curMidiNote ); lastMidiNote = curMidiNote; lastNote = curNote; } break; #ifdef USE_WAVE_SYNTH case 2: // continuous synth if( !SUPPRESS_CURSOR_BIT( inArgs.targetCode ) ) { float centerFreq = 440.0 * pow( 2.0, ( gmFBCenterNote - 69 ) / 12.0 ), freq = centerFreq * pow( 2.0, ( 0.5 - yNormalized ) * gmFBInterval ); waveSynth->SetPitch( freq ); waveSynth->Play(); } else waveSynth->Stop(); break; #endif // USE_WAVE_SYNTH default: assert( false ); } }
int QmitkNumberPropertyEditor::maxValue() const { return ROUND( QSpinBox::maximum() / m_FactorPropertyToSpinbox ); }
static void blowfish_decrypt(word32 xL, word32 xR, word32 * output, BlowfishContext * ctx) { word32 *S0 = ctx->S0; word32 *S1 = ctx->S1; word32 *S2 = ctx->S2; word32 *S3 = ctx->S3; word32 *P = ctx->P; word32 t; ROUND(17); ROUND(16); ROUND(15); ROUND(14); ROUND(13); ROUND(12); ROUND(11); ROUND(10); ROUND(9); ROUND(8); ROUND(7); ROUND(6); ROUND(5); ROUND(4); ROUND(3); ROUND(2); xL ^= P[1]; xR ^= P[0]; output[0] = xR; output[1] = xL; }
/* *--------------------------------------------------------------------------- * * Blt_RotateScaleBitmapArea -- * * Creates a scaled and rotated bitmap from a given bitmap. The * caller also provides (offsets and dimensions) the region of * interest in the destination bitmap. This saves having to * process the entire destination bitmap is only part of it is * showing in the viewport. * * This uses a simple rotation/scaling of each pixel in the * destination image. For each pixel, the corresponding * pixel in the source bitmap is used. This means that * destination coordinates are first scaled to the size of * the rotated source bitmap. These coordinates are then * rotated back to their original orientation in the source. * * Results: * The new rotated and scaled bitmap is returned. * * Side Effects: * A new pixmap is allocated. The caller must release this. * *--------------------------------------------------------------------------- */ Pixmap Blt_ScaleRotateBitmapArea( Tk_Window tkwin, Pixmap srcBitmap, /* Source bitmap. */ unsigned int srcWidth, unsigned int srcHeight, /* Size of source bitmap */ int regionX, int regionY, /* Offset of region in virtual * destination bitmap. */ unsigned int regionWidth, unsigned int regionHeight, /* Desire size of bitmap region. */ unsigned int destWidth, unsigned int destHeight, /* Virtual size of destination bitmap. */ float angle) /* Angle to rotate bitmap. */ { Display *display; /* X display */ Window root; /* Root window drawable */ Pixmap destBitmap; XImage *srcImgPtr, *destImgPtr; double xScale, yScale; double rotWidth, rotHeight; GC bitmapGC; display = Tk_Display(tkwin); root = Tk_RootWindow(tkwin); #ifdef notdef /* Create a bitmap and image big enough to contain the rotated text */ bitmapGC = Blt_GetBitmapGC(tkwin); destBitmap = Tk_GetPixmap(display, root, regionWidth, regionHeight, 1); XSetForeground(display, bitmapGC, 0x0); XFillRectangle(display, destBitmap, bitmapGC, 0, 0, regionWidth, regionHeight); srcImgPtr = XGetImage(display, srcBitmap, 0, 0, srcWidth, srcHeight, 1, ZPixmap); destImgPtr = XGetImage(display, destBitmap, 0, 0, regionWidth, regionHeight, 1, ZPixmap); angle = FMOD(angle, 360.0); Blt_GetBoundingBox(srcWidth, srcHeight, angle, &rotWidth, &rotHeight, (Point2d *)NULL); xScale = rotWidth / (double)destWidth; yScale = rotHeight / (double)destHeight; if (FMOD(angle, (double)90.0) == 0.0) { int quadrant; int x, y; /* Handle right-angle rotations specifically */ quadrant = (int)(angle / 90.0); switch (quadrant) { case ROTATE_270: /* 270 degrees */ for (y = 0; y < regionHeight; y++) { int sx; sx = (int)(yScale * (double)(y + regionY)); for (x = 0; x < regionWidth; x++) { int sy; unsigned long pixel; sy = (int)(xScale *(double)(destWidth - (x + regionX) - 1)); pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; case ROTATE_180: /* 180 degrees */ for (y = 0; y < regionHeight; y++) { int sy; sy = (int)(yScale * (double)(destHeight - (y + regionY) - 1)); for (x = 0; x < regionWidth; x++) { int sx; unsigned long pixel; sx = (int)(xScale *(double)(destWidth - (x + regionX) - 1)); pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; case ROTATE_90: /* 90 degrees */ for (y = 0; y < regionHeight; y++) { int sx; sx = (int)(yScale * (double)(destHeight - (y + regionY) - 1)); for (x = 0; x < regionWidth; x++) { int sy; unsigned long pixel; sy = (int)(xScale * (double)(x + regionX)); pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; case ROTATE_0: /* 0 degrees */ for (y = 0; y < regionHeight; y++) { int sy; sy = (int)(yScale * (double)(y + regionY)); for (x = 0; x < regionWidth; x++) { int sx; unsigned long pixel; sx = (int)(xScale * (double)(x + regionX)); pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; default: /* The calling routine should never let this happen. */ break; } } else { double radians, sinTheta, cosTheta; double sox, soy; /* Offset from the center of the * source rectangle. */ double rox, roy; /* Offset to the center of the * rotated rectangle. */ int x, y; radians = (angle / 180.0) * M_PI; sinTheta = sin(radians), cosTheta = cos(radians); /* * Coordinates of the centers of the source and destination rectangles */ sox = srcWidth * 0.5; soy = srcHeight * 0.5; rox = rotWidth * 0.5; roy = rotHeight * 0.5; /* For each pixel of the destination image, transform back to the * associated pixel in the source image. */ for (y = 0; y < regionHeight; y++) { double ty; ty = (yScale * (double)(y + regionY)) - roy; for (x = 0; x < regionWidth; x++) { double tx, rx, ry; int sx, sy; unsigned long pixel; /* Translate origin to center of destination image. */ tx = (xScale * (double)(x + regionX)) - rox; /* Rotate the coordinates about the origin. */ rx = (tx * cosTheta) - (ty * sinTheta); ry = (tx * sinTheta) + (ty * cosTheta); /* Translate back to the center of the source image. */ rx += sox; ry += soy; sx = ROUND(rx); sy = ROUND(ry); /* * Verify the coordinates, since the destination image can be * bigger than the source. */ if ((sx >= srcWidth) || (sx < 0) || (sy >= srcHeight) || (sy < 0)) { continue; } pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } } /* Write the rotated image into the destination bitmap. */ XPutImage(display, destBitmap, bitmapGC, destImgPtr, 0, 0, 0, 0, regionWidth, regionHeight); /* Clean up the temporary resources used. */ XDestroyImage(srcImgPtr), XDestroyImage(destImgPtr); #endif return destBitmap; }
int main( int argc, const char *argv[] ) { int i; PLFLT dtr, theta, dx, dy, r, offset; char text[4]; static PLFLT x0[361], y0[361]; static PLFLT x[361], y[361]; dtr = M_PI / 180.0; for ( i = 0; i <= 360; i++ ) { x0[i] = cos( dtr * i ); y0[i] = sin( dtr * i ); } /* Parse and process command line arguments */ (void) plparseopts( &argc, argv, PL_PARSE_FULL ); /* Set orientation to portrait - note not all device drivers * support this, in particular most interactive drivers do not */ plsori( 1 ); /* Initialize plplot */ plinit(); /* Set up viewport and window, but do not draw box */ plenv( -1.3, 1.3, -1.3, 1.3, 1, -2 ); /* Draw circles for polar grid */ for ( i = 1; i <= 10; i++ ) { plarc( 0.0, 0.0, 0.1 * i, 0.1 * i, 0.0, 360.0, 0 ); } plcol0( 2 ); for ( i = 0; i <= 11; i++ ) { theta = 30.0 * i; dx = cos( dtr * theta ); dy = sin( dtr * theta ); /* Draw radial spokes for polar grid */ pljoin( 0.0, 0.0, dx, dy ); sprintf( text, "%d", ROUND( theta ) ); /* Write labels for angle */ if ( theta < 9.99 ) { offset = 0.45; } else if ( theta < 99.9 ) { offset = 0.30; } else { offset = 0.15; } /* Slightly off zero to avoid floating point logic flips at 90 and 270 deg. */ if ( dx >= -0.00001 ) plptex( dx, dy, dx, dy, -offset, text ); else plptex( dx, dy, -dx, -dy, 1. + offset, text ); } /* Draw the graph */ for ( i = 0; i <= 360; i++ ) { r = sin( dtr * ( 5 * i ) ); x[i] = x0[i] * r; y[i] = y0[i] * r; } plcol0( 3 ); plline( 361, x, y ); plcol0( 4 ); plmtex( "t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh" ); /* Close the plot at end */ plend(); exit( 0 ); }
/*-------------------------------------------------------------------*/ bool DPMatchingMultiStart ( int *C, double &T_best, // output double *A, double thre, // input int M, int N, // A is MxN matrix int n_start, int n_search) { double *A2 = new double[M*2*N]; bool bSucc = false; memcpy(A2,A,M*N*sizeof(double)); memcpy(A2+M*N,A,M*N*sizeof(double)); int *CC = new int[M*N]; double TT; int id_best; id_best = -1; T_best = 4000*N; n_start = MIN(N,n_start); // try different start points int id_start, iS, iS1, iS2, dS; for(iS=0;iS<n_start;++iS) { id_start = ROUND(N*iS/(double)n_start); bSucc = DPMatchingFixStartPoint(CC+id_start*M, TT, A2+id_start*M, thre, M, N); if(TT<T_best) { T_best = TT; id_best = id_start; } for(dS=1;dS<n_search;++dS) { // forward iS1 = id_start+dS; if(iS1>N) iS1-=N; bSucc = DPMatchingFixStartPoint(CC+iS1*M, TT, A2+iS1*M, thre, M, N); if(TT<T_best) { T_best = TT; id_best = iS1; } // backward iS2 = id_start-dS; if(iS2<0) iS2+=N; bSucc = DPMatchingFixStartPoint(CC+iS2*M, TT, A2+iS2*M, thre, M, N); if(TT<T_best) { T_best = TT; id_best = iS2; } } } // adjust indices if(id_best<0) printf("\n\tId_best=%d !!!!!!!\n",id_best); memcpy(C,CC+id_best*M,M*sizeof(int)); for(int ii=0;ii<M;++ii) { if(C[ii]<N) { // not occluded C[ii] += id_best; if(C[ii]>=N) C[ii] -= N; } } delete []A2; delete []CC; return true; }
/* * This function is called if the user clicks and releases the left * button without moving it. There are the things we might want * to do here: * 1) If there is an existing rectangle and we are inside it, we * convert it into a selection. * 2) If there is an existing rectangle and we are outside it, we * clear it. * 3) If there is no rectangle and there is a floating selection, * we anchor it. * 4) If there is no rectangle and we are inside the selection, we * create a rectangle from the selection bounds. * 5) If there is no rectangle and we are outside the selection, * we clear the selection. */ static gboolean gimp_rectangle_select_tool_execute (GimpRectangleTool *rectangle, gint x, gint y, gint w, gint h) { GimpTool *tool = GIMP_TOOL (rectangle); GimpRectangleSelectTool *rect_sel_tool; GimpRectangleSelectToolPrivate *priv; rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (rectangle); priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool); if (w == 0 && h == 0 && tool->display != NULL) { GimpImage *image = gimp_display_get_image (tool->display); GimpChannel *selection = gimp_image_get_mask (image); gint pressx; gint pressy; if (gimp_image_get_floating_selection (image)) { floating_sel_anchor (gimp_image_get_floating_selection (image)); gimp_image_flush (image); return TRUE; } pressx = ROUND (priv->press_x); pressy = ROUND (priv->press_y); /* if the click was inside the marching ants */ if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (selection), pressx, pressy) > 0.5) { gint x, y, w, h; if (gimp_item_bounds (GIMP_ITEM (selection), &x, &y, &w, &h)) { g_object_set (rectangle, "x1", x, "y1", y, "x2", x + w, "y2", y + h, NULL); } gimp_rectangle_tool_set_function (rectangle, GIMP_RECTANGLE_TOOL_MOVING); gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, FALSE); return FALSE; } else { GimpTool *tool = GIMP_TOOL (rectangle); GimpChannelOps operation; /* prevent this change from halting the tool */ gimp_tool_control_push_preserve (tool->control, TRUE); /* We can conceptually think of a click outside of the * selection as adding a 0px selection. Behave intuitivly * for the current selection mode */ operation = gimp_rectangle_select_tool_get_operation (rect_sel_tool); switch (operation) { case GIMP_CHANNEL_OP_REPLACE: case GIMP_CHANNEL_OP_INTERSECT: gimp_channel_clear (selection, NULL, TRUE); gimp_image_flush (image); break; case GIMP_CHANNEL_OP_ADD: case GIMP_CHANNEL_OP_SUBTRACT: default: /* Do nothing */ break; } gimp_tool_control_pop_preserve (tool->control); } } gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, FALSE); /* Reset the automatic undo/redo mechanism */ priv->undo = NULL; priv->redo = NULL; return TRUE; }
// // gateway driver to call the distance transform code from matlab // // This is the matlab entry point void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i, j, k, c, nrow, ncol, maxdim, nmpt; int mxfn, myfn, mrfn, mvxfn, mvyfn, mpfn, mchfn; int root, curt, ch, prnt, dtarrbase, dtarrlim; int ldim[3], *v, *mp, *mnch, *mdone, *mndesc, *dtarrhist; int *loc, *loc2, *lscratch, **locarr, **locarr2; char *pbimgc; double x_multiply, y_multiply, yx_ratio, maxd, *z; double *cost, *out, *scratch, *scratch2, *scl; double *mx, *my, *mr, *mvx, *mvy, *pbimg, *dt1, *tranarr; double **mch, **locp, **dtarr, **dtarrp; mxArray *cell, *field; // check for proper number and size of arguments errCheck(nrhs >= 2,"Arguments: model, bimg, [maxd]"); errCheck(nrhs <= 3,"Arguments: model, bimg, [maxd]"); errCheck(nlhs <= 3,"Outputs: dt, [loc], [scale]"); errCheck(mxIsStruct(prhs[0]),"model must be struct."); mxfn = mxGetFieldNumber(prhs[0],"x"); errCheck(mxfn>=0,"Model must have field named x."); myfn = mxGetFieldNumber(prhs[0],"y"); errCheck(myfn>=0,"Model must have field named y."); mrfn = mxGetFieldNumber(prhs[0],"r"); errCheck(mrfn>=0,"Model must have field named r."); mvxfn = mxGetFieldNumber(prhs[0],"vx"); errCheck(mvxfn>=0,"Model must have field named vx."); mvyfn = mxGetFieldNumber(prhs[0],"vy"); errCheck(mvyfn>=0,"Model must have field named vy."); mpfn = mxGetFieldNumber(prhs[0],"parent"); errCheck(mpfn>=0,"Model must have field named parent."); mchfn = mxGetFieldNumber(prhs[0],"children"); errCheck(mchfn>=0,"Model must have field named children."); errCheck(mxIsDouble(prhs[1])||mxIsLogical(prhs[1])||mxIsUint8(prhs[1]), "Second argument must be binary image type."); errCheck(mxGetNumberOfDimensions(prhs[1])==2, "Second argument must be binary image type."); if (nrhs>2) { errCheck(mxIsDouble(prhs[2])&&!mxIsComplex(prhs[2]), "maxd must be real double."); errCheck(mxGetNumberOfElements(prhs[2])==1, "maxd must be scalar."); maxd = *mxGetPr(prhs[2]); } else { maxd = LARGE; } nmpt = (int)mxGetNumberOfElements(prhs[0]); nrow = (int)mxGetM(prhs[1]); ncol = (int)mxGetN(prhs[1]); // transcribe model variables root = -1; mx = (double*)mxMalloc(nmpt*sizeof(double)); my = (double*)mxMalloc(nmpt*sizeof(double)); mr = (double*)mxMalloc(nmpt*sizeof(double)); mvx = (double*)mxMalloc(nmpt*sizeof(double)); mvy = (double*)mxMalloc(nmpt*sizeof(double)); mp = (int*)mxMalloc(nmpt*sizeof(int)); mch = (double**)mxMalloc(nmpt*sizeof(double*)); mnch = (int*)mxMalloc(nmpt*sizeof(int)); for (int i = 0; i < nmpt; i++) { mx[i] = *mxGetPr(mxGetFieldByNumber(prhs[0],i,mxfn)); errCheck(ABS(ROUND(mx[i])) < ncol,"Model displacement larger than image."); my[i] = *mxGetPr(mxGetFieldByNumber(prhs[0],i,myfn)); errCheck(ABS(ROUND(my[i])) < nrow,"Model displacement larger than image."); mr[i] = *mxGetPr(mxGetFieldByNumber(prhs[0],i,mrfn)); mvx[i] = *mxGetPr(mxGetFieldByNumber(prhs[0],i,mvxfn)); mvy[i] = *mxGetPr(mxGetFieldByNumber(prhs[0],i,mvyfn)); mp[i] = (int)(*mxGetPr(mxGetFieldByNumber(prhs[0],i,mpfn))); field = mxGetFieldByNumber(prhs[0],i,mchfn); mch[i] = mxGetPr(field); mnch[i] = (int)(mxGetNumberOfElements(field)); if (mp[i]==0) { errCheck(root<0,"Model must have a single root."); root = i; } } errCheck(root>=0,"Model must have a root."); // allocate output space plhs[0] = mxCreateDoubleMatrix(nrow, ncol, mxREAL); out = mxGetPr(plhs[0]); if (nlhs>=2) { locp = (double**)mxMalloc(nrow*ncol*sizeof(double*)); plhs[1] = mxCreateCellMatrix(nrow,ncol); for (i = 0; i < nrow*ncol; i++) { cell = mxCreateDoubleMatrix(2,nmpt,mxREAL); mxSetCell(plhs[1],i,cell); locp[i] = mxGetPr(cell); } loc = (int*)mxMalloc(2*nrow*ncol*sizeof(int)); loc2 = loc+nrow*ncol; if (nlhs>=3) { plhs[2] = mxCreateDoubleMatrix(nrow,ncol,mxREAL); scl = mxGetPr(plhs[2]); } } else { loc = 0; loc2 = 0; locp = 0; } // transcribe image pbimg = mxGetPr(prhs[1]); pbimgc = (char*)pbimg; dt1 = out; // this is where the answer will end up, eventually if (mxIsDouble(prhs[1])) { for (int i = 0; i <nrow*ncol; i++) { if (pbimg[i]) { dt1[i] = 0; } else { dt1[i] = maxd; } } } else { for (int i = 0; i <nrow*ncol; i++) { if (pbimgc[i]) { dt1[i] = 0; } else { dt1[i] = maxd; } } } // allocate scratch space for distance transform maxdim = MAX(nrow,ncol); scratch = (double*)mxMalloc(maxdim*sizeof(double)); scratch2 = (double*)mxMalloc(nrow*ncol*sizeof(double)); if (loc) { lscratch = (int*)mxMalloc(nrow*ncol*sizeof(int)); } else { lscratch = 0; } v = (int*)mxMalloc(maxdim*sizeof(int)); z = (double*)mxMalloc((maxdim+1)*sizeof(double)); // allocate other variables mdone = (int*)mxMalloc(nmpt*sizeof(int)); mndesc = (int*)mxMalloc(nmpt*sizeof(int)); tranarr = (double*)mxMalloc(nrow*ncol*sizeof(double)); // stores translation dtarr = (double**)mxMalloc(nmpt*sizeof(double*)); // stores intermediate dt dtarrp = (double**)mxMalloc(nmpt*sizeof(double*)); // pointer to storage dtarrhist = (int*)mxMalloc(nmpt*sizeof(int)); // stores historical size locarr = (int**)mxMalloc(2*nmpt*sizeof(int*)); // stores intermediate loc locarr2 = locarr+nmpt; for (i = 0; i < nmpt; i++) { mdone[i] = 0; mndesc[i] = 1; dtarrp[i] = 0; } if (loc) { for (i = 0; i < nmpt; i++) { locarr[i] = (int*)mxMalloc(2*nrow*ncol*sizeof(int)); locarr2[i] = locarr[i]+nrow*ncol; } } else { for (i = 0; i < nmpt; i++) { locarr[i] = 0; locarr2[i] = 0; } } // compute distance transform on input image gdt2d(dt1,dt1,0,v,z,nrow,ncol,1,1,scratch,scratch2,lscratch); // run computation curt = root; dtarrlim = 0; dtarrbase = 0; dtarrp[root] = dt1; k = 0; while (curt != -1) { // set base point if (mdone[curt]==0) { dtarrhist[curt] = dtarrbase; } // figure out if we need to descend to children if (mdone[curt]<mnch[curt]) { // figure out current child ch = (int)(mch[curt][mdone[curt]])-1; // Matlab indices start from 1 // we haven't yet computed the current child; set up to do that now ch = (int)(mch[curt][mdone[curt]])-1; // Matlab indices start from 1 // allocate new dt storage space if necessary if (dtarrlim==dtarrbase) { dtarr[dtarrlim] = (double*)mxMalloc(nrow*ncol*sizeof(double)); dtarrlim++; } // copy dt1 for (i = 0; i < nrow*ncol; i++) { dtarr[dtarrbase][i] = dt1[i]; } // set up storage for this child dtarrp[ch] = dtarr[dtarrbase]; dtarrbase++; // move on, but when we return, remember that this child is done mdone[curt]++; curt = ch; } else { // all children complete; assemble result for (c = 0; c < mnch[curt]; c++) { ch = (int)(mch[curt][c])-1; // Matlab indices start from 1 errCheck(dtarrp[ch]!=0,"Null pointer"); mxAssert((ch>=0)&&(ch<nmpt),"Out of bounds"); tranDT(dtarrp[ch],tranarr,nrow,ncol,mx[ch],my[ch],maxd*mndesc[ch]); gdt2d(tranarr,dtarrp[ch],locarr[ch],v,z,nrow,ncol,mvx[ch],mvy[ch], scratch,scratch2,lscratch); for (i = 0; i < nrow*ncol; i++) { dtarrp[curt][i] += dtarrp[ch][i]; } } // now go back up to the parent if (mp[curt]>0) { mxAssert((curt>=0)&&(curt<nmpt),"Out of bounds"); mxAssert((mp[curt]-1>=0)&&(mp[curt]-1<nmpt),"Out of bounds"); mndesc[mp[curt]-1] += mndesc[curt]; } dtarrbase = dtarrhist[curt]; curt = mp[curt]-1; // Matlab indices start from 1 } } // do final translation and distance transform tranDT(dt1,tranarr,nrow,ncol,mx[root],my[root],maxd*nmpt); gdt2d(tranarr,dt1,locarr[root],v,z,nrow,ncol,mvx[root],mvy[root], scratch,scratch2,lscratch); // assemble loc information if required prnt = -1; if (loc) { for (i = 0; i < nmpt; i++) { mdone[i] = 0; } curt = root; while (curt != -1) { // first time through: if (mdone[curt] == 0) { int y = ROUND(my[curt]); int x = ROUND(mx[curt]); // copy results for this node for (i = 0; i < nrow; i++) { for (j = 0; j < ncol; j++) { if (prnt == -1) { locp[i+j*nrow][2*curt] = BOUND(j+x,0,ncol-1); locp[i+j*nrow][2*curt+1] = BOUND(i+y,0,nrow-1); } else { int jj = (int)BOUND(locp[i+j*nrow][2*prnt],0,ncol-1); int ii = (int)BOUND(locp[i+j*nrow][2*prnt+1],0,nrow-1); locp[i+j*nrow][2*curt] = locarr[curt][ii+nrow*jj]+x; locp[i+j*nrow][2*curt+1] = locarr2[curt][ii+nrow*jj]+y; } } } } // descend to children if any left if (mdone[curt]<mnch[curt]) { // descend to child prnt = curt; ch = (int)(mch[curt][mdone[curt]])-1; // Matlab indices start from 1 mdone[curt]++; curt = ch; } else { // come back up curt = prnt; // Matlab indices start from 1 prnt = mp[curt]-1; } } // add +1 to all indices for Matlab for (i = 0; i < nrow*ncol; i++) { for (j = 0; j < 2*nmpt; j++) { locp[i][j]++; } } } // compute scale if needed if (nlhs>=3) { for (i = 0; i < nrow*ncol; i++) { double tmp = 0; for (j = 0; j < nmpt; j++) { if (mp[j]>0) { tmp += sqrt(SQR(locp[i][2*j]-locp[i][2*mp[j]-2])+ SQR(locp[i][2*j+1]-locp[i][2*mp[j]-1])); } } scl[i] = tmp; } } // free stuff for (i = 0; i < dtarrlim; i++) { mxFree(dtarr[i]); } if (loc) { for (i = 0; i < nmpt; i++) { mxFree(locarr[i]); } } mxFree(locarr); mxFree(dtarrhist); mxFree(dtarrp); mxFree(dtarr); mxFree(mndesc); mxFree(mdone); mxFree(z); mxFree(v); if (locp) { mxFree(lscratch); } mxFree(scratch2); mxFree(scratch); if (nlhs==2) { mxFree(loc); mxFree(locp); } mxFree(mnch); mxFree(mch); mxFree(mp); mxFree(mvy); mxFree(mvx); mxFree(mr); mxFree(my); mxFree(mx); }
/* * This function calculates the curve values between the control points * p2 and p3, taking the potentially existing neighbors p1 and p4 into * account. * * This function uses a cubic bezier curve for the individual segments and * calculates the necessary intermediate control points depending on the * neighbor curve control points. */ static void gimp_curve_plot (GimpCurve *curve, gint p1, gint p2, gint p3, gint p4) { gint i; gdouble x0, x3; gdouble y0, y1, y2, y3; gdouble dx, dy; gdouble slope; /* the outer control points for the bezier curve. */ x0 = curve->points[p2].x; y0 = curve->points[p2].y; x3 = curve->points[p3].x; y3 = curve->points[p3].y; /* * the x values of the inner control points are fixed at * x1 = 2/3*x0 + 1/3*x3 and x2 = 1/3*x0 + 2/3*x3 * this ensures that the x values increase linearily with the * parameter t and enables us to skip the calculation of the x * values altogehter - just calculate y(t) evenly spaced. */ dx = x3 - x0; dy = y3 - y0; g_return_if_fail (dx > 0); if (p1 == p2 && p3 == p4) { /* No information about the neighbors, * calculate y1 and y2 to get a straight line */ y1 = y0 + dy / 3.0; y2 = y0 + dy * 2.0 / 3.0; } else if (p1 == p2 && p3 != p4) { /* only the right neighbor is available. Make the tangent at the * right endpoint parallel to the line between the left endpoint * and the right neighbor. Then point the tangent at the left towards * the control handle of the right tangent, to ensure that the curve * does not have an inflection point. */ slope = (curve->points[p4].y - y0) / (curve->points[p4].x - x0); y2 = y3 - slope * dx / 3.0; y1 = y0 + (y2 - y0) / 2.0; } else if (p1 != p2 && p3 == p4) { /* see previous case */ slope = (y3 - curve->points[p1].y) / (x3 - curve->points[p1].x); y1 = y0 + slope * dx / 3.0; y2 = y3 + (y1 - y3) / 2.0; } else /* (p1 != p2 && p3 != p4) */ { /* Both neighbors are available. Make the tangents at the endpoints * parallel to the line between the opposite endpoint and the adjacent * neighbor. */ slope = (y3 - curve->points[p1].y) / (x3 - curve->points[p1].x); y1 = y0 + slope * dx / 3.0; slope = (curve->points[p4].y - y0) / (curve->points[p4].x - x0); y2 = y3 - slope * dx / 3.0; } /* * finally calculate the y(t) values for the given bezier values. We can * use homogenously distributed values for t, since x(t) increases linearily. */ for (i = 0; i <= ROUND (dx * (gdouble) (curve->n_samples - 1)); i++) { gdouble y, t; gint index; t = i / dx / (gdouble) (curve->n_samples - 1); y = y0 * (1-t) * (1-t) * (1-t) + 3 * y1 * (1-t) * (1-t) * t + 3 * y2 * (1-t) * t * t + y3 * t * t * t; index = i + ROUND (x0 * (gdouble) (curve->n_samples - 1)); if (index < curve->n_samples) curve->samples[index] = CLAMP (y, 0.0, 1.0); } }
static void gimp_curve_calculate (GimpCurve *curve) { gint *points; gint i; gint num_pts; gint p1, p2, p3, p4; if (gimp_data_is_frozen (GIMP_DATA (curve))) return; points = g_newa (gint, curve->n_points); switch (curve->curve_type) { case GIMP_CURVE_SMOOTH: /* cycle through the curves */ num_pts = 0; for (i = 0; i < curve->n_points; i++) if (curve->points[i].x >= 0.0) points[num_pts++] = i; /* Initialize boundary curve points */ if (num_pts != 0) { GimpVector2 point; gint boundary; point = curve->points[points[0]]; boundary = ROUND (point.x * (gdouble) (curve->n_samples - 1)); for (i = 0; i < boundary; i++) curve->samples[i] = point.y; point = curve->points[points[num_pts - 1]]; boundary = ROUND (point.x * (gdouble) (curve->n_samples - 1)); for (i = boundary; i < curve->n_samples; i++) curve->samples[i] = point.y; } for (i = 0; i < num_pts - 1; i++) { p1 = points[MAX (i - 1, 0)]; p2 = points[i]; p3 = points[i + 1]; p4 = points[MIN (i + 2, num_pts - 1)]; gimp_curve_plot (curve, p1, p2, p3, p4); } /* ensure that the control points are used exactly */ for (i = 0; i < num_pts; i++) { gdouble x = curve->points[points[i]].x; gdouble y = curve->points[points[i]].y; curve->samples[ROUND (x * (gdouble) (curve->n_samples - 1))] = y; } g_object_notify (G_OBJECT (curve), "samples"); break; case GIMP_CURVE_FREE: break; } }
int main(int argc, char **argv) { char * input_file = NULL; double image_gamma = TIFF_GAMMA; int i, j; TIFF * tif; unsigned char * scan_line; uint16 red[CMSIZE], green[CMSIZE], blue[CMSIZE]; float refblackwhite[2*3]; programName = argv[0]; switch (argc) { case 2: image_gamma = TIFF_GAMMA; input_file = argv[1]; break; case 4: if (!strcmp(argv[1], "-gamma")) { image_gamma = atof(argv[2]); input_file = argv[3]; } else Usage(); break; default: Usage(); } for (i = 0; i < CMSIZE; i++) { if (i == 0) red[i] = green[i] = blue[i] = 0; else { red[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0)); green[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0)); blue[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0)); } } refblackwhite[0] = 0.0; refblackwhite[1] = 255.0; refblackwhite[2] = 0.0; refblackwhite[3] = 255.0; refblackwhite[4] = 0.0; refblackwhite[5] = 255.0; if ((tif = TIFFOpen(input_file, "w")) == NULL) { fprintf(stderr, "can't open %s as a TIFF file\n", input_file); exit(0); } TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, WIDTH); TIFFSetField(tif, TIFFTAG_IMAGELENGTH, HEIGHT); TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3); TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE); #ifdef notdef TIFFSetField(tif, TIFFTAG_WHITEPOINT, whitex, whitey); TIFFSetField(tif, TIFFTAG_PRIMARYCHROMATICITIES, primaries); #endif TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refblackwhite); TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, red, green, blue); scan_line = (unsigned char *) malloc(WIDTH * 3); for (i = 0; i < 255; i++) { for (j = 0; j < 75; j++) { scan_line[j * 3] = 255; scan_line[(j * 3) + 1] = 255 - i; scan_line[(j * 3) + 2] = 255 - i; } for (j = 75; j < 150; j++) { scan_line[j * 3] = 255 - i; scan_line[(j * 3) + 1] = 255; scan_line[(j * 3) + 2] = 255 - i; } for (j = 150; j < 225; j++) { scan_line[j * 3] = 255 - i; scan_line[(j * 3) + 1] = 255 - i; scan_line[(j * 3) + 2] = 255; } for (j = 225; j < 300; j++) { scan_line[j * 3] = (i - 1) / 2; scan_line[(j * 3) + 1] = (i - 1) / 2; scan_line[(j * 3) + 2] = (i - 1) / 2; } for (j = 300; j < 375; j++) { scan_line[j * 3] = 255 - i; scan_line[(j * 3) + 1] = 255; scan_line[(j * 3) + 2] = 255; } for (j = 375; j < 450; j++) { scan_line[j * 3] = 255; scan_line[(j * 3) + 1] = 255 - i; scan_line[(j * 3) + 2] = 255; } for (j = 450; j < 525; j++) { scan_line[j * 3] = 255; scan_line[(j * 3) + 1] = 255; scan_line[(j * 3) + 2] = 255 - i; } TIFFWriteScanline(tif, scan_line, i, 0); } for (i = 255; i < 512; i++) { for (j = 0; j < 75; j++) { scan_line[j * 3] = i; scan_line[(j * 3) + 1] = 0; scan_line[(j * 3) + 2] = 0; } for (j = 75; j < 150; j++) { scan_line[j * 3] = 0; scan_line[(j * 3) + 1] = i; scan_line[(j * 3) + 2] = 0; } for (j = 150; j < 225; j++) { scan_line[j * 3] = 0; scan_line[(j * 3) + 1] = 0; scan_line[(j * 3) + 2] = i; } for (j = 225; j < 300; j++) { scan_line[j * 3] = (i - 1) / 2; scan_line[(j * 3) + 1] = (i - 1) / 2; scan_line[(j * 3) + 2] = (i - 1) / 2; } for (j = 300; j < 375; j++) { scan_line[j * 3] = 0; scan_line[(j * 3) + 1] = i; scan_line[(j * 3) + 2] = i; } for (j = 375; j < 450; j++) { scan_line[j * 3] = i; scan_line[(j * 3) + 1] = 0; scan_line[(j * 3) + 2] = i; } for (j = 450; j < 525; j++) { scan_line[j * 3] = i; scan_line[(j * 3) + 1] = i; scan_line[(j * 3) + 2] = 0; } TIFFWriteScanline(tif, scan_line, i, 0); } free(scan_line); TIFFClose(tif); exit(0); }
void _nettle_md5_compress(uint32_t *digest, const uint8_t *input) { uint32_t data[MD5_DATA_LENGTH]; uint32_t a, b, c, d; unsigned i; for (i = 0; i < MD5_DATA_LENGTH; i++, input += 4) data[i] = LE_READ_UINT32(input); a = digest[0]; b = digest[1]; c = digest[2]; d = digest[3]; ROUND(F1, a, b, c, d, data[ 0] + 0xd76aa478, 7); ROUND(F1, d, a, b, c, data[ 1] + 0xe8c7b756, 12); ROUND(F1, c, d, a, b, data[ 2] + 0x242070db, 17); ROUND(F1, b, c, d, a, data[ 3] + 0xc1bdceee, 22); ROUND(F1, a, b, c, d, data[ 4] + 0xf57c0faf, 7); ROUND(F1, d, a, b, c, data[ 5] + 0x4787c62a, 12); ROUND(F1, c, d, a, b, data[ 6] + 0xa8304613, 17); ROUND(F1, b, c, d, a, data[ 7] + 0xfd469501, 22); ROUND(F1, a, b, c, d, data[ 8] + 0x698098d8, 7); ROUND(F1, d, a, b, c, data[ 9] + 0x8b44f7af, 12); ROUND(F1, c, d, a, b, data[10] + 0xffff5bb1, 17); ROUND(F1, b, c, d, a, data[11] + 0x895cd7be, 22); ROUND(F1, a, b, c, d, data[12] + 0x6b901122, 7); ROUND(F1, d, a, b, c, data[13] + 0xfd987193, 12); ROUND(F1, c, d, a, b, data[14] + 0xa679438e, 17); ROUND(F1, b, c, d, a, data[15] + 0x49b40821, 22); ROUND(F2, a, b, c, d, data[ 1] + 0xf61e2562, 5); ROUND(F2, d, a, b, c, data[ 6] + 0xc040b340, 9); ROUND(F2, c, d, a, b, data[11] + 0x265e5a51, 14); ROUND(F2, b, c, d, a, data[ 0] + 0xe9b6c7aa, 20); ROUND(F2, a, b, c, d, data[ 5] + 0xd62f105d, 5); ROUND(F2, d, a, b, c, data[10] + 0x02441453, 9); ROUND(F2, c, d, a, b, data[15] + 0xd8a1e681, 14); ROUND(F2, b, c, d, a, data[ 4] + 0xe7d3fbc8, 20); ROUND(F2, a, b, c, d, data[ 9] + 0x21e1cde6, 5); ROUND(F2, d, a, b, c, data[14] + 0xc33707d6, 9); ROUND(F2, c, d, a, b, data[ 3] + 0xf4d50d87, 14); ROUND(F2, b, c, d, a, data[ 8] + 0x455a14ed, 20); ROUND(F2, a, b, c, d, data[13] + 0xa9e3e905, 5); ROUND(F2, d, a, b, c, data[ 2] + 0xfcefa3f8, 9); ROUND(F2, c, d, a, b, data[ 7] + 0x676f02d9, 14); ROUND(F2, b, c, d, a, data[12] + 0x8d2a4c8a, 20); ROUND(F3, a, b, c, d, data[ 5] + 0xfffa3942, 4); ROUND(F3, d, a, b, c, data[ 8] + 0x8771f681, 11); ROUND(F3, c, d, a, b, data[11] + 0x6d9d6122, 16); ROUND(F3, b, c, d, a, data[14] + 0xfde5380c, 23); ROUND(F3, a, b, c, d, data[ 1] + 0xa4beea44, 4); ROUND(F3, d, a, b, c, data[ 4] + 0x4bdecfa9, 11); ROUND(F3, c, d, a, b, data[ 7] + 0xf6bb4b60, 16); ROUND(F3, b, c, d, a, data[10] + 0xbebfbc70, 23); ROUND(F3, a, b, c, d, data[13] + 0x289b7ec6, 4); ROUND(F3, d, a, b, c, data[ 0] + 0xeaa127fa, 11); ROUND(F3, c, d, a, b, data[ 3] + 0xd4ef3085, 16); ROUND(F3, b, c, d, a, data[ 6] + 0x04881d05, 23); ROUND(F3, a, b, c, d, data[ 9] + 0xd9d4d039, 4); ROUND(F3, d, a, b, c, data[12] + 0xe6db99e5, 11); ROUND(F3, c, d, a, b, data[15] + 0x1fa27cf8, 16); ROUND(F3, b, c, d, a, data[ 2] + 0xc4ac5665, 23); ROUND(F4, a, b, c, d, data[ 0] + 0xf4292244, 6); ROUND(F4, d, a, b, c, data[ 7] + 0x432aff97, 10); ROUND(F4, c, d, a, b, data[14] + 0xab9423a7, 15); ROUND(F4, b, c, d, a, data[ 5] + 0xfc93a039, 21); ROUND(F4, a, b, c, d, data[12] + 0x655b59c3, 6); ROUND(F4, d, a, b, c, data[ 3] + 0x8f0ccc92, 10); ROUND(F4, c, d, a, b, data[10] + 0xffeff47d, 15); ROUND(F4, b, c, d, a, data[ 1] + 0x85845dd1, 21); ROUND(F4, a, b, c, d, data[ 8] + 0x6fa87e4f, 6); ROUND(F4, d, a, b, c, data[15] + 0xfe2ce6e0, 10); ROUND(F4, c, d, a, b, data[ 6] + 0xa3014314, 15); ROUND(F4, b, c, d, a, data[13] + 0x4e0811a1, 21); ROUND(F4, a, b, c, d, data[ 4] + 0xf7537e82, 6); ROUND(F4, d, a, b, c, data[11] + 0xbd3af235, 10); ROUND(F4, c, d, a, b, data[ 2] + 0x2ad7d2bb, 15); ROUND(F4, b, c, d, a, data[ 9] + 0xeb86d391, 21); digest[0] += a; digest[1] += b; digest[2] += c; digest[3] += d; }
/* Permute the state while xoring in the block of data. */ static void blake2s_compress(BLAKE2S_CTX *S, const uint8_t block[BLAKE2S_BLOCKBYTES]) { uint32_t m[16]; uint32_t v[16]; size_t i; for(i = 0; i < 16; ++i) { m[i] = load32(block + i * sizeof(m[i])); } for(i = 0; i < 8; ++i) { v[i] = S->h[i]; } v[ 8] = blake2s_IV[0]; v[ 9] = blake2s_IV[1]; v[10] = blake2s_IV[2]; v[11] = blake2s_IV[3]; v[12] = S->t[0] ^ blake2s_IV[4]; v[13] = S->t[1] ^ blake2s_IV[5]; v[14] = S->f[0] ^ blake2s_IV[6]; v[15] = S->f[1] ^ blake2s_IV[7]; #define G(r,i,a,b,c,d) \ do { \ a = a + b + m[blake2s_sigma[r][2*i+0]]; \ d = rotr32(d ^ a, 16); \ c = c + d; \ b = rotr32(b ^ c, 12); \ a = a + b + m[blake2s_sigma[r][2*i+1]]; \ d = rotr32(d ^ a, 8); \ c = c + d; \ b = rotr32(b ^ c, 7); \ } while(0) #define ROUND(r) \ do { \ G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ G(r,2,v[ 2],v[ 6],v[10],v[14]); \ G(r,3,v[ 3],v[ 7],v[11],v[15]); \ G(r,4,v[ 0],v[ 5],v[10],v[15]); \ G(r,5,v[ 1],v[ 6],v[11],v[12]); \ G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ } while(0) ROUND(0); ROUND(1); ROUND(2); ROUND(3); ROUND(4); ROUND(5); ROUND(6); ROUND(7); ROUND(8); ROUND(9); for(i = 0; i < 8; ++i) { S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; } #undef G #undef ROUND }
/* * For all x and y as requested, replace the pixel at (x,y) * with a weighted average of the most frequently occurring * values in a circle of mask_size diameter centered at (x,y). */ static void oilify (GimpDrawable *drawable, GimpPreview *preview) { gboolean use_inten; gboolean use_msmap = FALSE; gboolean use_emap = FALSE; GimpDrawable *mask_size_map_drawable = NULL; GimpDrawable *exponent_map_drawable = NULL; GimpPixelRgn mask_size_map_rgn; GimpPixelRgn exponent_map_rgn; gint msmap_bpp = 0; gint emap_bpp = 0; GimpPixelRgn dest_rgn; GimpPixelRgn *regions[3]; gint n_regions; gint bpp; gint *sqr_lut; gint x1, y1, x2, y2; gint width, height; gint Hist[HISTSIZE]; gint Hist_rgb[4][HISTSIZE]; gpointer pr; gint progress, max_progress; guchar *src_buf; guchar *src_inten_buf = NULL; gint i; use_inten = (ovals.mode == MODE_INTEN); /* Get the selection bounds */ if (preview) { gimp_preview_get_position (preview, &x1, &y1); gimp_preview_get_size (preview, &width, &height); x2 = x1 + width; y2 = y1 + height; } else { gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); width = x2 - x1; height = y2 - y1; } progress = 0; max_progress = width * height; bpp = drawable->bpp; /* * Look-up-table implementation of the square function, for use in the * VERY TIGHT inner loops */ { gint lut_size = (gint) ovals.mask_size / 2 + 1; sqr_lut = g_new (gint, lut_size); for (i = 0; i < lut_size; i++) sqr_lut[i] = SQR (i); } /* Get the map drawables, if applicable */ if (ovals.use_mask_size_map && ovals.mask_size_map >= 0) { use_msmap = TRUE; mask_size_map_drawable = gimp_drawable_get (ovals.mask_size_map); gimp_pixel_rgn_init (&mask_size_map_rgn, mask_size_map_drawable, x1, y1, width, height, FALSE, FALSE); msmap_bpp = mask_size_map_drawable->bpp; } if (ovals.use_exponent_map && ovals.exponent_map >= 0) { use_emap = TRUE; exponent_map_drawable = gimp_drawable_get (ovals.exponent_map); gimp_pixel_rgn_init (&exponent_map_rgn, exponent_map_drawable, x1, y1, width, height, FALSE, FALSE); emap_bpp = exponent_map_drawable->bpp; } gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, width, height, (preview == NULL), TRUE); { GimpPixelRgn src_rgn; gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, width, height, FALSE, FALSE); src_buf = g_new (guchar, width * height * bpp); gimp_pixel_rgn_get_rect (&src_rgn, src_buf, x1, y1, width, height); } /* * If we're working in intensity mode, then generate a separate intensity * map of the source image. This way, we can avoid calculating the * intensity of any given source pixel more than once. */ if (use_inten) { guchar *src; guchar *dest; src_inten_buf = g_new (guchar, width * height); for (i = 0, src = src_buf, dest = src_inten_buf ; i < (width * height) ; i++, src += bpp, dest++) { *dest = (guchar) GIMP_RGB_LUMINANCE (src[0], src[1], src[2]); } } n_regions = 0; regions[n_regions++] = &dest_rgn; if (use_msmap) regions[n_regions++] = &mask_size_map_rgn; if (use_emap) regions[n_regions++] = &exponent_map_rgn; for (pr = gimp_pixel_rgns_register2 (n_regions, regions); pr != NULL; pr = gimp_pixel_rgns_process (pr)) { gint y; guchar *dest_row; guchar *src_msmap_row = NULL; guchar *src_emap_row = NULL; for (y = dest_rgn.y, dest_row = dest_rgn.data, src_msmap_row = mask_size_map_rgn.data, /* valid iff use_msmap */ src_emap_row = exponent_map_rgn.data /* valid iff use_emap */ ; y < (gint) (dest_rgn.y + dest_rgn.h) ; y++, dest_row += dest_rgn.rowstride, src_msmap_row += mask_size_map_rgn.rowstride, /* valid iff use_msmap */ src_emap_row += exponent_map_rgn.rowstride) /* valid iff use_emap */ { gint x; guchar *dest; guchar *src_msmap = NULL; guchar *src_emap = NULL; for (x = dest_rgn.x, dest = dest_row, src_msmap = src_msmap_row, /* valid iff use_msmap */ src_emap = src_emap_row /* valid iff use_emap */ ; x < (gint) (dest_rgn.x + dest_rgn.w) ; x++, dest += bpp, src_msmap += msmap_bpp, /* valid iff use_msmap */ src_emap += emap_bpp) /* valid iff use_emap */ { gint radius, radius_squared; gfloat exponent; gint mask_x1, mask_y1; gint mask_x2, mask_y2; gint mask_y; gint src_offset; guchar *src_row; guchar *src_inten_row = NULL; if (use_msmap) { gfloat factor = get_map_value (src_msmap, msmap_bpp); radius = ROUND (factor * (0.5 * ovals.mask_size)); } else { radius = (gint) ovals.mask_size / 2; } radius_squared = SQR (radius); exponent = ovals.exponent; if (use_emap) exponent *= get_map_value (src_emap, emap_bpp); if (use_inten) memset (Hist, 0, sizeof (Hist)); memset (Hist_rgb, 0, sizeof (Hist_rgb)); mask_x1 = CLAMP ((x - radius), x1, x2); mask_y1 = CLAMP ((y - radius), y1, y2); mask_x2 = CLAMP ((x + radius + 1), x1, x2); mask_y2 = CLAMP ((y + radius + 1), y1, y2); src_offset = (mask_y1 - y1) * width + (mask_x1 - x1); for (mask_y = mask_y1, src_row = src_buf + src_offset * bpp, src_inten_row = src_inten_buf + src_offset /* valid iff use_inten */ ; mask_y < mask_y2 ; mask_y++, src_row += width * bpp, src_inten_row += width) /* valid iff use_inten */ { guchar *src; guchar *src_inten = NULL; gint dy_squared = sqr_lut[ABS (mask_y - y)]; gint mask_x; for (mask_x = mask_x1, src = src_row, src_inten = src_inten_row /* valid iff use_inten */ ; mask_x < mask_x2 ; mask_x++, src += bpp, src_inten++) /* valid iff use_inten */ { gint dx_squared = sqr_lut[ABS (mask_x - x)]; gint b; /* Stay inside a circular mask area */ if ((dx_squared + dy_squared) > radius_squared) continue; if (use_inten) { gint inten = *src_inten; ++Hist[inten]; for (b = 0; b < bpp; b++) Hist_rgb[b][inten] += src[b]; } else { for (b = 0; b < bpp; b++) ++Hist_rgb[b][src[b]]; } } /* for mask_x */ } /* for mask_y */ if (use_inten) { weighted_average_color (Hist, Hist_rgb, exponent, dest, bpp); } else { gint b; for (b = 0; b < bpp; b++) dest[b] = weighted_average_value (Hist_rgb[b], exponent); } } /* for x */ } /* for y */ if (preview) { gimp_drawable_preview_draw_region (GIMP_DRAWABLE_PREVIEW (preview), &dest_rgn); } else { progress += dest_rgn.w * dest_rgn.h; gimp_progress_update ((gdouble) progress / (gdouble) max_progress); } } /* for pr */ /* Detach from the map drawables */ if (mask_size_map_drawable) gimp_drawable_detach (mask_size_map_drawable); if (exponent_map_drawable) gimp_drawable_detach (exponent_map_drawable); if (src_inten_buf) g_free (src_inten_buf); g_free (src_buf); g_free (sqr_lut); if (!preview) { gimp_progress_update (1.0); /* Update the oil-painted region */ gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x1, y1, width, height); } }
static void ComputeTextBbox( Tk_Canvas canvas, /* Canvas that contains item. */ TextItem *textPtr) /* Item whose bbox is to be recomputed. */ { Tk_CanvasTextInfo *textInfoPtr; int leftX, topY, width, height, fudge, i; Tk_State state = textPtr->header.state; double x[4], y[4], dx[4], dy[4], sinA, cosA, tmp; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } Tk_FreeTextLayout(textPtr->textLayout); textPtr->textLayout = Tk_ComputeTextLayout(textPtr->tkfont, textPtr->text, textPtr->numChars, textPtr->width, textPtr->justify, 0, &width, &height); if (state == TK_STATE_HIDDEN || textPtr->color == NULL) { width = height = 0; } /* * Use overall geometry information to compute the top-left corner of the * bounding box for the text item. */ leftX = ROUND(textPtr->x); topY = ROUND(textPtr->y); for (i=0 ; i<4 ; i++) { dx[i] = dy[i] = 0.0; } switch (textPtr->anchor) { case TK_ANCHOR_NW: case TK_ANCHOR_N: case TK_ANCHOR_NE: break; case TK_ANCHOR_W: case TK_ANCHOR_CENTER: case TK_ANCHOR_E: topY -= height / 2; for (i=0 ; i<4 ; i++) { dy[i] = -height / 2; } break; case TK_ANCHOR_SW: case TK_ANCHOR_S: case TK_ANCHOR_SE: topY -= height; for (i=0 ; i<4 ; i++) { dy[i] = -height; } break; } switch (textPtr->anchor) { case TK_ANCHOR_NW: case TK_ANCHOR_W: case TK_ANCHOR_SW: break; case TK_ANCHOR_N: case TK_ANCHOR_CENTER: case TK_ANCHOR_S: leftX -= width / 2; for (i=0 ; i<4 ; i++) { dx[i] = -width / 2; } break; case TK_ANCHOR_NE: case TK_ANCHOR_E: case TK_ANCHOR_SE: leftX -= width; for (i=0 ; i<4 ; i++) { dx[i] = -width; } break; } textPtr->actualWidth = width; sinA = textPtr->sine; cosA = textPtr->cosine; textPtr->drawOrigin[0] = textPtr->x + dx[0]*cosA + dy[0]*sinA; textPtr->drawOrigin[1] = textPtr->y + dy[0]*cosA - dx[0]*sinA; /* * Last of all, update the bounding box for the item. The item's bounding * box includes the bounding box of all its lines, plus an extra fudge * factor for the cursor border (which could potentially be quite large). */ textInfoPtr = textPtr->textInfoPtr; fudge = (textInfoPtr->insertWidth + 1) / 2; if (textInfoPtr->selBorderWidth > fudge) { fudge = textInfoPtr->selBorderWidth; } /* * Apply the rotation before computing the bounding box. */ dx[0] -= fudge; dx[1] += width + fudge; dx[2] += width + fudge; dy[2] += height; dx[3] -= fudge; dy[3] += height; for (i=0 ; i<4 ; i++) { x[i] = textPtr->x + dx[i] * cosA + dy[i] * sinA; y[i] = textPtr->y + dy[i] * cosA - dx[i] * sinA; } /* * Convert to a rectilinear bounding box. */ for (i=1,tmp=x[0] ; i<4 ; i++) { if (x[i] < tmp) { tmp = x[i]; } } textPtr->header.x1 = ROUND(tmp); for (i=1,tmp=y[0] ; i<4 ; i++) { if (y[i] < tmp) { tmp = y[i]; } } textPtr->header.y1 = ROUND(tmp); for (i=1,tmp=x[0] ; i<4 ; i++) { if (x[i] > tmp) { tmp = x[i]; } } textPtr->header.x2 = ROUND(tmp); for (i=1,tmp=y[0] ; i<4 ; i++) { if (y[i] > tmp) { tmp = y[i]; } } textPtr->header.y2 = ROUND(tmp); }
/* *--------------------------------------------------------------------------- * * Blt_RotateBitmap -- * * Creates a new bitmap containing the rotated image of the given * bitmap. We also need a special GC of depth 1, so that we do * not need to rotate more than one plane of the bitmap. * * Results: * Returns a new bitmap containing the rotated image. * *--------------------------------------------------------------------------- */ Pixmap Blt_RotateBitmap( Tk_Window tkwin, Pixmap srcBitmap, /* Source bitmap to be rotated */ int srcWidth, int srcHeight, /* Width and height of the source bitmap */ float angle, /* # of degrees to rotate the bitmap. */ int *destWidthPtr, int *destHeightPtr) { Display *display; /* X display */ GC bitmapGC; Pixmap destBitmap; Window root; /* Root window drawable */ XImage *srcImgPtr, *destImgPtr; double rotWidth, rotHeight; int destWidth, destHeight; display = Tk_Display(tkwin); root = Tk_RootWindow(tkwin); #ifdef notdef /* Create a bitmap and image big enough to contain the rotated text */ Blt_GetBoundingBox(srcWidth, srcHeight, angle, &rotWidth, &rotHeight, (Point2d *)NULL); destWidth = ROUND(rotWidth); destHeight = ROUND(rotHeight); destBitmap = Tk_GetPixmap(display, root, destWidth, destHeight, 1); bitmapGC = Blt_GetBitmapGC(tkwin); XSetForeground(display, bitmapGC, 0x0); XFillRectangle(display, destBitmap, bitmapGC, 0, 0, destWidth, destHeight); srcImgPtr = XGetImage(display, srcBitmap, 0, 0, srcWidth, srcHeight, 1, ZPixmap); destImgPtr = XGetImage(display, destBitmap, 0, 0, destWidth, destHeight, 1, ZPixmap); angle = FMOD(angle, 360.0); if (FMOD(angle, 90.0) == 0.0) { int quadrant; int y; /* Handle right-angle rotations specifically */ quadrant = (int)(angle / 90.0); switch (quadrant) { case ROTATE_270: /* 270 degrees */ for (y = 0; y < destHeight; y++) { int x, sx; sx = y; for (x = 0; x < destWidth; x++) { int sy; unsigned long pixel; sy = destWidth - x - 1; pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; case ROTATE_180: /* 180 degrees */ for (y = 0; y < destHeight; y++) { int x, sy; sy = destHeight - y - 1; for (x = 0; x < destWidth; x++) { int sx; unsigned long pixel; sx = destWidth - x - 1, pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; case ROTATE_90: /* 90 degrees */ for (y = 0; y < destHeight; y++) { int x, sx; sx = destHeight - y - 1; for (x = 0; x < destWidth; x++) { int sy; unsigned long pixel; sy = x; pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; case ROTATE_0: /* 0 degrees */ for (y = 0; y < destHeight; y++) { int x; for (x = 0; x < destWidth; x++) { unsigned long pixel; pixel = XGetPixel(srcImgPtr, x, y); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } break; default: /* The calling routine should never let this happen. */ break; } } else { double radians, sinTheta, cosTheta; double sox, soy; /* Offset from the center of * the source rectangle. */ double destCX, destCY; /* Offset to the center of the destination * rectangle. */ int y; radians = (angle / 180.0) * M_PI; sinTheta = sin(radians), cosTheta = cos(radians); /* * Coordinates of the centers of the source and destination rectangles */ sox = srcWidth * 0.5; soy = srcHeight * 0.5; destCX = destWidth * 0.5; destCY = destHeight * 0.5; /* For each pixel of the destination image, transform back to the * associated pixel in the source image. */ for (y = 0; y < destHeight; y++) { double ty; int x; ty = y - destCY; for (x = 0; x < destWidth; x++) { double tx, rx, ry, sx, sy; unsigned long pixel; /* Translate origin to center of destination image. */ tx = x - destCX; /* Rotate the coordinates about the origin. */ rx = (tx * cosTheta) - (ty * sinTheta); ry = (tx * sinTheta) + (ty * cosTheta); /* Translate back to the center of the source image. */ rx += sox; ry += soy; sx = ROUND(rx); sy = ROUND(ry); /* * Verify the coordinates, since the destination image can be * bigger than the source. */ if ((sx >= srcWidth) || (sx < 0) || (sy >= srcHeight) || (sy < 0)) { continue; } pixel = XGetPixel(srcImgPtr, sx, sy); if (pixel) { XPutPixel(destImgPtr, x, y, pixel); } } } } /* Write the rotated image into the destination bitmap. */ XPutImage(display, destBitmap, bitmapGC, destImgPtr, 0, 0, 0, 0, destWidth, destHeight); /* Clean up the temporary resources used. */ XDestroyImage(srcImgPtr), XDestroyImage(destImgPtr); *destWidthPtr = destWidth; *destHeightPtr = destHeight; #endif return destBitmap; }
int memcmp( const void *s1, const void *s2, size_t n ) /****************************************************/ { UINT * dw1 = ROUND(s1); /* round down to dword */ UINT * dw2 = ROUND(s2); /* round down to dword */ UINT dword1, dword2, tmpdword1, tmpdword2; int tmpchar, shr1, shr2, shl1, shl2; if( n == 0 ) return( 0 ); /*** Initialize locals ***/ shr1 = OFFSET(s1) << 3; /* shift right = offset * 8 */ shr2 = OFFSET(s2) << 3; shl1 = INT_SIZE - shr1; /* shift left = 32 - shift right */ shl2 = INT_SIZE - shr2; if (shr1 != 0) { dword1 = *dw1++; } if (shr2 != 0) { dword2 = *dw2++; } /*** Scan in aligned 4-byte groups ***/ for( ;; ) { /*** Extract the next few characters from each string ***/ if( shr1 == 0 ) { tmpdword1 = *dw1++; } else { tmpdword1 = dword1 >> shr1; dword1 = *dw1++; tmpdword1 |= (dword1 << shl1); } if( shr2 == 0 ) { tmpdword2 = *dw2++; } else { tmpdword2 = dword2 >> shr2; dword2 = *dw2++; tmpdword2 |= (dword2 << shl2); } if( n < BYTES_PER_WORD ) break; /*** Are s1 and s2 still the same? ***/ if( tmpdword1 != tmpdword2 ) { tmpchar = CHR1(tmpdword1) - CHR1(tmpdword2); if( tmpchar ) return( tmpchar ); tmpchar = CHR2(tmpdword1) - CHR2(tmpdword2); if( tmpchar ) return( tmpchar ); tmpchar = CHR3(tmpdword1) - CHR3(tmpdword2); if( tmpchar ) return( tmpchar ); return( CHR4(tmpdword1) - CHR4(tmpdword2) ); } n -= BYTES_PER_WORD; } /*** Scan the last byte(s) in the buffer ***/ if( tmpdword1 == tmpdword2 ) return( 0 ); if( n == 1 ) { return( CHR1(tmpdword1) - CHR1(tmpdword2) ); } else if( n == 2 ) { tmpchar = CHR1(tmpdword1) - CHR1(tmpdword2); if( tmpchar ) return( tmpchar ); return( CHR2(tmpdword1) - CHR2(tmpdword2) ); } else if( n == 3 ) { tmpchar = CHR1(tmpdword1) - CHR1(tmpdword2); if( tmpchar ) return( tmpchar ); tmpchar = CHR2(tmpdword1) - CHR2(tmpdword2); if( tmpchar ) return( tmpchar ); return( CHR3(tmpdword1) - CHR3(tmpdword2) ); } return( 0 ); }
static void rmd256_transform(u32 *state, const __le32 *in) { u32 aa, bb, cc, dd, aaa, bbb, ccc, ddd, tmp; /* Initialize left lane */ aa = state[0]; bb = state[1]; cc = state[2]; dd = state[3]; /* Initialize right lane */ aaa = state[4]; bbb = state[5]; ccc = state[6]; ddd = state[7]; /* round 1: left lane */ ROUND(aa, bb, cc, dd, F1, K1, in[0], 11); ROUND(dd, aa, bb, cc, F1, K1, in[1], 14); ROUND(cc, dd, aa, bb, F1, K1, in[2], 15); ROUND(bb, cc, dd, aa, F1, K1, in[3], 12); ROUND(aa, bb, cc, dd, F1, K1, in[4], 5); ROUND(dd, aa, bb, cc, F1, K1, in[5], 8); ROUND(cc, dd, aa, bb, F1, K1, in[6], 7); ROUND(bb, cc, dd, aa, F1, K1, in[7], 9); ROUND(aa, bb, cc, dd, F1, K1, in[8], 11); ROUND(dd, aa, bb, cc, F1, K1, in[9], 13); ROUND(cc, dd, aa, bb, F1, K1, in[10], 14); ROUND(bb, cc, dd, aa, F1, K1, in[11], 15); ROUND(aa, bb, cc, dd, F1, K1, in[12], 6); ROUND(dd, aa, bb, cc, F1, K1, in[13], 7); ROUND(cc, dd, aa, bb, F1, K1, in[14], 9); ROUND(bb, cc, dd, aa, F1, K1, in[15], 8); /* round 1: right lane */ ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[5], 8); ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[14], 9); ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[7], 9); ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[0], 11); ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[9], 13); ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[2], 15); ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[11], 15); ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[4], 5); ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[13], 7); ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[6], 7); ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[15], 8); ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[8], 11); ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[1], 14); ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[10], 14); ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[3], 12); ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[12], 6); /* Swap contents of "a" registers */ tmp = aa; aa = aaa; aaa = tmp; /* round 2: left lane */ ROUND(aa, bb, cc, dd, F2, K2, in[7], 7); ROUND(dd, aa, bb, cc, F2, K2, in[4], 6); ROUND(cc, dd, aa, bb, F2, K2, in[13], 8); ROUND(bb, cc, dd, aa, F2, K2, in[1], 13); ROUND(aa, bb, cc, dd, F2, K2, in[10], 11); ROUND(dd, aa, bb, cc, F2, K2, in[6], 9); ROUND(cc, dd, aa, bb, F2, K2, in[15], 7); ROUND(bb, cc, dd, aa, F2, K2, in[3], 15); ROUND(aa, bb, cc, dd, F2, K2, in[12], 7); ROUND(dd, aa, bb, cc, F2, K2, in[0], 12); ROUND(cc, dd, aa, bb, F2, K2, in[9], 15); ROUND(bb, cc, dd, aa, F2, K2, in[5], 9); ROUND(aa, bb, cc, dd, F2, K2, in[2], 11); ROUND(dd, aa, bb, cc, F2, K2, in[14], 7); ROUND(cc, dd, aa, bb, F2, K2, in[11], 13); ROUND(bb, cc, dd, aa, F2, K2, in[8], 12); /* round 2: right lane */ ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[6], 9); ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[11], 13); ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[3], 15); ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[7], 7); ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[0], 12); ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[13], 8); ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[5], 9); ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[10], 11); ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[14], 7); ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[15], 7); ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[8], 12); ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[12], 7); ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[4], 6); ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[9], 15); ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[1], 13); ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[2], 11); /* Swap contents of "b" registers */ tmp = bb; bb = bbb; bbb = tmp; /* round 3: left lane */ ROUND(aa, bb, cc, dd, F3, K3, in[3], 11); ROUND(dd, aa, bb, cc, F3, K3, in[10], 13); ROUND(cc, dd, aa, bb, F3, K3, in[14], 6); ROUND(bb, cc, dd, aa, F3, K3, in[4], 7); ROUND(aa, bb, cc, dd, F3, K3, in[9], 14); ROUND(dd, aa, bb, cc, F3, K3, in[15], 9); ROUND(cc, dd, aa, bb, F3, K3, in[8], 13); ROUND(bb, cc, dd, aa, F3, K3, in[1], 15); ROUND(aa, bb, cc, dd, F3, K3, in[2], 14); ROUND(dd, aa, bb, cc, F3, K3, in[7], 8); ROUND(cc, dd, aa, bb, F3, K3, in[0], 13); ROUND(bb, cc, dd, aa, F3, K3, in[6], 6); ROUND(aa, bb, cc, dd, F3, K3, in[13], 5); ROUND(dd, aa, bb, cc, F3, K3, in[11], 12); ROUND(cc, dd, aa, bb, F3, K3, in[5], 7); ROUND(bb, cc, dd, aa, F3, K3, in[12], 5); /* round 3: right lane */ ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[15], 9); ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[5], 7); ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[1], 15); ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[3], 11); ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[7], 8); ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[14], 6); ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[6], 6); ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[9], 14); ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[11], 12); ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[8], 13); ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[12], 5); ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[2], 14); ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[10], 13); ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[0], 13); ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[4], 7); ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[13], 5); /* Swap contents of "c" registers */ tmp = cc; cc = ccc; ccc = tmp; /* round 4: left lane */ ROUND(aa, bb, cc, dd, F4, K4, in[1], 11); ROUND(dd, aa, bb, cc, F4, K4, in[9], 12); ROUND(cc, dd, aa, bb, F4, K4, in[11], 14); ROUND(bb, cc, dd, aa, F4, K4, in[10], 15); ROUND(aa, bb, cc, dd, F4, K4, in[0], 14); ROUND(dd, aa, bb, cc, F4, K4, in[8], 15); ROUND(cc, dd, aa, bb, F4, K4, in[12], 9); ROUND(bb, cc, dd, aa, F4, K4, in[4], 8); ROUND(aa, bb, cc, dd, F4, K4, in[13], 9); ROUND(dd, aa, bb, cc, F4, K4, in[3], 14); ROUND(cc, dd, aa, bb, F4, K4, in[7], 5); ROUND(bb, cc, dd, aa, F4, K4, in[15], 6); ROUND(aa, bb, cc, dd, F4, K4, in[14], 8); ROUND(dd, aa, bb, cc, F4, K4, in[5], 6); ROUND(cc, dd, aa, bb, F4, K4, in[6], 5); ROUND(bb, cc, dd, aa, F4, K4, in[2], 12); /* round 4: right lane */ ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[8], 15); ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[6], 5); ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[4], 8); ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[1], 11); ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[3], 14); ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[11], 14); ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[15], 6); ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[0], 14); ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[5], 6); ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[12], 9); ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[2], 12); ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[13], 9); ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[9], 12); ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[7], 5); ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[10], 15); ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[14], 8); /* Swap contents of "d" registers */ tmp = dd; dd = ddd; ddd = tmp; /* combine results */ state[0] += aa; state[1] += bb; state[2] += cc; state[3] += dd; state[4] += aaa; state[5] += bbb; state[6] += ccc; state[7] += ddd; return; }
void mdvi_shrink_glyph(DviContext *dvi, DviFont *font, DviFontChar *pk, DviGlyph *dest) { int rows_left, rows, init_cols; int cols_left, cols; BmUnit *old_ptr, *new_ptr; BITMAP *oldmap, *newmap; BmUnit m, *cp; DviGlyph *glyph; int sample, min_sample; int old_stride; int new_stride; int x, y; int w, h; int hs, vs; hs = dvi->params.hshrink; vs = dvi->params.vshrink; min_sample = vs * hs * dvi->params.density / 100; glyph = &pk->glyph; oldmap = (BITMAP *)glyph->data; x = (int)glyph->x / hs; init_cols = (int)glyph->x - x * hs; if(init_cols <= 0) init_cols += hs; else x++; w = x + ROUND((int)glyph->w - glyph->x, hs); cols = (int)glyph->y + 1; y = cols / vs; rows = cols - y * vs; if(rows <= 0) { rows += vs; y--; } h = y + ROUND((int)glyph->h - cols, vs) + 1; /* create the new glyph */ newmap = bitmap_alloc(w, h); dest->data = newmap; dest->x = x; dest->y = glyph->y / vs; dest->w = w; dest->h = h; old_ptr = oldmap->data; old_stride = oldmap->stride; new_ptr = newmap->data; new_stride = newmap->stride; rows_left = glyph->h; while(rows_left) { if(rows > rows_left) rows = rows_left; cols_left = glyph->w; m = FIRSTMASK; cp = new_ptr; cols = init_cols; while(cols_left > 0) { if(cols > cols_left) cols = cols_left; sample = do_sample(old_ptr, old_stride, glyph->w - cols_left, cols, rows); if(sample >= min_sample) *cp |= m; if(m == LASTMASK) { m = FIRSTMASK; cp++; } else NEXTMASK(m); cols_left -= cols; cols = hs; } new_ptr = bm_offset(new_ptr, new_stride); old_ptr = bm_offset(old_ptr, rows * old_stride); rows_left -= rows; rows = vs; } DEBUG((DBG_BITMAPS, "shrink_glyph: (%dw,%dh,%dx,%dy) -> (%dw,%dh,%dx,%dy)\n", glyph->w, glyph->h, glyph->x, glyph->y, dest->w, dest->h, dest->x, dest->y)); if(DEBUGGING(BITMAP_DATA)) bitmap_print(stderr, newmap); }
BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout) { register int desired_align = 0; /* The following are used only if the field is a bitfield */ register const char *bfld_type = 0; register int bfld_type_align = 0, bfld_field_size = 0; /* The current type without the type qualifiers */ const char *type; BOOL unionp = layout->original_type[-1] == _C_UNION_B; /* Add the size of the previous field to the size of the record. */ if (layout->prev_type) { type = objc_skip_type_qualifiers (layout->prev_type); if (unionp) layout->record_size = MAX (layout->record_size, objc_sizeof_type (type) * BITS_PER_UNIT); else if (*type != _C_BFLD) layout->record_size += objc_sizeof_type (type) * BITS_PER_UNIT; else { /* Get the bitfield's type */ for (bfld_type = type + 1; isdigit ((unsigned char)*bfld_type); bfld_type++) /* do nothing */; bfld_type_align = objc_alignof_type (bfld_type) * BITS_PER_UNIT; bfld_field_size = atoi (objc_skip_typespec (bfld_type)); layout->record_size += bfld_field_size; } } if ((unionp && *layout->type == _C_UNION_E) || (!unionp && *layout->type == _C_STRUCT_E)) return NO; /* Skip the variable name if any */ layout->type = objc_skip_variable_name (layout->type); type = objc_skip_type_qualifiers (layout->type); if (*type != _C_BFLD) desired_align = objc_alignof_type (type) * BITS_PER_UNIT; else { desired_align = 1; /* Skip the bitfield's offset */ for (bfld_type = type + 1; isdigit ((unsigned char) *bfld_type); bfld_type++) /* do nothing */; bfld_type_align = objc_alignof_type (bfld_type) * BITS_PER_UNIT; bfld_field_size = atoi (objc_skip_typespec (bfld_type)); } /* The following won't work for vectors. */ #ifdef BIGGEST_FIELD_ALIGNMENT desired_align = MIN (desired_align, BIGGEST_FIELD_ALIGNMENT); #endif #ifdef ADJUST_FIELD_ALIGN desired_align = ADJUST_FIELD_ALIGN (type, desired_align); #endif /* Record must have at least as much alignment as any field. Otherwise, the alignment of the field within the record is meaningless. */ #ifndef PCC_BITFIELD_TYPE_MATTERS layout->record_align = MAX (layout->record_align, desired_align); #else /* PCC_BITFIELD_TYPE_MATTERS */ if (*type == _C_BFLD) { /* For these machines, a zero-length field does not affect the alignment of the structure as a whole. It does, however, affect the alignment of the next field within the structure. */ if (bfld_field_size) layout->record_align = MAX (layout->record_align, desired_align); else desired_align = objc_alignof_type (bfld_type) * BITS_PER_UNIT; /* A named bit field of declared type `int' forces the entire structure to have `int' alignment. Q1: How is encoded this thing and how to check for it? Q2: How to determine maximum_field_alignment at runtime? */ /* if (DECL_NAME (field) != 0) */ { int type_align = bfld_type_align; #if 0 if (maximum_field_alignment != 0) type_align = MIN (type_align, maximum_field_alignment); else if (DECL_PACKED (field)) type_align = MIN (type_align, BITS_PER_UNIT); #endif layout->record_align = MAX (layout->record_align, type_align); } } else layout->record_align = MAX (layout->record_align, desired_align); #endif /* PCC_BITFIELD_TYPE_MATTERS */ /* Does this field automatically have alignment it needs by virtue of the fields that precede it and the record's own alignment? */ if (*type == _C_BFLD) layout->record_size = atoi (type + 1); else if (layout->record_size % desired_align != 0) { /* No, we need to skip space before this field. Bump the cumulative size to multiple of field alignment. */ layout->record_size = ROUND (layout->record_size, desired_align); } /* Jump to the next field in record. */ layout->prev_type = layout->type; layout->type = objc_skip_typespec (layout->type); /* skip component */ return YES; }
void mdvi_shrink_glyph_grey(DviContext *dvi, DviFont *font, DviFontChar *pk, DviGlyph *dest) { int rows_left, rows; int cols_left, cols, init_cols; long sampleval, samplemax; BmUnit *old_ptr; void *image; int w, h; int x, y; DviGlyph *glyph; BITMAP *map; Ulong *pixels; int npixels; Ulong colortab[2]; int hs, vs; DviDevice *dev; hs = dvi->params.hshrink; vs = dvi->params.vshrink; dev = &dvi->device; glyph = &pk->glyph; map = (BITMAP *)glyph->data; x = (int)glyph->x / hs; init_cols = (int)glyph->x - x * hs; if(init_cols <= 0) init_cols += hs; else x++; w = x + ROUND((int)glyph->w - glyph->x, hs); cols = (int)glyph->y + 1; y = cols / vs; rows = cols - y * vs; if(rows <= 0) { rows += vs; y--; } h = y + ROUND((int)glyph->h - cols, vs) + 1; ASSERT(w && h); /* before touching anything, do this */ image = dev->create_image(dev->device_data, w, h, BITMAP_BITS); if(image == NULL) { mdvi_shrink_glyph(dvi, font, pk, dest); return; } /* save these colors */ pk->fg = MDVI_CURRFG(dvi); pk->bg = MDVI_CURRBG(dvi); samplemax = vs * hs; npixels = samplemax + 1; pixels = get_color_table(&dvi->device, npixels, pk->fg, pk->bg, dvi->params.gamma, dvi->params.density); if(pixels == NULL) { npixels = 2; colortab[0] = pk->fg; colortab[1] = pk->bg; pixels = &colortab[0]; } /* setup the new glyph */ dest->data = image; dest->x = x; dest->y = glyph->y / vs; dest->w = w; dest->h = h; y = 0; old_ptr = map->data; rows_left = glyph->h; while(rows_left && y < h) { x = 0; if(rows > rows_left) rows = rows_left; cols_left = glyph->w; cols = init_cols; while(cols_left && x < w) { if(cols > cols_left) cols = cols_left; sampleval = do_sample(old_ptr, map->stride, glyph->w - cols_left, cols, rows); /* scale the sample value by the number of grey levels */ if(npixels - 1 != samplemax) sampleval = ((npixels-1) * sampleval) / samplemax; ASSERT(sampleval < npixels); dev->put_pixel(image, x, y, pixels[sampleval]); cols_left -= cols; cols = hs; x++; } for(; x < w; x++) dev->put_pixel(image, x, y, pixels[0]); old_ptr = bm_offset(old_ptr, rows * map->stride); rows_left -= rows; rows = vs; y++; } for(; y < h; y++) { for(x = 0; x < w; x++) dev->put_pixel(image, x, y, pixels[0]); } dev->image_done(image); DEBUG((DBG_BITMAPS, "shrink_glyph_grey: (%dw,%dh,%dx,%dy) -> (%dw,%dh,%dx,%dy)\n", glyph->w, glyph->h, glyph->x, glyph->y, dest->w, dest->h, dest->x, dest->y)); }
void QmitkNumberPropertyEditor::setMaxValue(int value) { QSpinBox::setMaximum( ROUND( value * m_FactorPropertyToSpinbox ) ); }
void BlowfishPIMPL::Blowfish_decipher(uint32_t *xl, uint32_t *xr) { union aword Xl; union aword Xr; Xl.dword = *xl; Xr.dword = *xr; Xl.dword ^= PArray [17]; ROUND(Xr, Xl, 16); ROUND(Xl, Xr, 15); ROUND(Xr, Xl, 14); ROUND(Xl, Xr, 13); ROUND(Xr, Xl, 12); ROUND(Xl, Xr, 11); ROUND(Xr, Xl, 10); ROUND(Xl, Xr, 9); ROUND(Xr, Xl, 8); ROUND(Xl, Xr, 7); ROUND(Xr, Xl, 6); ROUND(Xl, Xr, 5); ROUND(Xr, Xl, 4); ROUND(Xl, Xr, 3); ROUND(Xr, Xl, 2); ROUND(Xl, Xr, 1); Xr.dword ^= PArray[0]; *xl = Xr.dword; *xr = Xl.dword; }
int QmitkNumberPropertyEditor::valueFromText(const QString& text) const { return ROUND( text.toDouble() / m_FactorSpinboxToDisplay ); }
/* modified lambda (mlambda) search (ref. [2]) -------------------------------*/ static int search(int n, int m, const double *L, const double *D, const double *zs, double *zn, double *s) { int i,j,k,c,nn=0,imax=0; double newdist,maxdist=1E99,y; double S[n*n]; double dist[n]; double zb[n]; double z[n]; double step[n]; memset(S, 0, sizeof(double)*n*n); k=n-1; dist[k]=0.0; zb[k]=zs[k]; z[k]=ROUND(zb[k]); y=zb[k]-z[k]; step[k]=SGN(y); for (c=0;c<LOOPMAX;c++) { newdist=dist[k]+y*y/D[k]; if (newdist<maxdist) { if (k!=0) { dist[--k]=newdist; for (i=0;i<=k;i++) S[k+i*n]=S[k+1+i*n]+(z[k+1]-zb[k+1])*L[k+1+i*n]; zb[k]=zs[k]+S[k+k*n]; z[k]=ROUND(zb[k]); y=zb[k]-z[k]; step[k]=SGN(y); } else { if (nn<m) { if (nn==0||newdist>s[imax]) imax=nn; for (i=0;i<n;i++) zn[i+nn*n]=z[i]; s[nn++]=newdist; } else { if (newdist<s[imax]) { for (i=0;i<n;i++) zn[i+imax*n]=z[i]; s[imax]=newdist; for (i=imax=0;i<m;i++) if (s[imax]<s[i]) imax=i; } maxdist=s[imax]; } z[0]+=step[0]; y=zb[0]-z[0]; step[0]=-step[0]-SGN(step[0]); } } else { if (k==n-1) break; else { k++; z[k]+=step[k]; y=zb[k]-z[k]; step[k]=-step[k]-SGN(step[k]); } } } for (i=0;i<m-1;i++) { /* sort by s */ for (j=i+1;j<m;j++) { if (s[i]<s[j]) continue; SWAP(s[i],s[j]); for (k=0;k<n;k++) SWAP(zn[k+i*n],zn[k+j*n]); } } if (c>=LOOPMAX) { log_error("LAMBDA search loop count overflow\n"); return -1; } return 0; }
HRESULT CDrawMenu::DoDraw(HDC hdcDest) { if (m_bButtonDisplayed) { USES_CONVERSION; RECT rect; rect.left = ROUND(m_rcPosition.left); rect.top = ROUND(m_rcPosition.top); rect.right = ROUND(m_rcPosition.right); rect.bottom = ROUND(m_rcPosition.bottom); // 画边框 if (m_enumButtonState == ButtonStateDown) { ::DrawEdge(hdcDest, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST); } else { if (m_bMouseOn || !ClientIsRunMode()) ::DrawEdge(hdcDest, &rect, BDR_RAISEDINNER, BF_RECT | BF_ADJUST); } COLORREF clrMenu = GetSysColor(COLOR_MENU); COLORREF clrMenuText = GetSysColor(COLOR_MENUTEXT); COLORREF clrOld = SetTextColor(hdcDest, clrMenuText); int iOldMode = SetBkMode(hdcDest, TRANSPARENT); if (m_fontMenu.m_hFont == NULL) GetSystemSettings(); CFontHandle fontOld = (HFONT)SelectObject(hdcDest, m_fontMenu); LPTSTR szCaption = W2T(m_bstrButtonCaption); int cbCaption = lstrlen(szCaption); CBrush brushBack; brushBack.CreateSolidBrush(clrMenu); ::FillRect(hdcDest, &rect, brushBack); ::DrawText(hdcDest, szCaption, cbCaption, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); SetTextColor(hdcDest, clrOld); SetBkMode(hdcDest, iOldMode); SelectObject(hdcDest, fontOld); } else { if (ClientIsRunMode()) return S_OK; int nLeft = ROUND(m_rcPosition.left); int nTop = ROUND(m_rcPosition.top); int nRight = ROUND(m_rcPosition.right); int nBottom = ROUND(m_rcPosition.bottom); HBRUSH hOldBrush = (HBRUSH)::SelectObject(hdcDest, (HBRUSH)GetStockObject(BLACK_BRUSH)); Rectangle(hdcDest, nLeft, nTop, nLeft + (nRight - nLeft) / 4, nBottom); RECT rect; rect.left = nLeft + (nRight - nLeft) / 4; rect.top = nTop; rect.right = nRight; rect.bottom = nBottom; ::SelectObject(hdcDest, (HBRUSH)GetStockObject(WHITE_BRUSH)); Rectangle(hdcDest, rect.left, nTop, nRight, nBottom); int iOldBkMode = SetBkMode(hdcDest, TRANSPARENT); HFONT hOldFont = (HFONT)::SelectObject(hdcDest, (HFONT)GetStockObject(DEFAULT_GUI_FONT)); DrawText(hdcDest, _T("菜单"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); SetBkMode(hdcDest, iOldBkMode); ::SelectObject(hdcDest, hOldBrush); ::SelectObject(hdcDest, hOldFont); } return S_OK; }
// the low level (private) decryption function void CBlowFish::Blowfish_decipher (DWORD *xl, DWORD *xr) { union aword Xl ; union aword Xr ; Xl.dword = *xl ; Xr.dword = *xr ; Xl.dword ^= PArray [17] ; ROUND (Xr, Xl, 16) ; ROUND (Xl, Xr, 15) ; ROUND (Xr, Xl, 14) ; ROUND (Xl, Xr, 13) ; ROUND (Xr, Xl, 12) ; ROUND (Xl, Xr, 11) ; ROUND (Xr, Xl, 10) ; ROUND (Xl, Xr, 9) ; ROUND (Xr, Xl, 8) ; ROUND (Xl, Xr, 7) ; ROUND (Xr, Xl, 6) ; ROUND (Xl, Xr, 5) ; ROUND (Xr, Xl, 4) ; ROUND (Xl, Xr, 3) ; ROUND (Xr, Xl, 2) ; ROUND (Xl, Xr, 1) ; Xr.dword ^= PArray[0]; *xl = Xr.dword; *xr = Xl.dword; }