… | |
… | |
141 | return ((align + 100) * smaller / 100) - image_size; |
141 | return ((align + 100) * smaller / 100) - image_size; |
142 | return 0; |
142 | return 0; |
143 | } |
143 | } |
144 | |
144 | |
145 | static inline void |
145 | static inline void |
146 | make_clip_rectangle (int pos, int size, int target_size, short &clip_pos, unsigned short &clip_size) |
146 | make_clip_rectangle (int pos, int size, int target_size, int &clip_pos, int &clip_size) |
147 | { |
147 | { |
|
|
148 | if (size <= 0) |
|
|
149 | { /* special case - tiling */ |
|
|
150 | clip_pos = pos; |
|
|
151 | clip_size = target_size; |
|
|
152 | } |
148 | if (pos < 0) |
153 | else if (pos < 0) |
149 | { |
154 | { |
150 | clip_pos = 0; |
155 | clip_pos = 0; |
151 | clip_size = MIN (target_size, size + pos); |
156 | clip_size = MIN (target_size, size + pos); |
152 | } |
157 | } |
153 | else |
158 | else |
… | |
… | |
351 | // flags, h_scale, v_scale, h_align, v_align); |
356 | // flags, h_scale, v_scale, h_align, v_align); |
352 | return (changed > 0); |
357 | return (changed > 0); |
353 | } |
358 | } |
354 | |
359 | |
355 | #ifdef HAVE_AFTERIMAGE |
360 | #ifdef HAVE_AFTERIMAGE |
356 | ASImage * |
361 | bool |
357 | bgPixmap_t::resize_asim (rxvt_term *target, ASImage *background, XRectangle &dst_rect) |
362 | bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) |
358 | { |
363 | { |
359 | if (original_asim == NULL || target == NULL) |
364 | if (target == NULL) |
360 | return NULL; |
365 | return false; |
361 | |
366 | |
362 | int target_width = (int)target->szHint.width; |
367 | int target_width = (int)target->szHint.width; |
363 | int target_height = (int)target->szHint.height; |
368 | int target_height = (int)target->szHint.height; |
|
|
369 | int new_pmap_width = target_width, new_pmap_height = target_height; |
|
|
370 | ASImage *result = NULL; |
|
|
371 | |
|
|
372 | int x = 0; |
|
|
373 | int y = 0; |
364 | int w = h_scale * target_width / 100; |
374 | int w = h_scale * target_width / 100; |
365 | int h = v_scale * target_height / 100; |
375 | int h = v_scale * target_height / 100; |
366 | int x = make_align_position (h_align, target_width, w); |
|
|
367 | int y = make_align_position (v_align, target_height, h); |
|
|
368 | |
376 | |
|
|
377 | if (original_asim) |
|
|
378 | { |
|
|
379 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
380 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
381 | } |
|
|
382 | |
|
|
383 | int dst_x, dst_y; |
|
|
384 | int clip_width, clip_height; |
|
|
385 | |
369 | make_clip_rectangle (x, w, target_width, dst_rect.x, dst_rect.width); |
386 | make_clip_rectangle (x, w, target_width, dst_x, clip_width); |
370 | make_clip_rectangle (y, h, target_height, dst_rect.y, dst_rect.height); |
387 | make_clip_rectangle (y, h, target_height, dst_y, clip_height); |
371 | |
388 | |
372 | /* TODO : actuall scaling code :) */ |
389 | /* TODO : actuall scaling code :) */ |
|
|
390 | if (dst_x >= target_width || dst_y >= target_height |
|
|
391 | || clip_width <= 0 || clip_height <= 0 || original_asim == NULL) |
|
|
392 | { |
|
|
393 | result = background; |
|
|
394 | dst_x = dst_y = 0; |
|
|
395 | if (background) |
|
|
396 | { |
|
|
397 | new_pmap_width = clip_width = background->width; |
|
|
398 | new_pmap_height = clip_height = background->height; |
|
|
399 | } |
|
|
400 | else |
|
|
401 | new_pmap_width = new_pmap_height = 0; |
|
|
402 | } |
|
|
403 | else |
|
|
404 | { |
|
|
405 | result = original_asim; |
|
|
406 | if ((w > 0 && w != original_asim->width) |
|
|
407 | || (h > 0 && h != original_asim->height)) |
|
|
408 | { |
|
|
409 | result = scale_asimage (target->asv, original_asim, |
|
|
410 | w > 0 ? w : original_asim->width, |
|
|
411 | h > 0 ? h : original_asim->height, |
|
|
412 | background ? ASA_ASImage : ASA_XImage, |
|
|
413 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
414 | } |
|
|
415 | if (background == NULL) |
|
|
416 | {/* if tiling - pixmap has to be sized exactly as the image */ |
|
|
417 | if (h_scale == 0) |
|
|
418 | new_pmap_width = result->width; |
|
|
419 | if (v_scale == 0) |
|
|
420 | new_pmap_height = result->height; |
|
|
421 | } |
|
|
422 | else |
|
|
423 | {/* if blending background and image - pixmap has to be sized same as target window */ |
|
|
424 | ASImageLayer *layers = create_image_layers (2); |
|
|
425 | ASImage *merged_im = NULL; |
373 | |
426 | |
|
|
427 | layers[0].im = background; |
|
|
428 | layers[0].clip_width = target_width; |
|
|
429 | layers[0].clip_height = target_height; |
|
|
430 | layers[0].tint = background_tint; |
|
|
431 | layers[1].im = result; |
|
|
432 | if (w <= 0) |
|
|
433 | {/* tile horizontally */ |
|
|
434 | layers[1].dst_x = dst_x - (int)result->width; |
|
|
435 | layers[1].clip_width = result->width; |
|
|
436 | } |
|
|
437 | else |
|
|
438 | {/* clip horizontally */ |
|
|
439 | layers[1].dst_x = dst_x; |
|
|
440 | layers[1].clip_width = clip_width; |
|
|
441 | } |
|
|
442 | if (h <= 0) |
|
|
443 | { |
|
|
444 | layers[1].dst_y = dst_y - (int)result->height; |
|
|
445 | layers[1].clip_height = result->height; |
|
|
446 | } |
|
|
447 | else |
|
|
448 | { |
|
|
449 | layers[1].dst_y = dst_y; |
|
|
450 | layers[1].clip_height = clip_height; |
|
|
451 | } |
|
|
452 | if (target->rs[Rs_blendtype]) |
|
|
453 | { |
|
|
454 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
|
|
455 | if (layers[1].merge_scanlines == NULL) |
|
|
456 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
457 | } |
|
|
458 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
|
|
459 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
460 | if (tmp) |
|
|
461 | { |
|
|
462 | if (result != original_asim) |
|
|
463 | destroy_asimage (&result); |
|
|
464 | result = tmp; |
|
|
465 | dst_x = dst_y = 0; |
|
|
466 | clip_width = target_width; |
|
|
467 | clip_height = target_height; |
|
|
468 | } |
|
|
469 | free (layers); |
|
|
470 | } |
|
|
471 | } |
|
|
472 | |
|
|
473 | if (pixmap) |
|
|
474 | { |
|
|
475 | if (result == NULL |
|
|
476 | || pmap_width != new_pmap_width |
|
|
477 | || pmap_height != new_pmap_height |
|
|
478 | || pmap_depth != target->depth) |
|
|
479 | { |
|
|
480 | XFreePixmap (target->dpy, pixmap); |
|
|
481 | pixmap = None; |
|
|
482 | } |
|
|
483 | } |
|
|
484 | |
|
|
485 | if (result) |
|
|
486 | { |
|
|
487 | XGCValues gcv; |
|
|
488 | GC gc; |
|
|
489 | |
|
|
490 | /* create Pixmap */ |
|
|
491 | if (pixmap == None) |
|
|
492 | { |
|
|
493 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
494 | pmap_width = new_pmap_width; |
|
|
495 | pmap_height = new_pmap_height; |
|
|
496 | pmap_depth = target->depth; |
|
|
497 | } |
|
|
498 | /* fill with background color ( if result's not completely overlapping it)*/ |
|
|
499 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
500 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
501 | |
|
|
502 | if (dst_x > 0 || dst_y > 0 |
|
|
503 | || dst_x + clip_width < new_pmap_width |
|
|
504 | || dst_y + clip_height < new_pmap_height) |
|
|
505 | { |
|
|
506 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
507 | } |
|
|
508 | /* put result on pixmap */ |
|
|
509 | asimage2drawable (target->asv, pixmap, result, gc, 0, 0, dst_x, dst_y, clip_width, clip_height, True); |
|
|
510 | |
|
|
511 | /* set target's background to pixmap */ |
|
|
512 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
513 | |
|
|
514 | XFreeGC (target->dpy, gc); |
|
|
515 | } |
|
|
516 | else |
|
|
517 | { |
|
|
518 | /* set target background to a pixel */ |
|
|
519 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
520 | } |
|
|
521 | |
|
|
522 | return true; |
374 | } |
523 | } |
375 | #endif |
524 | #endif |
376 | |
525 | |
377 | void |
526 | void |
378 | rxvt_term::resize_pixmap () |
527 | rxvt_term::resize_pixmap () |