<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic C# SaveJPEG example in Intel® Integrated Performance Primitives</title>
    <link>https://community.intel.com/t5/Intel-Integrated-Performance/C-SaveJPEG-example/m-p/846685#M6138</link>
    <description>&lt;P&gt;Hi all,&lt;BR /&gt;I am looking for help in resolving an issue I have when saving a Bitmap to JPEG.&lt;BR /&gt;I am using a minimally adapted code extracted from the tippi.cs example delivered with the samples in version 6.&lt;BR /&gt;&lt;BR /&gt;The problem here is that every third or fourth image turns out completely gray. I have also verified that the same behaviour is present in the unmodified version of the example. Any help or further c# example will be greatly apreciated.&lt;BR /&gt;&lt;BR /&gt;TIA,&lt;BR /&gt;&lt;BR /&gt;msjuniorc&lt;BR /&gt;&lt;BR /&gt;PS some background: I am collecting about 15fps at 1280x1024, processing the frames and then creating an MJPEG stream of cropped frames.&lt;/P&gt;
&lt;PRE&gt;[c-sharp]&lt;BR /&gt;&lt;BR /&gt;unsafe public static void SaveJPEG(string filename)
      {
              IppiSize roi;
              // JSS sampling = JSS.JS_OTHER;
              JSS sampling = JSS.JS_411;
              // JSS sampling = JSS.JS_422;
              // JSS sampling = JSS.JS_444;
              
              JCOLOR in_color = JCOLOR.JC_BGR;
              JCOLOR out_color = JCOLOR.JC_YCBCR;
              

              int JPEGSize;
              byte[] pJPEG;
              JERRCODE jerr;
              JPEGEncoder encoder = new JPEGEncoder();

              roi = new IppiSize(bmpdst.Width, bmpdst.Height);
              
              //01// Console.WriteLine("Width: {0} Height: {1}", bmpdst.Width, bmpdst.Height);
              JPEGSize = roi.width * roi.height * nChannels;
              
              //01// Console.WriteLine("JPEGSize: {0}", JPEGSize);
              // just for too small images
              if (JPEGSize &amp;lt; 1024)
              {
                  JPEGSize = 4096;
              }
              pJPEG = new byte[JPEGSize];
              switch (nChannels)
              {
                  case 1:
                      in_color = JCOLOR.JC_GRAY;
                      out_color = JCOLOR.JC_GRAY;
                      sampling = JSS.JS_444;
                      break;
                  case 3:
                      in_color = JCOLOR.JC_BGR;
                      out_color = JCOLOR.JC_YCBCR;
                      break;
                  case 4:
                      in_color = JCOLOR.JC_CMYK;
                      out_color = JCOLOR.JC_YCCK;
                      break;
                  default:
                      break;
              }
              // This saves whithout issues.&lt;BR /&gt;              // bmpdst.Save(@"R:OutputImage.bmp");
              BitmapData dstdata = getBmpData(bmpdst);
              
              encoder.SetSource((byte*)dstdata.Scan0, dstdata.Stride, roi, nChannels, in_color);
              int qualityJPEG = 50;
              encoder.SetDestination(ref pJPEG, JPEGSize, qualityJPEG, sampling, out_color, JMODE.JPEG_BASELINE, 0);
              // encoder.SetDestination(ref pJPEG, JPEGSize, qualityJPEG, sampling, out_color, JMODE.JPEG_PROGRESSIVE, 0);
              if (in_color == JCOLOR.JC_CMYK)
              {
                  BGRA_to_RGBA((byte*)dstdata.Scan0, width, height, dstdata.Stride);
              }
              int size = JPEGSize;
              jerr = encoder.WriteImageBaseline(ref size);
              // jerr = encoder.WriteImageProgressive(ref size);
              // Console.WriteLine("jerr&amp;gt; {0}", jerr);
              if (JERRCODE.JPEG_OK == jerr)
              {
                  FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
                  BinaryWriter bw = new BinaryWriter(fs);
                  bw.Write(pJPEG, 0, size);
                  bw.Close();
                  fs.Close();
                  bmpdst.UnlockBits(dstdata);
              }

      }
[/c-sharp]&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Nov 2008 00:53:33 GMT</pubDate>
    <dc:creator>msjuniorc</dc:creator>
    <dc:date>2008-11-12T00:53:33Z</dc:date>
    <item>
      <title>C# SaveJPEG example</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/C-SaveJPEG-example/m-p/846685#M6138</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;I am looking for help in resolving an issue I have when saving a Bitmap to JPEG.&lt;BR /&gt;I am using a minimally adapted code extracted from the tippi.cs example delivered with the samples in version 6.&lt;BR /&gt;&lt;BR /&gt;The problem here is that every third or fourth image turns out completely gray. I have also verified that the same behaviour is present in the unmodified version of the example. Any help or further c# example will be greatly apreciated.&lt;BR /&gt;&lt;BR /&gt;TIA,&lt;BR /&gt;&lt;BR /&gt;msjuniorc&lt;BR /&gt;&lt;BR /&gt;PS some background: I am collecting about 15fps at 1280x1024, processing the frames and then creating an MJPEG stream of cropped frames.&lt;/P&gt;
&lt;PRE&gt;[c-sharp]&lt;BR /&gt;&lt;BR /&gt;unsafe public static void SaveJPEG(string filename)
      {
              IppiSize roi;
              // JSS sampling = JSS.JS_OTHER;
              JSS sampling = JSS.JS_411;
              // JSS sampling = JSS.JS_422;
              // JSS sampling = JSS.JS_444;
              
              JCOLOR in_color = JCOLOR.JC_BGR;
              JCOLOR out_color = JCOLOR.JC_YCBCR;
              

              int JPEGSize;
              byte[] pJPEG;
              JERRCODE jerr;
              JPEGEncoder encoder = new JPEGEncoder();

              roi = new IppiSize(bmpdst.Width, bmpdst.Height);
              
              //01// Console.WriteLine("Width: {0} Height: {1}", bmpdst.Width, bmpdst.Height);
              JPEGSize = roi.width * roi.height * nChannels;
              
              //01// Console.WriteLine("JPEGSize: {0}", JPEGSize);
              // just for too small images
              if (JPEGSize &amp;lt; 1024)
              {
                  JPEGSize = 4096;
              }
              pJPEG = new byte[JPEGSize];
              switch (nChannels)
              {
                  case 1:
                      in_color = JCOLOR.JC_GRAY;
                      out_color = JCOLOR.JC_GRAY;
                      sampling = JSS.JS_444;
                      break;
                  case 3:
                      in_color = JCOLOR.JC_BGR;
                      out_color = JCOLOR.JC_YCBCR;
                      break;
                  case 4:
                      in_color = JCOLOR.JC_CMYK;
                      out_color = JCOLOR.JC_YCCK;
                      break;
                  default:
                      break;
              }
              // This saves whithout issues.&lt;BR /&gt;              // bmpdst.Save(@"R:OutputImage.bmp");
              BitmapData dstdata = getBmpData(bmpdst);
              
              encoder.SetSource((byte*)dstdata.Scan0, dstdata.Stride, roi, nChannels, in_color);
              int qualityJPEG = 50;
              encoder.SetDestination(ref pJPEG, JPEGSize, qualityJPEG, sampling, out_color, JMODE.JPEG_BASELINE, 0);
              // encoder.SetDestination(ref pJPEG, JPEGSize, qualityJPEG, sampling, out_color, JMODE.JPEG_PROGRESSIVE, 0);
              if (in_color == JCOLOR.JC_CMYK)
              {
                  BGRA_to_RGBA((byte*)dstdata.Scan0, width, height, dstdata.Stride);
              }
              int size = JPEGSize;
              jerr = encoder.WriteImageBaseline(ref size);
              // jerr = encoder.WriteImageProgressive(ref size);
              // Console.WriteLine("jerr&amp;gt; {0}", jerr);
              if (JERRCODE.JPEG_OK == jerr)
              {
                  FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
                  BinaryWriter bw = new BinaryWriter(fs);
                  bw.Write(pJPEG, 0, size);
                  bw.Close();
                  fs.Close();
                  bmpdst.UnlockBits(dstdata);
              }

      }
[/c-sharp]&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2008 00:53:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/C-SaveJPEG-example/m-p/846685#M6138</guid>
      <dc:creator>msjuniorc</dc:creator>
      <dc:date>2008-11-12T00:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: C# SaveJPEG example</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/C-SaveJPEG-example/m-p/846686#M6139</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;The solution to the problem can be found at thread:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://software.intel.com/en-us/forums/showthread.php?t=61729" target="_blank"&gt;http://software.intel.com/en-us/forums/showthread.php?t=61729&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.intel.com/../profile/121779" target="_new"&gt;lee_step&lt;/A&gt; provided a modified version of encoder.cs and solved the problem.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;msjuniorc&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2008 19:14:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/C-SaveJPEG-example/m-p/846686#M6139</guid>
      <dc:creator>msjuniorc</dc:creator>
      <dc:date>2008-11-14T19:14:44Z</dc:date>
    </item>
  </channel>
</rss>

