Skip to content

Commit

Permalink
Add BGR_888 and YUYV support
Browse files Browse the repository at this point in the history
Adds the possibility to have a check button on the raw open GUI.

Signed-off-by: Marcel Tunnissen <marcelteun@gmail.com>
  • Loading branch information
Marcel Tunnissen authored and marcelteun committed Mar 28, 2011
1 parent 5b758ad commit 887e3e3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 19 deletions.
18 changes: 16 additions & 2 deletions file-raw-load-gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
struct load_dlg_data {
GtkWidget* id;
GtkWidget* size[SIZE_DIM];
GtkWidget* checked;
struct raw_data* img_data;
gint result_ok;
};
Expand Down Expand Up @@ -66,6 +67,10 @@ static void load_on_ok(GtkWidget *widget, gpointer data)
dlg_data->img_data->size[i] = s_ui;
}
}
if (dlg_data->checked) {
dlg_data->img_data->checked = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(dlg_data->checked));
}

gtk_widget_destroy(GTK_WIDGET(dlg_data->id));
dlg_data->result_ok = TRUE;
Expand Down Expand Up @@ -96,7 +101,7 @@ void show_message(gchar *msg)
fprintf (stderr, "Import-raw: %s\n", msg);
}

gint load_dialog(struct raw_data* img_data)
gint load_dialog(struct raw_data* img_data, gchar* check_button_label)
{
int i;
GtkWidget* dlg;
Expand Down Expand Up @@ -144,7 +149,7 @@ gint load_dialog(struct raw_data* img_data)
gtk_widget_show(wgt);

/* Width and Height */
wgt = gtk_table_new(2, SIZE_DIM, FALSE);
wgt = gtk_table_new(3, SIZE_DIM, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(wgt), 3);
gtk_table_set_col_spacings(GTK_TABLE(wgt), 3);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), wgt, TRUE, TRUE, 0);
Expand All @@ -167,6 +172,15 @@ gint load_dialog(struct raw_data* img_data)
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show(dlg_data.size[i]);
}
if (check_button_label) {
dlg_data.checked = gtk_check_button_new_with_mnemonic(
check_button_label);
gtk_table_attach(GTK_TABLE(wgt), dlg_data.checked, 0, 1, i, i+1,
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show(dlg_data.checked);
} else {
dlg_data.checked = NULL;
}

gtk_widget_show(dlg);
gtk_main();
Expand Down
2 changes: 1 addition & 1 deletion file-raw-load-gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#include "file-raw-load.h"

void show_message(gchar *msg);
gint load_dialog(struct raw_data* img_data);
gint load_dialog(struct raw_data* img_data, gchar* check_button_label);

#endif
54 changes: 51 additions & 3 deletions file-raw-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ static guchar read_yuv_pixel(FILE* file, enum pix_fmt fmt, guchar yuv[3]) {
odd_pixel = !odd_pixel;
return OK;
break;
case YUYV_422:
if (odd_pixel) {
yuv[0] = yuv_sav[0];
yuv[1] = yuv_sav[1];
yuv[2] = yuv_sav[2];
} else {
if ((yuv[0] = fgetc(file)) == EOF) return ERROR;
if ((yuv[1] = fgetc(file)) == EOF) return ERROR;
if ((yuv_sav[0] = fgetc(file)) == EOF) return ERROR;
if ((yuv[2] = fgetc(file)) == EOF) return ERROR;
yuv_sav[1] = yuv[1];
yuv_sav[2] = yuv[2];
}
odd_pixel = !odd_pixel;
return OK;
break;
default:
return ERROR;
break;
Expand Down Expand Up @@ -152,6 +168,8 @@ static guchar read_rgb_pixel(FILE* file, enum pix_fmt fmt, guchar rgb[3]) {
return OK;
break;
case UYVY_422:
/* intentional fall through */
case YUYV_422:
{
guchar yuv[3];
if (read_yuv_pixel(file, fmt, yuv) != ERROR) {
Expand All @@ -162,6 +180,12 @@ static guchar read_rgb_pixel(FILE* file, enum pix_fmt fmt, guchar rgb[3]) {
}
}
break;
case BGR_888:
if ((rgb[2] = fgetc(file)) == EOF) return ERROR;
if ((rgb[1] = fgetc(file)) == EOF) return ERROR;
if ((rgb[0] = fgetc(file)) == EOF) return ERROR;
return OK;
break;
default:
return ERROR;
break;
Expand Down Expand Up @@ -251,8 +275,9 @@ void run(
struct raw_data* img_data
) {
static GimpParam values[2];
GimpRunMode run_mode;
gint32 img = ERROR;
GimpRunMode run_mode;
gchar* check_button_label;
gint32 img = ERROR;

if (!img_data) goto call_error;

Expand All @@ -270,8 +295,19 @@ void run(
case GIMP_RUN_INTERACTIVE:
/* Possibly retrieve data */
gimp_get_data(plugin_name, img_data);
switch(fmt) {
case RGB_888:
check_button_label = "BGR";
break;
case UYVY_422:
check_button_label = "YUYV";
break;
default:
check_button_label = NULL;
break;
}

if (!load_dialog(img_data))
if (!load_dialog(img_data, check_button_label))
goto exec_error;
break;

Expand All @@ -285,6 +321,18 @@ void run(
break;
}

if (img_data->checked) {
switch(fmt) {
case RGB_888:
fmt = BGR_888;
break;
case UYVY_422:
fmt = YUYV_422;
break;
default:
break;
}
}
img = open_raw(param[1].data.d_string, fmt, img_data, plugin_name);

if (img == ERROR)
Expand Down
5 changes: 4 additions & 1 deletion file-raw-load.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ enum pix_fmt {
RGBA_5551,
RGBA_4444,
RGB_888,
BGR_888,
RGBX_8888,
RGBA_8888,
UYVY_422,
YUYV_422,
nr_of_pix_fmts,
};

#define SIZE_DIM 2
struct raw_data {
guint size[SIZE_DIM];
guint size[SIZE_DIM];
gboolean checked;
};

void run(
Expand Down
24 changes: 12 additions & 12 deletions file-uyvy.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (C) 2011 Marcel Tunnissen
*
* This file implements a GIMP plugin for load raw images in a UYVY 422 format
* This file implements a GIMP plugin for load raw images in a YUV 422 format
*
* License: GNU Public License version 2
*
Expand All @@ -26,8 +26,8 @@

#include "file-raw-load.h"

static void query_uyuv(void);
static void run_uyuv(
static void query_yuv(void);
static void run_yuv(
const gchar* name,
gint nparams,
const GimpParam* param,
Expand All @@ -39,8 +39,8 @@ GimpPlugInInfo PLUG_IN_INFO =
{
.init_proc = NULL,
.quit_proc = NULL,
.query_proc = query_uyuv,
.run_proc = run_uyuv
.query_proc = query_yuv,
.run_proc = run_yuv
};

MAIN()
Expand All @@ -60,31 +60,31 @@ static GimpParamDef results[] =
static int nr_results = G_N_ELEMENTS(results);

#define PLUGIN_VERSION "2011-03-26"
#define PLUGIN_NAME "raw_file_uyv422_load"
#define PLUGIN_NAME "raw_file_yuv_422_load"

static struct raw_data Image_input_data = {
.size = {640, 480},
};

static void query_uyuv(void)
static void query_yuv(void)
{
gimp_install_procedure(
PLUGIN_NAME,
"raw file UYVY-422 load",
"Load raw file in UYVY 422 format",
"raw file YUV-422 load",
"Load raw file in YUV 422 format",
"Marcel Tunnissen",
"Copyright Marcel Tunnissen",
PLUGIN_VERSION,
"<Load>/UYUV422",
"<Load>/YUV422",
NULL,
GIMP_PLUGIN,
nr_args, nr_results, args, results
);

gimp_register_load_handler(PLUGIN_NAME, "UYVY-422, uyvy", "");
gimp_register_load_handler(PLUGIN_NAME, "UYVY, YUYV, YUV-422, 422", "");
}

static void run_uyuv(
static void run_yuv(
const gchar* name,
gint nparams,
const GimpParam* param,
Expand Down

0 comments on commit 887e3e3

Please sign in to comment.