From 7fe60435bce6595a9c58a9bfd8244d74b5320e96 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 15 Jan 2013 08:46:13 +0100 Subject: Import DirectFB141_2k11R3_beta5 --- .../DirectFB/gfxdrivers/sh772x/sh7722_jpegtool.c | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 Source/DirectFB/gfxdrivers/sh772x/sh7722_jpegtool.c (limited to 'Source/DirectFB/gfxdrivers/sh772x/sh7722_jpegtool.c') diff --git a/Source/DirectFB/gfxdrivers/sh772x/sh7722_jpegtool.c b/Source/DirectFB/gfxdrivers/sh772x/sh7722_jpegtool.c new file mode 100755 index 0000000..5fd0fad --- /dev/null +++ b/Source/DirectFB/gfxdrivers/sh772x/sh7722_jpegtool.c @@ -0,0 +1,142 @@ +#ifdef SH7722_DEBUG_JPEG +#define DIRECT_ENABLE_DEBUG +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef STANDALONE +#include "sh7722_jpeglib_standalone.h" +#else +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#endif + +#include "sh7722_jpeglib.h" + + +void +write_ppm( const char *filename, + unsigned long phys, + int pitch, + unsigned int width, + unsigned int height ) +{ + int i; + int fd; + int size; + void *mem; + FILE *file; + + size = direct_page_align( pitch * height ); + + fd = open( "/dev/mem", O_RDWR ); + if (fd < 0) { + D_PERROR( "SH7722/JPEG: Could not open /dev/mem!\n" ); + return; + } + + mem = mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, phys ); + if (mem == MAP_FAILED) { + D_PERROR( "SH7722/JPEG: Could not map /dev/mem at 0x%08lx (length %d)!\n", phys, size ); + close( fd ); + return; + } + + close( fd ); + + file = fopen( filename, "wb" ); + if (!file) { + D_PERROR( "SH7722/JPEG: Could not open '%s' for writing!\n", filename ); + munmap( mem, size ); + return; + } + + fprintf( file, "P6\n%d %d\n255\n", width, height ); + + for (i=0; i\n", argv[0] ); + return -1; + } + +#ifndef STANDALONE + direct_initialize(); + + direct_config->debug = true; +#endif + + ret = SH7722_JPEG_Initialize(); + if (ret) + return ret; + + ret = direct_stream_create( argv[1], &stream ); + if (ret) + goto out; + + ret = SH7722_JPEG_Open( stream, &info ); + if (ret) + goto out; + + D_INFO( "SH7722/JPEGTool: Opened %dx%d image (4:%s)\n", info.width, info.height, + info.mode420 ? "2:0" : info.mode444 ? "4:4" : "2:2?" ); + + format = DSPF_RGB24;// info.mode444 ? DSPF_NV16 : DSPF_NV12; + pitch = (DFB_BYTES_PER_LINE( format, info.width ) + 31) & ~31; + + ret = SH7722_JPEG_Decode( &info, NULL, NULL, format, 0x0f800000, NULL, pitch, info.width, info.height ); + if (ret) + goto out; + + +// Use RGB24 format for this +// write_ppm( "test.ppm", 0x0f800000, pitch, info.width, info.height ); + + ret = SH7722_JPEG_Encode( "test.jpg", NULL, format, 0x0f800000, pitch, info.width, info.height, 0 ); + if (ret) + goto out; + + +out: + if (stream) + direct_stream_destroy( stream ); + + SH7722_JPEG_Shutdown(); + + return ret; +} -- cgit