| 117 | |
| 118 | |
| 119 | class ImageToStruct(object): |
| 120 | |
| 121 | def __init__(self, filename): |
| 122 | self.max_height = 32 |
| 123 | self.max_width = 128 |
| 124 | self.x_offset = 0 |
| 125 | self.y_offset = 0 |
| 126 | self.filename = filename |
| 127 | self.output_image = STLcdGraphic( self.max_height, self.max_width ) |
| 128 | self.disp_test = self.prep() |
| 129 | |
| 130 | def create_and_convert_image(self): |
| 131 | # Load the input filename and convert to black & white |
| 132 | try: |
| 133 | input_image = Image.open( self.filename ).convert('1') |
| 134 | except Exception: |
| 135 | raise StandardError( "Unable to load image '{0}'".format( self.filename ) ) |
| 136 | return input_image |
| 137 | |
| 138 | def check_boundries(self, input_image): |
| 139 | # Check the image size to see if within the bounds of the display |
| 140 | if input_image.size[0] > self.max_width or input_image.size[1] > self.max_height: |
| 141 | raise StandardError( "ERROR: '{0}:{1}' is too large, must be no larger than {2}x{3}".format( |
| 142 | filename, |
| 143 | ( input_image.format, input_image.size, input_image.mode ), |
| 144 | self.max_width, |
| 145 | self.max_height ) |
| 146 | ) |
| 147 | |
| 148 | def center_image(self, input_image): |
| 149 | # Center the image |
| 150 | height_start = int( ( self.max_height - input_image.size[1] ) / 2 ) |
| 151 | height_end = int( height_start + input_image.size[1] ) |
| 152 | width_start = int( ( self.max_width - input_image.size[0] ) / 2 ) |
| 153 | width_end = int( width_start + input_image.size[0] ) |
| 154 | return height_start, height_end, width_start, width_end |
| 155 | |
| 156 | def prepare_view(self, input_image, height_start, height_end, width_start, width_end): |
| 157 | # Iterate over all of the pixels |
| 158 | # Also prepare the debug view of the image (disp_test) |
| 159 | disp_test = "+" |
| 160 | for pixel in range( 0, self.max_width ): |
| 161 | disp_test += "-" |
| 162 | disp_test += "+\n" |
| 163 | |
| 164 | for y in range( 0, self.max_height ): |
| 165 | disp_test += "|" |
| 166 | |
| 167 | # Check if within height range |
| 168 | if not ( y >= height_start and y < height_end ): |
| 169 | disp_test += " " * self.max_width + "|\n|" |
| 170 | continue |
| 171 | |
| 172 | for x in range( 0, self.max_width ): |
| 173 | # Check if within width range |
| 174 | if not ( x >= width_start and x < width_end ): |
| 175 | disp_test += " " |
| 176 | continue |
no outgoing calls
no test coverage detected
searching dependent graphs…