def _create_metallic_roughness_map(self, metal_map, rough_map): metal = QImage(metal_map) rough = QImage(rough_map) metal_pixel = QColor() metal = metal.convertToFormat(QImage.Format_RGB32); rough = rough.convertToFormat(QImage.Format_RGB32); metal_uchar_ptr = metal.bits() rough_uchar_ptr = rough.bits() if (not metal.width() == rough.width() or not metal.height() == rough.height()): raise RuntimeError("Error processing material: {}. Metallic map and roughness map must have same dimensions.".format(self.maya_node)) width = metal.width(); height = metal.height(); i = 0 for y in range(height): for x in range(width): metal_color = struct.unpack('I', metal_uchar_ptr[i:i+4])[0] rough_color = struct.unpack('I', rough_uchar_ptr[i:i+4])[0] metal_pixel.setRgb(0, qGreen(rough_color), qBlue(metal_color)) metal_uchar_ptr[i:i+4] = struct.pack('I', metal_pixel.rgb()) i+=4 output = ExportSettings.out_dir + "/"+self.name+"_metalRough.jpg" return output, metal
def _create_metallic_roughness_map(self, metal_map, rough_map): metal = QImage(metal_map) rough = QImage(rough_map) metal_pixel = QColor() metal = metal.convertToFormat(QImage.Format_RGB32) rough = rough.convertToFormat(QImage.Format_RGB32) metal_uchar_ptr = metal.bits() rough_uchar_ptr = rough.bits() if (not metal.width() == rough.width() or not metal.height() == rough.height()): raise RuntimeError( "Error processing material: {}. Metallic map and roughness map must have same dimensions." .format(self.maya_node)) width = metal.width() height = metal.height() i = 0 for y in range(height): for x in range(width): metal_color = struct.unpack('I', metal_uchar_ptr[i:i + 4])[0] rough_color = struct.unpack('I', rough_uchar_ptr[i:i + 4])[0] metal_pixel.setRgb(0, qGreen(rough_color), qBlue(metal_color)) metal_uchar_ptr[i:i + 4] = struct.pack('I', metal_pixel.rgb()) i += 4 output = ExportSettings.out_dir + "/" + self.name + "_metalRough.jpg" return output, metal
def __init__(self, parent): super(HueSliderWidget, self).__init__(parent) self.setFixedSize(parent.width(), parent.height()) self.value = 0 size = 100 self.colorImage = QtGui.QImage(1, size, QtGui.QImage.Format_RGB32) c = QColor() for y in range(0, size): k = y / float(size) c.setHsvF(k, 1.0, 1.0) self.colorImage.setPixel(0, y, c.rgb()) self.setCursor(Qt.PointingHandCursor)
def __init__(self, parent): super(AlphaSliderWidget, self).__init__(parent) self.setFixedSize(parent.width(), parent.height()) self.setCursor(Qt.PointingHandCursor) self.value = 0 size = 100 self.colorImage = QtGui.QImage(size, 1, QtGui.QImage.Format_RGB32) c = QColor() for x in range(0, size): k = x / float(size) c.setHsvF(1.0, 0.0, k) self.colorImage.setPixel(x, 0, c.rgb())
def generateHSVImage(w, h, hue, img=None): if not img: img = QtGui.QImage(w, h, QtGui.QImage.Format_RGB32) du = 1.0 / w dv = 1.0 / h c = QColor() for y in range(0, h): for x in range(0, w): s = du * x v = 1.0 - dv * y c.setHsvF(hue, s, v) img.setPixel(x, y, c.rgb()) return img
def paint(self, canvas, is_secondary_color=False, additional_flag=False): if is_secondary_color: switch_color = self.data_singleton.secondary_color else: switch_color = self.data_singleton.primary_color # TODO: не заливает, если кликать на transparent фон x, y = self._start_point.x(), self._start_point.y() pixel = canvas.image.pixel(x, y) old_color = QColor(pixel) if switch_color != old_color: self.fill_recurs(x, y, switch_color.rgb(), old_color.rgb(), canvas.image) canvas.edited = True canvas.update()
def update(self): """" Mise a jour de l'image. """ if self.__first: self.__first = False self.__map_data = self.__gui_handler.get_map_data() self.__next_data = self.__gui_handler.get_entities() labels = [] # Découverte du terrain for terrain in SimUtils.get_terrains(): self.__terrain.append(terrain.color) labels.append(StatItem(terrain.name, "", terrain.color)) # Tri lexicographique des labels. labels.sort(key=lambda stat: stat._name) # Ajout des labels de terrain for label in labels: self.__gui_handler.add_stat(label) # Remplissage de la carte avec les terrains. for i in range(0, self.__width): for j in range(0, self.__height): # Affichage du point. color = QColor(self.__terrain[self.__map_data.get_terrain_type(i,j)]) self.__image.setPixel(i,j,color.rgb()) # Permet de faire le tri entre les entités déjà rencontrées et les # autres. entity_types = {} # Liste des futurs labels labels = [] # Découverte des entités - affectation des couleurs for entity in self.__next_data: # Ajout des labels de couleur pour les entités if not entity_types.has_key(entity.__name__): entity_types[entity.__name__] = True for label, color in entity._labels.iteritems(): labels.append(StatItem(label, "", color)) # Affichage de l'entité. self.__image.setPixel(entity._x, entity._y, QColor(entity._color).rgb()) self.positions[id(entity)] = [entity._x, entity._y] # Tri lexicographique des labels. labels.sort(key=lambda stat: stat._name) for label in labels: self.__gui_handler.add_stat(label) else: # Mise à jour du rendu for entity in self.__next_data: # Cas d'une entité désactivée (morte) remove_entity = not entity._is_active() if id(entity) not in self.positions: # Ajout de l'entité en cours de simulation self.__image.setPixel(entity._x, entity._y, QColor(entity._color).rgb()) self.positions[id(entity)] = [entity._x,entity._y] # Le simulateur demande de repeindre l'entité old_points = self.positions[id(entity)] if not remove_entity: self.positions[id(entity)] = [entity._x, entity._y] # On remet la couleur du terrain. color = QColor(self.__terrain[self.__map_data.get_terrain_type(old_points[0], old_points[1])]) self.__image.setPixel(old_points[0], old_points[1], color.rgb()) if not remove_entity: # Ajout des paramètres de setPixel dans une liste pour être ploté après. self.__image.setPixel(entity._x, entity._y, QColor(entity._color).rgb())