Lose the 1px lines... there's no need for them.
I did code for this awhile back in SDL. Basically, Load the whole bitmap into a surface, and when requested via an index number, fill a rect:
Code:
SDL_Rect rSrc =
{
((INDEX % ENTRIES_PER_LINE) * TILE_WIDTH),
((INDEX % (TOTAL_HEIGHT/ ENTRIES_PER_LINE)) * TILE_HEIGHT),
TILE_WIDTH,
TILE_HEIGHT};
Then create a new empty surface TILE_WIDTH wide and TILE_HEIGHT high and finally blit from the palette you loaded (huge bitmap) using rSrc as the clipping rect onto your newly created surface.
Here's a copy_surface() function I created, it might help you out.
Code:
bool sdlwrap::surface::copy_surface(SDL_Surface *surface, sdlwrap::RECT *clip)
{
m_autofree = 1; // This surface is now ours
m_data = ::SDL_CreateRGBSurface // Create surface using passed surface params
(
surface->flags,
(clip == NULL) ? surface->w : clip->w,
(clip == NULL) ? surface->h : clip->h,
surface->format->BitsPerPixel,
surface->format->Rmask,
surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask
);
if (m_data == NULL)
return 1;
::SDL_BlitSurface(surface, reinterpret_cast<SDL_Rect *>(clip), m_data, NULL);
::SDL_SetColorKey(m_data, sdlwrap::surface::flags::srccolorkey, ::SDL_MapRGB(m_data->format, 0, 0, 255));
return 0;
};