Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #2671 > unrolled thread

1 bit RGB image representation problem

Started bybhor.pranjal@gmail.com
First post2016-06-23 05:01 -0700
Last post2016-06-30 12:19 +0200
Articles 7 — 3 participants

Back to article view | Back to comp.lang.postscript


Contents

  1 bit RGB image representation problem bhor.pranjal@gmail.com - 2016-06-23 05:01 -0700
    Re: 1 bit RGB image representation problem luser droog <luser.droog@gmail.com> - 2016-06-23 21:02 -0700
      Re: 1 bit RGB image representation problem bhor.pranjal@gmail.com - 2016-06-24 21:22 -0700
        Re: 1 bit RGB image representation problem luser droog <luser.droog@gmail.com> - 2016-06-24 22:51 -0700
          Re: 1 bit RGB image representation problem bhor.pranjal@gmail.com - 2016-06-25 00:00 -0700
            Re: 1 bit RGB image representation problem luser droog <luser.droog@gmail.com> - 2016-06-29 17:15 -0700
              Re: 1 bit RGB image representation problem Carlos <angus@quovadis.com.ar> - 2016-06-30 12:19 +0200

#2671 — 1 bit RGB image representation problem

Frombhor.pranjal@gmail.com
Date2016-06-23 05:01 -0700
Subject1 bit RGB image representation problem
Message-ID<5d8cc135-891d-40b4-9ca2-0d215611aaf2@googlegroups.com>
Hello. I have written a program to convert PWG raster images into postscript. The image data is represented in Flate encoded format. The format of the output file generated look like this (take from a sample file generated)

%%Page: 1 1
%%BeginPageSetup
<< /PageSize[4958 7017] >> setpagedevice
%%EndPageSetup
gsave
/DeviceRGB setcolorspace
4958 7017 scale
<< 
/ImageType 1
/Width 4958
/Height 7017
/BitsPerComponent 1
/Decode [0 1 0 1 0 1]
/DataSource currentfile /FlateDecode filter
/ImageMatrix [4958 0 0 -7017 0 7017]
>> image

...Flate encoded image data...


grestore
showpage
%PageTrailer
%Trailer
%%Pages: 1
%EOF

I am able to display images of various color spaces and bit depths. But the problem is with RGB color model (rgb, srgb, adobergb) and bit depth 1. When I run the postscript files with rgb or srgb or adobergb depth 1 bit, I get error '/undefined in <some random characters>'. The postscript files generated with rgb, srgb and adobergb with 8 bit depths are working great.
I read in PLRM on page 607 that If bits/sample is less than 8, sample values are packed from left to right within a character (see Section 4.10.2, “Sample Representation”). Is there any difference with 8 bit depth and 1 bit depth representation of image? Why files with 1 bit depth are not working ?

If you want any more information please feel free to ask. Also, I am a postscript newbie that's why struggling with lots of things.

[toc] | [next] | [standalone]


#2674

Fromluser droog <luser.droog@gmail.com>
Date2016-06-23 21:02 -0700
Message-ID<875df2f7-19a0-4103-8f46-a81093e1b118@googlegroups.com>
In reply to#2671
On Thursday, June 23, 2016 at 7:01:27 AM UTC-5, bhor.p...@gmail.com wrote:
> Hello. I have written a program to convert PWG raster images into postscript. The image data is represented in Flate encoded format. The format of the output file generated look like this (take from a sample file generated)
> 
> %%Page: 1 1
> %%BeginPageSetup
> << /PageSize[4958 7017] >> setpagedevice
> %%EndPageSetup
> gsave
> /DeviceRGB setcolorspace
> 4958 7017 scale
> << 
> /ImageType 1
> /Width 4958
> /Height 7017
> /BitsPerComponent 1
> /Decode [0 1 0 1 0 1]
> /DataSource currentfile /FlateDecode filter
> /ImageMatrix [4958 0 0 -7017 0 7017]
> >> image
> 
> ...Flate encoded image data...
> 
> 
> grestore
> showpage
> %PageTrailer
> %Trailer
> %%Pages: 1
> %EOF
> 
> I am able to display images of various color spaces and bit depths. But the problem is with RGB color model (rgb, srgb, adobergb) and bit depth 1. When I run the postscript files with rgb or srgb or adobergb depth 1 bit, I get error '/undefined in <some random characters>'. The postscript files generated with rgb, srgb and adobergb with 8 bit depths are working great.
> I read in PLRM on page 607 that If bits/sample is less than 8, sample values are packed from left to right within a character (see Section 4.10.2, “Sample Representation”). Is there any difference with 8 bit depth and 1 bit depth representation of image? Why files with 1 bit depth are not working ?
> 
> If you want any more information please feel free to ask. Also, I am a postscript newbie that's why struggling with lots of things.

I looked over the PLRM sections on images and the image and 
colorimage operators and I don't see that it's disallowed 
anywhere. But at the same time I wonder why you (think you)
need this? If it's just for a sense of completeness and exposing
all the conversion possibilities to the users of your code,
then I'd recommend you not worry about this corner.

RGB with 1-bit-per-component? That's 3 bits per pixel.
Unless you're employing a nice color-blending dithering
to produce this thing, and unless you're targeting some
obscure hardware that can naturally express the result,
then I'm failing to imagine where this would be useful.

I think the technical description of what you're doing is
sufficient. But it seems like it's probably and X/Y problem. 
Whatever the real goal is, a conversion of images to 1bpp rgb
possibly is not the best route to get there.

[toc] | [prev] | [next] | [standalone]


#2677

Frombhor.pranjal@gmail.com
Date2016-06-24 21:22 -0700
Message-ID<fca1ed29-394c-4ced-9b22-99a5d8df8112@googlegroups.com>
In reply to#2674
On Saturday, 25 June 2016 05:30:30 UTC+5:30, luser droog  wrote:
> On Thursday, June 23, 2016 at 7:01:27 AM UTC-5, bhor.p...@gmail.com wrote:
> > Hello. I have written a program to convert PWG raster images into postscript. The image data is represented in Flate encoded format. The format of the output file generated look like this (take from a sample file generated)
> > 
> > %%Page: 1 1
> > %%BeginPageSetup
> > << /PageSize[4958 7017] >> setpagedevice
> > %%EndPageSetup
> > gsave
> > /DeviceRGB setcolorspace
> > 4958 7017 scale
> > << 
> > /ImageType 1
> > /Width 4958
> > /Height 7017
> > /BitsPerComponent 1
> > /Decode [0 1 0 1 0 1]
> > /DataSource currentfile /FlateDecode filter
> > /ImageMatrix [4958 0 0 -7017 0 7017]
> > >> image
> > 
> > ...Flate encoded image data...
> > 
> > 
> > grestore
> > showpage
> > %PageTrailer
> > %Trailer
> > %%Pages: 1
> > %EOF
> > 
> > I am able to display images of various color spaces and bit depths. But the problem is with RGB color model (rgb, srgb, adobergb) and bit depth 1. When I run the postscript files with rgb or srgb or adobergb depth 1 bit, I get error '/undefined in <some random characters>'. The postscript files generated with rgb, srgb and adobergb with 8 bit depths are working great.
> > I read in PLRM on page 607 that If bits/sample is less than 8, sample values are packed from left to right within a character (see Section 4.10.2, “Sample Representation”). Is there any difference with 8 bit depth and 1 bit depth representation of image? Why files with 1 bit depth are not working ?
> > 
> > If you want any more information please feel free to ask. Also, I am a postscript newbie that's why struggling with lots of things.
> 
> I looked over the PLRM sections on images and the image and 
> colorimage operators and I don't see that it's disallowed 
> anywhere. But at the same time I wonder why you (think you)
> need this? If it's just for a sense of completeness and exposing
> all the conversion possibilities to the users of your code,
> then I'd recommend you not worry about this corner.
> 
> RGB with 1-bit-per-component? That's 3 bits per pixel.
> Unless you're employing a nice color-blending dithering
> to produce this thing, and unless you're targeting some
> obscure hardware that can naturally express the result,
> then I'm failing to imagine where this would be useful.
> 
> I think the technical description of what you're doing is
> sufficient. But it seems like it's probably and X/Y problem. 
> Whatever the real goal is, a conversion of images to 1bpp rgb
> possibly is not the best route to get there.

I am adding support for raster to PS conversion in CUPS filters project. That's why I need this.

I want to add the RGB with 1 bpp I get from raster data is padded with extra 0 to align the bits in multiples of 4, that is, 1 byte of data contains information for 2 pixels like RGB0RGB0. Can this be a problem ?

The fineness of the output does not matter (so dithering is not an issue). The output just has to resemble the raster file in PS format. What can I do or where should I look to solve this issue?

[toc] | [prev] | [next] | [standalone]


#2678

Fromluser droog <luser.droog@gmail.com>
Date2016-06-24 22:51 -0700
Message-ID<4dcf1d03-0b39-44a4-9c4e-c716ba1d1d44@googlegroups.com>
In reply to#2677
On Friday, June 24, 2016 at 11:22:26 PM UTC-5, bhor.p...@gmail.com wrote:
> On Saturday, 25 June 2016 05:30:30 UTC+5:30, luser droog  wrote:
> > On Thursday, June 23, 2016 at 7:01:27 AM UTC-5, bhor.p...@gmail.com wrote:
> > > Hello. I have written a program to convert PWG raster images into postscript. The image data is represented in Flate encoded format. The format of the output file generated look like this (take from a sample file generated)
> > > 
> > > %%Page: 1 1
> > > %%BeginPageSetup
> > > << /PageSize[4958 7017] >> setpagedevice
> > > %%EndPageSetup
> > > gsave
> > > /DeviceRGB setcolorspace
> > > 4958 7017 scale
> > > << 
> > > /ImageType 1
> > > /Width 4958
> > > /Height 7017
> > > /BitsPerComponent 1
> > > /Decode [0 1 0 1 0 1]
> > > /DataSource currentfile /FlateDecode filter
> > > /ImageMatrix [4958 0 0 -7017 0 7017]
> > > >> image
> > > 
> > > ...Flate encoded image data...
> > > 
> > > 
> > > grestore
> > > showpage
> > > %PageTrailer
> > > %Trailer
> > > %%Pages: 1
> > > %EOF
> > > 
> > > I am able to display images of various color spaces and bit depths. But the problem is with RGB color model (rgb, srgb, adobergb) and bit depth 1. When I run the postscript files with rgb or srgb or adobergb depth 1 bit, I get error '/undefined in <some random characters>'. The postscript files generated with rgb, srgb and adobergb with 8 bit depths are working great.
> > > I read in PLRM on page 607 that If bits/sample is less than 8, sample values are packed from left to right within a character (see Section 4.10.2, “Sample Representation”). Is there any difference with 8 bit depth and 1 bit depth representation of image? Why files with 1 bit depth are not working ?
> > > 
> > > If you want any more information please feel free to ask. Also, I am a postscript newbie that's why struggling with lots of things.
> > 
> > I looked over the PLRM sections on images and the image and 
> > colorimage operators and I don't see that it's disallowed 
> > anywhere. But at the same time I wonder why you (think you)
> > need this? If it's just for a sense of completeness and exposing
> > all the conversion possibilities to the users of your code,
> > then I'd recommend you not worry about this corner.
> > 
> > RGB with 1-bit-per-component? That's 3 bits per pixel.
> > Unless you're employing a nice color-blending dithering
> > to produce this thing, and unless you're targeting some
> > obscure hardware that can naturally express the result,
> > then I'm failing to imagine where this would be useful.
> > 
> > I think the technical description of what you're doing is
> > sufficient. But it seems like it's probably and X/Y problem. 
> > Whatever the real goal is, a conversion of images to 1bpp rgb
> > possibly is not the best route to get there.
> 
> I am adding support for raster to PS conversion in CUPS filters project. That's why I need this.
> 
> I want to add the RGB with 1 bpp I get from raster data is padded with extra 0 to align the bits in multiples of 4, that is, 1 byte of data contains information for 2 pixels like RGB0RGB0. Can this be a problem ?

Yes, that smells like the problem. That would explain
your error message as well. If the data has more
padding than the decoder in the image operator expects,
then it will not read all the data present and image
will return to ps which reads from the file and ...
attempts to (parse and) execute some fragment of the 
data as postscript code. I didn't find any details
on this in the plrm, so some experimentation may be
necessary.

My "feeling" is postscript would prefer the samples
to be packed across bytes and only the last byte of
a row is padded. But I'm not finding any docs to
corroborate me here.

Another possibility is adding another 0 1 pair to
the /Decode parameter to request that it consume
another component. I'm not sure if this works.

> The fineness of the output does not matter (so dithering is not an issue). The output just has to resemble the raster file in PS format. What can I do or where should I look to solve this issue?

[toc] | [prev] | [next] | [standalone]


#2679

Frombhor.pranjal@gmail.com
Date2016-06-25 00:00 -0700
Message-ID<8048fb28-42ab-4325-9870-d30c5542a356@googlegroups.com>
In reply to#2678
On Saturday, 25 June 2016 11:21:53 UTC+5:30, luser droog  wrote:
> On Friday, June 24, 2016 at 11:22:26 PM UTC-5, bhor.p...@gmail.com wrote:
> > On Saturday, 25 June 2016 05:30:30 UTC+5:30, luser droog  wrote:
> > > On Thursday, June 23, 2016 at 7:01:27 AM UTC-5, bhor.p...@gmail.com wrote:
> > > > Hello. I have written a program to convert PWG raster images into postscript. The image data is represented in Flate encoded format. The format of the output file generated look like this (take from a sample file generated)
> > > > 
> > > > %%Page: 1 1
> > > > %%BeginPageSetup
> > > > << /PageSize[4958 7017] >> setpagedevice
> > > > %%EndPageSetup
> > > > gsave
> > > > /DeviceRGB setcolorspace
> > > > 4958 7017 scale
> > > > << 
> > > > /ImageType 1
> > > > /Width 4958
> > > > /Height 7017
> > > > /BitsPerComponent 1
> > > > /Decode [0 1 0 1 0 1]
> > > > /DataSource currentfile /FlateDecode filter
> > > > /ImageMatrix [4958 0 0 -7017 0 7017]
> > > > >> image
> > > > 
> > > > ...Flate encoded image data...
> > > > 
> > > > 
> > > > grestore
> > > > showpage
> > > > %PageTrailer
> > > > %Trailer
> > > > %%Pages: 1
> > > > %EOF
> > > > 
> > > > I am able to display images of various color spaces and bit depths. But the problem is with RGB color model (rgb, srgb, adobergb) and bit depth 1. When I run the postscript files with rgb or srgb or adobergb depth 1 bit, I get error '/undefined in <some random characters>'. The postscript files generated with rgb, srgb and adobergb with 8 bit depths are working great.
> > > > I read in PLRM on page 607 that If bits/sample is less than 8, sample values are packed from left to right within a character (see Section 4.10.2, “Sample Representation”). Is there any difference with 8 bit depth and 1 bit depth representation of image? Why files with 1 bit depth are not working ?
> > > > 
> > > > If you want any more information please feel free to ask. Also, I am a postscript newbie that's why struggling with lots of things.
> > > 
> > > I looked over the PLRM sections on images and the image and 
> > > colorimage operators and I don't see that it's disallowed 
> > > anywhere. But at the same time I wonder why you (think you)
> > > need this? If it's just for a sense of completeness and exposing
> > > all the conversion possibilities to the users of your code,
> > > then I'd recommend you not worry about this corner.
> > > 
> > > RGB with 1-bit-per-component? That's 3 bits per pixel.
> > > Unless you're employing a nice color-blending dithering
> > > to produce this thing, and unless you're targeting some
> > > obscure hardware that can naturally express the result,
> > > then I'm failing to imagine where this would be useful.
> > > 
> > > I think the technical description of what you're doing is
> > > sufficient. But it seems like it's probably and X/Y problem. 
> > > Whatever the real goal is, a conversion of images to 1bpp rgb
> > > possibly is not the best route to get there.
> > 
> > I am adding support for raster to PS conversion in CUPS filters project. That's why I need this.
> > 
> > I want to add the RGB with 1 bpp I get from raster data is padded with extra 0 to align the bits in multiples of 4, that is, 1 byte of data contains information for 2 pixels like RGB0RGB0. Can this be a problem ?
> 
> Yes, that smells like the problem. That would explain
> your error message as well. If the data has more
> padding than the decoder in the image operator expects,
> then it will not read all the data present and image
> will return to ps which reads from the file and ...
> attempts to (parse and) execute some fragment of the 
> data as postscript code. I didn't find any details
> on this in the plrm, so some experimentation may be
> necessary.
> 
> My "feeling" is postscript would prefer the samples
> to be packed across bytes and only the last byte of
> a row is padded. But I'm not finding any docs to
> corroborate me here.
> 
> Another possibility is adding another 0 1 pair to
> the /Decode parameter to request that it consume
> another component. I'm not sure if this works.
> 
> > The fineness of the output does not matter (so dithering is not an issue). The output just has to resemble the raster file in PS format. What can I do or where should I look to solve this issue?

I have tried with adding extra 0 1 to /Decode array but still it fails. Do you think that my flate encoding could be wrong (which is least possible given that other bit depths are working) ?

I was thinking on these lines now: Take the image data 3 bits at a time into some array and skip every 4th bit so that I will get RGBRGBRG combination per byte. And then encode it. Will this work?

[toc] | [prev] | [next] | [standalone]


#2683

Fromluser droog <luser.droog@gmail.com>
Date2016-06-29 17:15 -0700
Message-ID<e249e657-680b-4ca2-ad38-b2da78cd0121@googlegroups.com>
In reply to#2679
On Saturday, June 25, 2016 at 2:00:34 AM UTC-5, bhor.p...@gmail.com wrote:
> On Saturday, 25 June 2016 11:21:53 UTC+5:30, luser droog  wrote:
> > On Friday, June 24, 2016 at 11:22:26 PM UTC-5, bhor.p...@gmail.com wrote:
> > > On Saturday, 25 June 2016 05:30:30 UTC+5:30, luser droog  wrote:
> > > > On Thursday, June 23, 2016 at 7:01:27 AM UTC-5, bhor.p...@gmail.com wrote:
> > > > > Hello. I have written a program to convert PWG raster images into postscript. The image data is represented in Flate encoded format. The format of the output file generated look like this (take from a sample file generated)
> > > > > 
> > > > > %%Page: 1 1
> > > > > %%BeginPageSetup
> > > > > << /PageSize[4958 7017] >> setpagedevice
> > > > > %%EndPageSetup
> > > > > gsave
> > > > > /DeviceRGB setcolorspace
> > > > > 4958 7017 scale
> > > > > << 
> > > > > /ImageType 1
> > > > > /Width 4958
> > > > > /Height 7017
> > > > > /BitsPerComponent 1
> > > > > /Decode [0 1 0 1 0 1]
> > > > > /DataSource currentfile /FlateDecode filter
> > > > > /ImageMatrix [4958 0 0 -7017 0 7017]
> > > > > >> image
> > > > > 
> > > > > ...Flate encoded image data...
> > > > > 
> > > > > 
> > > > > grestore
> > > > > showpage
> > > > > %PageTrailer
> > > > > %Trailer
> > > > > %%Pages: 1
> > > > > %EOF
> > > > > 
> > > > > I am able to display images of various color spaces and bit depths. But the problem is with RGB color model (rgb, srgb, adobergb) and bit depth 1. When I run the postscript files with rgb or srgb or adobergb depth 1 bit, I get error '/undefined in <some random characters>'. The postscript files generated with rgb, srgb and adobergb with 8 bit depths are working great.
> > > > > I read in PLRM on page 607 that If bits/sample is less than 8, sample values are packed from left to right within a character (see Section 4.10.2, “Sample Representation”). Is there any difference with 8 bit depth and 1 bit depth representation of image? Why files with 1 bit depth are not working ?
> > > > > 
> > > > > If you want any more information please feel free to ask. Also, I am a postscript newbie that's why struggling with lots of things.
> > > > 
> > > > I looked over the PLRM sections on images and the image and 
> > > > colorimage operators and I don't see that it's disallowed 
> > > > anywhere. But at the same time I wonder why you (think you)
> > > > need this? If it's just for a sense of completeness and exposing
> > > > all the conversion possibilities to the users of your code,
> > > > then I'd recommend you not worry about this corner.
> > > > 
> > > > RGB with 1-bit-per-component? That's 3 bits per pixel.
> > > > Unless you're employing a nice color-blending dithering
> > > > to produce this thing, and unless you're targeting some
> > > > obscure hardware that can naturally express the result,
> > > > then I'm failing to imagine where this would be useful.
> > > > 
> > > > I think the technical description of what you're doing is
> > > > sufficient. But it seems like it's probably and X/Y problem. 
> > > > Whatever the real goal is, a conversion of images to 1bpp rgb
> > > > possibly is not the best route to get there.
> > > 
> > > I am adding support for raster to PS conversion in CUPS filters project. That's why I need this.
> > > 
> > > I want to add the RGB with 1 bpp I get from raster data is padded with extra 0 to align the bits in multiples of 4, that is, 1 byte of data contains information for 2 pixels like RGB0RGB0. Can this be a problem ?
> > 
> > Yes, that smells like the problem. That would explain
> > your error message as well. If the data has more
> > padding than the decoder in the image operator expects,
> > then it will not read all the data present and image
> > will return to ps which reads from the file and ...
> > attempts to (parse and) execute some fragment of the 
> > data as postscript code. I didn't find any details
> > on this in the plrm, so some experimentation may be
> > necessary.
> > 
> > My "feeling" is postscript would prefer the samples
> > to be packed across bytes and only the last byte of
> > a row is padded. But I'm not finding any docs to
> > corroborate me here.
> > 
> > Another possibility is adding another 0 1 pair to
> > the /Decode parameter to request that it consume
> > another component. I'm not sure if this works.
> > 
> > > The fineness of the output does not matter (so dithering is not an issue). The output just has to resemble the raster file in PS format. What can I do or where should I look to solve this issue?
> 
> I have tried with adding extra 0 1 to /Decode array but still it fails. Do you think that my flate encoding could be wrong (which is least possible given that other bit depths are working) ?
> 
> I was thinking on these lines now: Take the image data 3 bits at a time into some array and skip every 4th bit so that I will get RGBRGBRG combination per byte. And then encode it. Will this work?

Yes, that's roughly what I was thinking. I think the last byte of
each row will need to be padded with zero bits. So if your image
was 6x4, it would be laid out like this:

  rgbrgbrg brgbrgbr gb000000
  rgbrgbrg brgbrgbr gb000000
  rgbrgbrg brgbrgbr gb000000
  rgbrgbrg brgbrgbr gb000000

But I still haven't found any specific documentation that speaks
to this. So, it still might not work. :/

[toc] | [prev] | [next] | [standalone]


#2684

FromCarlos <angus@quovadis.com.ar>
Date2016-06-30 12:19 +0200
Message-ID<nl2ro6$4nt$1@dont-email.me>
In reply to#2683
On 30/06/2016 2:15, luser droog wrote:
[...]
> Yes, that's roughly what I was thinking. I think the last byte of
> each row will need to be padded with zero bits. So if your image
> was 6x4, it would be laid out like this:
>
>    rgbrgbrg brgbrgbr gb000000
>    rgbrgbrg brgbrgbr gb000000
>    rgbrgbrg brgbrgbr gb000000
>    rgbrgbrg brgbrgbr gb000000
>
> But I still haven't found any specific documentation that speaks
> to this. So, it still might not work. :/

It does work that way, at least in Ghostscript.

     %!PS

     /to_s {
         dup length dup string 0 1  4 -1 roll 1 sub {
             3 copy exch pop get
             3 copy put pop pop
         } for
         exch pop
     } def

     /img <<
         /ImageType 1
         /Width     3
         /Height    3
         /ImageMatrix [ 3 0 0 -3 0 3 ]
         /DataSource [
         % col [0][1][2   ][pad  ]
             2#11111010 2#10000000
             2#10001101 2#00000000
             2#00100011 2#10000000
         ] to_s
         /BitsPerComponent 1
         /Decode [ 0 1 0 1 0 1 ]
     >> def

     gsave
       /DeviceRGB setcolorspace
       200 200 translate
       100 100 scale
       img image
     grestore

     showpage

-- 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web