1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import numpy as np
- class _RGB:
- def process(self, image):
- width = image.shape[1]
- height = image.shape[0]
- data = np.zeros((height, width, 3), np.uint8)
- for row in range(height):
- for column in range(width):
- pixel = data[row][column]
- v = int((image[row][column] + 10000) * 10)
- pixel[0] = v >> 16 & 0x0000FF
- pixel[1] = v >> 8 & 0x0000FF
- pixel[2] = v & 0x0000FF
- pass
- pass
- return data, 'RGB'
- pass
- class _RGBA:
- def __init__(self, nodata):
- self._nodata = nodata
- pass
- def process(self, image):
- width = image.shape[1]
- height = image.shape[0]
- data = np.zeros((height, width, 4), np.uint8)
- for row in range(height):
- for column in range(width):
- pixel = data[row][column]
- v = int((image[row][column] + 10000) * 10)
- pixel[0] = v >> 16 & 0x0000FF
- pixel[1] = v >> 8 & 0x0000FF
- pixel[2] = v & 0x0000FF
- pixel[3] = 0 if v == self._nodata else 255
- pass
- pass
- return data, 'RGBA'
- pass
- class RendererMapboxRGB:
- def __init__(self, datatype, nodata = None):
- self._datatype = datatype
- self._nodata = nodata
- if self._nodata is None:
- self._implement = _RGB()
- pass
- else:
- self._implement = _RGBA(nodata)
- pass
- pass
- def process(self, image):
- return self._implement.process(image)
- pass
|