19 Replies Latest reply: Oct 6, 2008 1:27 AM by (Aandi_Inston) RSS

    One question on ColorSpace usage via SDk

    andrejusc Community Member
      Hi,

      If particular element uses ColorSpace - then I see structure like this:

      /CS0 cs 0 scn
      ...

      Is it possible via PDE layer to change that 0 value to 1 right after "cs" token? Or do I need again to dive into Cos?
        • 1. Re: One question on ColorSpace usage via SDk
          (Aandi_Inston) Community Member
          The PDE layer doesn't provide access to individual operators, but
          provides an abstraction based on their effect. So the cs/scn operators
          are only interesting in that they lead to colouring of
          fill/stroke/image mask/patterns. So you should be able to get the
          effect you want by changing the colour of the affected elements.

          Aandi Inston
          • 2. Re: One question on ColorSpace usage via SDk
            andrejusc Community Member
            What I actually need is to apply Separation ColorSpace to particular elements/curves. While in file from Illustrator I see that when such ColorSpace is used - then there is sequence like:

            /CS0 cs 1 scn

            and after my code run I get in file:

            /CS0 cs 0 scn

            I'm creating ColorSpace from Cos object through PDEColorSpaceCreateFromCosObj and then apply it to PDEGraphicState, which later is used far various paint operations. So at which place in this sequence I could manage that 1 to 0 change for cs?
            • 3. Re: One question on ColorSpace usage via SDk
              (Aandi_Inston) Community Member
              You need to think in terms of the elements and curves that you want to
              recolour, and create a new graphics state for them.

              Aandi Inston
              • 4. Re: One question on ColorSpace usage via SDk
                andrejusc Community Member
                In which case do I need to set this kPDEFillCSpaceWasSet or kPDEFillCValueWasSet in graphics state wasSetFlags member if at all?

                Yes, I'm creating that new graphics state and thus I'm not sure on stroking and nonstroking colors specification. How should I set them?

                If I do like this:

                PDEColorValue strokeClrValue;

                strokeClrValue.color[0] = c;
                strokeClrValue.color[1] = m;
                strokeClrValue.color[2] = y;
                strokeClrValue.color[3] = k;

                strokeClrSpec.space = clrSpace;
                strokeClrSpec.value = strokeClrValue;

                memset(&gState, 0, sizeof(PDEGraphicState));
                gState.strokeColorSpec = strokeClrSpec;
                gState.lineWidth = w;
                gState.miterLimit = fixedTen;
                gState.flatness = fixedOne;

                Does it mean that I set both stroking and nonstroking colors? And if it's only for stroking - how to set similar for nonstroking?
                • 5. Re: One question on ColorSpace usage via SDk
                  (Aandi_Inston) Community Member
                  Sorry, that's gone further into the API than I have. Indeed, I would
                  have used the Cos API, but I remain convinced the PDFEdit API would do
                  it.

                  Aandi Inston
                  • 6. Re: One question on ColorSpace usage via SDk
                    andrejusc Community Member
                    Ok, I know what I really want to ask.

                    If I have Separation color space, defined as such:

                    [/Separation/my_ink/DeviceCMYK<</C0[0.0 0.0 0.0 0.0]/C1[0.0 0.600006 0.899994 0.0]/FunctionType 2/N 1.0/Domain[0 1]/Range[0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0]>>]

                    and now when I apply it via graphics state to particular curve - how whould I say that I want to use second component, i.e. C1, instead of default C0? I can't find any way for setting that and by default it always selects that C0 component to be used.
                    • 7. Re: One question on ColorSpace usage via SDk
                      andrejusc Community Member
                      From PDF Reference section 7.6.2: "The color component value, or tint, for a spot color specifies the concentration of
                      the corresponding spot colorant."

                      How do I specify with code that tint value?
                      • 8. Re: One question on ColorSpace usage via SDk
                        (Aandi_Inston) Community Member
                        C0 is used if the tint value is 0, C1 is used if the tint value is 1.
                        If the tint value is between 0 and 1, a calculation is made using 0
                        and 1.

                        Returning to your original code, "/CS0 cs 0 scn" selects "no ink".

                        If you change the tint transform you can affect how this is displayed
                        (though a PDF viewer may reasonably take the view that "0 scn" always
                        means "No ink" and optimize that case). When printing to an actual
                        press/imagesetter that 0 will always result in no ink for that plate,
                        unless converting to process: the tint transform is not used.

                        I would be inclined to look at the PDF producer. Why is it specifying
                        0% of a spot colour, something that is exactly equivalent to selecting
                        a white object (barring overprint effects).

                        Aandi Inston
                        • 9. Re: One question on ColorSpace usage via SDk
                          andrejusc Community Member
                          Aaandi,

                          "If you change the tint transform you can affect how this is displayed" - but how???

                          Intially I've tried to construct my Separation color space by constructing appropriate CosObj first and then calling PDEColorSpaceCreateFromCosObj. But tintTransform parameter exists only for PDESeparationColorData type and not inside PDEColorSpace.

                          If I go instead this wat:

                          CosObj tintTransform = CosNewFixed(cosDoc, false, FloatNToFixed(1.0));

                          PDEColorSpace altSpace = PDEColorSpaceCreateFromName(ASAtomFromString("DeviceCMYK"));
                          PDESeparationColorData data;
                          data.alt = altSpace;
                          data.name = ASAtomFromString("myspot");
                          data.size = sizeof(data);
                          data.tintTransform = tintTransform;

                          PDEColorSpaceStruct clrStruct;
                          clrStruct.sep = &data;
                          clrSpace = PDEColorSpaceCreate(ASAtomFromString("Separation"), &clrStruct);

                          I get Bad parameter exception.

                          How should I use that tintTransform? I can't find any sample line of code on whole Internet for that simple matter!
                          • 10. Re: One question on ColorSpace usage via SDk
                            (Aandi_Inston) Community Member
                            >"If you change the tint transform you can affect how this is displayed" - but how???

                            At that level I would probably use the Cos layer. But I would strongly
                            advise against changing the behaviour of displaying a tint value of 0;
                            leave this as white or you may run into unexpected effects.

                            ...
                            >CosObj tintTransform = CosNewFixed(cosDoc, false, FloatNToFixed(1.0));
                            ...
                            >data.tintTransform = tintTransform;

                            A tint transform must be a function object (dictionary or stream). A
                            tint transform is a function, not a fixed value. This all leads me to
                            suppose that you are trying to achieve something that separations are
                            not designed to do.

                            Bear in mind this: if you are using spot colours, this won't work on
                            output. If you are NOT using spot colours, then why use a separation
                            color space?

                            >How should I use that tintTransform? I can't find any sample line of code on whole Internet for that simple matter!

                            Contructing a function dictionary is just a matter of understanding
                            how functions work and making the stream/dictionary accordingly.


                            Aandi Inston
                            • 11. Re: One question on ColorSpace usage via SDk
                              andrejusc Community Member
                              I see.

                              Well, will do now my BMC container hacking with Cos again. So many things are not exposed to higher (i.e. PDE) level...

                              Thank you for your help!
                              • 12. Re: One question on ColorSpace usage via SDk
                                andrejusc Community Member
                                One question now from Cos layer while digging - is it possible to set back PDEContainer content with similar to PDPageAddCosContents? I only want to change content of a paticular container and not whole page via file opened stream, which contains new data. What should I use in this case?
                                • 13. Re: One question on ColorSpace usage via SDk
                                  (Aandi_Inston) Community Member
                                  Just one more thought: you are mixing up, I think, the colour space (a
                                  fixed definition of the spot colour, including a tint transform used
                                  to define how to see the spot on screen); with the color (in this case
                                  a single value from 0 to 1.)

                                  I'll have to pass on PDFEdit.

                                  Aandi Inston
                                  • 14. Re: One question on ColorSpace usage via SDk
                                    andrejusc Community Member
                                    Aandi,

                                    I don't know what exactlty "1 scn" in my situation, but I need to achieve that in resulting Cos stream. I believe it's not just color, but the value to be used in tint transformation function.

                                    I'm able to change that inside my container's stream, but don't know how to set it back when it's not whole page Cos object.

                                    Btw, I've found these 2 functions:
                                    PDEContentSetContainingStream
                                    PDEContentSetStreamOwner

                                    but have no idea how to use CosStream with them. Invoking any of them with CosObj stream and them following with PDPageSetPDEContent seems to have no effect for my case.
                                    • 15. Re: One question on ColorSpace usage via SDk
                                      andrejusc Community Member
                                      If during construction of PDF for my container I have such CosObj dump:

                                      (Indir 72 0 R)
                                      (InDir Stream::)**
                                      Stream offset: 763101; Stream length: 1536
                                      (Dir dict::)**
                                      TAG: (Dir name - value == Length)
                                      (Dir integer - val == 1536)

                                      how could I attach another Cos stream to it? Somehow via stream dictionary?
                                      • 16. Re: One question on ColorSpace usage via SDk
                                        (Aandi_Inston) Community Member
                                        >I don't know what exactlty "1 scn" in my situation

                                        It really would be better to understand. To me it still makes no sense
                                        why you would be using 0% of a spot colour, and you haven't said
                                        anything about your workflow. To me it is still likely that the use of
                                        spot in the first place is a mistake or oversight, which would greatly
                                        simplify the task.

                                        > I believe it's not just color, but the value to be used in tint transformation function.

                                        It is the "color" by the PDF definition of color. For a spot color,
                                        WHEN IT IS NOT USED FOR PRINTING, it is the INPUT to the tint
                                        transformation function. The function itself decides the actual color
                                        that is used (such as a CMYK equivalent).
                                        >
                                        >I'm able to change that inside my container's stream, but don't know how to set it back when it's not whole page Cos object.

                                        Use the Cos methods OR the PDE methods to change a page stream. Not
                                        both.

                                        Aandi Inston
                                        • 17. Re: One question on ColorSpace usage via SDk
                                          (Aandi_Inston) Community Member
                                          >If during construction of PDF for my container I have such CosObj dum...
                                          >how could I attach another Cos stream to it? Somehow via stream dictionary?

                                          What do you mean by "attach"? I think you need to focus on what you
                                          really want in terms of the PDF reference.

                                          If it is page contents, you update the value of Contents.

                                          If it is a form XObject you have to make a new single stream with all
                                          changes.

                                          In all other cases, it depends on the specification.


                                          Aandi Inston
                                          • 18. Re: One question on ColorSpace usage via SDk
                                            andrejusc Community Member
                                            Hi Aandi,

                                            After doing all those tests - I've actually found that PDEElementCopy works with an ERROR!

                                            I've used CosStream to see what is inside my PDEContainer's PDEContent before PDEElementCopy operation:

                                            origContent(Indir 30 0 R)
                                            origContent(InDir Stream::)**
                                            Stream offset: 62145; Stream length: 410
                                            (Dir dict::)**
                                            TAG: (Dir name - value == Length)
                                            (Dir integer - val == 410)
                                            q
                                            0 283.465 283.465 -283.465 re
                                            W n
                                            q
                                            1 0 0 1 -8.8535004 134.4385071 cm
                                            /CS0 cs 1 scn
                                            1 i
                                            /GS0 gs
                                            0 0 m
                                            0 82.438 66.83 149.268 149.267 149.268 c
                                            231.705 149.268 298.535 82.438 298.535 0 c
                                            298.535 -82.438 231.705 -149.267 149.267 -149.267 c
                                            66.83 -149.267 0 -82.438 0 0 c
                                            f
                                            Q
                                            Q
                                            q
                                            23.846 48.562 160.373 160.37 re
                                            W n
                                            q
                                            0 g
                                            1 i
                                            /GS0 gs
                                            -160.3720093 0 0 160.3720093 184.2041016 128.7929688 cm
                                            BX /Sh0 sh EX Q
                                            Q

                                            And after:

                                            copyContent(Indir 31 0 R)
                                            copyContent(InDir Stream::)**
                                            Stream offset: 62555; Stream length: 393
                                            (Dir dict::)**
                                            TAG: (Dir name - value == Length)
                                            (Dir integer - val == 393)
                                            q
                                            0 283.465 283.465 -283.465 re
                                            W n
                                            q
                                            1 0 0 1 -8.8535004 134.4385071 cm
                                            /CS0 cs 1 scn
                                            1 i
                                            /GS0 gs
                                            0 0 m
                                            0 82.438 66.83 149.268 149.267 149.268 c
                                            231.705 149.268 298.535 82.438 298.535 0 c
                                            298.535 -82.438 231.705 -149.267 149.267 -149.267 c
                                            66.83 -149.267 0 -82.438 0 0 c
                                            f
                                            Q
                                            Q
                                            q
                                            23.846 48.562 160.373 160.37 re
                                            W n
                                            q
                                            -160.3720093 0 0 160.3720093 184.2041016 128.7929688 cm
                                            BX /Sh0 sh EX Q
                                            Q

                                            As you could see in copy version we have an absence of these lines:

                                            0 g
                                            1 i
                                            /GS0 gs

                                            Why??? I don't know. Maybe it's a bug in SDK... So that was workarounded with CosStreams instead.

                                            Now in regards to CosStream "attach" - for me it was not obvious (from API documentation and samples code) if I could create PDEContainer's PDEContent from CosStream as well, but now I have:

                                            myNewContent = PDEContentCreateFromCosObj (&cStmObj, &oTmpRes);
                                            PDEContainerSetContent(myNewContainer, myNewContent);

                                            and it works perfectly for me.

                                            Now in regards to that "/CS0 cs 1 scn" sequence - you could see it inside my initial CosStream. So while I wanted to create new special marks with SPOT color - I needed to preserve that as well. And didn't find how besides again CosStream tokens parcing and replacing 0 to 1 where needed. I hope there is a better way for that...

                                            Does all of that clarify my thoughts?

                                            Andrejus
                                            • 19. Re: One question on ColorSpace usage via SDk
                                              (Aandi_Inston) Community Member
                                              >Hi Aandi,
                                              I haven't read this in detail, but

                                              >As you could see in copy version we have an absence of these lines:
                                              >
                                              >0 g
                                              >1 i
                                              >/GS0 gs
                                              >
                                              >Why??? I don't know. Maybe it's a bug in SDK...

                                              Have you checked the exact semantic meaning of those lines, and the
                                              contents of the graphics state GS0? Maybe these lines are left out
                                              because they have a default affect.

                                              >
                                              >Now in regards to that "/CS0 cs 1 scn" sequence ...

                                              Maybe we can go back.

                                              You do want spot color, Ok. And you realise that the spot color has no
                                              effect on screen, or some kinds of printing, so you also want to
                                              control what you see on screen.

                                              But why does the file contain 0% of a spot color to start with? Maybe
                                              if we understand where the file comes from and how it will be used, we
                                              can offer better advice. Right now I feel we aren't able to go in the
                                              same direction because we don't know where you want to end up.

                                              Aandi Inston