shithub: jbig2

Download patch

ref: 57c5cda834b84dbec0f4898427bf4283dc2c327d
parent: e22ae8f124c9ed5a3ccadbad3a302285d94ffc4c
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Sat Jun 15 10:15:12 EDT 2002

Add page segment parse and dump routines.


git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@62 ded80894-8fb9-0310-811b-c03f3676ab4d

--- /dev/null
+++ b/jbig2_page.c
@@ -1,0 +1,82 @@
+/*
+    jbig2dec
+    
+    Copyright (c) 2001 artofcode LLC.
+    
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    $Id: jbig2_page.c,v 1.1 2002/06/15 14:15:12 giles Exp $
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "jbig2.h"
+#include "jbig2_priv.h"
+#include "jbig2_page.h"
+
+/* parse the page info segment data starting at ctx->offset
+   a pointer to a new Jbig2PageInfo struct is returned
+
+   the ctx->offset pointer is not advanced; the caller must
+   take care of that, using the data_length field of the
+   segment header.
+*/
+static Jbig2PageInfo *
+jbig2_read_page_info (Jbig2Ctx *ctx) {
+  Jbig2PageInfo *info = (Jbig2PageInfo *)jbig2_alloc(ctx->allocator, sizeof(Jbig2PageInfo));
+  int offset = ctx->buf_rd_idx;
+
+	if (info == NULL) {
+		printf("unable to allocate memory to parse page info segment\n");
+		return NULL;
+	}
+	
+	info->width = get_int32(ctx, offset);
+	info->height = get_int32(ctx, offset + 4);
+	offset += 8;
+	
+	info->x_resolution = get_int32(ctx, offset);
+	info->y_resolution = get_int32(ctx, offset + 4);
+	offset += 8;
+	
+	get_bytes(ctx, &(info->flags), 1, offset++);
+	
+	{
+	int16 striping = get_int16(ctx, offset);
+	if (striping & 0x8000) {
+		info->striped = TRUE;
+		info->stripe_size = striping & 0x7FFF;
+	} else {
+		info->striped = FALSE;
+		info->stripe_size = 0;	/* would info->height be better? */
+	}
+	offset += 2;
+	}
+	
+	return info;
+}
+
+/* dump the page info struct */
+static void
+dump_page_info(Jbig2PageInfo *info)
+{
+    FILE *out = stderr;
+    
+    fprintf(out, "image is %dx%d ", info->width, info->height);
+    if (info->x_resolution == 0) {
+        fprintf(out, "(unknown res) ");
+    } else if (info->x_resolution == info->y_resolution) {
+        fprintf(out, "(%d ppm) ", info->x_resolution);
+    } else {
+        fprintf(out, "(%dx%d ppm) ", info->x_resolution, info->y_resolution);
+    }
+    if (info->striped) {
+        fprintf(out, "\tmaximum stripe size: %d\n", info->stripe_size);
+    } else {
+        fprintf(out, "\tno striping\n");
+    }
+}
\ No newline at end of file
--- /dev/null
+++ b/jbig2_page.h
@@ -1,0 +1,33 @@
+/*
+    jbig2dec
+    
+    Copyright (c) 2001 artofcode LLC.
+    
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    $Id: jbig2_page.h,v 1.1 2002/06/15 14:15:12 giles Exp $
+*/
+
+#ifndef JBIG2_PAGE_H
+#define JBIG2_PAGE_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "jbig2dec.h"
+
+
+struct _Jbig2PageInfo {
+	uint32_t	height, width;	/* in pixels */
+	uint32_t	x_resolution,
+                        y_resolution;	/* in pixels per meter */
+	uint16_t	stripe_size;
+	bool		striped;
+	uint8_t		flags;
+};
+
+#endif /* JBIG2_PAGE_H */