Task 104: .CPC File Format
Task 104: .CPC File Format
File Format Specifications for .CPC
The .CPC file format refers to Cartesian Perceptual Compression, a proprietary lossy compression format for bi-level (black and white) raster images, primarily used for document imaging. It was developed by Cartesian Products, Inc. in the 1990s and is designed for high compression of scanned documents, achieving ratios 5-20 times better than standard TIFF Group 4 compression. The format is proprietary, with no public detailed specifications available for the internal structure, encoding, or decoding algorithms. The only known technical detail is the file signature (magic bytes). Information is based on archival descriptions from sources like the Library of Congress and Wikipedia, as the company's website appears inaccessible or outdated as of the current date.
List of Properties Intrinsic to the File Format
- File Extension: .cpc (or sometimes .cpi)
- Magic Bytes (File Signature): 0x43 0x50 0x43 0xB2 (ASCII: "CPC" followed by the byte 0xB2)
- Image Type: Bi-level (1-bit per pixel, black and white) raster image
- Compression Method: Proprietary perceptual compression based on symbol matching and pattern analysis, non-degrading (repeated compression/decompression reaches a steady state without further loss)
- Intended Use: High-compression storage and transmission of document images, such as legal documents, design plans, and geographical plots
- Developer: Cartesian Products, Inc.
- Patent: US Patent #5,303,313 (issued 1994)
- Sustainability: Proprietary, requires specific tools for viewing/decompression (e.g., CPC View plug-in or CPC Tool); compression tools are licensed
- Dependencies: No external dependencies noted, but viewing requires plug-ins or APIs from the developer
- Transparency: Low, as algorithms are not public; depends on proprietary tools for access
- Adoption: Limited to specialized document imaging systems; not widely supported in modern software
Two Direct Download Links for .CPC Files
No public direct download links for .CPC files were found. The format is proprietary, and samples are typically demonstrated through HTML pages requiring a browser plug-in (e.g., CPC Lite). Cartesian Products' demonstration library and sample pages do not provide direct .CPC file downloads; they use embedded viewers. If you have access to the CPC Tool software, you can generate .CPC files from TIFF inputs, but no free public samples are available.
Ghost Blog Embedded HTML JavaScript for Drag and Drop .CPC File Dump
Since the format is proprietary and full decoding is not possible without licensed tools, the script below allows drag-and-drop of a .CPC file, reads it as binary, checks the magic bytes, and dumps the known properties (file name, size, magic bytes, and a note on proprietary nature). It does not decode the image data.
Drag and Drop .CPC File
Python Class for .CPC File Handling
Since the format is proprietary, full decoding and writing is not possible without licensed APIs. The class below opens the file, checks the magic bytes, reads basic info, "decodes" by noting the proprietary nature, and "writes" a stub file with the magic bytes (not a valid image). It prints the known properties.
import os
class CPCFile:
MAGIC = b'\x43\x50\x43\xB2'
def __init__(self, filepath):
self.filepath = filepath
self.size = 0
self.is_valid = False
self.properties = {}
def open(self):
if not os.path.exists(self.filepath):
raise FileNotFoundError(f"File {self.filepath} not found")
self.size = os.path.getsize(self.filepath)
def decode_read(self):
with open(self.filepath, 'rb') as f:
magic = f.read(4)
self.is_valid = magic == self.MAGIC
self.properties = {
'File Name': os.path.basename(self.filepath),
'File Size': f"{self.size} bytes",
'Magic Bytes': ' '.join(f"{b:02x}" for b in self.MAGIC),
'Valid Magic': self.is_valid,
'Extension': '.cpc',
'Type': 'Bi-level raster image (proprietary compression)',
'Intended Use': 'Document imaging',
'Developer': 'Cartesian Products, Inc.',
'Patent': 'US #5,303,313',
'Note': 'Full decoding not possible; proprietary format.'
}
def print_properties(self):
for key, value in self.properties.items():
print(f"{key}: {value}")
def write(self, new_filepath):
with open(new_filepath, 'wb') as f:
f.write(self.MAGIC)
# Stub: Write dummy data (not a valid CPC file)
f.write(b'\x00' * 100)
print(f"Stub .CPC file written to {new_filepath} (not fully valid due to proprietary format)")
# Example usage
if __name__ == "__main__":
cpc = CPCFile('example.cpc')
cpc.open()
cpc.decode_read()
cpc.print_properties()
cpc.write('new_example.cpc')
Java Class for .CPC File Handling
Similar limitations apply. The class checks magic, reads basic info, and writes a stub.
import java.io.*;
public class CPCFile {
private static final byte[] MAGIC = {(byte)0x43, (byte)0x50, (byte)0x43, (byte)0xB2};
private String filepath;
private long size;
private boolean isValid;
private java.util.Map<String, String> properties = new java.util.HashMap<>();
public CPCFile(String filepath) {
this.filepath = filepath;
}
public void open() throws IOException {
File file = new File(filepath);
if (!file.exists()) {
throw new FileNotFoundException("File " + filepath + " not found");
}
this.size = file.length();
}
public void decodeRead() throws IOException {
try (FileInputStream fis = new FileInputStream(filepath)) {
byte[] magic = new byte[4];
fis.read(magic);
isValid = java.util.Arrays.equals(magic, MAGIC);
}
properties.put("File Name", new File(filepath).getName());
properties.put("File Size", size + " bytes");
properties.put("Magic Bytes", String.format("%02X %02X %02X %02X", MAGIC[0], MAGIC[1], MAGIC[2], MAGIC[3]));
properties.put("Valid Magic", String.valueOf(isValid));
properties.put("Extension", ".cpc");
properties.put("Type", "Bi-level raster image (proprietary compression)");
properties.put("Intended Use", "Document imaging");
properties.put("Developer", "Cartesian Products, Inc.");
properties.put("Patent", "US #5,303,313");
properties.put("Note", "Full decoding not possible; proprietary format.");
}
public void printProperties() {
properties.forEach((key, value) -> System.out.println(key + ": " + value));
}
public void write(String newFilepath) throws IOException {
try (FileOutputStream fos = new FileOutputStream(newFilepath)) {
fos.write(MAGIC);
// Stub: Write dummy data
byte[] dummy = new byte[100];
fos.write(dummy);
}
System.out.println("Stub .CPC file written to " + newFilepath + " (not fully valid due to proprietary format)");
}
public static void main(String[] args) throws IOException {
CPCFile cpc = new CPCFile("example.cpc");
cpc.open();
cpc.decodeRead();
cpc.printProperties();
cpc.write("new_example.cpc");
}
}
JavaScript Class for .CPC File Handling
(Note: JavaScript in browser context; for node, add fs module. This is browser-friendly with FileReader.)
class CPCFile {
static MAGIC = new Uint8Array([0x43, 0x50, 0x43, 0xB2]);
constructor(file) {
this.file = file;
this.properties = {};
}
async decodeRead() {
const arrayBuffer = await this.file.arrayBuffer();
const uint8Array = new Uint8Array(arrayBuffer);
const magic = uint8Array.slice(0, 4);
const isValid = magic.every((v, i) => v === CPCFile.MAGIC[i]);
this.properties = {
'File Name': this.file.name,
'File Size': `${this.file.size} bytes`,
'Magic Bytes': Array.from(CPCFile.MAGIC).map(b => b.toString(16).padStart(2, '0')).join(' '),
'Valid Magic': isValid,
'Extension': '.cpc',
'Type': 'Bi-level raster image (proprietary compression)',
'Intended Use': 'Document imaging',
'Developer': 'Cartesian Products, Inc.',
'Patent': 'US #5,303,313',
'Note': 'Full decoding not possible; proprietary format.'
};
}
printProperties() {
Object.entries(this.properties).forEach(([key, value]) => console.log(`${key}: ${value}`));
}
write() {
// Browser JS can't write files directly; simulate blob download
const blob = new Blob([CPCFile.MAGIC, new Uint8Array(100)], { type: 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'new_example.cpc';
a.click();
URL.revokeObjectURL(url);
console.log('Stub .CPC file downloaded (not fully valid due to proprietary format)');
}
}
// Example usage (assume file from input or drop)
// const inputFile = new File([...], 'example.cpc');
// const cpc = new CPCFile(inputFile);
// await cpc.decodeRead();
// cpc.printProperties();
// cpc.write();
C Class for .CPC File Handling
(Note: This is a struct-based "class" in C. Compiles with stdio.h, stdlib.h.)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef struct {
const unsigned char magic[4];
char* filepath;
long size;
bool is_valid;
} CPCFile;
const unsigned char CPC_MAGIC[4] = {0x43, 0x50, 0x43, 0xB2};
CPCFile* cpcfile_new(const char* filepath) {
CPCFile* cpc = malloc(sizeof(CPCFile));
memcpy((void*)cpc->magic, CPC_MAGIC, 4);
cpc->filepath = strdup(filepath);
cpc->size = 0;
cpc->is_valid = false;
return cpc;
}
void cpcfile_open(CPCFile* cpc) {
FILE* f = fopen(cpc->filepath, "rb");
if (!f) {
perror("File not found");
exit(1);
}
fseek(f, 0, SEEK_END);
cpc->size = ftell(f);
fclose(f);
}
void cpcfile_decode_read(CPCFile* cpc) {
FILE* f = fopen(cpc->filepath, "rb");
unsigned char magic_read[4];
fread(magic_read, 1, 4, f);
cpc->is_valid = memcmp(magic_read, cpc->magic, 4) == 0;
fclose(f);
}
void cpcfile_print_properties(const CPCFile* cpc) {
printf("File Name: %s\n", strrchr(cpc->filepath, '/') ? strrchr(cpc->filepath, '/') + 1 : cpc->filepath);
printf("File Size: %ld bytes\n", cpc->size);
printf("Magic Bytes: %02X %02X %02X %02X\n", cpc->magic[0], cpc->magic[1], cpc->magic[2], cpc->magic[3]);
printf("Valid Magic: %s\n", cpc->is_valid ? "Yes" : "No");
printf("Extension: .cpc\n");
printf("Type: Bi-level raster image (proprietary compression)\n");
printf("Intended Use: Document imaging\n");
printf("Developer: Cartesian Products, Inc.\n");
printf("Patent: US #5,303,313\n");
printf("Note: Full decoding not possible; proprietary format.\n");
}
void cpcfile_write(const CPCFile* cpc, const char* new_filepath) {
FILE* f = fopen(new_filepath, "wb");
fwrite(cpc->magic, 1, 4, f);
// Stub: Write dummy data
unsigned char dummy[100] = {0};
fwrite(dummy, 1, 100, f);
fclose(f);
printf("Stub .CPC file written to %s (not fully valid due to proprietary format)\n", new_filepath);
}
void cpcfile_free(CPCFile* cpc) {
free(cpc->filepath);
free(cpc);
}
int main() {
CPCFile* cpc = cpcfile_new("example.cpc");
cpcfile_open(cpc);
cpcfile_decode_read(cpc);
cpcfile_print_properties(cpc);
cpcfile_write(cpc, "new_example.cpc");
cpcfile_free(cpc);
return 0;
}