57361504c44772e5a26b94942be5e90f4a24f211
[asdcplib.git] / src / j2c-test.cpp
1 /*
2 Copyright (c) 2005-2006, John Hurst
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11    notice, this list of conditions and the following disclaimer in the
12    documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14    derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 /*! \file    jp2k-test.cpp
28     \version $Id$
29     \brief   JP2K parser test
30 */
31
32 #include <AS_DCP.h>
33 #include <KM_fileio.h>
34 #include <KM_util.h>
35 #include <JP2K.h>
36
37 using namespace Kumu;
38 using namespace ASDCP;
39 using namespace ASDCP::JP2K;
40
41 //
42 int
43 main(int argc, const char** argv)
44 {
45   ASDCP::JP2K::FrameBuffer FB;
46   Marker        MyMarker;
47
48   if ( argc < 2 )
49     return 1;
50
51   FB.Capacity(1024*1024*2);
52   CodestreamParser Parser;
53
54   Result_t result = Parser.OpenReadFrame(argv[1], FB);
55
56   if ( result != RESULT_OK )
57     {
58       fputs("Program stopped on error.\n", stderr);
59
60       if ( result != RESULT_FAIL )
61         {
62           fputs(result.Label(), stderr);
63           fputc('\n', stderr);
64         }
65
66       return 1;
67     }
68
69   const byte_t* p = FB.RoData();
70   const byte_t* end_p = p + FB.Size();
71
72   hexdump(p, 256, stderr);
73
74   while ( p < end_p && ASDCP_SUCCESS(GetNextMarker(&p, MyMarker)) )
75     {
76       MyMarker.Dump();
77
78       switch ( MyMarker.m_Type )
79         {
80         case MRK_SOD:
81           p = end_p;
82           break;
83
84         case MRK_SIZ:
85           {
86             Accessor::SIZ SIZ_(MyMarker);
87             hexdump(MyMarker.m_Data - 2, MyMarker.m_DataSize + 2, stderr);
88             SIZ_.Dump();
89           }
90           break;
91
92         case MRK_COM:
93           {
94             Accessor::COM COM_(MyMarker);
95             COM_.Dump();
96           }
97           break;
98         }
99     }
100       
101   return 0;
102 }
103
104
105 //
106 // end jp2k-test.cpp
107 //