JPIP Streaming Images(with download images client end)byte by byte save single same file of bitmap file folder c++

JPIP streaming images(with download).How to save the bitmap in c++ local folder.

Kakadu)JPEG 2000 Interactive Protocol is protocol using this i streaming the images from server to client(without images downloaded) its streaming concept done in kakadu.

I need to save bitmap images local folder(with same file name) bytes by bytes (concept in kakadu code) while saving time I did not get orginal images thats why i am asked.


bool kdu_client::save_cache_contents(const char *path, const char *tgt_id,const char *host, const char *res,const char *tgt, const char *sub_tgt)
{
FILE *cache_file = fopen(path,"wb");
if (cache_file == NULL)
return false;
fprintf(cache_file,"kjc/1.1\n");
fprintf(cache_file,"Host:%s\n",host);
fprintf(cache_file,"Resource:%s\n",res);
fprintf(cache_file,"Target:%s\n",(tgt==NULL)?"":tgt);
fprintf(cache_file,"Sub-target:%s\n",(sub_tgt==NULL)?"":sub_tgt);
fprintf(cache_file,"Target-id:%s\n",tgt_id);

bool is_complete;
int cls, length, id_bits, cs_bits, i;
kdu_long cs_id, bin_id;
kdu_byte *hd, header[24];

int cache_store_len = 300;
kdu_byte *cache_store_buf = new kdu_byte[cache_store_len];

try {
cs_id = get_next_codestream(-1);
while (cs_id >= 0)
{
for (cls=0; cls < KDU_NUM_DATABIN_CLASSES; cls++)
{
bin_id = get_next_lru_databin(cls,cs_id,-1,false);
while (bin_id >= 0)
{
length = get_databin_length(cls,cs_id,bin_id,&is_complete);
if ((length > 0) || is_complete)
{ // Save data-bin
if (length > cache_store_len)
{
if (cache_store_buf != NULL) delete[] cache_store_buf;
cache_store_len += length+256;
cache_store_buf = new kdu_byte[cache_store_len];

}
length = get_databin_prefix(cls,cs_id,bin_id,cache_store_buf,length);
hd = header;
if (is_complete)
*(hd++) = (kdu_byte)(2*cls+1);
else
*(hd++) = (kdu_byte)(2*cls);
for (cs_bits=0; (cs_id>>cs_bits) > 0; cs_bits+=8);
for (id_bits=0; (bin_id>>id_bits) > 0; id_bits+=8);
*(hd++) = (kdu_byte)((cs_bits<<1) | (id_bits>>3));
for (i=cs_bits-8; i >= 0; i-=8)
*(hd++) = (kdu_byte)(cs_id>>i);
for (i=id_bits-8; i >= 0; i-=8)
*(hd++) = (kdu_byte)(bin_id>>i);
for (i=24; i >= 0; i-=8)
*(hd++) = (kdu_byte)(length>>i);
fwrite(header,1,(size_t)(hd-header),cache_file);
fwrite(cache_store_buf,1,(size_t) length,cache_file);
//////////////////////////////////////
int imageWidth = 0;
int imageHeight = 0;
unsigned long imageSize = 0;
unsigned long padding = 0;
FILE *localfile=fopen("C:\\LogEntries\\bluesquareOneTwoNew.bmp","w");


if (localfile==NULL)
{
fputs ("File error",stderr); exit (1);
} // obtain file size:

long lSize;
// obtain file size:
fseek (localfile , 0 , SEEK_END);
lSize = ftell (localfile);


if ( lSize == 0 )
{
padding = ( 4 - ( ( 1024 * 3 ) % 4 ) ) % 4;
SaveBitmapToFileOLD( (BYTE*) cache_store_buf,1024,768,24,padding,_T("C:\\LogEntries\\bluesquareOneTwoNew.bmp"));

}
else
{
int cache_store_lenvalues=300;
// Load the bitmap file, amd put its data part into the BYTE array
BYTE* bytes = LoadBMP( &imageWidth, &imageHeight, &imageSize, _T("C:\\LogEntries\\bluesquareOneTwoNew.bmp") );
std::reverse( bytes, bytes + imageSize );
// Determine amount of padding required, if any, and create a new BYTE array from this
std::unique_ptr<BYTE[]> newbuf2 = CreateNewBuffer( padding, bytes, imageWidth, imageHeight );
memcpy(&newbuf2,cache_store_buf,300);
// Use the new array data to create the new bitmap file
SaveBitmapToFile( (BYTE*) &newbuf2[ 0 ],imageWidth,imageHeight,24,padding,_T("C:\\LogEntries\\bluesquareOneTwoNew.bmp") );
}
}
bin_id = get_next_lru_databin(cls,cs_id,bin_id,false);
}
}
cs_id = get_next_codestream(cs_id);
}
}
catch (...)
{ // Something went wrong; delete the cache file
fclose(cache_file);
remove(path);
delete[] cache_store_buf;
return false;
}
fclose(cache_file);
////////////////////
// SaveBitmapToFile( (BYTE*) cache_store_buf,128,128,24,0,_T("C:\\LogEntries\\save_cache_contents.bmp"));
/////////////////
delete[] cache_store_buf;
return true;
}
Last edited on
Topic archived. No new replies allowed.