1 /* GStreamer 2 * Copyright (C) 2010 Oblong Industries, Inc. 3 * Copyright (C) 2010 Collabora Multimedia 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef __JP2K_CODESTREAM_H__ 22 #define __JP2K_CODESTREAM_H__ 23 24 #include <gst/gst.h> 25 #include <gst/base/gstbytereader.h> 26 #include <gst/base/gstbitreader.h> 27 #include <gst/base/gstbytewriter.h> 28 29 #include "gstjp2kdecimator.h" 30 31 /* Used to represent codestream packets */ 32 typedef struct 33 { 34 gboolean sop; 35 gboolean eph; 36 guint16 seqno; 37 38 const guint8 *data; 39 guint length; 40 } Packet; 41 42 /* Used to represent unparsed markers for passthrough */ 43 typedef struct 44 { 45 const guint8 *data; 46 guint length; 47 } Buffer; 48 49 typedef struct 50 { 51 guint8 s; /* sample precision */ 52 guint8 xr, yr; /* resolution */ 53 } ComponentSize; 54 55 /* SIZ */ 56 typedef struct 57 { 58 guint16 caps; /* capabilities */ 59 guint32 x, y; /* reference grid size */ 60 guint32 xo, yo; /* origin */ 61 ComponentSize *components; 62 guint16 n_components; 63 guint32 xt, yt; /* tile sizes */ 64 guint32 xto, yto; /* tile origin */ 65 } ImageSize; 66 67 /* Progression orders 68 * L - layer 69 * R - resolution/decomposition level 70 * C - component 71 * P - position/precinct 72 */ 73 typedef enum 74 { 75 PROGRESSION_ORDER_LRCP = 0, 76 PROGRESSION_ORDER_RLCP, 77 PROGRESSION_ORDER_RPCL, 78 PROGRESSION_ORDER_PCRL, 79 PROGRESSION_ORDER_CPRL, 80 PROGRESSION_ORDER_MAX 81 } ProgressionOrder; 82 83 /* COD */ 84 typedef struct 85 { 86 /* Scod */ 87 gboolean sop, eph; 88 /* SGcod */ 89 ProgressionOrder progression_order; 90 guint16 n_layers; 91 guint8 multi_component_transform; 92 /* SPcod */ 93 guint8 n_decompositions; 94 guint8 xcb, ycb; /* code block dimensions */ 95 guint8 code_block_style; 96 guint8 transformation; 97 guint8 *PPx, *PPy; /* precinct sizes (default:15, 98 * otherwise n_decompositions+1 elements) */ 99 } CodingStyleDefault; 100 101 /* SOT */ 102 typedef struct 103 { 104 guint16 tile_index; 105 guint32 tile_part_size; 106 guint8 tile_part_index, n_tile_parts; 107 } StartOfTile; 108 109 /* PLT */ 110 typedef struct 111 { 112 guint8 index; 113 GArray *packet_lengths; /* array of guint32 */ 114 } PacketLengthTilePart; 115 116 typedef struct 117 { 118 StartOfTile sot; 119 CodingStyleDefault *cod; 120 121 Buffer *qcd; 122 GList *qcc; /* list of Buffer */ 123 124 GList *plt; /* list of PacketLengthTilePart */ 125 126 GList *com; /* list of Buffer */ 127 128 GList *packets; /* list of Packet, codestream */ 129 130 /* TODO: COC, PPT */ 131 132 /* Calculated value */ 133 gint tile_x, tile_y; 134 gint tx0, tx1, ty0, ty1; /* tile dimensions */ 135 } Tile; 136 137 typedef struct 138 { 139 /* Parsed values */ 140 ImageSize siz; 141 CodingStyleDefault cod; 142 143 Buffer qcd; 144 GList *qcc; /* list of Buffer */ 145 GList *crg, *com; /* lists of Buffer */ 146 147 /* TODO: COC, PPM, TLM, PLM */ 148 149 guint n_tiles_x, n_tiles_y, n_tiles; /* calculated */ 150 Tile *tiles; 151 } MainHeader; 152 153 typedef struct _PacketIterator PacketIterator; 154 struct _PacketIterator 155 { 156 gboolean (*next) (PacketIterator * it); 157 const MainHeader *header; 158 const Tile *tile; 159 160 gboolean first; 161 162 gint cur_layer; 163 gint cur_resolution; 164 gint cur_component; 165 gint cur_precinct; 166 gint cur_x, cur_y; 167 168 gint n_layers; 169 gint n_resolutions; 170 gint n_components; 171 gint n_precincts, n_precincts_w, n_precincts_h; 172 173 gint tx0, tx1, ty0, ty1; 174 gint x_step, y_step; 175 176 /* cached calculated values */ 177 /* depends on resolution and component */ 178 gint tcx0, tcx1, tcy0, tcy1; 179 gint trx0, trx1, try0, try1; 180 gint tpx0, tpx1, tpy0, tpy1; 181 gint yr, xr; 182 gint two_nl_r, two_ppx, two_ppy; 183 184 gint cur_packet; 185 }; 186 187 GstFlowReturn parse_main_header (GstJP2kDecimator * self, GstByteReader * reader, MainHeader * header); 188 guint sizeof_main_header (GstJP2kDecimator * self, const MainHeader * header); 189 void reset_main_header (GstJP2kDecimator * self, MainHeader * header); 190 GstFlowReturn write_main_header (GstJP2kDecimator * self, GstByteWriter * writer, const MainHeader * header); 191 GstFlowReturn decimate_main_header (GstJP2kDecimator * self, MainHeader * header); 192 193 #endif /* __JP2K_CODESTREAM_H__ */ 194