#include <openb3d.mod/stbimageloader.mod/.bmx/stbimageloader.bmx.release.win32.x64.h>
struct BBDebugScope_2{int kind; const char *name; BBDebugDecl decls[3]; };
void _openb3d_stbimageloader_TPixmapLoaderB3D_New(struct openb3d_stbimageloader_TPixmapLoaderB3D_obj* o) {
	_brl_pixmap_TPixmapLoader_New((struct brl_pixmap_TPixmapLoader_obj*)o);
	o->clas = &openb3d_stbimageloader_TPixmapLoaderB3D;
}
struct brl_pixmap_TPixmap_obj* _openb3d_stbimageloader_TPixmapLoaderB3D_LoadPixmap_TTStream(struct openb3d_stbimageloader_TPixmapLoaderB3D_obj* o,struct brl_stream_TStream_obj* bbt_stream){
	BBSIZET bbt_bufLen=((BBSIZET)brl_stream_StreamSize((struct brl_stream_TStream_obj*)bbt_stream));
	BBBYTE* bbt_buffer=bbMemAlloc((size_t)bbt_bufLen);
	struct brl_ramstream_TRamStream_obj* bbt_ram=(struct brl_ramstream_TRamStream_obj*)brl_ramstream_CreateRamStream(bbt_buffer,((BBLONG)bbt_bufLen),1,1);
	brl_stream_CopyStream((struct brl_stream_TStream_obj*)bbt_stream,(struct brl_stream_TStream_obj*)((struct brl_stream_TStream_obj*)bbObjectDowncast((BBOBJECT)bbt_ram,(BBClass*)&brl_stream_TStream)),4096);
	struct brl_pixmap_TPixmap_obj* bbt_pixmap=(struct brl_pixmap_TPixmap_obj*)((struct brl_pixmap_TPixmap_obj*)&bbNullObject);
	BBBYTE* bbt_imgPtr=0;
	BBINT bbt_width=0;
	BBINT bbt_height=0;
	BBINT bbt_channels=0;
	BBINT bbt_test=stbi_info_from_memory(bbt_buffer,bbt_bufLen,(&bbt_width),(&bbt_height),(&bbt_channels));
	if(bbt_test==1){
		bbt_imgPtr=stbi_load_from_memory(bbt_buffer,bbt_bufLen,(&bbt_width),(&bbt_height),(&bbt_channels),4);
		if(bbt_channels==3){
			bbt_channels=4;
		}
	}
	if(bbt_imgPtr){
		BBINT bbt_pf=0;
		BBINT bbt_=bbt_channels;
		if(bbt_==1){
			bbt_pf=1;
		}else{
			if(bbt_==3){
				bbt_pf=4;
			}else{
				if(bbt_==4){
					bbt_pf=6;
				}else{
					if(bbt_==2){
						BBBYTE* bbt_src=bbt_imgPtr;
						BBBYTE* bbt_dst=bbt_pixmap->_brl_pixmap_tpixmap_pixels ;
						bbt_pixmap=(struct brl_pixmap_TPixmap_obj*)brl_pixmap_CreatePixmap(bbt_width,bbt_height,6,4);
						{
							BBINT bbt_y=0;
							BBINT bbt_2=bbt_height;
							for(;(bbt_y<bbt_2);bbt_y=(bbt_y+1)){
								{
									BBINT bbt_x=0;
									BBINT bbt_3=bbt_width;
									for(;(bbt_x<bbt_3);bbt_x=(bbt_x+1)){
										BBINT bbt_a=((BBINT)bbt_src[0]);
										BBINT bbt_i=((BBINT)bbt_src[1]);
										bbt_dst[0]=((BBBYTE)bbt_i);
										bbt_dst[1]=((BBBYTE)bbt_i);
										bbt_dst[2]=((BBBYTE)bbt_i);
										bbt_dst[3]=((BBBYTE)bbt_a);
										bbt_src+=2;
										bbt_dst+=4;
									}
								}
							}
						}
					}
				}
			}
		}
		if(bbt_pf!=0){
			bbt_pixmap=(struct brl_pixmap_TPixmap_obj*)brl_pixmap_CreatePixmap(bbt_width,bbt_height,bbt_pf,((BBINT*)BBARRAYDATA(brl_pixmap_pixel_BytesPerPixel,1))[((BBUINT)bbt_pf)]);
			bbMemCopy((void*)bbt_pixmap->_brl_pixmap_tpixmap_pixels ,(const void*)bbt_imgPtr,(size_t)((BBSIZET)((bbt_width*bbt_height)*((BBINT*)BBARRAYDATA(brl_pixmap_pixel_BytesPerPixel,1))[((BBUINT)bbt_pf)])));
		}
		brl_stream_CloseStream((struct brl_stream_TStream_obj*)((struct brl_stream_TStream_obj*)bbObjectDowncast((BBOBJECT)bbt_ram,(BBClass*)&brl_stream_TStream)));
		bbMemFree((void*)bbt_buffer);
		stbi_image_free(bbt_imgPtr);
	}
	return (struct brl_pixmap_TPixmap_obj*)bbt_pixmap;
}
struct BBDebugScope_2 openb3d_stbimageloader_TPixmapLoaderB3D_scope ={
	BBDEBUGSCOPE_USERTYPE,
	"TPixmapLoaderB3D",
	{
		{
			BBDEBUGDECL_TYPEMETHOD,
			"New",
			"()",
			.func_ptr=(BBFuncPtr)&_openb3d_stbimageloader_TPixmapLoaderB3D_New
		},
		{
			BBDEBUGDECL_TYPEMETHOD,
			"LoadPixmap",
			"(:TStream):TPixmap",
			.func_ptr=(BBFuncPtr)&_openb3d_stbimageloader_TPixmapLoaderB3D_LoadPixmap_TTStream
		},
		{
			BBDEBUGDECL_END
		}
	}
};
struct BBClass_openb3d_stbimageloader_TPixmapLoaderB3D openb3d_stbimageloader_TPixmapLoaderB3D={
	&brl_pixmap_TPixmapLoader,
	bbObjectFree,
	(BBDebugScope*)&openb3d_stbimageloader_TPixmapLoaderB3D_scope,
	sizeof(struct openb3d_stbimageloader_TPixmapLoaderB3D_obj),
	(void (*)(BBOBJECT))_openb3d_stbimageloader_TPixmapLoaderB3D_New,
	bbObjectDtor,
	bbObjectToString,
	bbObjectCompare,
	bbObjectSendMessage,
	0,
	0,
	0
	,0
	,sizeof(void*)
	,_openb3d_stbimageloader_TPixmapLoaderB3D_LoadPixmap_TTStream
};

static int __bb_openb3d_stbimageloader_stbimageloader_inited = 0;
int __bb_openb3d_stbimageloader_stbimageloader(){
	if (!__bb_openb3d_stbimageloader_stbimageloader_inited) {
		__bb_openb3d_stbimageloader_stbimageloader_inited = 1;
		__bb_brl_blitz_blitz();
		__bb_brl_pixmap_pixmap();
		__bb_brl_ramstream_ramstream();
		bbObjectRegisterType((BBCLASS)&openb3d_stbimageloader_TPixmapLoaderB3D);
		(struct openb3d_stbimageloader_TPixmapLoaderB3D_obj*)bbObjectNew((BBClass *)&openb3d_stbimageloader_TPixmapLoaderB3D);
		return 0;
	}
	return 0;
}