sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <sys/stat.h>
|
sl@0
|
19 |
#include <fcntl.h>
|
sl@0
|
20 |
#include <unistd.h>
|
sl@0
|
21 |
#include <stdlib.h>
|
sl@0
|
22 |
#include <stdio.h>
|
sl@0
|
23 |
#include "jpeg.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
#define LOG_FILE "c:\\logs\\examples_jpeg_log1.txt"
|
sl@0
|
26 |
#include "std_log_result.h"
|
sl@0
|
27 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
28 |
|
sl@0
|
29 |
void create_xml(int result)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
if(result)
|
sl@0
|
32 |
assert_failed = 1;
|
sl@0
|
33 |
|
sl@0
|
34 |
testResultXml("examples_jpeg");
|
sl@0
|
35 |
close_log_file();
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
/* getfile */
|
sl@0
|
39 |
|
sl@0
|
40 |
void *getfile (char *path, int *n_bytes);
|
sl@0
|
41 |
static void dump_pgm (unsigned char *ptr, int rowstride, int width, int height);
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
int
|
sl@0
|
45 |
main (int argc, char *argv[])
|
sl@0
|
46 |
{
|
sl@0
|
47 |
unsigned char *data;
|
sl@0
|
48 |
int len;
|
sl@0
|
49 |
JpegDecoder *dec;
|
sl@0
|
50 |
char *fn = "c:\\data\\liboil\\test.jpg";
|
sl@0
|
51 |
unsigned char *ptr;
|
sl@0
|
52 |
int rowstride;
|
sl@0
|
53 |
int width;
|
sl@0
|
54 |
int height;
|
sl@0
|
55 |
|
sl@0
|
56 |
/*if (argc < 2) {
|
sl@0
|
57 |
printf("jpeg_test <file.jpg>\n");
|
sl@0
|
58 |
exit(1);
|
sl@0
|
59 |
}*/
|
sl@0
|
60 |
if (argc > 1)
|
sl@0
|
61 |
fn = argv[1];
|
sl@0
|
62 |
|
sl@0
|
63 |
std_log(LOG_FILENAME_LINE, "Test Started examples_jpeg");
|
sl@0
|
64 |
dec = jpeg_decoder_new (); //to create decoder instance
|
sl@0
|
65 |
|
sl@0
|
66 |
data = getfile (fn, &len);
|
sl@0
|
67 |
|
sl@0
|
68 |
jpeg_decoder_addbits (dec, data, len);
|
sl@0
|
69 |
jpeg_decoder_decode (dec);
|
sl@0
|
70 |
|
sl@0
|
71 |
jpeg_decoder_get_component_ptr (dec, 1, &ptr, &rowstride);
|
sl@0
|
72 |
jpeg_decoder_get_component_size (dec, 1, &width, &height);
|
sl@0
|
73 |
|
sl@0
|
74 |
dump_pgm (ptr, rowstride, width, height);
|
sl@0
|
75 |
|
sl@0
|
76 |
std_log(LOG_FILENAME_LINE, "Test Successful");
|
sl@0
|
77 |
create_xml(0);
|
sl@0
|
78 |
return 0;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
/* getfile */
|
sl@0
|
83 |
|
sl@0
|
84 |
void *
|
sl@0
|
85 |
getfile (char *path, int *n_bytes)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
int fd;
|
sl@0
|
88 |
struct stat st;
|
sl@0
|
89 |
void *ptr = NULL;
|
sl@0
|
90 |
int ret;
|
sl@0
|
91 |
|
sl@0
|
92 |
fd = open (path, O_RDONLY);
|
sl@0
|
93 |
if (!fd)
|
sl@0
|
94 |
return NULL;
|
sl@0
|
95 |
|
sl@0
|
96 |
ret = fstat (fd, &st);
|
sl@0
|
97 |
if (ret < 0) {
|
sl@0
|
98 |
close (fd);
|
sl@0
|
99 |
return NULL;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
ptr = malloc (st.st_size);
|
sl@0
|
103 |
if (!ptr) {
|
sl@0
|
104 |
close (fd);
|
sl@0
|
105 |
return NULL;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
ret = read (fd, ptr, st.st_size);
|
sl@0
|
109 |
if (ret != st.st_size) {
|
sl@0
|
110 |
free (ptr);
|
sl@0
|
111 |
close (fd);
|
sl@0
|
112 |
return NULL;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
if (n_bytes)
|
sl@0
|
116 |
*n_bytes = st.st_size;
|
sl@0
|
117 |
|
sl@0
|
118 |
close (fd);
|
sl@0
|
119 |
return ptr;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
static void
|
sl@0
|
123 |
dump_pgm (unsigned char *ptr, int rowstride, int width, int height)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
int x, y;
|
sl@0
|
126 |
|
sl@0
|
127 |
printf ("P2\n");
|
sl@0
|
128 |
printf ("%d %d\n", width, height);
|
sl@0
|
129 |
printf ("255\n");
|
sl@0
|
130 |
|
sl@0
|
131 |
for (y = 0; y < height; y++) {
|
sl@0
|
132 |
for (x = 0; x < width; x++) {
|
sl@0
|
133 |
printf ("%d ", ptr[x]);
|
sl@0
|
134 |
if ((x & 15) == 15) {
|
sl@0
|
135 |
printf ("\n");
|
sl@0
|
136 |
}
|
sl@0
|
137 |
}
|
sl@0
|
138 |
printf ("\n");
|
sl@0
|
139 |
ptr += rowstride;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
}
|