summaryrefslogtreecommitdiff
path: root/XMPFiles/source/FileHandlers/GIF_Handler.hpp
blob: 10ef3f9db9cb5e6395fb0bea8713ec1961f24ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef __GIF_Handler_hpp__
#define __GIF_Handler_hpp__	1

// =================================================================================================
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// 
// This file includes implementation of GIF file metadata, according to GIF89a Specification. 
// https://www.w3.org/Graphics/GIF/spec-gif89a.txt
// The Graphics Interchange Format(c) is the Copyright property of CompuServe Incorporated. 
// GIF(sm) is a Service Mark property of CompuServe Incorporated.
// All Rights Reserved . http://www.w3.org/Consortium/Legal
//
//Derived from PNG_Handler.hpp by Ian Jacobi
// =================================================================================================

#include "public/include/XMP_Environment.h"	// ! Must be the first #include!

#include "public/include/XMP_Const.h"
#include "public/include/XMP_IO.hpp"

#include "XMPFiles/source/XMPFiles_Impl.hpp"

// =================================================================================================
/// \file GIF_Handler.hpp
/// \brief File format handler for GIF.
///
/// This header ...
///
// =================================================================================================

// *** Could derive from Basic_Handler - buffer file tail in a temp file.

extern XMPFileHandler* GIF_MetaHandlerCTor ( XMPFiles* parent );

extern bool GIF_CheckFormat ( XMP_FileFormat format,
							   XMP_StringPtr filePath,
                               XMP_IO*       fileRef,
                               XMPFiles*     parent );

static const XMP_OptionBits kGIF_HandlerFlags = ( kXMPFiles_CanInjectXMP |
												  kXMPFiles_CanExpand |
												  kXMPFiles_PrefersInPlace |
												  kXMPFiles_AllowsOnlyXMP |
												  kXMPFiles_ReturnsRawPacket |
												  kXMPFiles_NeedsReadOnlyPacket
													);

class GIF_MetaHandler : public XMPFileHandler
{
public:

	void CacheFileData();
	void ProcessXMP();

	void UpdateFile ( bool doSafeUpdate );
	void WriteTempFile ( XMP_IO* tempRef );

	bool SafeWriteFile ();

	GIF_MetaHandler ( XMPFiles* parent );
	virtual ~GIF_MetaHandler();

private:

	enum GIFBlockType 
	{
		kXMP_block_ImageDesc = 0x2C,
		kXMP_block_Extension = 0x21,
		kXMP_block_Trailer = 0x3B,
		kXMP_block_Header = 0x47
	};

	XMP_Uns64 XMPPacketOffset;
	XMP_Uns32 XMPPacketLength;
	XMP_Uns64 trailerOffset;

	bool ParseGIFBlocks( XMP_IO * fileRef );
	void ReadLogicalScreenDesc( XMP_IO* fileRef );
	void SeekFile( XMP_IO * fileRef, XMP_Int64 offset, SeekMode mode );

};	// GIF_MetaHandler

// =================================================================================================

#endif /* __GIF_Handler_hpp__ */