Commit 037a8b9c authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

jbig2

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62532 954022d7-b5bf-4e40-9824-e11837661b57
parent 36cbfb50
......@@ -7269,6 +7269,13 @@ DesktopEditor/mac_build/raster/raster.xcodeproj/xcuserdata svnc_tsvn_003alogmins
DesktopEditor/mac_build/raster/raster.xcodeproj/xcuserdata/alexey.musinov.xcuserdatad svnc_tsvn_003alogminsize=5
DesktopEditor/mac_build/raster/raster.xcodeproj/xcuserdata/alexey.musinov.xcuserdatad/xcschemes svnc_tsvn_003alogminsize=5
DesktopEditor/raster svn_global_002dignores=*%0A*.ncb%0A*.user%0A
DesktopEditor/raster/JBig2 svnc_tsvn_003alogminsize=5
DesktopEditor/raster/JBig2/linux svnc_tsvn_003alogminsize=5
DesktopEditor/raster/JBig2/source svnc_tsvn_003alogminsize=5
DesktopEditor/raster/JBig2/source/Decoder svnc_tsvn_003alogminsize=5
DesktopEditor/raster/JBig2/source/Encoder svnc_tsvn_003alogminsize=5
DesktopEditor/raster/JBig2/source/LeptonLib svnc_tsvn_003alogminsize=5
DesktopEditor/raster/JBig2/win32 svnc_tsvn_003alogminsize=5
DesktopEditor/raster/Jp2 svnc_tsvn_003alogminsize=5
DesktopEditor/raster/Metafile svnc_tsvn_003alogminsize=5 svn_global_002dignores
DesktopEditor/raster/Metafile/Common svnc_tsvn_003alogminsize=5
......@@ -2,6 +2,7 @@
#include "../common/File.h"
#include "../cximage/CxImage/ximage.h"
#include "Jp2/J2kFile.h"
#include "JBig2/JBig2File.h"
bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileType)
{
......
This diff is collapsed.
// Copyright 2006 Google Inc. All Rights Reserved.
// Author: agl@imperialviolet.org (Adam Langley)
//
// Copyright (C) 2006 Google Inc.
//
// Licensed 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.
#ifndef JBIG2ENC_JBIG2ENC_H__
#define JBIG2ENC_JBIG2ENC_H__
#include <vector>
#include "../LeptonLib/additionaltypes.h"
#define JBIG2_MAX_CTX 65536
#define JBIG2_OUTPUTBUFFER_SIZE 20 * 1024
#ifdef _MSC_VER
#define __restrict__ __restrict
#endif
//#define JBIG2_DEBUGGING
//#define CODER_DEBUGGING
//#define SYM_DEBUGGING
//#define SYMBOL_COMPRESSION_DEBUGGING
// -----------------------------------------------------------------------------
// This is the context for the arithmetic encoder used in JBIG2. The coder is a
// state machine and there are many different states used - one for coding
// images, many more for coding numbers etc.
//
// When outputting data, the bytes are collected into chunks of size
// JBIG2_OUTPUTBUFFER_SIZE. These are chained in a linked list.
// -----------------------------------------------------------------------------
struct jbig2enc_ctx {
// these are the current state of the arithmetic coder
uint32_t c;
uint16_t a;
uint8_t ct, b;
int bp;
// This is a list of output chunks, not including the current one
std::vector<uint8_t *> *output_chunks;
uint8_t *outbuf; // this is the current output chunk
int outbuf_used; // number of bytes used in outbuf
uint8_t context[JBIG2_MAX_CTX]; // state machine context for encoding images
uint8_t intctx[13][512]; // 512 bytes of context indexes for each of 13 different int decodings
// this data is also used for refinement coding
uint8_t *iaidctx; // size of this context not known at construction time
};
// these are the proc numbers for encoding different classes of integers
enum {
JBIG2_IAAI = 0,
JBIG2_IADH,
JBIG2_IADS,
JBIG2_IADT,
JBIG2_IADW,
JBIG2_IAEX,
JBIG2_IAFS,
JBIG2_IAIT,
JBIG2_IARDH,
JBIG2_IARDW,
JBIG2_IARDX,
JBIG2_IARDY,
JBIG2_IARI
};
// -----------------------------------------------------------------------------
// Returns the number of bytes of output in the given context
//
// Before doing this you should make sure that the coder is _flush()'ed
// -----------------------------------------------------------------------------
unsigned jbig2enc_datasize(const struct jbig2enc_ctx *ctx);
// -----------------------------------------------------------------------------
// Writes the output of the given context to a buffer. The buffer must be at
// least long enough to contain all the data (see _datasize)
// -----------------------------------------------------------------------------
void jbig2enc_tobuffer(const struct jbig2enc_ctx *__restrict__ ctx,
uint8_t *__restrict__ buffer);
// -----------------------------------------------------------------------------
// Encode an integer of a given class. proc is one of JBIG2_IA* and specifies
// the type of the number. IAID is special and is handled by another function.
// -----------------------------------------------------------------------------
void jbig2enc_int(struct jbig2enc_ctx *__restrict__ ctx, int proc, int value);
// -----------------------------------------------------------------------------
// Encode an IAID number. This needs to know how many bits to use.
// -----------------------------------------------------------------------------
void jbig2enc_iaid(struct jbig2enc_ctx *__restrict__ ctx, int symcodelen,
int value);
// -----------------------------------------------------------------------------
// Encode the special out-of-bounds (-0) number for a given type. proc is one
// of JBIG2_IA*
// -----------------------------------------------------------------------------
void jbig2enc_oob(struct jbig2enc_ctx *__restrict__ ctx, int proc);
// -----------------------------------------------------------------------------
// Encode a bitmap with the arithmetic encoder.
// data: an array of mx * my bytes
// mx: max x value
// my: max y value
// duplicate_line_removal: if true, TPGD is used
//
// TPGD often takes very slightly more bytes to encode, but cuts the time taken
// by half.
// -----------------------------------------------------------------------------
void jbig2enc_image(struct jbig2enc_ctx *__restrict__ ctx,
const uint8_t *__restrict__ data, int mx, int my,
bool duplicate_line_removal);
// -----------------------------------------------------------------------------
// This function takes almost the same arguments as _image, above. But in this
// case the data pointer points to packed data.
//
// This is designed for Leptonica's 1bpp packed format images. Each row is some
// number of 32-bit words.
//
// *The pad bits at the end of each line must be zero.*
// -----------------------------------------------------------------------------
void jbig2enc_bitimage(struct jbig2enc_ctx *__restrict__ ctx,
const uint8_t *__restrict__ data, int mx, int my,
bool duplicate_line_removal);
// -----------------------------------------------------------------------------
// Encode the refinement of an exemplar to a bitmap.
//
// This encodes the difference between two images. If the template image is
// close to the final image the amount of data needed should hopefully be
// small.
// templ: the template image
// tx, ty: the size of the template image
// target: the desired image
// mx, my: the size of the desired image
// ox, oy: offset of the desired image from the template image.
// ox is limited to [-1, 0, 1]
//
// This uses Leptonica's 1bpp packed images (see comments above last function).
//
// *The pad bits at the end of each line, for both images, must be zero*
// -----------------------------------------------------------------------------
void jbig2enc_refine(struct jbig2enc_ctx *__restrict__ ctx,
const uint8_t *__restrict__ templ, int tx, int ty,
const uint8_t *__restrict__ target, int mx, int my,
int ox, int oy);
// -----------------------------------------------------------------------------
// Init a new context
// -----------------------------------------------------------------------------
void jbig2enc_init(struct jbig2enc_ctx *ctx);
// -----------------------------------------------------------------------------
// Destroy a context
// -----------------------------------------------------------------------------
void jbig2enc_dealloc(struct jbig2enc_ctx *ctx);
// -----------------------------------------------------------------------------
// Flush all the data stored in a context
// -----------------------------------------------------------------------------
void jbig2enc_flush(struct jbig2enc_ctx *ctx);
// -----------------------------------------------------------------------------
// Reset the arithmetic coder back to a init state
// -----------------------------------------------------------------------------
void jbig2enc_reset(struct jbig2enc_ctx *ctx);
// -----------------------------------------------------------------------------
// Flush any remaining arithmetic encoder context to the output.
// -----------------------------------------------------------------------------
void jbig2enc_final(struct jbig2enc_ctx *ctx);
#endif // EXPERIMENTAL_USERS_AGL_JBIG2ENC_JBIG2ENC_H__
This diff is collapsed.
// Copyright 2006 Google Inc. All Rights Reserved.
// Author: agl@imperialviolet.org (Adam Langley)
//
// Copyright (C) 2006 Google Inc.
//
// Licensed 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.
#ifndef JBIG2ENC_JBIG2_H__
#define JBIG2ENC_JBIG2_H__
// -----------------------------------------------------------------------------
// Welcome gentle reader,
//
// This is an encoder for JBIG2:
// www.jpeg.org/public/fcd14492.pdf
//
// JBIG2 encodes bi-level (1 bpp) images using a number of clever tricks to get
// better compression than G4. This encoder can:
// * Generate JBIG2 files, or fragments for embedding in PDFs
// * Generic region encoding
// * Symbol extraction, classification and text region coding
//
// It uses the (Apache-ish licensed) Leptonica library:
// http://www.leptonica.com/
// -----------------------------------------------------------------------------
//#pragma comment ( lib, "Ws2_32.lib" )
#include "../LeptonLib/additionaltypes.h"
struct Pix;
// This is the (opaque) structure which handles multi-page compression.
struct jbig2ctx;
// -----------------------------------------------------------------------------
// Multipage compression.
//
// First call jbig2_init to setup the structure. This structure must be free'ed
// by calling jbig2_destroy when you are finished.
//
// First, add all the pages with jbig2_add_page. This will collect all the
// information required. If refinement is on, it will also save all the
// component images, so this may take large amounts of memory.
//
// Then call jbig2_pages_complete. This returns a malloced buffer with the
// symbol table encoded.
//
// Then call jbig2_produce_page for each page. You must call it with pages
// numbered from zero, and for every page.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Create a multi-page compression context structure
//
// thresh: The threshold for the classifier. The larger the number the larger
// the number of different symbols, the more bits used and the closer
// the resulting image is to the original. (0.85 is a good value)
// weight: Use 0.5
// xres: the ppi in the X direction. If 0, the ppi is taken from bw
// yres: see xres
// full_headers: if true a full JBIG2 file is produced, otherwise the data is
// only good for embedding in PDFs
// refine: If < 0, disable refinement. Otherwise, the number of incorrect
// pixels which will be accepted per symbol. Enabling refinement
// increases memory use.
// -----------------------------------------------------------------------------
struct jbig2ctx *jbig2_init(float thresh, float weight, int xres, int yres,
bool full_headers, int refine_level);
// -----------------------------------------------------------------------------
// Delete a context returned by jbig2_init
// -----------------------------------------------------------------------------
void jbig2_destroy(struct jbig2ctx *);
// -----------------------------------------------------------------------------
// Classify and record information about a page.
//
// bw: A 1-bpp image
// -----------------------------------------------------------------------------
void jbig2_add_page(struct jbig2ctx *ctx, struct Pix *bw);
// -----------------------------------------------------------------------------
// Finalise information about the document and encode the symbol table.
//
// WARNING: returns a malloced buffer which the caller must free
// -----------------------------------------------------------------------------
uint8_t *jbig2_pages_complete(struct jbig2ctx *ctx, int *const length);
// -----------------------------------------------------------------------------
// Encode a page.
//
// page_no: number of this page, indexed from 0. This *must* match the order of
// pages presented to jbig2_add_page.
// xres, yres: if -1, use values given in _init. Otherwise, set the resolution
// for this page only
//
// WARNING: returns a malloced buffer which the caller must free
// -----------------------------------------------------------------------------
uint8_t *jbig2_produce_page(struct jbig2ctx *ctx, int page_no, int xres,
int yres, int *const length);
// WARNING: returns a malloced buffer which the caller must free
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Single page compression
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Encode an image as a single generic region. This is lossless. It should not
// be used for images as half-tone coding is not implemented.
//
// see argument comments for jbig2_init
// duplicate_line_removal: turning this on
// * Breaks ghostscript
// * Takes ever so slightly more bytes to encode
// * Cuts the encode time by half
//
// WARNING: returns a malloced buffer which the caller must free
// -----------------------------------------------------------------------------
uint8_t *
jbig2_encode_generic(struct Pix *const bw, const bool full_headers,
const int xres, const int yres,
const bool duplicate_line_removal,
int *const length);
#endif // JBIG2ENC_JBIG2_H__
#ifndef _JBIG2_ENCODER_H
#define _JBIG2_ENCODER_H
#include <vector>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "../LeptonLib/allheaders.h"
#include "../LeptonLib/pix.h"
#include "jbig2enc.h"
#include "io.h"
#if defined(_WIN32) || defined (_WIN64)
// -----------------------------------------------------------------------------
// Windows, sadly, lacks asprintf
// -----------------------------------------------------------------------------
#include <stdarg.h>
int asprintf(char **strp, const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
const int required = vsnprintf(NULL, 0, fmt, va);
char *const buffer = (char *) malloc(required + 1);
const int ret = vsnprintf(buffer, required + 1, fmt, va);
*strp = buffer;
va_end(va);
return ret;
}
#endif
// -----------------------------------------------------------------------------
// Morphological operations for segmenting an image into text regions
// -----------------------------------------------------------------------------
static const char *segment_mask_sequence = "r11";
static const char *segment_seed_sequence = "r1143 + o4.4 + x4"; /* maybe o6.6 */
static const char *segment_dilation_sequence = "d3.3";
// -----------------------------------------------------------------------------
// Takes two pix as input, generated from the same original image:
// 1. pixb - a binary thresholded image
// 2. piximg - a full color or grayscale image
// and segments them by finding the areas that contain color or grayscale
// graphics, removing those areas from the binary image, and doing the
// opposite for the full color/grayscale image. The upshot is that after
// this routine has been run, the binary image contains only text and the
// full color image contains only the graphics.
//
// Both input images are modified by this procedure. If no text is found,
// pixb is set to NULL. If no graphics is found, piximg is set to NULL.
//
// Thanks to Dan Bloomberg for this
// -----------------------------------------------------------------------------
static PIX*
segment_image(PIX *pixb, PIX *piximg) {
// Make seed and mask, and fill seed into mask
PIX *pixmask4 = pixMorphSequence(pixb, (char *) segment_mask_sequence, 0);
PIX *pixseed4 = pixMorphSequence(pixb, (char *) segment_seed_sequence, 0);
PIX *pixsf4 = pixSeedfillBinary(NULL, pixseed4, pixmask4, 8);
PIX *pixd4 = pixMorphSequence(pixsf4, (char *) segment_dilation_sequence, 0);
// we want to force the binary mask to be the same size as the
// input color image, so we have to do it this way...
// is there a better way?
// PIX *pixd = pixExpandBinary(pixd4, 4);
PIX *pixd = pixCreate(piximg->w, piximg->h, 1);
pixCopyResolution(pixd, piximg);
expandBinaryPower2Low(pixd->data, pixd->w, pixd->h, pixd->wpl,
pixd4->data, pixd4->w, pixd4->h, pixd4->wpl, 4);
pixDestroy(&pixd4);
pixDestroy(&pixsf4);
pixDestroy(&pixseed4);
pixDestroy(&pixmask4);
pixSubtract(pixb, pixb, pixd);
// now see what we got from the segmentation
static l_int32 *tab = NULL;
if (tab == NULL) tab = makePixelSumTab8();
// if no image portion was found, set the image pointer to NULL and return
l_int32 pcount;
pixCountPixels(pixd, &pcount, tab);
if (pcount < 100) {
pixDestroy(&pixd);
return NULL;
}
// if no text portion found, set the binary pointer to NULL
pixCountPixels(pixb, &pcount, tab);
if (pcount < 100) {
pixDestroy(&pixb);
}
PIX *piximg1;
if (piximg->d == 1 || piximg->d == 8 || piximg->d == 32) {
piximg1 = pixClone(piximg);
} else if (piximg->d > 8) {
piximg1 = pixConvertTo32(piximg);
} else {
piximg1 = pixConvertTo8(piximg, FALSE);
}
PIX *pixd1;
if (piximg1->d == 32) {
pixd1 = pixConvertTo32(pixd);
} else if (piximg1->d == 8) {
pixd1 = pixConvertTo8(pixd, FALSE);
} else {
pixd1 = pixClone(pixd);
}
pixDestroy(&pixd);
pixRasteropFullImage(pixd1, piximg1, PIX_SRC | PIX_DST);
pixDestroy(&piximg1);
return pixd1;
}
#endif /* _JBIG2_ENCODER_H */
\ No newline at end of file
// Copyright 2006 Google Inc. All Rights Reserved.
// Author: agl@google.com (Adam Langley)
#ifndef THIRD_PARTY_JBIG2ENC_JBIG2SEGMENTS_H__
#define THIRD_PARTY_JBIG2ENC_JBIG2SEGMENTS_H__
#include <vector>
#ifdef _MSC_VER
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
// -----------------------------------------------------------------------------
// See comments in jbig2structs.h about the bit packing in this structure.
// -----------------------------------------------------------------------------
#if defined(WIN32)
#pragma pack(1)
#endif
struct jbig2_segment {
u32 number;
#ifndef _BIG_ENDIAN
unsigned char type : 6;
unsigned char page_assoc_size : 1;
unsigned char deferred_non_retain : 1;
#else
unsigned char deferred_non_retain : 1;
unsigned char page_assoc_size : 1;
unsigned char type : 6;
#endif
#ifndef _BIG_ENDIAN
unsigned char retain_bits : 5;
unsigned char segment_count : 3;
#else
unsigned char segment_count : 3;
unsigned char retain_bits : 5;
#endif
}
#if defined(WIN32)
#pragma pack()
#else
__attribute__((packed));
#endif
;
// -----------------------------------------------------------------------------
// This structure represents a JBIG2 segment header because they have too many
// variable length fields (number of referred to segments, page length etc).
// You should access and set the members directly. Endian swapping is carried
// out internally.
// -----------------------------------------------------------------------------
struct Segment {
unsigned number; // segment number
int type; // segment type (see enum in jbig2structs.h)
int deferred_non_retain; // see JBIG2 spec
int retain_bits;
std::vector<unsigned> referred_to; // list of segment numbers referred to
unsigned page; // page number
unsigned len; // length of trailing data
Segment()
: number(0),
type(0),
deferred_non_retain(0),
retain_bits(0),
page(0),
len(0) {}
// ---------------------------------------------------------------------------
// Return the size of the segment reference for this segment. Segments can
// only refer to previous segments, so the bits needed is determined by the
// number of this segment. (7.2.5)
// ---------------------------------------------------------------------------
unsigned reference_size() const {
int refsize;
if (number <= 256) {
refsize = 1;
} else if (number <= 65536) {
refsize = 2;
} else {
refsize = 4;
}
return refsize;
}
// ---------------------------------------------------------------------------
// Return the number of bytes that this segment header will take up
// ---------------------------------------------------------------------------
unsigned size() const {
const int refsize = reference_size();
const int pagesize = page <= 255 ? 1 : 2;
return sizeof(struct jbig2_segment) + refsize * referred_to.size() +
pagesize + sizeof(u32);
}
// ---------------------------------------------------------------------------
// Serialise this segment header into the memory pointed to by buf, which
// must be at least long enough to contain it (e.g. size() bytes)
// ---------------------------------------------------------------------------
void write(u8 *buf) {
struct jbig2_segment s;
memset(&s, 0, sizeof(s));
#define F(x) s.x = x;
s.number = htonl(number);
s.type = type;
s.deferred_non_retain = deferred_non_retain;
s.retain_bits = retain_bits;
#undef F
s.segment_count = referred_to.size();
const int pagesize = page <= 255 ? 1 : 2;
const int refsize = reference_size();
if (pagesize == 2) s.page_assoc_size = 1;
unsigned j = 0;
memcpy(buf, &s, sizeof(s));
j += sizeof(s);
#define APPEND(type, val) type __i; __i = val; \
memcpy(&buf[j], &__i, sizeof(type)); \
j += sizeof(type)
for (std::vector<unsigned>::const_iterator i = referred_to.begin();
i != referred_to.end(); ++i) {
if (refsize == 4) {
APPEND(u32, htonl(*i));
} else if (refsize == 2) {
APPEND(u16, htons(*i));
} else {
APPEND(u8, *i);
}
}
if (pagesize == 2) {
APPEND(u16, htonl(page));
} else {
APPEND(u8, page);
}
APPEND(u32, htonl(len));
if (j != size()) abort();
}
};
#endif // THIRD_PARTY_JBIG2ENC_JBIG2SEGMENTS_H__
// Copyright 2006 Google Inc. All Rights Reserved.
// Author: agl@imperialviolet.org (Adam Langley)
//
// Copyright (C) 2006 Google Inc.
//
// Licensed 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.
#ifndef JBIG2ENC_JBIG2STRUCTS_H__
#define JBIG2ENC_JBIG2STRUCTS_H__
// GCC packs bit fields in a different order on big endian machines
enum {
segment_symbol_table = 0,
segment_imm_generic_region = 38,
segment_page_information = 48,
segment_imm_text_region = 6,
segment_end_of_page = 49,
segment_end_of_file = 51
};
// note that the < 1 byte fields are packed from the LSB upwards - unless
// you're bigendian, in which case they are packed MSB downwards. Joy.
#define JBIG2_FILE_MAGIC "\x97\x4a\x42\x32\x0d\x0a\x1a\x0a"
#if defined(WIN32)
#pragma pack(1)
#define PACKED
#else
#define PACKED __attribute__((packed))
#endif
struct jbig2_file_header {
u8 id[8];
#ifndef _BIG_ENDIAN
u8 organisation_type : 1;
u8 unknown_n_pages : 1;
u8 reserved : 6;
#else
u8 reserved : 6;
u8 unknown_n_pages : 1;
u8 organisation_type : 1;
#endif
u32 n_pages;
} PACKED;
struct jbig2_page_info {
u32 width;
u32 height;
u32 xres;
u32 yres;
#ifndef _BIG_ENDIAN
u8 is_lossless : 1;
u8 contains_refinements : 1;
u8 default_pixel : 1;
u8 default_operator : 2;
u8 aux_buffers : 1;
u8 operator_override : 1;
u8 reserved : 1;
#else
u8 reserved : 1;
u8 operator_override : 1;
u8 aux_buffers : 1;
u8 default_operator : 2;
u8 default_pixel : 1;
u8 contains_refinements : 1;
u8 is_lossless : 1;
#endif
u16 segment_flags;
} PACKED;
struct jbig2_generic_region {
u32 width;
u32 height;
u32 x;
u32 y;
u8 comb_operator;
#ifndef _BIG_ENDIAN
u8 mmr : 1;
u8 gbtemplate : 2;
u8 tpgdon : 1;
u8 reserved : 4;
#else
u8 reserved : 4;
u8 tpgdon : 1;
u8 gbtemplate : 2;
u8 mmr : 1;
#endif
// generic region segment here. You may not need to write all 8 bytes here.
// If the template is 1..3 only the first two are needed.
signed char a1x, a1y, a2x, a2y, a3x, a3y, a4x, a4y;
} PACKED ;
struct jbig2_symbol_dict {
#ifndef _BIG_ENDIAN
u8 sdhuff:1;
u8 sdrefagg:1;
u8 sdhuffdh:2;
u8 sdhuffdw:2;
u8 sdhuffbmsize:1;
u8 sdhuffagginst:1;
u8 bmcontext:1;
u8 bmcontextretained:1;
u8 sdtemplate:2;
u8 sdrtemplate:1;
u8 reserved:3;
#else
u8 reserved:3;
u8 sdrtemplate:1;
u8 sdtemplate:2;
u8 bmcontextretained:1;
u8 bmcontext:1;
u8 sdhuffagginst:1;
u8 sdhuffbmsize:1;
u8 sdhuffdw:2;
u8 sdhuffdh:2;
u8 sdrefagg:1;
u8 sdhuff:1;
#endif
signed char a1x, a1y, a2x, a2y, a3x, a3y, a4x, a4y;
// refinement AT flags omitted
u32 exsyms;
u32 newsyms;
} PACKED;
struct jbig2_text_region {
u32 width;
u32 height;
u32 x;
u32 y;
u8 comb_operator;
#ifndef _BIG_ENDIAN
u8 sbcombop2:1;
u8 sbdefpixel:1;
u8 sbdsoffset:5;
u8 sbrtemplate:1;
u8 sbhuff:1;
u8 sbrefine:1;
u8 logsbstrips:2;
u8 refcorner:2;
u8 transposed:1;
u8 sbcombop1:1;
#else
u8 sbcombop1:1;
u8 transposed:1;
u8 refcorner:2;
u8 logsbstrips:2;
u8 sbrefine:1;
u8 sbhuff:1;
u8 sbrtemplate:1;
u8 sbdsoffset:5;
u8 sbdefpixel:1;
u8 sbcombop2:1;
#endif
// huffman flags omitted
} PACKED;
struct jbig2_text_region_atflags {
signed char a1x, a1y, a2x, a2y;
} PACKED;
struct jbig2_text_region_syminsts {
u32 sbnuminstances;
// huffman decoding table omitted
} PACKED;
#endif // JBIG2ENC_JBIG2STRUCTS_H__
This diff is collapsed.
// Copyright 2006 Google Inc. All Rights Reserved.
// Author: agl@imperialviolet.org (Adam Langley)
//
// Copyright (C) 2006 Google Inc.
//
// Licensed 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.
#ifndef JBIG2ENC_JBIG2SYM_H__
#define JBIG2ENC_JBIG2SYM_H__
struct jbig2enc_ctx;
// -----------------------------------------------------------------------------
// Write a symbol table.
//
// symbols: A 2d array. The first dimention is of different classes of symbols.
// Then, for each class, there are all the examples of that class. The
// first member of the class is taken as the exemplar.
// symbol_list: a list of symbols to encode
// symmap: an empty map which is filled. The symbols are written to the file in
// a different order than they are given in symbols. The maps an index
// into the symbols array to a symbol number in the file
// unborder_symbols: if true, remove a border from every element of symbols
// -----------------------------------------------------------------------------
void jbig2enc_symboltable(struct jbig2enc_ctx *__restrict__ ctx,
PIXA *__restrict__ const symbols,
std::vector<unsigned> *__restrict__ symbol_list,
std::map<int, int> *symmap,
bool unborder_symbols);
// -----------------------------------------------------------------------------
// Write a text region.
//
// A text region is a list of placements of symbols. The symbols must already
// have been coded.
//
// symmap: This maps class numbers to symbol numbers. Only symbol numbers
// appear in the JBIG2 data stream
// symmap2: If not found in the first symmap, try this one
// comps: a list of connected-component numbers for this page
// ll: This is an array of the lower-left corners of the boxes for each symbol
// assignments: an array, of the same length as boxes, mapping each box to a
// symbol
// stripwidth: 1 is a safe default (one of [1, 2, 4, 8])
// symbits: number of bits needed to code the symbol number (log2(number of
// symbols) - rounded up)
// source: an array of the original images for all the connected components.
// If NULL, refinement is disabled. (page indexed)
// boxes: if source is non-NULL, this is page based list of boxes of symbols on
// the page
// baseindex: if source is non-NULL, this is the component number of the first
// component on this page
// refine_level: the number of incorrect pixels allowed before refining.
// unborder_symbols: if true, symbols have a 6px border around them
// -----------------------------------------------------------------------------
void jbig2enc_textregion(struct jbig2enc_ctx *__restrict__ ctx,
/*const*/ std::map<int, int> &symmap,
/*const*/ std::map<int, int> &symmap2,
const std::vector<int> &comps,
PTA *const ll, PIXA *const symbols,
NUMA *assignments,
int stripwidth, int symbits,
PIXA *const source, BOXA *boxes, int baseindex,
int refine_level, bool unborder_symbols);
#endif // JBIG2ENC_JBIG2SYM_H__
// JBig2File.cpp : Implementation of CJBig2File
#include "JBig2File.h"
#include "Encoder/jbig2encoder.h"
#if defined(_WIN32) || defined(_WIN64)
#include <tchar.h>
#endif
CJBig2File::CJBig2File()
{
m_bDuplicateLineRemoval = false;
m_bPDFMode = true;
m_bSymbolMode = false;
m_bRefine = false;
m_bUpscale2x = false;
m_bUpscale4x = false;
m_bSegment = false;
m_dTreshold = 0.85;
m_nBwTreshold = 188;
}
bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int nWidth, int nHeight, std::wstring sDstFileName)
{
// check for valid input parameters
///////////////////////////////////////////////////////////
if ( NULL == pBufferBGRA ) return false;
int lBufferSize = BufferSize;
unsigned char *pSourceBuffer = pBufferBGRA;
PIX *pSource = pixCreate( nWidth, nHeight, 32 );
if ( !pSource ) return false;
for ( int nY = 0; nY < nHeight; nY++ )
{
for ( int nX = 0; nX < nWidth; nX++, pSourceBuffer += 4 )
{
pixSetRGBPixel( pSource, nX, nY, pSourceBuffer[ 2 ], pSourceBuffer[ 1 ], pSourceBuffer[ 0 ] );
}
}
jbig2ctx *pContext = jbig2_init( m_dTreshold, 0.5, 0, 0, ! m_bPDFMode, m_bRefine ? 10 : -1 );
// JBig2
// TO DO: 1 JBig2
// ColorMap
PIX *pPixL = NULL;
if ( NULL == ( pPixL = pixRemoveColormap( pSource, REMOVE_CMAP_BASED_ON_SRC ) ) )
{
pixDestroy( &pSource );
jbig2_destroy( pContext );
return false;
}
pixDestroy( &pSource );
PIX *pPixT = NULL;
if ( pPixL->d > 1 )
{
PIX *pGray = NULL;
if ( pPixL->d > 8 )
{
pGray = pixConvertRGBToGrayFast( pPixL );
if ( !pGray )
{
pixDestroy( &pSource );
jbig2_destroy( pContext );
return false;
}
}
else
{
pGray = pixClone( pPixL );
}
if ( m_bUpscale2x )
{
pPixT = pixScaleGray2xLIThresh( pGray, m_nBwTreshold );
}
else if ( m_bUpscale4x )
{
pPixT = pixScaleGray4xLIThresh( pGray, m_nBwTreshold );
}
else
{
pPixT = pixThresholdToBinary( pGray, m_nBwTreshold );
}
pixDestroy( &pGray );
}
else
{
pPixT = pixClone( pPixL );
}
if ( m_sOutputTreshold.length() > 0 )
{
pixWrite( m_sOutputTreshold.c_str(), pPixT, IFF_BMP );
}
if ( m_bSegment && pPixL->d > 1 )
{
PIX *pGraphics = segment_image( pPixT, pPixL );
if ( pGraphics )
{
char *sFilename;
asprintf( &sFilename, "%s.%04d.%s", m_sBaseName.c_str(), 0, ".bmp" );
pixWrite( sFilename, pGraphics, IFF_BMP );
free( sFilename );
}
if ( !pPixT )
{
//
return true;
}
}
pixDestroy( &pPixL );
if ( !m_bSymbolMode )
{
int nLength = 0;
uint8_t *pBuffer = jbig2_encode_generic( pPixT, !m_bPDFMode, 0, 0, m_bDuplicateLineRemoval, &nLength );
bool bRes = true;
FILE *pFile = _wfopen( sDstFileName.c_str(), _T("wb") );
if ( pFile && pBuffer )
{
::fwrite( pBuffer, nLength, 1, pFile );
::fclose( pFile );
bRes = true;
}
else
bRes = false;
pixDestroy( &pPixT );
if ( pBuffer ) free( pBuffer );
jbig2_destroy( pContext );
return bRes;
}
int nNumPages = 1;
jbig2_add_page( pContext, pPixT );
pixDestroy( &pPixT );
int nLength = 0;
uint8_t *pBuffer = jbig2_pages_complete( pContext, &nLength );
if ( !pBuffer )
{
jbig2_destroy( pContext );
return false;
}
if ( m_bPDFMode )
{
std::wstring sFileName = sDstFileName;//m_sBaseName + _T(".sym");
const int nFileD = _wopen( sFileName.c_str(), O_WRONLY | O_TRUNC | O_CREAT /*| WINBINARY*/, 0600 );
if ( nFileD < 0 )
{
free( pBuffer );
jbig2_destroy( pContext );
return false;
}
write( nFileD, pBuffer, nLength );
close( nFileD );
}
free( pBuffer );
for ( int nIndex = 0; nIndex < nNumPages; ++nIndex )
{
pBuffer = jbig2_produce_page( pContext, nIndex, -1, -1, &nLength );
if ( m_bPDFMode )
{
std::wstring sFileName = m_sBaseName + _T(".0000");
const int nFileD = _wopen( sFileName.c_str(), O_WRONLY | O_TRUNC | O_CREAT /*| WINBINARY*/, 0600 );
if ( nFileD < 0 )
{
free( pBuffer );
jbig2_destroy( pContext );
return false;
}
write( nFileD, pBuffer, nLength );
close( nFileD );
}
free( pBuffer );
}
jbig2_destroy( pContext );
return true;
}
// CJBig2File
#pragma once
#include <string>
class CJBig2File
{
public:
CJBig2File();
bool MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int nWidth, int nHeight, std::wstring sDstFileName);
bool m_bDuplicateLineRemoval;
bool m_bPDFMode;
bool m_bSymbolMode;
bool m_bRefine;
bool m_bUpscale2x;
bool m_bUpscale4x;
bool m_bSegment;
double m_dTreshold;
int m_nBwTreshold;
std::wstring m_sBaseName;
std::string m_sOutputTreshold;
};
\ No newline at end of file
This diff is collapsed.
#ifndef _ADD_TYPES_H
#define _ADD_TYPES_H
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#endif /* _ADD_TYPES_H */
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ALLHEADERS_H
#define LEPTONICA_ALLHEADERS_H
#define LIBLEPT_MAJOR_VERSION 1
#define LIBLEPT_MINOR_VERSION 67
#pragma warning(disable: 4305 4244 4996 4101 4018 4309)
#include "alltypes.h"
#ifndef NO_PROTOS
#include "funcprotos.h"
#endif /* NO_PROTOS */
#endif /* LEPTONICA_ALLHEADERS_H */
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ALLTYPES_H
#define LEPTONICA_ALLTYPES_H
/* Standard */
#include <stdio.h>
#include <stdlib.h>
/* General and configuration defs */
#include "environ.h"
/* Imaging */
#include "array.h"
#include "arrayaccess.h"
#include "bbuffer.h"
#include "bmf.h"
#include "ccbord.h"
#include "dewarp.h"
#include "gplot.h"
#include "heap.h"
#include "imageio.h"
#include "jbclass.h"
#include "list.h"
#include "morph.h"
#include "pix.h"
#include "ptra.h"
#include "queue.h"
#include "regutils.h"
#include "sudoku.h"
#include "stack.h"
#include "watershed.h"
#endif /* LEPTONICA_ALLTYPES_H */
This diff is collapsed.
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ARRAY_H
#define LEPTONICA_ARRAY_H
/*
* Contains the following structs:
* struct Numa
* struct Numaa
* struct Numa2d
* struct NumaHash
* struct Sarray
*
* Contains definitions for:
* Numa interpolation flags
*/
/*------------------------------------------------------------------------*
* Array Structs *
*------------------------------------------------------------------------*/
#define NUMA_VERSION_NUMBER 1
/* Number array: an array of floats */
struct Numa
{
l_int32 nalloc; /* size of allocated number array */
l_int32 n; /* number of numbers saved */
l_int32 refcount; /* reference count (1 if no clones) */
l_float32 startx; /* x value assigned to array[0] */
l_float32 delx; /* change in x value as i --> i + 1 */
l_float32 *array; /* number array */
};
typedef struct Numa NUMA;
/* Array of number arrays */
struct Numaa
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 n; /* number of Numa saved */
struct Numa **numa; /* array of Numa */
};
typedef struct Numaa NUMAA;
/* Sparse 2-dimensional array of number arrays */
struct Numa2d
{
l_int32 nrows; /* number of rows allocated for ptr array */
l_int32 ncols; /* number of cols allocated for ptr array */
l_int32 initsize; /* initial size of each numa that is made */
struct Numa ***numa; /* 2D array of Numa */
};
typedef struct Numa2d NUMA2D;
/* A hash table of Numas */
struct NumaHash
{
l_int32 nbuckets;
l_int32 initsize; /* initial size of each numa that is made */
struct Numa **numa;
};
typedef struct NumaHash NUMAHASH;
#define SARRAY_VERSION_NUMBER 1
/* String array: an array of C strings */
struct Sarray
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 n; /* number of strings allocated */
l_int32 refcount; /* reference count (1 if no clones) */
char **array; /* string array */
};
typedef struct Sarray SARRAY;
/*------------------------------------------------------------------------*
* Array flags *
*------------------------------------------------------------------------*/
/* Flags for interpolation in Numa */
enum {
L_LINEAR_INTERP = 1, /* linear */
L_QUADRATIC_INTERP = 2 /* quadratic */
};
/* Flags for added borders in Numa */
enum {
L_EXTENDED_BORDER = 1, /* extended with same value */
L_MIRRORED_BORDER = 2 /* mirrored */
};
#endif /* LEPTONICA_ARRAY_H */
This diff is collapsed.
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ARRAY_ACCESS_H
#define LEPTONICA_ARRAY_ACCESS_H
/*
* arrayaccess.h
*
* 1, 2, 4, 8, 16 and 32 bit data access within an array of 32-bit words
*
* This is used primarily to access 1, 2, 4, 8, 16 and 32 bit pixels
* in a line of image data, represented as an array of 32-bit words.
*
* pdata: pointer to first 32-bit word in the array
* n: index of the pixel in the array
*
* Function calls for these accessors are defined in arrayaccess.c.
*
* However, for efficiency we use the inline macros for all accesses.
* Even though the 2 and 4 bit set* accessors are more complicated,
* they are about 10% faster than the function calls.
*
* The 32 bit access is just a cast and ptr arithmetic. We include
* it so that the input ptr can be void*.
*
* At the end of this file is code for invoking the function calls
* instead of inlining.
*
* The macro SET_DATA_BIT_VAL(pdata, n, val) is a bit slower than
* if (val == 0)
* CLEAR_DATA_BIT(pdata, n);
* else
* SET_DATA_BIT(pdata, n);
*/
/* Use the inline accessors (except with _MSC_VER), because they
* are faster. */
#define USE_INLINE_ACCESSORS 1
#if USE_INLINE_ACCESSORS
#ifndef _MSC_VER
/*--------------------------------------------------*
* 1 bit access *
*--------------------------------------------------*/
#define GET_DATA_BIT(pdata, n) \
((*((l_uint32 *)(pdata) + ((n) >> 5)) >> (31 - ((n) & 31))) & 1)
#define SET_DATA_BIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 5)) |= (0x80000000 >> ((n) & 31)))
#define CLEAR_DATA_BIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 5)) &= ~(0x80000000 >> ((n) & 31)))
#define SET_DATA_BIT_VAL(pdata, n, val) \
({l_uint32 *_TEMP_WORD_PTR_; \
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 5); \
*_TEMP_WORD_PTR_ &= ~(0x80000000 >> ((n) & 31)); \
*_TEMP_WORD_PTR_ |= ((val) << (31 - ((n) & 31))); \
})
/*--------------------------------------------------*
* 2 bit access *
*--------------------------------------------------*/
#define GET_DATA_DIBIT(pdata, n) \
((*((l_uint32 *)(pdata) + ((n) >> 4)) >> (2 * (15 - ((n) & 15)))) & 3)
#define SET_DATA_DIBIT(pdata, n, val) \
({l_uint32 *_TEMP_WORD_PTR_; \
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 4); \
*_TEMP_WORD_PTR_ &= ~(0xc0000000 >> (2 * ((n) & 15))); \
*_TEMP_WORD_PTR_ |= (((val) & 3) << (30 - 2 * ((n) & 15))); \
})
#define CLEAR_DATA_DIBIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 4)) &= ~(0xc0000000 >> (2 * ((n) & 15))))
/*--------------------------------------------------*
* 4 bit access *
*--------------------------------------------------*/
#define GET_DATA_QBIT(pdata, n) \
((*((l_uint32 *)(pdata) + ((n) >> 3)) >> (4 * (7 - ((n) & 7)))) & 0xf)
#define SET_DATA_QBIT(pdata, n, val) \
({l_uint32 *_TEMP_WORD_PTR_; \
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 3); \
*_TEMP_WORD_PTR_ &= ~(0xf0000000 >> (4 * ((n) & 7))); \
*_TEMP_WORD_PTR_ |= (((val) & 15) << (28 - 4 * ((n) & 7))); \
})
#define CLEAR_DATA_QBIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 3)) &= ~(0xf0000000 >> (4 * ((n) & 7))))
/*--------------------------------------------------*
* 8 bit access *
*--------------------------------------------------*/
#ifdef L_BIG_ENDIAN
#define GET_DATA_BYTE(pdata, n) \
(*((l_uint8 *)(pdata) + (n)))
#else /* L_LITTLE_ENDIAN */
#define GET_DATA_BYTE(pdata, n) \
(*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3))
#endif /* L_BIG_ENDIAN */
#ifdef L_BIG_ENDIAN
#define SET_DATA_BYTE(pdata, n, val) \
(*((l_uint8 *)(pdata) + (n)) = (val))
#else /* L_LITTLE_ENDIAN */
#define SET_DATA_BYTE(pdata, n, val) \
(*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3) = (val))
#endif /* L_BIG_ENDIAN */
/*--------------------------------------------------*
* 16 bit access *
*--------------------------------------------------*/
#ifdef L_BIG_ENDIAN
#define GET_DATA_TWO_BYTES(pdata, n) \
(*((l_uint16 *)(pdata) + (n)))
#else /* L_LITTLE_ENDIAN */
#define GET_DATA_TWO_BYTES(pdata, n) \
(*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2))
#endif /* L_BIG_ENDIAN */
#ifdef L_BIG_ENDIAN
#define SET_DATA_TWO_BYTES(pdata, n, val) \
(*((l_uint16 *)(pdata) + (n)) = (val))
#else /* L_LITTLE_ENDIAN */
#define SET_DATA_TWO_BYTES(pdata, n, val) \
(*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2) = (val))
#endif /* L_BIG_ENDIAN */
/*--------------------------------------------------*
* 32 bit access *
*--------------------------------------------------*/
#define GET_DATA_FOUR_BYTES(pdata, n) \
(*((l_uint32 *)(pdata) + (n)))
#define SET_DATA_FOUR_BYTES(pdata, n, val) \
(*((l_uint32 *)(pdata) + (n)) = (val))
#endif /* ! _MSC_VER */
#endif /* USE_INLINE_ACCESSORS */
/*--------------------------------------------------*
* Slower, using function calls for all accessors *
*--------------------------------------------------*/
#if !USE_INLINE_ACCESSORS || defined(_MSC_VER)
#define GET_DATA_BIT(pdata, n) l_getDataBit(pdata, n)
#define SET_DATA_BIT(pdata, n) l_setDataBit(pdata, n)
#define CLEAR_DATA_BIT(pdata, n) l_clearDataBit(pdata, n)
#define SET_DATA_BIT_VAL(pdata, n, val) l_setDataBitVal(pdata, n, val)
#define GET_DATA_DIBIT(pdata, n) l_getDataDibit(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val) l_setDataDibit(pdata, n, val)
#define CLEAR_DATA_DIBIT(pdata, n) l_clearDataDibit(pdata, n)
#define GET_DATA_QBIT(pdata, n) l_getDataQbit(pdata, n)
#define SET_DATA_QBIT(pdata, n, val) l_setDataQbit(pdata, n, val)
#define CLEAR_DATA_QBIT(pdata, n) l_clearDataQbit(pdata, n)
#define GET_DATA_BYTE(pdata, n) l_getDataByte(pdata, n)
#define SET_DATA_BYTE(pdata, n, val) l_setDataByte(pdata, n, val)
#define GET_DATA_TWO_BYTES(pdata, n) l_getDataTwoBytes(pdata, n)
#define SET_DATA_TWO_BYTES(pdata, n, val) l_setDataTwoBytes(pdata, n, val)
#define GET_DATA_FOUR_BYTES(pdata, n) l_getDataFourBytes(pdata, n)
#define SET_DATA_FOUR_BYTES(pdata, n, val) l_setDataFourBytes(pdata, n, val)
#endif /* !USE_INLINE_ACCESSORS || _MSC_VER */
#endif /* LEPTONICA_ARRAY_ACCESS_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_BBUFFER_H
#define LEPTONICA_BBUFFER_H
/*
* bbuffer.h
*
* Expandable byte buffer for reading data in from memory and
* writing data out to other memory.
*
* This implements a queue of bytes, so data read in is put
* on the "back" of the queue (i.e., the end of the byte array)
* and data written out is taken from the "front" of the queue
* (i.e., from an index marker "nwritten" that is initially set at
* the beginning of the array.) As usual with expandable
* arrays, we keep the size of the allocated array and the
* number of bytes that have been read into the array.
*
* For implementation details, see bbuffer.c.
*/
struct ByteBuffer
{
l_int32 nalloc; /* size of allocated byte array */
l_int32 n; /* number of bytes read into to the array */
l_int32 nwritten; /* number of bytes written from the array */
l_uint8 *array; /* byte array */
};
typedef struct ByteBuffer BBUFFER;
#endif /* LEPTONICA_BBUFFER_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#if !defined (L_BIG_ENDIAN) && !defined (L_LITTLE_ENDIAN)
# if 0
# ifdef __BIG_ENDIAN__
# define L_BIG_ENDIAN
# else
# define L_LITTLE_ENDIAN
# endif
# else
# define L_LITTLE_ENDIAN
# endif
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*====================================================================*
- Copyright (C) 2008 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_FREETYPE_H
#define LEPTONICA_FREETYPE_H
#define LEPTONICA_FT_RESOLUTION 96
typedef struct ft_library_st FT_LIBRARY;
#endif /* LEPTONICA_FREETYPE_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment