First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include <liboil/liboil.h>
25 #include "liboil/liboilcolorspace.h"
28 #define LOG_FILE "c:\\logs\\examples_jpeg_rgb_log1.txt"
29 #include "std_log_result.h"
30 #define LOG_FILENAME_LINE __FILE__, __LINE__
32 void create_xml(int result)
37 testResultXml("examples_jpeg_rgb");
43 void *getfile (char *path, int *n_bytes);
44 static void dump_pnm (uint32_t *ptr, int rowstride, int width, int height);
47 main (int argc, char *argv[])
51 char *fn = "c:\\data\\liboil\\test.jpg";
52 uint32_t *image = NULL;
56 std_log(LOG_FILENAME_LINE, "Test Started examples_jpeg_rgb");
59 printf("jpeg_rgb_test <file.jpg>\n");
60 std_log(LOG_FILENAME_LINE,"jpeg_rgb_test <file.jpg>");
66 std_log(LOG_FILENAME_LINE,"fn = %s",fn);
67 data = getfile (fn, &len);
70 printf("cannot read file %s\n", fn);
74 ret = jpeg_decode_argb (data, len, &image, &width, &height);
76 dump_pnm (image, width*4, width, height);
79 if (image) free (image);
83 std_log(LOG_FILENAME_LINE, "Test Successful");
93 getfile (char *path, int *n_bytes)
99 std_log(LOG_FILENAME_LINE, "getfile ENTER");
100 fd = open (path, O_RDONLY);
104 ret = fstat (fd, &st);
110 ptr = malloc (st.st_size);
116 ret = read (fd, ptr, st.st_size);
117 if (ret != st.st_size) {
124 *n_bytes = st.st_size;
127 std_log(LOG_FILENAME_LINE, "getfile EXIT");
132 dump_pnm (uint32_t *ptr, int rowstride, int width, int height)
137 printf ("%d %d\n", width, height);
139 std_log(LOG_FILENAME_LINE, "P3");
140 std_log(LOG_FILENAME_LINE, "%d %d",width, height);
141 std_log(LOG_FILENAME_LINE, "255");
143 for (y = 0; y < height; y++) {
144 for (x = 0; x < width; x++) {
145 printf ("%d ", oil_argb_R(ptr[x]));
146 printf ("%d ", oil_argb_G(ptr[x])); //Extracts the green component from color.Evaluates to the green component
147 printf ("%d ", oil_argb_B(ptr[x]));
148 std_log(LOG_FILENAME_LINE, "%d ",oil_argb_R(ptr[x]));
149 std_log(LOG_FILENAME_LINE, "%d ",oil_argb_G(ptr[x]));
150 std_log(LOG_FILENAME_LINE, "%d ",oil_argb_B(ptr[x]));
151 if ((x & 15) == 15) {