How to convert rgb image to cmyk?

Aug 14, 2017

Copy link to clipboard

Copied

I tried 2 methods, none of them worked.

1:

  1.     AVDoc avDoc = AVAppGetActiveDoc();
  2.     PDDoc pdDoc = AVDocGetPDDoc(avDoc);
  3.     PDColorConvertParams colorParams = (PDColorConvertParams) calloc( 1 , sizeof(PDColorConvertParamsRec) ); 
  4.     PDColorConvertAction colorConvertAction = (PDColorConvertAction) calloc( 1 , sizeof( PDColorConvertActionRec ) ); 
  5.     ASBool pageChanged = false; 
  6.     AC_Profile  workingProfile;  
  7.     ACGetWorkingSpaceProfile  (kACWorkingCMYK, &workingProfile); 
  8. //Populate the PDColorConvertAction data members 
  9.     colorConvertAction[0].mMatchAttributesAny = -1;//kColorConvObj_AnyObject; 
  10.     colorConvertAction[0].mMatchSpaceTypeAny = -1;//kColorConvAnySpace; 
  11.     colorConvertAction[0].mMatchIntent= AC_UseProfileIntent; 
  12.     colorConvertAction[0].mConvertIntent = AC_UseProfileIntent; 
  13.     colorConvertAction[0].mConvertProfile= workingProfile; 
  14.     colorConvertAction[0].mEmbed = true
  15.     colorConvertAction[0].mPreserveBlack = true
  16.     colorConvertAction[0].mUseBlackPointCompensation= true
  17.     colorConvertAction[0].mAction = kColorConvConvert; 
  18.     colorConvertAction[0].mIsProcessColor = false
  19.     colorParams->mActions = colorConvertAction; 
  20.     colorParams->mNumActions = 1; 
  21.     colorParams->mInks = NULL; 
  22.     colorParams->mNumInks = 0; 
  23.     pageChanged = false; 
  24.     PDDocColorConvertPage( pdDoc , colorParams , 0 , NULL , NULL , 0 , NULL , &pageChanged ); 

2:

  1. AVDoc avDoc = AVAppGetActiveDoc();
  2. PDDoc pdDoc = AVDocGetPDDoc(avDoc);
  3. int pageCount = PDDocGetNumPages(pdDoc);
  4. for(int i=0;i<pageCount;i++)
  5. {
  6.     PDPage page = PDDocAcquirePage(pdDoc, i);
  7.     PDEContent pdeContent = PDPageAcquirePDEContent(page, gExtensionID);
  8.     ASInt32 elementCount = PDEContentGetNumElems(pdeContent);
  9.     for(int j=0;j<elementCount;j++)
  10.     {
  11.         PDEElement e = PDEContentGetElem(pdeContent, j);
  12.         ASInt32 t = PDEObjectGetType(e);
  13.         if(t == kPDEImage)
  14.         {
  15.             PDEImage pdeImage = (PDEImage)element;
  16.             PDEColorSpace space = PDEImageGetColorSpace(pdeImage);
  17.             ASAtom spaceName = PDEColorSpaceGetName(space);
  18.             if(std::string(ASSAtomGetString(spaceName)) == "DeviceCMYK")
  19.             {
  20.                 PDEColorSpace cmyk = PDEColorSpaceCreateFromName(ASAtomFromString("DeviceCMYK"));
  21.                 PDEImageSetColorSpace(pdeImage, cmyk);
  22.             }
  23.         }
  24.     }
  25.     PDPageSetPDEContent(page, gExtensionID);
  26.     PDPageNotifyContentsDidChange(page);
  27.     PDPageReleasePDEContent(page, gExtensionID);
  28.     PDPageRelease(page)
  29. }

The second method is a definitely fail – that won’t do any color conversion. There is an API for color converting a single PDEElement, though can’t recall it offhand.

On #1

- the BIG issue is that you aren’t setting a value for the mSize member in the ActionRec

- The second issue is that you aren’t clearing the memory and/or setting all unused fields to 0. Memory is a funny thing ☺.

- Finally, not sure why you are using -1’s instead of the proper kColorConvObj_AnyObject, etc. Use the constants, they are there for a reason

TOPICS
Acrobat SDK and JavaScript

Views

381

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to convert rgb image to cmyk?

Aug 14, 2017

Copy link to clipboard

Copied

I tried 2 methods, none of them worked.

1:

  1.     AVDoc avDoc = AVAppGetActiveDoc();
  2.     PDDoc pdDoc = AVDocGetPDDoc(avDoc);
  3.     PDColorConvertParams colorParams = (PDColorConvertParams) calloc( 1 , sizeof(PDColorConvertParamsRec) ); 
  4.     PDColorConvertAction colorConvertAction = (PDColorConvertAction) calloc( 1 , sizeof( PDColorConvertActionRec ) ); 
  5.     ASBool pageChanged = false; 
  6.     AC_Profile  workingProfile;  
  7.     ACGetWorkingSpaceProfile  (kACWorkingCMYK, &workingProfile); 
  8. //Populate the PDColorConvertAction data members 
  9.     colorConvertAction[0].mMatchAttributesAny = -1;//kColorConvObj_AnyObject; 
  10.     colorConvertAction[0].mMatchSpaceTypeAny = -1;//kColorConvAnySpace; 
  11.     colorConvertAction[0].mMatchIntent= AC_UseProfileIntent; 
  12.     colorConvertAction[0].mConvertIntent = AC_UseProfileIntent; 
  13.     colorConvertAction[0].mConvertProfile= workingProfile; 
  14.     colorConvertAction[0].mEmbed = true
  15.     colorConvertAction[0].mPreserveBlack = true
  16.     colorConvertAction[0].mUseBlackPointCompensation= true
  17.     colorConvertAction[0].mAction = kColorConvConvert; 
  18.     colorConvertAction[0].mIsProcessColor = false
  19.     colorParams->mActions = colorConvertAction; 
  20.     colorParams->mNumActions = 1; 
  21.     colorParams->mInks = NULL; 
  22.     colorParams->mNumInks = 0; 
  23.     pageChanged = false; 
  24.     PDDocColorConvertPage( pdDoc , colorParams , 0 , NULL , NULL , 0 , NULL , &pageChanged ); 

2:

  1. AVDoc avDoc = AVAppGetActiveDoc();
  2. PDDoc pdDoc = AVDocGetPDDoc(avDoc);
  3. int pageCount = PDDocGetNumPages(pdDoc);
  4. for(int i=0;i<pageCount;i++)
  5. {
  6.     PDPage page = PDDocAcquirePage(pdDoc, i);
  7.     PDEContent pdeContent = PDPageAcquirePDEContent(page, gExtensionID);
  8.     ASInt32 elementCount = PDEContentGetNumElems(pdeContent);
  9.     for(int j=0;j<elementCount;j++)
  10.     {
  11.         PDEElement e = PDEContentGetElem(pdeContent, j);
  12.         ASInt32 t = PDEObjectGetType(e);
  13.         if(t == kPDEImage)
  14.         {
  15.             PDEImage pdeImage = (PDEImage)element;
  16.             PDEColorSpace space = PDEImageGetColorSpace(pdeImage);
  17.             ASAtom spaceName = PDEColorSpaceGetName(space);
  18.             if(std::string(ASSAtomGetString(spaceName)) == "DeviceCMYK")
  19.             {
  20.                 PDEColorSpace cmyk = PDEColorSpaceCreateFromName(ASAtomFromString("DeviceCMYK"));
  21.                 PDEImageSetColorSpace(pdeImage, cmyk);
  22.             }
  23.         }
  24.     }
  25.     PDPageSetPDEContent(page, gExtensionID);
  26.     PDPageNotifyContentsDidChange(page);
  27.     PDPageReleasePDEContent(page, gExtensionID);
  28.     PDPageRelease(page)
  29. }

The second method is a definitely fail – that won’t do any color conversion. There is an API for color converting a single PDEElement, though can’t recall it offhand.

On #1

- the BIG issue is that you aren’t setting a value for the mSize member in the ActionRec

- The second issue is that you aren’t clearing the memory and/or setting all unused fields to 0. Memory is a funny thing ☺.

- Finally, not sure why you are using -1’s instead of the proper kColorConvObj_AnyObject, etc. Use the constants, they are there for a reason

TOPICS
Acrobat SDK and JavaScript

Views

382

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 14, 2017 0
Adobe Employee ,
Aug 14, 2017

Copy link to clipboard

Copied

The second method is a definitely fail – that won’t do any color conversion. There is an API for color converting a single PDEElement, though can’t recall it offhand.

On #1

- the BIG issue is that you aren’t setting a value for the mSize member in the ActionRec

- The second issue is that you aren’t clearing the memory and/or setting all unused fields to 0. Memory is a funny thing ☺.

- Finally, not sure why you are using -1’s instead of the proper kColorConvObj_AnyObject, etc. Use the constants, they are there for a reason

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 14, 2017 0
Aug 15, 2017

Copy link to clipboard

Copied

I didn't find mSize member in the PDColorConvertActionRec

I've changed like this, but still not:

  1. AVDoc avDoc = AVAppGetActiveDoc();
  2. PDDoc pdDoc = AVDocGetPDDoc(avDoc);
  3. ASBool pageChanged = false;
  4. PDColorConvertParamsRec colorParams = {0};
  5. PDColorConvertActionRec colorConvertAction = {0};
  6. AC_Profile  workingProfile; 
  7. ACGetWorkingSpaceProfile(kACWorkingCMYK, &workingProfile);
  8. colorConvertAction.mMatchAttributesAny = kColorConvObj_AnyObject;
  9. colorConvertAction.mMatchSpaceTypeAny = kColorConvAnySpace;
  10. colorConvertAction.mMatchIntent= AC_UseProfileIntent;
  11. colorConvertAction.mConvertIntent = AC_UseProfileIntent;
  12. colorConvertAction.mConvertProfile= workingProfile;
  13. colorConvertAction.mEmbed = true;
  14. colorConvertAction.mPreserveBlack = true;
  15. colorConvertAction.mUseBlackPointCompensation= true;
  16. colorConvertAction.mAction = kColorConvConvert;
  17. colorConvertAction.mIsProcessColor = false;
  18. colorParams.mActions = &colorConvertAction;
  19. colorParams.mNumActions = 1;
  20. colorParams.mInks = NULL;
  21. colorParams.mNumInks = 0;
  22. PDDocColorConvertPage( pdDoc , &colorParams , 0 , NULL , NULL , 0 , NULL , &pageChanged ); 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 15, 2017 0
lrosenth LATEST
Adobe Employee ,
Aug 15, 2017

Copy link to clipboard

Copied

Ah, I see now.

I am looking at the Ex versions of these structures and APIs…

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 15, 2017 0