J2K-Codec ™

News
Overview
Download
Order
F.A.Q.
More info
Support
Links

Welcome
QuickStart

ActiveX Control

C++ Wrapper
J2K_Image
open
easyDecode
selectTiles
getMetaData
decode
close
J2K_Frames
open
getFrames
getFrame
operators
close

API Reference
General
getVersion
getLastError
getErrorStr
getLastErrorStr
Unlock
Open / Close
Open
Close
Info
GetInfo
GetInfoEx
GetResolutions
GetResDimensions
GetMetaData
Decoding
EasyDecode
SelectTiles
Decode
Cancel
Debug
StartLogging
StopLogging


Custom Data Sources


Implementing custom data source is easy. All you need to do is to create 2 functions: read() and close().
One to read the data and another - to close the data source.
And if your data source allows random access you may also want to add a seek() function to decrease memory requirements.
 int  read (void *ptr, int size, void *data_source);
 int  seek (void *data_source, int offset);
 void close(void *data_source);
These functions are similar to the stdio.h functions fread(), fseek() and fclose() except that all of them receive not a FILE pointer, but a pointer to whatever internal data these functions might need to identify the data source.

1. read()
The read() function must read size bytes of data from the data source into the memory buffer, pointed by ptr and return the actual amount of bytes read. In case of error it must return -1.
2. seek()
The seek() function is optional. If your data source is not seekable, just return -1. Otherwise, this function must seek the reading position at offset bytes, starting from the beginning of the data. If seeking was successful the function must return 0.
3. close()
The close() function is used to close the data source after image processing is finished. If your data source does not require closing, you may simply create an empty placeholder for this function.

All these functions must be declared with __stdcall keyword if you are using C or C++.


To tell J2K-Codec about your functions, you need to fill the following structure and pass it to the J2K_Image::open() or J2K_OpenCustom() function.
typedef struct
{
   int  (__stdcall *seek)  (void *data_source, int offset);
   int  (__stdcall *read)  (void *ptr, int size, void *data_source);
   void (__stdcall *close) (void *data_source);
}
J2K_Callbacks;
Before using J2K_Image::open() or J2K_OpenCustom() you need to open your data source and pass the pointer to it.

See "C++\e_CustomSource" or "Delphi\PasDemo2" samples for more information.

Example

J2K_Callbacks cbs;

// Prepare callbacks structure
cbs.seek = MySeek;
cbs.read = MyRead;
cbs.close = MyClose;

// Open data source
data_source = OpenMyDataSource();   if(!data_source) return -1;

// Open J2K file from your data source
j2k_image = J2K_OpenCustom((void*)data_source, &cbs;);   if(!j2k_image) return -1;

2004-2006 © Alex Saveliev