Error image read from windows clipboard (copy from chrome)

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Hi,

when trying to read from the clipboard an image copied from chrome, the image scrolls horizontally a few pixels.

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Error image read from windows clipboard (copy from chrome)

Post by snibgo »

Without more information, this is difficult to diagnose.

What version of IM? On what platform?

What software copies from Chrome? Is that a function in Chrome?

When other software reads from the clipboard (eg paste into Paint or Gimp), does this scrolling happen?

When other non-Chrome software copies image to the clipboard, and IM reads the clipboard, does this scrolling happen?
snibgo's IM pages: im.snibgo.com

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Both IM and Chrome are updated to the latest version.
IM: 7.0.8-67
Chrome 77.0.3865.90

Microsoft Paint paste ok
Adobe Photoshop paste ok
Everybody ok except IM.


IM Convert.exe also does it wrong.

If the image is copied by Internet Explorer, Firefox or another program, IM does well.

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Error image read from windows clipboard (copy from chrome)

Post by snibgo »

On what platform? Eg Windows 10, some version of Mac, some version of Unix.

Perhaps Chrome puts something into the clipboard that IM is ignoring. A developer would need to reproduce the problem.
snibgo's IM pages: im.snibgo.com

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Sorry, in WIndows 10.

User avatar
GeeMack
Posts: 754
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Error image read from windows clipboard (copy from chrome)

Post by GeeMack »

Windows 10 has an issue with the way it handles grayscale images in its clipboard that causes alignment problems for ImageMagick. Find a description of this problem from a couple years ago at THIS LINK. Possibly this is a related issue.

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

The error also happens with color images.
I have tried GraphicsMagick and it does well but I don't want to change libraries.

I love ImageMagick

Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Error image read from windows clipboard (copy from chrome)

Post by Jason S »

There seems to be at least one ImageMagick bug here. Its clipboard handler manufactures a BMP file header, but in that header it doesn't always set the bfOffBits field correctly. I'm referring to this line in coders/clipboard.c:

Code: Select all

  offset=((unsigned int) p[0])+BMP_HEADER_SIZE;
It ought to also add the size of the color table (for paletted images), and for BMPv3 images with compression=BI_BITFIELDS, 12 for the BITFIELDS segment.

The issue with Chrome seems like it must be the BITFIELDS part of this bug. But something doesn't make sense: It looks to me like IM would be acquiring the image in CF_DIBV5 format, while only CF_DIB format would lead to the bug. At the moment, I don't know what's going on.

User avatar
dlemstra
Posts: 1610
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Error image read from windows clipboard (copy from chrome)

Post by dlemstra »

Thanks for your research Jason. The code now assumes that there is no colormap so that could be an issue but I will take a look at that when that situation occurs. I just pushed a patch to fixed the issue for BMP3 (CF_DIB) images where the offset should be increased by 12. It looks like this also needs to happen for the CF_DIBV5 when the bits per pixel are 32 bit but I don't understand why.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Any solution?

User avatar
dlemstra
Posts: 1610
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Error image read from windows clipboard (copy from chrome)

Post by dlemstra »

As stated before I have no clue why this happens so I cannot fix this at this time.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Any news about this?

Thanks

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Temporary solution

Microsoft official documentation on the BITMAPINFOHEADER structure:
https://docs.microsoft.com/es-es/previo ... 6(v=vs.85)

The problem is when the compression is BI_BITFIELDS: "Specifies that the bitmap is not compressed and that the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bpp bitmaps "
I have checked that as long as they are 32 color bits and BI_BITFIELDS adding 3 DWORD to the color bit pointer works perfectly.

I paste a C ++ code in case it helps

Code: Select all

Image image;
try
{
	// Chapuza monumental hasta que Imagemagick arregle el portapapeles
	LPBITMAPINFO lpBI;
	LPBYTE pDIBBits;
	BOOL bReaded = FALSE;
	if (::IsClipboardFormatAvailable(CF_DIB))
	{
		::OpenClipboard(NULL);
		HANDLE hData = GetClipboardData(CF_DIB);
		lpBI = (LPBITMAPINFO)GlobalLock(hData);
		// Puntero a los pixeles
		pDIBBits = (LPBYTE)(lpBI->bmiColors);
		if ((lpBI->bmiHeader.biBitCount == 16 || lpBI->bmiHeader.biBitCount == 32) && lpBI->bmiHeader.biCompression == BI_BITFIELDS)
		{
			// Añadir 3 DWORD
			image.read(lpBI->bmiHeader.biWidth, lpBI->bmiHeader.biHeight, "BGRA", Magick::CharPixel, pDIBBits + 3 * sizeof(DWORD));
			image.flip();
			bReaded = TRUE;
		}
		else if (lpBI->bmiHeader.biBitCount == 24 && lpBI->bmiHeader.biCompression == BI_RGB)
		{
			image.read(lpBI->bmiHeader.biWidth, lpBI->bmiHeader.biHeight, "BGR", Magick::CharPixel, pDIBBits);
			image.flip();
			bReaded = TRUE;
		}

		GlobalUnlock(hData);
		::CloseClipboard();
	}
	if (!bReaded)
		image.read("clipboard:");
}
catch (Exception & error_)
{
	// Error....
}

User avatar
dlemstra
Posts: 1610
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Error image read from windows clipboard (copy from chrome)

Post by dlemstra »

I found a hack that can be used to work around this.The next version of ImageMagick will copy the image without any issues.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Portiella
Posts: 25
Joined: 2018-12-05T07:30:35-07:00
Authentication code: 1152

Re: Error image read from windows clipboard (copy from chrome)

Post by Portiella »

Thanks

Post Reply