[Armadillo:03747] Re: Armadillo-500 のビデオ端子

西 智哉 email@hidden
2008年 11月 28日 (金) 16:38:28 JST


yashi さん

西です。お手数おかけします。ヘッダ部分は
いくらか、削除しました。

/*
 * device filename
 */
#define FB_DEV_NAME			"/dev/fb0"

/*
 * display feature
 */
#define WINDOW_WIDTH		640
#define WINDOW_HEIGHT		480
#define COLOR_DEPTH			3 /* 24 bit */
#define FB_SIZE				WINDOW_WIDTH * WINDOW_HEIGHT * COLOR_DEPTH


/*
 * picture data on window (used display and touch panel event)
 */
typedef struct _window_item
{
	int x;
	int y;
	int width;
	int height;
	int depth;
	int event;
	char filename[256];
	void* data;
} window_item;

#define WINDOW_ITEM_NUM	8

#define DIR ""

window_item item_list[] =
{
	{ 0, 0, 75, 75, 3, SS_PAUSE_SOUND, PICTURE_DIR "pause.jpg", NULL },
	{ 725, 0, 75, 75, 3, SS_PLAY_SOUND, PICTURE_DIR "play.jpg", NULL },
	{ 0, 175, 75, 75, 3, SS_REWIND, PICTURE_DIR "rewind.jpg", NULL },
	{ 725, 175, 75, 75, 3, SS_FAST_FORWARD, PICTURE_DIR "fast_forward.jpg", NULL },
	{ 0, 350, 75, 75, 3, SS_SKIP_PREV, PICTURE_DIR "prev.jpg", NULL },
	{ 725, 350, 75, 75, 3, SS_SKIP_NEXT, PICTURE_DIR "next.jpg", NULL },
	{ 0, 525, 75, 75, 3, SS_VOLUME_DOWN, PICTURE_DIR "volumedown.jpg", NULL },
	{ 725, 525, 75, 75, 3, SS_VOLUME_UP, PICTURE_DIR "volumeup.jpg", NULL },
};


static int fb_fd;
static void* fb_memory;

/***********************************************************************
 *  summary   : convert from jpeg format file data to RGB 24bit data
 *              and copy to indicated memory location
 *              (fixed size is supported only)
 *  return    : success : 0, filed : -1
 **********************************************************************/
/*
 * error handler for jpeg library
 */
struct error_manager
{
	struct jpeg_error_mgr pub;
	jmp_buf setjmp_buffer;
};

typedef struct error_manager* error_ptr;

METHODDEF(void) error_exit(j_common_ptr cinfo)
{
	error_ptr err = (error_ptr)cinfo->err;
	(*cinfo->err->output_message)(cinfo);

	longjmp(err->setjmp_buffer, 1);
}

static int convert_jpegfile(
	window_item* jpeg_picture	/* item data */
	)
{
	int row_stride;
	int pos = 0;
	JSAMPARRAY buffer;
	struct jpeg_decompress_struct cinfo;
	struct error_manager jerr;

	FILE* infile;

	if((infile = fopen(jpeg_picture->filename, "rb")) == NULL){
		fprintf(stderr, "can't open %s\n", jpeg_picture->filename);
		return -1;
	}

	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = error_exit;

	if(setjmp(jerr.setjmp_buffer)){
		jpeg_destroy_decompress(&cinfo);
		fclose(infile);
		return -1;
	}

	jpeg_create_decompress(&cinfo);
	jpeg_stdio_src(&cinfo, infile);
	jpeg_read_header(&cinfo, TRUE);
	jpeg_start_decompress(&cinfo);

	jpeg_picture->width = cinfo.output_width;
	jpeg_picture->height = cinfo.output_height;
	jpeg_picture->depth = cinfo.output_components;

	row_stride = cinfo.output_width * cinfo.output_components;

	buffer = (*cinfo.mem->alloc_sarray)
		((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
	
	jpeg_picture->data = malloc(row_stride * cinfo.output_height);
	if(jpeg_picture->data == NULL){
		fprintf(stderr, "malloc() failed\n");
		return -1;
	}

	pos = 0;
	while(cinfo.output_scanline < cinfo.output_height){
		jpeg_read_scanlines(&cinfo, buffer, 1);
		memcpy(jpeg_picture->data + pos, buffer[0], row_stride);
		pos += row_stride;
	}

	jpeg_finish_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);

	fclose(infile);
	return 0;
}

/***********************************************************************
 *  summary   : draw indicated window item to the flame buffer
 *  return    : 0 : success, -1 : failed
 **********************************************************************/
static int draw_window_item(
	window_item* draw_item	/* item data to draw */
)
{
	int i;
	void* base_addr = fb_memory + 
					  (WINDOW_WIDTH * draw_item->y * COLOR_DEPTH) + 
					  draw_item->x * COLOR_DEPTH;

	/* SHOUD CHECK SIZE */
	assert((draw_item->x + draw_item->width) <= WINDOW_WIDTH);
	assert((draw_item->y + draw_item->height) <= WINDOW_HEIGHT);

	for(i = 0 ; i < draw_item->height ; i++){
		memcpy(
				base_addr + (i * WINDOW_WIDTH * COLOR_DEPTH),
				draw_item->data + (i * draw_item->width * COLOR_DEPTH),
				draw_item->width * COLOR_DEPTH
				);
	}

	return 0;
}

/***********************************************************************
 *	summary   : 
 *	return    : 
 **********************************************************************/
static int display_jpeg_picture(
	void
)
{

	window_item jpeg_picture;
	memset(&jpeg_picture, 0, sizeof(jpeg_picture));
	jpeg_picture.x = 0;
	jpeg_picture.y = 0;
	jpeg_picture.width = 640;
	jpeg_picture.height = 480;
	jpeg_picture.depth = 3;
	jpeg_picture.event = SS_NO_EVENT;
	strcpy(jpeg_picture.filename, "flower24.jpg");
	jpeg_picture.data = NULL;

	convert_jpegfile(&jpeg_picture);

	/* to the center of screen */
	jpeg_picture.x = (WINDOW_WIDTH - jpeg_picture.width) / 2;
	jpeg_picture.y = (WINDOW_HEIGHT - jpeg_picture.height) / 2;
	
	draw_window_item(&jpeg_picture);
	msync(fb_memory, FB_SIZE, MS_ASYNC);
	free(jpeg_picture.data);

	return 0;
}

/***********************************************************************
 *	summary   : main routine
 *	return    : 
 **********************************************************************/
int main(	
	int argc, 
	char* argv[]
)
{

	/*
	 *	open flame buffer and touch panel, serial device
	 */
	fb_fd = open(FB_DEV_NAME, O_RDWR);
	if(fb_fd < 0){
		perror(FB_DEV_NAME);
		return 0;
	}

	/*
	 *	map flame buffer to memory
	 */
	fb_memory = mmap(0, FB_SIZE, PROT_WRITE, MAP_SHARED, fb_fd, 0);
	if(fb_memory < 0){
		fprintf(stderr, "mmap() failed\n");
		return 0;
	}
	memset(fb_memory, 0, FB_SIZE);

	/*
	 *	regist window items to the list, then draw them and initial picture
	 */

	display_jpeg_picture();

	return 0;
}


On Fri, 28 Nov 2008 16:27:33 +0900
Yasushi SHOJI <email@hidden> wrote:

> At Fri, 28 Nov 2008 11:51:10 +0900,
> 西 智哉 wrote:
> > 
> > Armadillo-500 を 24bpp に設定しているので、青と赤が
> > 入れ替わってしまったのでしょうか?
> 
> いや、そうではなくて、元画像のデータの色列びが違うんじゃないでしょうか?
> 
> 画像表示のコードは、ここに貼れますか?
> -- 
>            yashi
> _______________________________________________
> armadillo mailing list
> email@hidden
> http://lists.atmark-techno.com/cgi-bin/mailman/listinfo/armadillo





armadillo メーリングリストの案内