SDL_PIXELFORMAT_INDEX1LSB and SDL_PIXELFORMAT_INDEX1MSB

What are SDL_PIXELFORMAT_INDEX1LSB and SDL_PIXELFORMAT_INDEX1MSB? I just need an explanation about what makes them different from each other and how they are supposed to be used. When I change from SDL_PIXELFORMAT_INDEX1LSB to SDL_PIXELFORMAT_INDEX1MSB in my test program there is no difference in what I see in my window, why is that? Thanks!

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <unistd.h>

#define WIDTH 24
#define HEIGHT 10
#define SCALE 20 

void destroy_window(SDL_Window *window, SDL_Renderer *renderer);
void test_sdl(SDL_Window *window,SDL_Renderer *renderer);

int main(int argc, char * argv[]){
    
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;

    
    SDL_Init(SDL_INIT_EVERYTHING);

    window = SDL_CreateWindow(
        "TEST",
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        WIDTH*SCALE,
        HEIGHT*SCALE,
        0
    );

    renderer = SDL_CreateRenderer(window, -1, 0);

    test_sdl(window, renderer);

    return 0;
}


void test_sdl(SDL_Window *window,SDL_Renderer *renderer){

    uint8_t arr[WIDTH * HEIGHT];
    
    for(int i = 0; i < WIDTH * HEIGHT ; i++){
        if(i <= 2){
            arr[i] = 0b11110000;
        }
        else{
            arr[i] = 0b000000000;

        }
        
    }


    SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(arr, WIDTH, HEIGHT, 1, 3, SDL_PIXELFORMAT_INDEX1MSB);

                     
    SDL_Color colors[2] = {{255, 0, 0, 255}, {0, 0, 255, 255}}; 
    SDL_SetPaletteColors(surface->format->palette, colors, 0, 2);
        
    SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);

    SDL_RenderCopy(renderer, texture, NULL, NULL); 
    SDL_RenderPresent(renderer);

    sleep(100);

    SDL_FreeSurface(surface);
    SDL_DestroyTexture(texture);
    destroy_window(window,renderer);

}

void destroy_window(SDL_Window *window, SDL_Renderer *renderer){
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
}

I can see a difference.

msb-lsb
The top one is MSB. The bottom one is LSB.

According to this discussion it didn’t work correctly before SDL 2.28

1 Like

Ah, thanks for the help!