Пример #1
0
func makeSourceManager(src io.Reader, dinfo *C.struct_jpeg_decompress_struct) (mgr *sourceManager) {
	mgr = new(sourceManager)
	mgr.src = src
	mgr.pub = C.malloc_jpeg_source_mgr()
	if mgr.pub == nil {
		panic("Failed to allocate C.struct_jpeg_source_mgr")
	}
	mgr.buffer = C.malloc(readBufferSize)
	if mgr.buffer == nil {
		panic("Failed to allocate buffer")
	}
	mgr.pub.init_source = (*[0]byte)(C.sourceInit)
	mgr.pub.fill_input_buffer = (*[0]byte)(C.sourceFill)
	mgr.pub.skip_input_data = (*[0]byte)(C.sourceSkip)
	mgr.pub.resync_to_restart = (*[0]byte)(C._get_jpeg_resync_to_restart())
	mgr.pub.term_source = (*[0]byte)(C.sourceTerm)
	mgr.pub.bytes_in_buffer = 0
	mgr.pub.next_input_byte = nil
	dinfo.src = mgr.pub

	sourceManagerMapMutex.Lock()
	defer sourceManagerMapMutex.Unlock()
	sourceManagerMap[uintptr(unsafe.Pointer(mgr.pub))] = mgr

	return
}
Пример #2
0
func makeSourceManager(src io.Reader, dinfo *C.struct_jpeg_decompress_struct) (ret *sourceManager) {
	ret = (*sourceManager)(C.malloc(C.size_t(unsafe.Sizeof(sourceManager{}))))
	if ret == nil {
		panic("Failed to allocate sourceManager")
	}
	ret.magic = magic
	ret.src = src
	ret.pub.init_source = (*[0]byte)(C.sourceInit)
	ret.pub.fill_input_buffer = (*[0]byte)(C.sourceFill)
	ret.pub.skip_input_data = (*[0]byte)(C.sourceSkip)
	ret.pub.resync_to_restart = (*[0]byte)(C.jpeg_resync_to_restart) // default implementation
	ret.pub.term_source = (*[0]byte)(C.sourceTerm)
	ret.pub.bytes_in_buffer = 0
	ret.pub.next_input_byte = nil
	dinfo.src = &ret.pub
	return
}