ajaybatta54
2019-8-28 10:17:01

@ajaybatta54 has joined the channel


samdphillips
2019-8-28 17:22:26

If I have a bitmap pict and I scale it, it appears that the pict is blurred/smoothed if I scale it. Is there a way to not have this behavior?


soegaard2
2019-8-28 17:22:58

Also if you scale it by a factor of exact 2 ?


samdphillips
2019-8-28 17:23:20

Hmm I was scaling it by exact 4


soegaard2
2019-8-28 17:23:27

Same thing.


samdphillips
2019-8-28 17:23:37

Just checking :slightly_smiling_face:


soegaard2
2019-8-28 17:23:44

There must be an option somewhere.


samdphillips
2019-8-28 17:24:14

I thought there was a parameter to control it. But I’m drawing a blank


soegaard2
2019-8-28 17:25:23

Is it a png?


samdphillips
2019-8-28 17:25:32

Yes.


samdphillips
2019-8-28 17:26:26

It’s a bitmap-section copy of a png


soegaard2
2019-8-28 17:30:23

So a simple (scale 4 (bitmap “foo.png”)) ?


samdphillips
2019-8-28 17:32:16

More like (scale (bitmap (copy-bitmap-section (read-bitmap “foo.png”) 0 0 96 96)) 4)


samdphillips
2019-8-28 17:33:24

copy-bitmap-section creates a new bitmap and uses draw-bitmap-section on it


soegaard2
2019-8-28 17:35:03

Can’t find it in the docs.


samdphillips
2019-8-28 17:36:53

It’s local to my code: (define (copy-bitmap-section src src-x src-y width height) (define new-bitmap (make-bitmap width height)) (define new-bitmap-dc (send new-bitmap make-dc)) (send new-bitmap-dc draw-bitmap-section src 0 0 src-x src-y width height) new-bitmap)


soegaard2
2019-8-28 17:47:24

I see it too.


soegaard2
2019-8-28 17:48:25

I think I see it without the copy-bitmap-section too.


soegaard2
2019-8-28 17:48:27

(scale (bitmap bm) 8 )


samdphillips
2019-8-28 17:49:17

Yeah, just wanted to make sure I wasn’t mucking it up


soegaard2
2019-8-28 17:49:58

Let’s see what happens if we scale it without using scale.


samdphillips
2019-8-28 17:52:31

The insides of the scale adjuster seems straightforward: https://github.com/racket/pict/blob/master/pict-lib/pict/private/utils.rkt#L1178


soegaard2
2019-8-28 18:00:04
(define (scaled-bitmap src k)
  (define w (send src get-width))
  (define h (send src get-height))
  (define new-bitmap (make-bitmap (* k w) (* k h)))
  (define new-bitmap-dc (send new-bitmap make-dc))
  (send new-bitmap-dc set-scale k k)
  (send new-bitmap-dc draw-bitmap src 0 0)
  new-bitmap)

samdphillips
2019-8-28 18:00:11

I feel like I may need to smuggle a set-smoothing into the scaling …


soegaard2
2019-8-28 18:00:15

Looks crisper.


samdphillips
2019-8-28 18:01:30

Cool.


soegaard2
2019-8-28 18:04:31

Weird. I have a smoothed and an aligned in metapict, but no unsmoothed.


samdphillips
2019-8-28 18:05:09

In DrRacket: > (dc (lambda (dc x0 y0) (displayln (send dc get-smoothing))) 10 10) unsmoothed aligned


soegaard2
2019-8-28 18:07:10
;; unsmoothed : pict -> pict
;;  Produces a pict like `p`, but that always draws in 'unsmoothed mode
(define (unsmoothed p)
  ; (define draw-p (make-pict-drawer p))
  (def p2
    (dc (lambda (dc x y)
          (def s (send dc get-smoothing))
          (send dc set-smoothing 'unsmoothed)
          ; (draw-p dc x y)
          (draw-pict p dc x y)
          (send dc set-smoothing s))
        (pict-width p)
        (pict-height p)))
  (make-pict (pict-draw p2)
             (pict-width p)
             (pict-height p)
             (pict-ascent p)
             (pict-descent p)
             (list (make-child p 0 0 1 1 0 0))
             #f
             (pict-last p)))

soegaard2
2019-8-28 18:13:59

It seems to me that it would have been better to have separate smoothing settings for bitmaps and path drawings.


soegaard2
2019-8-28 18:20:02

(scale (unsmoothed (bitmap (copy-bitmap-section bm 0 0 50 50))) 8)


samdphillips
2019-8-28 18:41:19

Thanks. That’s near what I was thinking.


ryanc
2019-8-28 20:39:20

@samdphillips Do you see the blurring if you wrap the bitmap pict with size-in-pixels before scaling?


samdphillips
2019-8-28 20:42:15

I’ll give that a try.


samdphillips
2019-8-28 21:24:27

@ryanc still blurry that way and squished a bit


samdphillips
2019-8-28 21:26:46

@soegaard2 unsmoothed works


samdphillips
2019-8-28 21:27:06

dotsond96
2019-8-28 22:50:42

@dotsond96 has joined the channel


samdphillips
2019-8-28 23:42:53

What is the reason for doing the copy in a dc pict and then copying it to the one that is returned?


joel
2019-8-29 00:08:53

@joel has joined the channel


soegaard2
2019-8-29 00:29:28

Good question. It’s to preserve the ascent and descent.


soegaard2
2019-8-29 00:31:16

Also p2 does not have the correct pict-last value.