dige wrote:JPG offers the possibility for remarks etc.. to store ' invisibly ' text
into image header. The text can be read, for instance with IrfanView.
Dige, being as dumb as politicians, I pb4'ed your code and it works a treat. But I don't know enough to play with it and turn it into a reader as well.
P.s. What is the character limit for info shoved into a jpeg this way?
WriteWord(#FID, Len(comment) + 2 ) ; Len Text incl. size
WriteString(#FID, comment )
And that means, you can write 2^16 - 2 Chars as jpeg comment.
Thanks Dige, that's very useful. Now I need to make a reader routine as well. This is for all the family pictures that we have. Very useful to make a database for them.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
You made a big !!!! mistake in your Code and it seems nobody except me has noticed it....
If you allocate memory and store that address,
You CANNOT add 2 to that pointer and free that new address later.
I've seen that mistake for years in your code, and could'nt resist anymore to tell you.
Do invite a new variable for the calculating with same value, but leave *mem unchanged!
PNG is even better: you can define your own PNG format as it is a REAL container that divides all data into chunks. So you can add a comment-chunk if it isn't present in current PNG format specification http://www.libpng.org/pub/png/spec/1.1/ ... tents.html
ok I have to go...you can look for TGA on wikipedia on yourself
;Hello Dige
;
;Try out this codeexample but close all running Tasks
;Then you'll find out what I'm talking about
;It seems that your behavior of changing the
;Memory vector leaves 'holes' in memory list or it
;even destroys the memory list (in Windows)
;After finishing the task
;Windows seems to be
;so clever to cleanup Memory
;So the problem is'nt noticeable if you use it
;just once in a task, what you have done propably.
Declare memory(change.l)
Debug "First with correct freevec"
Debug "This is very fast done without any problems"
;
memory(#False)
;
Debug "Now we do the same with vector change"
Debug "And the problem occurs !"
;
memory(#True)
;
Debug "Done"
Procedure memory(change.l)
; this procedure demonstrates that
; changing *mem Vector generates Errors
size = 100000 ;
sizesp = size
maxsize=size+2000
For n= 1 To 100000
*mem = GlobalAlloc_ (#GMEM_FIXED|#GMEM_ZEROINIT, size)
If *mem
If change.l=#True
*mem+900 ; changing the mem vector
EndIf
GlobalFree_( *mem )
Else
Debug "No Memory available"
EndIf
size +4 :If size>maxsize :size=sizesp :EndIf
Next n
EndProcedure
;With this little modifications Your code works OK ;
Procedure.b WriteTxtToJpgFile (File.s, comment.s)
Protected size.l, success.b, *mem.l
success = #False
#FID = 0
size.l = FileSize(File)
If size
*mem = GlobalAlloc_ (#GMEM_FIXED | #GMEM_ZEROINIT, size)
If *mem And ReadFile(#FID, File)
ReadData(#FID, *mem, size)
CloseFile(#FID)
If PeekW(*mem) & $FFFF = $D8FF And CreateFile(#FID, File)
WriteLong(#FID, $FEFFD8FF ) ; JPG & Comment Marker (Little Endian Format)
WriteByte(#FID, $00)
WriteByte(#FID, Len(comment) + 3 ) ; Comment lenght incl. size
WriteString(#FID, comment )
WriteByte(#FID, $00 )
*mem1 = *mem
If PeekW (*mem + 2 ) & $FFFF = $FEFF ; Found comment
size - PeekB(*mem + 5) - 4
*mem1 + PeekB(*mem + 5) + 4 ;so *mem is not changed
Else ; No comment found
size - 2
*mem1 + 2 ;so *Mem is not changed
EndIf
WriteData(#FID, *mem1, size)
CloseFile(#FID)
success = #True
EndIf
EndIf
GlobalFree_(*mem)
EndIf
ProcedureReturn success
EndProcedure