func makeDestinationManager(dest io.Writer, cinfo *C.struct_jpeg_compress_struct) (ret destinationManager) { ret.magic = magic ret.dest = dest ret.pub.init_destination = (*[0]byte)(C.destinationInit) ret.pub.empty_output_buffer = (*[0]byte)(C.destinationEmpty) ret.pub.term_destination = (*[0]byte)(C.destinationTerm) ret.pub.free_in_buffer = writeBufferSize ret.pub.next_output_byte = (*C.JOCTET)(&ret.buffer[0]) cinfo.dest = &ret.pub return }
func makeDestinationManager(dest io.Writer, cinfo *C.struct_jpeg_compress_struct) (ret *destinationManager) { ret = (*destinationManager)(C.malloc(C.size_t(unsafe.Sizeof(destinationManager{})))) if ret == nil { panic("Failed to allocate destinationManager") } ret.magic = magic ret.dest = dest ret.pub.init_destination = (*[0]byte)(C.destinationInit) ret.pub.empty_output_buffer = (*[0]byte)(C.destinationEmpty) ret.pub.term_destination = (*[0]byte)(C.destinationTerm) ret.pub.free_in_buffer = writeBufferSize ret.pub.next_output_byte = (*C.JOCTET)(&ret.buffer[0]) cinfo.dest = &ret.pub return }
func makeDestinationManager(dest io.Writer, cinfo *C.struct_jpeg_compress_struct) (mgr *destinationManager) { mgr = new(destinationManager) mgr.dest = dest mgr.pub = C.malloc_jpeg_destination_mgr() if mgr.pub == nil { panic("Failed to allocate C.struct_jpeg_destination_mgr") } mgr.buffer = C.malloc(writeBufferSize) if mgr.buffer == nil { panic("Failed to allocate buffer") } mgr.pub.init_destination = (*[0]byte)(C.destinationInit) mgr.pub.empty_output_buffer = (*[0]byte)(C.destinationEmpty) mgr.pub.term_destination = (*[0]byte)(C.destinationTerm) mgr.pub.free_in_buffer = writeBufferSize mgr.pub.next_output_byte = (*C.JOCTET)(mgr.buffer) cinfo.dest = mgr.pub destinationManagerMapMutex.Lock() defer destinationManagerMapMutex.Unlock() destinationManagerMap[uintptr(unsafe.Pointer(mgr.pub))] = mgr return }