Python PyQt5.QtGui.qRgb() Examples
The following are 14
code examples of PyQt5.QtGui.qRgb().
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
PyQt5.QtGui
, or try the search function
.
Example #1
Source File: gui_utilities.py From CvStudio with MIT License | 6 votes |
def array_to_qimage(im: np.ndarray, copy=False): gray_color_table = [qRgb(i, i, i) for i in range(256)] if im is None: return QImage() if im.dtype == np.uint8: if len(im.shape) == 2: qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_Indexed8) qim.setColorTable(gray_color_table) return qim.copy() if copy else qim elif len(im.shape) == 3: if im.shape[2] == 3: qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_RGB888); return qim.copy() if copy else qim elif im.shape[2] == 4: qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_ARGB32); return qim.copy() if copy else qim
Example #2
Source File: crawl.py From IDACyber with MIT License | 6 votes |
def on_mb_click(self, event, addr, size, mouse_offs): button = event.button() if button == Qt.MiddleButton: mouse = addr+mouse_offs c = get_byte(mouse) head, name, size = self._get_item_info(mouse) funcname = self._get_func_name(mouse) self.ann = [(mouse, qRgb(c, 0xFF, self.hl_color), "Address: %X" % (mouse), qRgb(c, 0xFF, self.hl_color)), (None, None, " Item: %s" % (name), qRgb(c, 0xFF, self.hl_color)), (None, None, " Head: %X" % (head), qRgb(c, 0xFF, self.hl_color)), (None, None, " Size: %d" % (size), qRgb(c, 0xFF, self.hl_color)) ] if funcname: self.ann.append((None, None, " Function: %s" % (funcname), qRgb(c, 0xFF, self.hl_color))) self.last_sel = (head, size) elif button == Qt.MiddleButton: pass elif button == Qt.RightButton: self.switch ^= 1 msg('Highlighting %s\n' % self.mode[self.switch])
Example #3
Source File: xrefsto.py From IDACyber with MIT License | 6 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] goffs = 0 for mapped, buf in buffers: xrefs = [] if mapped: for i in range(len(buf)): xrefs.append(self.xrefcount(addr + goffs + i)) if xrefs: minimum, maximum = min(xrefs), max(xrefs) for count in xrefs: r, g, b = self.hm(minimum, maximum, count) colors.append((True, qRgb(r, g, b))) else: for i in range(len(buf)): colors.append((False, None)) goffs += len(buf) return colors
Example #4
Source File: test_imageqt.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_rgb(self): # from https://doc.qt.io/archives/qt-4.8/qcolor.html # typedef QRgb # An ARGB quadruplet on the format #AARRGGBB, # equivalent to an unsigned int. if ImageQt.qt_version == '5': from PyQt5.QtGui import qRgb elif ImageQt.qt_version == '4': from PyQt4.QtGui import qRgb elif ImageQt.qt_version == 'side': from PySide.QtGui import qRgb elif ImageQt.qt_version == 'side2': from PySide2.QtGui import qRgb self.assertEqual(qRgb(0, 0, 0), qRgba(0, 0, 0, 255)) def checkrgb(r, g, b): val = ImageQt.rgb(r, g, b) val = val % 2**24 # drop the alpha self.assertEqual(val >> 16, r) self.assertEqual(((val >> 8) % 2**8), g) self.assertEqual(val % 2**8, b) checkrgb(0, 0, 0) checkrgb(255, 0, 0) checkrgb(0, 255, 0) checkrgb(0, 0, 255)
Example #5
Source File: xor.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] for mapped, buf in buffers: if mapped: for c in buf: c = (c ^ self.key) & 0xFF colors.append((True, qRgb(0, c, c))) else: for i in range(len(buf)): colors.append((False, None)) return colors
Example #6
Source File: expr.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] for mapped, buf in buffers: if mapped: for c in buf: r = g = b = c & 0xFF r, g, b = eval(self.xpr) colors.append((True, qRgb(r&0xFF, g&0xFF, b&0xFF))) else: for i in range(len(buf)): colors.append((False, None)) return colors
Example #7
Source File: autoxor.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] self._update_key(buffers) for mapped, buf in buffers: if mapped: for c in buf: c = (c ^ self.key) if self.highlight_key and not c: colors.append((True, [qRgb(0x20, c, c), qRgb(0x7a, 0x0e, 0x7a)][self.hl_color_idx])) else: colors.append((True, qRgb(0x20, c, c))) else: for i in range(len(buf)): colors.append((False, None)) return colors
Example #8
Source File: dbg.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] goffs = 0 for mapped, buf in buffers: if mapped: ip = get_ip_val() i = 0 while i < len(buf): if ip is not None and ip == addr + goffs + i and self.hook.highlighted: size = get_item_size(ip) for j in range(size): colors.append((True, qRgb(0xFF, 0x45, 0))) i += size continue else: if addr + goffs + i in self.hook.hits: data = self.hook.hits[addr + goffs + i] size = data[1] hits = data[0] for j in range(size): base = self.palette[len(self.palette)-1] col = QColor(base).darker(100+(float(hits)/self.hook.maxhits)*105).rgb() colors.append((True, col)) i += size continue else: c = buf[i] colors.append((True, self.palette[self._byte2coloridx(c)])) i += 1 else: for i in range(len(buf)): colors.append((False, None)) goffs += len(buf) return colors
Example #9
Source File: NES.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): #Bit 7 6 5 4 3 2 1 0 #Data R R R G G G B B colors = [] for mapped, buf in buffers: if mapped: for c in buf: red = c & 0xE0 green = (c << 3) & 0xE0 blue = (c << 6) & 0xC0 colors.append((True, qRgb(red, green, blue))) else: for i in range(len(buf)): colors.append((False, None)) return colors
Example #10
Source File: crawl.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] head = BADADDR tail = BADADDR goffs = 0 for mapped, buf in buffers: if mapped: if mouse_offs is not None: if self.switch == 0: # data head = get_item_head(addr + mouse_offs) tail = get_item_end(addr + mouse_offs) else: # code f = get_func(addr + mouse_offs) if f: head = f.start_ea tail = f.end_ea for pos in range(len(buf)): c = buf[pos] & 0xFF highlight = False if mouse_offs is not None: if addr + pos + goffs >= head and addr + pos + goffs < tail: highlight = True if self.last_sel: lhead, lsize = self.last_sel if addr + pos + goffs >= lhead and addr + pos + goffs < lhead+lsize: highlight = True if highlight: colors.append((True, qRgb(c, 0xFF, self.hl_color))) else: colors.append((True, qRgb(c, 0, 0))) else: for pos in range(len(buf)): colors.append((False, None)) goffs += len(buf) return colors
Example #11
Source File: heatmap.py From IDACyber with MIT License | 5 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] for mapped, buf in buffers: if mapped: for c in buf: r, g, b = self.hm(c) colors.append((True, qRgb(r, g, b))) else: for i in range(len(buf)): colors.append((False, None)) return colors
Example #12
Source File: cityscapesViewer.py From Detectron-PYTORCH with Apache License 2.0 | 4 votes |
def loadDisparities(self): if not self.enableDisparity: return if not self.showDisparity: return filename = self.getDisparityFilename() if not filename: self.dispImg = None return # If we have everything and the filename did not change, then we are good if self.dispImg and filename == self.currentDispFile: return # Clear the current labels first self.dispImg = None try: self.dispImg = Image.open(filename) except IOError as e: # This is the error if the file does not exist message = "Error parsing disparities in {0}. Message: {1}".format(filename, e.strerror) self.statusBar().showMessage(message) self.dispImg = None if self.dispImg: dispNp = np.array(self.dispImg) dispNp /= 128 dispNp.round() dispNp = np.array(dispNp, dtype=np.uint8) dispQt = QtGui.QImage(dispNp.data, dispNp.shape[1], dispNp.shape[0], QtGui.QImage.Format_Indexed8) colortable = [] for i in range(256): color = self.colormap.to_rgba(i) colorRgb = (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255)) colortable.append(QtGui.qRgb(*colorRgb)) dispQt.setColorTable(colortable) dispQt = dispQt.convertToFormat(QtGui.QImage.Format_ARGB32_Premultiplied) self.dispOverlay = dispQt # Remember the filename loaded self.currentDispFile = filename # Remember the status bar message to restore it later restoreMessage = self.statusBar().currentMessage() # Restore the message self.statusBar().showMessage(restoreMessage) ############################# ## Drawing ############################# # This method is called when redrawing everything # Can be manually triggered by self.update() # Note that there must not be any other self.update within this method # or any methods that are called within
Example #13
Source File: Viewer.py From PyRAT with Mozilla Public License 2.0 | 4 votes |
def processPicture(self, **kwargs): if "fitwin" in kwargs.keys(): # self.size = size of data set self.scale = len(self.data) - 1 # self.scale = pyramid level while self.scale > 0: # self.box = displayed part if self.data[self.scale].shape[-1] > self.imageLabel.width() or \ self.data[self.scale].shape[-2] > self.imageLabel.height(): break self.scale -= 1 self.box = [0, self.size[0], 0, self.size[1]] cut_box = [foo // 2 ** self.scale for foo in self.box] else: self.scale = len(self.data) - 1 while self.scale > 0: cut_box = [foo // 2 ** self.scale for foo in self.box] if cut_box[1] - cut_box[0] > self.imageLabel.width() or \ cut_box[3] - cut_box[2] > self.imageLabel.height(): break self.scale -= 1 cut_box = [foo // 2 ** self.scale for foo in self.box] cut_box[1] = cut_box[0] + (cut_box[1] - cut_box[0]) // 4 * 4 # QT Limitation!! cut_box[3] = cut_box[2] + (cut_box[3] - cut_box[2]) // 4 * 4 self.scale = int(np.clip(self.scale, 0, len(self.data) - 1)) self.box[1] = cut_box[1] * int(2 ** self.scale) self.box[3] = cut_box[3] * int(2 ** self.scale) img = self.data2img(cut_box, scale=self.scale) xWin = self.imageLabel.width() yWin = self.imageLabel.height() winRatio = 1.0 * xWin / yWin self.imgwidth = img.width() self.imgheight = img.height() imgRatio = 1.0 * self.imgwidth / self.imgheight if imgRatio >= winRatio: # match widths self.imgwidth = xWin self.imgheight = int(xWin / imgRatio) else: # match heights self.imgheight = yWin self.imgwidth = int(yWin * imgRatio) self.factor = int(100.0 * self.imgwidth / (self.box[1] - self.box[0])) if self.factor <= 100: img = img.scaled(self.imgwidth, self.imgheight) # Bilinear? else: img = img.scaled(self.imgwidth, self.imgheight) # Nearest Neighbour self.statusBar.setMessage(size=1, zoom=1, level=1, scale=1) self.viewCombo.setItemText(0, str(int(self.factor)) + '%') # colortable = [QtGui.qRgb(i, i, i) for i in range(256)] p = colortables(self.config['palette'])[1] colortable = [QtGui.qRgb(p[i, 0], p[i, 1], p[i, 2]) for i in range(256)] img.setColorTable(colortable) self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(img))
Example #14
Source File: ascii.py From IDACyber with MIT License | 4 votes |
def on_process_buffer(self, buffers, addr, size, mouse_offs): colors = [] for mapped, buf in buffers: last_offs = None cur_len = 0 offsets = {} if mapped: localcolors = [] for i in range(len(buf)): c = buf[i] r = 0 printable = c >= 0x20 and c <= 0x7E if printable: if last_offs is not None: cur_len += 1 else: last_offs = i cur_len = 1 else: if last_offs is not None and cur_len >= self.threshold: offsets[last_offs] = cur_len last_offs = None cur_len = 0 # bg color localcolors.append(0x101010) for k, v in offsets.items(): for i in range(v): c = buf[k+i] b = c + (0xFF - 0x7E) if (c >= 0x41 and c <= 0x5A or c >= 0x61 and c <= 0x7A or c >= 0x30 and c <= 0x39): localcolors[k+i] = qRgb(b, b&0x7E, 0) else: localcolors[k+i] = qRgb(b&0x7E, b&0x7E, b&0x7E) for color in localcolors: colors.append((True, color)) else: for i in range(len(buf)): colors.append((False, None)) return colors