Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

crop_image.c

Go to the documentation of this file.
00001 #include <volume_io/internal_volume_io.h> 00002 #include <bicpl/objects.h> 00003 #include <bicpl/images.h> 00004 00005 private BOOLEAN is_clear_slab( 00006 pixels_struct *pixels, 00007 Colour bg_colour, 00008 int x_min, 00009 int y_min, 00010 int x_max, 00011 int y_max ) 00012 { 00013 int x, y; 00014 00015 for_inclusive( x, x_min, x_max ) 00016 { 00017 for_inclusive( y, y_min, y_max ) 00018 { 00019 if( PIXEL_RGB_COLOUR(*pixels,x,y) != bg_colour ) 00020 return( FALSE ); 00021 } 00022 } 00023 00024 return( TRUE ); 00025 } 00026 00027 public void crop_pixels( 00028 pixels_struct *in_pixels, 00029 Colour background_colour, 00030 int border, 00031 pixels_struct *out_pixels ) 00032 { 00033 int x, y; 00034 int x_min, x_max, y_min, y_max; 00035 00036 if( in_pixels->pixel_type != RGB_PIXEL ) 00037 { 00038 print_error( "cannot crop non-rgb pixels.\n" ); 00039 return; 00040 } 00041 00042 x_min = 0; 00043 while( x_min < in_pixels->x_size && 00044 is_clear_slab( in_pixels, background_colour, 00045 x_min, 0, x_min, in_pixels->y_size-1 ) ) 00046 ++x_min; 00047 00048 x_max = in_pixels->x_size-1; 00049 while( x_max >= 0 && 00050 is_clear_slab( in_pixels, background_colour, 00051 x_max, 0, x_max, in_pixels->y_size-1 ) ) 00052 --x_max; 00053 00054 y_min = 0; 00055 while( y_min < in_pixels->y_size && 00056 is_clear_slab( in_pixels, background_colour, 00057 0, y_min, in_pixels->x_size-1, y_min ) ) 00058 ++y_min; 00059 00060 y_max = in_pixels->y_size-1; 00061 while( y_max >= 0 && 00062 is_clear_slab( in_pixels, background_colour, 00063 0, y_max, in_pixels->x_size-1, y_max ) ) 00064 --y_max; 00065 00066 x_max = MIN( in_pixels->x_size-1, x_max + border ); 00067 x_min = MAX( 0, x_min - border ); 00068 y_max = MIN( in_pixels->y_size-1, y_max + border ); 00069 y_min = MAX( 0, y_min - border ); 00070 00071 if( x_max < x_min ) 00072 x_max = x_min; 00073 if( y_max < y_min ) 00074 y_max = y_min; 00075 00076 initialize_pixels( out_pixels, in_pixels->x_position + x_min, 00077 in_pixels->y_position + y_min, 00078 x_max - x_min + 1, y_max - y_min + 1, 00079 in_pixels->x_zoom, in_pixels->y_zoom, 00080 RGB_PIXEL ); 00081 00082 for_inclusive( x, x_min, x_max ) 00083 { 00084 for_inclusive( y, y_min, y_max ) 00085 { 00086 PIXEL_RGB_COLOUR(*out_pixels,x-x_min,y-y_min) = 00087 PIXEL_RGB_COLOUR(*in_pixels,x,y); 00088 } 00089 } 00090 }

Generated on Wed Jul 28 09:10:57 2004 for BICPL by doxygen 1.3.7