After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 142074 - Paste into 1x1 pixel image from buffer crashes GIMP 2.01
Paste into 1x1 pixel image from buffer crashes GIMP 2.01
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Tools
2.0.x
Other All
: Normal critical
: 2.2
Assigned To: GIMP Bugs
GIMP Bugs
: 147576 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-05-07 05:14 UTC by Adrel
Modified: 2004-12-11 01:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to allow you to get a TempBuf of a sub-section fo a Drawable. Untested. (4.57 KB, patch)
2004-09-09 20:23 UTC, Dave Neary
none Details | Review

Description Adrel 2004-05-07 05:14:53 UTC
1) Load Knoppix 3.4
2) Start GIMP v2.0 from the menu. K-> The GIMP (v2.0)
3) Take a screenshot using (GIMP) File->Acquire->Screenshot (whole screen option) 
4) Click screen to capture. I only did this to get something into the buffer
5) Select some of the screenshot using the select tool
6) IMPORTANT BIT -> Edit >> Copy the selection
7) IMPORTANT BIT -> File >> New (open a new image)
8) IMPORTANT BIT -> Set the height and width of the new image to 1pixel by 1pixel
9) IMPORTANT BIT -> Edit >> Paste 
10) There is no step 10 as GIMP has crashed and removed all windows.

Basically, get something in the buffer

Also works with:
A) Open and Select part of an existing image (edit >> copy)
B) Resize image to 1px by 1px
C) Edit >> Paste.

Thanks for istening.
Comment 1 Sven Neumann 2004-05-07 08:59:11 UTC
I can confirm this.
Comment 2 Sven Neumann 2004-05-07 09:10:39 UTC
Seems to be a bug in the preview code. It tries to allocate a gigantic preview:

  • #41 g_malloc
    from /usr/lib/libglib-2.0.so.0
  • #42 temp_buf_new
    at temp-buf.c line 190
  • #43 gimp_drawable_preview_private
    at gimpdrawable-preview.c line 161
  • #44 gimp_viewable_get_preview
    at gimpviewable.c line 505
  • #45 gimp_image_get_new_preview
    at gimpimage-preview.c line 253
  • #46 gimp_image_get_preview
    at gimpimage-preview.c line 134
  • #47 gimp_viewable_get_preview
    at gimpviewable.c line 505
  • #48 gimp_viewable_get_new_preview_pixbuf
    at gimpviewable.c line 660
  • #49 gimp_display_shell_update_icon
    at gimpdisplayshell.c line 1272
  • #50 gimp_display_shell_idle_update_icon
    at gimpdisplayshell-handlers.c line 662

Comment 3 Sven Neumann 2004-05-15 13:17:51 UTC
What's happening here is that in order to create a preview of the layer in the
image context (for the Layers dialog), the layer is first scaled up to correct
for the fact that the preview is larger than the image. Then an area from the
scaled preview is taken as the preview. A typical setup is to create a preview
of 32x32 pixels. That means the layer is scaled up 32 times. For a typical
screenshot size of 1024x786 the layer is scaled to a size of 32768 x 24576. That
would need about 3GB of memory.
Comment 4 weskaggs 2004-06-01 18:45:56 UTC
A trivial fix (or workaround) is to change line 171 of gimpimage-preview.c from

  ratio = (gdouble) width / (gdouble) gimage->width;

to

  ratio = MIN (1.0, (gdouble) width / (gdouble) gimage->width);

This causes previews for very small images to be shown at the actual image size
rather than scaled up.  The number 1.0 could be replaced with something larger
if one wanted to limit the amount of magnification without preventing it
completely.    If this kind of trickery is not acceptable, then it seems
necessary to clip each layer to the image dimensions before scaling it to create
the preview, and this would involve substantial complications.
Comment 5 Henrik Brix Andersen 2004-06-14 11:48:17 UTC
I think the proposed fix sounds sane. 
Comment 6 Sven Neumann 2004-06-14 13:45:09 UTC
To me the proposed fix sounds like a regression. I haven't tried the patch but
it seems to disable the feature that previews show a magnified view of very
small images. I know that people working on icons and such like this behaviour.
Comment 7 Sven Neumann 2004-07-14 13:54:45 UTC
*** Bug 147576 has been marked as a duplicate of this bug. ***
Comment 8 Sven Neumann 2004-07-14 13:56:36 UTC
Bug #147576 shows that this problem is not only triggered by pasting but can
also happen when loading an image.
Comment 9 Philip L 2004-07-16 20:47:32 UTC
Here's what sounds logical to me: isolate the section of the layer that's
actually within the image boundaries, then scale that to the preview size. I
don't understand why the entire layer is scaled before taking out that section.
Comment 10 Sven Neumann 2004-07-16 21:54:42 UTC
Yep, that's how it should be done.
Comment 11 Sven Neumann 2004-07-17 16:42:27 UTC
Moving all bugs remaining on the 2.0.3 milestone to 2.0.4.
Comment 12 Sven Neumann 2004-08-06 11:08:01 UTC
Moving remaining bugs from milestone 2.0.4 to milestone 2.0.4
Comment 13 Dave Neary 2004-09-07 19:09:01 UTC
Comment #9: Phillipe: The whole layer is scaled because it's not exactly trivial
to get just the part of the layer in the image bounds.

Alternative, perhaps easier to do, method is to check the scaling factor, and if
we're scaling up to do the preview, then to compose first, and scale the result. 

I agree though that the best thing to do is to clip the layers first. I just
have to figure out how to do that.

Source reference: app/core/gimpimage-preview, gimp_image_get_new_preview (lines
143 to 336)

The loop which is messing things up starts at line 225, which calls
gimp_viewable_get_preview(), which in turn resolves to the implementation
gimp_drawable_get_preview in gimpdrawable-preview.c, and there (I think) is
where the actual scaling is done.

I will spend some time looking at this this evening.

Cheers,
Dave.

Comment 14 Dave Neary 2004-09-08 21:57:32 UTC
I have gone round in circles with this a bit...

I believe the correct thing to do is 

- Request a TempBuf from a Viewable corresponding to offset x, y and size w, h
- Create a PixelRegion from this buffer with offset max(x,0), max(y, 0) 
- Merge the PixelRegions

The stuff that has been confusing me is the second bit - in
gimp_image_get_new_preview, everything is scaled already, and frankly I don't
understand how the scaling is done in gimp_drawable_get_preview_private. So all
of the PixBufs that you end up with are from scaled Viewables.

There is currently no API for the first bit. Should be easy, but currently it's
not there. Is adding something like that necessary? Is it appropriate for a
stable release? There doesn't appear to me to be a way to delegate the creation
of the relevant TempBuf to the drawable without this or some similar API.

In the meantime, I reccommend that we put in the trivial fix (which is a
regression) if (ratio > 1) as reccommended in comment #4.
Comment 15 weskaggs 2004-09-09 17:18:00 UTC
It's not like we're being flooded with complaints about this bug, so it seems
more reasonable to wait for a proper fix to evolve than to do something that
would be a regression.
Comment 16 Dave Neary 2004-09-09 20:23:33 UTC
Created attachment 31453 [details] [review]
Patch to allow you to get a TempBuf of a sub-section fo a Drawable. Untested.

Adding this unfinished bit of fluff here so that if I don't have time to do the
rest, siomeone else might like to have a go. It probably doesn't do what I
think it does, it's not tested at all, but it compiles.
Comment 17 Sven Neumann 2004-11-02 18:32:42 UTC
Moving all remaining bugs from the 2.0.6 milestone to 2.2.
Comment 18 Michael Natterer 2004-12-11 01:24:57 UTC
Fixed in CVS:

2004-12-11  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpdrawable-preview.[ch]: added new function
	gimp_drawable_get_sub_preview() which returns a scaled preview of
	a part of a drawable.

	(gimp_drawable_preview_scale): made it work with srcPR.x and
	srcPR.y being != 0.

	* app/core/gimpimage-preview.c (gimp_image_get_new_preview)
	* app/widgets/gimpviewrendererdrawable.c
	(gimp_view_renderer_drawable_render): if the area of the drawable
	preview is more than 4 times larger than the drawable itself (evil
	heuristic, but seems to work fine), use above function to get a
	sub-preview of the drawable instead of getting an insanely large
	preview of the whole drawable just to use a small part of it.
	Fixes bug #142074.

	* app/core/gimpimage-preview.c (gimp_image_get_new_preview):
	optimized by skipping layers which do not intersect with the
	canvas.