Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:12:22+00:00 2026-06-15T23:12:22+00:00

I’m working on a Cocoa OS X program to clean up scanned pages and

  • 0

I’m working on a Cocoa OS X program to clean up scanned pages and would like to use Leptonica’s library to do the heavy lifting. I’ve found some info in this post, this one, and this one. I can certainly get a CGImage from the NSImage and can write data to a Leptonica Pix image. The problem I have is that 75% of the time my image comes out warped with a barbershop pole type pattern (each successive row of pixels from the top to the bottom of the image is shifted farther and farther to the right). Sometimes though the picture comes out fine. I assume that I am doing something wrong in seting up the image data, but it’s not really my forte so I’m having trouble understanding the issue. I’m creating the Pix image using the following code:

CGImageRef myCGImage = [processedImage CGImageForProposedRect:NULL context:NULL hints:NULL];
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(myCGImage));
const UInt8 *imageData = CFDataGetBytePtr(data);

Pix *myPix = (Pix *) malloc(sizeof(Pix));
myPix->w = (int)CGImageGetWidth (myCGImage);
myPix->h = (int)CGImageGetHeight (myCGImage);
myPix->d = (int)CGImageGetBitsPerPixel(myCGImage);
myPix->wpl =  ((CGImageGetWidth (myCGImage)*CGImageGetBitsPerPixel(myCGImage))+31)/32;
myPix->informat = IFF_TIFF;
myPix->data = (l_uint32 *) imageData;
myPix->colormap = NULL;

The pix struct is defined as follows:

/*-------------------------------------------------------------------------*
 *                              Basic Pix                                  *
 *-------------------------------------------------------------------------*/
struct Pix
{
uint32             w;           /* width in pixels                   */
uint32             h;           /* height in pixels                  */
uint32             d;           /* depth in bits                     */
uint32             wpl;         /* 32-bit words/line                 */
uint32             refcount;    /* reference count (1 if no clones)  */
int              xres;        /* image res (ppi) in x direction    */
                                  /* (use 0 if unknown)                */
int              yres;        /* image res (ppi) in y direction    */
                                  /* (use 0 if unknown)                */
int              informat;    /* input file format, IFF_*          */
char                *text;        /* text string associated with pix   */
struct PixColormap  *colormap;    /* colormap (may be null)            */
uint32            *data;        /* the image data                    */
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:12:23+00:00Added an answer on June 15, 2026 at 11:12 pm

    The “barbershop pole type pattern” is a classic sign of having the wrong number of bytes per row of pixel data.

    You should base wpl on the value returned by CGImageGetBytesPerRow. Most likely:

    myPix->wpl = CGImageGetBytesPerRow(myCGImage) / 4;
    

    There are several reasons why the image’s bytes-per-row would differ from your guess based on CGImageGetWidth(). For instance, it might be rounded up for performance reasons, or the image might be a sub-image of a wider image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.