def loadImage(filePath): inputImg = ASVLOFFSCREEN() if bUseBGRToEngine: #true bufferInfo = ImageLoader.getBGRFromFile(filePath) inputImg.u32PixelArrayFormat = ASVL_COLOR_FORMAT.ASVL_PAF_RGB24_B8G8R8 inputImg.i32Width = bufferInfo.width inputImg.i32Height = bufferInfo.height inputImg.pi32Pitch[0] = bufferInfo.width * 3 inputImg.ppu8Plane[0] = cast(bufferInfo.buffer, c_ubyte_p) inputImg.ppu8Plane[1] = cast(0, c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) else: bufferInfo = ImageLoader.getI420FromFile(filePath) inputImg.u32PixelArrayFormat = ASVL_COLOR_FORMAT.ASVL_PAF_I420 inputImg.i32Width = bufferInfo.width inputImg.i32Height = bufferInfo.height inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width // 2 inputImg.pi32Pitch[2] = inputImg.i32Width // 2 inputImg.ppu8Plane[0] = cast(bufferInfo.buffer, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast( addressof(inputImg.ppu8Plane[1].contents) + (inputImg.pi32Pitch[1] * inputImg.i32Height // 2), c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) inputImg.gc_ppu8Plane0 = bufferInfo.buffer return inputImg
def loadImage(filePath): """ 加载图片 """ t1 = time.time() bufferInfo = ImageLoader.getI420FromFile(filePath) inputImg = ASVLOFFSCREEN() inputImg.u32PixelArrayFormat = ASVL_COLOR_FORMAT.ASVL_PAF_I420 inputImg.i32Width = bufferInfo.width inputImg.i32Height = bufferInfo.height inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width // 2 inputImg.pi32Pitch[2] = inputImg.i32Width // 2 inputImg.ppu8Plane[0] = cast(bufferInfo.buffer, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast( addressof(inputImg.ppu8Plane[1].contents) + (inputImg.pi32Pitch[1] * inputImg.i32Height // 2), c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) inputImg.gc_ppu8Plane0 = bufferInfo.buffer t2 = time.time() print('Time on loadImage:',t2-t1) return inputImg
def loadYUVImage(yuv_filePath, yuv_width, yuv_height, yuv_format): yuv_rawdata_size = 0 inputImg = ASVLOFFSCREEN() inputImg.u32PixelArrayFormat = yuv_format inputImg.i32Width = yuv_width inputImg.i32Height = yuv_height if ASVL_COLOR_FORMAT.ASVL_PAF_I420 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width // 2 inputImg.pi32Pitch[2] = inputImg.i32Width // 2 yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 // 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_NV12 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 // 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_NV21 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 // 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_YUYV == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width * 2 yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_RGB24_B8G8R8 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width * 3 yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 else: print(u'unsupported yuv format') exit(0) # load YUV Image Data from File f = None try: f = open(yuv_filePath, u'rb') imagedata = f.read(yuv_rawdata_size) except Exception as e: traceback.print_exc() print(e.message) exit(0) finally: if f is not None: f.close() if ASVL_COLOR_FORMAT.ASVL_PAF_I420 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast( addressof(inputImg.ppu8Plane[1].contents) + (inputImg.pi32Pitch[1] * inputImg.i32Height // 2), c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_NV12 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_NV21 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_YUYV == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast(0, c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_RGB24_B8G8R8 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast(0, c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) else: print(u'unsupported yuv format') exit(0) inputImg.gc_ppu8Plane0 = imagedata return inputImg
def loadYUVImage(yuv_filePath, yuv_width, yuv_height, yuv_format): """ 加载YUV图片 """ yuv_rawdata_size = 0 inputImg = ASVLOFFSCREEN() inputImg.u32PixelArrayFormat = yuv_format inputImg.i32Width = yuv_width inputImg.i32Height = yuv_height if ASVL_COLOR_FORMAT.ASVL_PAF_I420 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width // 2 inputImg.pi32Pitch[2] = inputImg.i32Width // 2 yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 // 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_NV12 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 // 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_NV21 == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width inputImg.pi32Pitch[1] = inputImg.i32Width yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 3 // 2 elif ASVL_COLOR_FORMAT.ASVL_PAF_YUYV == inputImg.u32PixelArrayFormat: inputImg.pi32Pitch[0] = inputImg.i32Width * 2 yuv_rawdata_size = inputImg.i32Width * inputImg.i32Height * 2 else: print(u'unsupported yuv format') exit(0) # load YUV Image Data from File f = None try: f = open(yuv_filePath, u'rb') imagedata = f.read(yuv_rawdata_size) except Exception as e: traceback.print_exc() print(e.message) exit(0) finally: if f is not None: f.close() if ASVL_COLOR_FORMAT.ASVL_PAF_I420 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast( addressof(inputImg.ppu8Plane[1].contents) + (inputImg.pi32Pitch[1] * inputImg.i32Height // 2), c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_NV12 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_NV21 == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast( addressof(inputImg.ppu8Plane[0].contents) + (inputImg.pi32Pitch[0] * inputImg.i32Height), c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) elif ASVL_COLOR_FORMAT.ASVL_PAF_YUYV == inputImg.u32PixelArrayFormat: inputImg.ppu8Plane[0] = cast(imagedata, c_ubyte_p) inputImg.ppu8Plane[1] = cast(0, c_ubyte_p) inputImg.ppu8Plane[2] = cast(0, c_ubyte_p) inputImg.ppu8Plane[3] = cast(0, c_ubyte_p) else: print(u'unsupported yuv format') exit(0) inputImg.gc_ppu8Plane0 = imagedata return inputImg