[l2h] JPEG patch

Shigeharu TAKENO shige at iee.niit.ac.jp
Sat Nov 15 11:39:37 CET 2003


shige 11/15 2003
----------------

I made a patch to latex2html-2002-2-1, for using JPEG image. To 
use it, you need to make JPEG icons, for example (on csh):

  cd latex2html-2002-2-1
  patch -p1 < (this patch)
  cd icons
    foreach i ( *.gif )
      giftopnm $i | pnmtojpeg > `basename $i .gif`.jpg
    end
  cd ..
  ./configure --prefix=(any setting)
  make ; make check ; make install

After that, you can use the feature by the option 

  -image_type jpg  (not "-image_type jpeg")

----- from here -----
diff -ru latex2html-2002-2-1-org/config/config.pl latex2html-2002-2-1/config/config.pl
--- latex2html-2002-2-1-org/config/config.pl	Fri Nov 29 20:49:01 2002
+++ latex2html-2002-2-1/config/config.pl	Fri Nov 14 11:22:30 2003
@@ -786,11 +786,12 @@
 $opt{'IMAGES'} = &is_true(&get_name('IMAGES'));
 $opt{'GIF'} = &is_true(&get_name('GIF'));
 $opt{'PNG'} = &is_true(&get_name('PNG'));
+$opt{'JPG'} = &is_true(&get_name('JPG'));
 
-unless($opt{'GIF'} || $opt{'PNG'}) {
+unless($opt{'GIF'} || $opt{'PNG'} || $opt{'JPG'}) {
   $opt{'IMAGES'} = 0;
   $opt{'have_pstoimg'} = 0;
-  logit("Warning: Both GIF and PNG support disabled. LaTeX2HTML won't generate any images.\n");
+  logit("Warning: GIF, PNG, and JPEG support disabled. LaTeX2HTML won't generate any images.\n");
 }
 
 # --------------------------------------------------------------------------
@@ -1470,20 +1471,6 @@
   }
 }
 
-$newcfg{'have_images'} = $opt{'IMAGES'};
-if($opt{'have_pstoimg'}) {
-  if($opt{'GIF'} || $opt{'PNG'}) {
-    $newcfg{'have_pstoimg'} = 1;
-  }
-  else {
-    $newcfg{'have_images'} = $newcfg{'have_pstoimg'} = 0;
-    &warn_no_images();
-  }
-}
-else {
-  $newcfg{'have_images'} = $newcfg{'have_pstoimg'} = 0;
-}
-
 # --------------------------------------------------------------------------
 # PPMTOJPEG
 # --------------------------------------------------------------------------
@@ -1496,10 +1483,24 @@
   if($ppmtojpeg) {
     $newcfg{'PPMTOJPEG'} = $ppmtojpeg;
   } else {
+     $opt{'JPG'} = 0;
      &warn_no_image_type('jpg');
   }
 }
 
+$newcfg{'have_images'} = $opt{'IMAGES'};
+if($opt{'have_pstoimg'}) {
+  if($opt{'GIF'} || $opt{'PNG'} || $opt{'JPG'}) {
+    $newcfg{'have_pstoimg'} = 1;
+  }
+  else {
+    $newcfg{'have_images'} = $newcfg{'have_pstoimg'} = 0;
+    &warn_no_images();
+  }
+}
+else {
+  $newcfg{'have_images'} = $newcfg{'have_pstoimg'} = 0;
+}
 
 $newcfg{'IMAGE_TYPES'} = '';
 
@@ -1510,6 +1511,9 @@
   }
   if($opt{'GIF'}) {
     push(@imgtypes,'gif');
+  }
+  if($opt{'JPG'}) {
+    push(@imgtypes,'jpg');
   }
   $newcfg{'IMAGE_TYPES'} = join(' ', at imgtypes);
 }
diff -ru latex2html-2002-2-1-org/configure latex2html-2002-2-1/configure
--- latex2html-2002-2-1-org/configure	Fri Nov 29 20:49:01 2002
+++ latex2html-2002-2-1/configure	Fri Nov 14 10:57:57 2003
@@ -52,6 +52,8 @@
 ac_help="$ac_help
   --enable-png            add support of PNG images"
 ac_help="$ac_help
+  --enable-jpg            add support of JPEG images"
+ac_help="$ac_help
   --enable-pipes          use pipes to connect portable bitmap programs"
 ac_help="$ac_help
   --enable-paths          store absolute pathnames of external programs"
@@ -783,6 +785,14 @@
   enable_png=''
 fi
 
+# Check whether --enable-jpg or --disable-jpg was given.
+if test "${enable_jpg+set}" = set; then
+  enableval="$enable_jpg"
+  :
+else
+  enable_jpg=''
+fi
+
 # Check whether --enable-pipes or --disable-pipes was given.
 if test "${enable_pipes+set}" = set; then
   enableval="$enable_pipes"
@@ -1177,6 +1187,7 @@
   REVERSE=$enable_reverse \
   GIF=$enable_gif \
   PNG=$enable_png \
+  JPG=$enable_jpg \
   PIPES=$enable_pipes \
   ABSPATHS=$enable_paths \
   PREFIX=$prefix \
diff -ru latex2html-2002-2-1-org/l2hconf.pin latex2html-2002-2-1/l2hconf.pin
--- latex2html-2002-2-1-org/l2hconf.pin	Fri Nov 29 20:49:12 2002
+++ latex2html-2002-2-1/l2hconf.pin	Fri Nov 14 10:59:15 2003
@@ -1165,7 +1165,7 @@
 		, "change_end_right", "change_end", "change_delete_right"
 		, "change_delete", "contents", "index");
 
-    if ($icon =~ /(gif|png)$/) {
+    if ($icon =~ /(gif|png|jpg)$/) {
 	$used_icons{$icon} = 1;
 	if ($iconmark =~ /change_(begin|end|delete)_right/) { $align = ' ' };
 	local($pre);
diff -ru latex2html-2002-2-1-org/latex2html.pin latex2html-2002-2-1/latex2html.pin
--- latex2html-2002-2-1-org/latex2html.pin	Fri Nov 29 20:49:17 2002
+++ latex2html-2002-2-1/latex2html.pin	Fri Nov 14 11:42:51 2003
@@ -4003,7 +4003,7 @@
 	if ($ALTERNATIVE_ICONS) {
 	    L2hos->Copy("$ALTERNATIVE_ICONS$dd$_", ".$dd$_")
 		if (-e "$ALTERNATIVE_ICONS$dd$_" && !-e $_);
-	} elsif (/(gif|png)$/) {
+	} elsif (/(gif|png|jpg)$/) {
 	    L2hos->Copy("$LATEX2HTMLDIR${dd}icons$dd$_", ".$dd$_")
 		if (-e "$LATEX2HTMLDIR${dd}icons$dd$_" && !-e $_);
 	}
@@ -9157,7 +9157,7 @@
 			    if (-d "$this_dir$dd$_") {
 				&new_dir("$this_dir$dd$_",'d');
 			    } elsif ($this_dir eq '.') {
-				L2hos->Unlink($_) if (/\.(pl|gif|png)$/) 
+				L2hos->Unlink($_) if (/\.(pl|gif|png|jpg)$/) 
 			    } else {
 				L2hos->Unlink("$this_dir$dd$_"); 
 			    };
@@ -10036,6 +10036,36 @@
                 $width = $height = 0;
             }
 	}
+	elsif ($IMAGE_TYPE =~ /jpg/) {
+	    read(IMAGE,$buffer,6);
+	    my ($marker,$chunklen,$count);
+	    ($magic,$marker,$chunklen) = unpack('a2a2n',$buffer);
+	    unless($magic eq "\xff\xd8") {
+		$width = $height = 0;
+	    }
+	    $count=1;
+	    while($marker !~ "\xff[\xc0-\xc3\xc5-\xcb\xcd-\xcf]"){
+		seek(IMAGE,$chunklen-2,1);
+		read(IMAGE,$buffer,4);
+		($marker,$chunklen)=unpack('a2n',$buffer);
+		print "In jpg loop ($marker)\n" if ($DEBUG);
+		$count ++;
+		if( ++$count > 20 || $marker eq "\xff\xd9" ){
+		    $count = -1;
+		    last;
+		}
+	    }
+	    if ($count < 0){
+		$width = $height = 0;
+	    }
+	    else {
+		read(IMAGE,$buffer,5);
+		($dummy,$height,$width) = unpack('ann',$buffer);
+		unless($width*$height>0){
+		    $width = $height = 0;
+		}
+	    }
+	}
 	close(IMAGE);
 
 	# adjust for non-trivial $scale factor.
@@ -17184,9 +17214,9 @@
 =item B<-image_type> I<type>
 
 Specify the type of bitmap images to be generated. Depending on your setup,
-B<LaTeX2HTML> can generate B<gif> or B<png> images. Note: Gif images have
-certain legal restrictions, as their generation involves an algorithm
-patented by Unisys.
+B<LaTeX2HTML> can generate B<gif>, B<png>, or B<jpg> images. 
+Note: Gif images have certain legal restrictions, as their generation 
+involves an algorithm patented by Unisys.
 
 =item B<->(B<no>)B<images>
 
diff -ru latex2html-2002-2-1-org/prefs.pm latex2html-2002-2-1/prefs.pm
--- latex2html-2002-2-1-org/prefs.pm	Fri Nov 29 20:49:17 2002
+++ latex2html-2002-2-1/prefs.pm	Fri Nov 14 11:10:32 2003
@@ -246,6 +246,10 @@
 # to disable PNG support even if possible.
 $prefs{'PNG'} = 1;
 
+# Try to implement JPG image support. Set to 0 if you want
+# to disable JPG support even if possible.
+$prefs{'JPG'} = 1;
+
 # Ghostscript
 # this is one of the crucial points. Use the most recent version of gs
 # available. Versions known to work well are 3.33 and 4.03
diff -ru latex2html-2002-2-1-org/pstoimg.pin latex2html-2002-2-1/pstoimg.pin
--- latex2html-2002-2-1-org/pstoimg.pin	Fri Nov 29 20:49:17 2002
+++ latex2html-2002-2-1/pstoimg.pin	Fri Nov 14 11:15:38 2003
@@ -331,6 +331,11 @@
 my $PNMTOPNG = '@PNMTOPNG@';
 #fi
 #-
+#if @IMAGE_TYPES@ =~ /jpg/i
+# JPEG support
+my $PPMTOJPEG = '@PPMTOJPEG@';
+#fi
+#-
 # Temporary diskspace
 my $def_tmp = '@TMPSPACE@'; # Space for temporary files
 
@@ -390,7 +395,7 @@
 
 my %opt = ();
 unless(&GetOptions(\%opt, qw(-help -version -debug -discard -antialias -aaliastext
-  -multipage -type=s -gif -png -out=s -depth=i -color=i -flip=s -density=i
+  -multipage -type=s -gif -png -jpg -out=s -depth=i -color=i -flip=s -density=i
   -scale=f -geometry=s -margins=s -crop=s -transparent -interlaced 
   -rightjustify=i -center=i -topjustify=s -shoreup=s -tmp=s -white -quiet))) {
   print_usage("$prompt: Error: Invalid option(s) specified.");
@@ -822,6 +827,17 @@
 EOF
     }
   }
+if($opt{jpg}) {
+  print qq{$prompt: Warning: The -jpg switch is deprecated. Use "-type jpg" instead.\n};
+  if(grep($_ eq 'jpg', at IMAGE_TYPES)) {
+    $opt{type} = 'jpg';
+    }
+  else {
+    die <<"EOF";
+$prompt: Error: This version of pstoimg does not support "jpg" format.
+EOF
+    }
+  }
 
 =item B<-white>
 
@@ -1498,6 +1514,17 @@
     }
   }
 #fi - png
+#if @IMAGE_TYPES@ =~ /jpg/i
+  if($opt{type} eq 'jpg') {
+    $pnmtoimg = $PPMTOJPEG;
+    if($INTERLACE) {
+      $pnmtoimg .= ' --progressive';
+    }
+    if($TRANSPARENT) {
+      # ppmtojpeg have no option for transparency
+    }
+  }
+#fi - jpg
   unless($pnmtoimg) {
     print qq($prompt: Error: unknown image type "$opt{type}".\n);
     exit 2;
----- to here -----

+========================================================+
 Shigeharu TAKENO     NIigata Institute of Technology
                       kashiwazaki,Niigata 945-1195 JAPAN
 shige at iee.niit.ac.jp   TEL(&FAX): +81-257-22-8161
+========================================================+


More information about the latex2html mailing list