getCustomBlockImageCoordinates = function(image, blockType, blockIndex) {
                // The image is based on the first ("upright") orientation
                var positions = game._shapes[blockType][0];
                // Find the number of tiles it should have
                var minX = Math.min(positions[0], positions[2], positions[4], positions[6]);
                var maxX = Math.max(positions[0], positions[2], positions[4], positions[6]);
                var minY = Math.min(positions[1], positions[3], positions[5], positions[7]);
                var maxY = Math.max(positions[1], positions[3], positions[5], positions[7]);
                var rangeX = maxX - minX + 1;
                var rangeY = maxY - minY + 1;
                
                // X and Y sizes should match. Should.
                var tileSizeX = image.width / rangeX;
                var tileSizeY = image.height / rangeY;

                return {
                  x: tileSizeX * (positions[blockIndex*2]-minX),
                  y: tileSizeY * Math.abs(minY-positions[blockIndex*2+1]),
                  w: tileSizeX,
                  h: tileSizeY
                };
              }
Draws one block (Each piece is made of 4 blocks)
The blockType is used to draw any block. 
The falling attribute is needed to apply different styles for falling and placed blocks.