Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Help stamp out Mickey-Mouse computer interfaces -- Menus are for Restaurants!


devel / comp.lang.c / Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

SubjectAuthor
* Running into problems while trying to scale Cairo surface to take upBlue-Maned_Hawk
`* Re: Running into problems while trying to scale Cairo surface to take up maximumBen Bacarisse
 `* Re: Running into problems while trying to scale Cairo surface to takeBlue-Maned_Hawk
  `* Re: Running into problems while trying to scale Cairo surface to takeBart
   +* Re: Running into problems while trying to scale Cairo surface toKaz Kylheku
   |`- Re: Running into problems while trying to scale Cairo surface to takeBart
   `- Re: Running into problems while trying to scale Cairo surface to take up maximumBen Bacarisse

1
Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<u657o3$2pqan$1@bluemanedhawk.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25885&group=comp.lang.c++#25885

  copy link   Newsgroups: comp.lang.c
 by: Blue-Maned_Hawk - Sun, 11 Jun 2023 19:36 UTC


​Hello!
I'm looking for help with a problem i'm running into with the Cairo
graphics library. I want to paint a surface onto another surface (in
this case an XLib window) in such a way that it will take up as much
space as possible while staying at a 4:3 aspect ratio and be centered
within the window. However, i seemingly can't figure out the right
parameters for cairo_scale(), and am running into issues with a
stretched image and an image that doesn't take up the right amount of space.
Minimum example program demonstrating this behavior below; compile with
`$CC tmp.c -lX11 -lm -lcairo`. Rescale the window and you'll see the
problem i'm facing. (I am fully aware this will lead to a pixelated
output [not visible in the example program where it's just pure white];
this is intentional and exactly what i want to happen.)
#include <X11/Xlib.h>
#include <cairo/cairo.h>
#include <cairo/cairo-xlib.h>
#include <stddef.h>
#include <math.h>
const int width = 640, height = 480;
const long double aspect_ratio = 4.0l/3.0l, inverse_aspect_ratio =
3.0l/4.0l;
int main(void)
{
Display * display = XOpenDisplay(NULL);
int screen = DefaultScreen(display);
Window window = XCreateSimpleWindow(display, RootWindow(display,
screen), 10, 10, width, height, 1, BlackPixel(display, screen),
WhitePixel(display, screen));
XSelectInput(display, window, StructureNotifyMask);
XMapWindow(display, window);
cairo_surface_t * surface = cairo_xlib_surface_create(display, window,
DefaultVisual(display, screen), width, height);
cairo_xlib_surface_set_size(surface, width, height);
cairo_t * root_instance = cairo_create(surface);
cairo_surface_destroy(surface);
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t * instance = cairo_create(surface);
cairo_set_source_rgb(instance, 1, 1, 1);
cairo_paint(instance);
for (;;) {
for (XEvent e; XPending(display) != 0; XNextEvent(display, &e))
if (e.type == ConfigureNotify) {
cairo_identity_matrix(root_instance);
if (e.xconfigure.width < width || e.xconfigure.height < height) {
XResizeWindow(display, window, fmax(width, e.xconfigure.width),
fmax(width, e.xconfigure.height));
cairo_xlib_surface_set_size(cairo_get_target(root_instance),
fmax(width, e.xconfigure.width), fmax(height, e.xconfigure.height));
} else {
cairo_xlib_surface_set_size(cairo_get_target(root_instance),
e.xconfigure.width, e.xconfigure.height);
if (e.xconfigure.width >= aspect_ratio * e.xconfigure.height) {
cairo_translate(root_instance, (e.xconfigure.width -
e.xconfigure.height * aspect_ratio) / 2, 0);
cairo_scale(root_instance, (e.xconfigure.height * aspect_ratio) /
width, e.xconfigure.height / height);
} else {
cairo_translate(root_instance, 0, (e.xconfigure.height -
e.xconfigure.width * inverse_aspect_ratio) / 2);
cairo_scale(root_instance, e.xconfigure.width / width,
(e.xconfigure.height * inverse_aspect_ratio) / height);
}
}
}
cairo_push_group(root_instance);
cairo_set_source_rgb(root_instance, 0, 0, 0);
cairo_paint(root_instance);
cairo_set_source_surface(root_instance, surface, 0, 0);
cairo_paint(root_instance);
cairo_pop_group_to_source(root_instance); cairo_paint(root_instance);
cairo_surface_flush(cairo_get_target(root_instance));
}
}
--
⚗︎ | /blu.mɛin.dʰak/ | shortens to "Hawk" | he/him/his/himself/Mr.
bluemanedhawk.github.io
Bitches stole my whole ass ␔🭖᷿᪳𝼗᷍⏧𒒫𐻾ࣛ↉�⃣ quoted-printable, can't
have shit in Thunderbird 😩

Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<878rcpy560.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25888&group=comp.lang.c++#25888

  copy link   Newsgroups: comp.lang.c
 by: Ben Bacarisse - Sun, 11 Jun 2023 23:01 UTC

Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:

> I'm looking for help with a problem i'm running into with the Cairo
> graphics library.

Have you posted this anywhere that it's topical? I'd be happy to say
what's wrong in some other group, but none of the problems in the code
have anything to do with the C language. Does comp.graphics.misc still
exist?

--
Ben.

Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<u65k9n$2r139$1@bluemanedhawk.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25889&group=comp.lang.c++#25889

  copy link   Newsgroups: comp.lang.c
 by: Blue-Maned_Hawk - Sun, 11 Jun 2023 23:10 UTC

On 6/11/23 19:01, Ben Bacarisse wrote:
> Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:
>
>> I'm looking for help with a problem i'm running into with the Cairo
>> graphics library.
>
> Have you posted this anywhere that it's topical? I'd be happy to say
> what's wrong in some other group, but none of the problems in the code
> have anything to do with the C language. Does comp.graphics.misc still
> exist?
>
​Ah, i hadn't realized this wasn't appropriate for this group. I'll try
the group you suggested. Thank you for redirecting me, and apologies
for the inconvenience.
--
⚗︎ | /blu.mɛin.dʰak/ | shortens to "Hawk" | he/him/his/himself/Mr.
bluemanedhawk.github.io
Bitches stole my whole ass ␔🭖᷿᪳𝼗᷍⏧𒒫𐻾ࣛ↉�⃣ quoted-printable, can't
have shit in Thunderbird 😩

Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<u67ee0$35920$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25926&group=comp.lang.c++#25926

  copy link   Newsgroups: comp.lang.c
 by: Bart - Mon, 12 Jun 2023 15:42 UTC

On 12/06/2023 00:10, Blue-Maned_Hawk wrote:
> On 6/11/23 19:01, Ben Bacarisse wrote:
>> Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:
>>
>>> I'm looking for help with a problem i'm running into with the Cairo
>>> graphics library.
>>
>> Have you posted this anywhere that it's topical?  I'd be happy to say
>> what's wrong in some other group, but none of the problems in the code
>> have anything to do with the C language.  Does comp.graphics.misc still
>> exist?
>>
>
> ​Ah, i hadn't realized this wasn't appropriate for this group.  I'll try
> the group you suggested.  Thank you for redirecting me, and apologies
> for the inconvenience.
>

This Reddit forum:

https://www.reddit.com/r/C_Programming/

despite being moderated, is not so bothered about somewhat off-topic
posts, and is much busier than this one with more people who can help,
or who can direct you to a specialist subreddit.

Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<20230612093057.635@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25929&group=comp.lang.c++#25929

  copy link   Newsgroups: comp.lang.c
 by: Kaz Kylheku - Mon, 12 Jun 2023 16:31 UTC

On 2023-06-12, Bart <bc@freeuk.com> wrote:
> This Reddit forum:
>
> https://www.reddit.com/r/C_Programming/
>
> despite being moderated, is not so bothered about somewhat off-topic
> posts, and is much busier than this one with more people who can help,
> or who can direct you to a specialist subreddit.

When it does get bothered, you will be kicked out. You know that, which
is why you're here, right?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<87zg54ttlm.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25932&group=comp.lang.c++#25932

  copy link   Newsgroups: comp.lang.c
 by: Ben Bacarisse - Mon, 12 Jun 2023 18:37 UTC

Bart <bc@freeuk.com> writes:

> On 12/06/2023 00:10, Blue-Maned_Hawk wrote:
>> On 6/11/23 19:01, Ben Bacarisse wrote:
>>> Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:
>>>
>>>> I'm looking for help with a problem i'm running into with the Cairo
>>>> graphics library.
>>>
>>> Have you posted this anywhere that it's topical?  I'd be happy to say
>>> what's wrong in some other group, but none of the problems in the code
>>> have anything to do with the C language.  Does comp.graphics.misc still
>>> exist?
>>>
>> ​Ah, i hadn't realized this wasn't appropriate for this group.  I'll try
>> the group you suggested.  Thank you for redirecting me, and apologies for
>> the inconvenience.
>
> This Reddit forum:

.... meanwhile the OP has posted in a suitable news group and been
answered. Usenet my be dying, but if more people tried to make it work
it could still beat all the alternatives hands down.

--
Ben.

Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio

<u67pfi$36knq$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25933&group=comp.lang.c++#25933

  copy link   Newsgroups: comp.lang.c
 by: Bart - Mon, 12 Jun 2023 18:51 UTC

On 12/06/2023 17:31, Kaz Kylheku wrote:
> On 2023-06-12, Bart <bc@freeuk.com> wrote:
>> This Reddit forum:
>>
>> https://www.reddit.com/r/C_Programming/
>>
>> despite being moderated, is not so bothered about somewhat off-topic
>> posts, and is much busier than this one with more people who can help,
>> or who can direct you to a specialist subreddit.
>
> When it does get bothered, you will be kicked out. You know that, which
> is why you're here, right?
>

If I'd got kicked out, I probably wouldn't be recommending it.

It's harder to recommend usenet groups, since most are overrun by spam,
are moribund, or dominated by nutters.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor