def export_height_map(self):
     name = QtGui.QFileDialog.getSaveFileName(self,
         'Export Heightmap', filter = IMAGE_SAVE_FILTER)[0]
     if not name:
         return
     height_packed = []
     for z in xrange(0, 64):
         height = (63 - z) * 4
         height_packed.append(struct.pack('I', QtGui.qRgba(height, height, height, 255)))
     height_image = QImage(512, 512, QImage.Format_ARGB32)
     height_lines = []
     height_found = []
     for y in xrange(0, 512):
         height_lines.append(height_image.scanLine(y))
         height_found.append([])
         for x in xrange(0, 512):
             height_found[y].append(False)
     progress = progress_dialog(self.edit_widget, 0, 63, 'Exporting Heightmap...')
     for z in xrange(0, 64):
         if progress.wasCanceled():
             break
         progress.setValue(z)
         packed_value = height_packed[z]
         image = self.layers[z]
         for y in xrange(0, 512):
             image_line = image.scanLine(y)
             height_line = height_lines[y]
             for x in xrange(0, 512):
                 if height_found[y][x] is False:
                     s = x * 4
                     if image_line[s:s + 4] != TRANSPARENT_PACKED:
                         height_found[y][x] = True
                         height_line[s:s + 4] = packed_value
     height_image.save(name)
Exemple #2
0
 def export_height_map(self):
     name = QtGui.QFileDialog.getSaveFileName(self,
         'Export Heightmap', filter = IMAGE_SAVE_FILTER)[0]
     if not name:
         return
     height_packed = []
     for z in xrange(0, 64):
         height = (63 - z) * 4
         height_packed.append(struct.pack('I',
             QtGui.qRgba(height, height, height, 255)))
     height_image = QImage(512, 512, QImage.Format_ARGB32)
     height_lines = []
     height_found = []
     for y in xrange(0, 512):
         height_lines.append(height_image.scanLine(y))
         height_found.append([])
         for x in xrange(0, 512):
             height_found[y].append(False)
     progress = progress_dialog(self.edit_widget, 0, 63, 'Exporting Heightmap...')
     for z, image in enumerate(self.layers):
         if progress.wasCanceled():
             break
         progress.setValue(z)
         packed_value = height_packed[z]
         for y in xrange(0, 512):
             image_line = image.scanLine(y)
             height_line = height_lines[y]
             for x in xrange(0, 512):
                 if height_found[y][x] is False:
                     s = x * 4
                     if image_line[s:s + 4] != TRANSPARENT_PACKED:
                         height_found[y][x] = True
                         height_line[s:s + 4] = packed_value
     height_image.save(name)
 def export_color_map(self):
     name = QtGui.QFileDialog.getSaveFileName(self,
         'Export Colormap', filter = IMAGE_SAVE_FILTER)[0]
     if not name:
         return
     color_image = QImage(512, 512, QImage.Format_ARGB32)
     color_lines = []
     height_found = []
     for y in xrange(0, 512):
         color_lines.append(color_image.scanLine(y))
         height_found.append([])
         for x in xrange(0, 512):
             height_found[y].append(False)
     progress = progress_dialog(self.edit_widget, 0, 63, 'Exporting Colormap...')
     for z in xrange(0, 64):
         if progress.wasCanceled():
             break
         progress.setValue(z)
         image = self.layers[z]
         for y in xrange(0, 512):
             image_line = image.scanLine(y)
             color_line = color_lines[y]
             for x in xrange(0, 512):
                 if height_found[y][x] is False:
                     s = x * 4
                     image_pixel = image_line[s:s + 4]
                     if image_pixel != TRANSPARENT_PACKED:
                         height_found[y][x] = True
                         color_line[s:s + 4] = image_pixel
     color_image.save(name)
Exemple #4
0
 def export_color_map(self):
     name = QtGui.QFileDialog.getSaveFileName(self,
         'Export Colormap', filter = IMAGE_SAVE_FILTER)[0]
     if not name:
         return
     color_image = QImage(512, 512, QImage.Format_ARGB32)
     color_lines = []
     height_found = []
     for y in xrange(0, 512):
         color_lines.append(color_image.scanLine(y))
         height_found.append([])
         for x in xrange(0, 512):
             height_found[y].append(False)
     progress = progress_dialog(self.edit_widget, 0, 63, 'Exporting Colormap...')
     for z, image in enumerate(self.layers):
         if progress.wasCanceled():
             break
         progress.setValue(z)
         for y in xrange(0, 512):
             image_line = image.scanLine(y)
             color_line = color_lines[y]
             for x in xrange(0, 512):
                 if height_found[y][x] is False:
                     s = x * 4
                     image_pixel = image_line[s:s + 4]
                     if image_pixel != TRANSPARENT_PACKED:
                         height_found[y][x] = True
                         color_line[s:s + 4] = image_pixel
     color_image.save(name)
Exemple #5
0
 def generate_heightmap(self, delete=False):
     h_name = QtGui.QFileDialog.getOpenFileName(self,
                                                'Select heightmap file',
                                                filter=IMAGE_OPEN_FILTER)[0]
     if not h_name:
         return
     h_image = QImage(h_name)
     if not delete:
         c_name = QtGui.QFileDialog.getOpenFileName(
             self, 'Select colormap file', filter=IMAGE_OPEN_FILTER)[0]
         if not c_name:
             return
         c_image = QImage(c_name)
     height_values = []
     color_lines = []
     for y in xrange(0, 512):
         height_values.append([])
         height_line = h_image.scanLine(y)
         if not delete:
             color_lines.append(c_image.scanLine(y))
         for x in xrange(0, 512):
             height_values[y].append(
                 self.get_height(
                     struct.unpack('I', height_line[x * 4:x * 4 + 4])[0]))
     progress = progress_dialog(self.edit_widget, 0, 63,
                                'Generating from heightmap...')
     for z, image in enumerate(reversed(self.layers)):
         if progress.wasCanceled():
             break
         progress.setValue(z)
         if z == 0 and delete:
             continue
         for y in xrange(0, 512):
             image_line = image.scanLine(y)
             if not delete:
                 color_line = color_lines[y]
             for x in xrange(0, 512):
                 if z <= height_values[y][x]:
                     s = x * 4
                     if not delete:
                         image_line[s:s + 4] = color_line[s:s + 4]
                     else:
                         image_line[s:s + 4] = TRANSPARENT_PACKED
         image.dirty = True
     self.set_dirty()
Exemple #6
0
 def generate_heightmap(self, delete = False):
     h_name = QtGui.QFileDialog.getOpenFileName(self,
         'Select heightmap file', filter = IMAGE_OPEN_FILTER)[0]
     if not h_name:
         return
     h_image = QImage(h_name)
     if not delete:
         c_name = QtGui.QFileDialog.getOpenFileName(self,
             'Select colormap file', filter = IMAGE_OPEN_FILTER)[0]
         if not c_name:
             return
         c_image = QImage(c_name)
     height_values = []
     color_lines = []
     for y in xrange(0, 512):
         height_values.append([])
         height_line = h_image.scanLine(y)
         if not delete:
             color_lines.append(c_image.scanLine(y))
         for x in xrange(0,512):
             height_values[y].append(self.get_height(
                 struct.unpack('I', height_line[x * 4:x * 4 + 4])[0]))
     progress = progress_dialog(self.edit_widget, 0, 63,
         'Generating from heightmap...')
     for z, image in enumerate(reversed(self.layers)):
         if progress.wasCanceled():
             break
         progress.setValue(z)
         if z == 0 and delete:
             continue
         for y in xrange(0, 512):
             image_line = image.scanLine(y)
             if not delete:
                 color_line = color_lines[y]
             for x in xrange(0, 512):
                 if z <= height_values[y][x]:
                     s = x * 4
                     if not delete:
                         image_line[s:s + 4] = color_line[s:s + 4]
                     else:
                         image_line[s:s + 4] = TRANSPARENT_PACKED
         image.dirty = True
     self.set_dirty()
def image_from_hbitmap(hdc, bitmap, width, height):
    bitmap_info = BITMAPINFO()
    memset(byref(bitmap_info), 0, sizeof(bitmap_info))
    bitmap_info.bmiHeader.biSize = sizeof(bitmap_info.bmiHeader)
    bitmap_info.bmiHeader.biWidth = width
    bitmap_info.bmiHeader.biHeight = -height
    bitmap_info.bmiHeader.biPlanes = 1
    bitmap_info.bmiHeader.biBitCount = 32
    bitmap_info.bmiHeader.biCompression = BI_RGB
    bitmap_info.bmiHeader.biSizeImage = width * height * 4
    image = QImage(width, height, QImage.Format_ARGB32_Premultiplied)
    if image.isNull(): return image
    data = (c_ubyte * bitmap_info.bmiHeader.biSizeImage)()
    if not GetDIBits(hdc, bitmap, 0, height, data, byref(bitmap_info), 
            DIB_RGB_COLORS):
        raise WindowsError('call to GetDIBits failed')
    bytes_per_line = image.bytesPerLine()
    for y in xrange(0, height):
        offset = y * bytes_per_line
        line = image.scanLine(y)
        for x in xrange(0, bytes_per_line):
            line[x] = chr(data[offset + x])
    return image
Exemple #8
0
def qt_fromWinHBITMAP(hdc, h_bitmap, w, h):
    """

    Original:
    static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
    {
        BITMAPINFO bmi;
        memset(&bmi, 0, sizeof(bmi));
        bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
        bmi.bmiHeader.biWidth       = w;
        bmi.bmiHeader.biHeight      = -h;
        bmi.bmiHeader.biPlanes      = 1;
        bmi.bmiHeader.biBitCount    = 32;
        bmi.bmiHeader.biCompression = BI_RGB;
        bmi.bmiHeader.biSizeImage   = w * h * 4;

        QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
        if (image.isNull())
            return image;

        // Get bitmap bits
        uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage);

        if (GetDIBits(hdc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
            // Create image and copy data into image.
            for (int y=0; y<h; ++y) {
                void *dest = (void *) image.scanLine(y);
                void *src = data + y * image.bytesPerLine();
                memcpy(dest, src, image.bytesPerLine());
            }
        } else {
            qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits");
        }
        qFree(data);

        return image;
    }
    """

    import ctypes
    GetDIBits = ctypes.windll.gdi32.GetDIBits
    DIB_RGB_COLORS = 0
    BI_RGB = 0

    bitmapInfo = BITMAPINFO()
    bitmapInfo.bmiHeader.biSize = ctypes.sizeof(BITMAPINFOHEADER)
    bitmapInfo.bmiHeader.biWidth = w
    bitmapInfo.bmiHeader.biHeight = -h
    bitmapInfo.bmiHeader.biPlanes = 1
    bitmapInfo.bmiHeader.biBitCount = 32
    bitmapInfo.bmiHeader.biCompression = BI_RGB
    bitmapInfo.bmiHeader.biSizeImage = w * h * 4

    from PySide.QtGui import QImage
    image = QImage(w, h, QImage.Format_ARGB32_Premultiplied)
    if image.isNull():
        return image

    # Get bitmap bits
    data = ctypes.create_string_buffer(bitmapInfo.bmiHeader.biSizeImage)

    if GetDIBits(hdc, h_bitmap, 0, h, ctypes.byref(data),
                 ctypes.byref(bitmapInfo), DIB_RGB_COLORS):
        # Create image and copy data into image.
        for y in range(h):
            dest = image.scanLine(y)

            src = data[y * image.bytesPerLine():y * image.bytesPerLine() +
                       image.bytesPerLine()]
            for i in range(image.bytesPerLine()):
                dest[i] = src[i]

    else:
        # qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits");
        print("qt_fromWinHBITMAP(), failed to get bitmap bits")

    return image