performance - Speed up bmp image loading in python -


i reading in 24 bpp bitmap image in python. using struct module , reading in file byte byte , storing bgr elements in multidimensional array. see code below:

            char = fileobject.read(1)             self.blue[w][h] = struct.unpack('=b', char)[0]             char = fileobject.read(1)             self.green[w][h] = struct.unpack('=b', char)[0]             char = fileobject.read(1)             self.red[w][h] = struct.unpack('=b', char)[0] 

this takes long time (10 seconds 2732 x 1536 pixel image).

i want speed i'm not sure how. thinking this:

            threechar = fileobject.read(3)             self.blue[w][h] = ((threechar >> 8) << 8) #knock of not-needed bits             self.green[w][h] = ((threechar >> 4) << 8)             self.red[w][h] = (threechar << 8) 

i'm not sure how go speeding things here. can give me advice? slow here , why slow? how speed up?


Comments

Popular posts from this blog

ios - Is 'init' forbidden as *part* of a variable name? -

angular - Angular2 Router: Cannot find primary outlet to load 'HomeComponent' -

qt - Microsoft FTP Service 451 The parameter is incorrect -