sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "jpeg.h" sl@0: sl@0: #define LOG_FILE "c:\\logs\\examples_jpeg_log1.txt" sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: sl@0: void create_xml(int result) sl@0: { sl@0: if(result) sl@0: assert_failed = 1; sl@0: sl@0: testResultXml("examples_jpeg"); sl@0: close_log_file(); sl@0: } sl@0: sl@0: /* getfile */ sl@0: sl@0: void *getfile (char *path, int *n_bytes); sl@0: static void dump_pgm (unsigned char *ptr, int rowstride, int width, int height); sl@0: sl@0: sl@0: int sl@0: main (int argc, char *argv[]) sl@0: { sl@0: unsigned char *data; sl@0: int len; sl@0: JpegDecoder *dec; sl@0: char *fn = "c:\\data\\liboil\\test.jpg"; sl@0: unsigned char *ptr; sl@0: int rowstride; sl@0: int width; sl@0: int height; sl@0: sl@0: /*if (argc < 2) { sl@0: printf("jpeg_test \n"); sl@0: exit(1); sl@0: }*/ sl@0: if (argc > 1) sl@0: fn = argv[1]; sl@0: sl@0: std_log(LOG_FILENAME_LINE, "Test Started examples_jpeg"); sl@0: dec = jpeg_decoder_new (); //to create decoder instance sl@0: sl@0: data = getfile (fn, &len); sl@0: sl@0: jpeg_decoder_addbits (dec, data, len); sl@0: jpeg_decoder_decode (dec); sl@0: sl@0: jpeg_decoder_get_component_ptr (dec, 1, &ptr, &rowstride); sl@0: jpeg_decoder_get_component_size (dec, 1, &width, &height); sl@0: sl@0: dump_pgm (ptr, rowstride, width, height); sl@0: sl@0: std_log(LOG_FILENAME_LINE, "Test Successful"); sl@0: create_xml(0); sl@0: return 0; sl@0: } sl@0: sl@0: sl@0: /* getfile */ sl@0: sl@0: void * sl@0: getfile (char *path, int *n_bytes) sl@0: { sl@0: int fd; sl@0: struct stat st; sl@0: void *ptr = NULL; sl@0: int ret; sl@0: sl@0: fd = open (path, O_RDONLY); sl@0: if (!fd) sl@0: return NULL; sl@0: sl@0: ret = fstat (fd, &st); sl@0: if (ret < 0) { sl@0: close (fd); sl@0: return NULL; sl@0: } sl@0: sl@0: ptr = malloc (st.st_size); sl@0: if (!ptr) { sl@0: close (fd); sl@0: return NULL; sl@0: } sl@0: sl@0: ret = read (fd, ptr, st.st_size); sl@0: if (ret != st.st_size) { sl@0: free (ptr); sl@0: close (fd); sl@0: return NULL; sl@0: } sl@0: sl@0: if (n_bytes) sl@0: *n_bytes = st.st_size; sl@0: sl@0: close (fd); sl@0: return ptr; sl@0: } sl@0: sl@0: static void sl@0: dump_pgm (unsigned char *ptr, int rowstride, int width, int height) sl@0: { sl@0: int x, y; sl@0: sl@0: printf ("P2\n"); sl@0: printf ("%d %d\n", width, height); sl@0: printf ("255\n"); sl@0: sl@0: for (y = 0; y < height; y++) { sl@0: for (x = 0; x < width; x++) { sl@0: printf ("%d ", ptr[x]); sl@0: if ((x & 15) == 15) { sl@0: printf ("\n"); sl@0: } sl@0: } sl@0: printf ("\n"); sl@0: ptr += rowstride; sl@0: } sl@0: }