* apps/include/graphics/tiff.h
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
* "TIFF, Revision 6.0, Final," June 3, 1992, Adobe Developers Association.
*/
#ifndef __APPS_INCLUDE_GRAPHICS_TIFF_H
#define __APPS_INCLUDE_GRAPHICS_TIFF_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/nx/nxglib.h>
* Pre-processor Definitions
****************************************************************************/
#define IFD_FIELD_BYTE 1
#define IFD_FIELD_ASCII 2
* The last byte must be NUL */
#define IFD_FIELD_SHORT 3
#define IFD_FIELD_LONG 4
#define IFD_FIELD_RATIONAL 5
* numerator of a fraction, the second the
* denominator */
#define IFD_FIELD_SBYTE 6
#define IFD_FIELD_UNDEFINED 7
* depending on the definition of the field */
#define IFD_FIELD_SSHORT 8
* integer */
#define IFD_FIELD_SLONG 9
* integer */
#define IFD_FIELD_SRATIONAL 10
* numerator of a fraction, the second the
* denominator */
#define IFD_FIELD_FLOAT 11
#define IFD_FIELD_DOUBLE 12
#define IFD_TAG_NEWSUBFILETYPE 254
# define TAG_NEWSUBFILETYPE_REDUCED (1 << 0)
# define TAG_NEWSUBFILETYPE_SINGLE (1 << 1)
# define TAG_NEWSUBFILETYPE_TRANSP (1 << 2)
#define IFD_TAG_SUBFILETYPE 255
# define TAG_SUBFILETYPE_FULL 1
# define TAG_SUBFILETYPE_REDUCED 2
# define TAG_SUBFILETYPE_SINGLE 3
#define IFD_TAG_IMAGEWIDTH 256
#define IFD_TAG_IMAGELENGTH 257
#define IFD_TAG_BITSPERSAMPLE 258
* in greyscale and palette-color image files) */
#define IFD_TAG_COMPRESSION 259
# define TAG_COMP_NONE 1
# define TAG_COMP_CCITT 2
* run length encoding */
# define TAG_COMP_T4 3
# define TAG_COMP_T6 4
# define TAG_COMP_LZW 5
# define TAG_COMP_JPEG 6
# define TAG_COMP_PACKBITS 32773
#define IFD_TAG_PMI 262
# define TAG_PMI_WHITE 0
# define TAG_PMI_BLACK 1
# define TAG_PMI_RGB 2
# define TAG_PMI_PALETTE 3
# define TAG_PMI_TRANSP 4
# define TAG_PMI_CMYK 5
# define TAG_PMI_YCbCr 6
# define TAG_PMI_CIELAB 8
#define IFD_TAG_THRESHHOLDING 263
# define TAG_THRESHHOLD_NONE 1
# define TAG_THRESHHOLD_ORDERED 2
# define TAG_THRESHHOLD_RANDOM 3
#define IFD_TAG_CELLWIDTH 264
#define IFD_TAG_CELLLENGTH 265
#define IFD_TAG_FILLORDER 266
# define TAG_FILLORDER_HIGH 1
* higher-order bits */
# define TAG_FILLORDER_LOW 2
* lower-order bits */
#define IFD_TAG_DOCUMENTNAME 269
#define IFD_TAG_IMAGEDESCRIPTION 270
#define IFD_TAG_MAKE 271
#define IFD_TAG_MODEL 272
#define IFD_TAG_STRIPOFFSETS 273
#define IFD_TAG_ORIENTATION 274
# define TAG_ORIENTATION_TL 1
# define TAG_ORIENTATION_TR 2
# define TAG_ORIENTATION_BR 3
# define TAG_ORIENTATION_BL 4
# define TAG_ORIENTATION_LT 5
# define TAG_ORIENTATION_RT 6
# define TAG_ORIENTATION_RB 7
# define TAG_ORIENTATION_LB 8
#define IFD_TAG_SAMPLESPERPIXEL 277
* RGB full color files) */
#define IFD_TAG_ROWSPERSTRIP 278
#define IFD_TAG_STRIPCOUNTS 279
#define IFD_TAG_MINSAMPLEVALUE 280
#define IFD_TAG_MAXSAMPLEVALUE 281
#define IFD_TAG_XRESOLUTION 282
#define IFD_TAG_YRESOLUTION 283
#define IFD_TAG_PLANARCONFIG 284
# define TAG_PLCONFIG_CHUNKY 1
# define TAG_PLCONFIG_PLANAR 2
#define IFD_TAG_PAGENAME 285
#define IFD_TAG_XPOSITION 286
#define IFD_TAG_YPOSITION 287
#define IFD_TAG_FREEOFFSETS 288
#define IFD_TAG_FREEBYTECOUNTS 289
#define IFD_TAG_GRAYRESPONSEUNIT 290
# define TAG_GRAYRESPUNIT_10THS 1
# define TAG_GRAYRESPUNIT_100THS 2
# define TAG_GRAYRESPUNIT_1KTHS 3
# define TAG_GRAYRESPUNIT_10KTHS 4
# define TAG_GRAYRESPUNIT_100KTHS 5
#define IFD_TAG_GRAYRESPONSECURVE 291
#define IFD_TAG_T4OPTIONS 292
# define TAG_T4OPTIONS_2D (1 << 0)
# define TAG_T4OPTIONS_NONE (1 << 1)
# define TAG_T4OPTIONS_FILL (1 << 2)
#define IFD_TAG_T6OPTIONS 293
# define TAG_T6OPTIONS_NONE (1 << 1)
#define IFD_TAG_RESUNIT 296
# define TAG_RESUNIT_NONE 1
# define TAG_RESUNIT_INCH 2
# define TAG_RESUNIT_CENTIMETER 3
#define IFD_TAG_PAGENUMBER 297
#define IFD_TAG_TRANSFERFUNCTION 301
#define IFD_TAG_SOFTWARE 305
#define IFD_TAG_DATETIME 306
#define IFD_TAG_ARTIST 315
#define IFD_TAG_HOSTCOMPUTER 316
#define IFD_TAG_PREDICTOR 317
# define TAG_PREDICTOR_NONE 1
# define TAG_PREDICTOR_HORIZ 2
#define IFD_TAG_WHITEPOINT 318
#define IFD_TAG_PRIMARYCHROMA 319
#define IFD_TAG_COLORMAP 320
* color image files) */
#define IFD_TAG_HALFTONEHINTS 321
#define IFD_TAG_TILEWIDTH 322
#define IFD_TAG_TILELENGTH 323
#define IFD_TAG_TILEOFFSETS 324
#define IFD_TAG_TILEBYTECOUNTS 325
#define IFD_TAG_INKSET 332
# define TAG_INKSET_CMYK 1
# define TAG_INKSET_OTHER 2
#define IFD_TAG_INKNAMES 333
#define IFD_TAG_NUMBEROFINKS 334
#define IFD_TAG_DOTRANGE 336
#define IFD_TAG_TARGETPRINTER 337
#define IFD_TAG_EXTRASAMPLES 338
# define TAG_EXTSAMP_UNSPEC 0
# define TAG_EXTSAMP_ASSOCALPHA 1
# define TAG_EXTSAMP_UNASSALPHA 2
#define IFD_TAG_SAMPLEFORMAT 339
# define TAG_SAMPLEFMT_UNSIGED 1
# define TAG_SAMPLEFMT_SIGNED 2
# define TAG_SAMPLEFMT_FLOAT 3
# define TAG_SAMPLEFMT_UNDEFINED 4
#define IFD_TAG_SMINSAMPLEVALUE 340
#define IFD_TAG_SMAXSAMPLEVALUE 341
#define IFD_TAG_TRANSFERRANGE 342
#define IFD_TAG_JPEGPROC 512
#define IFD_TAG_JPEGFMT 513
#define IFD_TAG_JPEGLENGTH 514
#define IFD_TAG_JPEGRESTART 515
#define IFD_TAG_JPEGLLPREDICTORS 517
#define IFD_TAG_JPEGPOINTXFORMS 518
#define IFD_TAG_JPEGQTABLES 519
#define IFD_TAG_JPEGDCTABLES 520
#define IFD_TAG_JPEGACTABLES 521
#define IFD_TAG_YCbCrCOEFFS 529
#define IFD_TAG_YCbCrSUBSAMPLING 530
#define IFD_TAG_YCbCrPOSITIONING 531
#define IFD_TAG_REFERENCEBW 532
#define IFD_TAG_COPYRIGHT 33432
* Public Types
****************************************************************************/
* image file directory (IFD). An image file directory contains information
* about the image, as well as pointers to the actual image data."
*/
struct tiff_header_s
{
uint8_t order[2];
uint8_t magic[2];
uint8_t offset[4];
};
#define SIZEOF_TIFF_HEADER 8
* of directory entries (i.e., the number of fields), followed by a sequence
* of 12-byte field entries, followed by a 4-byte offset of the next IFD (or
* 0 if none).
*
* Each 12-byte IFD entry has the following format:
*/
struct tiff_ifdentry_s
{
uint8_t tag[2];
uint8_t type[2];
uint8_t count[4];
uint8_t offset[4];
};
#define SIZEOF_IFD_ENTRY 12
* also structures used only internally by the TIFF file creation library).
*/
struct tiff_strip_s
{
uint32_t offset;
uint32_t count;
};
* to manage file offsets.
*/
struct tiff_filefmt_s
{
uint16_t nifdentries;
uint16_t soifdoffset;
uint16_t sbcifdoffset;
uint16_t valoffset;
uint16_t xresoffset;
uint16_t yresoffset;
uint16_t swoffset;
uint16_t dateoffset;
uint16_t sbcoffset;
};
* construction
*/
struct tiff_info_s
{
* logic via tiff_initialize().
*
* Filenames. Three file names are required. (1) path to the final
* output file and (2) two paths to temporary files. One temporary file
* (tmpfile1) will be used to hold the strip image data and the other
* (tmpfile2) will be used to hold strip offset and count information.
*
* colorfmt - Specifies the form of the color data that will be provided
* in the strip data. These are the FB_FMT_* definitions
* provided in include/nuttx/video/fb.h. Only the following
* values are supported:
*
* FB_FMT_Y1 BPP=1, monochrome, 0=black
* FB_FMT_Y4 BPP=4, 4-bit greyscale, 0=black
* FB_FMT_Y8 BPP=8, 8-bit greyscale, 0=black
* FB_FMT_RGB16_565 BPP=16 R=6, G=6, B=5
* FB_FMT_RGB24 BPP=24 R=8, G=8, B=8
*
* rps - TIFF RowsPerStrip
* imgwidth - TIFF ImageWidth, Number of columns in the image
* imgheight - TIFF ImageLength, Number of rows in the image
*/
FAR const char *outfile;
FAR const char *tmpfile1;
FAR const char *tmpfile2;
uint8_t colorfmt;
nxgl_coord_t rps;
nxgl_coord_t imgwidth;
nxgl_coord_t imgheight;
* used for color conversions and as the intermediate buffer for copying
* files. The larger the buffer, the better the performance.
*/
FAR uint8_t *iobuffer;
unsigned int iosize;
* creation logic. These fields must be set to zero initially by the
* caller of tiff_initialize(). User logic should not depend upon any
* definitions in the following -- they are subject to change without
* notice. They are only exposed here so that the caller can allocate
* memory for their storage.
*/
uint8_t imgflags;
nxgl_coord_t nstrips;
size_t pps;
size_t bps;
int outfd;
int tmp1fd;
int tmp2fd;
off_t outsize;
off_t tmp1size;
off_t tmp2size;
FAR const struct tiff_filefmt_s *filefmt;
};
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
* Name: tiff_initialize
*
* Description:
* Setup to create a new TIFF file. The overall steps to creating a
* TIFF file are as follows:
*
* 1) Create an initialize a struct tiff_info_s instance
* 2) Call tiff_initialize() to setup the file creation
* 3) Call tiff_addstrip() repeatedly to add strips to the graphic image
* 4) Call tiff_finalize() to complete the file creation.
*
* Input Parameters:
* info - A pointer to the caller allocated parameter passing/TIFF state
* instance.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int tiff_initialize(FAR struct tiff_info_s *info);
* Name: tiff_addstrip
*
* Description:
* Add an image data strip. The size of the strip in pixels
* must be equal to the RowsPerStrip x ImageWidth values
* that were provided to tiff_initialize().
*
* Input Parameters:
* info - A pointer to the caller allocated parameter passing/TIFF state
* instance.
* buffer - A buffer containing a single row of data.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip);
* Name: tiff_finalize
*
* Description:
* Finalize the TIFF output file, completing the TIFF file creation steps.
*
* Input Parameters:
* info - A pointer to the caller allocated parameter passing/TIFF state
* instance.
*
* Returned Value:
* Zero (OK) on success. A negated errno value on failure.
*
****************************************************************************/
int tiff_finalize(FAR struct tiff_info_s *info);
* Name: tiff_abort
*
* Description:
* Abort the TIFF file creation and create-up resources.
*
* Input Parameters:
* info - A pointer to the caller allocated parameter passing/TIFF state
* instance.
*
* Returned Value:
* None
*
****************************************************************************/
void tiff_abort(FAR struct tiff_info_s *info);
* Name: tiff_put/get16/32
*
* Description:
* Put and get 16 and 32 values in the correct byte order at the specified
* position.
*
* Input Parameters:
* dest - The location to store the multi-byte data (put only)
* src - The location to get the multi-byte data (get only)
*
* Returned Value:
* None (put)
* The extracted value (get)
*
****************************************************************************/
void tiff_put16(FAR uint8_t *dest, uint16_t value);
void tiff_put32(FAR uint8_t *dest, uint32_t value);
uint16_t tiff_get16(FAR uint8_t *dest);
uint32_t tiff_get32(FAR uint8_t *dest);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif