title: How to convert 256 colors palettized RGBA image data to NSImage
body: <p>I'm a newbie developer and I need your help with something that is probably trivial for you.</p>
  
  <p>I have an image data in this pixel format: 256 colors palettized RGBA. It comes from FFmpeg <code>(PIX_FMT_PAL8)</code> and it's explained this way:</p>
  
  <blockquote>
    <p>PIX_FMT_RGB32 is handled in an endian-specific manner. An RGBA
    color is put together as:</p>
    
    <p>(A &lt;&lt; 24) | (R &lt;&lt; 16) | (G &lt;&lt; 8) | B</p>
    
    <p>This is stored as BGRA on little-endian CPU architectures and ARGB on big-endian CPUs.</p>
    
    <p>When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized image data is stored in AVFrame.data[0]. </p>
    
    <p>The palette is transported in AVFrame.data[1], is 1024 bytes long (256 4-byte entries) and is formatted the same as in PIX_FMT_RGB32 described above (i.e., it is also endian-specific). Note also that the individual RGB palette components stored in AVFrame.data[1] should be in the range 0..255.</p>
  </blockquote>
  
  <p>AVFrame struct contains <code>uint8_t *data[4]</code> and <code>int linesize[4]</code> and they are described simply with:</p>
  
  <blockquote>
    <ul>
    <li><code>uint8_t *data[4]</code> = pointer to the picture planes</li>
    <li>four components are given, that's all.</li>
    <li>the last component is alpha</li>
    <li><code>int linesize[4]</code> = number of bytes per line</li>
    </ul>
  </blockquote>
  
  <p>I have the AVFrame struct with all the needed data but I don't know how to handle it.
  I need to create a NSImage from this image data.</p>
  
  <p>How can I do this?</p>