/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program 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.

**********************************************************************/



#include	"r64.h"

int r64_plane(
	char **	data,
	int *	w,
	int *	h,
	int *	size,
	R64_FILE * f,
	int x,
	int y,
	int level)
{
R64_CACHE_ENT * ce;
int ww,hh;
	if ( level < 0 ) {
		r64_error = E_NOLEV;
printf("b\n");
		return -1;
	}
	if ( f->level_ofs[level] == 0 ) {
		r64_error = E_NOLEV;
printf("c\n");
		return -1;
	}
	if ( x < 0 || x >= f->level_w[level] ||
			y < 0 || y >= f->level_h[level] ) {
		*data = 0;
		r64_error = E_OK;
		return 0;
	}
	if ( _search_ce(f,x,y,level) < 0 )
{
printf("d\n");
		return -1;
}
	ce = f->cache[0].next;
	*w = ce->w_len;
	*h = ce->h_len;
	*data = ce->buf;
	*size = ENT_VOL(f,ce);
	r64_error = E_OK;
	return 0;
}
