# Help with converting between SDL\_Texture pixel formats?

**URL:** <https://discourse.libsdl.org/t/help-with-converting-between-sdl-texture-pixel-formats/20987>\
**Category:** SDL Development\
**Created:** [September 19, 2014, 9:53pm UTC](https://discourse.libsdl.org/t/help-with-converting-between-sdl-texture-pixel-formats/20987 "2014-09-19T21:53:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BadManiac](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/badmaniac/32/2722_2.png) [@BadManiac](https://discourse.libsdl.org/u/BadManiac)\
**Post date:** [September 19, 2014, 9:53pm UTC](https://discourse.libsdl.org/t/help-with-converting-between-sdl-texture-pixel-formats/20987/1 "2014-09-19T21:53:44Z")

</div>

Hi,

I’ve recently started playing around with SDL for a hobby project of mine, replacing my old 16 bit software blitting library. And I’ve come across a problem I’m hoping someone here can help me with.

I have a block of raw pixel data in BGR888 format, and I want to convert it to a ARGB8888 texture. I tried SDL\_ConvertPixels but it doesn’t work in the way I need it to. I need each pixel to be “expanded” from three byte to four byte. SDL\_Convert pixels does it on a row by row basis.

So is there some clever SDL function I’m missing that will do this or willl I have to break out the old assembler? 🙂

---

<div class="post-metadata">

**Author:** ![Christian\_Leger](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/ecae2f/32.png) [@Christian\_Leger](https://discourse.libsdl.org/u/Christian_Leger)\
**Post date:** [November 13, 2014, 3:58am UTC](https://discourse.libsdl.org/t/help-with-converting-between-sdl-texture-pixel-formats/20987/2 "2014-11-13T03:58:04Z")

</div>

Hi,

I’m not familiar enough with the SDL library functions for conversions to  
answer the first part of your question, however I would recommend you  
complete your task in C rather than in assembler. Unless you are totally  
proficient in asm, then never mind ^\_^On Fri, Sep 19, 2014 at 5:53 PM, BadManiac \<martin\_maniac at [hotmail.com](http://hotmail.com)\> wrote:

> Hi,
> 
> I’ve recently started playing around with SDL for a hobby project of mine,  
> replacing my old 16 bit software blitting library. And I’ve come across a  
> problem I’m hoping someone here can help me with.
> 
> I have a block of raw pixel data in BGR888 format, and I want to convert  
> it to a ARGB8888 texture. I tried SDL\_ConvertPixels but it doesn’t work  
> in the way I need it to. I need each pixel to be “expanded” from three byte  
> to four byte. SDL\_Convert pixels does it on a row by row basis.
> 
> So is there some clever SDL function I’m missing that will do this or  
> willl I have to break out the old assembler? [image: Smile]
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Gabriele\_Greco](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/8edcca/32.png) [@Gabriele\_Greco](https://discourse.libsdl.org/u/Gabriele_Greco)\
**Post date:** [November 13, 2014, 9:06am UTC](https://discourse.libsdl.org/t/help-with-converting-between-sdl-texture-pixel-formats/20987/3 "2014-11-13T09:06:56Z")

</div>

> Hi,
> 
> I’ve recently started playing around with SDL for a hobby project of mine,  
> replacing my old 16 bit software blitting library. And I’ve come across a  
> problem I’m hoping someone here can help me with.
> 
> I have a block of raw pixel data in BGR888 format, and I want to convert  
> it to a ARGB8888 texture. I tried SDL\_ConvertPixels but it doesn’t work  
> in the way I need it to. I need each pixel to be “expanded” from three byte  
> to four byte. SDL\_Convert pixels does it on a row by row basis.

Use SDL\_CreateRGBSurfaceFrom with the appropriate parameters on your  
BGR888 raw data and blit the result to a SDL\_CreateRGBSurface with format  
ARGB8888.On Fri, Sep 19, 2014 at 11:53 PM, BadManiac \<martin\_maniac at [hotmail.com](http://hotmail.com)\> wrote:

–  
Bye,  
Gabry

---

<div class="post-metadata">

**Author:** ![Andreas\_Schiffler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Andreas\_Schiffler](https://discourse.libsdl.org/u/Andreas_Schiffler)\
**Post date:** [November 13, 2014, 4:26pm UTC](https://discourse.libsdl.org/t/help-with-converting-between-sdl-texture-pixel-formats/20987/4 "2014-11-13T16:26:44Z")

</div>

Wouldn’t this just do it behind the scenes?  
SDL\_Texture\* texture = SDL\_CreateTexture(renderer, pixelData,  
SDL\_PIXELFORMAT\_BGR888, SDL\_TEXTUREACCESS\_STATIC, w, h);  
(see [https://wiki.libsdl.org/SDL\_CreateTexture](https://wiki.libsdl.org/SDL_CreateTexture))On 11/13/2014 1:06 AM, Gabriele Greco wrote:

> On Fri, Sep 19, 2014 at 11:53 PM, BadManiac \<martin\_maniac at [hotmail.com](http://hotmail.com) \<mailto:martin\_maniac at [hotmail.com](http://hotmail.com)\>\> wrote:
> 
> ```
> Hi,
> 
> I've recently started playing around with SDL for a hobby project
> of mine, replacing my old 16 bit software blitting library. And
> I've come across a problem I'm hoping someone here can help me with.
> 
> I have a block of raw pixel data in BGR888 format, and I want to
> convert it to a ARGB8888 texture. I tried SDL_ConvertPixels but it
> doesn't work in the way I need it to. I need each pixel to be
> "expanded" from three byte to four byte. SDL_Convert pixels does
> it on a row by row basis.
> 
> ```
> 
> Use SDL\_CreateRGBSurfaceFrom with the appropriate parameters on your  
> BGR888 raw data and blit the result to a SDL\_CreateRGBSurface with  
> format ARGB8888.
> 
> –  
> Bye,  
> Gabry
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
