
       bantha:  ok, I got my id3-jpg-metadata code working.  but since I'm trying to be the first to implement this standard, there's really nothing for me to test it against
       bantha:  anyone want to take a look at some code and see if I'm understanding it right?
<<< Cookie Monster has left >>>
<<< 09:01:19 PM >>>
      bullitB:  try making an independent implementation
      bullitB:  like...a little app that spits the jpeg out
<<< AgentO has left >>>
<<< 09:09:44 PM >>>
       bantha:  the test is of my understanding of the docs, not of my ability to make apps that implement that understanding
      bullitB:  alright, sure, post it
       bantha:  ok, we have this:
       bantha:  V2.3-2.4 encoding
       bantha:      Text encoding      $xx
       bantha:      MIME type          <text string> $00
       bantha:      Picture type       $xx
       bantha:      Description        <text string according to encoding> $00 (00)
       bantha:      Picture data       <binary data>
       bantha:  and my header looks like this:
       bantha:  00 69 6D 61 67 65 2F 6A 70 65 67 00 03 00 
       bantha:  (.image/jpeg...)
       bantha:  then the jpeg file appended to the end
       bantha:  is that what the spec says?
      bullitB:  the text encoding is 00?
       bantha:  yeah
       bantha:  according to one of the methods in that framework you linked to earlier
       bantha:  the id3 framework
      bullitB:  quick thought, compare this to the id3 tags of an mp3
       bantha:  an mp3 with an image in it?
       bantha:  where do I find that?
      bullitB:  yeah
      bullitB:  uhm, make one in itunes
       bantha:  this is going to sound stupid, but, how?
      bullitB:  cmd+g to show artwork
      bullitB:  then drop an image in there
      bullitB:  it adds it to the tags of the file
      bullitB:  then open that file in hexedit
      bullitB:  
      bullitB:  00 41 50 49 43 00 06 7E A7 00 00 00 69 6D 61 67
      bullitB:  65 2F 70 6E 67 00 00 00 89 50 4E 47 
      bullitB:  uh, roughly
      bullitB:  APIC
      bullitB:  then ~.
      bullitB:  then image/png
      bullitB:  then .PNG
      bullitB:  then the data or something
      bullitB:  i dunno
       bantha:  so I see 2 0's after APIC
       bantha:  is that because I need two, or because the metadata type has a trailing \0?
      bullitB:  maybe one to terminate the "APIC" string and one to say that the text encoding is 0
       bantha:  oh, yours doesn't have 2
      bullitB:  hrm, or that
       bantha:  mine does
       bantha:  so basically this experiment hasn't told me if I'm misunderstanding the spec
      bullitB:  uh, make yours look like what itunes does
       bantha:  but how do I know where the type ends and the content begins (the metadata content)?
       bantha:  ok, for this: Text encoding      $xx iTunes has 00 00 09 12 00 00 00
       bantha:  how does that work out?
       bantha:  I mean, how does "$xx" turn into "00 00 09 12 00 00 00"?
      bullitB:  hrm. fair question
Stux *-Jedi (:  extened hex
Stux *-Jedi (:  looks like you've dropped a byte
       bantha:  you mean in my code or in my copying to here?
Stux *-Jedi (:  sorry, forget me
Stux *-Jedi (:  i though we were talking about %xx in print or something :)
Stux *-Jedi (:  printf
Stux *-Jedi (:  are you using 2v3-2v4 encoding in iTunes/
Stux *-Jedi (:  ?
       bantha:  how do I check?
       bantha:  I just converted the song to 2.3 and it modified the file, but that tag still looks the same
Stux *-Jedi (:  Description
Stux *-Jedi (:  <text string according to encoding> $00 (00)
Stux *-Jedi (:  http://www.id3.org/id3v2.3.0.html#sec4.15
       bantha:  I thought that was the "image/jpeg" part
Stux *-Jedi (:  i dunno :)
       bantha:  and here's another question.  I assume the $00 means to indicate the end of your string with a \0 (makes sense).  what does the (00) mean?
Stux *-Jedi (:  Frame ID
Stux *-Jedi (:  Ê
Stux *-Jedi (:  $xx xx xx xx (four characters)
Stux *-Jedi (:  
Stux *-Jedi (:  Size
Stux *-Jedi (:  $xx xx xx xx
Stux *-Jedi (:  
Stux *-Jedi (:  Flags
Stux *-Jedi (:  $xx xx
Stux *-Jedi (:  i'm assuming it means "optional 0x00"
Stux *-Jedi (:  some specs in the past use a double null to end strings...
Stux *-Jedi (:  The frame ID is followed by a size descriptor, making a total header size of ten bytes in every frame. The size is calculated as frame size excluding frame header (frame size - 10).
Stux *-Jedi (:  so
Stux *-Jedi (:  APIC$xxxxxxxxxxxx
Stux *-Jedi (:  ie 10 bytes
       bantha:  but the MIME type is an arbitrary length string, and "image/jpeg" already pushes the total to 14 bytes
       bantha:  also Description, which I didn't include
Stux *-Jedi (:  There may only be one text information frame of its kind in an tag. If the textstring is followed by a termination ($00 (00)) all the following information should be ignored and not be displayed. All text frame identifiers begin with "T". Only text frame identifiers begin with "T", with the exception of the "TXXX" frame. All the text information frames have the following format:
Stux *-Jedi (:  
Stux *-Jedi (:  
Stux *-Jedi (:  
Stux *-Jedi (:  <Header for 'Text information frame', ID: "T000" - "TZZZ", excluding "TXXX" described in 4.2.2.>
Stux *-Jedi (:  
Stux *-Jedi (:  Text encoding
Stux *-Jedi (:  $xx
Stux *-Jedi (:  
Stux *-Jedi (:  Information
Stux *-Jedi (:  <text string according to encoding>
Stux *-Jedi (:  is "00 00 09 12" the size?
Stux *-Jedi (:  912 bytes?
Stux *-Jedi (:  then you have 00 00 for flags
Stux *-Jedi (:  and 00 for picture type
Stux *-Jedi (:  or text encoding, sorry
       bantha:  Finder says 2308 bytes for this image
       bantha:  does itunes recompress the image?
Stux *-Jedi (:  the image might have preview data
Stux *-Jedi (:  in the resource fork... drop it on resourcerer
       bantha:  I don't really know how to use resourcer, but it seems to just have a data fork
Stux *-Jedi (:  Terminated strings are terminated with $00 if encoded with ISO-8859-1 and $00 00 if encoded as unicode
Stux *-Jedi (:  bingo
Stux *-Jedi (:  the double null is used for unicode
       bantha:  I just got the jpeg from Safari with drag and drop to the desktop, if that sheds any light
       bantha:  thanks
Stux *-Jedi (:  yeah. its got a preview in it
Stux *-Jedi (:  if you were to drop it on resourcer you'd see a 'pnot' resource
Stux *-Jedi (:  has it got a custonm icon too?
       bantha:  I did drop it on resourcer, and all it lists in it's table is "1 jpeg resource"
       bantha:  no custom icon
       bantha:  just Preview's
Stux *-Jedi (:  I just dropped a safari saved jpg on resourcer
Stux *-Jedi (:  icl4, icl8, ICN#, icns, ics#, ics4, ics8, jpeg, PICT, pnot
       bantha:  saved with Save As or with DnD?
Stux *-Jedi (:  save as
       bantha:  yeah I think that's different.  try one with just dragging the image to the desktop
Stux *-Jedi (:  yeah, I just have a 'jpeg' resource, which I think is the data fork
       bantha:  so the question is does JPEG have any metadata that iTunes would discard
       bantha:  and would it be 60% of the file
Stux *-Jedi (:  dunno :)
Stux *-Jedi (:  maybe a JFIF is more than a JPEG ;)
       bantha:  also, I don't see the image size anywhere in the APIC doc
       bantha:  just in that FrameID thing.  what is that anyway?
Stux *-Jedi (:  the frame id is the frame header
Stux *-Jedi (:  ie frametype + framesize + frameflags
       bantha:  oh so the image would have to fit inside that
Stux *-Jedi (:  APIC + framesize-10+frameflags
Stux *-Jedi (:  yah, i assume
Stux *-Jedi (:  its a bit like a qt atom
Stux *-Jedi (:  i would not bother with the frame header junk
Stux *-Jedi (:  the frameid should be replaced by qt atom stuff... yes?
       bantha:  yeah I agree
Stux *-Jedi (:  unless the flags are necessary
Stux *-Jedi (:  http://www.id3.org/id3v2.3.0.html#sec3.3
Stux *-Jedi (:  yeah, i think its safe to discard the flags in your case, and just assume 0x0000 for the flags :)
       bantha:  ok, so the 00 00 09 12 00 00 00 69 6D 61 67 65 2F 6A 70 65
       bantha:  67 00 00 00 I see in my mp3 file is ten bytes of frame header and then just what I'd expect
       bantha:  uh, 41 50 49 43 00 00 09 12 00 00 00 69 6D 61 67 65
       bantha:  2F 6A 70 65 67 00 00 00 
       bantha:  so we have APIC, 0912, 0 0, then 0, then image/jpeg, then 0 0 0
Stux *-Jedi (:  looks good
       bantha:  I just have a 0 3 0 because my image type is Cover(front) and Apple's is Other
       bantha:  ok, cools
       bantha:  *cool
Stux *-Jedi (:  so, basically, 912 is the size of everything, less the header
       bantha:  now I just have to figure out how to make an image well that accepts only file paths, and then stores the file path instead of the NSImage
Stux *-Jedi (:  this is beginning to sound very cool :)
       bantha:  yeah, I'm still not clear on that
       bantha:  maybe 912 is 2308 in hex
Stux *-Jedi (:  well, try copying the "image data" out and sticking it in a raw file... i bet it doesn't work
Stux *-Jedi (:  oh yeah!
Stux *-Jedi (:  hah
Stux *-Jedi (:  2322
Stux *-Jedi (:  which is 2308 + crap
       bantha:  14, which was exactly my header size...
Stux *-Jedi (:  so, its done, congrats :)
       bantha:  nice.  just one more lingering question
Stux *-Jedi (:  you should probably store the filename as the description?
       bantha:  a double 0 at the end of the encoding string would screw up my parser
Stux *-Jedi (:  only if unicode is used
       bantha:  so...when would the image encoding ever be recorded as unicode?
       bantha:  is that actually done?  just for shits and giggles?
Stux *-Jedi (:  its the text encoding
       bantha:  what filename would be stored in the description?
Stux *-Jedi (:  it *can* be done, so you have to prepare for it
Stux *-Jedi (:  well, where did the jpg come from?
Stux *-Jedi (:  I just thought it might be nice to actually be able to extract the exact jpg which was embedded in the fist place
       bantha:  ok I was thinking of scanning to the next non-0.  do any image formats start with 0?
Stux *-Jedi (:  i'd guess a lot ;)
       bantha:  then how will I know if the last zero is there because I'm off count or because it's part of the image file?
Stux *-Jedi (:  basically you do
Stux *-Jedi (:  you scan for 00
Stux *-Jedi (:  then you go
       bantha:  oh I see, the file name not the file path
Stux *-Jedi (:  yes
Stux *-Jedi (:  you scan for 00, then if you get 00
Stux *-Jedi (:  if( unicode && next == 00 )
Stux *-Jedi (:  etc
       bantha:  how do I know if (unicode)?
Stux *-Jedi (:  if text_encoding = unicode
Stux *-Jedi (:  first byte in the frame
       bantha:  ah
Stux *-Jedi (:   Frames that allow different types of text encoding have a text encoding description byte directly after the frame size. If ISO-8859-1 is used this byte should be $00, if Unicode is used it should be $01. Strings dependent on encoding is represented as <text string according to encoding>, or <full text string according to encoding> if newlines are allowed. Any empty Unicode strings which are NULL-terminated may have the Unicode BOM followed by a Unicode NULL ($FF FE 00 00 or $FE FF 00 00).
Stux *-Jedi (:  so, if its 0x01, then its unicode
Stux *-Jedi (:  should be clear now
       bantha:  yes, thanks
Stux *-Jedi (:  now, you'd use unicode, if the description... was in ... say.. japanese...
Stux *-Jedi (:  my spec skills are strong ;)
Stux *-Jedi (:  actually, you know... you don' need to use an id3 lib for this... it seems fairly simple :)
Stux *-Jedi (:  you should just whip up a quick BSD lib for it
       bantha:  I just whipped up a quick obj-c method for myself actually
       bantha:  the libs I found were way overkill
       bantha:  so I copy/pasted the good parts from the obj-c one
Stux *-Jedi (:  that's my point, but if you're making up a spec you might as well stick the implemnentation up on teh web
Stux *-Jedi (:  looks like on a few hundred lines at the max
       bantha:  you think a separate lib would be worthwhile for such a small block of code?
       bantha:  almost seems like it'd be easier to put the code right on the website, not as a download
Stux *-Jedi (:  at least a separate .c file
       bantha:  yeah ok.  both maybe, html and .c versions
Stux *-Jedi (:  basically a simple .h and .c would be good I think
Stux *-Jedi (:  I can imagine the h would be just a couple of lines
Stux *-Jedi (:  and some documentation
Stux *-Jedi (:  hehe, the license boiler plate will be more than the code ;)