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
af/merge-core
Michael Weber 10 years ago
parent
commit
6882edce67
  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.IO;
using System.Threading.Tasks;
public partial class Decoder
{
@ -62,7 +63,7 @@ namespace ImageProcessorCore.Formats.Jpg
public Decoder()
{
huff = new huffman_class[maxTc + 1, maxTh + 1];
huff = new huffman_class[maxTc + 1, maxTh + 1];
quant = new Block[maxTq + 1];
tmp = new byte[2 * Block.blockSize];
comp = new Component[maxComponents];
@ -1088,26 +1089,31 @@ namespace ImageProcessorCore.Formats.Jpg
private img_rgb convert_to_rgb(int w, int h)
{
var ret = new img_rgb(w, h);
int cScale = comp[0].h / comp[1].h;
for(var y = 0; y < h; y++)
{
int po = ret.get_row_offset(y);
int yo = img3.get_row_y_offset(y);
int co = img3.get_row_c_offset(y);
for(int x = 0; x < w; x++)
Parallel.For(
0,
h,
y =>
{
byte yy = img3.pix_y[yo+x];
byte cb = img3.pix_cb[co+x/cScale];
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;
int po = ret.get_row_offset(y);
int yo = img3.get_row_y_offset(y);
int co = img3.get_row_c_offset(y);
for (int x = 0; x < w; x++)
{
byte yy = img3.pix_y[yo+x];
byte cb = img3.pix_cb[co+x/cScale];
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;
}

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

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

Loading…
Cancel
Save