Results 1 to 4 of 4

Thread: IS3ColorReplaceImage

  1. #1
    Join Date
    Dec 1969
    Location
    São Paulo/Brazil
    Posts
    62

    Default IS3ColorReplaceImage

    Chris,
    I'm trying to replace the colors on my image using IS3ColorReplaceImage, but not happen.
    My image in memory is 8 bit grayscale, but the original file is 4 bit grayscale, so the palette is 256 colors but only 16 is used.
    I would like to change 15% to black and 85% to white.

    <pre>
    BYTE *pImage = GetImagePointer();
    if(pImage==NULL) return(IS_ERR_BADPARAM);

    UINT32 arrayColor[256];
    memset(&arrayColor,0,sizeof(UINT32)*256);
    ISrc(IS3FindColorsUsedIn8BitImage)(pImage,m_czPix. cx,m_czPix.cy,m_czPix.cx,arrayColor);

    UINT32 unPixels=m_czPix.cx*m_czPix.cy;
    double pBlack=0.0;

    for(UINT32 i=0;i<16;i++)
    {
    pBlack+=((double)((double)arrayColor[i]/unPixels)*100.0);
    if(pBlack>=15.0)
    ISrc(IS3ColorReplaceImage)(pImage,m_czPix.cx,m_czP ix.cy,m_czPix.cx,1,i,15,0,0); //15=white
    else
    ISrc(IS3ColorReplaceImage)(pImage,m_czPix.cx,m_czP ix.cy,m_czPix.cx,1,i, 0,0,0); //0=black
    }
    </pre>

  2. #2
    Join Date
    Mar 2006
    Location
    Raleigh, NC
    Posts
    1,356

    Default RE: IS3ColorReplaceImage

    >Chris,
    >I'm trying to replace the colors on my image using
    >IS3ColorReplaceImage, but not happen.

    what happens?

    >My image in memory is 8 bit grayscale, but the original file
    >is 4 bit grayscale, so the palette is 256 colors but only 16
    >is used.

    are the pixel values 0..15 or 0..255 ?

    >I would like to change 15% to black and 85% to white.

    (put code inside <code> ... </code> tags - but use square brackets instead of < and >)

    Code:
      BYTE *pImage = GetImagePointer();
      if(pImage==NULL) return(IS_ERR_BADPARAM);
    
      UINT32 arrayColor[256];
      memset(&arrayColor,0,sizeof(UINT32)*256);
      
      ISrc(IS3FindColorsUsedIn8BitImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,arrayColor);
    
      UINT32 unPixels=m_czPix.cx*m_czPix.cy;
      double pBlack=0.0;
    
      for(UINT32 i=0;i<16;i++)
      {
        pBlack+=((double)((double)arrayColor[i]/unPixels)*100.0);
        if(pBlack>=15.0) 
          ISrc(IS3ColorReplaceImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,1,i,15,0,0);//15=white
        else
          ISrc(IS3ColorReplaceImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,1,i,0,0,0); //0=black
      }
    so, if the pixel is equal or brighter than 15% of the total pixels, you set it to white, else to black ?

    a faster way might be:

    Code:
      BYTE *pImage = GetImagePointer();
      if(pImage==NULL) return(IS_ERR_BADPARAM);
    
      UINT32 arrayColor[256];
      memset(&arrayColor,0,sizeof(UINT32)*256);
      
      ISrc(IS3FindColorsUsedIn8BitImage)(pImage,m_czPix.cx,m_czPix.cy,m_czPix.cx,arrayColor);
    
      UINT32 unPixels=m_czPix.cx*m_czPix.cy;
      double pBlack=0.0;
    
      BYTE lut[16];
      BYTE *luts[1];
      luts[0] = lut;
      for(UINT32 i=0;i<16;i++)
      {
        pBlack+=((double)((double)arrayColor[i]/unPixels)*100.0);
        if(pBlack>=15.0) 
           lut[i] = 15;
        else
           lut[i] = 0;
      }
      IS3ApplyLUTsToImage(pImage,m_czPix.cx,m_czPix.cy,1,m_czPix.cx,luts);
    besides being probably 20 times faster, this way, you can look at the LUT in the debugger and see exactly how you are mapping the original colors to the new colors.
    Chris Losinger
    Smaller Animals Software, Inc

  3. #3
    Join Date
    Dec 1969
    Location
    São Paulo/Brazil
    Posts
    62

    Default RE: IS3ColorReplaceImage

    -> what happens?
    The image seems me unchanged.

    -> are the pixel values 0..15 or 0..255 ?
    0..15.

    -> so, if the pixel is equal or brighter than 15% of the total pixels, you set it to white, else to black ?
    because the palette is inverted.

    The other way works very well.

    If my image source is 256 colors how it works ?


  4. #4
    Join Date
    Mar 2006
    Location
    Raleigh, NC
    Posts
    1,356

    Default RE: IS3ColorReplaceImage

    >If my image source is 256 colors how it works ?

    just change the 15's and 16s to 255s and 256s. it should work the same.
    Chris Losinger
    Smaller Animals Software, Inc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •