Public: Returns the phantom rasterize command
432780
def cmd
      cookie_file                       = dump_cookies
      format, zoom, margin, orientation = options[:format], options[:zoom], options[:margin], options[:orientation]
      rendering_time, timeout           = options[:rendering_time], options[:rendering_timeout]
      viewport_width, viewport_height   = options[:viewport_width], options[:viewport_height]
      max_redirect_count                = options[:max_redirect_count]
      @outfile                          ||= "#{options[:tmpdir]}/#{Digest::MD5.hexdigest((Time.now.to_i + rand(9001)).to_s)}.pdf"
      command_config_file               = "--config=#{options[:command_config_file]}"
      [
        Shrimp.configuration.phantomjs,
        command_config_file,
        SCRIPT_FILE,
        @source.to_s.shellescape,
        @outfile,
        format,
        zoom,
        margin,
        orientation,
        cookie_file,
        rendering_time,
        timeout,
        viewport_width,
        viewport_height,
        max_redirect_count
      ].join(" ")
    end
1100053
def block_reduce(self, block_size, how=np.ma.mean):
        '''
        
        '''
        raster2 = block_reduce(self.raster, block_size, func=how)
        geot = self.geot
        geot = (geot[0], block_size[0] * geot[1], geot[2], geot[3], geot[4],
                block_size[1] * geot[-1])
        return GeoRaster(raster2, geot, nodata_value=self.nodata_value,\
                        projection=self.projection, datatype=self.datatype)
1026964
def raster_statistics(raster_file):
        
        ds = gdal_Open(raster_file)
        band = ds.GetRasterBand(1)
        minv, maxv, meanv, std = band.ComputeStatistics(False)
        return minv, maxv, meanv, std
375919
def inpaint(self):
        

        import inpaint
        filled = inpaint.replace_nans(np.ma.filled(self.raster_data, np.NAN).astype(np.float32), 3, 0.01, 2)
        self.raster_data = np.ma.masked_invalid(filled)
1018280
def _print_image(self, line, size):
        
        i = 0
        cont = 0
        buffer = ""

       
        self._raw(S_RASTER_N)
        buffer = "%02X%02X%02X%02X" % (((size[0]/size[1])/8), 0, size[1], 0)
        self._raw(buffer.decode('hex'))
        buffer = ""

        while i < len(line):
            hex_string = int(line[i:i+8],2)
            buffer += "%02X" % hex_string
            i += 8
            cont += 1
            if cont % 4 == 0:
                self._raw(buffer.decode("hex"))
                buffer = ""
                cont = 0
1338924
def pixscale(self):
        
        try:
            (x, y) = self['NAXIS1'] / 2.0, self['NAXIS2'] / 2.0
            p1 = SkyCoord(*self.wcs.xy2sky(x, y) * units.degree)
            p2 = SkyCoord(*self.wcs.xy2sky(x + 1, y + 1) * units.degree)
            return round(p1.separation(p2).to(units.arcsecond).value / math.sqrt(2), 3)
        except Exception as ex:
            logging.debug("Failed to compute PIXSCALE using WCS: {}".format(ex))

        return float(self['PIXSCAL'])
376420
def get_frag_shader(volumes, clipped=False, n_volume_max=5):
    

    declarations = ""
    before_loop = ""
    in_loop = ""
    after_loop = ""

    for index in range(n_volume_max):
        declarations += "uniform $sampler_type u_volumetex_{0:d};\n".format(index)
        before_loop += "dummy = $sample(u_volumetex_{0:d}, loc).g;\n".format(index)

    declarations += "uniform $sampler_type dummy1;\n"
    declarations += "float dummy;\n"

    for label in sorted(volumes):

        index = volumes[label]['index']

        # Global declarations
        declarations += "uniform float u_weight_{0:d};\n".format(index)
        declarations += "uniform int u_enabled_{0:d};\n".format(index)

        # Declarations before the raytracing loop
        before_loop += "float max_val_{0:d} = 0;\n".format(index)

        # Calculation inside the main raytracing loop

        in_loop += "if(u_enabled_{0:d} == 1) {{\n\n".format(index)

        if clipped:
            in_loop += ("if(loc.r > u_clip_min.r && loc.r < u_clip_max.r &&\n"
                        "   loc.g > u_clip_min.g && loc.g < u_clip_max.g &&\n"
                        "   loc.b > u_clip_min.b && loc.b < u_clip_max.b) {\n\n")

        in_loop += "// Sample texture for layer {0}\n".format(label)
        in_loop += "val = $sample(u_volumetex_{0:d}, loc).g;\n".format(index)

        if volumes[label].get('multiply') is not None:
            index_other = volumes[volumes[label]['multiply']]['index']
            in_loop += ("if (val != 0) {{ val *= $sample(u_volumetex_{0:d}, loc).g; }}\n"
                        .format(index_other))

        in_loop += "max_val_{0:d} = max(val, max_val_{0:d});\n\n".format(index)

        if clipped:
            in_loop += "}\n\n"

        in_loop += "}\n\n"

        # Calculation after the main loop

        after_loop += "// Compute final color for layer {0}\n".format(label)
        after_loop += ("color = $cmap{0:d}(max_val_{0:d});\n"
                       "color.a *= u_weight_{0:d};\n"
                       "total_color += color.a * color;\n"
                       "max_alpha = max(color.a, max_alpha);\n"
                       "count += color.a;\n\n").format(index)

    if not clipped:
        before_loop += "\nfloat val3 = u_clip_min.g + u_clip_max.g;\n\n"

    # Code esthetics
    before_loop = indent(before_loop, " " * 4).strip()
    in_loop = indent(in_loop, " " * 16).strip()
    after_loop = indent(after_loop, " " * 4).strip()

    return FRAG_SHADER.format(declarations=declarations,
                              before_loop=before_loop,
                              in_loop=in_loop,
                              after_loop=after_loop)
427392
def smudgeraw(target, offset, magicbytes):
    
    magicbytes = magicbytes.replace('\\x', '').decode('hex')

    _backup_bytes(target, offset, len(magicbytes))
    _smudge_bytes(target, offset, magicbytes)
305813
def apply(self, func, *args, **kwargs):
        '''
        
        '''
        return func(self.raster, *args, **kwargs)
537421
def get_mask_from_raster(rasterfile, outmaskfile, keep_nodata=False):
        
        raster_r = RasterUtilClass.read_raster(rasterfile)
        xsize = raster_r.nCols
        ysize = raster_r.nRows
        nodata_value = raster_r.noDataValue
        srs = raster_r.srs
        x_min = raster_r.xMin
        y_max = raster_r.yMax
        dx = raster_r.dx
        data = raster_r.data

        if not keep_nodata:
            i_min = ysize - 1
            i_max = 0
            j_min = xsize - 1
            j_max = 0
            for i in range(ysize):
                for j in range(xsize):
                    if abs(data[i][j] - nodata_value) > DELTA:
                        i_min = min(i, i_min)
                        i_max = max(i, i_max)
                        j_min = min(j, j_min)
                        j_max = max(j, j_max)

            # print(i_min, i_max, j_min, j_max)
            y_size_mask = i_max - i_min + 1
            x_size_mask = j_max - j_min + 1
            x_min_mask = x_min + j_min * dx
            y_max_mask = y_max - i_min * dx
        else:
            y_size_mask = ysize
            x_size_mask = xsize
            x_min_mask = x_min
            y_max_mask = y_max
            i_min = 0
            j_min = 0
        print('%dx%d -> %dx%d' % (xsize, ysize, x_size_mask, y_size_mask))

        mask = numpy.zeros((y_size_mask, x_size_mask))

        for i in range(y_size_mask):
            for j in range(x_size_mask):
                if abs(data[i + i_min][j + j_min] - nodata_value) > DELTA:
                    mask[i][j] = 1
                else:
                    mask[i][j] = DEFAULT_NODATA

        mask_geotrans = [x_min_mask, dx, 0, y_max_mask, 0, -dx]
        RasterUtilClass.write_gtiff_file(outmaskfile, y_size_mask, x_size_mask, mask,
                                         mask_geotrans, srs, DEFAULT_NODATA, GDT_Int32)
        return Raster(y_size_mask, x_size_mask, mask, DEFAULT_NODATA, mask_geotrans, srs)
685252
def transformation_command
      scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
      trans = []
      trans << "-resize" << %["#{scale}"] unless scale.nil? || scale.empty?
      trans << "-crop" << %["#{crop}"] << "+repage" if crop
      trans
    end
317550
def as_png_data_uri(matrix, version, scale=1, border=None, color='#000',
                    background='#fff', compresslevel=9, addad=True):
    
    buff = io.BytesIO()
    write_png(matrix, version, buff, scale=scale, border=border, color=color,
              background=background, compresslevel=compresslevel, addad=addad)
    return 'data:image/png;base64,{0}' \
                .format(base64.b64encode(buff.getvalue()).decode('ascii'))
691545
public final WritableRaster filter(final Raster pSource, WritableRaster pDest, IndexColorModel pColorModel) {
        int width = pSource.getWidth();
        int height = pSource.getHeight();

        if (pDest == null) {
            pDest = createCompatibleDestRaster(pSource, pColorModel);
        }

        // temp buffers
        final int[] inRGB = new int[4];
        Object pixel = null;

        // TODO: Use getPixels instead of getPixel for better performance?

        // Loop through image data
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                // Get rgb from original raster
                // DON'T KNOW IF THIS WILL WORK FOR ALL TYPES..?
                pSource.getPixel(x, y, inRGB);

                // Get pixel value...
                // It is VERY important that we are using an IndexColorModel that
                // support reverse color lookup for speed.
                pixel = pColorModel.getDataElements(toIntARGB(inRGB), pixel);

                // And set it
                pDest.setDataElements(x, y, pixel);
            }
        }

        return pDest;
    }
957081
function getPixelHeights(tableGrid) {

        var rows = getRowBlocks(tableGrid);

        var backups = Tools.map(rows, function (row) {
          return getTopEdge(row.rowIndex, row.element).y;
        });

        var heights = [];

        for (var i = 0; i < rows.length; i++) {
          var span = rows[i].element.hasAttribute('rowspan') ? parseInt(rows[i].element.getAttribute('rowspan'), 10) : 1;

          var height = span > 1 ? deduceSize(backups, i) : getPixelHeight(rows[i].element);

          height = height ? height : RESIZE_MINIMUM_HEIGHT;
          heights.push(height);
        }

        return heights;
      }
155147
def _get_dpi_from(cmd, pattern, func):
    
    try:
        out, _ = run_subprocess([cmd])
    except (OSError, CalledProcessError):
        pass
    else:
        match = re.search(pattern, out)
        if match:
            return func(*map(float, match.groups()))
916865
function(args) {

                var tpl = 'SVGFEDropShadowElement' in window
                    ? '<filter><feDropShadow stdDeviation="${blur}" dx="${dx}" dy="${dy}" flood-color="${color}" flood-opacity="${opacity}"/></filter>'
                    : '<filter><feGaussianBlur in="SourceAlpha" stdDeviation="${blur}"/><feOffset dx="${dx}" dy="${dy}" result="offsetblur"/><feFlood flood-color="${color}"/><feComposite in2="offsetblur" operator="in"/><feComponentTransfer><feFuncA type="linear" slope="${opacity}"/></feComponentTransfer><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter>';

                return joint.util.template(tpl)({
                    dx: args.dx || 0,
                    dy: args.dy || 0,
                    opacity: Number.isFinite(args.opacity) ? args.opacity : 1,
                    color: args.color || 'black',
                    blur: Number.isFinite(args.blur) ? args.blur : 4
                });
            }
404893
static BufferedImage gaussianBlur(BufferedImage src, BufferedImage dst, int radius) {
        int width  = src.getWidth();
        int height = src.getHeight();

        if (dst == null || dst.getWidth() != width || dst.getHeight() != height || src.getType() != dst.getType()) {
            dst = createColorModelCompatibleImage(src);
        }

        float[] kernel = createGaussianKernel(radius);

        if (src.getType() == BufferedImage.TYPE_INT_ARGB) {
            int[] srcPixels = new int[width * height];
            int[] dstPixels = new int[width * height];

            getPixels(src, 0, 0, width, height, srcPixels);

            // horizontal pass
            blur(srcPixels, dstPixels, width, height, kernel, radius);

            // vertical pass
            // noinspection SuspiciousNameCombination
            blur(dstPixels, srcPixels, height, width, kernel, radius);

            // the result is now stored in srcPixels due to the 2nd pass
            setPixels(dst, 0, 0, width, height, srcPixels);
        } else if (src.getType() == BufferedImage.TYPE_BYTE_GRAY) {
            byte[] srcPixels = new byte[width * height];
            byte[] dstPixels = new byte[width * height];

            getPixels(src, 0, 0, width, height, srcPixels);

            // horizontal pass
            blur(srcPixels, dstPixels, width, height, kernel, radius);

            // vertical pass
            // noinspection SuspiciousNameCombination
            blur(dstPixels, srcPixels, height, width, kernel, radius);

            // the result is now stored in srcPixels due to the 2nd pass
            setPixels(dst, 0, 0, width, height, srcPixels);
        } else {
            throw new IllegalArgumentException("EffectUtils.gaussianBlur() src image is not a supported type, type=[" + src.getType()
                                               + "]");
        }

        return dst;
    }