<commit_before>#lang racket/base
(require ffi/unsafe
         racket/draw/unsafe/cairo
         racket/draw
         racket/draw/private/local
         racket/class
         "types.rkt"
         "utils.rkt"
         "const.rkt")

(provide
 (protect-out bitmap->hbitmap
              hbitmap->bitmap))

(define (bitmap->hbitmap bm 
                         #:mask [mask-bm #f]
                         #:b&w? [b&w? #f] 
                         #:bg [bg (GetSysColor COLOR_BTNFACE)])
  (let* ([w (send bm get-width)]
         [h (send bm get-height)]
         [mask-bm (or mask-bm
                      (send bm get-loaded-mask))]
         [to-frac (lambda (v) (/ v 255.0))]
         [screen-hdc (GetDC #f)]
         [hdc (CreateCompatibleDC screen-hdc)]
         [hbitmap (if b&w?
                      (CreateBitmap w h 1 1 #f)
                      (CreateCompatibleBitmap screen-hdc w h))]
         [old-hbitmap (SelectObject hdc hbitmap)])
    (ReleaseDC #f screen-hdc)
    (let* ([s (cairo_win32_surface_create hdc)]
           [cr (cairo_create s)])
      (cairo_surface_destroy s)<commit_msg>win32: fix problem with bitmap labels  related to PR 11566<commit_after>#lang racket/base
(require ffi/unsafe
         racket/draw/unsafe/cairo
         racket/draw
         racket/draw/private/local
         racket/class
	 "dc.rkt"
         "types.rkt"
         "utils.rkt"
         "const.rkt")

(provide
 (protect-out bitmap->hbitmap
              hbitmap->bitmap))

(define (bitmap->hbitmap bm 
                         #:mask [mask-bm #f]
                         #:b&w? [b&w? #f] 
                         #:bg [bg (GetSysColor COLOR_BTNFACE)])
  (let* ([w (send bm get-width)]
         [h (send bm get-height)]
	 [bm (if (bm . is-a? . win32-bitmap%)
		 ;; Windows wants to use the result bitmap
		 ;; as an ARGB bitmap, but Cairo seems to transfer
		 ;; RGB win32 bitmaps to RGB win32 bitmaps in a
		 ;; way that sometimes mangles the alpha; avoid the
		 ;; problem by first copying to a Cairo memory bitmap.
		 (let* ([new-b (make-object bitmap% w h #f #f)]
			[dc (make-object bitmap-dc% new-b)])
		   (send dc draw-bitmap bm 0 0)
		   (send dc set-bitmap #f)
		   new-b)
		 bm)]
         [mask-bm (or mask-bm
                      (send bm get-loaded-mask))]
         [to-frac (lambda (v) (/ v 255.0))]
         [screen-hdc (GetDC #f)]
         [hdc (CreateCompatibleDC screen-hdc)]
         [hbitmap (if b&w?
                      (CreateBitmap w h 1 1 #f)
                      (CreateCompatibleBitmap screen-hdc w h))]
         [old-hbitmap (SelectObject hdc hbitmap)])
    (ReleaseDC #f screen-hdc)
    (let* ([s (cairo_win32_surface_create hdc)]
           [cr (cairo_create s)])
      (cairo_surface_destroy s)
{'fraction_non_alphanumeric': 0.12513761467889908, 'fraction_numerical': 0.011376146788990826, 'mean_word_length': 1.7178464606181456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678549', 'n_tokens_mistral': 983, 'n_tokens_neox': 911, 'n_words': 246}