PasJPEG で非プログレ時にもハフマン最適化する & サブサンプリングOFF
こっちも聞かれた. PasJPEG の1.1をベースにした差分.
$ diff -u JPEG.PAS.old JPEG.PAS --- JPEG.PAS.old +++ JPEG.PAS @@ -54,6 +54,7 @@ FPerformance: TJPEGPerformance; FScale: TJPEGScale; FNeedRecalc: Boolean; + FSubsampling: Boolean; procedure CalcOutputDimensions; function GetBitmap: TBitmap; function GetGrayscale: Boolean; @@ -108,6 +109,8 @@ property Performance: TJPEGPerformance read FPerformance write SetPerformance; property Scale: TJPEGScale read FScale write SetScale; property Smoothing: Boolean read FSmoothing write SetSmoothing; + + property Subsampling: Boolean read FSubsampling write FSubsampling; end; TJPEGDefaults = record @@ -119,6 +122,7 @@ ProgressiveEncoding: Boolean; Scale: TJPEGScale; Smoothing: Boolean; + Subsampling: Boolean; end; var { Default settings for all new TJPEGImage instances } @@ -131,6 +135,7 @@ ProgressiveEncoding: False; Scale: jsFullSize; Smoothing: True; + Subsampling: True; ); implementation @@ -250,6 +255,7 @@ FProgressiveEncoding := JPEGDefaults.ProgressiveEncoding; FScale := JPEGDefaults.Scale; FSmoothing := JPEGDefaults.Smoothing; + FSubsampling := JPEGDefaults.Subsampling; end; destructor TJPEGImage.Destroy; @@ -448,6 +454,13 @@ jpeg_set_defaults(@jc.c); jpeg_set_quality(@jc.c, FQuality, True); + if not FSubsampling then + begin + jc.c.comp_info^[0].h_samp_factor := 1; + jc.c.comp_info^[0].v_samp_factor := 1; + end; + + if FGrayscale then begin FImage.FGrayscale := True; @@ -455,7 +468,9 @@ end; if ProgressiveEncoding then - jpeg_simple_progression(@jc.c); + jpeg_simple_progression(@jc.c) + else + jc.c.optimize_coding := True; SrcScanline := Src.ScanLine[0]; PtrInc := Integer(Src.ScanLine[1]) - Integer(SrcScanline);