问题
I am developing a PDF generator by using c++.
During in process, i have faced a big problem with image soft mask.
I put an image right side of PDF page as like above. The pink bear is a bitmap image and has alpha channel. However, it has not PDF mask yet.
After i succeed to put an image right way. i need to find a way to remove black background of the image. (a.k.a alpha processing)
I found that there are several options to archive it as like below.
- monochrome mask.
- stencil mask.
- soft mask.
My application has gradient images. Therefore, the soft mask method was the best for me. So, i implemented it as like below.
The black background of image was gone. It seems all things are good.
However, i realized that there is some artifacts when i zoomed in the result.
Left side is correct image with its alpha, right side is PDF result.
There are black noise around outlines of the bear.(click the image to show larger) When i put a rectangle image, i could find black lines around edge.
It seems like that RGB channels and A channel is not matched exactly.(It seems like A channels is bigger by 1~2 px)
I implement it as like below.
- I made an XObject (SMask)
8 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 693
/Height 972
/BitsPerComponent 8
/Filter /FlateDecode
/ColorSpace /DeviceGray
/Length 137856
>>
stream
- Linked the XObject to orignal image.
7 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 693
/Height 972
/BitsPerComponent 8
/Filter /FlateDecode
/ColorSpace /DeviceRGB
/SMask 8 0 R
/Length 261436
>>
stream
That is all i did. Do i have to do more things?
I spent a week to fix it. But, i still do not have any ideas even though i searched on google.
I attach the result file.
https://www.dropbox.com/s/09ggj28bhzi8f6e/Output.pdf?dl=0
Please, somebody give me piece of advice.
**** UPDATE ****
I made more simple version for testing.
I made a bitmap. And i drew a white rectangle left side of the image as like above. Right side is empty.
After putting the bitmap on PDF and applying soft mask by its alpha values, there is a black line at the edge of white rectangle. (Left side is drawn white rectangle. Right side is transparent.)
The bitmap's alpha channel is absolutely the same with above image. I have checked it on Photoshop. There is not any grey color in alpha channel and exactly matched with RGB channels each pixels.
I attach the PDF result.
Before soft masking
After soft masking
来源:https://stackoverflow.com/questions/62558338/pdf-image-soft-mask-artifacts