2011-09-22 16:53:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/graphics/tiff/tiff_main.c
|
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2011-09-22 16:53:15 +02:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-09-22 16:53:15 +02:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2011-09-22 16:53:15 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "graphics/tiff.h"
|
2011-09-22 16:53:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-Processor Definitions
|
|
|
|
****************************************************************************/
|
2011-09-22 20:28:42 +02:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
/* This is a simple unit test for the TIFF creation library at apps/graphic/tiff.
|
|
|
|
* It is configured to work in the Linux user-mode simulation and has not been
|
2019-10-06 14:14:39 +02:00
|
|
|
* tested in any other environment.
|
2011-09-22 20:28:42 +02:00
|
|
|
*
|
|
|
|
* Other configuration options:
|
|
|
|
*
|
|
|
|
* CONFIG_EXAMPLES_TIFF_OUTFILE - Name of the resulting TIFF file
|
|
|
|
* CONFIG_EXAMPLES_TIFF_TMPFILE1/2 - Names of two temporaries files that
|
|
|
|
* will be used in the file creation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_TIFF_OUTFILE
|
|
|
|
# define CONFIG_EXAMPLES_TIFF_OUTFILE "/tmp/result.tif"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_TIFF_TMPFILE1
|
|
|
|
# define CONFIG_EXAMPLES_TIFF_TMPFILE1 "/tmp/tmpfile1.dat"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_TIFF_TMPFILE2
|
|
|
|
# define CONFIG_EXAMPLES_TIFF_TMPFILE2 "/tmp/tmpfile2.dat"
|
|
|
|
#endif
|
2011-09-22 16:53:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-08-30 22:13:50 +02:00
|
|
|
* Name: tiff_main
|
2011-09-22 16:53:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* TIFF unit test.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2011-09-22 16:53:15 +02:00
|
|
|
{
|
|
|
|
struct tiff_info_s info;
|
|
|
|
uint8_t strip[3*256];
|
|
|
|
uint8_t *ptr;
|
|
|
|
int green;
|
|
|
|
int blue;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Configure the interface structure */
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(struct tiff_info_s));
|
2011-09-22 20:28:42 +02:00
|
|
|
info.outfile = CONFIG_EXAMPLES_TIFF_OUTFILE;
|
|
|
|
info.tmpfile1 = CONFIG_EXAMPLES_TIFF_TMPFILE1;
|
|
|
|
info.tmpfile2 = CONFIG_EXAMPLES_TIFF_TMPFILE2;
|
2011-09-22 16:53:15 +02:00
|
|
|
info.colorfmt = FB_FMT_RGB24;
|
|
|
|
info.rps = 1;
|
|
|
|
info.imgwidth = 256;
|
|
|
|
info.imgheight = 256;
|
|
|
|
info.iobuffer = (uint8_t *)malloc(300);
|
|
|
|
info.iosize = 300;
|
|
|
|
|
|
|
|
/* Initialize the TIFF library */
|
|
|
|
|
|
|
|
ret = tiff_initialize(&info);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf("tiff_initialize() failed: %d\n", ret);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add each strip to the TIFF file */
|
|
|
|
|
|
|
|
for (green = 0, ptr = strip; green < 256; green++)
|
|
|
|
{
|
2011-09-22 20:28:42 +02:00
|
|
|
ptr = strip;
|
2011-09-22 16:53:15 +02:00
|
|
|
for (blue = 0; blue < 256; blue++)
|
|
|
|
{
|
|
|
|
*ptr++ = (green + blue) >> 1;
|
|
|
|
*ptr++ = green;
|
2014-04-14 00:24:28 +02:00
|
|
|
*ptr++ = blue;
|
2011-09-22 16:53:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = tiff_addstrip(&info, strip);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf("tiff_addstrip() #%d failed: %d\n", green, ret);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then finalize the TIFF file */
|
|
|
|
|
|
|
|
ret = tiff_finalize(&info);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2011-09-22 20:28:42 +02:00
|
|
|
printf("tiff_finalize() failed: %d\n", ret);
|
2011-09-22 16:53:15 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|