idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
149,300 | private URL [ ] getClasspath ( JobInstance ji , JobRunnerCallback cb ) throws JqmPayloadException { switch ( ji . getJD ( ) . getPathType ( ) ) { case MAVEN : return mavenResolver . resolve ( ji ) ; case MEMORY : return new URL [ 0 ] ; case FS : default : return fsResolver . getLibraries ( ji . getNode ( ) , ji . getJD ( ) ) ; } } | Returns all the URL that should be inside the classpath . This includes the jar itself if any . | 104 | 20 |
149,301 | public static int forceCleanup ( Thread t ) { int i = 0 ; for ( Map . Entry < ConnectionPool , Set < ConnPair > > e : conns . entrySet ( ) ) { for ( ConnPair c : e . getValue ( ) ) { if ( c . thread . equals ( t ) ) { try { // This will in turn remove it from the static Map. c . conn . getHandler ( ) . invoke ( c . conn , Connection . class . getMethod ( "close" ) , null ) ; } catch ( Throwable e1 ) { e1 . printStackTrace ( ) ; } i ++ ; } } } return i ; } | Called by the engine to trigger the cleanup at the end of a payload thread . | 144 | 17 |
149,302 | public static GlobalParameter create ( DbConn cnx , String key , String value ) { QueryResult r = cnx . runUpdate ( "globalprm_insert" , key , value ) ; GlobalParameter res = new GlobalParameter ( ) ; res . id = r . getGeneratedId ( ) ; res . key = key ; res . value = value ; return res ; } | Create a new GP entry in the database . No commit performed . | 83 | 13 |
149,303 | public static String getParameter ( DbConn cnx , String key , String defaultValue ) { try { return cnx . runSelectSingle ( "globalprm_select_by_key" , 3 , String . class , key ) ; } catch ( NoResultException e ) { return defaultValue ; } } | Retrieve the value of a single - valued parameter . | 68 | 11 |
149,304 | static JndiContext createJndiContext ( ) throws NamingException { try { if ( ! NamingManager . hasInitialContextFactoryBuilder ( ) ) { JndiContext ctx = new JndiContext ( ) ; NamingManager . setInitialContextFactoryBuilder ( ctx ) ; return ctx ; } else { return ( JndiContext ) NamingManager . getInitialContext ( null ) ; } } catch ( Exception e ) { jqmlogger . error ( "Could not create JNDI context: " + e . getMessage ( ) ) ; NamingException ex = new NamingException ( "Could not initialize JNDI Context" ) ; ex . setRootCause ( e ) ; throw ex ; } } | Will create a JNDI Context and register it as the initial context factory builder | 159 | 16 |
149,305 | private static ClassLoader getParentCl ( ) { try { Method m = ClassLoader . class . getMethod ( "getPlatformClassLoader" ) ; return ( ClassLoader ) m . invoke ( null ) ; } catch ( NoSuchMethodException e ) { // Java < 9, just use the bootstrap CL. return null ; } catch ( Exception e ) { throw new JqmInitError ( "Could not fetch Platform Class Loader" , e ) ; } } | A helper - in Java 9 the extension CL was renamed to platform CL and hosts all the JDK classes . Before 9 it was useless and we used bootstrap CL instead . | 98 | 35 |
149,306 | public static Properties loadProperties ( String [ ] filesToLoad ) { Properties p = new Properties ( ) ; InputStream fis = null ; for ( String path : filesToLoad ) { try { fis = Db . class . getClassLoader ( ) . getResourceAsStream ( path ) ; if ( fis != null ) { p . load ( fis ) ; jqmlogger . info ( "A jqm.properties file was found at {}" , path ) ; } } catch ( IOException e ) { // We allow no configuration files, but not an unreadable configuration file. throw new DatabaseException ( "META-INF/jqm.properties file is invalid" , e ) ; } finally { closeQuietly ( fis ) ; } } // Overload the datasource name from environment variable if any (tests only). String dbName = System . getenv ( "DB" ) ; if ( dbName != null ) { p . put ( "com.enioka.jqm.jdbc.datasource" , "jdbc/" + dbName ) ; } // Done return p ; } | Helper method to load a property file from class path . | 246 | 11 |
149,307 | private void init ( boolean upgrade ) { initAdapter ( ) ; initQueries ( ) ; if ( upgrade ) { dbUpgrade ( ) ; } // First contact with the DB is version checking (if no connection opened by pool). // If DB is in wrong version or not available, just wait for it to be ready. boolean versionValid = false ; while ( ! versionValid ) { try { checkSchemaVersion ( ) ; versionValid = true ; } catch ( Exception e ) { String msg = e . getLocalizedMessage ( ) ; if ( e . getCause ( ) != null ) { msg += " - " + e . getCause ( ) . getLocalizedMessage ( ) ; } jqmlogger . error ( "Database not ready: " + msg + ". Waiting for database..." ) ; try { Thread . sleep ( 10000 ) ; } catch ( Exception e2 ) { } } } } | Main database initialization . To be called only when _ds is a valid DataSource . | 190 | 17 |
149,308 | private void dbUpgrade ( ) { DbConn cnx = this . getConn ( ) ; Map < String , Object > rs = null ; int db_schema_version = 0 ; try { rs = cnx . runSelectSingleRow ( "version_select_latest" ) ; db_schema_version = ( Integer ) rs . get ( "VERSION_D1" ) ; } catch ( Exception e ) { // Database is to be created, so version 0 is OK. } cnx . rollback ( ) ; if ( SCHEMA_VERSION > db_schema_version ) { jqmlogger . warn ( "Database is being upgraded from version {} to version {}" , db_schema_version , SCHEMA_VERSION ) ; // Upgrade scripts are named from_to.sql with 5 padding (e.g. 00000_00003.sql) // We try to find the fastest path (e.g. a direct 00000_00005.sql for creating a version 5 schema from nothing) // This is a simplistic and non-optimal algorithm as we try only a single path (no going back) int loop_from = db_schema_version ; int to = db_schema_version ; List < String > toApply = new ArrayList <> ( ) ; toApply . addAll ( adapter . preSchemaCreationScripts ( ) ) ; while ( to != SCHEMA_VERSION ) { boolean progressed = false ; for ( int loop_to = SCHEMA_VERSION ; loop_to > db_schema_version ; loop_to -- ) { String migrationFileName = String . format ( "/sql/%05d_%05d.sql" , loop_from , loop_to ) ; jqmlogger . debug ( "Trying migration script {}" , migrationFileName ) ; if ( Db . class . getResource ( migrationFileName ) != null ) { toApply . add ( migrationFileName ) ; to = loop_to ; loop_from = loop_to ; progressed = true ; break ; } } if ( ! progressed ) { break ; } } if ( to != SCHEMA_VERSION ) { throw new DatabaseException ( "There is no migration path from version " + db_schema_version + " to version " + SCHEMA_VERSION ) ; } for ( String s : toApply ) { jqmlogger . info ( "Running migration script {}" , s ) ; ScriptRunner . run ( cnx , s ) ; } cnx . commit ( ) ; // Yes, really. For advanced DB! cnx . close ( ) ; // HSQLDB does not refresh its schema without this. cnx = getConn ( ) ; cnx . runUpdate ( "version_insert" , SCHEMA_VERSION , SCHEMA_COMPATIBLE_VERSION ) ; cnx . commit ( ) ; jqmlogger . info ( "Database is now up to date" ) ; } else { jqmlogger . info ( "Database is already up to date" ) ; } cnx . close ( ) ; } | Updates the database . Never call this during normal operations upgrade is a user - controlled operation . | 673 | 19 |
149,309 | private void initAdapter ( ) { Connection tmp = null ; DatabaseMetaData meta = null ; try { tmp = _ds . getConnection ( ) ; meta = tmp . getMetaData ( ) ; product = meta . getDatabaseProductName ( ) . toLowerCase ( ) ; } catch ( SQLException e ) { throw new DatabaseException ( "Cannot connect to the database" , e ) ; } finally { try { if ( tmp != null ) { tmp . close ( ) ; } } catch ( SQLException e ) { // Nothing to do. } } DbAdapter newAdpt = null ; for ( String s : ADAPTERS ) { try { Class < ? extends DbAdapter > clazz = Db . class . getClassLoader ( ) . loadClass ( s ) . asSubclass ( DbAdapter . class ) ; newAdpt = clazz . newInstance ( ) ; if ( newAdpt . compatibleWith ( meta ) ) { adapter = newAdpt ; break ; } } catch ( Exception e ) { throw new DatabaseException ( "Issue when loading database adapter named: " + s , e ) ; } } if ( adapter == null ) { throw new DatabaseException ( "Unsupported database! There is no JQM database adapter compatible with product name " + product ) ; } else { jqmlogger . info ( "Using database adapter {}" , adapter . getClass ( ) . getCanonicalName ( ) ) ; } } | Creates the adapter for the target database . | 315 | 9 |
149,310 | public DbConn getConn ( ) { Connection cnx = null ; try { Thread . interrupted ( ) ; // this is VERY sad. Needed for Oracle driver which otherwise fails spectacularly. cnx = _ds . getConnection ( ) ; if ( cnx . getAutoCommit ( ) ) { cnx . setAutoCommit ( false ) ; cnx . rollback ( ) ; // To ensure no open transaction created by the pool before changing TX mode } if ( cnx . getTransactionIsolation ( ) != Connection . TRANSACTION_READ_COMMITTED ) { cnx . setTransactionIsolation ( Connection . TRANSACTION_READ_COMMITTED ) ; } return new DbConn ( this , cnx ) ; } catch ( SQLException e ) { DbHelper . closeQuietly ( cnx ) ; // May have been left open when the pool has given us a failed connection. throw new DatabaseException ( e ) ; } } | A connection to the database . Should be short - lived . No transaction active by default . | 215 | 18 |
149,311 | String getQuery ( String key ) { String res = this . adapter . getSqlText ( key ) ; if ( res == null ) { throw new DatabaseException ( "Query " + key + " does not exist" ) ; } return res ; } | Gets the interpolated text of a query from cache . If key does not exist an exception is thrown . | 53 | 22 |
149,312 | public RuntimeParameter addParameter ( String key , String value ) { RuntimeParameter jp = new RuntimeParameter ( ) ; jp . setJi ( this . getId ( ) ) ; jp . setKey ( key ) ; jp . setValue ( value ) ; return jp ; } | Helper method to add a parameter without having to create it explicitely . The created parameter should be persisted afterwards . | 62 | 23 |
149,313 | void endOfRunDb ( ) { DbConn cnx = null ; try { cnx = Helpers . getNewDbSession ( ) ; // Done: put inside history & remove instance from queue. History . create ( cnx , this . ji , this . resultStatus , endDate ) ; jqmlogger . trace ( "An History was just created for job instance " + this . ji . getId ( ) ) ; cnx . runUpdate ( "ji_delete_by_id" , this . ji . getId ( ) ) ; cnx . commit ( ) ; } catch ( RuntimeException e ) { endBlockDbFailureAnalysis ( e ) ; } finally { Helpers . closeQuietly ( cnx ) ; } } | Part of the endOfRun process that needs the database . May be deferred if the database is not available . | 168 | 22 |
149,314 | private Integer highlanderMode ( JobDef jd , DbConn cnx ) { if ( ! jd . isHighlander ( ) ) { return null ; } try { Integer existing = cnx . runSelectSingle ( "ji_select_existing_highlander" , Integer . class , jd . getId ( ) ) ; return existing ; } catch ( NoResultException ex ) { // Just continue, this means no existing waiting JI in queue. } // Now we need to actually synchronize through the database to avoid double posting // TODO: use a dedicated table, not the JobDef one. Will avoid locking the configuration. ResultSet rs = cnx . runSelect ( true , "jd_select_by_id" , jd . getId ( ) ) ; // Now we have a lock, just retry - some other client may have created a job instance recently. try { Integer existing = cnx . runSelectSingle ( "ji_select_existing_highlander" , Integer . class , jd . getId ( ) ) ; rs . close ( ) ; cnx . commit ( ) ; // Do not keep the lock! return existing ; } catch ( NoResultException ex ) { // Just continue, this means no existing waiting JI in queue. We keep the lock! } catch ( SQLException e ) { // Who cares. jqmlogger . warn ( "Issue when closing a ResultSet. Transaction or session leak is possible." , e ) ; } jqmlogger . trace ( "Highlander mode analysis is done: nor existing JO, must create a new one. Lock is hold." ) ; return null ; } | Helper . Current transaction is committed in some cases . | 358 | 10 |
149,315 | private String getStringPredicate ( String fieldName , List < String > filterValues , List < Object > prms ) { if ( filterValues != null && ! filterValues . isEmpty ( ) ) { String res = "" ; for ( String filterValue : filterValues ) { if ( filterValue == null ) { continue ; } if ( ! filterValue . isEmpty ( ) ) { prms . add ( filterValue ) ; if ( filterValue . contains ( "%" ) ) { res += String . format ( "(%s LIKE ?) OR " , fieldName ) ; } else { res += String . format ( "(%s = ?) OR " , fieldName ) ; } } else { res += String . format ( "(%s IS NULL OR %s = '') OR " , fieldName , fieldName ) ; } } if ( ! res . isEmpty ( ) ) { res = "AND (" + res . substring ( 0 , res . length ( ) - 4 ) + ") " ; return res ; } } return "" ; } | GetJob helper - String predicates are all created the same way so this factors some code . | 220 | 19 |
149,316 | public void prepare ( Properties p , Connection cnx ) { this . tablePrefix = p . getProperty ( "com.enioka.jqm.jdbc.tablePrefix" , "" ) ; queries . putAll ( DbImplBase . queries ) ; for ( Map . Entry < String , String > entry : DbImplBase . queries . entrySet ( ) ) { queries . put ( entry . getKey ( ) , this . adaptSql ( entry . getValue ( ) ) ) ; } } | Called after creating the first connection . The adapter should create its caches and do all initialization it requires . Most importantly the SQL query cache should be created . | 112 | 31 |
149,317 | @ Override public boolean accept ( File file ) { //All directories are added in the least that can be read by the Application if ( file . isDirectory ( ) && file . canRead ( ) ) { return true ; } else if ( properties . selection_type == DialogConfigs . DIR_SELECT ) { /* True for files, If the selection type is Directory type, ie. * Only directory has to be selected from the list, then all files are * ignored. */ return false ; } else { /* Check whether name of the file ends with the extension. Added if it * does. */ String name = file . getName ( ) . toLowerCase ( Locale . getDefault ( ) ) ; for ( String ext : validExtensions ) { if ( name . endsWith ( ext ) ) { return true ; } } } return false ; } | Function to filter files based on defined rules . | 180 | 9 |
149,318 | public void setSize ( int size ) { if ( size != MaterialProgressDrawable . LARGE && size != MaterialProgressDrawable . DEFAULT ) { return ; } final DisplayMetrics metrics = getResources ( ) . getDisplayMetrics ( ) ; if ( size == MaterialProgressDrawable . LARGE ) { mCircleHeight = mCircleWidth = ( int ) ( CIRCLE_DIAMETER_LARGE * metrics . density ) ; } else { mCircleHeight = mCircleWidth = ( int ) ( CIRCLE_DIAMETER * metrics . density ) ; } // force the bounds of the progress circle inside the circle view to // update by setting it to null before updating its size and then // re-setting it mCircleView . setImageDrawable ( null ) ; mProgress . updateSizes ( size ) ; mCircleView . setImageDrawable ( mProgress ) ; } | One of DEFAULT or LARGE . | 199 | 8 |
149,319 | public void setRefreshing ( boolean refreshing ) { if ( refreshing && mRefreshing != refreshing ) { // scale and show mRefreshing = refreshing ; int endTarget = 0 ; if ( ! mUsingCustomStart ) { switch ( mDirection ) { case BOTTOM : endTarget = getMeasuredHeight ( ) - ( int ) ( mSpinnerFinalOffset ) ; break ; case TOP : default : endTarget = ( int ) ( mSpinnerFinalOffset - Math . abs ( mOriginalOffsetTop ) ) ; break ; } } else { endTarget = ( int ) mSpinnerFinalOffset ; } setTargetOffsetTopAndBottom ( endTarget - mCurrentTargetOffsetTop , true /* requires update */ ) ; mNotify = false ; startScaleUpAnimation ( mRefreshListener ) ; } else { setRefreshing ( refreshing , false /* notify */ ) ; } } | Notify the widget that refresh state has changed . Do not call this when refresh is triggered by a swipe gesture . | 190 | 23 |
149,320 | private void setAnimationProgress ( float progress ) { if ( isAlphaUsedForScale ( ) ) { setColorViewAlpha ( ( int ) ( progress * MAX_ALPHA ) ) ; } else { ViewCompat . setScaleX ( mCircleView , progress ) ; ViewCompat . setScaleY ( mCircleView , progress ) ; } } | Pre API 11 this does an alpha animation . | 75 | 9 |
149,321 | public void setProgressBackgroundColor ( int colorRes ) { mCircleView . setBackgroundColor ( colorRes ) ; mProgress . setBackgroundColor ( getResources ( ) . getColor ( colorRes ) ) ; } | Set the background color of the progress spinner disc . | 46 | 11 |
149,322 | private void setRawDirection ( SwipyRefreshLayoutDirection direction ) { if ( mDirection == direction ) { return ; } mDirection = direction ; switch ( mDirection ) { case BOTTOM : mCurrentTargetOffsetTop = mOriginalOffsetTop = getMeasuredHeight ( ) ; break ; case TOP : default : mCurrentTargetOffsetTop = mOriginalOffsetTop = - mCircleView . getMeasuredHeight ( ) ; break ; } } | only TOP or Bottom | 101 | 4 |
149,323 | public static boolean uniform ( Color color , Pixel [ ] pixels ) { return Arrays . stream ( pixels ) . allMatch ( p -> p . toInt ( ) == color . toRGB ( ) . toInt ( ) ) ; } | Returns true if all pixels in the array have the same color | 49 | 12 |
149,324 | public static int scale ( Double factor , int pixel ) { return rgb ( ( int ) Math . round ( factor * red ( pixel ) ) , ( int ) Math . round ( factor * green ( pixel ) ) , ( int ) Math . round ( factor * blue ( pixel ) ) ) ; } | Scales the brightness of a pixel . | 62 | 8 |
149,325 | public void set ( String name , Object value ) { hashAttributes . put ( name , value ) ; if ( plugin != null ) { plugin . invalidate ( ) ; } } | Set an attribute . | 37 | 4 |
149,326 | public static int wavelengthToRGB ( float wavelength ) { float gamma = 0.80f ; float r , g , b , factor ; int w = ( int ) wavelength ; if ( w < 380 ) { r = 0.0f ; g = 0.0f ; b = 0.0f ; } else if ( w < 440 ) { r = - ( wavelength - 440 ) / ( 440 - 380 ) ; g = 0.0f ; b = 1.0f ; } else if ( w < 490 ) { r = 0.0f ; g = ( wavelength - 440 ) / ( 490 - 440 ) ; b = 1.0f ; } else if ( w < 510 ) { r = 0.0f ; g = 1.0f ; b = - ( wavelength - 510 ) / ( 510 - 490 ) ; } else if ( w < 580 ) { r = ( wavelength - 510 ) / ( 580 - 510 ) ; g = 1.0f ; b = 0.0f ; } else if ( w < 645 ) { r = 1.0f ; g = - ( wavelength - 645 ) / ( 645 - 580 ) ; b = 0.0f ; } else if ( w <= 780 ) { r = 1.0f ; g = 0.0f ; b = 0.0f ; } else { r = 0.0f ; g = 0.0f ; b = 0.0f ; } // Let the intensity fall off near the vision limits if ( 380 <= w && w <= 419 ) factor = 0.3f + 0.7f * ( wavelength - 380 ) / ( 420 - 380 ) ; else if ( 420 <= w && w <= 700 ) factor = 1.0f ; else if ( 701 <= w && w <= 780 ) factor = 0.3f + 0.7f * ( 780 - wavelength ) / ( 780 - 700 ) ; else factor = 0.0f ; int ir = adjust ( r , factor , gamma ) ; int ig = adjust ( g , factor , gamma ) ; int ib = adjust ( b , factor , gamma ) ; return 0xff000000 | ( ir << 16 ) | ( ig << 8 ) | ib ; } | Convert a wavelength to an RGB value . | 471 | 9 |
149,327 | public static void convolveHV ( Kernel kernel , int [ ] inPixels , int [ ] outPixels , int width , int height , boolean alpha , int edgeAction ) { int index = 0 ; float [ ] matrix = kernel . getKernelData ( null ) ; int rows = kernel . getHeight ( ) ; int cols = kernel . getWidth ( ) ; int rows2 = rows / 2 ; int cols2 = cols / 2 ; for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { float r = 0 , g = 0 , b = 0 , a = 0 ; for ( int row = - rows2 ; row <= rows2 ; row ++ ) { int iy = y + row ; int ioffset ; if ( 0 <= iy && iy < height ) ioffset = iy * width ; else if ( edgeAction == CLAMP_EDGES ) ioffset = y * width ; else if ( edgeAction == WRAP_EDGES ) ioffset = ( ( iy + height ) % height ) * width ; else continue ; int moffset = cols * ( row + rows2 ) + cols2 ; for ( int col = - cols2 ; col <= cols2 ; col ++ ) { float f = matrix [ moffset + col ] ; if ( f != 0 ) { int ix = x + col ; if ( ! ( 0 <= ix && ix < width ) ) { if ( edgeAction == CLAMP_EDGES ) ix = x ; else if ( edgeAction == WRAP_EDGES ) ix = ( x + width ) % width ; else continue ; } int rgb = inPixels [ ioffset + ix ] ; a += f * ( ( rgb >> 24 ) & 0xff ) ; r += f * ( ( rgb >> 16 ) & 0xff ) ; g += f * ( ( rgb >> 8 ) & 0xff ) ; b += f * ( rgb & 0xff ) ; } } } int ia = alpha ? PixelUtils . clamp ( ( int ) ( a + 0.5 ) ) : 0xff ; int ir = PixelUtils . clamp ( ( int ) ( r + 0.5 ) ) ; int ig = PixelUtils . clamp ( ( int ) ( g + 0.5 ) ) ; int ib = PixelUtils . clamp ( ( int ) ( b + 0.5 ) ) ; outPixels [ index ++ ] = ( ia << 24 ) | ( ir << 16 ) | ( ig << 8 ) | ib ; } } } | Convolve with a 2D kernel . | 568 | 9 |
149,328 | private void initPixelsArray ( BufferedImage image ) { int width = image . getWidth ( ) ; int height = image . getHeight ( ) ; pixels = new int [ width * height ] ; image . getRGB ( 0 , 0 , width , height , pixels , 0 , width ) ; } | takes the pixels from a BufferedImage and stores them in an array | 64 | 15 |
149,329 | private int [ ] changeColor ( ) { int [ ] changedPixels = new int [ pixels . length ] ; double frequenz = 2 * Math . PI / 1020 ; for ( int i = 0 ; i < pixels . length ; i ++ ) { int argb = pixels [ i ] ; int a = ( argb >> 24 ) & 0xff ; int r = ( argb >> 16 ) & 0xff ; int g = ( argb >> 8 ) & 0xff ; int b = argb & 0xff ; r = ( int ) ( 255 * Math . sin ( frequenz * r ) ) ; b = ( int ) ( - 255 * Math . cos ( frequenz * b ) + 255 ) ; changedPixels [ i ] = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b ; } return changedPixels ; } | changes the color of the image - more red and less blue | 186 | 12 |
149,330 | private static Set < String > imageOrientationsOf ( ImageMetadata metadata ) { String exifIFD0DirName = new ExifIFD0Directory ( ) . getName ( ) ; Tag [ ] tags = Arrays . stream ( metadata . getDirectories ( ) ) . filter ( dir -> dir . getName ( ) . equals ( exifIFD0DirName ) ) . findFirst ( ) . map ( Directory :: getTags ) . orElseGet ( ( ) -> new Tag [ 0 ] ) ; return Arrays . stream ( tags ) . filter ( tag -> tag . getType ( ) == 274 ) . map ( Tag :: getRawValue ) . collect ( Collectors . toSet ( ) ) ; } | returns the values of the orientation tag | 155 | 8 |
149,331 | public static float noise1 ( float x ) { int bx0 , bx1 ; float rx0 , rx1 , sx , t , u , v ; if ( start ) { start = false ; init ( ) ; } t = x + N ; bx0 = ( ( int ) t ) & BM ; bx1 = ( bx0 + 1 ) & BM ; rx0 = t - ( int ) t ; rx1 = rx0 - 1.0f ; sx = sCurve ( rx0 ) ; u = rx0 * g1 [ p [ bx0 ] ] ; v = rx1 * g1 [ p [ bx1 ] ] ; return 2.3f * lerp ( sx , u , v ) ; } | Compute 1 - dimensional Perlin noise . | 173 | 9 |
149,332 | public static float noise2 ( float x , float y ) { int bx0 , bx1 , by0 , by1 , b00 , b10 , b01 , b11 ; float rx0 , rx1 , ry0 , ry1 , q [ ] , sx , sy , a , b , t , u , v ; int i , j ; if ( start ) { start = false ; init ( ) ; } t = x + N ; bx0 = ( ( int ) t ) & BM ; bx1 = ( bx0 + 1 ) & BM ; rx0 = t - ( int ) t ; rx1 = rx0 - 1.0f ; t = y + N ; by0 = ( ( int ) t ) & BM ; by1 = ( by0 + 1 ) & BM ; ry0 = t - ( int ) t ; ry1 = ry0 - 1.0f ; i = p [ bx0 ] ; j = p [ bx1 ] ; b00 = p [ i + by0 ] ; b10 = p [ j + by0 ] ; b01 = p [ i + by1 ] ; b11 = p [ j + by1 ] ; sx = sCurve ( rx0 ) ; sy = sCurve ( ry0 ) ; q = g2 [ b00 ] ; u = rx0 * q [ 0 ] + ry0 * q [ 1 ] ; q = g2 [ b10 ] ; v = rx1 * q [ 0 ] + ry0 * q [ 1 ] ; a = lerp ( sx , u , v ) ; q = g2 [ b01 ] ; u = rx0 * q [ 0 ] + ry1 * q [ 1 ] ; q = g2 [ b11 ] ; v = rx1 * q [ 0 ] + ry1 * q [ 1 ] ; b = lerp ( sx , u , v ) ; return 1.5f * lerp ( sy , a , b ) ; } | Compute 2 - dimensional Perlin noise . | 453 | 9 |
149,333 | private List < Pair < Integer , Double > > integerPixelCoordinatesAndWeights ( double d , int numPixels ) { if ( d <= 0.5 ) return Collections . singletonList ( new Pair <> ( 0 , 1.0 ) ) ; else if ( d >= numPixels - 0.5 ) return Collections . singletonList ( new Pair <> ( numPixels - 1 , 1.0 ) ) ; else { double shifted = d - 0.5 ; double floor = Math . floor ( shifted ) ; double floorWeight = 1 - ( shifted - floor ) ; double ceil = Math . ceil ( shifted ) ; double ceilWeight = 1 - floorWeight ; assert ( floorWeight + ceilWeight == 1 ) ; return Arrays . asList ( new Pair <> ( ( int ) floor , floorWeight ) , new Pair <> ( ( int ) ceil , ceilWeight ) ) ; } } | Operates on one dimension at a time . | 200 | 9 |
149,334 | public static BufferedImage createImage ( ImageProducer producer ) { PixelGrabber pg = new PixelGrabber ( producer , 0 , 0 , - 1 , - 1 , null , 0 , 0 ) ; try { pg . grabPixels ( ) ; } catch ( InterruptedException e ) { throw new RuntimeException ( "Image fetch interrupted" ) ; } if ( ( pg . status ( ) & ImageObserver . ABORT ) != 0 ) throw new RuntimeException ( "Image fetch aborted" ) ; if ( ( pg . status ( ) & ImageObserver . ERROR ) != 0 ) throw new RuntimeException ( "Image fetch error" ) ; BufferedImage p = new BufferedImage ( pg . getWidth ( ) , pg . getHeight ( ) , BufferedImage . TYPE_INT_ARGB ) ; p . setRGB ( 0 , 0 , pg . getWidth ( ) , pg . getHeight ( ) , ( int [ ] ) pg . getPixels ( ) , 0 , pg . getWidth ( ) ) ; return p ; } | Cretae a BufferedImage from an ImageProducer . | 222 | 13 |
149,335 | public static BufferedImage convertImageToARGB ( Image image ) { if ( image instanceof BufferedImage && ( ( BufferedImage ) image ) . getType ( ) == BufferedImage . TYPE_INT_ARGB ) return ( BufferedImage ) image ; BufferedImage p = new BufferedImage ( image . getWidth ( null ) , image . getHeight ( null ) , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D g = p . createGraphics ( ) ; g . drawImage ( image , 0 , 0 , null ) ; g . dispose ( ) ; return p ; } | Convert an Image into a TYPE_INT_ARGB BufferedImage . If the image is already of this type the original image is returned unchanged . | 131 | 31 |
149,336 | public static BufferedImage cloneImage ( BufferedImage image ) { BufferedImage newImage = new BufferedImage ( image . getWidth ( ) , image . getHeight ( ) , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D g = newImage . createGraphics ( ) ; g . drawRenderedImage ( image , null ) ; g . dispose ( ) ; return newImage ; } | Clones a BufferedImage . | 87 | 7 |
149,337 | public static void paintCheckedBackground ( Component c , Graphics g , int x , int y , int width , int height ) { if ( backgroundImage == null ) { backgroundImage = new BufferedImage ( 64 , 64 , BufferedImage . TYPE_INT_ARGB ) ; Graphics bg = backgroundImage . createGraphics ( ) ; for ( int by = 0 ; by < 64 ; by += 8 ) { for ( int bx = 0 ; bx < 64 ; bx += 8 ) { bg . setColor ( ( ( bx ^ by ) & 8 ) != 0 ? Color . lightGray : Color . white ) ; bg . fillRect ( bx , by , 8 , 8 ) ; } } bg . dispose ( ) ; } if ( backgroundImage != null ) { Shape saveClip = g . getClip ( ) ; Rectangle r = g . getClipBounds ( ) ; if ( r == null ) r = new Rectangle ( c . getSize ( ) ) ; r = r . intersection ( new Rectangle ( x , y , width , height ) ) ; g . setClip ( r ) ; int w = backgroundImage . getWidth ( ) ; int h = backgroundImage . getHeight ( ) ; if ( w != - 1 && h != - 1 ) { int x1 = ( r . x / w ) * w ; int y1 = ( r . y / h ) * h ; int x2 = ( ( r . x + r . width + w - 1 ) / w ) * w ; int y2 = ( ( r . y + r . height + h - 1 ) / h ) * h ; for ( y = y1 ; y < y2 ; y += h ) for ( x = x1 ; x < x2 ; x += w ) g . drawImage ( backgroundImage , x , y , ) ; } g . setClip ( saveClip ) ; } } | Paint a check pattern used for a background to indicate image transparency . | 416 | 14 |
149,338 | public static Rectangle getSelectedBounds ( BufferedImage p ) { int width = p . getWidth ( ) ; int height = p . getHeight ( ) ; int maxX = 0 , maxY = 0 , minX = width , minY = height ; boolean anySelected = false ; int y1 ; int [ ] pixels = null ; for ( y1 = height - 1 ; y1 >= 0 ; y1 -- ) { pixels = getRGB ( p , 0 , y1 , width , 1 , pixels ) ; for ( int x = 0 ; x < minX ; x ++ ) { if ( ( pixels [ x ] & 0xff000000 ) != 0 ) { minX = x ; maxY = y1 ; anySelected = true ; break ; } } for ( int x = width - 1 ; x >= maxX ; x -- ) { if ( ( pixels [ x ] & 0xff000000 ) != 0 ) { maxX = x ; maxY = y1 ; anySelected = true ; break ; } } if ( anySelected ) break ; } pixels = null ; for ( int y = 0 ; y < y1 ; y ++ ) { pixels = getRGB ( p , 0 , y , width , 1 , pixels ) ; for ( int x = 0 ; x < minX ; x ++ ) { if ( ( pixels [ x ] & 0xff000000 ) != 0 ) { minX = x ; if ( y < minY ) minY = y ; anySelected = true ; break ; } } for ( int x = width - 1 ; x >= maxX ; x -- ) { if ( ( pixels [ x ] & 0xff000000 ) != 0 ) { maxX = x ; if ( y < minY ) minY = y ; anySelected = true ; break ; } } } if ( anySelected ) return new Rectangle ( minX , minY , maxX - minX + 1 , maxY - minY + 1 ) ; return null ; } | Calculates the bounds of the non - transparent parts of the given image . | 427 | 16 |
149,339 | public static void composeThroughMask ( Raster src , WritableRaster dst , Raster sel ) { int x = src . getMinX ( ) ; int y = src . getMinY ( ) ; int w = src . getWidth ( ) ; int h = src . getHeight ( ) ; int srcRGB [ ] = null ; int selRGB [ ] = null ; int dstRGB [ ] = null ; for ( int i = 0 ; i < h ; i ++ ) { srcRGB = src . getPixels ( x , y , w , 1 , srcRGB ) ; selRGB = sel . getPixels ( x , y , w , 1 , selRGB ) ; dstRGB = dst . getPixels ( x , y , w , 1 , dstRGB ) ; int k = x ; for ( int j = 0 ; j < w ; j ++ ) { int sr = srcRGB [ k ] ; int dir = dstRGB [ k ] ; int sg = srcRGB [ k + 1 ] ; int dig = dstRGB [ k + 1 ] ; int sb = srcRGB [ k + 2 ] ; int dib = dstRGB [ k + 2 ] ; int sa = srcRGB [ k + 3 ] ; int dia = dstRGB [ k + 3 ] ; float a = selRGB [ k + 3 ] / 255f ; float ac = 1 - a ; dstRGB [ k ] = ( int ) ( a * sr + ac * dir ) ; dstRGB [ k + 1 ] = ( int ) ( a * sg + ac * dig ) ; dstRGB [ k + 2 ] = ( int ) ( a * sb + ac * dib ) ; dstRGB [ k + 3 ] = ( int ) ( a * sa + ac * dia ) ; k += 4 ; } dst . setPixels ( x , y , w , 1 , dstRGB ) ; y ++ ; } } | Compose src onto dst using the alpha of sel to interpolate between the two . I can t think of a way to do this using AlphaComposite . | 415 | 34 |
149,340 | public void setMatrix ( int [ ] matrix ) { this . matrix = matrix ; sum = 0 ; for ( int i = 0 ; i < matrix . length ; i ++ ) sum += matrix [ i ] ; } | Set the dither matrix . | 45 | 6 |
149,341 | public static float gain ( float a , float b ) { /* float p = (float)Math.log(1.0 - b) / (float)Math.log(0.5); if (a < .001) return 0.0f; else if (a > .999) return 1.0f; if (a < 0.5) return (float)Math.pow(2 * a, p) / 2; else return 1.0f - (float)Math.pow(2 * (1. - a), p) / 2; */ float c = ( 1.0f / b - 2.0f ) * ( 1.0f - 2.0f * a ) ; if ( a < 0.5 ) return a / ( c + 1.0f ) ; else return ( c - a ) / ( c - 1.0f ) ; } | A variant of the gamma function . | 192 | 7 |
149,342 | public static float smoothPulse ( float a1 , float a2 , float b1 , float b2 , float x ) { if ( x < a1 || x >= b2 ) return 0 ; if ( x >= a2 ) { if ( x < b1 ) return 1.0f ; x = ( x - b1 ) / ( b2 - b1 ) ; return 1.0f - ( x * x * ( 3.0f - 2.0f * x ) ) ; } x = ( x - a1 ) / ( a2 - a1 ) ; return x * x * ( 3.0f - 2.0f * x ) ; } | A smoothed pulse function . A cubic function is used to smooth the step between two thresholds . | 144 | 19 |
149,343 | public static float smoothStep ( float a , float b , float x ) { if ( x < a ) return 0 ; if ( x >= b ) return 1 ; x = ( x - a ) / ( b - a ) ; return x * x * ( 3 - 2 * x ) ; } | A smoothed step function . A cubic function is used to smooth the step between two thresholds . | 62 | 19 |
149,344 | public static int mixColors ( float t , int rgb1 , int rgb2 ) { int a1 = ( rgb1 >> 24 ) & 0xff ; int r1 = ( rgb1 >> 16 ) & 0xff ; int g1 = ( rgb1 >> 8 ) & 0xff ; int b1 = rgb1 & 0xff ; int a2 = ( rgb2 >> 24 ) & 0xff ; int r2 = ( rgb2 >> 16 ) & 0xff ; int g2 = ( rgb2 >> 8 ) & 0xff ; int b2 = rgb2 & 0xff ; a1 = lerp ( t , a1 , a2 ) ; r1 = lerp ( t , r1 , r2 ) ; g1 = lerp ( t , g1 , g2 ) ; b1 = lerp ( t , b1 , b2 ) ; return ( a1 << 24 ) | ( r1 << 16 ) | ( g1 << 8 ) | b1 ; } | Linear interpolation of ARGB values . | 213 | 9 |
149,345 | public static int bilinearInterpolate ( float x , float y , int nw , int ne , int sw , int se ) { float m0 , m1 ; int a0 = ( nw >> 24 ) & 0xff ; int r0 = ( nw >> 16 ) & 0xff ; int g0 = ( nw >> 8 ) & 0xff ; int b0 = nw & 0xff ; int a1 = ( ne >> 24 ) & 0xff ; int r1 = ( ne >> 16 ) & 0xff ; int g1 = ( ne >> 8 ) & 0xff ; int b1 = ne & 0xff ; int a2 = ( sw >> 24 ) & 0xff ; int r2 = ( sw >> 16 ) & 0xff ; int g2 = ( sw >> 8 ) & 0xff ; int b2 = sw & 0xff ; int a3 = ( se >> 24 ) & 0xff ; int r3 = ( se >> 16 ) & 0xff ; int g3 = ( se >> 8 ) & 0xff ; int b3 = se & 0xff ; float cx = 1.0f - x ; float cy = 1.0f - y ; m0 = cx * a0 + x * a1 ; m1 = cx * a2 + x * a3 ; int a = ( int ) ( cy * m0 + y * m1 ) ; m0 = cx * r0 + x * r1 ; m1 = cx * r2 + x * r3 ; int r = ( int ) ( cy * m0 + y * m1 ) ; m0 = cx * g0 + x * g1 ; m1 = cx * g2 + x * g3 ; int g = ( int ) ( cy * m0 + y * m1 ) ; m0 = cx * b0 + x * b1 ; m1 = cx * b2 + x * b3 ; int b = ( int ) ( cy * m0 + y * m1 ) ; return ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b ; } | Bilinear interpolation of ARGB values . | 451 | 11 |
149,346 | public static int brightnessNTSC ( int rgb ) { int r = ( rgb >> 16 ) & 0xff ; int g = ( rgb >> 8 ) & 0xff ; int b = rgb & 0xff ; return ( int ) ( r * 0.299f + g * 0.587f + b * 0.114f ) ; } | Return the NTSC gray level of an RGB value . | 72 | 11 |
149,347 | public static int colorSpline ( int x , int numKnots , int [ ] xknots , int [ ] yknots ) { int span ; int numSpans = numKnots - 3 ; float k0 , k1 , k2 , k3 ; float c0 , c1 , c2 , c3 ; if ( numSpans < 1 ) throw new IllegalArgumentException ( "Too few knots in spline" ) ; for ( span = 0 ; span < numSpans ; span ++ ) if ( xknots [ span + 1 ] > x ) break ; if ( span > numKnots - 3 ) span = numKnots - 3 ; float t = ( float ) ( x - xknots [ span ] ) / ( xknots [ span + 1 ] - xknots [ span ] ) ; span -- ; if ( span < 0 ) { span = 0 ; t = 0 ; } int v = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { int shift = i * 8 ; k0 = ( yknots [ span ] >> shift ) & 0xff ; k1 = ( yknots [ span + 1 ] >> shift ) & 0xff ; k2 = ( yknots [ span + 2 ] >> shift ) & 0xff ; k3 = ( yknots [ span + 3 ] >> shift ) & 0xff ; c3 = m00 * k0 + m01 * k1 + m02 * k2 + m03 * k3 ; c2 = m10 * k0 + m11 * k1 + m12 * k2 + m13 * k3 ; c1 = m20 * k0 + m21 * k1 + m22 * k2 + m23 * k3 ; c0 = m30 * k0 + m31 * k1 + m32 * k2 + m33 * k3 ; int n = ( int ) ( ( ( c3 * t + c2 ) * t + c1 ) * t + c0 ) ; if ( n < 0 ) n = 0 ; else if ( n > 255 ) n = 255 ; v |= n << shift ; } return v ; } | Compute a Catmull - Rom spline for RGB values but with variable knot spacing . | 483 | 19 |
149,348 | public void copyTo ( Gradient g ) { g . numKnots = numKnots ; g . map = ( int [ ] ) map . clone ( ) ; g . xKnots = ( int [ ] ) xKnots . clone ( ) ; g . yKnots = ( int [ ] ) yKnots . clone ( ) ; g . knotTypes = ( byte [ ] ) knotTypes . clone ( ) ; } | Copy one Gradient into another . | 97 | 7 |
149,349 | public void setColor ( int n , int color ) { int firstColor = map [ 0 ] ; int lastColor = map [ 256 - 1 ] ; if ( n > 0 ) for ( int i = 0 ; i < n ; i ++ ) map [ i ] = ImageMath . mixColors ( ( float ) i / n , firstColor , color ) ; if ( n < 256 - 1 ) for ( int i = n ; i < 256 ; i ++ ) map [ i ] = ImageMath . mixColors ( ( float ) ( i - n ) / ( 256 - n ) , color , lastColor ) ; } | Set a knot color . | 133 | 5 |
149,350 | public void setKnotType ( int n , int type ) { knotTypes [ n ] = ( byte ) ( ( knotTypes [ n ] & ~ COLOR_MASK ) | type ) ; rebuildGradient ( ) ; } | Set a knot type . | 49 | 5 |
149,351 | public void setKnotBlend ( int n , int type ) { knotTypes [ n ] = ( byte ) ( ( knotTypes [ n ] & ~ BLEND_MASK ) | type ) ; rebuildGradient ( ) ; } | Set a knot blend type . | 50 | 6 |
149,352 | public void setKnots ( int [ ] x , int [ ] rgb , byte [ ] types ) { numKnots = rgb . length + 2 ; xKnots = new int [ numKnots ] ; yKnots = new int [ numKnots ] ; knotTypes = new byte [ numKnots ] ; if ( x != null ) System . arraycopy ( x , 0 , xKnots , 1 , numKnots - 2 ) ; else for ( int i = 1 ; i > numKnots - 1 ; i ++ ) xKnots [ i ] = 255 * i / ( numKnots - 2 ) ; System . arraycopy ( rgb , 0 , yKnots , 1 , numKnots - 2 ) ; if ( types != null ) System . arraycopy ( types , 0 , knotTypes , 1 , numKnots - 2 ) ; else for ( int i = 0 ; i > numKnots ; i ++ ) knotTypes [ i ] = RGB | SPLINE ; sortKnots ( ) ; rebuildGradient ( ) ; } | Set the values of all the knots . This version does not require the extra knots at - 1 and 256 | 240 | 21 |
149,353 | public void setKnots ( int [ ] x , int [ ] y , byte [ ] types , int offset , int count ) { numKnots = count ; xKnots = new int [ numKnots ] ; yKnots = new int [ numKnots ] ; knotTypes = new byte [ numKnots ] ; System . arraycopy ( x , offset , xKnots , 0 , numKnots ) ; System . arraycopy ( y , offset , yKnots , 0 , numKnots ) ; System . arraycopy ( types , offset , knotTypes , 0 , numKnots ) ; sortKnots ( ) ; rebuildGradient ( ) ; } | Set the values of a set of knots . | 154 | 9 |
149,354 | public void splitSpan ( int n ) { int x = ( xKnots [ n ] + xKnots [ n + 1 ] ) / 2 ; addKnot ( x , getColor ( x / 256.0f ) , knotTypes [ n ] ) ; rebuildGradient ( ) ; } | Split a span into two by adding a knot in the middle . | 66 | 13 |
149,355 | public int knotAt ( int x ) { for ( int i = 1 ; i < numKnots - 1 ; i ++ ) if ( xKnots [ i + 1 ] > x ) return i ; return 1 ; } | Return the knot at a given position . | 49 | 8 |
149,356 | public void randomize ( ) { numKnots = 4 + ( int ) ( 6 * Math . random ( ) ) ; xKnots = new int [ numKnots ] ; yKnots = new int [ numKnots ] ; knotTypes = new byte [ numKnots ] ; for ( int i = 0 ; i < numKnots ; i ++ ) { xKnots [ i ] = ( int ) ( 255 * Math . random ( ) ) ; yKnots [ i ] = 0xff000000 | ( ( int ) ( 255 * Math . random ( ) ) << 16 ) | ( ( int ) ( 255 * Math . random ( ) ) << 8 ) | ( int ) ( 255 * Math . random ( ) ) ; knotTypes [ i ] = RGB | SPLINE ; } xKnots [ 0 ] = - 1 ; xKnots [ 1 ] = 0 ; xKnots [ numKnots - 2 ] = 255 ; xKnots [ numKnots - 1 ] = 256 ; sortKnots ( ) ; rebuildGradient ( ) ; } | Randomize the gradient . | 242 | 5 |
149,357 | public void mutate ( float amount ) { for ( int i = 0 ; i < numKnots ; i ++ ) { int rgb = yKnots [ i ] ; int r = ( ( rgb >> 16 ) & 0xff ) ; int g = ( ( rgb >> 8 ) & 0xff ) ; int b = ( rgb & 0xff ) ; r = PixelUtils . clamp ( ( int ) ( r + amount * 255 * ( Math . random ( ) - 0.5 ) ) ) ; g = PixelUtils . clamp ( ( int ) ( g + amount * 255 * ( Math . random ( ) - 0.5 ) ) ) ; b = PixelUtils . clamp ( ( int ) ( b + amount * 255 * ( Math . random ( ) - 0.5 ) ) ) ; yKnots [ i ] = 0xff000000 | ( r << 16 ) | ( g << 8 ) | b ; knotTypes [ i ] = RGB | SPLINE ; } sortKnots ( ) ; rebuildGradient ( ) ; } | Mutate the gradient . | 224 | 5 |
149,358 | public void setBufferedImage ( BufferedImage img ) { image = img ; width = img . getWidth ( ) ; height = img . getHeight ( ) ; updateColorArray ( ) ; } | Sets a new image | 42 | 5 |
149,359 | public BufferedImage getNewImageInstance ( ) { BufferedImage buf = new BufferedImage ( image . getWidth ( ) , image . getHeight ( ) , image . getType ( ) ) ; buf . setData ( image . getData ( ) ) ; return buf ; } | Return a new instance of the BufferedImage | 60 | 9 |
149,360 | public BufferedImage getBufferedImage ( int width , int height ) { // using the new approach of Java 2D API BufferedImage buf = new BufferedImage ( width , height , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D g2d = ( Graphics2D ) buf . getGraphics ( ) ; g2d . setRenderingHint ( RenderingHints . KEY_INTERPOLATION , RenderingHints . VALUE_INTERPOLATION_BILINEAR ) ; g2d . drawImage ( image , 0 , 0 , width , height , null ) ; g2d . dispose ( ) ; return ( buf ) ; } | Resize and return the image passing the new height and width | 144 | 12 |
149,361 | public void resize ( int w , int h ) { // using the new approach of Java 2D API BufferedImage buf = new BufferedImage ( w , h , image . getType ( ) ) ; Graphics2D g2d = ( Graphics2D ) buf . getGraphics ( ) ; g2d . setRenderingHint ( RenderingHints . KEY_INTERPOLATION , RenderingHints . VALUE_INTERPOLATION_BILINEAR ) ; g2d . drawImage ( image , 0 , 0 , w , h , null ) ; g2d . dispose ( ) ; image = buf ; width = w ; height = h ; updateColorArray ( ) ; } | Resize the image passing the new height and width | 148 | 10 |
149,362 | public double multi8p ( int x , int y , double masc ) { int aR = getIntComponent0 ( x - 1 , y - 1 ) ; int bR = getIntComponent0 ( x - 1 , y ) ; int cR = getIntComponent0 ( x - 1 , y + 1 ) ; int aG = getIntComponent1 ( x - 1 , y - 1 ) ; int bG = getIntComponent1 ( x - 1 , y ) ; int cG = getIntComponent1 ( x - 1 , y + 1 ) ; int aB = getIntComponent1 ( x - 1 , y - 1 ) ; int bB = getIntComponent1 ( x - 1 , y ) ; int cB = getIntComponent1 ( x - 1 , y + 1 ) ; int dR = getIntComponent0 ( x , y - 1 ) ; int eR = getIntComponent0 ( x , y ) ; int fR = getIntComponent0 ( x , y + 1 ) ; int dG = getIntComponent1 ( x , y - 1 ) ; int eG = getIntComponent1 ( x , y ) ; int fG = getIntComponent1 ( x , y + 1 ) ; int dB = getIntComponent1 ( x , y - 1 ) ; int eB = getIntComponent1 ( x , y ) ; int fB = getIntComponent1 ( x , y + 1 ) ; int gR = getIntComponent0 ( x + 1 , y - 1 ) ; int hR = getIntComponent0 ( x + 1 , y ) ; int iR = getIntComponent0 ( x + 1 , y + 1 ) ; int gG = getIntComponent1 ( x + 1 , y - 1 ) ; int hG = getIntComponent1 ( x + 1 , y ) ; int iG = getIntComponent1 ( x + 1 , y + 1 ) ; int gB = getIntComponent1 ( x + 1 , y - 1 ) ; int hB = getIntComponent1 ( x + 1 , y ) ; int iB = getIntComponent1 ( x + 1 , y + 1 ) ; double rgb = 0 ; rgb = ( ( aR * masc ) + ( bR * masc ) + ( cR * masc ) + ( dR * masc ) + ( eR * masc ) + ( fR * masc ) + ( gR * masc ) + ( hR * masc ) + ( iR * masc ) ) ; return ( rgb ) ; } | Multiple of gradient windwos per masc relation of x y | 543 | 12 |
149,363 | public void fillRect ( int x , int y , int w , int h , Color c ) { int color = c . getRGB ( ) ; for ( int i = x ; i < x + w ; i ++ ) { for ( int j = y ; j < y + h ; j ++ ) { setIntColor ( i , j , color ) ; } } } | Fills a rectangle in the image . | 79 | 8 |
149,364 | public void prepareFilter ( float transition ) { try { method . invoke ( filter , new Object [ ] { new Float ( transition ) } ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Error setting value for property: " + property ) ; } } | Prepare the filter for the transiton at a given time . The default implementation sets the given filter property but you could override this method to make other changes . | 58 | 32 |
149,365 | public static MarvinImage rgbToBinary ( MarvinImage img , int threshold ) { MarvinImage resultImage = new MarvinImage ( img . getWidth ( ) , img . getHeight ( ) , MarvinImage . COLOR_MODEL_BINARY ) ; for ( int y = 0 ; y < img . getHeight ( ) ; y ++ ) { for ( int x = 0 ; x < img . getWidth ( ) ; x ++ ) { int gray = ( int ) ( ( img . getIntComponent0 ( x , y ) * 0.3 ) + ( img . getIntComponent1 ( x , y ) * 0.59 ) + ( img . getIntComponent2 ( x , y ) * 0.11 ) ) ; if ( gray <= threshold ) { resultImage . setBinaryColor ( x , y , true ) ; } else { resultImage . setBinaryColor ( x , y , false ) ; } } } return resultImage ; } | Converts an image in RGB mode to BINARY mode | 204 | 12 |
149,366 | public static MarvinImage binaryToRgb ( MarvinImage img ) { MarvinImage resultImage = new MarvinImage ( img . getWidth ( ) , img . getHeight ( ) , MarvinImage . COLOR_MODEL_RGB ) ; for ( int y = 0 ; y < img . getHeight ( ) ; y ++ ) { for ( int x = 0 ; x < img . getWidth ( ) ; x ++ ) { if ( img . getBinaryColor ( x , y ) ) { resultImage . setIntColor ( x , y , 0 , 0 , 0 ) ; } else { resultImage . setIntColor ( x , y , 255 , 255 , 255 ) ; } } } return resultImage ; } | Converts an image in BINARY mode to RGB mode | 151 | 12 |
149,367 | public static int [ ] binaryToRgb ( boolean [ ] binaryArray ) { int [ ] rgbArray = new int [ binaryArray . length ] ; for ( int i = 0 ; i < binaryArray . length ; i ++ ) { if ( binaryArray [ i ] ) { rgbArray [ i ] = 0x00000000 ; } else { rgbArray [ i ] = 0x00FFFFFF ; } } return rgbArray ; } | Converts a boolean array containing the pixel data in BINARY mode to an integer array with the pixel data in RGB mode . | 91 | 26 |
149,368 | public void setAngle ( float angle ) { this . angle = angle ; float cos = ( float ) Math . cos ( angle ) ; float sin = ( float ) Math . sin ( angle ) ; m00 = cos ; m01 = sin ; m10 = - sin ; m11 = cos ; } | Specifies the angle of the effect . | 64 | 8 |
149,369 | public static int scanright ( Color color , int height , int width , int col , PixelsExtractor f , int tolerance ) { if ( col == width || ! PixelTools . colorMatches ( color , tolerance , f . apply ( new Area ( col , 0 , 1 , height ) ) ) ) return col ; else return scanright ( color , height , width , col + 1 , f , tolerance ) ; } | Starting with the given column index will return the first column index which contains a colour that does not match the given color . | 88 | 24 |
149,370 | public void clear ( ) { if ( arrMask != null ) { for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { arrMask [ x ] [ y ] = false ; } } } } | Clear the mask for a new selection | 59 | 7 |
149,371 | public Pixel [ ] pixels ( ) { Pixel [ ] pixels = new Pixel [ count ( ) ] ; Point [ ] points = points ( ) ; for ( int k = 0 ; k < points . length ; k ++ ) { pixels [ k ] = pixel ( points [ k ] ) ; } return pixels ; } | Returns all the pixels for the image | 65 | 7 |
149,372 | public boolean forall ( PixelPredicate predicate ) { return Arrays . stream ( points ( ) ) . allMatch ( p -> predicate . test ( p . x , p . y , pixel ( p ) ) ) ; } | Returns true if the predicate is true for all pixels in the image . | 47 | 14 |
149,373 | public void foreach ( PixelFunction fn ) { Arrays . stream ( points ( ) ) . forEach ( p -> fn . apply ( p . x , p . y , pixel ( p ) ) ) ; } | Executes the given side effecting function on each pixel . | 45 | 12 |
149,374 | public boolean contains ( Color color ) { return exists ( p -> p . toInt ( ) == color . toPixel ( ) . toInt ( ) ) ; } | Returns true if a pixel with the given color exists | 34 | 10 |
149,375 | public int [ ] argb ( int x , int y ) { Pixel p = pixel ( x , y ) ; return new int [ ] { p . alpha ( ) , p . red ( ) , p . green ( ) , p . blue ( ) } ; } | Returns the ARGB components for the pixel at the given coordinates | 56 | 12 |
149,376 | public int [ ] [ ] argb ( ) { return Arrays . stream ( points ( ) ) . map ( p -> argb ( p . x , p . y ) ) . toArray ( int [ ] [ ] :: new ) ; } | Returns the ARGB components for all pixels in this image | 52 | 11 |
149,377 | public Set < RGBColor > colours ( ) { return stream ( ) . map ( Pixel :: toColor ) . collect ( Collectors . toSet ( ) ) ; } | Returns a set of the distinct colours used in this image . | 36 | 12 |
149,378 | public BufferedImage toNewBufferedImage ( int type ) { BufferedImage target = new BufferedImage ( width , height , type ) ; Graphics2D g2 = ( Graphics2D ) target . getGraphics ( ) ; g2 . drawImage ( awt , 0 , 0 , null ) ; g2 . dispose ( ) ; return target ; } | Returns a new AWT BufferedImage from this image . | 76 | 12 |
149,379 | public static Dimension dimensionsToFit ( Dimension target , Dimension source ) { // if target width/height is zero then we have no preference for that, so set it to the original value, // since it cannot be any larger int maxWidth ; if ( target . getX ( ) == 0 ) { maxWidth = source . getX ( ) ; } else { maxWidth = target . getX ( ) ; } int maxHeight ; if ( target . getY ( ) == 0 ) { maxHeight = source . getY ( ) ; } else { maxHeight = target . getY ( ) ; } double wscale = maxWidth / ( double ) source . getX ( ) ; double hscale = maxHeight / ( double ) source . getY ( ) ; if ( wscale < hscale ) return new Dimension ( ( int ) ( source . getX ( ) * wscale ) , ( int ) ( source . getY ( ) * wscale ) ) ; else return new Dimension ( ( int ) ( source . getX ( ) * hscale ) , ( int ) ( source . getY ( ) * hscale ) ) ; } | Returns width and height that allow the given source width height to fit inside the target width height without losing aspect ratio | 239 | 22 |
149,380 | public void setGamma ( float rGamma , float gGamma , float bGamma ) { this . rGamma = rGamma ; this . gGamma = gGamma ; this . bGamma = bGamma ; initialized = false ; } | Set the gamma levels . | 57 | 5 |
149,381 | public void setColorInterpolated ( int index , int firstIndex , int lastIndex , int color ) { int firstColor = map [ firstIndex ] ; int lastColor = map [ lastIndex ] ; for ( int i = firstIndex ; i <= index ; i ++ ) map [ i ] = ImageMath . mixColors ( ( float ) ( i - firstIndex ) / ( index - firstIndex ) , firstColor , color ) ; for ( int i = index ; i < lastIndex ; i ++ ) map [ i ] = ImageMath . mixColors ( ( float ) ( i - index ) / ( lastIndex - index ) , color , lastColor ) ; } | Set the color at index to color . Entries are interpolated linearly from the existing entries at firstIndex and lastIndex to the new entry . firstIndex < index < lastIndex must hold . | 143 | 40 |
149,382 | public void setColorRange ( int firstIndex , int lastIndex , int color1 , int color2 ) { for ( int i = firstIndex ; i <= lastIndex ; i ++ ) map [ i ] = ImageMath . mixColors ( ( float ) ( i - firstIndex ) / ( lastIndex - firstIndex ) , color1 , color2 ) ; } | Set a range of the colormap interpolating between two colors . | 77 | 14 |
149,383 | public void setColorRange ( int firstIndex , int lastIndex , int color ) { for ( int i = firstIndex ; i <= lastIndex ; i ++ ) map [ i ] = color ; } | Set a range of the colormap to a single color . | 42 | 13 |
149,384 | public void buttonClick ( View v ) { switch ( v . getId ( ) ) { case R . id . show : showAppMsg ( ) ; break ; case R . id . cancel_all : AppMsg . cancelAll ( this ) ; break ; default : return ; } } | Button onClick listener . | 60 | 5 |
149,385 | public LayoutParams getLayoutParams ( ) { if ( mLayoutParams == null ) { mLayoutParams = new LayoutParams ( LayoutParams . MATCH_PARENT , LayoutParams . WRAP_CONTENT ) ; } return mLayoutParams ; } | Gets the crouton s layout parameters constructing a default if necessary . | 60 | 15 |
149,386 | public AppMsg setLayoutGravity ( int gravity ) { mLayoutParams = new FrameLayout . LayoutParams ( LayoutParams . MATCH_PARENT , LayoutParams . WRAP_CONTENT , gravity ) ; return this ; } | Constructs and sets the layout parameters to have some gravity . | 52 | 12 |
149,387 | public static int getPercentage ( String percentage ) { if ( isNotEmpty ( percentage ) && isNumeric ( percentage ) ) { int p = Integer . parseInt ( percentage ) ; return p ; } else { return 0 ; } } | Takes a numeric string value and converts it to a integer between 0 and 100 . | 50 | 17 |
149,388 | public App named ( String name ) { App newApp = copy ( ) ; newApp . name = name ; return newApp ; } | Builder method for specifying the name of an app . | 28 | 10 |
149,389 | public App on ( Heroku . Stack stack ) { App newApp = copy ( ) ; newApp . stack = new App . Stack ( stack ) ; return newApp ; } | Builder method for specifying the stack an app should be created on . | 37 | 13 |
149,390 | public Range < App > listApps ( String range ) { return connection . execute ( new AppList ( range ) , apiKey ) ; } | List all apps for the current user s account . | 29 | 10 |
149,391 | public String renameApp ( String appName , String newName ) { return connection . execute ( new AppRename ( appName , newName ) , apiKey ) . getName ( ) ; } | Rename an existing app . | 41 | 6 |
149,392 | public AddonChange addAddon ( String appName , String addonName ) { return connection . execute ( new AddonInstall ( appName , addonName ) , apiKey ) ; } | Add an addon to the app . | 39 | 7 |
149,393 | public List < Addon > listAppAddons ( String appName ) { return connection . execute ( new AppAddonsList ( appName ) , apiKey ) ; } | List the addons already added to an app . | 36 | 10 |
149,394 | public AddonChange removeAddon ( String appName , String addonName ) { return connection . execute ( new AddonRemove ( appName , addonName ) , apiKey ) ; } | Remove an addon from an app . | 39 | 7 |
149,395 | public List < Release > listReleases ( String appName ) { return connection . execute ( new ReleaseList ( appName ) , apiKey ) ; } | List of releases for an app . | 32 | 7 |
149,396 | public Release rollback ( String appName , String releaseUuid ) { return connection . execute ( new Rollback ( appName , releaseUuid ) , apiKey ) ; } | Rollback an app to a specific release . | 37 | 9 |
149,397 | public Release getReleaseInfo ( String appName , String releaseName ) { return connection . execute ( new ReleaseInfo ( appName , releaseName ) , apiKey ) ; } | Information about a specific release . | 36 | 6 |
149,398 | public List < Collaborator > listCollaborators ( String appName ) { return connection . execute ( new CollabList ( appName ) , apiKey ) ; } | Get a list of collaborators that are allowed access to an app . | 35 | 13 |
149,399 | public void addCollaborator ( String appName , String collaborator ) { connection . execute ( new SharingAdd ( appName , collaborator ) , apiKey ) ; } | Add a collaborator to an app . | 34 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.