Writing Images FILE* F = fopen( "myImage.raw", "w" ); // on Macs, use "../../../myImage.raw" if ( F == NULL ) { printf("couldn't open file to write\n"); exit(0); } fwrite( myImage, width*height, 1, F ); fclose( F );
Reading Images FILE* F = fopen( "myImage.raw", "r" ); // on Macs, use "../../../myImage.raw" if ( F == NULL ) { printf("couldn't open file to read\n"); exit(0);
} fread( myImage, width*height, 1, F ); fclose( F );
Warning: Only set pixels within your image bounds if ( x < 0 || x >- imageWidth || y < 0 || y >= imageHeight ) continue; // continue to next loop of for loop
Efficient brush application for( int y=mouseY-rad; y<=mouseY+rad; y++ ) // limiting for loop to brush region { for( int x=mouseX-rad; x<=mouseX+rad; x++ ) { // blending code (to blend brush paint with existing pixels int existingPixel = myImage[ index ]; int newPixel = the brush color; float p = computed using brush falloff function;
// linear interpolation (LERP) between old and new pixel values myImage[ index ] = newPixel*(1.0-p) + existingPixel*p; } }
|
|