Python ctypes.c_byte() Examples
The following are 30
code examples of ctypes.c_byte().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ctypes
, or try the search function
.
Example #1
Source File: DDSLoader.py From PyEngine3D with BSD 2-Clause "Simplified" License | 6 votes |
def _compute_type(self): if not (self.header.dwCaps & DDSEnums.DDSCAPS_TEXTURE): raise FormatNotValid("Invalid format file not tagged as texture") if self.header.dwCaps2 & DDSEnums.DDSCAPS2_CUBEMAP: if self.ext_header.arraySize > 1: self.type = DDSTexture.Type.TextureCubeArray self.array_size = self.ext_header.arraySize else: self.type = DDSTexture.Type.TextureCube self.array_size = 1 # We either have a single texture or a texture array ( 2D ) else: if self.format_code == DDSEnums.DX10_CC and \ self.ext_header.arraySize > 1: self.type = DDSTexture.Type.Texture2DArray self.array_size = self.ext_header.arraySize else: self.type = DDSTexture.Type.Texture2D self.array_size = 1 # Loads the texture from the filename, obtaining # data - array of c_byte containing untouched texture data formatted matching the surfaces data # surfaces - metadata for the raw texture data that describes how it can be read, its valued are ready for DirectX11 creation ( Pitch, width, height, size ) # format - DXGI compatible format the integer self.format can be safely static_cast<DXGI_FORMAT> to obtain the C++ enumerator counterpart
Example #2
Source File: windows.py From mayhem with BSD 3-Clause "New" or "Revised" License | 6 votes |
def io_control_file(self, io_control_code, input_buffer=None, output_buffer_length=None): io_status_block = wintypes.IO_STATUS_BLOCK() input_buffer_length = (0 if input_buffer is None else len(input_buffer)) if output_buffer_length is None: output_buffer = None output_buffer_length = 0 else: output_buffer = (ctypes.c_byte * output_buffer_length)() value = m_ntdll.NtDeviceIoControlFile( self.handle, # FileHandle [in] None, # Event [in-opt] None, # ApcRoutine [in-opt] None, # ApcContext [in-opt] ctypes.byref(io_status_block), # IoStatusBlock [out] io_control_code, # IoControlCode [in] input_buffer, # InputBuffer [in-opt] input_buffer_length, # InputBufferLength [in] output_buffer, # OutputBuffer [out-opt] output_buffer_length # OutputBufferLength [out] ) return (value, mayhem.utilities.ctarray_to_bytes(output_buffer))
Example #3
Source File: vrep.py From costar_plan with Apache License 2.0 | 6 votes |
def simxGetVisionSensorImage(clientID, sensorHandle, options, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' resolution = (ct.c_int*2)() c_image = ct.POINTER(ct.c_byte)() bytesPerPixel = 3 if (options and 1) != 0: bytesPerPixel = 1 ret = c_GetVisionSensorImage(clientID, sensorHandle, resolution, ct.byref(c_image), options, operationMode) reso = [] image = [] if (ret == 0): image = [None]*resolution[0]*resolution[1]*bytesPerPixel for i in range(resolution[0] * resolution[1] * bytesPerPixel): image[i] = c_image[i] for i in range(2): reso.append(resolution[i]) return ret, reso, image
Example #4
Source File: vrep.py From visual-pushing-grasping with BSD 2-Clause "Simplified" License | 6 votes |
def simxGetVisionSensorImage(clientID, sensorHandle, options, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' resolution = (ct.c_int*2)() c_image = ct.POINTER(ct.c_byte)() bytesPerPixel = 3 if (options and 1) != 0: bytesPerPixel = 1 ret = c_GetVisionSensorImage(clientID, sensorHandle, resolution, ct.byref(c_image), options, operationMode) reso = [] image = [] if (ret == 0): image = [None]*resolution[0]*resolution[1]*bytesPerPixel for i in range(resolution[0] * resolution[1] * bytesPerPixel): image[i] = c_image[i] for i in range(2): reso.append(resolution[i]) return ret, reso, image
Example #5
Source File: vrep.py From vrep-api-python with GNU General Public License v2.0 | 6 votes |
def simxGetVisionSensorImage(clientID, sensorHandle, options, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' resolution = (ct.c_int*2)() c_image = ct.POINTER(ct.c_byte)() bytesPerPixel = 3 if (options and 1) != 0: bytesPerPixel = 1 ret = c_GetVisionSensorImage(clientID, sensorHandle, resolution, ct.byref(c_image), options, operationMode) reso = [] image = [] if (ret == 0): image = [None]*resolution[0]*resolution[1]*bytesPerPixel for i in range(resolution[0] * resolution[1] * bytesPerPixel): image[i] = c_image[i] for i in range(2): reso.append(resolution[i]) return ret, reso, image
Example #6
Source File: snapshot.py From hase with BSD 2-Clause "Simplified" License | 6 votes |
def traces(self) -> bytearray: aux_begin = self.pt_buffer.aux_buf.addr aux_end = self.pt_buffer.aux_buf.addr + self.pt_buffer.aux_buf.size for ev in self.pt_buffer.events(): if ev.type == PerfRecord.PERF_RECORD_ITRACE_START: self._itrace_start_event = ev break tail = aux_begin + self.pt_buffer.header.aux_tail head = aux_begin + self.pt_buffer.header.aux_head assert tail == aux_begin assert head < aux_end length = head - tail buf = bytearray(length) c_buf = (ct.c_byte * length).from_buffer(buf) ct.memmove(c_buf, tail, length) return buf
Example #7
Source File: etw.py From pywintrace with Apache License 2.0 | 6 votes |
def _getEventInformation(record): """ Initially we are handed an EVENT_RECORD structure. While this structure technically contains all of the information necessary, TdhGetEventInformation parses the structure and simplifies it so we can more effectively parse and handle the various fields. :param record: The EventRecord structure for the event we are parsing :return: Returns a pointer to a TRACE_EVENT_INFO structure or None on error. """ info = ct.POINTER(tdh.TRACE_EVENT_INFO)() buffer_size = wt.DWORD() # Call TdhGetEventInformation once to get the required buffer size and again to actually populate the structure. status = tdh.TdhGetEventInformation(record, 0, None, None, ct.byref(buffer_size)) if tdh.ERROR_INSUFFICIENT_BUFFER == status: info = ct.cast((ct.c_byte * buffer_size.value)(), ct.POINTER(tdh.TRACE_EVENT_INFO)) status = tdh.TdhGetEventInformation(record, 0, None, info, ct.byref(buffer_size)) if tdh.ERROR_SUCCESS != status: raise ct.WinError(status) return info
Example #8
Source File: vrep.py From pypot with GNU General Public License v3.0 | 6 votes |
def simxGetVisionSensorImage(clientID, sensorHandle, options, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' resolution = (ct.c_int*2)() c_image = ct.POINTER(ct.c_byte)() bytesPerPixel = 3 if (options and 1) != 0: bytesPerPixel = 1 ret = c_GetVisionSensorImage(clientID, sensorHandle, resolution, ct.byref(c_image), options, operationMode) reso = [] image = [] if (ret == 0): image = [None]*resolution[0]*resolution[1]*bytesPerPixel for i in range(resolution[0] * resolution[1] * bytesPerPixel): image[i] = c_image[i] for i in range(2): reso.append(resolution[i]) return ret, reso, image
Example #9
Source File: vixutils.py From vmware_guest_auth_bypass with Apache License 2.0 | 6 votes |
def open_vm(self, vmx_path, timeout=4): assert self.connected, "VixConnection not connected" start_time = time.time() job_handle = vixlib.VixVM_Open(self._host_handle, vmx_path, None, None) vm_handle = vixlib.VixHandle() job_completed = ctypes.c_byte(0) while not job_completed.value: err = vixlib.VixJob_CheckCompletion(job_handle, ctypes.byref(job_completed)) _check_job_err_code(err) if timeout and timeout < (time.time() - start_time): raise VixException("Timeout (%d seconds) waiting to open VM by VMX '%s'", 0, timeout, vmx_path) err = vixlib.Vix_GetProperties(job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_HANDLE, ctypes.byref(vm_handle), vixlib.VIX_PROPERTY_NONE) vixlib.Vix_ReleaseHandle(job_handle) _check_job_err_code(err) return VixVM(vm_handle)
Example #10
Source File: _multi_proc.py From pyresample with GNU Lesser General Public License v3.0 | 6 votes |
def shmem_as_ndarray(raw_array): _ctypes_to_numpy = { ctypes.c_char: np.int8, ctypes.c_wchar: np.int16, ctypes.c_byte: np.int8, ctypes.c_ubyte: np.uint8, ctypes.c_short: np.int16, ctypes.c_ushort: np.uint16, ctypes.c_int: np.int32, ctypes.c_uint: np.int32, ctypes.c_long: np.int32, ctypes.c_ulong: np.int32, ctypes.c_float: np.float32, ctypes.c_double: np.float64 } dtype = _ctypes_to_numpy[raw_array._type_] # The following works too, but occasionally raises # RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size. # and appears to be slower. # return np.ctypeslib.as_array(raw_array) return np.frombuffer(raw_array, dtype=dtype)
Example #11
Source File: ircsnapshot.py From ircsnapshot with MIT License | 6 votes |
def is_ipv6(ip): try: if os.name == "nt": class sockaddr(ctypes.Structure): _fields_ = [("sa_family", ctypes.c_short), ("__pad1", ctypes.c_ushort), ("ipv4_addr", ctypes.c_byte * 4), ("ipv6_addr", ctypes.c_byte * 16), ("__pad2", ctypes.c_ulong)] WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA addr = sockaddr() addr.sa_family = socket.AF_INET6 addr_size = ctypes.c_int(ctypes.sizeof(addr)) if WSAStringToAddressA(ip, socket.AF_INET6, None, ctypes.byref(addr), ctypes.byref(addr_size)) != 0: raise socket.error(ctypes.FormatError()) return ctypes.string_at(addr.ipv6_addr, 16) else: return socket.inet_pton(socket.AF_INET6, ip) except: return False
Example #12
Source File: win32.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 6 votes |
def _reset_state(self, vk, layout, scan): """Clears the internal kernel keyboard state. This method will remove all dead keys from the internal state. :param int vk: The virtual key code. :param layout: The keyboard layout. :param int scan: The scan code of the key. """ state = (ctypes.c_byte * 255)() out = (ctypes.wintypes.WCHAR * 5)() while self._ToUnicodeEx( vk, scan, ctypes.byref(state), ctypes.byref(out), len(out), 0, layout) < 0: pass
Example #13
Source File: _ffi.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def native(type_, value): if isinstance(value, type_): return value if sys.version_info < (3,) and type_ == int and isinstance(value, int_types): return value if isinstance(value, ctypes.Array) and value._type_ == ctypes.c_byte: return ctypes.string_at(ctypes.addressof(value), value._length_) return type_(value.value)
Example #14
Source File: PyKinectRuntime.py From PyKinect2 with MIT License | 5 votes |
def surface_as_array(self, surface_buffer_interface): address = ctypes.c_void_p() size = self.Py_ssize_t() self._PyObject_AsWriteBuffer(surface_buffer_interface, ctypes.byref(address), ctypes.byref(size)) bytes = (ctypes.c_byte * size.value).from_address(address.value) bytes.object = surface_buffer_interface return bytes
Example #15
Source File: vrep.py From costar_plan with Apache License 2.0 | 5 votes |
def simxSetVisionSensorImage(clientID, sensorHandle, image, options, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' size = len(image) image_bytes = (ct.c_byte*size)(*image) return c_SetVisionSensorImage(clientID, sensorHandle, image_bytes, size, options, operationMode)
Example #16
Source File: vrep.py From pypot with GNU General Public License v3.0 | 5 votes |
def simxSetVisionSensorImage(clientID, sensorHandle, image, options, operationMode): ''' Please have a look at the function description/documentation in the V-REP user manual ''' size = len(image) image_bytes = (ct.c_byte*size)(*image) return c_SetVisionSensorImage(clientID, sensorHandle, image_bytes, size, options, operationMode)
Example #17
Source File: _ffi.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def ref(value, offset=0): return ctypes.cast(ctypes.addressof(value) + offset, ctypes.POINTER(ctypes.c_byte))
Example #18
Source File: _ffi.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def byte_array(byte_string): return (ctypes.c_byte * len(byte_string))(*bytes_to_list(byte_string))
Example #19
Source File: _ffi.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def write_to_buffer(buffer, data, offset=0): if isinstance(buffer, ctypes.POINTER(ctypes.c_byte)): ctypes.memmove(buffer, data, len(data)) return if offset == 0: buffer.value = data else: buffer.value = buffer.raw[0:offset] + data
Example #20
Source File: instruction.py From Zvm with Apache License 2.0 | 5 votes |
def execute(self, frame): val = frame.operand_stack.pop_int() frame.operand_stack.push_int(ctypes.c_byte(val).value)
Example #21
Source File: win32.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def _create_bitmap(self, width, height): self._data = (ctypes.c_byte * (4 * width * height))() self._bitmap = ctypes.c_void_p() self._format = PixelFormat32bppARGB gdiplus.GdipCreateBitmapFromScan0(width, height, width * 4, self._format, self._data, ctypes.byref(self._bitmap)) self._graphics = ctypes.c_void_p() gdiplus.GdipGetImageGraphicsContext(self._bitmap, ctypes.byref(self._graphics)) gdiplus.GdipSetPageUnit(self._graphics, UnitPixel) self._dc = user32.GetDC(0) gdi32.SelectObject(self._dc, self.font.hfont) gdiplus.GdipSetTextRenderingHint(self._graphics, TextRenderingHintAntiAliasGridFit) self._brush = ctypes.c_void_p() gdiplus.GdipCreateSolidFill(0xffffffff, ctypes.byref(self._brush)) self._matrix = ctypes.c_void_p() gdiplus.GdipCreateMatrix(ctypes.byref(self._matrix)) self._flags = (DriverStringOptionsCmapLookup | DriverStringOptionsRealizedAdvance) self._rect = Rect(0, 0, width, height) self._bitmap_height = height
Example #22
Source File: instruction.py From Zvm with Apache License 2.0 | 5 votes |
def execute(self, frame): frame.operand_stack.push_int(ctypes.c_byte(self.byte).value)
Example #23
Source File: freetype.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def __init__(self, data): self.buffer = (ctypes.c_byte * len(data))() ctypes.memmove(self.buffer, data, len(data)) ft_library = ft_get_library() self.face = FT_Face() r = FT_New_Memory_Face(ft_library, self.buffer, len(self.buffer), 0, self.face) if r != 0: raise base.FontException('Could not load font data') self.name = self.face.contents.family_name self.bold = self.face.contents.style_flags & FT_STYLE_FLAG_BOLD != 0 self.italic = self.face.contents.style_flags & FT_STYLE_FLAG_ITALIC != 0 # Replace Freetype's generic family name with TTF/OpenType specific # name if we can find one; there are some instances where Freetype # gets it wrong. if self.face.contents.face_flags & FT_FACE_FLAG_SFNT: name = FT_SfntName() for i in range(FT_Get_Sfnt_Name_Count(self.face)): result = FT_Get_Sfnt_Name(self.face, i, name) if result != 0: continue if not (name.platform_id == TT_PLATFORM_MICROSOFT and name.encoding_id == TT_MS_ID_UNICODE_CS): continue if name.name_id == TT_NAME_ID_FONT_FAMILY: string = string_at(name.string, name.string_len) self.name = string.decode('utf-16be', 'ignore')
Example #24
Source File: win32.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def _create_bitmap(self, width, height): self._data = (ctypes.c_byte * (4 * width * height))() self._bitmap = ctypes.c_void_p() self._format = PixelFormat32bppARGB gdiplus.GdipCreateBitmapFromScan0(width, height, width * 4, self._format, self._data, ctypes.byref(self._bitmap)) self._graphics = ctypes.c_void_p() gdiplus.GdipGetImageGraphicsContext(self._bitmap, ctypes.byref(self._graphics)) gdiplus.GdipSetPageUnit(self._graphics, UnitPixel) self._dc = user32.GetDC(0) gdi32.SelectObject(self._dc, self.font.hfont) gdiplus.GdipSetTextRenderingHint(self._graphics, TextRenderingHintAntiAliasGridFit) self._brush = ctypes.c_void_p() gdiplus.GdipCreateSolidFill(0xffffffff, ctypes.byref(self._brush)) self._matrix = ctypes.c_void_p() gdiplus.GdipCreateMatrix(ctypes.byref(self._matrix)) self._flags = (DriverStringOptionsCmapLookup | DriverStringOptionsRealizedAdvance) self._rect = Rect(0, 0, width, height) self._bitmap_height = height
Example #25
Source File: vertexbuffer.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def __init__(self, size, target, usage): super(MappableVertexBufferObject, self).__init__(size, target, usage) self.data = (ctypes.c_byte * size)() self.data_ptr = ctypes.cast(self.data, ctypes.c_void_p).value self._dirty_min = sys.maxint self._dirty_max = 0
Example #26
Source File: vertexbuffer.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def resize(self, size): # Map, create a copy, then reinitialize. temp = (ctypes.c_byte * size)() glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glBindBuffer(self.target, self.id) data = glMapBuffer(self.target, GL_READ_ONLY) ctypes.memmove(temp, data, min(size, self.size)) glUnmapBuffer(self.target) self.size = size glBufferData(self.target, self.size, temp, self.usage) glPopClientAttrib()
Example #27
Source File: vertexbuffer.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def map(self, invalidate=False): glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glBindBuffer(self.target, self.id) if invalidate: glBufferData(self.target, self.size, None, self.usage) ptr = ctypes.cast(glMapBuffer(self.target, GL_WRITE_ONLY), ctypes.POINTER(ctypes.c_byte * self.size)).contents glPopClientAttrib() return ptr
Example #28
Source File: vertexbuffer.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def resize(self, size): array = (ctypes.c_byte * size)() ctypes.memmove(array, self.array, min(size, self.size)) self.size = size self.array = array self.ptr = ctypes.cast(self.array, ctypes.c_void_p).value
Example #29
Source File: vertexbuffer.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def __init__(self, size): self.size = size self.array = (ctypes.c_byte * size)() self.ptr = ctypes.cast(self.array, ctypes.c_void_p).value
Example #30
Source File: _ffi.py From oscrypto with MIT License | 5 votes |
def byte_array(byte_string): return (ctypes.c_byte * len(byte_string))(*bytes_to_list(byte_string))