Downsampling bitmaps from RSVG quality

Samuel Williams <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAHkN8V9_KLKEuFVZwcg5HkyKtRJjj=rOC61kGGcH=_7-fwRqYw@mail.gmail.com>
Hi.

I'm resizing and generating PNGs from SVG inputs.

I want the best possible quality but the downsampling of large input images
to small output images seems to be quite crude.

I've tried looking at how to use set_filter but it's not obvious how to use
this in conjunction with RSVG's render_rsvg_handle. I tried rendering to a
recording surface and then using a surface pattern with a filter set but
that didn't help. Here is an example of the Ruby code:

def save_surface_to_png(input_surface, output_path, size)
width, height = *size
 surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, width, height)
context = Cairo::Context.new(surface)
context.antialias = Cairo::ANTIALIAS_SUBPIXEL
 pattern = Cairo::SurfacePattern.new(input_surface)
pattern.set_filter(Cairo::FILTER_BEST)
 context.set_source(pattern)
context.rectangle(0,0,width,height)
context.fill
 context.target.write_to_png(output_path.to_s)
 surface.finish
end

def convert_svg_to_png_cairo(input_path, output_path, size)
puts "#{input_path} -> #{output_path}"
width, height = *size
 surface = Cairo::RecordingSurface.new(0, 0, width, height)
context = Cairo::Context.new(surface)
context.antialias = Cairo::ANTIALIAS_SUBPIXEL
 svg_handle = RSVG::Handle.new_from_file(input_path.to_s)
 svg_dimensions = svg_handle.dimensions
scale_factor = size[0].to_f / svg_dimensions.width.to_f
 context.scale(scale_factor, scale_factor)
 context.render_rsvg_handle(svg_handle)
 context.show_page
 save_surface_to_png(surface, output_path, size)
 surface.finish
end


It's not entirely obvious what I'm doing wrong or if it's even possible. Is
there some way to set the filter quality used by RSVG?

Thanks
Samuel

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.