<commit_before>/* Smoke codec
 * Copyright (C) <2004> <NAME> <<EMAIL>> 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/* this is a hack hack hack to get around jpeglib header bugs... */
#ifdef HAVE_STDLIB_H
# undef HAVE_STDLIB_H
#endif
#include <jpeglib.h>

#include "smokecodec.h"
#include "smokeformat.h"

#include <gst/gstinfo.h>

struct _SmokeCodecInfo
{
  unsigned int width;
  unsigned int height;
  unsigned int fps_num;
  unsigned int fps_denom;

  unsigned int minquality;
  unsigned int maxquality;
  unsigned int bitrate;
  unsigned int threshold;

  unsigned int refdec;

  unsigned char **line[3];
  unsigned char *compbuf[3];

  struct jpeg_error_mgr jerr;

  struct jpeg_compress_struct cinfo;
  struct jpeg_destination_mgr jdest;

  struct jpeg_decompress_struct dinfo;
  struct jpeg_source_mgr jsrc;

  int need_keyframe;
  unsigned char *reference;
};

static void
smokecodec_init_destination (j_compress_ptr cinfo)
{
}

static boolean
smokecodec_flush_destination (j_compress_ptr cinfo)
{
  return 1;
}

static void
smokecodec_term_destination (j_compress_ptr cinfo)
{
}

static void
smokecodec_init_source (j_decompress_ptr cinfo)
{
}

static boolean
smokecodec_fill_input_buffer (j_decompress_ptr cinfo)
{
  return 1;
}

static void
smokecodec_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
}

static boolean
smokecodec_resync_to_restart (j_decompress_ptr cinfo, int desired)
{
  return 1;
}

static void
smokecodec_term_source (j_decompress_ptr cinfo)
{
}


int
smokecodec_encode_new (SmokeCodecInfo ** info,
    const unsigned int width,
    const unsigned int height,
    const unsigned int fps_num, const unsigned int fps_denom)
{
  SmokeCodecInfo *newinfo;
  int i, j;
  unsigned char *base[3];

  if (!info)
    return SMOKECODEC_NULLPTR;
  if ((width & 0xf) || (height & 0xf))
    return SMOKECODEC_WRONGSIZE;

  newinfo = malloc (sizeof (SmokeCodecInfo));
  if (!newinfo) {
    return SMOKECODEC_NOMEM;
  }
  newinfo->width = width;
  newinfo->height = height;
  newinfo->fps_num = fps_num;
  newinfo->fps_denom = fps_denom;

  /* setup jpeglib */
  memset (&newinfo->cinfo, 0, sizeof (newinfo->cinfo));
  memset (&newinfo->jerr, 0, sizeof (newinfo->jerr));
  newinfo->cinfo.err = jpeg_std_error (&newinfo->jerr);
  jpeg_create_compress (&newinfo->cinfo);
  newinfo->cinfo.input_components = 3;
  jpeg_set_defaults (&newinfo->cinfo);

  newinfo->cinfo.dct_method = JDCT_FASTEST;

  newinfo->cinfo.raw_data_in = TRUE;
  newinfo->cinfo.in_color_space = JCS_YCbCr;
  newinfo->cinfo.comp_info[0].h_samp_factor = 2;<commit_msg>smokeenc: don't crash when compiled against libjpeg7<commit_after>/* Smoke codec
 * Copyright (C) <2004> <NAME> <<EMAIL>> 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/* this is a hack hack hack to get around jpeglib header bugs... */
#ifdef HAVE_STDLIB_H
# undef HAVE_STDLIB_H
#endif
#include <jpeglib.h>

#include "smokecodec.h"
#include "smokeformat.h"

#include <gst/gstinfo.h>

struct _SmokeCodecInfo
{
  unsigned int width;
  unsigned int height;
  unsigned int fps_num;
  unsigned int fps_denom;

  unsigned int minquality;
  unsigned int maxquality;
  unsigned int bitrate;
  unsigned int threshold;

  unsigned int refdec;

  unsigned char **line[3];
  unsigned char *compbuf[3];

  struct jpeg_error_mgr jerr;

  struct jpeg_compress_struct cinfo;
  struct jpeg_destination_mgr jdest;

  struct jpeg_decompress_struct dinfo;
  struct jpeg_source_mgr jsrc;

  int need_keyframe;
  unsigned char *reference;
};

static void
smokecodec_init_destination (j_compress_ptr cinfo)
{
}

static boolean
smokecodec_flush_destination (j_compress_ptr cinfo)
{
  return 1;
}

static void
smokecodec_term_destination (j_compress_ptr cinfo)
{
}

static void
smokecodec_init_source (j_decompress_ptr cinfo)
{
}

static boolean
smokecodec_fill_input_buffer (j_decompress_ptr cinfo)
{
  return 1;
}

static void
smokecodec_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
}

static boolean
smokecodec_resync_to_restart (j_decompress_ptr cinfo, int desired)
{
  return 1;
}

static void
smokecodec_term_source (j_decompress_ptr cinfo)
{
}


int
smokecodec_encode_new (SmokeCodecInfo ** info,
    const unsigned int width,
    const unsigned int height,
    const unsigned int fps_num, const unsigned int fps_denom)
{
  SmokeCodecInfo *newinfo;
  int i, j;
  unsigned char *base[3];

  if (!info)
    return SMOKECODEC_NULLPTR;
  if ((width & 0xf) || (height & 0xf))
    return SMOKECODEC_WRONGSIZE;

  newinfo = malloc (sizeof (SmokeCodecInfo));
  if (!newinfo) {
    return SMOKECODEC_NOMEM;
  }
  newinfo->width = width;
  newinfo->height = height;
  newinfo->fps_num = fps_num;
  newinfo->fps_denom = fps_denom;

  /* setup jpeglib */
  memset (&newinfo->cinfo, 0, sizeof (newinfo->cinfo));
  memset (&newinfo->jerr, 0, sizeof (newinfo->jerr));
  newinfo->cinfo.err = jpeg_std_error (&newinfo->jerr);
  jpeg_create_compress (&newinfo->cinfo);
  newinfo->cinfo.input_components = 3;
  jpeg_set_defaults (&newinfo->cinfo);

  newinfo->cinfo.dct_method = JDCT_FASTEST;

  /* prepare for raw input */
#if JPEG_LIB_VERSION >= 70
  newinfo->cinfo.do_fancy_downsampling = FALSE;
#endif

  newinfo->cinfo.raw_data_in = TRUE;
  newinfo->cinfo.in_color_space = JCS_YCbCr;
  newinfo->cinfo.comp_info[0].h_samp_factor = 2;
{'fraction_non_alphanumeric': 0.0909221902017291, 'fraction_numerical': 0.009654178674351584, 'mean_word_length': 4.465354330708662, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1419355', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2397, 'n_words': 717}