You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.2 KiB
C++
135 lines
3.2 KiB
C++
//:Source:206, "llgfx_texture_jpg", 3b93fb50
|
|
//
|
|
// File: llgfx_read_jpg.cpp
|
|
//
|
|
// ############################################################################
|
|
// # G A M E.O.N.E - LOW LEVEL LIB V1.0 #
|
|
// ############################################################################
|
|
// Copyright (C) 2001 LEVEL ONE ENTERTAINMENT,
|
|
//
|
|
// This library is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
// License as published by the Free Software Foundation; either
|
|
// version 2.1 of the License, or any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this library; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
//
|
|
// Libhome <http://lowlevellib.sourceforge.net>
|
|
// Contact <mailto:alex.piko@l-e-v-e-l-o-n-e.com>
|
|
//
|
|
// Modification History:
|
|
// 03 Sep 2001, Alex Piko -- Generated 23:51:12 by Genitor OCS V4.50.915.2
|
|
//
|
|
//:-----------------------------------------------------------------------------
|
|
|
|
//:Custom
|
|
#include "llgfx_read_jpg.h"
|
|
|
|
|
|
//:> +-----------------------------------+
|
|
//:>-------------------| Global Function Definitions |--------------------
|
|
//:> +-----------------------------------+
|
|
|
|
//::1
|
|
// +-------------------+
|
|
// | txReadJPGData() |
|
|
// +-------------------+
|
|
|
|
int txReadJPGData(
|
|
llfile_sMAPFILE *stream,
|
|
s_texture *info)
|
|
{
|
|
SYS_ASSERT_PTR(info);
|
|
|
|
if (Pd->begin())
|
|
return FAIL;
|
|
|
|
uchar *Pbuf = (uchar*) info->data;
|
|
|
|
for ( ; ; )
|
|
{
|
|
void *Pscan_line_ofs;
|
|
uint scan_line_len;
|
|
|
|
if (Pd->decode(&Pscan_line_ofs, &scan_line_len))
|
|
break;
|
|
|
|
if (Pd->get_num_components() == 3)
|
|
{
|
|
uchar *Psb = (uchar *)Pscan_line_ofs;
|
|
uchar *Pdb = (uchar *)Pbuf;
|
|
|
|
int src_bpp = Pd->get_bytes_per_pixel();
|
|
|
|
for (int x = Pd->get_width(); x > 0; x--, Psb += src_bpp, Pdb += 3)
|
|
{
|
|
Pdb[0] = Psb[2];
|
|
Pdb[1] = Psb[1];
|
|
Pdb[2] = Psb[0];
|
|
}
|
|
|
|
Pbuf = Pdb;
|
|
}
|
|
else
|
|
{
|
|
//status = Pdst->write_line(Pscan_line_ofs);
|
|
memcpy(Pbuf,Pscan_line_ofs,Pd->get_width());
|
|
Pbuf += Pd->get_width();
|
|
}
|
|
}
|
|
|
|
delete Pd;
|
|
delete Pinput_stream;
|
|
Pinput_stream = NULL;
|
|
Pd = NULL;
|
|
|
|
return OK;
|
|
}
|
|
|
|
//::2
|
|
// +---------------------+
|
|
// | txReadJPGHeader() |
|
|
// +---------------------+
|
|
|
|
int txReadJPGHeader(
|
|
llfile_sMAPFILE *stream,
|
|
s_texture *info)
|
|
{
|
|
SYS_ASSERT_PTR(info);
|
|
|
|
|
|
llfile_fseek(stream,0,SEEK_SET);
|
|
|
|
Pinput_stream = (Pjpeg_decoder_file_stream)
|
|
new l3lib_jpeg_decoder_file_stream(stream);
|
|
|
|
Pd = new jpeg_decoder(Pinput_stream, false);
|
|
|
|
if (Pd->get_error_code() != 0)
|
|
{
|
|
delete Pd;
|
|
delete Pinput_stream;
|
|
Pinput_stream = NULL;
|
|
Pd = NULL;
|
|
return FAIL;
|
|
}
|
|
|
|
|
|
info->width = Pd->get_width();
|
|
info->height = Pd->get_height();
|
|
|
|
if( Pd->get_num_components() == 1 )
|
|
info->format = TXFMT_I_8;
|
|
else
|
|
info->format = TXFMT_RGB;
|
|
|
|
return OK;
|
|
}
|