Browse Source

Slight performance increase in jpeg decode.

Convert from YCbCr to RGB in parallel.


Former-commit-id: b1ce38a5ca17f356844eb27ca783c5cce738c873
Former-commit-id: 60350e08a03692dcf18397f4eb1b604bfc91462b
Former-commit-id: f735411e49f3e0fd79b5a7cc7fdad0337e3905f3
pull/1/head
Michael Weber 10 years ago
parent
commit
00c4ed9db4
  1. 42
      src/ImageProcessorCore/Formats/Jpg/Decoder.cs
  2. 2
      src/ImageProcessorCore/Formats/Jpg/JpegEncoder.cs

42
src/ImageProcessorCore/Formats/Jpg/Decoder.cs

@ -2,6 +2,7 @@ namespace ImageProcessorCore.Formats.Jpg
{ {
using System; using System;
using System.IO; using System.IO;
using System.Threading.Tasks;
public partial class Decoder public partial class Decoder
{ {
@ -62,7 +63,7 @@ namespace ImageProcessorCore.Formats.Jpg
public Decoder() public Decoder()
{ {
huff = new huffman_class[maxTc + 1, maxTh + 1]; huff = new huffman_class[maxTc + 1, maxTh + 1];
quant = new Block[maxTq + 1]; quant = new Block[maxTq + 1];
tmp = new byte[2 * Block.blockSize]; tmp = new byte[2 * Block.blockSize];
comp = new Component[maxComponents]; comp = new Component[maxComponents];
@ -1088,26 +1089,31 @@ namespace ImageProcessorCore.Formats.Jpg
private img_rgb convert_to_rgb(int w, int h) private img_rgb convert_to_rgb(int w, int h)
{ {
var ret = new img_rgb(w, h); var ret = new img_rgb(w, h);
int cScale = comp[0].h / comp[1].h; int cScale = comp[0].h / comp[1].h;
for(var y = 0; y < h; y++)
{ Parallel.For(
int po = ret.get_row_offset(y); 0,
int yo = img3.get_row_y_offset(y); h,
int co = img3.get_row_c_offset(y); y =>
for(int x = 0; x < w; x++)
{ {
byte yy = img3.pix_y[yo+x]; int po = ret.get_row_offset(y);
byte cb = img3.pix_cb[co+x/cScale]; int yo = img3.get_row_y_offset(y);
byte cr = img3.pix_cr[co+x/cScale]; int co = img3.get_row_c_offset(y);
byte r, g, b; for (int x = 0; x < w; x++)
Colors.YCbCrToRGB(yy, cb, cr, out r, out g, out b); {
ret.pixels[po+3*x+0] = r; byte yy = img3.pix_y[yo+x];
ret.pixels[po+3*x+1] = g; byte cb = img3.pix_cb[co+x/cScale];
ret.pixels[po+3*x+2] = b; byte cr = img3.pix_cr[co+x/cScale];
byte r, g, b;
Colors.YCbCrToRGB(yy, cb, cr, out r, out g, out b);
ret.pixels[po+3*x+0] = r;
ret.pixels[po+3*x+1] = g;
ret.pixels[po+3*x+2] = b;
}
} }
} );
return ret; return ret;
} }

2
src/ImageProcessorCore/Formats/Jpg/JpegEncoder.cs

@ -18,7 +18,7 @@ namespace ImageProcessorCore.Formats
/// <summary> /// <summary>
/// The quality. /// The quality.
/// </summary> /// </summary>
private int quality = 100; private int quality = 75;
/// <summary> /// <summary>
/// Gets or sets the quality, that will be used to encode the image. Quality /// Gets or sets the quality, that will be used to encode the image. Quality

Loading…
Cancel
Save