Posts: 12
Threads: 2
Joined: Jan 2021
Reputation:
0
Gimp version: 2.10
11-05-2022, 02:37 AM
(This post was last modified: 11-05-2022, 03:26 AM by bitrat.)
Hi,
in CorelDraw, it is (was?) possible to render a one bit (b&w) image as an arbitrary solid colour for black and transparent for white. Note that this involved no blending or increase in bit width of the image.
I'm trying to do the same thing with GIMP and Inkscape (which sadly lacks this incredibly useful and probably not too difficult to implement feature).
So far all I've managed is an RGBA exported to png with a constant RGB and a high contrast alpha. It seems to be impossible to prevent some degree of 'anti-aliasing'.
I can import this into Inkscape and lay it over a coloured background, but when I export it, it's alpha blended, even though I didn't ask for that. Again, it seems to be impossible to prevent 'anti-aliasing'.
Also, for some reason, Inkscape adds a transparency checker pattern to the background (which is not visible in the edit window).
Surely there's a way to create a one bit transparency in GIMP and render it in colour in Inkscape, then export it without alpha or checkers!
Even better would probably be to do it all in GIMP, but I still need the absence of blending, just the one bit transparency.
UPDATE: I've figured out how to do this in GIMP, but I'd still really like to know if and how I can create and export a one bit colour + transparency image.
Heelp me.... heelp meee... pleeezzzzz.....
bitrat
Posts: 1,147
Threads: 178
Joined: Sep 2018
Reputation:
114
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
I think this is what you want :
Use Colours / Threshold (use the sliders to optimase result)
Select the black or white with the 'Select by Colour Tool'
Delete the selection
Image / Mode / Indexed (Use black and white (1-bit) palette)
The checkerboard is only gimp tranparent background, it is not visible on the exported image. If you make a screendump, then it is visble on the result image because you get all the visible information as you see it on the screen.
Posts: 12
Threads: 2
Joined: Jan 2021
Reputation:
0
Gimp version: 2.10
11-05-2022, 07:28 PM
(This post was last modified: 11-05-2022, 07:30 PM by bitrat.)
(11-05-2022, 09:16 AM)denzjos Wrote: Image / Mode / Indexed (Use black and white (1-bit) palette)
Thanks denzjos. That's a good idea to add the alpha then convert mode. I thought it solved the problem, but unfortunately it doesn't (quite) work...
Here's what I do (that doesn't work).
- create a black and white image with redundant bit width (RGB or grayscale)
- add a layer mask
- copy bw image to layer mask
- fill image layer with solid black
- convert to 1-bit indexed image mode [ Image | Mode | ...Indexed -> Use black and white (1-bit) palette ]
Unfortunately, although I ask for a 1-bit palette, the result is an antialiased 8-bit palette. (I'd call this a bug, because I'm not prevented from selecting the 1-bit palette.)
What I want is black+transparent, rather than black+white. I'm reasonably sure there are other ways to accomplish this. Unless it's actually impossible to do with PNG, I could probably write a C program to get wiw in 5 minutes. It's effectively a black sprite and I'm fairly sure it's possible in most icon file formats.
I'd also like to solve the associated Inkscape issue so, if any Inkscape aficionados out there can help, that would also be appreciated!
Cheers!
Posts: 7,136
Threads: 155
Joined: Oct 2016
Reputation:
1,006
Operating system(s):
Gimp version: 2.10
This has come up before see: https://www.gimp-forum.net/Thread-Export...with-Alpha
I do not know how you get a anti-alised 8-bit palette, even with Gimp 2.10 which throws in an extra indexed entry you just get 2
Work-flow:
Black-on-White image
Colour-to-Alpha to make black on transparent
Mode -> Indexed 1 bit.
You do not say which OS you are using. If you can get a Gimp 2.8 that might work for you.
ImageMagick - Same as you, I can not see any way of getting a 1 bit png out.
Posts: 12
Threads: 2
Joined: Jan 2021
Reputation:
0
Gimp version: 2.10
11-05-2022, 10:34 PM
(This post was last modified: 11-05-2022, 11:41 PM by bitrat.)
(11-05-2022, 08:40 PM)rich2005 Wrote: This has come up before see: https://www.gimp-forum.net/Thread-Export...with-Alpha
I do not know how you get a anti-alised 8-bit palette, even with Gimp 2.10 which throws in an extra indexed entry you just get 2
Work-flow:
Black-on-White image
Colour-to-Alpha to make black on transparent
Mode -> Indexed 1 bit.
You do not say which OS you are using. If you can get a Gimp 2.8 that might work for you.
ImageMagick - Same as you, I can not see any way of getting a 1 bit png out.
Hi rich2005,
I just found that link myself but thanks!
My GIMP doesn't allow me to create a black+white (1-bit) image. Minimum is 8-bit.
Every package seems determined to turn a bitmap into a grayscale at every opportunity, and to antialias screen rendering in the viewer, so it's often impossible to see whether the image itself is a bitmap or grayscale. Even the window manager is probably involved in this... Anyway, I'll update here when I've done some more experimenting.
I'm using GIMP 2.10.30 on Ubuntu 18.04. Due for a system rebuild, but too much on to do it right now..
I'm using an AppImage, so maybe I'll try the older version with that.
No AppImage for 2.8 I'll just need to manage with current limitations for now. Basically, I'm trying to get pixel level control over grayscale rendering using the 'newsprint' dot screen filter. It's very annoying to have this option removed, presumably based on the assumption that antialiasing and grayscale are always better....
Thanks again for the reminder to try ImageMagick, but sounds like it won't get me far... I don't want extra steps in my workflow if I can help it, but it can be a lifesaver sometimes.
____________________________
UPDATE:
It looks like a PNG exported from a GIMP image created as per your suggestion is 8-bit RGB ...
Code:
$ identify test-1bit-alpha.png
test-1bit-alpha.png PNG 1024x683 1024x683+0+0 8-bit sRGB 4.48KB 0.000u 0:00.000
but it looks like it's 1-bit (black+alpha) under the hood, padded to 8-bits just to use extra disk space or some other misbegotten 'optimisation' ...
Code:
$ identify -verbose test-1bit-alpha.png
Image: test-1bit-alpha.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 1024x683+0+0
Resolution: 118.11x118.11
Print size: 8.66988x5.78274
Units: PixelsPerCentimeter
Type: Bilevel
Endianess: Undefined
Colorspace: sRGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
Channel statistics:
Pixels: 699392
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: -nan
Alpha:
min: 0 (0)
max: 255 (1)
mean: 51.7903 (0.203099)
standard deviation: 102.588 (0.402306)
kurtosis: 0.178562
skewness: -1.476
entropy: -nan
Alpha: graya(0,0) #00000000
Colors: 2
Histogram:
557346: ( 0, 0, 0, 0) #00000000 graya(0,0)
142046: ( 0, 0, 0,255) #000000FF graya(0,1)
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: graya(0,1)
Border color: graya(223,1)
Matte color: graya(189,1)
Transparent color: graya(0,0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1024x683+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
Comment: Created with GIMP
date:create: 2022-11-06T11:46:11+13:00
date:modify: 2022-11-06T11:46:11+13:00
icc:copyright: Public Domain
icc:description: GIMP built-in sRGB
icc:manufacturer: GIMP
icc:model: sRGB
png:bKGD: chunk was found (see Background color, above)
png:iCCP: chunk was found
png:IHDR.bit-depth-orig: 2
png:IHDR.bit_depth: 2
png:IHDR.color-type-orig: 3
png:IHDR.color_type: 3 (Indexed)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 1024, 683
png:pHYs: x_res=11811, y_res=11811, units=1
png:PLTE.number_colors: 3
png:text: 1 tEXt/zTXt/iTXt chunks were found
png:tIME: 2022-11-05T22:46:11Z
png:tRNS: chunk was found
signature: 17cf50864f09dbe815449d6c9f96b0fabab283430f0375567ac4d732da83e9f7
Profiles:
Profile-icc: 672 bytes
Artifacts:
filename: test-1bit-alpha.png
verbose: true
Tainted: False
Filesize: 4.48KB
Number pixels: 699K
Pixels per second: 69.94MB
User time: 0.020u
Elapsed time: 0:01.010
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
I may get there yet...
Cheers,
bitrat
Posts: 6,355
Threads: 275
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(11-05-2022, 10:34 PM)bitrat Wrote: Hi rich2005,
I just found that link myself but thanks!
My GIMP doesn't allow me to create a black+white (1-bit) image. Minimum is 8-bit.
There is a difference between the image in Gimp and was it exported (otherwise you wouldn't export JPEG from 32-bit FP images).
I tried this:
- Create an image (white) fill a square with black
- Create a palette with two colors; black and white
- Image > Mode > Indexed and use the palette created above
- Export as PNG (auto pixel format, will create an indexed PNG)
Result:
Code:
01:40:28 @ ~/ : >file /tmp/OneBPP.png
/tmp/OneBPP.png: PNG image data, 600 x 400, 1-bit colormap, interlaced
01:42:03 @ ~/ : >identify -verbose /tmp/OneBPP.png
Image: /tmp/OneBPP.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: PseudoClass
Geometry: 600x400+0+0
Resolution: 28.35x28.35
Print size: 21.164x14.1093
Units: PixelsPerCentimeter
Colorspace: sRGB
Type: Bilevel
Base type: Undefined
Endianess: Undefined
Depth: 8/1-bit
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
Channel statistics:
Pixels: 240000
Red:
min: 0 (0)
max: 255 (1)
mean: 76.8124 (0.301225)
standard deviation: 116.992 (0.458791)
kurtosis: -1.24916
skewness: 0.866513
entropy: 0.882783
Green:
min: 0 (0)
max: 255 (1)
mean: 76.8124 (0.301225)
standard deviation: 116.992 (0.458791)
kurtosis: -1.24916
skewness: 0.866513
entropy: 0.882783
Blue:
min: 0 (0)
max: 255 (1)
mean: 76.8124 (0.301225)
standard deviation: 116.992 (0.458791)
kurtosis: -1.24916
skewness: 0.866513
entropy: 0.882783
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 76.8124 (0.301225)
standard deviation: 116.992 (0.458791)
kurtosis: -1.24915
skewness: 0.866516
entropy: 0.882783
Colors: 2
Histogram:
167706: ( 0, 0, 0) #000000 black
72294: (255,255,255) #FFFFFF white
Colormap entries: 2
Colormap:
0: ( 0, 0, 0) #000000 black
1: (255,255,255) #FFFFFF white
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: PNG
Intensity: Undefined
Compose: Over
Page geometry: 600x400+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2022-11-06T01:40:20+01:00
date:modify: 2022-11-06T01:40:20+01:00
png:IHDR.bit-depth-orig: 1
png:IHDR.bit_depth: 1
png:IHDR.color-type-orig: 3
png:IHDR.color_type: 3 (Indexed)
png:IHDR.interlace_method: 1 (Adam7 method)
png:IHDR.width,height: 600, 400
png:pHYs: x_res=2835, y_res=2835, units=1
png:PLTE.number_colors: 2
png:sRGB: intent=0 (Perceptual Intent)
png:text: 1 tEXt/zTXt/iTXt chunks were found
png:text-encoded profiles: 1 were found
png:tIME: 2022-11-06T00:40:20Z
signature: 57ab66a2a4259e7d6d1351b2fbcb79e287ad34c0428b5cb3cd405e0d082a48bf
Profiles:
Profile-exif: 15064 bytes
Artifacts:
filename: /tmp/OneBPP.png
verbose: true
Tainted: False
Filesize: 34712B
Number pixels: 240000
Pixels per second: 24MB
User time: 0.000u
Elapsed time: 0:01.009
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Posts: 12
Threads: 2
Joined: Jan 2021
Reputation:
0
Gimp version: 2.10
Thanks Ofnuts. I'm getting close. If only I could replace those white pixels with transparent, and persuade the whole thing to render from Inkscape, in colour ...
If I render the bw image from Inkscape using 'crisp-edges- render mode, it doesn't add gray, levels but this doesn't work for the one with alpha.
I can do wiw in GIMP so all good. Thank you.
Posts: 6,355
Threads: 275
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(11-06-2022, 07:04 AM)bitrat Wrote: Thanks Ofnuts. I'm getting close. If only I could replace those white pixels with transparent, and persuade the whole thing to render from Inkscape, in colour ...
If I render the bw image from Inkscape using 'crisp-edges- render mode, it doesn't add gray, levels but this doesn't work for the one with alpha.
I can do wiw in GIMP so all good. Thank you.
Once you have a two-color colormap, with GIF it is just a matter of marking one of the colors as transparent (with PNG it is different, opacity is a mask). But if it is consumed by Inkscape, why do you care about the internal representation? And what is your final target image format?
Posts: 7,136
Threads: 155
Joined: Oct 2016
Reputation:
1,006
Operating system(s):
Gimp version: 2.10
11-06-2022, 11:29 AM
(This post was last modified: 11-06-2022, 11:50 AM by rich2005.)
Quote:..My GIMP doesn't allow me to create a black+white (1-bit) image. Minimum is 8-bit...
Not true, just the way IM reports. You can always compare file sizes. This the same image, exported as a 1bit indexed file and then exported as 8bit RGBA.
Edit: If you want IM to report as 1 bit then the same indexed - 1 bit image exported as a tiff.
That is me out, best of luck
Posts: 12
Threads: 2
Joined: Jan 2021
Reputation:
0
Gimp version: 2.10
11-07-2022, 01:42 AM
(This post was last modified: 11-07-2022, 03:16 AM by bitrat.)
(11-06-2022, 08:49 AM)Ofnuts Wrote: But if it is consumed by Inkscape, why do you care about the internal representation? And what is your final target image format?
Many years ago, CorelDraw could import 1-bit black+white images and render each pixel with either of two arbitrary colours (defined as RGBA, HSV, Pantone, or whatever).
The arbitrary colours were not encoded in the imported bitmap. CorelDraw used one attribute (pen) to set the colour of the 'black' pixels, and another (fill) to set the 'white' ones.
On import, CorelDraw rendered black+white as black+transparent by default.
By overlaying and aligning multiple same size bitmaps, it was possible to control the colour and transparency of each pixel in the image. With care, different sized bitmaps could be overlaid, but I forget how I registered them.
I'm trying to accomplish something similar.
(11-06-2022, 11:29 AM)rich2005 Wrote: Not true, just the way IM reports. You can always compare file sizes. This the same image, exported as a 1bit indexed file and then exported as 8bit RGBA.
Edit: If you want IM to report as 1 bit then the same indexed - 1 bit image exported as a tiff.
Thanks rich2005, you've given me some good ideas.
File size is somewhat obscured by compression. Export to BMP is uncompressed by default, but it doesn't do alpha. Can't seem to find any settings to disable compression in other formats. Also, tif export of my source image is buggy in my GIMP.
All that said, I don't think spelunking image formats will solve my problem.
As per above, what I need is to:
- overlay multiple 1-bit bitmaps, with pixel registration.
- map arbitrary rgba values to the '0' and '1' pixels in each overlay. (ie, colour-0 in place of 0 and colour-1 in place of 1).
I've figured it out!
I can do it with layer masks.
I was too focused on bit width, but I just need to copy my 1-bit bitmaps onto the masks.
EXCEPT....
The advantage of using CorelDraw or Inkscape is that they render colours subtractively (like inks), while GIMP's is additive (like prisms).
Maybe something like the layer mode set to Subtract would work. That doesn't do what I want, but there are lots of modes.
Can anyone suggest a way to have red, green and blue add up to black, not white?
|