Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi all,

In my application, i want to read the characters from the available jpeg image file in a buffer and then upload the contents of the buffer.

I am opening the file using the ifilemgr and then reading the file using ifile interface. but the problem is if the image file is 4000 bytes, the ifile_read returns success for all the 4000 times as i m reading 1 byte at a time. Once i read the byte i copy it to a buffer. Once the file read is complete, the ifile returns success for all but may be ifile doesnot recognise few characters and so copies those characters as blank in the buffer. the size of characters read in the buffer is less the 4000 bytes.

what cud be the reason for this. are there any characters in jpeg files that are cannot be read with ifile interface. if yes then what acan be done to read such characters.

if(pApp->pImagefile )
{
r = 1;
STRCPY(pApp->data_buffer ,"");
while(r != 0)
{
r = IFILE_Read (pApp->pImagefile , l_szBuf, 1);
if(!STRCMP(l_szBuf,""))
DBGPRINTF("Character not recognised");
STRCAT(pApp->data_buffer , l_szBuf);
}

Pls help in solving this problem...
Thanks in Advance.
PriBhi.

I think the issue is probably coming from using STRCAT() to copy data. If the data read from the file is the null character, then STRCAT() will not add anything to your data buffer.
I do have to ask why you are using such a complicated way of reading the data, though. IFILE_Read() calls can be quite slow on certain handsets and I don't see any reason in this code fragment why you need to read it byte by byte. I also am not sure why you are reading into a temporary string buffer and then writing that into your destination buffer. I think it would work a lot better if you just read the entire file in one call directly into your data buffer, like this:
if (pApp->pImagefile)
{
r = IFILE_Read(pApp->pImagefile, pApp->data_buffer, size);
Where size is the size of the file, assuming pApp->data_buffer is large enough to hold that.

I think the issue is probably coming from using STRCAT() to copy data. If the data read from the file is the null character, then STRCAT() will not add anything to your data buffer.
I do have to ask why you are using such a complicated way of reading the data, though. IFILE_Read() calls can be quite slow on certain handsets and I don't see any reason in this code fragment why you need to read it byte by byte. I also am not sure why you are reading into a temporary string buffer and then writing that into your destination buffer. I think it would work a lot better if you just read the entire file in one call directly into your data buffer, like this:
if (pApp->pImagefile)
{
r = IFILE_Read(pApp->pImagefile, pApp->data_buffer, size);
Where size is the size of the file, assuming pApp->data_buffer is large enough to hold that.

pribhi wrote:In my application, i want to read the characters from the available jpeg image file in a buffer and then upload the contents of the buffer.
JPEG images are not strings of characters, they are a sequences of bytes. I think you really need to read up on how C strings work...
In any case, the biggest problem here is that you are using STRCPY, STRCMP, and STRCAT on arbitrary byte sequences, in particular single bytes (bad in itself -- seriously, find a C tutorial that covers strings) that are quite likely to occasionally have the value zero. Reading one byte at a time isn't a great idea either, but that will only hurt performance. And is there any reason why you can't just read directly into your destination array?
If you really must read one byte at a time and then copy that, I suggest copying it with MEMCPY or even with a simple assignment.

pribhi wrote:In my application, i want to read the characters from the available jpeg image file in a buffer and then upload the contents of the buffer.
JPEG images are not strings of characters, they are a sequences of bytes. I think you really need to read up on how C strings work...
In any case, the biggest problem here is that you are using STRCPY, STRCMP, and STRCAT on arbitrary byte sequences, in particular single bytes (bad in itself -- seriously, find a C tutorial that covers strings) that are quite likely to occasionally have the value zero. Reading one byte at a time isn't a great idea either, but that will only hurt performance. And is there any reason why you can't just read directly into your destination array?
If you really must read one byte at a time and then copy that, I suggest copying it with MEMCPY or even with a simple assignment.